diff --git a/app/src/main/res/raw/tiltshift_fragment.glsl b/app/src/main/res/raw/tiltshift_fragment.glsl index e05ee2c..86c4d99 100644 --- a/app/src/main/res/raw/tiltshift_fragment.glsl +++ b/app/src/main/res/raw/tiltshift_fragment.glsl @@ -29,6 +29,12 @@ float linearFocusDistance(vec2 uv) { vec2 center = vec2(uPositionY, 1.0 - uPositionX); vec2 offset = uv - center; + // Correct for screen aspect ratio to make coordinate space square + // After transform: offset.x = screen Y direction, offset.y = screen X direction + // Scale offset.y to match the scale of offset.x (height units) + float screenAspect = uResolution.x / uResolution.y; + offset.y *= screenAspect; + // Adjust angle by +90 degrees to compensate for the coordinate transformation // The position transform is a 90° CW rotation, so angles transform as θ + 90° float adjustedAngle = uAngle + 1.5707963; @@ -49,10 +55,11 @@ float radialFocusDistance(vec2 uv) { vec2 center = vec2(uPositionY, 1.0 - uPositionX); vec2 offset = uv - center; - // Adjust for aspect ratio to create ellipse - // Correct for screen aspect ratio first + // Correct for screen aspect ratio to make coordinate space square + // After transform: offset.x = screen Y direction, offset.y = screen X direction + // Scale offset.y to match the scale of offset.x (height units) float screenAspect = uResolution.x / uResolution.y; - offset.x *= screenAspect; + offset.y *= screenAspect; // Apply rotation // Adjust angle by +90 degrees to compensate for the coordinate transformation