Skip to content

Commit

Permalink
Tidy up background shaders code in love.draw
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydlobo committed Nov 7, 2024
1 parent ba3e3b7 commit 4c76e55
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
27 changes: 12 additions & 15 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2185,35 +2185,31 @@ function love.update(dt)
update_screenshake(dt)
end --< love.update()

local has_background = true
function love.draw()
if Config.Debug.IS_ASSERT then assert_consistent_state() end

-- This clears crt and background color each frame start.
if not true then LG.clear(1, 1, 1, 1) end

--- @type number
local alpha = dt_accum * Config.FIXED_DT_INV

local blend_mode = LG.getBlendMode()
local alpha = dt_accum * Config.FIXED_DT_INV --- @type number

LG.setBlendMode('screen', 'premultiplied')
do
local blend_mode = LG.getBlendMode()
LG.setBlendMode('screen', 'premultiplied')
do
LG.setShader(glsl_shaders.warp)
if has_background then -- Draw background fill, else background color shows up─if menu/pause else use LG.clearBackground())
do
LG.rectangle('fill', 0, 0, arena_w, arena_h)
end
LG.setShader() --> glsl_shader.warp
do
LG.setBlendMode('add', 'premultiplied')
Shaders.phong_lighting.shade_any_to_player_pov(function() draw_background_shader(alpha) end)
LG.setBlendMode('screen', 'premultiplied')
end
LG.setShader() --< end of glsl_shader.warp
end

LG.setBlendMode('add', 'premultiplied')
moonshine_shaders.fog(function() end)
Shaders.phong_lighting.shade_any_to_player_pov(function()
draw_background_shader(alpha) --[[]]
end)
LG.setBlendMode(blend_mode) --< end of 'screen'
end
LG.setBlendMode(blend_mode) -- end of 'screen'

-- Draw background fill, else background color shows up (maybe use LG.clearBackground())
--- PERF: A glow radial gradient texture may help shader switch calls
Expand All @@ -2223,6 +2219,7 @@ function love.draw()
-- screen|lighten work well
LG.setBlendMode(Config.Debug.IS_DEVELOPMENT and 'multiply' or 'screen', 'premultiplied')
Shaders.phong_lighting.shade_any_to_player_pov(function() LG.rectangle('fill', 0, 0, arena_w, arena_h) end)
moonshine_shaders.fog(function() end)
LG.setBlendMode(blend_mode)
end

Expand Down
2 changes: 1 addition & 1 deletion src/shaders/phong_lighting.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local LG = love.graphics
local common = require 'common'

local LIGHT_DEFAULT_ANY_TO_PLAYER_POV_DIFFUSE_COLOR = { 0.7, 0.7, 0.6 } -- error.. shouldn't be triggered, as player action must always be defined
local LIGHT_DEFAULT_ANY_TO_PLAYER_POV_DIFFUSE_COLOR = { 0.8, 0.8, 0.7 } -- error.. shouldn't be triggered, as player action must always be defined
local LIGHT_DEFAULT_PLAYER_TRAIL_DIFFUSE_COLOR = { 0.5, 0.5, 0.5 } -- error.. shouldn't be triggered, as player action must always be defined
local LIGHT_DIFFUSE_COLORS = common.PLAYER_ACTION_TO_COLOR

Expand Down

0 comments on commit 4c76e55

Please sign in to comment.