Guest User

Untitled

a guest
Oct 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #version 120
  2. varying vec2 vTexCoord;
  3.  
  4. uniform vec3 u_lightColor;
  5. uniform sampler2D u_texture;
  6.  
  7.  
  8. float drawShadow(){
  9. vec2 loc;
  10. vec2 norm = normalize(vTexCoord - vec2(.5,.5)); // Pointing from center to point
  11. vec4 smp;
  12.  
  13. float dst = 0.0;
  14.  
  15. // For now draw all casters
  16. if(texture2D(u_texture, vTexCoord - dst * norm).a > 0)
  17. return 1.0;
  18.  
  19. for(int i = 0; i < 256; i++){
  20. loc = vTexCoord - dst * norm;
  21.  
  22. if (length(loc-vec2(.5,.5)) < 1.0/256.0)
  23. break;
  24.  
  25. smp = texture2D(u_texture, loc);
  26.  
  27. if(smp.a > 0){
  28. return 0.0;
  29. }
  30.  
  31. dst += 1.0/256.0;
  32. }
  33.  
  34. return 1.0;
  35. }
  36.  
  37.  
  38. void main() {
  39. float dist = length(vec2(.5,.5) - vTexCoord.xy);
  40.  
  41. float shad = drawShadow();
  42.  
  43. float intensity = 1-dist*2.0;
  44.  
  45. gl_FragColor = vec4(u_lightColor, 1.0)*vec4(shad*vec3(intensity), shad);
  46. }
Add Comment
Please, Sign In to add comment