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

Article index

3 – Dome Distortion Shader

This shader is based on the following links:

Dome projection requires a fish eye projector lens, which necessarily distorts the image. A fisheye lens is needed for the projector to display across the nearly 180° of the dome. This necessarily introduces a distortion of the graphics that is being displayed through it. The trick is to then “pre-distort” the graphics in the opposite direction before sending it on to the projector.

The following GLSL program (which is not a post processing filter because it directly acts on the 3D object) shows the pre-distort effect:

Vertex shader:

#version 120
varying vec4 Vertex_UV;
uniform mat4 gxl3d_ModelViewMatrix;
uniform mat4 gxl3d_ProjectionMatrix;

uniform int do_distorsion;

const float PI = 3.1415926535;

void main()
{
  vec4 P = gxl3d_ModelViewMatrix * gl_Vertex;
  if (do_distorsion == 1)
  {  
    float rxy = length(P.xy);
    if (rxy > 0)
    {
      float phi = atan(rxy, -P.z);
      float lens_radius = phi * 180.0 / PI * 2.0;
      P.xy *= (lens_radius / rxy);
    }
  }
  gl_Position = gxl3d_ProjectionMatrix * P;
  Vertex_UV = gl_MultiTexCoord0 * 10.0;
}

Fragment shader:

#version 120
void main()
{
  gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}

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

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




Article index

2 thoughts on “(Shader Library) Fish Eye, Dome and Barrel Distortion GLSL Post Processing Filters”

Comments are closed.