From a3ce90a2fec99a79262e5eaadc1e0030e299ca01 Mon Sep 17 00:00:00 2001 From: Ole-Morten Duesund Date: Thu, 29 Jan 2026 16:57:01 +0100 Subject: [PATCH] Fix aspect ratio correction for intermediate rotation angles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apply screen aspect ratio correction to offset.y (screen X direction) instead of offset.x (screen Y direction) in both linear and radial mode distance calculations. This fixes angle distortion at non-90° rotations in portrait mode. Co-Authored-By: Claude Opus 4.5 --- app/src/main/res/raw/tiltshift_fragment.glsl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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