Skip to content

SetEntityStencil

Narta Xaymar Dirks edited this page Nov 25, 2026 · 1 revision

SetEntityStencil

SetEntityStencil:Void entity:Int32, compare:Int32, reference:Int32=0, read_mask:Int32=255, write_mask:Int32=255, fail:Int32=0, depth_fail:Int32=0, pass:Int32=0
Parameter Mode Type Default Description
entity In Int32 required Entity handle.
compare In Int32 required The comparison, from 0 to 7.
reference In Int32 0 The value compared with and written by replace, from 0 to 255. Default 0.
read_mask In Int32 255 The bits that are compared, from 0 to 255. Default 255.
write_mask In Int32 255 The bits that are written, from 0 to 255. Default 255.
fail In Int32 0 The operation when the comparison fails, from 0 to 7. Default 0 (keep).
depth_fail In Int32 0 The operation when the comparison holds and the depth test fails, from 0 to 7. Default 0 (keep).
pass In Int32 0 The operation when both hold, from 0 to 7. Default 0 (keep).

Description

Sets the stencil test of an entity and what it does to the stencil, for cameras with a stencil (SetCameraStencil). For every pixel of the entity, reference And read_mask is compared with stencil And read_mask; the pixel is only drawn if the comparison holds. Then the stencil gets one of three operations, in the bits of write_mask: fail if the comparison did not hold, depth_fail if it held but the depth test did not, and pass if both held. This is a BlitzLLVM extension.

Comparisons: 0 never, 1 less, 2 equal, 3 less or equal, 4 greater, 5 not equal, 6 greater or equal, 7 always. "Less" means that the reference is less than the stencil.

Operations: 0 keep, 1 zero, 2 replace (with the reference), 3 increment (stops at 255), 4 decrement (stops at 0), 5 invert, 6 increment and wrap, 7 decrement and wrap.

This sets both sides of the triangles; SetEntityStencilBack gives the back faces their own. Compare 7 with every operation 0, the default, is no stencil at all. Cameras without a stencil ignore all of this.

What the stencil does depends on the order in which things are drawn: the entity that marks the stencil has to be drawn before the ones that test it. Entities with a stencil keep the order they are drawn in, and EntityOrder puts the marking ones first. Entities that use order-independent transparency (BLITZLLVM_OIT 1 to 5) ignore the stencil.

Examples

Graphics3D 640, 480, 0, 2
SetBuffer BackBuffer()
camera = CreateCamera()
SetCameraStencil camera, True

; A portal frame that writes 1 to the stencil where it is drawn.
portal = CreateCube()
EntityOrder portal, 1
PositionEntity portal, 0, 0, 10
ScaleEntity portal, 2, 3, 0.1
SetEntityStencil portal, 7, 1, 255, 255, 0, 0, 2

; The world on the other side: only drawn inside the portal.
other = CreateSphere(32)
EntityColor other, 0, 128, 255
PositionEntity other, 0, 0, 20
ScaleEntity other, 6, 6, 6
SetEntityStencil other, 2, 1

; The world on this side: drawn everywhere else.
here = CreateCube()
EntityColor here, 255, 64, 0
PositionEntity here, 0, 0, 20
ScaleEntity here, 6, 6, 6
SetEntityStencil here, 5, 1

While Not KeyHit(1)
	TurnEntity other, 0, 1, 0
	TurnEntity here, 1, 0, 0
	RenderWorld
	Flip
Wend

Related Commands

CopyEntity, EntityAlpha, EntityAutoFade, EntityBlend, EntityClass, EntityColor, EntityDepthFade 〔BlitzLLVM〕, SetEntityStencilBack

Home · Command Index


Getting started

Language

Tools


Language Features
BlitzBasic
Blitz3D
BlitzPlus
Differences

More

Clone this wiki locally