diff --git a/data/shaders/planet.frag b/data/shaders/planet.frag index 35cd043f666151..fa6310182886db 100644 --- a/data/shaders/planet.frag +++ b/data/shaders/planet.frag @@ -185,6 +185,29 @@ vec3 linearToSRGB(vec3 lin) void main() { +#ifndef IS_MOON + if(sunInfo.w==0) + { + // We are drawing the Sun + vec4 texColor = texture2D(tex, texc); + texColor.rgb = srgbToLinear(texColor.rgb * sunInfo.rgb); + // Reference: Arthur N. Cox, "Allen's Astrophysical Quantities", 4th edition, + // chapter 14.7 Limb Darkening. + // The values for u2 and v2 for wavelengths 400nm-800nm were taken, linearly + // interpolated, and integrated against CIE 1931 color matching functions. + // The results were transformed from XYZ to linear sRGB color space. + // We call the results for u2 "a1", and for v2 "a2". + const vec3 a2 = vec3(-0.226988526315793, -0.232934589453355, -0.153026433664999); + const vec3 a1 = vec3(0.848380336865573, 0.937696820066542, 0.981762186155682); + const vec3 a0 = vec3(1) - a1 - a2; + float cosTheta = dot(eyeDirection, normalize(normalVS)); + float cosTheta2 = cosTheta*cosTheta; + vec3 limbDarkeningCoef = a0 + a1*cosTheta + a2*cosTheta2; + vec3 color = texColor.rgb * limbDarkeningCoef; + FRAG_COLOR = vec4(linearToSRGB(color), texColor.a); + return; + } +#endif mediump float final_illumination = 1.0; #ifdef OREN_NAYAR mediump float lum = 1.; diff --git a/src/core/modules/Planet.cpp b/src/core/modules/Planet.cpp index 80acb5129dc092..8815162ccb1353 100644 --- a/src/core/modules/Planet.cpp +++ b/src/core/modules/Planet.cpp @@ -3882,10 +3882,13 @@ Planet::RenderData Planet::setCommonShaderUniforms(const StelPainter& painter, Q GL(shader->setUniformValue(shaderVars.tex, 0)); GL(shader->setUniformValue(shaderVars.shadowCount, static_cast(data.shadowCandidates.size()))); GL(shader->setUniformValue(shaderVars.shadowData, data.shadowCandidatesData)); - GL(shader->setUniformValue(shaderVars.sunInfo, static_cast(data.mTarget[12]), - static_cast(data.mTarget[13]), - static_cast(data.mTarget[14]), - static_cast(sun->getEquatorialRadius()))); + if(this!=sun) + { + GL(shader->setUniformValue(shaderVars.sunInfo, static_cast(data.mTarget[12]), + static_cast(data.mTarget[13]), + static_cast(data.mTarget[14]), + static_cast(sun->getEquatorialRadius()))); + } GL(shader->setUniformValue(shaderVars.skyBrightness, lmgr->getAtmosphereAverageLuminance())); GL(shader->setUniformValue(shaderVars.poleLat, 1.1f, -0.1f)); // Avoid white objects. poleLat is only used for Mars. @@ -3956,15 +3959,6 @@ void Planet::drawSphere(StelPainter* painter, float screenRd, bool drawOnlyRing) const SolarSystem* ssm = GETSTELMODULE(SolarSystem); - if (this==ssm->getSun()) - { - texMap->bind(); - //painter->setColor(2, 2, 0.2); // This is now in draw3dModel() to apply extinction - painter->setArrays(reinterpret_cast(projectedVertexArr.constData()), reinterpret_cast(model.texCoordArr.constData())); - painter->drawFromArray(StelPainter::Triangles, model.indiceArr.size(), 0, false, model.indiceArr.constData()); - return; - } - //cancel out if shaders are invalid if(shaderError) return; @@ -4006,6 +4000,11 @@ void Planet::drawSphere(StelPainter* painter, float screenRd, bool drawOnlyRing) GL(shader->bind()); RenderData rData = setCommonShaderUniforms(*painter,shader,*shaderVars); + if(this==ssm->getSun()) + { + const auto color = painter->getColor(); + GL(shader->setUniformValue(shaderVars->sunInfo, color[0], color[1], color[2], 0.f)); + } if (rings!=Q_NULLPTR) {