diff --git a/lib/body.lua b/lib/body.lua index 1e74357..99c056d 100644 --- a/lib/body.lua +++ b/lib/body.lua @@ -25,7 +25,7 @@ function body:init(id, type, ...) self.tileX = 0 self.tileY = 0 self.zheight = 1 - + self.castsNoShadow = false self.visible = true self.is_on_screen = true diff --git a/lib/init.lua b/lib/init.lua index 103c236..3f4ab06 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -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) diff --git a/lib/light.lua b/lib/light.lua index 5c70ecb..85ee45d 100644 --- a/lib/light.lua +++ b/lib/light.lua @@ -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 diff --git a/lib/shaders/shadow.glsl b/lib/shaders/shadow.glsl index fe56749..c569bb8 100644 --- a/lib/shaders/shadow.glsl +++ b/lib/shaders/shadow.glsl @@ -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);