Adding samples to a pixel
32-bit, display onlyThe sum of sample colors and the sample count of every pixel in the reference tracer.
Sums are kept in a Float64Array. A sample with a channel that is not finite is counted but not added; negative channels are clamped to 0.
function render({ spp = 1, s0 = 0, accum = null, aux = null, x0 = 0, y0 = 0, x1 = w, y1 = h, active = null } = {}) { // active (RN.7, pt-adapt.js): 0 = this pixel gets no sample
accum = accum || new Float64Array(w * h * 4);
if (STRIDE) aux = aux || new Float64Array(w * h * STRIDE * 4);
for (let s = s0; s < s0 + spp; s++) {
for (let py = y0; py < y1; py++) for (let px = x0; px < x1; px++) {
if (active && !active[py * w + px]) continue;
const c = radiance(px, py, s), o = (py * w + px) * 4;
const fine = Number.isFinite(c[0]) && Number.isFinite(c[1]) && Number.isFinite(c[2]);
if (fine) { accum[o] += Math.max(0, c[0]); accum[o + 1] += Math.max(0, c[1]); accum[o + 2] += Math.max(0, c[2]); }
accum[o + 3] += 1;
if (STRIDE && fine) {
const b = (py * w + px) * STRIDE * 4;
for (let i = 0; i < STRIDE * 4; i++) {
if (lit && i >= EL.IDS * 4 && i < EL.IDS * 4 + 4) { if (s === 0) aux[b + i] = AX[i]; continue; }
aux[b + i] += Number.isFinite(AX[i]) ? AX[i] : 0;
}
}
}
}
return STRIDE ? Object.assign(accum, { aux }) : accum;
}