Skip to content

Commit

Permalink
Fix an off-by-one mistake in LP texture coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
10110111 committed Aug 5, 2024
1 parent a4b3d74 commit bb59d77
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions shaders/texture-coordinates.frag
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,12 @@ LightPollutionTexVars scatteringTexIndicesToLightPollutionTexVars(const vec2 tex
{
CONST vec2 indexMax=lightPollutionTextureSize-vec2(1);

CONST float altitudeURCoord = texIndices[1] / (indexMax[1]-1);
CONST float altitudeURCoord = texIndices[1] / indexMax[1];
CONST float distToHorizon = altitudeURCoord*LENGTH_OF_HORIZ_RAY_FROM_GROUND_TO_TOA;
// Rounding errors can result in altitude>max, breaking the code after this calculation, so we have to clamp.
CONST float altitude=clampAltitude(sqrt(sqr(distToHorizon)+sqr(earthRadius))-earthRadius);

CONST bool viewRayIntersectsGround = texIndices[0] < indexMax[0]/2;
CONST bool viewRayIntersectsGround = texIndices[0] < lightPollutionTextureSize[0]/2;
CONST float cosViewZenithAngleCoord = viewRayIntersectsGround ?
1-2*texIndices[0]/(indexMax[0]-1) :
2*(texIndices[0]-1)/(indexMax[0]-1)-1;
Expand Down

0 comments on commit bb59d77

Please sign in to comment.