PostProcessEffectContext
struct · iOS 26.0+ · SDK 27.1
struct PostProcessEffectContext<CommandBuffer>An object RealityKit passes data to a post process effect method. You can register a method that applies postprocessing effects to a scene RealityKit renders with a ``RealityView``. Once every frame, RealityKit calls that function before displaying the scene. You can use this to apply postprocess effects using any APIs that can modify an image texture. However, because RealityKit calls this method every frame, prioritize using 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 on top of the frame buffer, such as a SpriteKit scene. - 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 method takes a single `PostProcessEffectContext` parameter, which contains data the callback method needs to modify the rendered scene, including the frame buffer, depth map, and a property for writing the image you modify. The postprocess method in your ``PostProcessEffect`` type needs to encode to the output texture, or the frame is never displayed. A postprocess method looks like this: ```swift func postProcess(context: borrowing PostProcessEffectContext<MTLCommandBuffer>) { // Handle postprocessing here. } ``` To register a method as the postprocess render callback, add an implementation for ``PostProcessEffect/postProcess(context:)`` in your type that conforms to ``PostProcessEffect``: ```swift class LaplacianPostProcess: PostProcessEffect { // Post process callback. func postProcess(context: borrowing PostProcessEffectContext<MTLCommandBuffer>) { let filter = MPSImageLaplacian() filter.encode(commandBuffer: context.commandBuffer, sourceTexture: context.sourceColorTexture, destinationTexture: context.compatibleTargetTexture) } } ``` To stop postprocessing, you can set the ``RealityViewRenderingEffects/customPostProcessing`` property to ``RealityViewPostProcessEffect/none``. ```swift content.renderingEffects.customPostProcessing = .none ``` If your app turns postprocessing on and off frequently, another option for disabling postprocess effects is to keep your callbacks registered, but use an <doc://com.apple.documentation/metal/mtlblitcommandencoder> to encode the unmodified frame buffer directly to the output texture whenever postprocess effects aren’t active. ```swift var isEnabled: Binding<Bool> func postProcess(context: borrowing PostProcessEffectContext<MTLCommandBuffer>) { if isEnabled.wrappedValue { let filter = MPSImageLaplacian() filter.encode(commandBuffer: context.commandBuffer, sourceTexture: context.sourceColorTexture, destinationTexture: context.compatibleTargetTexture) } else { // Remove processing effects. let blitEncoder = context.commandBuffer.makeBlitCommandEncoder() blitEncoder?.copy(from: context.sourceColorTexture, to: context.targetColorTexture) blitEncoder?.endEncoding() } } ```
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
14 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
PostProcessEffectContext.device
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.device
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.commandBuffer
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.commandBuffer
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.sourceColorTexture
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.sourceColorTexture
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.sourceDepthTexture
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.sourceDepthTexture
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.targetColorTexture
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.targetColorTexture
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.projection
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.projection
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.time
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'
PostProcessEffectContext.time
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'PostProcessEffectContext<Any>' conform to 'Copyable'