Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions data/shaders/planet.frag
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,30 @@ 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: chapter 14.7 "Limb Darkening" in "Allen’s Astrophysical Quantities",
// A.N.Cox (ed.), 4th edition, New York: Springer-Verlag, 2002.
// DOI 10.1007/978-1-4612-1186-0
// 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.;
Expand Down
25 changes: 12 additions & 13 deletions src/core/modules/Planet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GLint>(data.shadowCandidates.size())));
GL(shader->setUniformValue(shaderVars.shadowData, data.shadowCandidatesData));
GL(shader->setUniformValue(shaderVars.sunInfo, static_cast<GLfloat>(data.mTarget[12]),
static_cast<GLfloat>(data.mTarget[13]),
static_cast<GLfloat>(data.mTarget[14]),
static_cast<GLfloat>(sun->getEquatorialRadius())));
if(this!=sun)
{
GL(shader->setUniformValue(shaderVars.sunInfo, static_cast<GLfloat>(data.mTarget[12]),
static_cast<GLfloat>(data.mTarget[13]),
static_cast<GLfloat>(data.mTarget[14]),
static_cast<GLfloat>(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.

Expand Down Expand Up @@ -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<const Vec3f*>(projectedVertexArr.constData()), reinterpret_cast<const Vec2f*>(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;
Expand Down Expand Up @@ -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)
{
Expand Down