diff --git a/examples/complex.lua b/examples/complex.lua index 13dbca3..c5e5b57 100644 --- a/examples/complex.lua +++ b/examples/complex.lua @@ -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) diff --git a/examples/normalMap.lua b/examples/normalMap.lua index 050bcf6..0d4634e 100644 --- a/examples/normalMap.lua +++ b/examples/normalMap.lua @@ -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() diff --git a/examples/short.lua b/examples/short.lua index 111da1b..3350c90 100644 --- a/examples/short.lua +++ b/examples/short.lua @@ -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() diff --git a/gfx/rock.png b/gfx/rock.png new file mode 100644 index 0000000..1f683b4 Binary files /dev/null and b/gfx/rock.png differ diff --git a/gfx/rock_n.png b/gfx/rock_n.png new file mode 100644 index 0000000..b91467e Binary files /dev/null and b/gfx/rock_n.png differ diff --git a/lib/body.lua b/lib/body.lua index fea2a87..3e9135b 100644 --- a/lib/body.lua +++ b/lib/body.lua @@ -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 diff --git a/lib/light.lua b/lib/light.lua index b24b5cf..86c732a 100644 --- a/lib/light.lua +++ b/lib/light.lua @@ -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})