Revision Difference
render.ClearStencil#561504
<function name="ClearStencil" parent="render" type="libraryfunc">
<description>Resets all values in the stencil buffer to zero.</description>⤶
<realm>Client and Menu</realm>⤶
</function>⤶
⤶
<example>⤶
<description>
A silly example that shows that nothing will render if you clear the stencil buffer (from
[Lex's Stencil Tutorial](https://github.com/Lexicality/stencil-tutorial)).
Sets the Stencil Buffer value to `0` for all pixels in the currently active <page text="Render Target">render_rendertargets</page>.
For more detailed information on the Stencil system, including usage examples, see the <page text="Stencils Render Reference">render_stencils</page> page⤶
</description>
<code>⤶
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 )⤶
⤶
-- 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 )⤶
-- Set the entire screen to 0⤶
render.ClearStencil()⤶
⤶
-- Attempt to draw our entities. Nothing will draw, because nothing in the buffer is 1.⤶
for _, ent in ipairs( ents.FindByClass( "sent_stencil_test" ) ) do⤶
ent:DrawModel()⤶
end⤶
⤶
-- Let everything render normally again⤶
render.SetStencilEnable( false )⤶
end )⤶
</code>⤶
<output><image src="stencil_clearbuffer_result.jpg" alt="left|400px"/></output>⤶
</example> <realm>Client and Menu</realm>⤶
</function>⤶