Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
This question shows lack of research. What have you tried already and what about it didn't work? – Byte56 Apr 20 '12 at 4:01
You should be able to achieve the effect just by altering your camera's projection matrix. – ktodisco Apr 20 '12 at 4:05
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/… – Rubber Mallet Apr 20 '12 at 4:37
1  
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. – Patrick Hughes Apr 20 '12 at 5:06
1  
Almost duplicate of gamedev.stackexchange.com/questions/20626/… – Sam Hocevar Apr 20 '12 at 11:27
show 1 more comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.