# StencilState

> Values for the stencil state.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine.Rendering](/engine/6000.0/script-reference/unityengine/rendering.md)
* **Assembly:** UnityEngine.CoreModule
* **Implements:** [IEquatable\<StencilState>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public struct StencilState : IEquatable<StencilState>
```

## Remarks

Use this with [RenderStateBlock](/engine/6000.0/script-reference/unityengine/rendering/renderstateblock.md) and [ScriptableRenderContext.DrawRenderers](/engine/6000.0/script-reference/unityengine/rendering/scriptablerendercontext/drawrenderers.md) to override the GPU's render state.

Corresponds to the `Stencil` command in [ShaderLab](/engine/6000.0/manual/materials-and-shaders/shaders/reference/sl-reference.md).

Additional Resources: [RenderStateBlock](/engine/6000.0/script-reference/unityengine/rendering/renderstateblock.md), \[\[ScriptableRenderContext.DrawRenderers], [ShaderLab command: Stencil](/engine/6000.0/manual/materials-and-shaders/shaders/reference/sl-reference/sl-commands/sl-stencil.md).

## Constructors

| Constructor                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Description                                        |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- |
| [StencilState(System.Boolean,System.Byte,System.Byte,UnityEngine.Rendering.CompareFunction,UnityEngine.Rendering.StencilOp,UnityEngine.Rendering.StencilOp,UnityEngine.Rendering.StencilOp)](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/ctor.md#stencilstate\(bool-byte-byte-comparefunction-stencilop-stencilop-stencilop\))                                                                                                                                                                                     | Creates a new stencil state with the given values. |
| [StencilState(System.Boolean,System.Byte,System.Byte,UnityEngine.Rendering.CompareFunction,UnityEngine.Rendering.StencilOp,UnityEngine.Rendering.StencilOp,UnityEngine.Rendering.StencilOp,UnityEngine.Rendering.CompareFunction,UnityEngine.Rendering.StencilOp,UnityEngine.Rendering.StencilOp,UnityEngine.Rendering.StencilOp)](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/ctor.md#stencilstate\(bool-byte-byte-comparefunction-stencilop-stencilop-stencilop-comparefunction-stencilop-stencilop-stencilop\)) | Creates a new stencil state with the given values. |

## Properties

| Property                                                                                                           | Description                                                                                                                |
| ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
| [compareFunctionBack](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/comparefunctionback.md)   | The function used to compare the reference value to the current contents of the buffer for back-facing geometry.           |
| [compareFunctionFront](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/comparefunctionfront.md) | The function used to compare the reference value to the current contents of the buffer for front-facing geometry.          |
| [enabled](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/enabled.md)                           | Controls whether the stencil buffer is enabled.                                                                            |
| [failOperationBack](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/failoperationback.md)       | What to do with the contents of the buffer if the stencil test fails for back-facing geometry.                             |
| [failOperationFront](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/failoperationfront.md)     | What to do with the contents of the buffer if the stencil test fails for front-facing geometry.                            |
| [passOperationBack](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/passoperationback.md)       | What to do with the contents of the buffer if the stencil test (and the depth test) passes for back-facing geometry.       |
| [passOperationFront](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/passoperationfront.md)     | What to do with the contents of the buffer if the stencil test (and the depth test) passes for front-facing geometry.      |
| [readMask](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/readmask.md)                         | An 8 bit mask as an 0–255 integer, used when comparing the reference value with the contents of the buffer.                |
| [writeMask](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/writemask.md)                       | An 8 bit mask as an 0–255 integer, used when writing to the buffer.                                                        |
| [zFailOperationBack](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/zfailoperationback.md)     | What to do with the contents of the buffer if the stencil test passes, but the depth test fails for back-facing geometry.  |
| [zFailOperationFront](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/zfailoperationfront.md)   | What to do with the contents of the buffer if the stencil test passes, but the depth test fails for front-facing geometry. |

## Static Properties

| Property                                                                                           | Description                           |
| -------------------------------------------------------------------------------------------------- | ------------------------------------- |
| [defaultValue](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/defaultvalue.md) | Default values for the stencil state. |

## Methods

| Method                                                                                                         | Description                                                                                      |
| -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| [SetCompareFunction](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/setcomparefunction.md) | The function used to compare the reference value to the current contents of the buffer.          |
| [SetFailOperation](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/setfailoperation.md)     | What to do with the contents of the buffer if the stencil test fails.                            |
| [SetPassOperation](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/setpassoperation.md)     | What to do with the contents of the buffer if the stencil test (and the depth test) passes.      |
| [SetZFailOperation](/engine/6000.0/script-reference/unityengine/rendering/stencilstate/setzfailoperation.md)   | What to do with the contents of the buffer if the stencil test passes, but the depth test fails. |
