fixed the light drawing with translation and scaling

This commit is contained in:
Tim Anema 2014-10-28 20:47:46 -04:00
parent 82061d93d0
commit b768c5479a
7 changed files with 17 additions and 11 deletions

View File

@ -131,9 +131,11 @@ end
function love.update(dt)
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()
my = love.mouse.getY()
mx, my = (love.mouse.getX() - offsetX)/scale, (love.mouse.getY() - offsetY)/scale
mouseLight:setPosition(mx, my, 16.0 + (math.sin(lightDirection) + 1.0) * 64.0)
lightDirection = lightDirection + dt
colorAberration = math.max(0.0, colorAberration - dt * 10.0)

View File

@ -6,8 +6,8 @@ function love.load()
y = 0
scale = 1
-- load images
image = love.graphics.newImage("gfx/crossColor.jpg")
image_normal = love.graphics.newImage("gfx/crossnrm.jpg")
image = love.graphics.newImage("gfx/rock.png")
image_normal = love.graphics.newImage("gfx/rock_n.png")
-- create light world
lightWorld = LightWorld({
@ -21,6 +21,7 @@ function love.load()
-- create light
lightMouse = lightWorld:newLight(0, 0, 160, 160, 160, 300)
lightMouse:setGlowStrength(0.3)
--lightMouse.normalInvert = true
-- create shadow bodys
local w, h = love.graphics.getWidth(), love.graphics.getHeight()

View File

@ -110,7 +110,7 @@ function love.update(dt)
lightWorld.post_shader:removeEffect("chromatic_aberration")
end
lightMouse:setPosition(love.mouse.getX()/scale, love.mouse.getY()/scale)
lightMouse:setPosition((love.mouse.getX() - x)/scale, (love.mouse.getY() - y)/scale)
end
function love.draw()

BIN
gfx/rock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

BIN
gfx/rock_n.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

View File

@ -617,10 +617,12 @@ function body:calculateCircleShadow(light)
curShadowGeometry[6] = y3 - (light.y - y3) * shadowLength
curShadowGeometry[7] = x2 - (light.x - x2) * shadowLength
curShadowGeometry[8] = y2 - (light.y - y2) * shadowLength
curShadowGeometry.alpha = self.alpha
curShadowGeometry.red = self.red
curShadowGeometry.green = self.green
curShadowGeometry.blue = self.blue
curShadowGeometry.alpha = self.alpha
return curShadowGeometry
else
return nil

View File

@ -32,6 +32,8 @@ function light:refresh(w, h)
self.shadow = 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
-- set position
@ -126,7 +128,8 @@ function light:drawShadow(l,t,w,h,s,bodies, canvas)
-- draw shadow
self.shadow:clear()
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("lightColor", {self.red / 255.0, self.green / 255.0, self.blue / 255.0})
self.shader:send("lightSmooth", self.smooth)
@ -182,16 +185,14 @@ end
function light:drawPixelShadow(l,t,w,h, normalMap, canvas)
if self.visible 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('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("lightSmooth", self.smooth)
self.normalInvertShader:send("lightAngle", math.pi - self.angle / 2.0)
self.normalInvertShader:send("lightDirection", self.direction)
util.drawCanvasToCanvas(normalMap, canvas, {shader = self.normalInvertShader})
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('lightPosition',{self.x, h - self.y, self.z / 255.0})
self.normalShader:send('lightRange',{self.range})