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.008;
- const float decay = 1.0;
- const float density = 0.95;
- const float weight = 4.65;
- const int NUM_SAMPLES = 100;
- void main()
- {
- vec4 sun = gl_ProjectionMatrix * vec4(sunVector, 0.0);
- vec2 lightPositionOnScreen = sun.xy;
- 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-=(NUM_SAMPLES * 4.5);
- crepRen*= exposure;
- crepRen.a = 1.0;
- crepRen = clamp(crepRen, 0.0, 1.0);
- vec4 sampler = texture2D(sampler0, gl_TexCoord[0].st);
- sampler.a = 1.0;
- gl_FragColor = clamp(sampler + crepRen, 0.0, 1.0);
- //gl_FragColor = crepRen; // uncomment this line to only see the rays
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement