1
0
Fork 0
fgdata/Shaders/projection-2d.frag
fly ad55c1d2df Merge next for changed Compositor layout
Signed-off-by: fly <merspieler@airmail.cc>
2020-11-17 02:04:45 +11:00

29 lines
830 B
GLSL

// 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;
}