just some light screen presence checking

This commit is contained in:
Tim Anema 2014-12-14 12:47:20 -05:00
parent eeb0cc7ca9
commit 5208475e18
4 changed files with 19 additions and 10 deletions

View File

@ -89,6 +89,10 @@ function light_world:update(dt)
self.bodies[i]:update(dt)
end
end
for i = 1, #self.lights do
self.lights[i].is_on_screen = self.lights[i]:inRange(self.l,self.t,self.w,self.h,self.s)
end
end
function light_world:draw(cb)
@ -129,7 +133,7 @@ function light_world:drawNormalShading(l,t,w,h,s)
self.normal2:clear()
for i = 1, #self.lights do
local light = self.lights[i]
if light:inRange(l,t,w,h,s) then
if light:isVisible() then
-- create shadow map for this light
self.shadowMap:clear()
util.drawto(self.shadowMap, l, t, s, function()
@ -146,7 +150,7 @@ function light_world:drawNormalShading(l,t,w,h,s)
self.shadowShader:send('shadowMap', self.shadowMap)
self.shadowShader:send('lightColor', {light.red / 255.0, light.green / 255.0, light.blue / 255.0})
self.shadowShader:send("lightPosition", {(light.x + l/s) * s, (h/s - (light.y + t/s)) * s, (light.z * 10) / 255.0})
self.shadowShader:send('lightRange',{light.range * s})
self.shadowShader:send('lightRange', light.range * s)
self.shadowShader:send("lightSmooth", light.smooth)
self.shadowShader:send("lightGlow", {1.0 - light.glowSize, light.glowStrength})
self.shadowShader:send("invert_normal", self.normalInvert)

View File

@ -17,6 +17,7 @@ function light:init(x, y, r, g, b, range)
self.glowSize = 0.1
self.glowStrength = 0.0
self.visible = true
self.is_on_screen = true
end
-- set position
@ -112,4 +113,8 @@ function light:setVisible(visible)
self.visible = visible
end
function light:isVisible()
return self.visible and self.is_on_screen
end
return light

View File

@ -2,13 +2,13 @@
Copyright (c) 2014 Tim Anema
light shadow, shine and normal shader all in one
*/
extern Image shadowMap; //a canvas containing shadow data only
extern vec3 lightPosition; //the light position on the screen(not global)
extern vec3 lightColor; //the rgb color of the light
extern float lightRange; //the range of the light
extern float lightSmooth; //smoothing of the lights attenuation
extern vec2 lightGlow = vec2(0.5, 0.5); //how brightly the light bulb part glows
extern bool invert_normal; //if the light should invert normals
extern Image shadowMap; //a canvas containing shadow data only
extern vec3 lightPosition; //the light position on the screen(not global)
extern vec3 lightColor; //the rgb color of the light
extern float lightRange; //the range of the light
extern float lightSmooth; //smoothing of the lights attenuation
extern vec2 lightGlow = vec2(0.5, 0.5); //how brightly the light bulb part glows
extern bool invert_normal = false; //if the light should invert normals
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
vec4 pixelColor = Texel(texture, texture_coords);