@pmndrs/reflections
    Preparing search index...

    Variable BILATERAL_FILL_WGSLConst

    BILATERAL_FILL_WGSL: "\n// ---- bilateralFill (core/bilateral/fill.ts) ----\nstruct BilateralSurface {\n position: vec3f, // world\n normal: vec3f, // world, unit\n roughness: f32, // perceptual\n valid: bool, // false: background / off screen (never taps, never filled)\n};\nstruct BilateralTap {\n surface: BilateralSurface,\n radiance: vec4f, // rgb + world ray length (the FFX radiance layout)\n hitDistance: f32,\n confidence: f32,\n source: u32, // weight 0 unless bit 'source' of sourceMask is set\n spatial: f32, // the includer's spatial weight (1 flat, bilinear for an upsample); 0 drops the tap\n};\nstruct BilateralWeights {\n planeTolerance: f32,\n normalPower: f32,\n roughnessTolerance: f32,\n sourceMask: u32,\n minWeightSum: f32,\n};\nstruct BilateralResult {\n radiance: vec4f,\n hitDistance: f32,\n confidence: f32,\n source: u32, // the source code with the largest weight share\n weightSum: f32, // compare with minWeightSum: below it, don't use the result\n taps: u32, // taps with weight > 0\n};\n\nfn bilateralWeight(p: BilateralSurface, viewDistance: f32, q: BilateralTap, w: BilateralWeights) -> f32 {\n if (!q.surface.valid || q.spatial <= 0.0 || q.source >= 8u) { return 0.0; }\n if (((w.sourceMask >> q.source) & 1u) == 0u) { return 0.0; }\n var weight = q.spatial;\n if (w.planeTolerance > 0.0) {\n let d = abs(dot(p.normal, q.surface.position - p.position));\n weight *= saturate(1.0 - d / max(w.planeTolerance * viewDistance, 1e-20));\n }\n if (w.normalPower > 0.0) {\n weight *= pow(saturate(dot(p.normal, q.surface.normal)), w.normalPower);\n }\n if (w.roughnessTolerance > 0.0) {\n weight *= saturate(1.0 - abs(p.roughness - q.surface.roughness) / w.roughnessTolerance);\n }\n return weight;\n}\n\n// The gather, split by coverage: class 1 = taps with confidence >= 0.5 (hits), class 0 = the rest\n// (misses). Per class: sum w, sum w x radiance.rgb, sum w x confidence, and confidence-weighted\n// sums of the ray length and hit distance (a miss's t is 0 by convention, not a distance).\nstruct BilateralClass {\n weight: f32,\n rgb: vec3f,\n confidence: f32,\n tWeight: f32, // sum w x confidence\n rayLength: f32, // sum w x confidence x radiance.w\n hitDistance: f32, // sum w x confidence x hitDistance\n taps: u32,\n perSource: array<f32, 8>,\n};\nstruct BilateralClasses { c: array<BilateralClass, 2> };\n\nfn bilateralGatherClasses(p: BilateralSurface, cameraPosition: vec3f, pixel: vec2i, originCell: vec2i, footprint: u32, w: BilateralWeights) -> BilateralClasses {\n var g: BilateralClasses;\n let viewDistance = length(p.position - cameraPosition);\n let lo = select(-1, 0, footprint == 2u);\n let hi = select(1, 2, footprint == 4u);\n for (var j = lo; j <= hi; j++) {\n for (var i = lo; i <= hi; i++) {\n let q = bilateralTap(originCell + vec2i(i, j), pixel);\n let wq = bilateralWeight(p, viewDistance, q, w);\n if (wq <= 0.0) { continue; }\n let k = select(0u, 1u, q.confidence >= 0.5);\n let wc = wq * q.confidence;\n g.c[k].weight += wq;\n g.c[k].rgb += wq * q.radiance.rgb;\n g.c[k].confidence += wc;\n g.c[k].tWeight += wc;\n g.c[k].rayLength += wc * q.radiance.w;\n g.c[k].hitDistance += wc * q.hitDistance;\n g.c[k].taps += 1u;\n g.c[k].perSource[q.source] += wq;\n }\n }\n return g;\n}\n\n// One class (or both merged) to a result: rgb and confidence by weight, ray length and hit distance\n// by weight x confidence, the source with the largest weight share.\nfn bilateralResolve(a: BilateralClass, b: BilateralClass) -> BilateralResult {\n var r: BilateralResult;\n r.weightSum = a.weight + b.weight;\n r.taps = a.taps + b.taps;\n if (r.weightSum > 0.0) {\n r.radiance = vec4f((a.rgb + b.rgb) / r.weightSum, 0.0);\n r.confidence = (a.confidence + b.confidence) / r.weightSum;\n }\n let tw = a.tWeight + b.tWeight;\n if (tw > 0.0) {\n r.radiance.w = (a.rayLength + b.rayLength) / tw;\n r.hitDistance = (a.hitDistance + b.hitDistance) / tw;\n }\n var best = 0.0;\n for (var s = 0u; s < 8u; s++) {\n let v = a.perSource[s] + b.perSource[s];\n if (v > best) { best = v; r.source = s; }\n }\n return r;\n}\n\n// Linear: every tap. Radiance and confidence are the weighted means; the ray length and hit distance\n// are means over the taps' hits (weighted by confidence), so two hits and two misses give confidence\n// 0.5 at the hits' distance, not at half of it.\nfn bilateralFill(p: BilateralSurface, cameraPosition: vec3f, pixel: vec2i, originCell: vec2i, footprint: u32, w: BilateralWeights) -> BilateralResult {\n var g = bilateralGatherClasses(p, cameraPosition, pixel, originCell, footprint, w); // var: runtime class index\n return bilateralResolve(g.c[0], g.c[1]);\n}\n\n// Majority coverage: the class (hits or misses) with the larger weight wins and the result is that\n// class alone, so mixed neighbours never produce a partial confidence (which a depth-aware blend\n// such as the three composite's D2400 reads as a thickness falloff) and the source is that class's.\n// weightSum is the total over both classes (the minWeightSum gate), taps the winner's.\nfn bilateralFillMajority(p: BilateralSurface, cameraPosition: vec3f, pixel: vec2i, originCell: vec2i, footprint: u32, w: BilateralWeights) -> BilateralResult {\n var g = bilateralGatherClasses(p, cameraPosition, pixel, originCell, footprint, w); // var: runtime class index\n var empty: BilateralClass;\n let k = select(0u, 1u, g.c[1].weight >= g.c[0].weight);\n var r = bilateralResolve(g.c[k], empty);\n r.weightSum = g.c[0].weight + g.c[1].weight;\n return r;\n}\n\n// Stochastic coverage (W74 review): the hit class wins with probability = its weight share, decided by\n// the caller's uniform random number u in [0, 1) (a hash of pixel and frame). Like the majority, a\n// result is one class (no partial confidence from mixing, t from hits only, that class's source); unlike\n// it, the expected confidence equals the neighbours' weighted hit share. In a glossy reflection the\n// hit / miss mix is stochastic, not a geometric edge: a majority vote pushed a 29 % hit share toward\n// misses (contact: filled px -11 % in the raw signal). The temporal noise this adds is the denoiser's.\nfn bilateralFillStochastic(p: BilateralSurface, cameraPosition: vec3f, pixel: vec2i, originCell: vec2i, footprint: u32, w: BilateralWeights, u: f32) -> BilateralResult {\n var g = bilateralGatherClasses(p, cameraPosition, pixel, originCell, footprint, w); // var: runtime class index\n var empty: BilateralClass;\n let total = g.c[0].weight + g.c[1].weight;\n let k = select(0u, 1u, u * total < g.c[1].weight);\n var r = bilateralResolve(g.c[k], empty);\n r.weightSum = total;\n return r;\n}\n" = ...

    The kernel. Defines BilateralSurface, BilateralTap, BilateralWeights, BilateralResult, bilateralWeight, bilateralFill (linear) and bilateralFillMajority (one coverage class, W74 review); needs the includer's bilateralTap(cell, pixel).