Jump to content

Recommended Posts

Posted

Here is a classic fisheye shader, you cn play with the zoom value and aperture values

 

#version 400
uniform sampler2D texture1;
uniform bool isbackbuffer;
uniform vec2 buffersize;
uniform float currenttime;
out vec4 fragData0;
const float PI = 3.1415926535;

void main(void)
{
 float zoom=2.0;
 float aperture = 178.0;
 float apertureHalf = 0.5 * aperture * (PI / 180.0);
 float maxFactor = sin(apertureHalf);
 vec2 tcoord = vec2(gl_FragCoord.xy/buffersize);
 if (isbackbuffer) tcoord.y = 1.0 - tcoord.y; 

 vec2 uv;
 vec2 xy = zoom * tcoord.xy - zoom*.5;
 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 = tcoord.xy;
 }
 vec4 c = texture(texture1, uv);
 fragData0 = c;
}

  • Upvote 5

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...