Skip to content

Commit

Permalink
Better tint
Browse files Browse the repository at this point in the history
- now reddening is drawn down to -3° solar altitude with a smooth curve
- Scenery3D: ambient also receives a slight reddening
- Scenery3D: cleanup outdated code (night mode)
  • Loading branch information
gzotti committed Aug 30, 2024
1 parent 4df73d2 commit 0b637f0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
50 changes: 19 additions & 31 deletions plugins/Scenery3d/src/S3DRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,31 +969,17 @@ void S3DRenderer::calculateLighting()
//specular factor is calculated from other values for now
float specular = std::min(ambientBrightness*directionalBrightness*5.0f,1.0f);

//if the night vision mode is on, use red-tinted lighting
bool red=StelApp::getInstance().getVisionModeNight();

float torchDiff = shaderParameters.torchLight ? torchBrightness : 0.0f;
lightInfo.torchAttenuation = 1.0f / (torchRange * torchRange);

if(red)
{
lightInfo.ambient = QVector3D(ambientBrightness,0, 0);
lightInfo.directional = QVector3D(directionalBrightness,0,0);
lightInfo.emissive = QVector3D(emissiveFactor,0,0);
lightInfo.specular = QVector3D(specular,0,0);
lightInfo.torchDiffuse = QVector3D(torchDiff,0,0);
}
else
{
static LandscapeMgr *lmgr=GETSTELMODULE(LandscapeMgr);
QVector3D solarTint=lmgr->getLandscapeTint().toQVector();
//for now, ambient is only whitish. Directional and specular are tinted with possibly reddened sun.
lightInfo.ambient = QVector3D(ambientBrightness,ambientBrightness, ambientBrightness);
lightInfo.directional = directionalBrightness*solarTint;
lightInfo.emissive = QVector3D(emissiveFactor,emissiveFactor,emissiveFactor);
lightInfo.specular = specular*solarTint;
lightInfo.torchDiffuse = QVector3D(torchDiff,torchDiff,torchDiff);
}
static LandscapeMgr *lmgr=GETSTELMODULE(LandscapeMgr);
QVector3D solarTint=lmgr->getLandscapeTint().toQVector();
//ambient tries to neutralize sunrise reddening a bit to model collecting light more of the blue sky. Directional and specular are tinted with possibly reddened sun.
lightInfo.ambient = ambientBrightness*(QVector3D(0.25,0.25,0.25)+0.75*solarTint);
lightInfo.directional = directionalBrightness*solarTint;
lightInfo.emissive = QVector3D(emissiveFactor,emissiveFactor,emissiveFactor);
lightInfo.specular = specular*solarTint;
lightInfo.torchDiffuse = QVector3D(torchDiff,torchDiff,torchDiff);
}

void S3DRenderer::calcCubeMVP(const Vec3d translation)
Expand Down Expand Up @@ -1499,10 +1485,12 @@ void S3DRenderer::drawDebug()
Q_ASSERT(lightInfo.directionalSource<=LightParameters::DS_Venus_Ambient);
directionalSourceString = directionalSourceStrings.at(lightInfo.directionalSource);

const QString lightMessage=QString("Ambient: %1 Directional: %2. Shadows cast by: %3 from %4/%5/%6")
.arg(lightInfo.ambient[0], 6, 'f', 4).arg(lightInfo.directional[0], 6, 'f', 4)
.arg(shadowCasterName).arg(lightInfo.lightDirectionV3f.v[0], 6, 'f', 4)
.arg(lightInfo.lightDirectionV3f.v[1], 6, 'f', 4).arg(lightInfo.lightDirectionV3f.v[2], 6, 'f', 4);
QString lightMessage=QString("Ambient: %1/%2/%3 Directional: %4/%5/%6. Shadows cast by: %7")
.arg(QString::number(lightInfo.ambient[0], 'f', 1), QString::number(lightInfo.ambient[1], 'f', 1), QString::number(lightInfo.ambient[2], 'f', 1),
QString::number(lightInfo.directional[0], 'f', 4), QString::number(lightInfo.directional[1], 'f', 4), QString::number(lightInfo.directional[2], 'f', 4))
.arg(shadowCasterName);
if (lightInfo.shadowCaster>LightParameters::SC_None)
lightMessage.append(QString(" from %1/%2/%3").arg(QString::number(lightInfo.lightDirectionV3f.v[0],'f', 4), QString::number(lightInfo.lightDirectionV3f.v[1], 'f', 4), QString::number(lightInfo.lightDirectionV3f.v[2],'f', 4)));
const QString lightMessage2=QString("Contributions: Ambient Sun: %1, Moon: %2, Background+^L: %3")
.arg(lightInfo.sunAmbient, 6, 'f', 4).arg(lightInfo.moonAmbient, 6, 'f', 4).arg(lightInfo.backgroundAmbient, 6, 'f', 4);
const QString lightMessage3=QString(" Directional %1 by: %2, emissive factor: %3, landscape opacity: %4")
Expand All @@ -1512,15 +1500,15 @@ void S3DRenderer::drawDebug()
painter.setFont(debugTextFont);
painter.setColor(1.f,0.f,1.f,1.f);
// For now, these messages print light mixture values.
painter.drawText(20, 160, lightMessage);
painter.drawText(20, 145, lightMessage2);
painter.drawText(20, 130, lightMessage3);
painter.drawText(20, 115, QString("Torch range %1, brightness %2/%3/%4").arg(torchRange).arg(lightInfo.torchDiffuse[0]).arg(lightInfo.torchDiffuse[1]).arg(lightInfo.torchDiffuse[2]));
painter.drawText(70, 160, lightMessage);
painter.drawText(70, 145, lightMessage2);
painter.drawText(70, 130, lightMessage3);
painter.drawText(70, 115, QString("Torch range %1, brightness %2/%3/%4").arg(torchRange).arg(lightInfo.torchDiffuse[0]).arg(lightInfo.torchDiffuse[1]).arg(lightInfo.torchDiffuse[2]));

const AABBox& bbox = currentScene->getSceneAABB();
QString str = QString("BB: %1/%2/%3 %4/%5/%6").arg(bbox.min.v[0], 7, 'f', 2).arg(bbox.min.v[1], 7, 'f', 2).arg(bbox.min.v[2], 7, 'f', 2)
.arg(bbox.max.v[0], 7, 'f', 2).arg(bbox.max.v[1], 7, 'f', 2).arg(bbox.max.v[2], 7, 'f', 2);
painter.drawText(10, 100, str);
painter.drawText(70, 100, str);
// PRINT OTHER MESSAGES HERE:

float screen_x = altAzProjector->getViewportWidth() - 500.0f;
Expand Down
8 changes: 4 additions & 4 deletions plugins/Scenery3d/src/S3DRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ class S3DRenderer : public QObject, protected QOpenGLFunctions
Vec3f lightDirectionV3f;
//same as lightDirectionV3f, but as QVector3D
QVector3D lightDirectionWorld;
QVector3D ambient;
QVector3D directional;
QVector3D specular;
QVector3D emissive;
QVector3D ambient; // color [0...1]
QVector3D directional; // color [0...1]
QVector3D specular; // color [0...1]
QVector3D emissive; // color [0...1]

QVector3D torchDiffuse;
float torchAttenuation;
Expand Down
24 changes: 17 additions & 7 deletions src/core/modules/Planet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2852,25 +2852,35 @@ void Planet::draw(StelCore* core, float maxMagLabels, const QFont& planetNameFon
if (isSun && currentLocationIsEarth)
{
static LandscapeMgr* lmgr = GETSTELMODULE(LandscapeMgr);
const Vec3f posAltAz = getAltAzPosAuto(core).toVec3f();

if (posAltAz[2]<0.f)
Vec3f posAltAz = getAltAzPosAuto(core).toVec3f();
posAltAz.normalize();

// If sun is higher than -3 degrees, tint the landscape.
// Down to 0 degree, this tint is derived from the halo color.
// Below that, we must find a smooth transition. Below -3 degrees,
// it is assumed the reddish tint should have dissipated, and the blue sky is illuminating the landscape in a neutral tone.
if (posAltAz[2]<sinf(-3.f*M_PI_180f))
lmgr->setLandscapeTint(Vec3f(1.f));
else
{
const float sunAlt=asinf(posAltAz[2]);
const float angleFactor=sunAlt>0 ? 1.f : 0.5f*(cosf(60.f*sunAlt)+1.f);

// Find extinction settings to change colors. The method is rather ad-hoc.
const float extinctedMag=getVMagnitudeWithExtinction(core)-getVMagnitude(core); // this is net value of extinction, in mag.
const float magFactorGreen=powf(0.85f, 0.6f*extinctedMag);
const float magFactorBlue=powf(0.6f, 0.5f*extinctedMag);
//const float magFactorGreen=powf(0.85f, 0.6f*extinctedMag);
//const float magFactorBlue=powf(0.6f, 0.5f*extinctedMag);
Vec3f color(haloColor[0], powf(0.75f, extinctedMag) * haloColor[1], powf(0.42f, 0.9f*extinctedMag) * haloColor[2]);

Vec3f fullTint(0.25f*Vec3f(3.f+sqrtf(color[0]), 3.f+sqrtf(color[1]), 3.f+sqrtf(color[2])));

//lmgr->setLandscapeTint(Vec3f(1.f, magFactorGreen, magFactorBlue)); // TODO: or simply apply color?
//lmgr->setLandscapeTint(color);
//lmgr->setLandscapeTint(Vec3f(color[0]*color[0], color[1]*color[1], color[2]*color[2])); // stronger tint: UGLY!
//lmgr->setLandscapeTint(Vec3f(sqrtf(color[0]), sqrtf(color[1]), sqrtf(color[2]))); // weaker tint
//lmgr->setLandscapeTint(0.5f*Vec3f(1.f+sqrtf(color[0]), 1.f+sqrtf(color[1]), 1.f+sqrtf(color[2]))); // even weaker tint
//lmgr->setLandscapeTint(0.25f*Vec3f(3.f+sqrtf(color[0]), 3.f+sqrtf(color[1]), 3.f+sqrtf(color[2]))); // even weaker tint
lmgr->setLandscapeTint(0.25f*Vec3f(4.f, 3.f+sqrtf(magFactorGreen), 3.f+sqrtf(magFactorBlue))); // even weaker tint
//lmgr->setLandscapeTint(0.25f*Vec3f(4.f, 3.f+sqrtf(magFactorGreen), 3.f+sqrtf(magFactorBlue))); // even weaker tint
lmgr->setLandscapeTint(angleFactor*fullTint + (1.f-angleFactor)*Vec3f(1.f)); // final tint
}
}

Expand Down

0 comments on commit 0b637f0

Please sign in to comment.