adcimon / portal-room

Use case of the stencil buffer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Portal Room

Use case of the stencil buffer.

The scene contains 4 different objects inside a room and each one of them is only visible from one side.

The stencil buffer is an extra data buffer that stores an integer per pixel, usually 1 byte. The most common uses of the stencil buffer are outline geometry, planar reflections or portal rendering. The stencil buffer parameters are exposed as shader properties.

Stencil
{
	Ref [_StencilRef]
	ReadMask [_StencilReadMask]
	WriteMask [_StencilWriteMask]
	Comp [_StencilComp]
	Pass [_StencilPass] 
	Fail [_StencilFail]
	ZFail [_StencilZFail]
}
  • _StencilRef. Value to be written to the buffer or the value to be compared against.
  • _StencilReadMask. 8-bit mask used when comparing the reference value with the contents of the buffer.
  • _StencilWriteMask. 8-bit mask used when writing to the buffer.
  • _StencilComp. Function used to compare the reference value to the current contents of the buffer.
  • _StencilPass. Opperation to do with the contents of the buffer if the stencil test (and the depth test) passes.
  • _StencilFail. Opperation to do with the contents of the buffer if the stencil test fails.
  • _StencilZFail. Opperation to do with the contents of the buffer if the stencil test passes, but the depth test fails.

Each plane has its own material where the stencil buffer is filled with an integer from 1 to 4.

Similarly, each gameobject has a material that only draws the object if the stencil buffer has a specific value from 1 to 4.

References.

Stencil Buffer Documentation

About

Use case of the stencil buffer.

License:MIT License


Languages

Language:ShaderLab 100.0%