Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all post-processing conditional #2173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions garrysmod/lua/postprocess/bloom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,26 @@ function DrawBloom( darken, multiply, sizex, sizey, passes, color, colr, colg, c

end

--[[---------------------------------------------------------
The function to draw the bloom (called from the hook)
-----------------------------------------------------------]]
hook.Add( "RenderScreenspaceEffects", "RenderBloom", function()
cvars.AddChangeCallback( "pp_bloom", function( _, _, newValue )

-- No bloom for crappy gpus

if ( !render.SupportsPixelShaders_2_0() ) then return end
if ( !pp_bloom:GetBool() ) then return end
if ( !GAMEMODE:PostProcessPermitted( "bloom" ) ) then return end

DrawBloom( pp_bloom_darken:GetFloat(), pp_bloom_multiply:GetFloat(),
if ( newValue != "0" ) then
hook.Add( "RenderScreenspaceEffects", "RenderBloom", function()

DrawBloom( pp_bloom_darken:GetFloat(), pp_bloom_multiply:GetFloat(),
pp_bloom_sizex:GetFloat(), pp_bloom_sizey:GetFloat(),
pp_bloom_passes:GetFloat(), pp_bloom_color:GetFloat(),
pp_bloom_color_r:GetFloat() / 255, pp_bloom_color_g:GetFloat() / 255, pp_bloom_color_b:GetFloat() / 255 )

end)
else
hook.Remove( "RenderScreenspaceEffects", "RenderBloom" )
end

Comment on lines -62 to +80
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing it this way introduces a regression where the result of GAMEMODE:PostProcessPermitted is not updated live.

I can understand SupportsPixelShaders_2_0 being a static thing and can be moved outside of the hook.

I also think it's a better idea to make a the hook a local function and reference that in the cvars.AddChangeCallback callback, rather than nesting functions like this.

end )

list.Set( "PostProcess", "#bloom_pp", {
Expand Down Expand Up @@ -113,4 +117,4 @@ list.Set( "PostProcess", "#bloom_pp", {

end

} )
} )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary change.

15 changes: 6 additions & 9 deletions garrysmod/lua/postprocess/bokeh_dof.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,19 @@ local function OnChange( name, oldvalue, newvalue )

if ( newvalue != "0" ) then
DOFModeHack( true )
hook.Add( "RenderScreenspaceEffects", "RenderBokeh", function()

DrawBokehDOF( pp_bokeh_blur:GetFloat(), pp_bokeh_distance:GetFloat(), pp_bokeh_focus:GetFloat() )

end)
else
hook.Remove( "RenderScreenspaceEffects", "RenderBokeh" )
DOFModeHack( false )
end

end
cvars.AddChangeCallback( "pp_bokeh", OnChange )

hook.Add( "RenderScreenspaceEffects", "RenderBokeh", function()

if ( !pp_bokeh:GetBool() ) then return end
if ( !GAMEMODE:PostProcessPermitted( "bokeh" ) ) then return end

DrawBokehDOF( pp_bokeh_blur:GetFloat(), pp_bokeh_distance:GetFloat(), pp_bokeh_focus:GetFloat() )

end )

hook.Add( "NeedsDepthPass", "NeedsDepthPass_Bokeh", function()

if ( pp_bokeh:GetBool() ) then return true end
Expand Down
17 changes: 13 additions & 4 deletions garrysmod/lua/postprocess/color_modify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ function DrawColorModify( tab )

end

hook.Add( "RenderScreenspaceEffects", "RenderColorModify", function()

if ( !pp_colormod:GetBool() ) then return end
if ( !GAMEMODE:PostProcessPermitted( "color mod" ) ) then return end
local function RenderColorModify()

local tab = {}

Expand All @@ -52,6 +49,18 @@ hook.Add( "RenderScreenspaceEffects", "RenderColorModify", function()

DrawColorModify( tab )

end

cvars.AddChangeCallback( "pp_colormod", function( _, _, newValue )

if ( !GAMEMODE:PostProcessPermitted( "color mod" ) ) then return end

if ( newValue != "0" ) then
hook.Add( "RenderScreenspaceEffects", "RenderColorModify", RenderColorModify )
else
hook.Remove( "RenderScreenspaceEffects", "RenderColorModify" )
end

end )

list.Set( "PostProcess", "#colormod_pp", {
Expand Down
12 changes: 7 additions & 5 deletions garrysmod/lua/postprocess/dof.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function DOF_Kill()

DOFModeHack( false )

hook.Remove( "Think", "DOFThink" )

end

function DOF_Start()
Expand All @@ -43,14 +45,14 @@ function DOF_Start()

DOFModeHack( true )

end
hook.Add( "Think", "DOFThink", function()

hook.Add( "Think", "DOFThink", function()
DOF_SPACING = pp_dof_spacing:GetFloat()
DOF_OFFSET = pp_dof_initlength:GetFloat()

DOF_SPACING = pp_dof_spacing:GetFloat()
DOF_OFFSET = pp_dof_initlength:GetFloat()
end)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary change that does not conform to the style guidelines:
https://github.com/Facepunch/garrysmod/blob/master/CONTRIBUTING.md


end )
end

cvars.AddChangeCallback( "pp_dof", function( name, oldvalue, newvalue )

Expand Down
16 changes: 14 additions & 2 deletions garrysmod/lua/postprocess/frame_blend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ end
--
if ( engine.IsPlayingDemo() ) then return end

hook.Add( "PostRender", "RenderFrameBlend", function()
local function RenderFrameBlend()

if ( !frame_blend.IsActive() ) then return end
if ( !frame_blend.IsActive() ) then hook.Remove( "RenderFrameBlend", "RenderFrameBlend" ) return end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?


if ( !frame_blend.ShouldSkipFrame() ) then
render.CopyRenderTargetToTexture( texFB )
Expand All @@ -186,6 +186,18 @@ hook.Add( "PostRender", "RenderFrameBlend", function()
frame_blend.AddFrame()
frame_blend.DrawPreview()

end

cvars.AddChangeCallback( "pp_fb", function( _, _, newValue )

if ( !GAMEMODE:PostProcessPermitted( "fb" ) ) then return end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "frame_blend", not "fb"


if ( newValue != "0" ) then
hook.Add( "PostRender", "RenderFrameBlend", RenderFrameBlend )
else
hook.Remove( "RenderFrameBlend", "RenderFrameBlend" )
end

end )

list.Set( "PostProcess", "#frame_blend_pp", {
Expand Down
13 changes: 10 additions & 3 deletions garrysmod/lua/postprocess/motion_blur.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,19 @@ function DrawMotionBlur( addalpha, drawalpha, delay )

end

hook.Add( "RenderScreenspaceEffects", "RenderMotionBlur", function()
cvars.AddChangeCallback( "pp_motionblur", function( _, _, newValue )

if ( !pp_motionblur:GetBool() ) then return end
if ( !GAMEMODE:PostProcessPermitted( "motion blur" ) ) then return end

DrawMotionBlur( pp_motionblur_addalpha:GetFloat(), pp_motionblur_drawalpha:GetFloat(), pp_motionblur_delay:GetFloat() )
if ( newValue != "0" ) then
hook.Add( "RenderScreenspaceEffects", "RenderMotionBlur", function()

DrawMotionBlur( pp_motionblur_addalpha:GetFloat(), pp_motionblur_drawalpha:GetFloat(), pp_motionblur_delay:GetFloat() )

end )
else
hook.Remove( "RenderScreenspaceEffects", "RenderMotionBlur" )
end

end )

Expand Down
15 changes: 10 additions & 5 deletions garrysmod/lua/postprocess/overlay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ function DrawMaterialOverlay( texture, refractamount )

end

hook.Add( "RenderScreenspaceEffects", "RenderMaterialOverlay", function()
cvars.AddChangeCallback( "pp_mat_overlay", function( _, _, newValue )

local overlay = pp_mat_overlay:GetString()

if ( overlay == "" ) then return end
if ( !GAMEMODE:PostProcessPermitted( "material overlay" ) ) then return end

DrawMaterialOverlay( overlay, pp_mat_overlay_refractamount:GetFloat() )
if ( newValue != "" ) then
hook.Add( "RenderScreenspaceEffects", "RenderMaterialOverlay", function()

DrawMaterialOverlay( newValue, pp_mat_overlay_refractamount:GetFloat() )

end)
else
hook.Remove( "RenderScreenspaceEffects", "RenderMaterialOverlay" )
end

end )

Expand Down
13 changes: 10 additions & 3 deletions garrysmod/lua/postprocess/sharpen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ function DrawSharpen( contrast, distance )

end

hook.Add( "RenderScreenspaceEffects", "RenderSharpen", function()
cvars.AddChangeCallback( "pp_sharpen", function( _, _, newValue )

if ( !pp_sharpen:GetBool() ) then return end
if ( !GAMEMODE:PostProcessPermitted( "sharpen" ) ) then return end

DrawSharpen( pp_sharpen_contrast:GetFloat(), pp_sharpen_distance:GetFloat() )
if ( newValue != "0" ) then
hook.Add( "RenderScreenspaceEffects", "RenderSharpen", function()

DrawSharpen( pp_sharpen_contrast:GetFloat(), pp_sharpen_distance:GetFloat() )

end )
else
hook.Remove( "RenderScreenspaceEffects", "RenderSharpen" )
end

end )

Expand Down
13 changes: 10 additions & 3 deletions garrysmod/lua/postprocess/sobel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ function DrawSobel( threshold )

end

hook.Add( "RenderScreenspaceEffects", "RenderSobel", function()
cvars.AddChangeCallback( "pp_sobel", function( _, _, newValue )

if ( !pp_sobel:GetBool() ) then return end
if ( !GAMEMODE:PostProcessPermitted( "sobel" ) ) then return end

DrawSobel( pp_sobel_threshold:GetFloat() )
if ( newValue != "0" ) then
hook.Add( "RenderScreenspaceEffects", "RenderSobel", function()

DrawSobel( pp_sobel_threshold:GetFloat() )

end )
else
hook.Remove( "RenderScreenspaceEffects", "RenderSobel" )
end

end )

Expand Down
21 changes: 13 additions & 8 deletions garrysmod/lua/postprocess/stereoscopy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,22 @@ function RenderStereoscopy( ViewOrigin, ViewAngles )

end

--[[---------------------------------------------------------
The function to draw the bloom (called from the hook)
-----------------------------------------------------------]]
hook.Add( "RenderScene", "RenderStereoscopy", function( ViewOrigin, ViewAngles, ViewFOV )
cvars.AddChangeCallback( "pp_stereoscopy", function( _, _, newValue )

if ( !GAMEMODE:PostProcessPermitted( "stereoscopy" ) ) then return end

if ( !pp_stereoscopy:GetBool() ) then return end
if ( newValue != "0" ) then
hook.Add( "RenderScene", "RenderStereoscopy", function(ViewOrigin, ViewAngles)

RenderStereoscopy( ViewOrigin, ViewAngles )
RenderStereoscopy( ViewOrigin, ViewAngles )

-- Return true to override drawing the scene
return true
-- Return true to override drawing the scene
return true

end)
else
hook.Remove( "RenderScene", "RenderStereoscopy" )
end

end )

Expand Down
19 changes: 14 additions & 5 deletions garrysmod/lua/postprocess/sunbeams.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ function DrawSunbeams( darken, multiply, sunsize, sunx, suny )

end

hook.Add( "RenderScreenspaceEffects", "RenderSunbeams", function()

if ( !pp_sunbeams:GetBool() ) then return end
if ( !GAMEMODE:PostProcessPermitted( "sunbeams" ) ) then return end
if ( !render.SupportsPixelShaders_2_0() ) then return end
local function RenderSunbeams()

local sun = util.GetSunInfo()

Expand All @@ -47,6 +43,19 @@ hook.Add( "RenderScreenspaceEffects", "RenderSunbeams", function()

DrawSunbeams( pp_sunbeams_darken:GetFloat(), pp_sunbeams_multiply:GetFloat() * dot * sun.obstruction, pp_sunbeams_sunsize:GetFloat(), scrpos.x / ScrW(), scrpos.y / ScrH() )

end

cvars.AddChangeCallback( "pp_sunbeams", function( _, _, newValue )

if ( !render.SupportsPixelShaders_2_0() ) then return end
if ( !GAMEMODE:PostProcessPermitted( "sunbeams" ) ) then return end

if ( newValue != "0" ) then
hook.Add( "RenderScreenspaceEffects", "RenderSunbeams", RenderSunbeams )
else
hook.Remove( "RenderScreenspaceEffects", "RenderSunbeams" )
end

end )

list.Set( "PostProcess", "#sunbeams_pp", {
Expand Down
44 changes: 22 additions & 22 deletions garrysmod/lua/postprocess/super_dof.lua
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,6 @@ function RenderSuperDoF( ViewOrigin, ViewAngles, ViewFOV )

end

hook.Add( "RenderScene", "RenderSuperDoF", function( ViewOrigin, ViewAngles, ViewFOV )

if ( !IsValid( SuperDOFWindow ) ) then return end

-- Don't render it when the console is up
if ( FrameTime() == 0 ) then return end

RenderSuperDoF( ViewOrigin, ViewAngles, ViewFOV )
return true

end )

concommand.Add( "pp_superdof", function()

Status = "Preview"
Expand All @@ -354,23 +342,35 @@ concommand.Add( "pp_superdof", function()
SuperDOFWindow:MakePopup()
SuperDOFWindow:PositionMyself()

end )
hook.Add( "RenderScene", "RenderSuperDoF", function( ViewOrigin, ViewAngles, ViewFOV )

hook.Add( "GUIMousePressed", "SuperDOFMouseDown", function( mouse )
if ( !IsValid( SuperDOFWindow ) ) then hook.Remove( "RenderScene", "RenderSuperDoF" ) return end

if ( !IsValid( SuperDOFWindow ) ) then return end
-- Don't render it when the console is up
if ( FrameTime() == 0 ) then return end

vgui.GetWorldPanel():MouseCapture( true )
FocusGrabber = true
RenderSuperDoF( ViewOrigin, ViewAngles, ViewFOV )
return true

end )
end )

hook.Add( "GUIMousePressed", "SuperDOFMouseDown", function( mouse )

if ( !IsValid( SuperDOFWindow ) ) then hook.Remove( "GUIMousePressed", "SuperDOFMouseDown" ) return end

vgui.GetWorldPanel():MouseCapture( true )
FocusGrabber = true

end )

hook.Add( "GUIMouseReleased", "SuperDOFMouseUp", function( mouse )

hook.Add( "GUIMouseReleased", "SuperDOFMouseUp", function( mouse )
if ( !IsValid( SuperDOFWindow ) ) then hook.Remove( "GUIMouseReleased", "SuperDOFMouseUp" ) return end

if ( !IsValid( SuperDOFWindow ) ) then return end
vgui.GetWorldPanel():MouseCapture( false )
FocusGrabber = false

vgui.GetWorldPanel():MouseCapture( false )
FocusGrabber = false
end )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire file is a mess. See previous comments.

I also think this can be all done better, such as removing the hooks from Panel.OnRemove of the SuperDOFWindow for example.


end )

Expand Down
Loading