Skip to content

watchOS: Metal-shader post-FX (chromatic aberration, film grain, sun shafts) #16

@proggeramlug

Description

@proggeramlug

Goal

Bloom's post-fx surface includes effects that need per-pixel Metal shaders to implement properly:

  • bloom_set_chromatic_aberration(strength) — sample R/G/B at slightly different positions
  • bloom_set_film_grain(strength) — time-animated noise overlay
  • 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:

  1. Compiles each .metal file with xcrun metal -c -target <triple> against the watchOS SDK.
  2. Links into a .metallib via xcrun metallib.
  3. 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.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions