Advertisement
Uhyve

Minecraft Ray Scattering - 2nd Try

Apr 12th, 2011
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. // Based on Fabien Sanglard's Light Scattering shader
  2. // http://www.fabiensanglard.net/lightScattering/index.php
  3. // Edited (unsuccessfully) for Minecraft by Uhyve
  4.  
  5. uniform sampler2D sampler0;
  6. uniform sampler2D sampler1;
  7. uniform sampler2D sampler2;
  8.  
  9. uniform float displayWidth;
  10. uniform float displayHeight;
  11.  
  12. uniform vec3 sunVector;
  13.  
  14. const float exposure = 0.008;
  15. const float decay = 1.0;
  16. const float density = 0.95;
  17. const float weight = 4.65;
  18. const int NUM_SAMPLES = 100;
  19.  
  20. void main()
  21. {  
  22.     vec4 sun = gl_ProjectionMatrix * vec4(sunVector, 0.0);
  23.     vec2 lightPositionOnScreen = sun.xy;
  24.  
  25.     vec2 deltaTextCoord = vec2( gl_TexCoord[0].st - lightPositionOnScreen.xy );
  26.     vec2 textCoo = gl_TexCoord[0].st;
  27.     deltaTextCoord *= 1.0 / float(NUM_SAMPLES) * density;
  28.     float illuminationDecay = 1.0;
  29.     vec4 crepRen = vec4(0.0, 0.0, 0.0, 1.0);
  30.    
  31.     for(int i=0; i < NUM_SAMPLES ; i++)
  32.     {
  33.         textCoo -= deltaTextCoord;
  34.             vec4 sample = texture2D(sampler1, textCoo );
  35.         sample *= illuminationDecay * weight;
  36.         crepRen += sample;
  37.         illuminationDecay *= decay;
  38.     }
  39.  
  40.     crepRen-=(NUM_SAMPLES * 4.5);
  41.     crepRen*= exposure;
  42.     crepRen.a = 1.0;
  43.     crepRen = clamp(crepRen, 0.0, 1.0);
  44.  
  45.     vec4 sampler = texture2D(sampler0, gl_TexCoord[0].st);
  46.     sampler.a = 1.0;
  47.     gl_FragColor = clamp(sampler + crepRen, 0.0, 1.0);
  48.     //gl_FragColor = crepRen; // uncomment this line to only see the rays
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement