water fog material prop; ragdoll float only on drowned
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / blit.fs
index b98d5e8832d6f124a5404209fd801296170b6b87..634e84fa2908e992bb701d7dbb90135a66bae201 100644 (file)
@@ -3,7 +3,39 @@ uniform sampler2D uTexMain;
 
 in vec2 aUv;
 
+float kPi = 3.14159265358979;
+
+vec2 fisheye_distort(vec2 xy)
+{
+   float aperture = 1350.0;
+   float apertureHalf = 0.5 * aperture * (kPi / 180.0);
+   float maxFactor = sin(apertureHalf);
+
+   vec2 uv;
+   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) / kPi;
+      float phi = atan(xy.y, xy.x);
+
+      uv.x = r * cos(phi) + 0.5;
+      uv.y = r * sin(phi) + 0.5;
+   }
+   else
+   {
+      uv = 0.5*xy + 0.5;
+   }
+   
+   return uv;
+}
+
+
 void main()
 {
+   vec2 vwarp = 2.0*aUv - 1.0;
+   vwarp = fisheye_distort( vwarp );
+
    FragColor = texture( uTexMain, aUv );
 }