VFX Spell Effects — Game-Quality Visual Effects for Apple Platforms
Decision Tree
What effect do you want?
|
|-- Smoke / Fog / Clouds?
| |-- Soft procedural blobs? -> Canvas noise blobs (like OCMiniOrb smoke)
| |-- Volumetric 3D fog? -> Ray marching (Metal fragment shader)
| |-- Quick particle smoke? -> SpriteKit SKEmitterNode or Vortex
| \-- Fluid dynamics? -> Metal compute (Navier-Stokes, advanced)
| -> See: references/smoke-fog.md
|
|-- Lightning / Electricity?
| |-- Single bolt? -> Midpoint displacement (most practical)
| |-- Smooth arc? -> Lissajous curves
| |-- Branching tree? -> Recursive fractal (Lichtenberg figures)
| \-- Glow on bolt? -> Additive bloom post-process
| -> See: references/lightning-electricity.md
|
|-- Particles (fire, sparks, magic)?
| |-- Quick preset? -> Vortex (SwiftUI-native)
| |-- 2D overlay? -> CAEmitterLayer or SpriteKit
| |-- Full GPU control? -> Metal compute shader pipeline
| |-- SwiftUI-only? -> Canvas + TimelineView
| -> See: references/particles.md
|
|-- Bloom / Glow / Post-processing?
| |-- SwiftUI quick glow? -> .shadow() + .blur() stacking
| |-- HDR bloom pipeline? -> Threshold -> Gaussian blur -> Composite (Metal)
| |-- Per-object glow? -> Render to texture + blur + additive blend
| -> See: references/bloom-glow.md
|
|-- Composing a full spell?
| |-- State machine? -> .idle -> .charging -> .casting -> .impact -> .dissipating
| |-- Layer ordering? -> base + particles + glow + screen shake + audio
| |-- Audio-reactive? -> Bind intensity to RMS amplitude
| -> See: references/spell-composition.md
|
\-- Performance issue?
|-- Dropped frames? -> Check particle count, blur radius, draw calls
|-- GPU bottleneck? -> Profile with Xcode GPU debugger
|-- CPU bottleneck? -> Move particle update to compute shader
-> See: Performance Budget Rules below
Quick Reference
| Effect |
Best API |
Approach |
Ref |
| Soft smoke blobs |
SwiftUI Canvas |
Noise-offset circles + alpha blend |
references/smoke-fog.md |
| Volumetric fog |
Metal fragment |
Ray march density field, 4-8 samples |
references/smoke-fog.md |
| Lightning bolt |
SwiftUI Canvas / Metal |
Midpoint displacement, 4-5 levels |
references/lightning-electricity.md |
| Branching lightning |
Canvas + recursion |
Fractal tree, angle +/-30deg |
references/lightning-electricity.md |
| Fire particles |
Vortex / SpriteKit |
Pre-built emitter, warm palette |
references/particles.md |
| Magic sparks |
Metal compute |
GPU particle pool, 500-2000 particles |
references/particles.md |
| Impact explosion |
Vortex + Canvas |
Burst emit + radial force + fade |
references/particles.md |
| Object glow |
SwiftUI .shadow |
Stacked .shadow(radius:) calls |
references/bloom-glow.md |
| HDR bloom |
Metal render pass |
Threshold + separable Gaussian + composite |
references/bloom-glow.md |
| Full spell |
Composite pattern |
State machine + layer stack + timeline |
references/spell-composition.md |
Performance Budget Rules (NON-NEGOTIABLE)
- 16ms frame budget -- Target 60fps. All VFX layers combined must complete within 16ms GPU + CPU time.
- Particle limits -- Mobile: 500-2000 active particles max. Desktop: up to 10,000 with compute shader. Never allocate mid-frame.
- Blur radius cap --
.blur(radius:) over 20pt on mobile tanks performance. Use downscaled render targets for large blurs.
- Draw call budget -- Keep under 10 draw calls for VFX overlay. Use Canvas (1 draw call per layer) or instanced rendering.
- Compute shader particles -- Mandatory for >500 particles. CPU-side
for loops over particle arrays cause frame drops on mobile.
- Ray march samples -- 4-8 samples per ray for real-time fog. More than 12 is offline-quality territory.
- Bloom passes -- 3-5 blur passes with ping-pong buffers. Downscale to half/quarter resolution for blur.
- Pool, never allocate -- Pre-allocate particle arrays. Use recycle-bin pattern (free list). Zero heap allocation during gameplay.
- Reduce motion --
@Environment(\.accessibilityReduceMotion) guards ALL effect starts. Provide static fallback.
- Profile on device -- Simulator GPU timing is meaningless. Test on oldest supported hardware.
Key Patterns
State Machine for Spell Lifecycle
enum SpellPhase: String, CaseIterable {
case idle, charging, casting, impact, dissipating
}
@Observable
class SpellState {
var phase: SpellPhase = .idle
var intensity: Float = 0.0 // 0.0-1.0
var elapsed: TimeInterval = 0.0
func advance(dt: TimeInterval) {
elapsed += dt
switch phase {
case .charging: intensity = min(1.0, Float(elapsed / 0.5))
case .casting: intensity = 1.0
case .impact: intensity = max(0.0, 1.0 - Float(elapsed / 0.3))
case .dissipating: intensity = max(0.0, 0.5 - Float(elapsed / 0.6))
case .idle: intensity = 0.0
}
}
}
Canvas-Based Effect Layer
struct EffectLayer: View {
let state: SpellState
@Environment(\.accessibilityReduceMotion) private var reduceMotion
var body: some View {
if !reduceMotion && state.phase != .idle {
TimelineView(.animation(minimumInterval: 1.0 / 60.0)) { ctx in
Canvas { context, size in
// Draw effect here -- single draw call
let t = ctx.date.timeIntervalSinceReferenceDate
drawEffect(context: context, size: size, time: t, intensity: state.intensity)
}
}
}
}
}
Midpoint Displacement Lightning (Minimal)
func generateBolt(from: CGPoint, to: CGPoint, levels: Int = 5, jaggedness: CGFloat = 0.4) -> [CGPoint] {
var points = [from, to]
for level in 0..<levels {
var newPoints = [points[0]]
let scale = jaggedness * pow(0.5, CGFloat(level))
for i in 0..<(points.count - 1) {
let mid = CGPoint(
x: (points[i].x + points[i+1].x) / 2 + CGFloat.random(in: -1...1) * scale * from.distance(to: to),
y: (points[i].y + points[i+1].y) / 2 + CGFloat.random(in: -1...1) * scale * from.distance(to: to)
)
newPoints.append(mid)
newPoints.append(points[i+1])
}
points = newPoints
}
return points
}
References
| File |
Content |
references/smoke-fog.md |
Noise-based smoke, ray marching fog, Canvas blobs, Metal fluid dynamics |
references/lightning-electricity.md |
Fractal midpoint displacement, Lissajous arcs, branching trees, glow rendering |
references/particles.md |
API comparison, GPU particle architecture, emission patterns, pool pattern, Vortex presets |
references/bloom-glow.md |
HDR bloom pipeline, threshold/blur/composite, Metal + SwiftUI integration |
references/spell-composition.md |
State machine, layer stacking, audio-reactive binding, timing curves, full spell examples |
External Resources
Related Skills
- orb -- OCMiniOrb implementation (smoke layer, fractal layer, glow compositing)
- swiftui-animation -- Animation curves, springs, Metal shader integration in SwiftUI
- swiftui-performance-audit -- Runtime GPU/CPU profiling when effects cause frame drops
Technique Map
- Effect type routing — Smoke/fog, lightning, particles, bloom, full spell; because each has distinct API and approach.
- State machine for lifecycle — idle→charging→casting→impact→dissipating; because spells have phases; state drives intensity.
- 16ms frame budget — 60fps non-negotiable; because dropped frames break immersion.
- Particle limits — 500-2000 mobile; 10k desktop with compute; because CPU particle loops tank mobile.
- Canvas for overlay — Single draw call per layer; because draw call budget matters.
- Pool, never allocate — Recycle bin pattern; because mid-frame allocation causes hitches.
- Reduce motion guard — Static fallback when accessibilityReduceMotion; because necessary for compliance.
- Midpoint displacement — For lightning; 4-5 levels; because simple, effective, performant.
Technique Notes
References: smoke-fog, lightning-electricity, particles, bloom-glow, spell-composition. APIs: Vortex, SpriteKit, Metal compute, Canvas. Profile on device; simulator GPU timing meaningless. Related: orb, swiftui-animation, swiftui-performance-audit.
Prompt Architect Overlay
Role Definition: VFX spell effects builder. Game-quality smoke, lightning, particles, bloom, spell composition. 60fps performance rules. Apple platforms.
Input Contract: Accepts effect type (smoke, lightning, fire, glow, full spell), target API (Vortex, Metal, Canvas), or performance issue. Platform, particle count, style.
Output Contract: Decision tree result. Quick reference row. Code pattern (state machine, canvas layer, midpoint displacement). Performance budget rules. Reference to deep-dive. Related skills.
Edge Cases & Fallbacks: If performance issue→check particle count, blur radius, draw calls. If >500 particles→compute shader mandatory. If bloom→downscale for blur passes. If reduce motion→guard all effects; provide static fallback.
1---2name: vfx-spell-effects3description: Build game-quality spell VFX on Apple platforms with practical recipes for smoke, lightning, particles, bloom, layering, and stable 60fps performance.4---56# VFX Spell Effects — Game-Quality Visual Effects for Apple Platforms78## Decision Tree910```11What effect do you want?12|13|-- Smoke / Fog / Clouds?14| |-- Soft procedural blobs? -> Canvas noise blobs (like OCMiniOrb smoke)15| |-- Volumetric 3D fog? -> Ray marching (Metal fragment shader)16| |-- Quick particle smoke? -> SpriteKit SKEmitterNode or Vortex17| \-- Fluid dynamics? -> Metal compute (Navier-Stokes, advanced)18| -> See: references/smoke-fog.md19|20|-- Lightning / Electricity?21| |-- Single bolt? -> Midpoint displacement (most practical)22| |-- Smooth arc? -> Lissajous curves23| |-- Branching tree? -> Recursive fractal (Lichtenberg figures)24| \-- Glow on bolt? -> Additive bloom post-process25| -> See: references/lightning-electricity.md26|27|-- Particles (fire, sparks, magic)?28| |-- Quick preset? -> Vortex (SwiftUI-native)29| |-- 2D overlay? -> CAEmitterLayer or SpriteKit30| |-- Full GPU control? -> Metal compute shader pipeline31| |-- SwiftUI-only? -> Canvas + TimelineView32| -> See: references/particles.md33|34|-- Bloom / Glow / Post-processing?35| |-- SwiftUI quick glow? -> .shadow() + .blur() stacking36| |-- HDR bloom pipeline? -> Threshold -> Gaussian blur -> Composite (Metal)37| |-- Per-object glow? -> Render to texture + blur + additive blend38| -> See: references/bloom-glow.md39|40|-- Composing a full spell?41| |-- State machine? -> .idle -> .charging -> .casting -> .impact -> .dissipating42| |-- Layer ordering? -> base + particles + glow + screen shake + audio43| |-- Audio-reactive? -> Bind intensity to RMS amplitude44| -> See: references/spell-composition.md45|46\-- Performance issue?47 |-- Dropped frames? -> Check particle count, blur radius, draw calls48 |-- GPU bottleneck? -> Profile with Xcode GPU debugger49 |-- CPU bottleneck? -> Move particle update to compute shader50 -> See: Performance Budget Rules below51```5253## Quick Reference5455| Effect | Best API | Approach | Ref |56|--------|----------|----------|-----|57| Soft smoke blobs | SwiftUI Canvas | Noise-offset circles + alpha blend | `references/smoke-fog.md` |58| Volumetric fog | Metal fragment | Ray march density field, 4-8 samples | `references/smoke-fog.md` |59| Lightning bolt | SwiftUI Canvas / Metal | Midpoint displacement, 4-5 levels | `references/lightning-electricity.md` |60| Branching lightning | Canvas + recursion | Fractal tree, angle +/-30deg | `references/lightning-electricity.md` |61| Fire particles | Vortex / SpriteKit | Pre-built emitter, warm palette | `references/particles.md` |62| Magic sparks | Metal compute | GPU particle pool, 500-2000 particles | `references/particles.md` |63| Impact explosion | Vortex + Canvas | Burst emit + radial force + fade | `references/particles.md` |64| Object glow | SwiftUI `.shadow` | Stacked `.shadow(radius:)` calls | `references/bloom-glow.md` |65| HDR bloom | Metal render pass | Threshold + separable Gaussian + composite | `references/bloom-glow.md` |66| Full spell | Composite pattern | State machine + layer stack + timeline | `references/spell-composition.md` |6768## Performance Budget Rules (NON-NEGOTIABLE)69701. **16ms frame budget** -- Target 60fps. All VFX layers combined must complete within 16ms GPU + CPU time.712. **Particle limits** -- Mobile: 500-2000 active particles max. Desktop: up to 10,000 with compute shader. Never allocate mid-frame.723. **Blur radius cap** -- `.blur(radius:)` over 20pt on mobile tanks performance. Use downscaled render targets for large blurs.734. **Draw call budget** -- Keep under 10 draw calls for VFX overlay. Use Canvas (1 draw call per layer) or instanced rendering.745. **Compute shader particles** -- Mandatory for >500 particles. CPU-side `for` loops over particle arrays cause frame drops on mobile.756. **Ray march samples** -- 4-8 samples per ray for real-time fog. More than 12 is offline-quality territory.767. **Bloom passes** -- 3-5 blur passes with ping-pong buffers. Downscale to half/quarter resolution for blur.778. **Pool, never allocate** -- Pre-allocate particle arrays. Use recycle-bin pattern (free list). Zero heap allocation during gameplay.789. **Reduce motion** -- `@Environment(\.accessibilityReduceMotion)` guards ALL effect starts. Provide static fallback.7910. **Profile on device** -- Simulator GPU timing is meaningless. Test on oldest supported hardware.8081## Key Patterns8283### State Machine for Spell Lifecycle8485```swift86enum SpellPhase: String, CaseIterable {87 case idle, charging, casting, impact, dissipating88}8990@Observable91class SpellState {92 var phase: SpellPhase = .idle93 var intensity: Float = 0.0 // 0.0-1.094 var elapsed: TimeInterval = 0.09596 func advance(dt: TimeInterval) {97 elapsed += dt98 switch phase {99 case .charging: intensity = min(1.0, Float(elapsed / 0.5))100 case .casting: intensity = 1.0101 case .impact: intensity = max(0.0, 1.0 - Float(elapsed / 0.3))102 case .dissipating: intensity = max(0.0, 0.5 - Float(elapsed / 0.6))103 case .idle: intensity = 0.0104 }105 }106}107```108109### Canvas-Based Effect Layer110111```swift112struct EffectLayer: View {113 let state: SpellState114 @Environment(\.accessibilityReduceMotion) private var reduceMotion115116 var body: some View {117 if !reduceMotion && state.phase != .idle {118 TimelineView(.animation(minimumInterval: 1.0 / 60.0)) { ctx in119 Canvas { context, size in120 // Draw effect here -- single draw call121 let t = ctx.date.timeIntervalSinceReferenceDate122 drawEffect(context: context, size: size, time: t, intensity: state.intensity)123 }124 }125 }126 }127}128```129130### Midpoint Displacement Lightning (Minimal)131132```swift133func generateBolt(from: CGPoint, to: CGPoint, levels: Int = 5, jaggedness: CGFloat = 0.4) -> [CGPoint] {134 var points = [from, to]135 for level in 0..<levels {136 var newPoints = [points[0]]137 let scale = jaggedness * pow(0.5, CGFloat(level))138 for i in 0..<(points.count - 1) {139 let mid = CGPoint(140 x: (points[i].x + points[i+1].x) / 2 + CGFloat.random(in: -1...1) * scale * from.distance(to: to),141 y: (points[i].y + points[i+1].y) / 2 + CGFloat.random(in: -1...1) * scale * from.distance(to: to)142 )143 newPoints.append(mid)144 newPoints.append(points[i+1])145 }146 points = newPoints147 }148 return points149}150```151152## References153154| File | Content |155|------|---------|156| `references/smoke-fog.md` | Noise-based smoke, ray marching fog, Canvas blobs, Metal fluid dynamics |157| `references/lightning-electricity.md` | Fractal midpoint displacement, Lissajous arcs, branching trees, glow rendering |158| `references/particles.md` | API comparison, GPU particle architecture, emission patterns, pool pattern, Vortex presets |159| `references/bloom-glow.md` | HDR bloom pipeline, threshold/blur/composite, Metal + SwiftUI integration |160| `references/spell-composition.md` | State machine, layer stacking, audio-reactive binding, timing curves, full spell examples |161162## External Resources163164- [Vortex](https://github.com/twostraws/Vortex) -- SwiftUI-native particle system165- [Inferno](https://github.com/twostraws/Inferno) -- Metal shader collection for SwiftUI166- [MetalNoise](https://github.com/jmade/MetalNoise) -- Perlin/Simplex noise in Metal167- [The Book of Shaders: Noise](https://thebookofshaders.com/11/) -- Noise function fundamentals168- [Ray Marching SDFs](https://jamie-wong.com/2016/07/15/ray-marching-signed-distance-functions/) -- Ray marching primer169- [2D Lightning Effects](https://gamedevelopment.tutsplus.com/tutorials/how-to-generate-shockingly-good-2d-lightning-effects--gamedev-2681) -- Midpoint displacement tutorial170- [LearnOpenGL: Bloom](https://learnopengl.com/Advanced-Lighting/Bloom) -- HDR bloom pipeline reference171- [Realtime Fire Rendering](https://andrewkchan.dev/posts/fire.html) -- Procedural fire techniques172173## Related Skills174175- **orb** -- OCMiniOrb implementation (smoke layer, fractal layer, glow compositing)176- **swiftui-animation** -- Animation curves, springs, Metal shader integration in SwiftUI177- **swiftui-performance-audit** -- Runtime GPU/CPU profiling when effects cause frame drops178## Technique Map179180- **Effect type routing** — Smoke/fog, lightning, particles, bloom, full spell; because each has distinct API and approach.181- **State machine for lifecycle** — idle→charging→casting→impact→dissipating; because spells have phases; state drives intensity.182- **16ms frame budget** — 60fps non-negotiable; because dropped frames break immersion.183- **Particle limits** — 500-2000 mobile; 10k desktop with compute; because CPU particle loops tank mobile.184- **Canvas for overlay** — Single draw call per layer; because draw call budget matters.185- **Pool, never allocate** — Recycle bin pattern; because mid-frame allocation causes hitches.186- **Reduce motion guard** — Static fallback when accessibilityReduceMotion; because necessary for compliance.187- **Midpoint displacement** — For lightning; 4-5 levels; because simple, effective, performant.188189## Technique Notes190191References: smoke-fog, lightning-electricity, particles, bloom-glow, spell-composition. APIs: Vortex, SpriteKit, Metal compute, Canvas. Profile on device; simulator GPU timing meaningless. Related: orb, swiftui-animation, swiftui-performance-audit.192193---194195## Prompt Architect Overlay196197**Role Definition:** VFX spell effects builder. Game-quality smoke, lightning, particles, bloom, spell composition. 60fps performance rules. Apple platforms.198199**Input Contract:** Accepts effect type (smoke, lightning, fire, glow, full spell), target API (Vortex, Metal, Canvas), or performance issue. Platform, particle count, style.200201**Output Contract:** Decision tree result. Quick reference row. Code pattern (state machine, canvas layer, midpoint displacement). Performance budget rules. Reference to deep-dive. Related skills.202203**Edge Cases & Fallbacks:** If performance issue→check particle count, blur radius, draw calls. If >500 particles→compute shader mandatory. If bloom→downscale for blur passes. If reduce motion→guard all effects; provide static fallback.