From df900a2e463cdc979bc0d00436d7913eaff764d6 Mon Sep 17 00:00:00 2001 From: fly Date: Thu, 12 Nov 2020 04:16:58 +1100 Subject: [PATCH] High fov Distortion correction Signed-off-by: fly --- Compositor/Effects/projection-2d.eff | 44 +++++++ Compositor/Shaders/ALS/projection-2d.frag | 29 +++++ Compositor/als-projection-2d.xml | 142 ++++++++++++++++++++++ 3 files changed, 215 insertions(+) create mode 100644 Compositor/Effects/projection-2d.eff create mode 100644 Compositor/Shaders/ALS/projection-2d.frag create mode 100644 Compositor/als-projection-2d.xml diff --git a/Compositor/Effects/projection-2d.eff b/Compositor/Effects/projection-2d.eff new file mode 100644 index 000000000..c65a85874 --- /dev/null +++ b/Compositor/Effects/projection-2d.eff @@ -0,0 +1,44 @@ + + + Effects/Compositor/projection-2d + + /sim/current-view/field-of-view + + /sim/startup/xsize + + + /sim/startup/ysize + + + + + + Compositor/Shaders/ALS/projection-2d.frag + + + 2 + 2d + + + display_x + int + display_xsize + + + display_y + int + display_ysize + + + hfov + float + hfov + + + iChannel0 + sampler-2d + 2 + + + + diff --git a/Compositor/Shaders/ALS/projection-2d.frag b/Compositor/Shaders/ALS/projection-2d.frag new file mode 100644 index 000000000..e86cf72b1 --- /dev/null +++ b/Compositor/Shaders/ALS/projection-2d.frag @@ -0,0 +1,29 @@ +// uniforms +uniform float hfov; +uniform vec2 fg_ViewportSize; +uniform sampler2D iChannel0; +uniform int display_x; +uniform int display_y; + +void main(void) +{ + // Defines + float pi = 3.1415926535897932384626433832795; + // Guess vfov based on screen dimensions + float vfov = hfov * (fg_ViewportSize.y / fg_ViewportSize.x); + + // Normalize + vec2 uv = gl_FragCoord.xy / fg_ViewportSize.xy; + // Indicates the position we want on the input + vec2 ray = vec2(0.0, 0.0); + + // Correction for the distortion in the original image + //ray.y = 0.5 * tan((vfov/180.0) * (uv.y - 0.5) * pi) / tan(0.5 * (vfov/180.0) * pi) + 0.5; + ray.y = uv.y; + ray.x = 0.5 * tan((hfov/180.0) * (uv.x - 0.5) * pi) / tan(0.5 * (hfov/180.0) * pi) + 0.5; + + // Lookup on the input texture + vec4 ret = texture2D( iChannel0, ray.xy ); + ret.a = 1.0; + gl_FragColor = ret; +} diff --git a/Compositor/als-projection-2d.xml b/Compositor/als-projection-2d.xml new file mode 100644 index 000000000..8dda3e5ed --- /dev/null +++ b/Compositor/als-projection-2d.xml @@ -0,0 +1,142 @@ + + + + ALS + + + color + 2d + screen + screen + rgba8 + + + depth + 2d + screen + screen + depth32f + + + + sun-shadowmap-atlas + 2d + /sim/rendering/als/shadows/sun-atlas-size + /sim/rendering/als/shadows/sun-atlas-size + depth32f + clamp-to-border + clamp-to-border + clamp-to-border + linear + linear + 1.0 1.0 1.0 1.0 + true + + + + + + csm0 + 0.1 + 3.0 + + 0.0 + 0.0 + 0.5 + 0.5 + + + + csm1 + 3.0 + 50.0 + + 0.5 + 0.0 + 0.5 + 0.5 + + + + csm2 + 50.0 + 150.0 + + 0.0 + 0.5 + 0.5 + 0.5 + + + + csm3 + 150.0 + 1500.0 + + 0.5 + 0.5 + 0.5 + 0.5 + + + + + forward + scene + als-lighting + + + 128 + 1 + 1 + + + csm0 + csm1 + csm2 + csm3 + + + + + sun-shadowmap-atlas + 10 + + + + color + color0 + 4 + 4 + + + depth + depth + 4 + 4 + + + + + display + quad + + color + 2 + + Compositor/Effects/projection-2d + +