From b1a90a7f915e7779aad975a70b503788b0a1b228 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 2 Sep 2015 02:44:16 +0200 Subject: Added some useful postprocessing shaders Shaders come in two flavours: - shaders/gl330: OpenGL 3.3+ (Windows, Linux, OSX) - shaders/gles100: OpenGL ES 2.0 (Android, RPI, HTML5) --- shaders/gl330/fisheye.fs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 shaders/gl330/fisheye.fs (limited to 'shaders/gl330/fisheye.fs') diff --git a/shaders/gl330/fisheye.fs b/shaders/gl330/fisheye.fs new file mode 100644 index 00000000..d0e42cca --- /dev/null +++ b/shaders/gl330/fisheye.fs @@ -0,0 +1,40 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 tintColor; + +// NOTE: Add here your custom variables + +const float PI = 3.1415926535; + +void main() +{ + float aperture = 178.0f; + float apertureHalf = 0.5 * aperture * (PI / 180.0); + float maxFactor = sin(apertureHalf); + + vec2 uv = vec2(0); + vec2 xy = 2.0 * fragTexCoord.xy - 1.0; + float d = length(xy); + + if (d < (2.0 - maxFactor)) + { + d = length(xy * maxFactor); + float z = sqrt(1.0 - d * d); + float r = atan(d, z) / PI; + float phi = atan(xy.y, xy.x); + + uv.x = r * cos(phi) + 0.5; + uv.y = r * sin(phi) + 0.5; + } + else + { + uv = fragTexCoord.xy; + } + + fragColor = texture2D(texture0, uv); +} \ No newline at end of file -- cgit v1.2.3