Stencil help.

So i was looking into stencil tut here on facepunch and i see someone posted a code to make whatever gun people were holding like grey. But the problem is this code is like 2 years old and when i try it out on my test server. I’m getting my whole screen set to like a grey pixel i think.


local mat1 = Material("models/debug/debugwhite")

hook.Add( "PostDrawOpaqueRenderables", "PostDrawing", function()

	--This code will draw mat1 over every players weapon, though since drawing the weapon also draws the play, i have to remove the player from the stencil afterwards.

	render.ClearStencil() --Clear stencil
	render.SetStencilEnable( true ) --Enable stencil
	
	render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_NEVER ) --We don't actually draw the weapon, we just want it on our stencil
	render.SetStencilFailOperation( STENCILOPERATION_INCR ) --If we fail, do nothing
	render.SetStencilPassOperation( STENCILOPERATION_KEEP ) --If we pass (we see it) increase the pixels value by 1
	render.SetStencilZFailOperation( STENCILOPERATION_KEEP ) --If it's behind something, dont do anything
			
	for _, ply in pairs( player.GetAll() ) do
		
		ply:GetActiveWeapon():DrawModel() --Draw all players weapons hurr
	end
	
	render.SetStencilPassOperation( STENCILOPERATION_DECR ) --Now we have to remove the player from the buffer, therefore we will decrease all player pixels by 1 
	
	for _, ply in pairs( player.GetAll() ) do
		
		ply:DrawModel() --Draw only player model (not weapon)
	end
		
	render.SetStencilReferenceValue( 1 ) --Reference value 1
	render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL ) --Only draw if pixel value == reference value
		
	render.SetMaterial( mat1 )
	render.DrawScreenQuad() --Draw over whole screen (the pixels outside the players weapons won't be rendered anyways.
	
	render.SetStencilEnable( false )
	
	--So to sum it up; all pixels had value 0 by default, we increase all the pixels that are either the player or the players weapon by 1, 
	--we then decrease all the pixels that are the player (not the weapon though) by 1, and so we achieve the only the pixels of the weapon have the 
	--value 1 whereas the rest of the screen has value 0. So we set the overlay to only draw if value is 1, and voila! we have greyish weapons =D
end )