light_world.lua/shader/pixel_self_shadow.glsl
2014-03-06 16:56:25 +01:00

24 lines
784 B
GLSL

extern vec3 lightPosition;
extern float lightRange;
extern vec3 lightColor;
extern vec3 lightAmbient;
extern float lightSmooth;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
vec3 lightDirection = vec3(pixel_coords.xy, 0) - lightPosition.xyz;
float distance = length(lightDirection);
vec4 pixel = Texel(texture, texture_coords);
vec3 normal = vec3(pixel.x, 1 - pixel.y, pixel.z);
normal = mix(vec3(-1), vec3(1), normal);
float att = 1 - distance / lightRange;
if(pixel.a > 0.0 && distance < lightRange) {
return vec4(vec3(clamp((1 - dot(normal, lightDirection)) * pow(att, lightSmooth * 4.0), 0.0, 1.0)) * lightColor + lightAmbient, 1.0);
} else if(pixel.a == 0.0) {
return vec4(0.0);
} else {
return vec4(0.0, 0.0, 0.0, 1.0);
}
}