Skip to content

Conversation

@Akabenko
Copy link

@Akabenko Akabenko commented Nov 11, 2025

Returning return true in the PreDrawHalos hook will avoid rendering the Halos effect and expand the use of PreDrawHalos to avoid artifacts when working with stencils.

Returns
1 boolean
Return true to disable Hallos effect

Returning return true in the PreDrawHalos hook will avoid rendering the Halos effect and expand the use of PreDrawHalos to avoid artifacts when working with stencils.

Returns
1 boolean
Return true to disable Hallos effect

https://wiki.facepunch.com/gmod/GM:PreDrawHalos
@robotboy655
Copy link
Collaborator

You should be able to use https://wiki.facepunch.com/gmod/halo.RenderedEntity for that purpose?

@Akabenko
Copy link
Author

Akabenko commented Nov 11, 2025

STENCIL_SSR = 0x30

hook.Add( "OnEntityCreated", "SSR", function( ent )
	if ent:GetClass() != "lvs_wheeldrive_regal" then return end
	ent.RenderOverride = function(self, flags)
	    render.SetStencilEnable( true )

	    render.SetStencilWriteMask(0xFF)
	    render.SetStencilTestMask(0xFF)
	    render.SetStencilReferenceValue(STENCIL_SSR)

	    render.SetStencilCompareFunction(STENCIL_ALWAYS)
	    render.SetStencilPassOperation(STENCIL_REPLACE)
	    render.SetStencilFailOperation(STENCIL_KEEP)
	    render.SetStencilZFailOperation(STENCIL_KEEP)

	    if halo.RenderedEntity() == self then
	    	self.AttachedEntity:DrawModel(flags) -- LUA attempt to index field 'AttachedEntity' (a nil value)
	    else
	    	self:DrawModel(flags)
	    end
	    render.SetStencilEnable( false )
	end
end )
hook.Add("RenderScreenspaceEffects", "SSR", function()
	render.SetStencilEnable(true)

	render.SetStencilPassOperation(STENCIL_KEEP)
	render.SetStencilFailOperation(STENCIL_KEEP)
	render.SetStencilZFailOperation(STENCIL_KEEP)
	render.SetStencilCompareFunction(STENCIL_EQUAL)

	render.SetStencilReferenceValue(STENCIL_SSR)

	render.SetMaterial(mat_ssr_stencil)
	render.DrawScreenQuad()

	render.SetStencilEnable(false)
end)

Lua error:

[shader_ssr] addons/shader_ssr/lua/postprocess/pp_ssr.lua:566: attempt to index field 'AttachedEntity' (a nil value)
  1. unknown - addons/shader_ssr/lua/postprocess/pp_ssr.lua:566
   2. DrawModel - [C]:-1
    3. unknown - lua/entities/lvs_base/cl_init.lua:47
     4. DrawModel - [C]:-1
      5. Render - lua/includes/modules/halo.lua:76
       6. v - lua/includes/modules/halo.lua:145
        7. unknown - lua/includes/modules/hook.lua:102 (x224)

self:DrawModel(flags):
image
Try to catch ent using physgun (self:DrawModel(flags)):
image

Also, during testing, my car was stolen (only the wheels remain).
image

@robotboy655
Copy link
Collaborator

hook.Add( "OnEntityCreated", "SSR", function( ent )
	if ent:GetClass() != "lvs_wheeldrive_regal" then return end
	ent.RenderOverride = function(self, flags)
	   if halo.RenderedEntity() == self then  self:DrawModel(flags) return end

	    render.SetStencilEnable( true )

	    render.SetStencilWriteMask(0xFF)
	    render.SetStencilTestMask(0xFF)
	    render.SetStencilReferenceValue(STENCIL_SSR)

	    render.SetStencilCompareFunction(STENCIL_ALWAYS)
	    render.SetStencilPassOperation(STENCIL_REPLACE)
	    render.SetStencilFailOperation(STENCIL_KEEP)
	    render.SetStencilZFailOperation(STENCIL_KEEP)

	 
	    self:DrawModel(flags)
	    render.SetStencilEnable( false )
	end
end )

Try this. The idea is that for the halo pass, you would not use any stencils and just render the model itself.

@Akabenko
Copy link
Author

Akabenko commented Nov 11, 2025

Thanks! Works.
image

But there are cases when you need to remove Halos in one of the render.RenderView, so Returns for PreDrawHalos would be useful:

hook.Add("PreRender", "ShadowMap", function()
	bDrawShadowMap = true
	-- material override, some code
	render.RenderView(viewSetup)
	bDrawShadowMap = false
end)

hook.Add("PreDrawHalos", "ShadowMap", function()
	if bDrawShadowMap then return true end
end)

@robotboy655 robotboy655 added the Enhancement The pull request enhances current functionality. label Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement The pull request enhances current functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants