NekoToonDocs Download

Advanced

Stencil

The stencil buffer is a per-pixel number that materials can write and test. One material marks pixels, and another draws only where the mark is (or is not). This is how effects like eyebrows showing through hair are made.

For the common cases, use the Simple Stencil Settings in Base Setting: they fill in these values and the render queue for you. This section exposes every stencil property directly. The main box applies to the main passes. Extra boxes appear for the PrePass (Two Pass transparent), the outline pass and the fur pass, each with the same seven settings under its own property prefix (_PreStencil…, _OutlineStencil…, _FurStencil…).

Stencil effects only work in the right draw order: the writer must render before the reader. Give the writer a lower Render Queue than the reader, and keep both in the same range (for example 2451 and 2452, as the simple presets do). Also, every avatar and world shares the same stencil buffer, so pick an uncommon Ref value to avoid clashing with other content.

Stencil#

Reset#

button

Sets the main stencil back to "no effect": Ref 0, ReadMask and WriteMask 255, Comp Always, Pass, Fail and ZFail Keep. It also resets the PrePass, outline and fur stencil when they exist.

Ref#

_StencilRef 0 – 255 · default 0

The reference value. It is what Replace writes into the buffer, and what Comp compares the buffer against. Materials that should interact need the same Ref.

ReadMask#

_StencilReadMask 0 – 255 · default 255

Bit mask applied to both Ref and the buffer value before comparing. 255 compares all 8 bits. Use smaller masks only if you deliberately split the stencil byte into separate bit flags.

WriteMask#

_StencilWriteMask 0 – 255 · default 255

Bit mask for writing: only the bits set here are changed in the buffer. 255 writes all bits.

Comp#

_StencilComp Disabled · Never · Less · Equal · LessEqual · Greater · NotEqual · GreaterEqual · Always · default Always

The stencil test. A pixel is only drawn if Ref compared with the buffer value passes. Always (the default) draws everywhere. Equal draws only where the buffer already holds Ref (shows only through a writer). NotEqual draws only where it does not (hidden by a writer).

Pass#

_StencilPass Keep · Zero · Replace · IncrementSaturate · DecrementSaturate · Invert · IncrementWrap · DecrementWrap · default Keep

What happens to the buffer when both the stencil test and the depth test pass. Keep leaves it alone. Replace writes Ref, which is what a writer uses.

Fail#

_StencilFail same options as Pass · default Keep

What happens to the buffer when the stencil test fails. Usually Keep.

ZFail#

_StencilZFail same options as Pass · default Keep

What happens when the stencil test passes but the depth test fails (the pixel is behind something already drawn). Set it to Replace on a writer if it should mark pixels even where something drawn earlier hides it.

PrePass#

Shown for Transparent with Transparent Mode Two Pass. Same seven settings (_PreStencilRef, _PreStencilReadMask, _PreStencilWriteMask, _PreStencilComp, _PreStencilPass, _PreStencilFail, _PreStencilZFail), with the same defaults, applied to the PrePass. The simple stencil modes copy the main values here, except Reader (Fade), which sets the PrePass Comp to Equal.

Outline#

Shown on outline materials. Same seven settings (_OutlineStencilRef … _OutlineStencilZFail) for the outline pass, with the same defaults. Keeping the outline at Comp Always while the body is a reader means the outline stays visible where the body is hidden. Match them if the outline should be hidden too.

Fur#

Shown on fur materials. Same seven settings (_FurStencilRef … _FurStencilZFail) for the fur pass, with the same defaults. The simple stencil modes copy the main values here.

FakeShadow#

The optional FakeShadow shader has its own stencil box. Its default Ref is 51 and it has three buttons:

  • Set Writer: Ref 51, Comp Equal, Pass Replace, render queue one below the shader's queue (plus 450 for Opaque).
  • Set Reader: Ref 51, Comp Equal, Pass Keep, render queue back to the shader default (plus 450 for Opaque).
  • Reset: Ref 51, Comp Equal, Pass Keep, render queue back to the shader default.

FakeShadow is meant to be a reader that only draws where another material (for example the face) has written Ref 51.

Eyebrows through hair, step by step: on the eyebrow material set Simple Stencil Mode to Writer. On the hair set it to Reader with the same Ref. Check that the eyebrow queue (2451) is lower than the hair queue (2452). Because the eyebrows are drawn before the hair, the hair cannot block their depth test, and the hair then skips every pixel the eyebrows marked.

NekoToon is a fork of lilToon by lilxyzw (MIT License). Fur styles are based on Xiexe's Unity Shaders (MIT). NekoToon and its documentation are made by Mora for 404NyanFound.