ray tracing test
Prompt
Build a high-throughput, physically based, GPU-accelerated real-time path tracer in a single self-contained HTML file (using WebGL 2.0 / GLSL ES 3.00, EXT_color_buffer_float floating-point ping-pong FBOs with Multiple Render Targets, and zero external dependencies) engineered for modern mid-tier laptops with unified-memory integrated GPUs (e.g., Apple Silicon, Intel Iris Xe/Arc, AMD Radeon 680M/780M) that renders an interactive rain-slicked city alley featuring standing water puddles, dynamic wave ripples, wet material reflections, neon signage, and a physics-simulated swinging overhead lamp. 1. Scene & Physics Requirements Rain-Slicked Urban Alley Environment (Global Illumination): Construct a narrow, high-detail architectural alleyway bounded by weathered brick walls, concrete ledges, corrugated metal shutters/pipes, ventilation ducts, and an uneven asphalt/cobblestone ground plane. Illuminate the alley with vibrant emissive neon signs mounted along the walls (e.g., warm magenta, cyan, and amber light strips/tubes) alongside a hanging overhead alley lamp, creating rich multi-colored indirect bounce and long, anisotropic specular streaks across the wet ground. Physically Based Water Puddles & Wet Surface Materials: Standing Water Puddles & Ripples: Generate natural puddles in low-lying depressions of a procedural asphalt heightfield. Model the water surface as a true refractive/reflective dielectric interface (IOR = 1.333) with exact Schlick Fresnel reflectance, Snell refraction onto the submerged stone bed, Beer-Lambert depth-dependent absorption, and subtle refractive caustics. Real-Time 2D Wave Ripple Simulation: Run a GPU ping-pong 2D damped wave equation (RG32F height/velocity FBO) driven by periodic falling raindrops and user mouse clicks/drags on the puddles, computing analytical surface gradients to perturb water normals with realistic concentric ripples. Wet Porous & Metallic Materials (Dual-Lobe Wetness Model): Implement physically accurate surface wetness driven by a procedural height/porosity mask: porous materials (brick, mortar, concrete, asphalt) darken significantly when wet due to internal light trapping while gaining a thin dielectric water-film specular coating (IOR = 1.333) with reduced microfacet roughness, whereas slick metals (pipes, shutters, wet steel) exhibit tight, high-contrast GGX reflections. Physics-Simulated Swinging Alley Lamp (Dynamic Light Source): Suspend a heavy industrial pendant streetlamp from an overhead cable spanning the alley, featuring an opaque weathered-metal hood with a glossy inner reflector lining (which blocks and directs light downward) and a bright warm-white emissive filament bulb. Run a fixed-timestep physics simulation (240 Hz sub-stepped XPBD / Verlet solver with rigid-body angular momentum, gravity, ambient wind gusts, aerodynamic drag, and cable tension constraints). Allow the user to click-and-drag the swinging lamp in 3D space (via raycasted grab plane) or flick it with the mouse—as well as click on the alley floor to splash the puddles—casting real-time sweeping soft shadows, shifting water reflections, and dynamic color bounce across the wet walls. 2. GPU Path Tracing & Real-Time Reconstruction Pipeline Implement a hardware-accelerated Monte Carlo path tracing and spatiotemporal reconstruction pipeline tailored for unified-memory iGPUs—maximizing visual fidelity at 60 FPS without blurring crisp water reflections, neon highlights, or geometric edges: GPU Acceleration Structures & Procedural Micro-Detail: Flattened SAH BVH in Data Textures: Build a Surface Area Heuristic (SAH) Bounding Volume Hierarchy for static alley architecture (walls, ledges, pipes, ducts, neon fixtures, ground) and update the dynamic swinging lamp transform per frame, packing BVH nodes, primitive descriptors, and material parameters into RGBA32F / RGBA32UI Data Textures and Uniform Buffer Objects (UBO) for coalesced GPU fetches. Branchless Traversal & Exact Analytical Intersections: Use precomputed inverse ray directions (1.0 / dir), sign-ordered front-to-back child traversal, early-exit anyHit shadow queries, and exact analytical ray intersections (oriented boxes, cylinders/pipes, capped cones for the lamp hood, spheres, and displaced/height-masked ground planes) paired with procedural brick/asphalt normal and roughness perturbation. Unbiased Monte Carlo & Multi-Emitter Light Transport: Multi-Light Next Event Estimation (NEE): Explicitly sample direct illumination toward both the emissive swinging lamp bulb and the emissive neon tubes on every diffuse/glossy bounce using flux-weighted importance sampling, properly occluded by the lampshade and alley geometry. Multiple Importance Sampling (MIS): Combine NEE direct light sampling and BSDF sampling using the power heuristic to eliminate fireflies on wet glossy asphalt, puddles, and metallic pipes while keeping lighting unbiased. Physically Based Wet-Surface BSDFs: Implement Oren-Nayar / cosine-weighted Lambertian diffuse with porosity darkening, multi-layered GGX microfacet specular (substrate + Fresnel water clearcoat) with Smith masking-shadowing, and dielectric water transmission/reflection. Russian Roulette & Spatiotemporal QMC Sampling: Terminate low-throughput paths probabilistically after bounce 3 (1 / p rescaling) and drive sampling with per-frame Owen-scrambled Sobol / R2 low-discrepancy sequences decorrelated across screen pixels via interleaved gradient / blue-noise offsets. Spatiotemporal Variance-Guided Denoising (SVGF-Lite) & Post-Processing: MRT G-Buffer & Reflection-Aware Temporal Reprojection: Output world-space normals, linear depth, effective surface roughness, albedo, and analytical motion vectors via Multiple Render Targets (MRT). Reproject previous frames using neighborhood variance clamping (AABB clipping in YCoCg color space) modulated by surface roughness and water-ripple delta so glossy puddle reflections stay sharp without ghosting, transitioning to infinite progressive accumulation when motion settles. Multi-Pass Edge-Avoiding À-Trous Wavelet Filter: Execute a 3-to-4 pass À-Trous wavelet filter weighted by G-Buffer normal, depth, roughness, and luminance variance edge-stopping functions so low-SPP (2–4 SPP/frame) real-time frames reconstruct into clean, filmic imagery without smearing specular streaks or brick mortar detail. HDR Tone Mapping & Optical Bloom: Apply ACES Filmic tone mapping, physically plausible optical bloom around the emissive bulb, neon tubes, and bright water glints, plus accurate sRGB gamma encoding. 3. UI & Controls Display a minimal, non-intrusive HUD showing live FPS, frame time (ms), detected GPU renderer string (WEBGL_debug_renderer_info), effective rays/second (Mrays/s), samples per frame, and accumulated SPP. Include lightweight controls to: apply a wind gust / impulse to the swinging lamp, toggle Raindrops & Water Ripples, adjust Surface Wetness / Puddle Coverage (0%–100%), switch render views (SVGF Denoised / Raw Path Traced / G-Buffer Normals, Roughness & Wetness), adjust Samples Per Frame (1–8 SPP), adjust Max Bounce Depth (3–10), and switch Resolution Scaling (0.5x / 0.75x / 1.0x / Native DPR).
A system prompt was added to support web rendering
Response not available