#version 100
#define FLR_MAX 7
precision mediump float;varying vec4 col;varying vec2 uv;uniform sampler2D tex0,tex1,
tex2,tex3,tex4;uniform float offset;uniform vec4 gamma, luminosity, contrast;uniform 
vec2 camView;uniform float flareAmt;float spherize = 0.2;float zoom = 0.87;mat4 flr_z
=mat4(vec4(1.1,3.,7.,-9.),vec4(-5.,-2.5,-1.5,  1.),vec4(.8,.5,.6,.4),vec4(.3,.8,.7,1.
));vec4 blur(sampler2D tex, vec2 uv, float rad, int sample){vec4 col=vec4(0.,0.,0.,0.
);for(int s=0;s<sample;s++){float f = 6.2832*float(s)/float(sample);vec4 c=texture2D
(tex,uv+vec2(sin(f),cos(f))*rad);col+= c+(c*c*c)*.25;}return col/float(sample);}vec4
leak(vec4 c){vec4 lum = (texture2D(tex0,vec2(.25,.25))+texture2D(tex0,vec2(-.25,.25))
+texture2D(tex0,vec2(.25,-.25))+texture2D(tex0,vec2(-.25,-.25)))/4.;vec2 luv = uv - 
vec2(.5, .5) ;luv = (luv*abs(luv)*abs(luv)) + vec2(.5,.5);c += texture2D(tex2,luv+ 
camView / 3.0)*length(lum.rgb);return c;}vec4 dirt(vec4 c){return c + texture2D(tex3,
uv)*pow(texture2D(tex4,uv),vec4(3.));}vec4 grain(vec4 c){vec2 gUV = uv*vec2(16.0/9.0,
1)+vec2(0,offset);c+= (texture2D(tex1,gUV)-vec4(.5,.5,.5,0))*.25;c = clamp(c,0.,1.);
return c;}vec4 flare(vec4 c){vec2 luv = uv - vec2(.5, .5) ;vec4 chn=vec4(0.);for(int
ch=0;ch<3;ch++){for(int i=0; i<FLR_MAX;i++){int y=i/4;int x=i-y*4;vec2 fuv=luv*flr_z
[y][x]*(1.-.05*float(ch));vec4 flc=pow(texture2D(tex4,fuv +vec2(.5,.5)),vec4(5.));
float mask=clamp(.5-length(fuv*vec2(1.,.6)),0.,.2)/.2;mask = pow(mask,.75)*flr_z[y+2]
[x]*flareAmt;if(ch==0)c.r+=flc.r*mask*.8;if(ch==1)c.g+=flc.g*mask*.6;if(ch==2)c.b+=
flc.b*mask*.5;}}return c;}void main(){vec3 normal;float dst= length(uv-vec2(0.5,0.5));
vec2 uv2 = (uv-vec2(0.5,0.5))*(zoom+dst*spherize) +vec2(0.5,0.5);uv2.y += (offset-0.5)
*0.002;vec4 orig = blur(tex0,uv2,dst*dst*0.015,6);orig*=orig;orig*=1.41-dst*2.0;orig=
flare(orig);orig = leak(orig);orig = dirt(orig);orig = grain(orig);orig = pow(orig,
gamma);orig*= contrast;orig+= luminosity;orig = sqrt(orig);gl_FragColor = orig;}