Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Based on Fabien Sanglard's Light Scattering shader
- // http://www.fabiensanglard.net/lightScattering/index.php
- // Edited (unsuccessfully) for Minecraft by Uhyve
- uniform sampler2D sampler0;
- uniform sampler2D sampler1;
- uniform sampler2D sampler2;
- uniform float displayWidth;
- uniform float displayHeight;
- uniform vec3 sunVector;
- const float exposure = 0.0034;
- const float decay = 1.0;
- const float density = 0.84;
- const float weight = 5.65;
- const int NUM_SAMPLES = 100;
- void main()
- {
- vec4 sun = gl_ProjectionMatrix * vec4(sunVector, 0.0);
- sun.xyz /= sun.w;
- vec2 lightPositionOnScreen = (1.0 + sun.xy)*vec2(displayWidth/2.0, displayHeight/2.0);
- vec2 deltaTextCoord = vec2( gl_TexCoord[0].st - lightPositionOnScreen.xy );
- vec2 textCoo = gl_TexCoord[0].st;
- deltaTextCoord *= 1.0 / float(NUM_SAMPLES) * density;
- float illuminationDecay = 1.0;
- vec4 crepRen = vec4(0.0, 0.0, 0.0, 1.0);
- for(int i=0; i < NUM_SAMPLES ; i++)
- {
- textCoo -= deltaTextCoord;
- vec4 sample = texture2D(sampler1, textCoo );
- sample *= illuminationDecay * weight;
- crepRen += sample;
- illuminationDecay *= decay;
- }
- crepRen*= exposure;
- crepRen.a = 1.0;
- vec4 sampler = texture2D(sampler0, gl_TexCoord[0].st);
- sampler.a = 1.0;
- gl_FragColor = clamp(sampler + crepRen, 0.0, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement