Rehandled Darkness and Lights. Refactored lots of stuff. Rewritten shaders.
This commit is contained in:
@@ -2,6 +2,7 @@ function GameworldDrawPrepare()
|
||||
if game_resize then
|
||||
Camera.height = game.height
|
||||
Camera.width = game.width
|
||||
Darkness.Recreate()
|
||||
end
|
||||
pcr, pcg, pcb, pca = love.graphics.getColor()
|
||||
love.graphics.scale(game.scale,game.scale)
|
||||
@@ -72,24 +73,53 @@ function GameworldDrawForeground()
|
||||
end
|
||||
end
|
||||
|
||||
function GameworldDrawLighting()
|
||||
if game_resize then
|
||||
Canvas.Darkness:release()
|
||||
Canvas.Darkness = CreateDarkness()
|
||||
love.graphics.setCanvas(Canvas.Darkness)
|
||||
SetDarkness()
|
||||
love.graphics.setCanvas()
|
||||
function GameworldDrawDarkness()
|
||||
Darkness.Reset()
|
||||
Darkness.DrawStart()
|
||||
love.graphics.setBlendMode("replace")
|
||||
love.graphics.setColor(0,0,0,0)
|
||||
for _, light in pairs(LoadedObjects.Lights) do
|
||||
if light.range ~= 0 then
|
||||
local position = {
|
||||
x = (light.pos.x - Camera.pos.x) / game.scale,
|
||||
y = (light.pos.y - Camera.pos.y) / game.scale
|
||||
}
|
||||
local range = (light.range + light.flicker) / game.scale
|
||||
love.graphics.circle(
|
||||
"fill",
|
||||
position.x,
|
||||
position.y,
|
||||
range
|
||||
)
|
||||
end
|
||||
end
|
||||
Darkness.DrawEnd()
|
||||
end
|
||||
|
||||
function GameworldDrawLights()
|
||||
for _, light in pairs(LoadedObjects.Lights) do
|
||||
if light.range ~= 0 then
|
||||
love.graphics.setColor(light.color[1],light.color[2],light.color[3],1)
|
||||
|
||||
Shader.RadiusGradient:send("pos_x",- Camera.pos.x + light.pos.x)
|
||||
Shader.RadiusGradient:send("pos_y",- Camera.pos.y + light.pos.y)
|
||||
Shader.RadiusGradient:send("range",light.range)
|
||||
Shader.RadiusGradient:send("scale",game.scale)
|
||||
|
||||
love.graphics.setShader(Shader.RadiusGradient)
|
||||
love.graphics.circle(
|
||||
"fill",
|
||||
- Camera.pos.x + light.pos.x,
|
||||
- Camera.pos.y + light.pos.y,
|
||||
light.range
|
||||
)
|
||||
love.graphics.setShader()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function GameWorldUpdateLights()
|
||||
for _, light in pairs(LoadedObjects.Lights) do
|
||||
light:Flicker()
|
||||
end
|
||||
|
||||
-- work on lighting canvas
|
||||
love.graphics.setCanvas(Canvas.Darkness)
|
||||
SetDarkness()
|
||||
DoLights()
|
||||
DoBorder()
|
||||
-- apply to game canvas
|
||||
love.graphics.setColor(1,1,1,1)
|
||||
love.graphics.scale(game.scale,game.scale)
|
||||
love.graphics.setCanvas()
|
||||
DrawDarkness()
|
||||
love.graphics.scale(1/game.scale,1/game.scale)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user