2d fisheye shader, works with this code:
+ Code Snippet// Project: Image FOV
// Created: 2015-11-03
// set window properties
SetWindowTitle( "Image FOV" )
SetWindowSize( 1280, 720, 0 )
// set display properties
SetVirtualResolution( 1920,1080 )
SetOrientationAllowed( 0, 0, 1, 0 )
fovshader=LoadspriteShader("fish.ps" )
img=LoadImage("img.png")
spr=CreateSprite(img)
spr2=CreateSprite(img)
SetSpritePosition(spr2,540,0)
SetSpriteShader(spr,fovshader)
do
// setShaderConstantByName(fovshader, "time", timer(), 0, 0, 0)
Print( ScreenFPS() )
Sync()
loop
fisheye.ps
+ Code Snippetuniform sampler2D tex0;
varying vec4 uvVarying;
const float PI = 3.1415926535;
void main()
{
float aperture = 178.0;
float apertureHalf = 0.5 * aperture * (PI / 180.0);
float maxFactor = sin(apertureHalf);
vec2 uv;
vec2 xy = 2.0 * uvVarying.xy - 1.0;
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 = uvVarying.xy;
}
vec4 c = texture2D(tex0, uv);
gl_FragColor = c;
}