From bb59d770b3cbdb24c78f70baf7ff588a53482fe9 Mon Sep 17 00:00:00 2001 From: Ruslan Kabatsayev Date: Mon, 5 Aug 2024 21:43:27 +0400 Subject: [PATCH] Fix an off-by-one mistake in LP texture coordinates --- shaders/texture-coordinates.frag | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shaders/texture-coordinates.frag b/shaders/texture-coordinates.frag index 6d3c082f..f952ccb3 100644 --- a/shaders/texture-coordinates.frag +++ b/shaders/texture-coordinates.frag @@ -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;