Skip to content

Commit

Permalink
fix: fix terrain shadows (doodlum#674)
Browse files Browse the repository at this point in the history
also fixed sign warnings
  • Loading branch information
Pentalimbed authored Oct 19, 2024
1 parent ba2fcb6 commit facfb2a
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ float GetInterpolatedHeight(float2 pxCoord, bool isVertical)
uint2 dims;
TexHeight.GetDimensions(dims.x, dims.y);

int2 lerpPxCoordA = min(0, int2(pxCoord - .5 * float2(isVertical, !isVertical)));
int2 lerpPxCoordB = min(0, int2(pxCoord + .5 * float2(isVertical, !isVertical)));
// oob is fine
int2 lerpPxCoordA = int2(pxCoord - .5 * float2(isVertical, !isVertical));
int2 lerpPxCoordB = int2(pxCoord + .5 * float2(isVertical, !isVertical));
float heightA = TexHeight[lerpPxCoordA];
float heightB = TexHeight[lerpPxCoordB];

Expand All @@ -29,9 +30,9 @@ float GetInterpolatedHeight(float2 pxCoord, bool isVertical)
heightB = (heightB - ZRange.x) / (ZRange.y - ZRange.x);

bool inBoundA = all(lerpPxCoordA > 0);
bool inBoundB = all(lerpPxCoordB < dims);
bool inBoundB = all(lerpPxCoordB < int2(dims));
if (inBoundA && inBoundB)
return lerp(heightA, heightB, frac(pxCoord.x - .5));
return lerp(heightA, heightB, frac((isVertical ? pxCoord.x : pxCoord.y) - .5));
else if (!inBoundA)
return heightB;
else
Expand All @@ -49,9 +50,9 @@ float2 GetInterpolatedHeightRW(float2 pxCoord, bool isVertical)
float2 heightB = RWTexShadowHeights[lerpPxCoordB];

bool inBoundA = all(lerpPxCoordA > 0);
bool inBoundB = all(lerpPxCoordB < dims);
bool inBoundB = all(lerpPxCoordB < int2(dims));
if (inBoundA && inBoundB)
return lerp(heightA, heightB, frac(pxCoord - .5));
return lerp(heightA, heightB, frac((isVertical ? pxCoord.x : pxCoord.y) - .5));
else if (!inBoundA)
return heightB;
else
Expand Down

0 comments on commit facfb2a

Please sign in to comment.