Skip to content

[MEDIUM] Performance: Temporal accumulation for branched flow #35

@pjt222

Description

@pjt222

Summary

Replace the simple 0.85 fade factor in the branched flow clear pass with proper temporal accumulation using double-buffered caustic textures. This allows tracing fewer rays per frame (8K-16K) while maintaining visual quality by accumulating deposits over 10-20 frames.

Current Behavior

  • Single caustic buffer with atomicAdd deposits and 0.85 multiplicative fade
  • Default 8K rays/frame (reduced from 32K) with fade-based persistence
  • High atomic contention at high ray counts

Proposed Change

  1. Create two caustic buffers (A and B)
  2. Each frame: read from A, deposit into a separate buffer, blend into B
  3. Blend pass: B[i] = alpha * A[i] + (1-alpha) * new_deposits[i]
  4. Swap A and B each frame
  5. Clear accumulation when laser parameters change (entry point, beam angle)

Acceptance Criteria

  • Double-buffered caustic texture implementation
  • Configurable accumulation factor (EMA alpha)
  • Automatic accumulation reset on laser parameter change
  • Visual quality equal or better than current approach at same ray count
  • All existing tests pass

Context

From deep review plan item 3.3. Estimated benefit: 4-8x fewer rays per frame for equivalent visual quality. Reduces both compute time and atomic contention.

Files: src/render/branched_flow.rs, src/render/shaders/branched_flow_compute.wgsl, src/render/pipeline.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestperformancePerformance optimizations

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions