Casual Shadertoy Path Tracing 1: Basic Camera, Diffuse, Emissive
path-tracingray-tracingshadertoyglslcomputer-graphicsrendering
Abstraction: Beginner path tracing tutorial implemented in Shadertoy GLSL shaders
Key points:
- Path tracing is ray tracing with recursive random bounces; pixels accumulate emissive * throughput where throughput is multiplied by each surface's albedo on each bounce
- Camera ray setup: pixel coordinates mapped to -1..+1, aspect ratio correction applied, FOV controls imaginary pixel plane distance (1 unit = 90° FOV)
- Cosine-weighted hemisphere sampling for diffuse bounce: get random unit vector, add to surface normal, normalize — equivalent to importance sampling of the cosine term
- Random number generation uses Wang hash (fast bit-manipulation hash) seeded per pixel and frame; random unit vectors generated from random spherical coordinates
- Multi-pass averaging: Buffer A accumulates per-frame renders using
mix(lastFrame, currentFrame, 1/(frameN+1)); 8 bounces, emissive sphere as light source, environment cubemap for missed rays
Connections: Shadertoy · Path Tracing · Ray Tracing · Computer Graphics
Source: https://blog.demofox.org/2020/05/25/casual-shadertoy-path-tracing-1-basic-camera-diffuse-emissive/