From 2344624b08b553fd4fcc97b1c41c3747498ba403 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 18 Jul 2021 22:48:13 +0100 Subject: [PATCH] PostProcessing: fix lens distortion shader for HLSL --- Data/Sys/Shaders/lens_distortion.glsl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Data/Sys/Shaders/lens_distortion.glsl b/Data/Sys/Shaders/lens_distortion.glsl index 9b40ea1a8b..f36f232524 100644 --- a/Data/Sys/Shaders/lens_distortion.glsl +++ b/Data/Sys/Shaders/lens_distortion.glsl @@ -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); @@ -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));