You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
watchOS: Metal-shader post-FX (chromatic aberration, film grain, sun shafts) #16
bloom_set_sun_shafts(...) — radial blur from light source
Today these are stored in watchOS but visually no-op. SwiftUI on watchOS 10+ supports .colorEffect(Shader(function:args:)) which runs Metal shader code against a view's rasterized content.
Scope
Perry-side
Add a new native-library manifest field metal_sources (array of paths) alongside the existing swift_sources. Perry:
Compiles each .metal file with xcrun metal -c -target <triple> against the watchOS SDK.
Links into a .metallib via xcrun metallib.
Copies the .metallib into .app/default.metallib so ShaderLibrary.default picks it up.
Bloom-side
native/watchos/src/shaders/: three .metal files — chromatic_aberration.metal, film_grain.metal, sun_shafts.metal. Each exports a [[ stitchable ]] half4 <name>(float2 position, half4 color) function.
BloomWatchApp.swift reads the effect strengths from bloom_watchos_postfx_state, wraps the root view with .colorEffect(Shader(function: .init(library: .default, name: "..."), arguments: [...])) per enabled effect.
Film grain needs time as a shader arg; sun shafts need the sun position in NDC.
Acceptance
bloom_set_chromatic_aberration(0.5) visibly offsets R/G/B channels near screen edges. bloom_set_film_grain(0.3) overlays animated noise. bloom_set_sun_shafts(...) produces radial light streaks from the sun direction.
Update: Perry landed metal_sources (PerryTS/perry#124 → v0.5.146) and the bloom-side shader file is written + stored — native/watchos/shaders/bloom_postfx.metal with three [[ stitchable ]] functions for chromatic aberration, film grain, and sun shafts. bloom_set_* state carries through to a PostFxState snapshot the Swift side can read.
Blocker: SwiftUI's shader-consumer modifiers — .colorEffect(Shader), .layerEffect(Shader), ShaderLibrary — are iOS 17+ / tvOS 17+ / macOS 14+ only. Apple deliberately excluded watchOS. Even with the .metallib correctly bundled (the Perry pipeline works), there's no SwiftUI-level way to attach the shaders to a view on the watch.
Three paths forward, ordered by realism:
SCNTechnique-based post-process — SceneKit's pass-based Metal pipeline is available on watchOS. Can load shader functions from default.metallib and apply them as post-passes over the SceneView output. Only processes the 3D layer (2D Canvas overlay would render unaffected over the top), but that's what post-fx is actually for in most games. Filing as a follow-up.
Custom MTLCommandQueue offscreen render + SwiftUI bridge — much more invasive, basically replaces SceneView entirely. Probably not worth the complexity.
Wait for Apple to ship SwiftUI Shader APIs on watchOS — filed an Apple Feedback, no ETA.
Committed the infrastructure + doc comment explaining all this in BloomWatchApp.swift. Keeping this issue open and filing #18 for the SCNTechnique path.
Activity
proggeramlug commentedon Apr 22, 2026
Update: Perry landed
metal_sources(PerryTS/perry#124 → v0.5.146) and the bloom-side shader file is written + stored —native/watchos/shaders/bloom_postfx.metalwith three[[ stitchable ]]functions for chromatic aberration, film grain, and sun shafts.bloom_set_*state carries through to a PostFxState snapshot the Swift side can read.Blocker: SwiftUI's shader-consumer modifiers —
.colorEffect(Shader),.layerEffect(Shader),ShaderLibrary— are iOS 17+ / tvOS 17+ / macOS 14+ only. Apple deliberately excluded watchOS. Even with the.metallibcorrectly bundled (the Perry pipeline works), there's no SwiftUI-level way to attach the shaders to a view on the watch.Three paths forward, ordered by realism:
SCNTechnique-based post-process — SceneKit's pass-based Metal pipeline is available on watchOS. Can load shader functions from
default.metalliband apply them as post-passes over the SceneView output. Only processes the 3D layer (2D Canvas overlay would render unaffected over the top), but that's what post-fx is actually for in most games. Filing as a follow-up.Custom MTLCommandQueue offscreen render + SwiftUI bridge — much more invasive, basically replaces SceneView entirely. Probably not worth the complexity.
Wait for Apple to ship SwiftUI Shader APIs on watchOS — filed an Apple Feedback, no ETA.
Committed the infrastructure + doc comment explaining all this in
BloomWatchApp.swift. Keeping this issue open and filing #18 for the SCNTechnique path.Commit: [f572f26]
feat(watchos): delta-sync retained scene + Metal post-fx shader source
feat(watchos): SCNTechnique scaffold for post-fx (#16/#18)