HIT_WGSL: "\nstruct Hit {\n t: f32,\n triangle: u32,\n barycentrics: vec2f,\n material: u32,\n instance: u32,\n normal: vec3f,\n frontFace: bool,\n}\nfn noHit() -> Hit { return Hit(-1.0, 0xffffffffu, vec2f(0.0), 0xffffffffu, 0xffffffffu, vec3f(0.0), true); }\n\nstruct HitMaterial {\n albedo: vec3f,\n emissive: vec3f,\n}\n\n// The specular lobe of a traced hit (W41, D3510): F0 (linear; mix(0.04, base, metalness) for a\n// metal-rough material), perceptual roughness, and a clear coat layer (three's / glTF's\n// KHR_materials_clearcoat: F0 0.04 over the base, factor and perceptual roughness).\nstruct HitSpecular {\n color: vec3f,\n roughness: f32,\n clearcoat: f32,\n clearcoatRoughness: f32,\n}\n\n// Karis 2014 (mobile) analytic fit of the split-sum DFG term: F0 x A + B, at NdotV and perceptual\n// roughness. Close to three's DFGLUT for the hit's one sample; no texture needed in the trace pass.\nfn hitEnvBRDF(f0: vec3f, roughness: f32, NdotV: f32) -> vec3f {\n let r = roughness * vec4f(-1.0, -0.0275, -0.572, 0.022) + vec4f(1.0, 0.0425, 1.04, -0.04);\n let a004 = min(r.x * r.x, exp2(-9.28 * NdotV)) * r.x + r.y;\n let ab = vec2f(-1.04, 1.04) * a004 + r.zw;\n return f0 * ab.x + ab.y;\n}\n\n// What leaves a traced hit toward the ray origin, given its diffuse radiance (emissive excluded) and\n// the environment along the mirror direction at the base and clear coat roughness: three's\n// split-sum IBL (F0 x A + B) on the base, the clear coat layered on top as three does\n// (base x (1 - clearcoat x Fcc) + clearcoat x coat), Fcc = Schlick(0.04, 1, NdotV).\nfn hitLayered(s: HitSpecular, diffuse: vec3f, envBase: vec3f, envCoat: vec3f, NdotV: f32) -> vec3f {\n let base = diffuse + envBase * hitEnvBRDF(s.color, s.roughness, NdotV);\n let fcc = 0.04 + 0.96 * pow(1.0 - NdotV, 5.0);\n let coat = envCoat * hitEnvBRDF(vec3f(0.04), s.clearcoatRoughness, NdotV);\n return base * (1.0 - s.clearcoat * fcc) + s.clearcoat * coat;\n}\n\n// Filtered importance sampling at a hit (W45, D3550; Colbert & Krivanek 2007, Stachowiak 2015's\n// pre-convolved hit colour): a ray sampled from a glossy pixel's lobe stands for that lobe's whole\n// cone, so the hit's own lobe looks its radiance up wider by the ray's spread: alpha^2 + spread,\n// spread = (k x the reflecting pixel's alpha)^2, set by the pass before it shades (0: as sampled).\n// The mean is unchanged (a prefilter is a convolution); what goes is the rare very bright sample\n// (a softbox seen sharply through a mirror floor) that the denoiser clips as a firefly.\nvar<private> hitLobeSpread: f32 = 0.0;\nfn hitLookupRoughness(roughness: f32) -> f32 {\n let a = roughness * roughness;\n return min(1.0, sqrt(sqrt(a * a + hitLobeSpread)));\n}\n" = ...