Skip to content

turbobrian/foggy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Foggy

Volumetric fog for Apple Vision Pro using analytic integration — no ray marching.

visionOS Metal License

What It Does

Renders soft, glowing fog volumes that float in your physical room using CompositorServices + Metal. Each volume is a unit sphere with a radial density function integrated analytically along view rays via closed-form antiderivatives.

Density types:

  • Quadraticρ(r) = 1 - r², polynomial antiderivative
  • Gaussianρ(r) = exp(-3r²), erf-based antiderivative

The fog composites over passthrough in mixed immersion mode using Beer-Lambert transmittance and premultiplied alpha.

How It Works

  1. Fullscreen triangle per eye (vertex amplification for stereo)
  2. Fragment shader reconstructs world-space ray via VP inverse matrix
  3. For each fog volume: ray-sphere intersection → analytic density integral → Beer-Lambert transmittance
  4. Front-to-back compositing across overlapping volumes
  5. discard_fragment() for transparent pixels so passthrough shows through

Based on matejlou's analytic fog technique.

Build & Run

Requires Xcode 16+ with visionOS SDK 2.0+.

xcodebuild -project Foggy.xcodeproj -scheme Foggy \
  -destination 'platform=visionOS Simulator,name=Apple Vision Pro' build

Deploy to Apple Vision Pro via Xcode for the full experience with passthrough.

Project Structure

Foggy/
├── FoggyApp.swift                    # App entry, immersive space (mixed mode)
├── Renderer/
│   ├── FogRenderer.swift             # Metal pipeline, per-frame uniforms, render loop
│   ├── FogShaders.metal              # Vertex/fragment shaders, fog math
│   └── ShaderTypes.h                 # Shared CPU/GPU structs (bridging header)
├── Model/
│   ├── FogVolume.swift               # Volume definition (position, scale, color, density)
│   └── FogScene.swift                # Volume collection, animation
└── Interaction/
    └── SpatialInteraction.swift      # Spawn model (placeholder)

Key Technical Details

  • No ray marching — closed-form density integrals for both density types
  • CompositorServices — direct Metal rendering, not RealityKit
  • Reversed-Z depth — content must write depth > 0 for the compositor to display it
  • drawable.computeProjection(viewIndex:) — visionOS 2.0+ API (replaces deprecated view.tangents)
  • Residency sets — required on real device for GPU texture access
  • Render thread — uses Thread (not Task) to avoid blocking the main actor

About

Analytic volumetric fog for Apple Vision Pro — no ray marching

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors