postProcess(context:)
A method where you can implement postprocess effects.
Declaration
nonisolated mutating func postProcess(context: borrowing PostProcessEffectContext<any MTLCommandBuffer>)Discussion
RealityKit calls this method after rendering the main scene, but before it is drawn on the screen, ideal for performing screen-space effects or drawing overlays.
When registering a post processing effect, the callback function needs to encode the modified frame buffer to the context’s targetColorTexture, or nothing renders.
An empty implementation might look like this, which copies the sourceColorTexture directly to the targetColorTexture:
func postProcess(context: borrowing PostProcessEffectContext<MTLCommandBuffer>) {
// Post processing with no effect.
let blitEncoder = context.commandBuffer.makeBlitCommandEncoder()
blitEncoder?.copy(from: context.sourceColorTexture, to: context.targetColorTexture)
blitEncoder?.endEncoding()
}