(Shader Library) Fish Eye, Dome and Barrel Distortion GLSL Post Processing Filters



Article index


4 – Another Very Cool Fish Eye Shader

(GLSL Shader Library) Fish Eye Post Processing Filter, Dome Distortion, barrel distortion



I found this very cool GLSL fish eye shader in this demo:



GLSL Vertex shader:

#version 120
varying vec4 Vertex_UV;
varying vec4 posDevSpace;
uniform mat4 gxl3d_ModelViewProjectionMatrix;
void main()
{
  gl_Position = gxl3d_ModelViewProjectionMatrix * gl_Vertex;
  Vertex_UV = gl_MultiTexCoord0;
  posDevSpace = gl_Position / gl_Position.z;
  posDevSpace = vec4(0.5, 0.5, 1.0, 1.0) + (posDevSpace + vec4(1.0, 1.0, 0.0, 0.0));
}



GLSL Fragment shader:

#version 120
uniform sampler2D tex0;
varying vec4 Vertex_UV;
const float PI = 3.1415926535;

varying vec4 posDevSpace;
uniform float lensradius; // 3
uniform float signcurvature; // 10

#define EPSILON 0.000011

void main(void)
{
    float curvature = abs(signcurvature);
    float extent = lensradius;
    float optics = extent / log2(curvature * extent + 1.0) / 1.4427;
    vec4 PP = posDevSpace - vec4 (1.5, 1.5, 0.0, 1.0);
    float P0 = PP[0];
    float P1 = PP[1];
    float radius = sqrt(P0 * P0 + P1 * P1);

    float cosangle = P0 / radius;
    float sinangle = P1 / radius;

    float rad1, rad2, newradius;
    rad1 = (exp2((radius / optics) * 1.4427) - 1.0) / curvature;
    rad2 = optics * log2(1.0 + curvature * radius) / 1.4427;
    newradius = signcurvature > 0.0 ? rad1 : rad2;

    vec4 FE = vec4 (0.0, 0.0, 0.0, 1.0);
    FE[0] = newradius * cosangle + 0.5;
    FE[1] = newradius * sinangle + 0.5;
    FE = radius <= extent ? FE : posDevSpace;
    FE = curvature < EPSILON ? posDevSpace : FE;

    gl_FragColor = texture2D(tex0, vec2(FE));
}

(GLSL Shader Library) Fish Eye Post Processing Filter, Dome Distortion, barrel distortion




Article index

Pages: 1 2 3 4 5 6





[ Subscribe to Geeks3D latest news by email ]

Geeks3D.com

↑ Grab this Headline Animator