Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 120
- varying vec2 vTexCoord;
- uniform vec3 u_lightColor;
- uniform sampler2D u_texture;
- float drawShadow(){
- vec2 loc;
- vec2 norm = normalize(vTexCoord - vec2(.5,.5)); // Pointing from center to point
- vec4 smp;
- float dst = 0.0;
- // For now draw all casters
- if(texture2D(u_texture, vTexCoord - dst * norm).a > 0)
- return 1.0;
- for(int i = 0; i < 256; i++){
- loc = vTexCoord - dst * norm;
- if (length(loc-vec2(.5,.5)) < 1.0/256.0)
- break;
- smp = texture2D(u_texture, loc);
- if(smp.a > 0){
- return 0.0;
- }
- dst += 1.0/256.0;
- }
- return 1.0;
- }
- void main() {
- float dist = length(vec2(.5,.5) - vTexCoord.xy);
- float shad = drawShadow();
- float intensity = 1-dist*2.0;
- gl_FragColor = vec4(u_lightColor, 1.0)*vec4(shad*vec3(intensity), shad);
- }
Add Comment
Please, Sign In to add comment