mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
fixed the light drawing with translation and scaling
This commit is contained in:
parent
82061d93d0
commit
b768c5479a
@ -131,9 +131,11 @@ end
|
|||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
love.window.setTitle("Light vs. Shadow Engine (FPS:" .. love.timer.getFPS() .. ")")
|
love.window.setTitle("Light vs. Shadow Engine (FPS:" .. love.timer.getFPS() .. ")")
|
||||||
mouseLight:setPosition(love.mouse.getX(), love.mouse.getY(), 16.0 + (math.sin(lightDirection) + 1.0) * 64.0)
|
|
||||||
mx = love.mouse.getX()
|
mx, my = (love.mouse.getX() - offsetX)/scale, (love.mouse.getY() - offsetY)/scale
|
||||||
my = love.mouse.getY()
|
|
||||||
|
mouseLight:setPosition(mx, my, 16.0 + (math.sin(lightDirection) + 1.0) * 64.0)
|
||||||
|
|
||||||
lightDirection = lightDirection + dt
|
lightDirection = lightDirection + dt
|
||||||
colorAberration = math.max(0.0, colorAberration - dt * 10.0)
|
colorAberration = math.max(0.0, colorAberration - dt * 10.0)
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ function love.load()
|
|||||||
y = 0
|
y = 0
|
||||||
scale = 1
|
scale = 1
|
||||||
-- load images
|
-- load images
|
||||||
image = love.graphics.newImage("gfx/crossColor.jpg")
|
image = love.graphics.newImage("gfx/rock.png")
|
||||||
image_normal = love.graphics.newImage("gfx/crossnrm.jpg")
|
image_normal = love.graphics.newImage("gfx/rock_n.png")
|
||||||
|
|
||||||
-- create light world
|
-- create light world
|
||||||
lightWorld = LightWorld({
|
lightWorld = LightWorld({
|
||||||
@ -21,6 +21,7 @@ function love.load()
|
|||||||
-- create light
|
-- create light
|
||||||
lightMouse = lightWorld:newLight(0, 0, 160, 160, 160, 300)
|
lightMouse = lightWorld:newLight(0, 0, 160, 160, 160, 300)
|
||||||
lightMouse:setGlowStrength(0.3)
|
lightMouse:setGlowStrength(0.3)
|
||||||
|
--lightMouse.normalInvert = true
|
||||||
|
|
||||||
-- create shadow bodys
|
-- create shadow bodys
|
||||||
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
|
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
|
||||||
|
@ -110,7 +110,7 @@ function love.update(dt)
|
|||||||
lightWorld.post_shader:removeEffect("chromatic_aberration")
|
lightWorld.post_shader:removeEffect("chromatic_aberration")
|
||||||
end
|
end
|
||||||
|
|
||||||
lightMouse:setPosition(love.mouse.getX()/scale, love.mouse.getY()/scale)
|
lightMouse:setPosition((love.mouse.getX() - x)/scale, (love.mouse.getY() - y)/scale)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
|
BIN
gfx/rock.png
Normal file
BIN
gfx/rock.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 127 KiB |
BIN
gfx/rock_n.png
Normal file
BIN
gfx/rock_n.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 116 KiB |
@ -617,10 +617,12 @@ function body:calculateCircleShadow(light)
|
|||||||
curShadowGeometry[6] = y3 - (light.y - y3) * shadowLength
|
curShadowGeometry[6] = y3 - (light.y - y3) * shadowLength
|
||||||
curShadowGeometry[7] = x2 - (light.x - x2) * shadowLength
|
curShadowGeometry[7] = x2 - (light.x - x2) * shadowLength
|
||||||
curShadowGeometry[8] = y2 - (light.y - y2) * shadowLength
|
curShadowGeometry[8] = y2 - (light.y - y2) * shadowLength
|
||||||
curShadowGeometry.alpha = self.alpha
|
|
||||||
curShadowGeometry.red = self.red
|
curShadowGeometry.red = self.red
|
||||||
curShadowGeometry.green = self.green
|
curShadowGeometry.green = self.green
|
||||||
curShadowGeometry.blue = self.blue
|
curShadowGeometry.blue = self.blue
|
||||||
|
curShadowGeometry.alpha = self.alpha
|
||||||
|
|
||||||
return curShadowGeometry
|
return curShadowGeometry
|
||||||
else
|
else
|
||||||
return nil
|
return nil
|
||||||
|
@ -32,6 +32,8 @@ function light:refresh(w, h)
|
|||||||
|
|
||||||
self.shadow = love.graphics.newCanvas(w, h)
|
self.shadow = love.graphics.newCanvas(w, h)
|
||||||
self.shine = love.graphics.newCanvas(w, h)
|
self.shine = love.graphics.newCanvas(w, h)
|
||||||
|
self.normalInvertShader:send('screenResolution', {w, h})
|
||||||
|
self.normalShader:send('screenResolution', {w, h})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set position
|
-- set position
|
||||||
@ -126,7 +128,8 @@ function light:drawShadow(l,t,w,h,s,bodies, canvas)
|
|||||||
-- draw shadow
|
-- draw shadow
|
||||||
self.shadow:clear()
|
self.shadow:clear()
|
||||||
util.drawto(self.shadow, l, t, s, function()
|
util.drawto(self.shadow, l, t, s, function()
|
||||||
self.shader:send("lightPosition", {self.x*s, (h/s - self.y)*s, self.z})
|
|
||||||
|
self.shader:send("lightPosition", {(self.x + l/s) * s, (h/s - (self.y + t/s)) * s, self.z})
|
||||||
self.shader:send("lightRange", self.range*s)
|
self.shader:send("lightRange", self.range*s)
|
||||||
self.shader:send("lightColor", {self.red / 255.0, self.green / 255.0, self.blue / 255.0})
|
self.shader:send("lightColor", {self.red / 255.0, self.green / 255.0, self.blue / 255.0})
|
||||||
self.shader:send("lightSmooth", self.smooth)
|
self.shader:send("lightSmooth", self.smooth)
|
||||||
@ -182,16 +185,14 @@ end
|
|||||||
function light:drawPixelShadow(l,t,w,h, normalMap, canvas)
|
function light:drawPixelShadow(l,t,w,h, normalMap, canvas)
|
||||||
if self.visible then
|
if self.visible then
|
||||||
if self.normalInvert then
|
if self.normalInvert then
|
||||||
self.normalInvertShader:send('screenResolution', {w, h})
|
|
||||||
self.normalInvertShader:send('lightColor', {self.red / 255.0, self.green / 255.0, self.blue / 255.0})
|
self.normalInvertShader:send('lightColor', {self.red / 255.0, self.green / 255.0, self.blue / 255.0})
|
||||||
self.normalInvertShader:send('lightPosition',{self.x, lh - self.y, self.z / 255.0})
|
self.normalInvertShader:send('lightPosition',{self.x, h - self.y, self.z / 255.0})
|
||||||
self.normalInvertShader:send('lightRange',{self.range})
|
self.normalInvertShader:send('lightRange',{self.range})
|
||||||
self.normalInvertShader:send("lightSmooth", self.smooth)
|
self.normalInvertShader:send("lightSmooth", self.smooth)
|
||||||
self.normalInvertShader:send("lightAngle", math.pi - self.angle / 2.0)
|
self.normalInvertShader:send("lightAngle", math.pi - self.angle / 2.0)
|
||||||
self.normalInvertShader:send("lightDirection", self.direction)
|
self.normalInvertShader:send("lightDirection", self.direction)
|
||||||
util.drawCanvasToCanvas(normalMap, canvas, {shader = self.normalInvertShader})
|
util.drawCanvasToCanvas(normalMap, canvas, {shader = self.normalInvertShader})
|
||||||
else
|
else
|
||||||
self.normalShader:send('screenResolution', {w, h})
|
|
||||||
self.normalShader:send('lightColor', {self.red / 255.0, self.green / 255.0, self.blue / 255.0})
|
self.normalShader:send('lightColor', {self.red / 255.0, self.green / 255.0, self.blue / 255.0})
|
||||||
self.normalShader:send('lightPosition',{self.x, h - self.y, self.z / 255.0})
|
self.normalShader:send('lightPosition',{self.x, h - self.y, self.z / 255.0})
|
||||||
self.normalShader:send('lightRange',{self.range})
|
self.normalShader:send('lightRange',{self.range})
|
||||||
|
Loading…
Reference in New Issue
Block a user