Advertisement
Uhyve

Minecraft Ray Scattering

Apr 12th, 2011
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 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.0034;
  15. const float decay = 1.0;
  16. const float density = 0.84;
  17. const float weight = 5.65;
  18. const int NUM_SAMPLES = 100;
  19.  
  20. void main()
  21. {  
  22.     vec4 sun = gl_ProjectionMatrix * vec4(sunVector, 0.0);
  23.     sun.xyz /= sun.w;
  24.     vec2 lightPositionOnScreen = (1.0 + sun.xy)*vec2(displayWidth/2.0, displayHeight/2.0);
  25.  
  26.     vec2 deltaTextCoord = vec2( gl_TexCoord[0].st - lightPositionOnScreen.xy );
  27.     vec2 textCoo = gl_TexCoord[0].st;
  28.     deltaTextCoord *= 1.0 / float(NUM_SAMPLES) * density;
  29.     float illuminationDecay = 1.0;
  30.     vec4 crepRen = vec4(0.0, 0.0, 0.0, 1.0);
  31.    
  32.     for(int i=0; i < NUM_SAMPLES ; i++)
  33.     {
  34.         textCoo -= deltaTextCoord;
  35.             vec4 sample = texture2D(sampler1, textCoo );
  36.         sample *= illuminationDecay * weight;
  37.         crepRen += sample;
  38.         illuminationDecay *= decay;
  39.     }
  40.  
  41.     crepRen*= exposure;
  42.     crepRen.a = 1.0;
  43.  
  44.     vec4 sampler = texture2D(sampler0, gl_TexCoord[0].st);
  45.     sampler.a = 1.0;
  46.     gl_FragColor = clamp(sampler + crepRen, 0.0, 1.0);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement