One Logo Pool Ball
RealityKit · IOS API REFERENCE

ARView.PostProcessContext

struct · iOS 15.0+ · SDK 27.1

struct PostProcessContext

An object the framework uses to pass data to a postprocess callback. In iOS 15 and later, as well as macOS 12 and later, you can register a callback function to apply postprocessing effects to RealityKit’s rendered scene. Once every frame, RealityKit calls that function before it displays the scene. You can use this callback to apply postprocess effects using any APIs that can modify an image texture. However, because RealityKit calls this method every frame, you should only use APIs that execute on the GPU, such as Metal compute functions, <doc://com.apple.documentation/documentation/metalperformanceshaders>, or <doc://com.apple.documentation/coreimage>. You can also render additional content, such as a rendered SpriteKit scene, on top of the frame buffer. - Note: For more information on implementing postprocess effects, see <doc://com.apple.documentation/documentation/realitykit/implementing_special_rendering_effects_with_realitykit_postprocessing>, which demonstrates multiple postprocess techniques. A postprocess callback takes a single `PostProcessContext` parameter, which contains data the callback function needs to modify the rendered scene, including the frame buffer, depth map, and a property for writing the modified image. If you’ve registered a postprocess callback, that function needs to encode to the output texture or the frame is never displayed. A postprocess function looks like this: ```swift func myPostProcessCallback(context: ARView.PostProcessContext) { // Handle postprocessing here. } ``` To register a function as the postprocess render callback, assign it to the ``ARView/RenderCallbacks-swift.struct/postProcess`` property of the ``ARView/renderCallbacks-swift.property`` property of the scene’s `ARView`: ```swift arView.renderCallbacks.postProcess = myPostProcessCallback ``` To stop postprocessing, set the ``ARView/RenderCallbacks-swift.struct/postProcess`` render callback to `nil`. ```swift arView.renderCallbacks.postProcess = nil ``` If your app turns postprocessing on and off frequently, another option for disabling postprocess effects is to keep your callback registered, but use an <doc://com.apple.documentation/metal/mtlblitcommandencoder> to encode the unmodified framebuffer directly to the output texture whenever postprocess effects aren’t active. ```swift func myPostProcessCallback(context: ARView.PostProcessContext) { if (usePostProcessEffects) { handlePostProcessing(context: ARView.PostProcessContext) return } // If postprocess effects are disabled, copy sourceColorTexture // directly to targetColorTexture. let blitEncoder = context.commandBuffer.makeBlitCommandEncoder() blitEncoder?.copy(from: context.sourceColorTexture, to: context.targetColorTexture) blitEncoder?.endEncoding() } ```

Members (15)

get · iOS 15.0+

projection

TypeScript
get projection(): Promise<SDKHandle>
Swift declaration
var projection: float4x4

The projection matrix used to render the frame.

set · iOS 15.0+

projection

TypeScript
setProjection(value: SDKHandle): Promise<void>
Swift declaration
var projection: float4x4

The projection matrix used to render the frame.

get · iOS 15.0+

commandBuffer

TypeScript
get commandBuffer(): Promise<SDKHandle>
Swift declaration
var commandBuffer: any MTLCommandBuffer

The Metal command buffer for encoding the frame.

set · iOS 15.0+

commandBuffer

TypeScript
setCommandBuffer(value: SDKHandle): Promise<void>
Swift declaration
var commandBuffer: any MTLCommandBuffer

The Metal command buffer for encoding the frame.

get · iOS 15.0+

sourceColorTexture

TypeScript
get sourceColorTexture(): Promise<SDKHandle>
Swift declaration
var sourceColorTexture: any MTLTexture

The rendered frame buffer.

set · iOS 15.0+

sourceColorTexture

TypeScript
setSourceColorTexture(value: SDKHandle): Promise<void>
Swift declaration
var sourceColorTexture: any MTLTexture

The rendered frame buffer.

get · iOS 15.0+

sourceDepthTexture

TypeScript
get sourceDepthTexture(): Promise<SDKHandle>
Swift declaration
var sourceDepthTexture: any MTLTexture

The frame’s depth buffer.

set · iOS 15.0+

sourceDepthTexture

TypeScript
setSourceDepthTexture(value: SDKHandle): Promise<void>
Swift declaration
var sourceDepthTexture: any MTLTexture

The frame’s depth buffer.

get · iOS 15.0+

targetColorTexture

TypeScript
get targetColorTexture(): Promise<SDKHandle>
Swift declaration
var targetColorTexture: any MTLTexture

The output texture where the postprocess callback writes the modified frame buffer.

set · iOS 15.0+

targetColorTexture

TypeScript
setTargetColorTexture(value: SDKHandle): Promise<void>
Swift declaration
var targetColorTexture: any MTLTexture

The output texture where the postprocess callback writes the modified frame buffer.

get · iOS 15.0+

time

TypeScript
get time(): Promise<number>
Swift declaration
var time: TimeInterval

The scene’s elapsed time.

set · iOS 15.0+

time

TypeScript
setTime(value: number): Promise<void>
Swift declaration
var time: TimeInterval

The scene’s elapsed time.

get · iOS 15.0+

device

TypeScript
get device(): Promise<SDKHandle>
Swift declaration
var device: any MTLDevice

The Metal device where the scene renders.

set · iOS 15.0+

device

TypeScript
setDevice(value: SDKHandle): Promise<void>
Swift declaration
var device: any MTLDevice

The Metal device where the scene renders.

init · iOS 15.0+

init

TypeScript
static init(device: SDKHandle, commandBuffer: SDKHandle, sourceColorTexture: SDKHandle, sourceDepthTexture: SDKHandle, targetColorTexture: SDKHandle, projection: SDKHandle, time: number): Promise<ARView_PostProcessContext>
Swift declaration
init(_ device: any MTLDevice, _ commandBuffer: any MTLCommandBuffer, _ sourceColorTexture: any MTLTexture, _ sourceDepthTexture: any MTLTexture, _ targetColorTexture: any MTLTexture, _ projection: float4x4, _ time: TimeInterval)

Creates a new context object. This initializer creates a new postprocess context object. RealityKit creates context objects and passes them to the postprocess render callback. Your code won’t usually need to create context objects directly. - Parameters: - device: The Metal device the view renders to. - commandBuffer: The Metal command buffer that encodes this view. - sourceColorTexture: A texture containing the rendered frame. - sourceDepthTexture: A texture containing the frame’s depth buffer. - targetColorTexture: A texture the callback function writes to. - projection: The projection matrix for this frame. - time: The current elapsed time.

Skipped declarations

No declarations were skipped in this snapshot.

All RealityKit types →