Skip to content

Commit

Permalink
Add support transparency for landscapes (#3293)
Browse files Browse the repository at this point in the history
Co-authored-by: Georg Zotti <Georg.Zotti@univie.ac.at>
  • Loading branch information
alex-w and gzotti committed Jul 2, 2023
1 parent c77b7c3 commit 5e14e82
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 135 deletions.
2 changes: 2 additions & 0 deletions guide/app_config_ini.tex
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ \subsection{\big[landscape\big]}
flag\_landscape\_sets\_minimal\_brightness & bool & Set \emph{true} to use value for minimal brightness for landscape from landscape settings.\\%\midrule
flag\_enable\_illumination\_layer & bool & Set \emph{true} to use illumination layer for landscape.\\%\midrule
flag\_enable\_labels & bool & Set \emph{true} to use landscape labels from gazetteer layer.\\%\midrule
flag\_transparency & bool & Set \emph{true} to show landscape semitransparent.\\
transparency & float & Use this transparency for landscapes. [0\ldots1] Typical value: \emph{0.5}\\
atmospheric\_extinction\_coefficient & float & Set atmospheric extinction coefficient $k$ [mag/airmass]\\%\midrule
temperature\_C & float & Set atmospheric temperature [Celsius]\\%\midrule
pressure\_mbar & float & Set atmospheric pressure [mbar]\\%\midrule
Expand Down
32 changes: 16 additions & 16 deletions guide/ch_interface.tex
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ \section{Setting Your Location}
``use as default'' checkbox, disable ``Get location from Network'',
and close the location window.

Two settings may influence the Landscape when changing locations:
Two settings may influence the landscape when changing locations:
\begin{description}
\item[Auto select landscapes] When changing the planet,
a fitting landscape panorama will be shown when available.
Expand Down Expand Up @@ -776,35 +776,35 @@ \subsection{The Landscape Tab}
The controls at the bottom right of the window operate as follows:

\begin{description}
\item[Show ground] This turns on and off landscape rendering (same
as the button \guibutton{0.6}{bt_ground.png} in the main tool bar).
\item[Use this landscape as default] Selecting this option will save
the landscape into the program configuration file so that the current
landscape will be the one used when Stellarium starts.
\item[Use associated planet and position] When enabled, selecting a
new landscape will automatically update the observer location.
Use this if the landscape is not just decoration, but a true
representation of a particular site you wish to visit in the simulation.
\item[Show landscape labels] Landscapes can be configured with a
gazetteer of interesting points, e.g., mountain peaks, which can be
labeled with this option.
\item[Show ground] This turns on and off landscape rendering (same
as the button \guibutton{0.6}{bt_ground.png} in the main tool bar).
\item[Show fog] This turns on and off rendering of a band of
fog/haze along the horizon, when available in this landscape.
\item[Show illumination] to reflect the ugly developments of our
civilisation, landscapes can be configured with a layer of light
pollution, e.g., streetlamps, bright windows, or the sky glow of a
nearby city. This layer, if present, will be mixed in when it is
dark enough.
\item[Minimal brightness] Use some minimal brightness
setting. Moonless night on very dark locations may appear too dark
on your screen. You may want to configure some minimal brightness
here.
\item[Show landscape labels] Landscapes can be configured with a
gazetteer of interesting points, e.g., mountain peaks, which can be
labeled with this option. Color and font size can also be configured.
\item[Position from landscape] When enabled, selecting a
new landscape will automatically update the observer location.
Use this if the landscape is not just decoration, but a true
representation of a particular site you wish to visit in the simulation.
\item[Minimal brightness] Moonless night on very dark locations may appear too dark
on your screen. You may want to configure some minimal brightness here.
\begin{description}
\item[from landscape, if given] Landscape authors may decide to
provide such a minimal brightness value in the \file{landscape.ini}
file.
\end{description}
\item[Draw only polygon]\newFeature{0.20.2} If a polygonal horizon line has been
defined for the landscape, only draw this.
\item[Polygonal line thickness]\newFeature{0.20.2} Set line width for the polygonal line.
defined for the landscape, only draw this with the given thickness.
\item[Transparency] Allow peeking below the horizon. \newFeature{23.3} Note that this may show graphical errors.
\end{description}

\noindent Using the button \menu{Add/remove landscapes\ldots}, you can also
Expand Down
Binary file modified guide/pictures/view_dialog_landscape_tab.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 20 additions & 17 deletions src/core/modules/Landscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ void LandscapeOldStyle::drawFog(StelCore*const core, const int firstFreeTexSampl
renderProgram->setUniformValue(shaderVars.vshift, vpos);

const float brightness = landFader.getInterstate()*fogFader.getInterstate()*(0.1f+0.1f*landscapeBrightness);
renderProgram->setUniformValue(shaderVars.brightness, brightness, brightness, brightness, landFader.getInterstate());
renderProgram->setUniformValue(shaderVars.brightness, brightness, brightness, brightness, (1.f-landscapeTransparency)*landFader.getInterstate());
renderProgram->setUniformValue(shaderVars.projectionMatrixInverse, prj->getProjectionMatrix().toQMatrix().inverted());
prj->setUnProjectUniforms(*renderProgram);

Expand All @@ -1096,14 +1096,15 @@ void LandscapeOldStyle::drawDecor(StelCore*const core, const int firstFreeTexSam
if (drawLight)
{
const auto brightness = illumFader.getInterstate()*lightScapeBrightness;
renderProgram->setUniformValue(shaderVars.brightness, brightness, brightness, brightness,
landFader.getInterstate());
renderProgram->setUniformValue(shaderVars.brightness,
brightness, brightness, brightness,
(1.f-landscapeTransparency)*landFader.getInterstate());
}
else
{
renderProgram->setUniformValue(shaderVars.brightness,
landscapeBrightness, landscapeBrightness, landscapeBrightness,
landFader.getInterstate());
landscapeBrightness, landscapeBrightness, landscapeBrightness,
(1.f-landscapeTransparency)*landFader.getInterstate());
}

renderProgram->setUniformValue(shaderVars.tanMode, tanMode);
Expand Down Expand Up @@ -1198,8 +1199,8 @@ void LandscapeOldStyle::drawGround(StelCore*const core, const int firstFreeTexSa
renderProgram->setUniformValue(shaderVars.vshift, vshift);
renderProgram->setUniformValue(shaderVars.projectionMatrixInverse, prj->getProjectionMatrix().toQMatrix().inverted());
renderProgram->setUniformValue(shaderVars.brightness,
landscapeBrightness, landscapeBrightness, landscapeBrightness,
landFader.getInterstate());
landscapeBrightness, landscapeBrightness, landscapeBrightness,
(1.f-landscapeTransparency)*landFader.getInterstate());
prj->setUnProjectUniforms(*renderProgram);
gl.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
Expand Down Expand Up @@ -1264,7 +1265,7 @@ void LandscapeOldStyle::drawFogLowGL(StelCore* core, StelPainter& sPainter) cons
transfo->combine(Mat4d::translation(Vec3d(0.,0.,static_cast<double>(vpos))));
sPainter.setProjector(core->getProjection(transfo));
sPainter.setBlending(true, GL_ONE, GL_ONE);
sPainter.setColor(Vec3f(landFader.getInterstate()*fogFader.getInterstate()*(0.1f+0.1f*landscapeBrightness)), landFader.getInterstate());
sPainter.setColor(Vec3f(landFader.getInterstate()*fogFader.getInterstate()*(0.1f+0.1f*landscapeBrightness)), (1.f-landscapeTransparency)*landFader.getInterstate());
fogTex->bind();
const double height = radius * static_cast<double>(calibrated?
(std::tan((fogAltAngle+fogAngleShift)*M_PI_180f) - std::tan(fogAngleShift*M_PI_180f))
Expand All @@ -1283,9 +1284,9 @@ void LandscapeOldStyle::drawDecorLowGL(StelCore* core, StelPainter& sPainter, co
if (landFader.getInterstate()==0.f)
return;
if (drawLight)
sPainter.setColor(Vec3f(illumFader.getInterstate()*lightScapeBrightness), landFader.getInterstate());
sPainter.setColor(Vec3f(illumFader.getInterstate()*lightScapeBrightness), (1.f-landscapeTransparency)*landFader.getInterstate());
else
sPainter.setColor(Vec3f(landscapeBrightness), landFader.getInterstate());
sPainter.setColor(Vec3f(landscapeBrightness), (1.f-landscapeTransparency)*landFader.getInterstate());

for (const auto& side : precomputedSides)
{
Expand All @@ -1307,7 +1308,7 @@ void LandscapeOldStyle::drawGroundLowGL(StelCore* core, StelPainter& sPainter) c
transfo->combine(Mat4d::zrotation(groundAngleRotateZ-static_cast<double>(angleRotateZOffset)) * Mat4d::translation(Vec3d(0,0,static_cast<double>(vshift))));

sPainter.setProjector(core->getProjection(transfo));
sPainter.setColor(landscapeBrightness, landscapeBrightness, landscapeBrightness, landFader.getInterstate());
sPainter.setColor(landscapeBrightness, landscapeBrightness, landscapeBrightness, (1.f-landscapeTransparency)*landFader.getInterstate());

if(groundTex.isNull())
{
Expand Down Expand Up @@ -1458,7 +1459,7 @@ void LandscapePolygonal::draw(StelCore* core, bool onlyPolygon)

if (!onlyPolygon) // The only useful application of the onlyPolygon is a demo which does not fill the polygon
{
sPainter.setColor(landscapeBrightness*groundColor, landFader.getInterstate());
sPainter.setColor(landscapeBrightness*groundColor, (1.f-landscapeTransparency)*landFader.getInterstate());
#ifdef GL_MULTISAMPLE
const auto gl = sPainter.glFuncs();
if (multisamplingEnabled_)
Expand Down Expand Up @@ -2033,7 +2034,7 @@ void main(void)

renderProgram->setUniformValue(shaderVars.brightness,
landscapeBrightness, landscapeBrightness,
landscapeBrightness, landFader.getInterstate());
landscapeBrightness, (1.f-landscapeTransparency)*landFader.getInterstate());
const int mainTexSampler = 0;
mapTex->bind(mainTexSampler);
renderProgram->setUniformValue(shaderVars.mapTex, mainTexSampler);
Expand Down Expand Up @@ -2063,8 +2064,9 @@ void main(void)
const float brightness = landFader.getInterstate()*fogFader.getInterstate()*(0.1f+0.1f*landscapeBrightness);

renderProgram->setUniformValue(shaderVars.bottomCapColor, 0.f, 0.f, 0.f, 0.f);
renderProgram->setUniformValue(shaderVars.brightness, brightness, brightness, brightness,
landFader.getInterstate());
renderProgram->setUniformValue(shaderVars.brightness,
brightness, brightness, brightness,
(1.f-landscapeTransparency)*landFader.getInterstate());
mapTexFog->bind();
renderProgram->setUniformValue(shaderVars.mapTexTop, fogTexTop);
renderProgram->setUniformValue(shaderVars.mapTexBottom, fogTexBottom);
Expand All @@ -2077,8 +2079,9 @@ void main(void)
gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE);
const float brightness = lightScapeBrightness*illumFader.getInterstate();
renderProgram->setUniformValue(shaderVars.bottomCapColor, 0.f, 0.f, 0.f, 0.f);
renderProgram->setUniformValue(shaderVars.brightness, brightness, brightness, brightness,
landFader.getInterstate());
renderProgram->setUniformValue(shaderVars.brightness,
brightness, brightness, brightness,
(1.f-landscapeTransparency)*landFader.getInterstate());
mapTexIllum->bind();
renderProgram->setUniformValue(shaderVars.mapTexTop, illumTexTop);
renderProgram->setUniformValue(shaderVars.mapTexBottom, illumTexBottom);
Expand Down
5 changes: 4 additions & 1 deletion src/core/modules/Landscape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Landscape
//! Get color for landscape labels
Vec3f getLabelColor() const { return labelColor; }
//! Set color for landscape labels
void setLabelColor(const Vec3f& c) { labelColor=c; };
void setLabelColor(const Vec3f& c) { labelColor=c; }

//! Get landscape name
QString getName() const {return name;}
Expand Down Expand Up @@ -179,6 +179,8 @@ class Landscape
//! Get the sine of the limiting altitude (can be used to short-cut drawing below horizon, like star fields). There is no set here, value is only from landscape.ini
double getSinMinAltitudeLimit() const {return sinMinAltitudeLimit;}

void setTransparency(const double f) { landscapeTransparency=f; }

//! Find opacity in a certain direction. (New in V0.13 series)
//! can be used to find sunrise or visibility questions on the real-world landscape horizon.
//! Default implementation indicates the horizon equals math horizon.
Expand Down Expand Up @@ -253,6 +255,7 @@ class Landscape
//! Not in landscape.ini: Used in special cases where the horizon may rotate, e.g. on a ship.

double sinMinAltitudeLimit; //! Minimal altitude of landscape cover. Can be used to construct bounding caps, so that e.g. no stars are drawn below this altitude. Default -0.035, i.e. sin(-2 degrees).
double landscapeTransparency;

StelLocation location; //! OPTIONAL. If present, can be used to set location.
/** May be given in landscape.ini:light_pollution_luminance in cd/m². Default: no change.
Expand Down
23 changes: 22 additions & 1 deletion src/core/modules/LandscapeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ LandscapeMgr::LandscapeMgr()
, defaultMinimalBrightness(0.01)
, flagLandscapeSetsMinimalBrightness(false)
, flagEnvironmentAutoEnabling(false)
, flagLandscapeUseTransparency(false)
, landscapeTransparency(0.)
{
setObjectName("LandscapeMgr"); // should be done by StelModule's constructor.

Expand Down Expand Up @@ -647,6 +649,8 @@ void LandscapeMgr::update(double deltaTime)
}

landscape->setBrightness(landscapeBrightness, lightscapeBrightness);
if (getFlagLandscapeUseTransparency())
landscape->setTransparency(landscapeTransparency);

messageFader.update(static_cast<int>(deltaTime*1000));
}
Expand Down Expand Up @@ -850,6 +854,9 @@ void LandscapeMgr::init()
setLabelFontSize(conf->value("landscape/label_font_size", 18).toInt());
setLabelColor(Vec3f(conf->value("landscape/label_color", "0.2,0.8,0.2").toString()));

setFlagLandscapeUseTransparency(conf->value("landscape/flag_transparency", false).toBool());
setLandscapeTransparency(conf->value("landscape/transparency", 0.5).toDouble());

cardinalPoints = new Cardinals();
cardinalPoints->setFlagShow4WCRLabels(conf->value("viewing/flag_cardinal_points", true).toBool());
cardinalPoints->setFlagShow8WCRLabels(conf->value("viewing/flag_ordinal_points", true).toBool());
Expand Down Expand Up @@ -1113,7 +1120,10 @@ bool LandscapeMgr::getIsLandscapeFullyVisible() const

double LandscapeMgr::getLandscapeSinMinAltitudeLimit() const
{
return landscape->getSinMinAltitudeLimit();
if (flagLandscapeUseTransparency && landscapeTransparency>0.)
return -1.;
else
return landscape->getSinMinAltitudeLimit();
}

bool LandscapeMgr::getFlagUseLightPollutionFromDatabase() const
Expand Down Expand Up @@ -1257,6 +1267,17 @@ bool LandscapeMgr::getFlagIllumination() const
return landscape->getFlagShowIllumination();
}

void LandscapeMgr::setLandscapeTransparency(const double f)
{
landscapeTransparency = f;
emit landscapeDisplayedChanged(f);
}

double LandscapeMgr::getLandscapeTransparency() const
{
return landscapeTransparency;
}

void LandscapeMgr::setFlagLabels(const bool displayed)
{
if (landscape->getFlagShowLabels() != displayed) {
Expand Down
32 changes: 32 additions & 0 deletions src/core/modules/LandscapeMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ class LandscapeMgr : public StelModule
READ getLabelColor
WRITE setLabelColor
NOTIFY labelColorChanged)
Q_PROPERTY(double landscapeTransparency
READ getLandscapeTransparency
WRITE setLandscapeTransparency
NOTIFY landscapeTransparencyChanged)
Q_PROPERTY(bool flagLandscapeUseTransparency
READ getFlagLandscapeUseTransparency
WRITE setFlagLandscapeUseTransparency
NOTIFY flagLandscapeUseTransparencyChanged)

public:
LandscapeMgr();
Expand Down Expand Up @@ -556,6 +564,23 @@ public slots:
//! Set atmosphere fade duration in s.
void setAtmosphereFadeDuration(const float f);

double getLandscapeTransparency() const;
void setLandscapeTransparency(const double f);
//! Return the value of the flag determining if a transparency should be used.
bool getFlagLandscapeUseTransparency() const {return flagLandscapeUseTransparency; }
//! Set the value of the flag determining if a transparency should be used.
void setFlagLandscapeUseTransparency(bool b)
{
if (b!=flagLandscapeUseTransparency)
{
flagLandscapeUseTransparency=b;
emit flagLandscapeUseTransparencyChanged(b);
}
if (b==false)
landscape->setTransparency(0.0);
}


/*
//This method has been removed, use StelSkyDrawer::getBortleScaleIndex instead, or StelMainScriptAPI::getBortleScaleIndex in scripts
//Also, if required, please use StelSkyDrawer::setBortleScaleIndex or StelMainScriptAPI::setBortleScaleIndex instead of LandscapeMgr::setAtmosphereBortleLightPollution
Expand Down Expand Up @@ -702,6 +727,8 @@ public slots:
void flagLandscapeSetsMinimalBrightnessChanged(const bool value);
void defaultMinimalBrightnessChanged(const double value);
void setFlagEnvironmentAutoEnableChanged(const bool enabled);
void landscapeTransparencyChanged(const double value);
void flagLandscapeUseTransparencyChanged(const bool value);

//! Emitted whenever the default landscape is changed
//! @param id the landscape id of the new default landscape
Expand Down Expand Up @@ -810,6 +837,11 @@ private slots:
//! Indicate auto-enable atmosphere and landscape for planets with atmospheres in location window
bool flagEnvironmentAutoEnabling;

//! Indicate use of the default transparency value specified in config.ini.
bool flagLandscapeUseTransparency;
//! A transparency value
double landscapeTransparency;

//! The ID of the currently loaded landscape
QString currentLandscapeID;

Expand Down
2 changes: 2 additions & 0 deletions src/gui/ConfigurationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,8 @@ void ConfigurationDialog::saveAllSettings()
conf->setValue("landscape/flag_minimal_brightness", propMgr->getStelPropertyValue("LandscapeMgr.flagLandscapeUseMinimalBrightness").toBool());
conf->setValue("landscape/flag_landscape_sets_minimal_brightness", propMgr->getStelPropertyValue("LandscapeMgr.flagLandscapeSetsMinimalBrightness").toBool());
conf->setValue("landscape/minimal_brightness", propMgr->getStelPropertyValue("LandscapeMgr.defaultMinimalBrightness").toFloat());
conf->setValue("landscape/flag_transparency", propMgr->getStelPropertyValue("LandscapeMgr.flagLandscapeUseTransparency").toBool());
conf->setValue("landscape/transparency", propMgr->getStelPropertyValue("LandscapeMgr.landscapeTransparency").toFloat());
conf->setValue("landscape/flag_polyline_only", propMgr->getStelPropertyValue("LandscapeMgr.flagPolyLineDisplayedOnly").toBool());
conf->setValue("landscape/polyline_thickness", propMgr->getStelPropertyValue("LandscapeMgr.polyLineThickness").toInt());
conf->setValue("stars/init_light_pollution_luminance", propMgr->getStelPropertyValue("StelSkyDrawer.lightPollutionLuminance").toFloat());
Expand Down
2 changes: 2 additions & 0 deletions src/gui/ViewDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ void ViewDialog::createDialogContent()
ui->localLandscapeBrightnessCheckBox->setEnabled(lmgr->property("flagLandscapeUseMinimalBrightness").toBool());
ui->landscapeBrightnessSpinBox->setEnabled(lmgr->property("flagLandscapeUseMinimalBrightness").toBool());
connectDoubleProperty(ui->landscapeBrightnessSpinBox,"LandscapeMgr.defaultMinimalBrightness");
connectBoolProperty(ui->landscapeTransparencyCheckBox,"LandscapeMgr.flagLandscapeUseTransparency");
connectDoubleProperty(ui->landscapeTransparencySpinBox,"LandscapeMgr.landscapeTransparency");
connectBoolProperty(ui->localLandscapeBrightnessCheckBox,"LandscapeMgr.flagLandscapeSetsMinimalBrightness");
connectBoolProperty(ui->landscapePolylineCheckBox, "LandscapeMgr.flagPolyLineDisplayedOnly");
connectIntProperty(ui->landscapePolylineThicknessSpinBox, "LandscapeMgr.polyLineThickness");
Expand Down

0 comments on commit 5e14e82

Please sign in to comment.