<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLRenderCommandEncoder/setStencilReferenceValue(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLRenderCommandEncoder(im)setStencilReferenceValue:"
  },
  "title" : "setStencilReferenceValue(_:)"
}
-->

# setStencilReferenceValue(_:)

Configures the same comparison value for front- and back-facing primitives.

```
func setStencilReferenceValue(_ referenceValue: UInt32)
```

## Parameters

`referenceValue`

A stencil test comparison value the render pipeline applies to both front- and back-facing primitives.

## Discussion

The command sets the same reference value for front- and back-facing primitives (see [`stencilCompareFunction`](/documentation/Metal/MTLStencilDescriptor/stencilCompareFunction), [`frontFaceStencil`](/documentation/Metal/MTLDepthStencilDescriptor/frontFaceStencil), and [`backFaceStencil`](/documentation/Metal/MTLDepthStencilDescriptor/backFaceStencil)). This reference value applies to the stencil state you set with the [`setDepthStencilState(_:)`](/documentation/Metal/MTLRenderCommandEncoder/setDepthStencilState(_:)) method.

The render pass’s default reference value for the front and back stencil compare function is `0`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)