Garry's Mod Wiki


  render.ClearBuffersObeyStencil( number r, number g, number b, number a, boolean depth )


Clears the portion of the active Render Target that passes the current stencil buffer conditions.


1 number r
Value of the red channel to clear the current rt with.
2 number g
Value of the green channel to clear the current rt with.
3 number b
Value of the blue channel to clear the current rt with.
4 number a
Value of the alpha channel to clear the current rt with.
5 boolean depth
Clear the depth buffer.


Clearing a section of the screen via the stencil buffer (from Lex's Stencil Tutorial).

hook.Add( "PostDrawOpaqueRenderables", "Stencil Tutorial Example", function() -- Reset everything to known good render.SetStencilWriteMask( 0xFF ) render.SetStencilTestMask( 0xFF ) render.SetStencilReferenceValue( 0 ) render.SetStencilCompareFunction( STENCIL_ALWAYS ) render.SetStencilPassOperation( STENCIL_KEEP ) render.SetStencilFailOperation( STENCIL_KEEP ) render.SetStencilZFailOperation( STENCIL_KEEP ) render.ClearStencil() -- Enable stencils render.SetStencilEnable( true ) -- Set the reference value to 1. This is what the compare function tests against render.SetStencilReferenceValue( 1 ) -- Refuse to write things to the screen unless that pixel's value is 1 render.SetStencilCompareFunction( STENCIL_EQUAL ) -- Write a 1 to the centre third of the screen. Because we cleared it earlier, everything is currently 0 local w, h = ScrW() / 3, ScrH() / 3 local x_start, y_start = w, h local x_end, y_end = x_start + w, y_start + h render.ClearStencilBufferRectangle( x_start, y_start, x_end, y_end, 1 ) -- Tell the render library to clear the screen, but obeying the stencil test function. -- This means it will only clear the centre third. render.ClearBuffersObeyStencil( 0, 148, 133, 255, false ) -- Let everything render normally again render.SetStencilEnable( false ) end )