Implementing special rendering effects with RealityKit postprocessing
At a glance
| Item | Summary |
|---|---|
| Purpose | Implement a variety of postprocessing techniques to alter RealityKit rendering. |
| App architecture | A C/Objective-C header, Metal, Swift sample with the source-visible chain AppDelegate → ContentView → Coordinator → RealityKit APIs. |
| Main patterns | Delegate or data-source callbacks, Coordinator, Binding-based state propagation |
| Project style | 19 scanned source file(s) across C/Objective-C header, Metal, Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | No structured execution marker indexed; callback threading requires source review. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper. |
| Key frameworks/packages | Foundation, RealityKit, SwiftUI, ARKit, MetalKit; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── RealityKitPostProcessing/
├── AppDelegate.swift
├── ContentView.swift
├── Application State/
│ ├── ApplicationState+Enums.swift
│ └── ApplicationState.swift
├── RealityView/
│ ├── RealityView.swift
│ ├── RealityView+CoachingView.swift
│ └── RealityViewContainer.swift
├── Kernel Functions/
│ ├── NightVision.h
│ ├── Pixelate.h
│ └── CustomPostProcess.metal
├── ARView+Utilities.swift
└── Bridging/
└── RealityKitPostProcessing-Bridging-Header.h
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: C/Objective-C header, Metal, Swift.
- The verified tree contains 3 project/configuration file(s) and 13 source declaration(s).
Overall architecture
flowchart LR
N1["AppDelegate"]
N2["ContentView"]
N3["Coordinator"]
N4["RealityKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
RealityKitPostProcessing/AppDelegate.swift:11 — architecture anchor
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let contentView = ContentView()
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
return true
}
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into RealityKit.
Ownership and state
classDiagram
AppDelegate o-- UIWindow : window
ContentView *-- ModeEntry : selection
SelectionCell o-- ModeEntry : entry
SelectionCell o-- ModeEntry : selectedEntry
Ownership evidence
RealityKitPostProcessing/AppDelegate.swift:14 — stored dependency or nearest verified ownership anchor
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
var window: UIWindow?
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
AppDelegate |
UIWindow (window) |
stores or receives | App/module collaborators |
ContentView |
ModeEntry (selection) |
owns wrapper-managed state | App/module collaborators |
SelectionCell |
ModeEntry (entry) |
stores or receives | Initialized by the owner; the binding is immutable |
SelectionCell |
ModeEntry (selectedEntry) |
borrows mutable state | The upstream binding owner is authoritative |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
No source-visible execution, scheduling, or synchronization boundary was found in the indexed source.
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | RealityKitPostProcessing/ContentView.swift:16 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | RealityKitPostProcessing/ARView+Utilities.swift:8 |
| Source import | RealityKit |
The cited file imports this module; runtime use and architectural role are not inferred. | RealityKitPostProcessing/ARView+Utilities.swift:9 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | RealityKitPostProcessing/AppDelegate.swift:9 |
| Source import | ARKit |
The cited file imports this module; runtime use and architectural role are not inferred. | RealityKitPostProcessing/ContentView.swift:12 |
| Source import | MetalKit |
The cited file imports this module; runtime use and architectural role are not inferred. | RealityKitPostProcessing/ContentView.swift:11 |
| Source import | metal_stdlib |
The cited file imports this module; runtime use and architectural role are not inferred. | RealityKitPostProcessing/Kernel Functions/CustomPostProcess.metal:8 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
RealityKitPostProcessing/AppDelegate.swift:12 — representative type boundary
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
var window: UIWindow?
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AppDelegate |
Receives callback-driven events | UIResponder, UIApplicationDelegate |
ContentView |
User-interface presentation and input forwarding | View |
RealityView |
User-interface presentation and input forwarding | ARView |
Coordinator |
Cross-object flow or session coordination | NSObject |
SelectionCell |
Represents a feature value or composable behavior | View |
CategoryEntry |
Represents a feature value or composable behavior | Identifiable, Hashable |
ModeEntry |
Represents a feature value or composable behavior | Identifiable, Hashable |
Category |
Defines a closed set of feature states or choices | UInt8, CaseIterable, CustomStringConvertible, Hashable |
Mode |
Defines a closed set of feature states or choices | UInt8, CaseIterable, CustomStringConvertible, Hashable |
RealityViewContainer |
Represents a feature value or composable behavior | UIViewRepresentable |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
postProcessUsingMetalShader (RealityKitPostProcessing/RealityView/RealityView+Metal.swift:105) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
configureWorldTracking (RealityKitPostProcessing/RealityView/RealityView.swift:76) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
setUpCoachingOverlay (RealityKitPostProcessing/RealityView/RealityView.swift:97) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
loadScene (RealityKitPostProcessing/RealityView/RealityView.swift:107) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
Reference code
RealityKitPostProcessing/RealityView/RealityView+Metal.swift:105 — representative boundary
private func postProcessUsingMetalShader(context: ARView.PostProcessContext,
pipeline: MTLComputePipelineState,
parameterHandler: MetalParameterSetup?) {
// ...
}Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Cross-object flow or session coordination | Coordinator |
The source’s Coordinator suffix makes this role explicit. |
| Receives callback-driven events | AppDelegate |
The source’s Delegate suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView, RealityView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Delegate or data-source callbacks | RealityKitPostProcessing/AppDelegate.swift:12 |
Callback protocols invert event delivery back into the sample’s owner. |
| Coordinator | RealityKitPostProcessing/RealityView/RealityViewContainer.swift:34 |
A role-named coordinator centralizes cross-object flow. |
| Binding-based state propagation | RealityKitPostProcessing/ContentView.swift:42 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
Naming conventions
- Types: Coordinator: Coordinator; Delegate: AppDelegate; View: ContentView, RealityView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
application,postProcessSetupCallback,configureWorldTracking,setUpCoachingOverlay,loadScene,setupPostProcessing,postProcess,postEffectNone. - Files:
RealityKitPostProcessing/AppDelegate.swift,RealityKitPostProcessing/ContentView.swift,RealityKitPostProcessing/RealityView/RealityView.swift,RealityKitPostProcessing/RealityView/RealityViewContainer.swift,RealityKitPostProcessing/Application State/ApplicationState.swift.
Architecture takeaways
AppDelegateis the main source-visible entry or composition anchor for this sample.- Framework work reaches RealityKit, SwiftUI, ARKit, MetalKit through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
RealityKitPostProcessing/AppDelegate.swift |
Cited implementation, AppDelegate, SwiftUI |
RealityKitPostProcessing/RealityView/RealityView+Metal.swift |
Cited implementation, Feature implementation |
RealityKitPostProcessing/RealityView/RealityView.swift |
Cited implementation, RealityView |
RealityKitPostProcessing/RealityView/RealityViewContainer.swift |
Coordinator, RealityViewContainer |
RealityKitPostProcessing/ContentView.swift |
Cited implementation, SwiftUI state property wrapper, ARKit, MetalKit, ContentView, SelectionCell, ContentView_Previews |
RealityKitPostProcessing/ARView+Utilities.swift |
Foundation, RealityKit, Feature implementation |
RealityKitPostProcessing/Kernel Functions/CustomPostProcess.metal |
metal_stdlib, Feature implementation |
RealityKitPostProcessing/Application State/ApplicationState+Enums.swift |
CategoryEntry, ModeEntry, Category, Mode |
RealityKitPostProcessing/RealityView/RealityView+CoachingView.swift |
Feature implementation |
RealityKitPostProcessing/Application State/ApplicationState.swift |
ApplicationState |
RealityKitPostProcessing/Kernel Functions/NightVision.h |
NightVisionArguments |
RealityKitPostProcessing/Kernel Functions/Pixelate.h |
PixelateArguments |
RealityKitPostProcessing/Bridging/RealityKitPostProcessing-Bridging-Header.h |
Feature implementation |
RealityKitPostProcessing/Kernel Functions/NightVision.metal |
Feature implementation |
RealityKitPostProcessing/Kernel Functions/Pixelate.metal |
Feature implementation |
RealityKitPostProcessing/Kernel Functions/PostProcessCommon.h |
Feature implementation |