Skip to content

Commit

Permalink
Fix Earth shadow on scaled Moon during eclipse
Browse files Browse the repository at this point in the history
The unprojected position passed to the shader should be the actual
physical position without the fake scaling effect, so that the shadow
gets properly computed.
  • Loading branch information
guillaumechereau committed Jul 27, 2018
1 parent cc3e40b commit 1641c8d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/modules/Planet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2557,11 +2557,15 @@ void Planet::drawSphere(StelPainter* painter, float screenSz, bool drawOnlyRing)

// Generates the vertice
Planet3DModel model;
sSphere(&model, radius*sphereScale, oneMinusOblateness, nb_facet, nb_facet);
sSphere(&model, radius, oneMinusOblateness, nb_facet, nb_facet);

QVector<float> projectedVertexArr(model.vertexArr.size());
for (int i=0;i<model.vertexArr.size()/3;++i)
painter->getProjector()->project(*((Vec3f*)(model.vertexArr.constData()+i*3)), *((Vec3f*)(projectedVertexArr.data()+i*3)));
{
Vec3f p = *((Vec3f*)(model.vertexArr.constData()+i*3));
p *= sphereScale;
painter->getProjector()->project(p, *((Vec3f*)(projectedVertexArr.data()+i*3)));
}

const SolarSystem* ssm = GETSTELMODULE(SolarSystem);

Expand Down Expand Up @@ -2774,7 +2778,7 @@ void Planet::drawSurvey(StelCore* core, StelPainter* painter)
v = verts[i];
painter->getProjector()->project(v, v);
projectedVertsArray[i] = Vec3f(v[0], v[1], v[2]);
v = Mat4d::scaling(radius * sphereScale) * verts[i];
v = Mat4d::scaling(radius) * verts[i];
v = Mat4d::scaling(Vec3d(1, 1, oneMinusOblateness)) * v;
// Undo the rotation we applied for the survey fix.
v = Mat4d::zrotation(M_PI / 2.0) * v;
Expand Down

0 comments on commit 1641c8d

Please sign in to comment.