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

# setStencilReferenceValues(front:back:)

Configures different comparison values for front- and back-facing primitives.

```
func setStencilReferenceValues(front frontReferenceValue: UInt32, back backReferenceValue: UInt32)
```

## Parameters

`frontReferenceValue`

A stencil test comparison value the render pipeline applies to only front-facing primitives.

`backReferenceValue`

A stencil test comparison value the render pipeline applies to only back-facing primitives.

## Discussion

The command sets separate reference values for front- and back-facing primitives (see [`stencilCompareFunction`](/documentation/Metal/MTLStencilDescriptor/stencilCompareFunction), [`frontFaceStencil`](/documentation/Metal/MTLDepthStencilDescriptor/frontFaceStencil), and [`backFaceStencil`](/documentation/Metal/MTLDepthStencilDescriptor/backFaceStencil)). These reference values apply 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)