Garry's Mod Wiki

render.SetStencilPassOperation

render.SetStencilPassOperation( number passOperation )

Description

Sets the operation to be performed on the stencil buffer values if the compare function was successful.

Arguments

1 number passOperation
Pass operation function, see Enums/STENCILOPERATION

Example

This uses the pass operation to blank out everything but what we just drew

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 ) -- Only draw things if their pixels are NOT 1. Currently this is everything. render.SetStencilCompareFunction( STENCIL_NOTEQUAL ) -- If something draws to the screen, set the pixels it draws to 1 render.SetStencilPassOperation( STENCIL_REPLACE ) -- Draw our entities. They will draw as normal for i, ent in ipairs( ents.FindByClass( "sent_stencil_test" ) ) do ent:DrawModel() end -- At this point, we cannot draw on top of anything that we have already drawn. -- So, if we flush the screen, our entities will still be there. render.ClearBuffersObeyStencil(0, 148, 133, 255, false); -- Let everything render normally again render.SetStencilEnable( false ) end )
Output:

Page Links


Special Pages


Wikis

?

Render Time: 103ms

DB GetPage 56
Generate Html 9
SaveChanges (1) 19
Render Body 0
Render Sidebar 12