volumetricLightScattering.fragment.fx 920 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifdef GL_ES
  2. precision highp float;
  3. #endif
  4. uniform sampler2D textureSampler;
  5. uniform sampler2D lightScatteringSampler;
  6. uniform float decay;
  7. uniform float exposure;
  8. uniform float weight;
  9. uniform float density;
  10. uniform vec2 meshPositionOnScreen;
  11. varying vec2 vUV;
  12. void main(void) {
  13. vec2 tc = vUV;
  14. vec2 deltaTexCoord = (tc - meshPositionOnScreen.xy);
  15. deltaTexCoord *= 1.0 / float(NUM_SAMPLES) * density;
  16. float illuminationDecay = 1.0;
  17. vec4 color = texture2D(lightScatteringSampler, tc) * 0.4;
  18. for(int i=0; i < NUM_SAMPLES; i++) {
  19. tc -= deltaTexCoord;
  20. vec4 sample = texture2D(lightScatteringSampler, tc) * 0.4;
  21. sample *= illuminationDecay * weight;
  22. color += sample;
  23. illuminationDecay *= decay;
  24. }
  25. vec4 realColor = texture2D(textureSampler, vUV);
  26. gl_FragColor = ((vec4((vec3(color.r, color.g, color.b) * exposure), 1)) + (realColor * (1.5 - 0.4)));
  27. }