2
\$\begingroup\$

I would like to render my scene with a wide FOV and then apply a fisheye distortion via fragment shader. How would this shader best be implemented?

Update

I try to reproduce a fisheye effect similar to what can be seen through a lense like this one. My first try was to port the fragment shader explained in How do I create a wide-angle / fisheye lens with HLSL? because it seemed to be a good starting point:

#version 120

uniform sampler2D src;

float fov = 2.09;

void main(void)
{
    float z = sqrt(1 - gl_TexCoord[0].s * gl_TexCoord[0].s - gl_TexCoord[0].t * gl_TexCoord[0].t);
    float a = 1.0 / (z * tan(fov * 0.5));
    gl_FragColor = texture2D(src, (gl_TexCoord[0].st - 0.5) * 2.0 * a);
}

unfortunately, the result looks like this: enter image description here

\$\endgroup\$
  • 1
    \$\begingroup\$ This question shows lack of research. What have you tried already and what about it didn't work? \$\endgroup\$ – MichaelHouse Apr 20 '12 at 4:01
  • \$\begingroup\$ You should be able to achieve the effect just by altering your camera's projection matrix. \$\endgroup\$ – kevintodisco Apr 20 '12 at 4:05
  • \$\begingroup\$ It will probably have to be done post. Look at objsAsDisplacement. Maybe try porting it to glsl and share with the community? developer.download.nvidia.com/shaderlibrary/webpages/… \$\endgroup\$ – Chuck D Apr 20 '12 at 4:37
  • 1
    \$\begingroup\$ Define "fisheye," there are various photographic meanings of that. You crank your FOV far enough and you don't need to distort in the fragment shader. Best results if you build your geometry all up close and personal, not spread out like a real 3D scene. \$\endgroup\$ – Patrick Hughes Apr 20 '12 at 5:06
  • \$\begingroup\$ I am sorry for the previous briefness and missing details and have updated my question with some example code and a rendering \$\endgroup\$ – Rodja Apr 21 '12 at 4:58