mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
just some light screen presence checking
This commit is contained in:
parent
eeb0cc7ca9
commit
5208475e18
@ -25,7 +25,7 @@ function body:init(id, type, ...)
|
|||||||
self.tileX = 0
|
self.tileX = 0
|
||||||
self.tileY = 0
|
self.tileY = 0
|
||||||
self.zheight = 1
|
self.zheight = 1
|
||||||
|
|
||||||
self.castsNoShadow = false
|
self.castsNoShadow = false
|
||||||
self.visible = true
|
self.visible = true
|
||||||
self.is_on_screen = true
|
self.is_on_screen = true
|
||||||
|
@ -89,6 +89,10 @@ function light_world:update(dt)
|
|||||||
self.bodies[i]:update(dt)
|
self.bodies[i]:update(dt)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
function light_world:draw(cb)
|
function light_world:draw(cb)
|
||||||
@ -129,7 +133,7 @@ function light_world:drawNormalShading(l,t,w,h,s)
|
|||||||
self.normal2:clear()
|
self.normal2:clear()
|
||||||
for i = 1, #self.lights do
|
for i = 1, #self.lights do
|
||||||
local light = self.lights[i]
|
local light = self.lights[i]
|
||||||
if light:inRange(l,t,w,h,s) then
|
if light:isVisible() then
|
||||||
-- create shadow map for this light
|
-- create shadow map for this light
|
||||||
self.shadowMap:clear()
|
self.shadowMap:clear()
|
||||||
util.drawto(self.shadowMap, l, t, s, function()
|
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('shadowMap', self.shadowMap)
|
||||||
self.shadowShader:send('lightColor', {light.red / 255.0, light.green / 255.0, light.blue / 255.0})
|
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("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("lightSmooth", light.smooth)
|
||||||
self.shadowShader:send("lightGlow", {1.0 - light.glowSize, light.glowStrength})
|
self.shadowShader:send("lightGlow", {1.0 - light.glowSize, light.glowStrength})
|
||||||
self.shadowShader:send("invert_normal", self.normalInvert)
|
self.shadowShader:send("invert_normal", self.normalInvert)
|
||||||
|
@ -17,6 +17,7 @@ function light:init(x, y, r, g, b, range)
|
|||||||
self.glowSize = 0.1
|
self.glowSize = 0.1
|
||||||
self.glowStrength = 0.0
|
self.glowStrength = 0.0
|
||||||
self.visible = true
|
self.visible = true
|
||||||
|
self.is_on_screen = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set position
|
-- set position
|
||||||
@ -112,4 +113,8 @@ function light:setVisible(visible)
|
|||||||
self.visible = visible
|
self.visible = visible
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function light:isVisible()
|
||||||
|
return self.visible and self.is_on_screen
|
||||||
|
end
|
||||||
|
|
||||||
return light
|
return light
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
Copyright (c) 2014 Tim Anema
|
Copyright (c) 2014 Tim Anema
|
||||||
light shadow, shine and normal shader all in one
|
light shadow, shine and normal shader all in one
|
||||||
*/
|
*/
|
||||||
extern Image shadowMap; //a canvas containing shadow data only
|
extern Image shadowMap; //a canvas containing shadow data only
|
||||||
extern vec3 lightPosition; //the light position on the screen(not global)
|
extern vec3 lightPosition; //the light position on the screen(not global)
|
||||||
extern vec3 lightColor; //the rgb color of the light
|
extern vec3 lightColor; //the rgb color of the light
|
||||||
extern float lightRange; //the range of the light
|
extern float lightRange; //the range of the light
|
||||||
extern float lightSmooth; //smoothing of the lights attenuation
|
extern float lightSmooth; //smoothing of the lights attenuation
|
||||||
extern vec2 lightGlow = vec2(0.5, 0.5); //how brightly the light bulb part glows
|
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 bool invert_normal = false; //if the light should invert normals
|
||||||
|
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user