colored shadows now work as expected with attenuated brightness and constant brightness not matter how many lights are present

This commit is contained in:
Tim Anema 2014-11-30 14:35:18 -05:00
parent 9c81c71f89
commit 9e59f9ffee
2 changed files with 20 additions and 30 deletions

View File

@ -108,17 +108,6 @@ function light_world:draw(l,t,s)
self.post_shader:drawWith(self.render_buffer, l, t, s) self.post_shader:drawWith(self.render_buffer, l, t, s)
end end
function light_world:drawBlur(blendmode, blur, canvas, canvas2, l, t, w, h, s)
if blur <= 0 then
return
end
canvas2:clear()
self.blurv:send("steps", blur)
self.blurh:send("steps", blur)
util.drawCanvasToCanvas(canvas, canvas2, {shader = self.blurv, blendmode = blendmode})
util.drawCanvasToCanvas(canvas2, canvas, {shader = self.blurh, blendmode = blendmode})
end
-- draw normal shading -- draw normal shading
function light_world:drawNormalShading(l,t,w,h,s) function light_world:drawNormalShading(l,t,w,h,s)
if not self.isShadows then if not self.isShadows then
@ -187,7 +176,11 @@ function light_world:drawGlow(l,t,w,h,s)
end end
end) end)
light_world:drawBlur("alpha", self.glowBlur, self.glowMap, self.glowMap2, l, t, w, h, s) self.glowMap2:clear()
self.blurv:send("steps", self.glowBlur)
self.blurh:send("steps", self.glowBlur)
util.drawCanvasToCanvas(self.glowMap, self.glowMap2, {shader = self.blurv, blendmode = "alpha"})
util.drawCanvasToCanvas(self.glowMap2, self.glowMap, {shader = self.blurh, blendmode = "alpha"})
util.drawCanvasToCanvas(self.glowMap, self.render_buffer, {blendmode = "additive"}) util.drawCanvasToCanvas(self.glowMap, self.render_buffer, {blendmode = "additive"})
end end
-- draw refraction -- draw refraction

View File

@ -11,22 +11,21 @@ extern float lightDirection;
extern float lightAngle; extern float lightAngle;
extern bool invert_normal; extern bool invert_normal;
bool not_in_slice(vec2 pixel_coords){
float angle = atan(lightPosition.x - pixel_coords.x, pixel_coords.y - lightPosition.y) + PI;
bool pastRightSide = angle < mod(lightDirection + lightAngle, PI * 2);
bool pastLeftSide = angle > mod(lightDirection - lightAngle, PI * 2);
bool lightUp = lightDirection - lightAngle > 0 && lightDirection + lightAngle < PI * 2;
return (lightUp && (pastRightSide && pastLeftSide)) || (!lightUp && (pastRightSide || pastLeftSide));
}
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) { vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
vec4 pixelColor = Texel(texture, texture_coords); vec4 pixelColor = Texel(texture, texture_coords);
vec4 shadowColor = Texel(shadowMap, texture_coords); vec4 shadowColor = Texel(shadowMap, texture_coords);
//if the light is a slice and the pixel is not inside //if the light is a slice and the pixel is not inside
if(lightAngle > 0.0) { if(lightAngle > 0.0 && not_in_slice(pixel_coords)) {
float angle2 = atan(lightPosition.x - pixel_coords.x, pixel_coords.y - lightPosition.y) + PI; return vec4(0.0, 0.0, 0.0, 1.0);
if(lightDirection - lightAngle > 0 && lightDirection + lightAngle < PI * 2) {
if(angle2 < mod(lightDirection + lightAngle, PI * 2) && angle2 > mod(lightDirection - lightAngle, PI * 2)) {
return vec4(0.0, 0.0, 0.0, 1.0);
}
} else {
if(angle2 < mod(lightDirection + lightAngle, PI * 2) || angle2 > mod(lightDirection - lightAngle, PI * 2)) {
return vec4(0.0, 0.0, 0.0, 1.0);
}
}
} }
vec3 normal; vec3 normal;
@ -44,18 +43,16 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
if(dist < lightRange) { if(dist < lightRange) {
float att = clamp((1.0 - dist / lightRange) / lightSmooth, 0.0, 1.0); float att = clamp((1.0 - dist / lightRange) / lightSmooth, 0.0, 1.0);
if(pixelColor.a == 0.0) { if(pixelColor.a == 0.0) {
vec4 val = pixelColor; vec4 pixel = vec4(0.0, 0.0, 0.0, 1.0);
val.a = 1.0;
if (lightGlow.x < 1.0 && lightGlow.y > 0.0) { if (lightGlow.x < 1.0 && lightGlow.y > 0.0) {
val.rgb = clamp(lightColor * pow(att, lightSmooth) + pow(smoothstep(lightGlow.x, 1.0, att), lightSmooth) * lightGlow.y, 0.0, 1.0); pixel.rgb = clamp(lightColor * pow(att, lightSmooth) + pow(smoothstep(lightGlow.x, 1.0, att), lightSmooth) * lightGlow.y, 0.0, 1.0);
} else { } else {
val.rgb = lightColor * pow(att, lightSmooth); pixel.rgb = lightColor * pow(att, lightSmooth);
} }
if(shadowColor.a > 0.0) { if(shadowColor.a > 0.0) {
shadowColor.a = 1.0 - shadowColor.a; pixel.rgb = pixel.rgb * shadowColor.rgb;
val = val * shadowColor;
} }
return val; return pixel;
} else { } else {
vec3 dir = vec3((lightPosition.xy - pixel_coords.xy) / screenResolution.xy, lightPosition.z); vec3 dir = vec3((lightPosition.xy - pixel_coords.xy) / screenResolution.xy, lightPosition.z);
dir.x *= screenResolution.x / screenResolution.y; dir.x *= screenResolution.x / screenResolution.y;