godray.frag 557 B

123456789101112131415161718192021222324252627282930313233
  1. uniform sampler2D tex;
  2. uniform vec2 sunpos;
  3. #define SAMPLES 12
  4. const float decaystep = 0.88;
  5. out vec4 FragColor;
  6. void main()
  7. {
  8. vec2 uv = 4. * gl_FragCoord.xy / screen;
  9. vec2 texc = uv;
  10. vec2 tosun = sunpos - texc;
  11. // if (dot(tosun, tosun) > 0.49) discard;
  12. vec2 dist = tosun * 1.0/(float(SAMPLES) * 1.12);
  13. vec3 col = texture(tex, texc).xyz;
  14. float decay = 1.0;
  15. for (int i = 0; i < SAMPLES; i++) {
  16. texc += dist;
  17. vec3 here = texture(tex, texc).xyz;
  18. here *= decay;
  19. col += here;
  20. decay *= decaystep;
  21. }
  22. FragColor = vec4(col, 1.0) * 0.8;
  23. }