Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9913 from Tilka/postprocess
PostProcessing: fix lens distortion shader for HLSL
  • Loading branch information
lioncash committed Jul 20, 2021
2 parents c184569 + 2344624 commit 6ed201c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Data/Sys/Shaders/lens_distortion.glsl
Expand Up @@ -63,7 +63,7 @@ void main()
}

// convert coordinates to NDC space
float2 fragPos = (GetCoordinates() - 0.5f - vec2(offsetAdd, 0.0f)) * 2.0f;
float2 fragPos = (GetCoordinates() - 0.5f - float2(offsetAdd, 0.0f)) * 2.0f;

// Calculate the source location "radius" (distance from the centre of the viewport)
float destR = length(fragPos);
Expand All @@ -72,16 +72,16 @@ void main()
float srcR = destR * sizeAdjust + ( ka * pow(destR, 2.0) + kb * pow(destR, 4.0));

// Calculate the source vector (radial)
vec2 correctedRadial = normalize(fragPos) * srcR;
float2 correctedRadial = normalize(fragPos) * srcR;

// fix aspect ratio
vec2 widenedRadial = correctedRadial * vec2(aspectAdjustment, 1.0f);
float2 widenedRadial = correctedRadial * float2(aspectAdjustment, 1.0f);

// Transform the coordinates (from [-1,1]^2 to [0, 1]^2)
vec2 uv = (widenedRadial/2.0f) + vec2(0.5f) + vec2(offsetAdd, 0.0f);
float2 uv = (widenedRadial/2.0f) + float2(0.5f, 0.5f) + float2(offsetAdd, 0.0f);

// Sample the texture at the source location
if(clamp(uv, 0.0, 1.0) != uv)
if(any(clamp(uv, 0.0, 1.0) != uv))
{
// black if beyond bounds
SetOutput(float4(0.0, 0.0, 0.0, 0.0));
Expand Down

0 comments on commit 6ed201c

Please sign in to comment.