@driftengine/core 4.1.4 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.json +3812 -3770
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +7 -1
  4. package/dist/render/backend/webgl2/renderer.d.ts +15 -0
  5. package/dist/render/backend/webgl2/renderer.js +28 -7
  6. package/dist/render/backend/webgpu/pointShadowPass.d.ts +4 -0
  7. package/dist/render/backend/webgpu/pointShadowPass.js +10 -0
  8. package/dist/render/backend/webgpu/renderer.js +11 -6
  9. package/dist/render/depthConvention.d.ts +19 -0
  10. package/dist/render/depthConvention.js +21 -0
  11. package/dist/render/livePointShadowSet.js +8 -0
  12. package/dist/render/pointShadowBudget.js +59 -5
  13. package/dist/render/pointShadowImage.d.ts +40 -0
  14. package/dist/render/pointShadowImage.js +20 -0
  15. package/dist/render/pointShadowMap.d.ts +4 -0
  16. package/dist/render/pointShadowMap.js +10 -0
  17. package/dist/render/pointShadowSystem.js +9 -0
  18. package/dist/render/renderQuality.d.ts +27 -4
  19. package/dist/render/renderQuality.js +1 -1
  20. package/dist/render/shaders/flat/main.d.ts +1 -1
  21. package/dist/render/shaders/flat/main.js +13 -5
  22. package/dist/render/shaders/flat/pointShadow.d.ts +1 -1
  23. package/dist/render/shaders/flat/pointShadow.js +42 -30
  24. package/dist/render/shaders/flat/preamble.js +26 -2
  25. package/dist/render/shaders/generated/flat.wgsl.d.ts +16 -16
  26. package/dist/render/shaders/generated/flat.wgsl.js +24 -24
  27. package/dist/render/shaders/sky.d.ts +10 -6
  28. package/dist/render/shaders/sky.js +35 -2
  29. package/dist/render/textRenderer.js +23 -4
  30. package/package.json +6 -6
  31. package/src/index.ts +11 -1
  32. package/src/render/backend/webgl2/renderer.ts +28 -7
  33. package/src/render/backend/webgpu/pointShadowPass.ts +13 -0
  34. package/src/render/backend/webgpu/renderer.ts +16 -10
  35. package/src/render/depthConvention.ts +22 -0
  36. package/src/render/livePointShadowSet.ts +7 -0
  37. package/src/render/pointShadowBudget.ts +58 -5
  38. package/src/render/pointShadowImage.ts +51 -0
  39. package/src/render/pointShadowMap.ts +13 -0
  40. package/src/render/pointShadowSystem.ts +8 -0
  41. package/src/render/renderQuality.ts +28 -5
  42. package/src/render/shaders/flat/main.ts +13 -5
  43. package/src/render/shaders/flat/pointShadow.ts +42 -30
  44. package/src/render/shaders/flat/preamble.ts +26 -2
  45. package/src/render/shaders/generated/flat.wgsl.ts +24 -24
  46. package/src/render/shaders/sky.ts +37 -2
  47. package/src/render/textRenderer.ts +23 -14
@@ -1 +1 @@
1
- export declare const POINTSHADOW_GLSL = "float pointShadow(\n highp sampler2DArray maps,\n float layer,\n vec3 toFrag,\n float far,\n float near,\n float sourceRadius\n) {\n /*\n * The receiver's own distance, and it is the *radius* now rather than a cube face's local Z.\n *\n * That difference removes two things. Every tap of an angular disk shares this one number,\n * where a cube needed each tap's own face-local Z recomputed \u2014 offsets changed it, and\n * comparing them all against the centre ray drew repeated wedges on large receivers. And the\n * stored value converts with a multiply instead of the perspective divide, which used to\n * magnify whatever error the sample arrived with, worst near the far plane.\n */\n float dist = length(toFrag);\n\n /*\n * A receiver nearer than the near plane is not shadowed at all.\n *\n * The near plane already says \"nothing this close to the source is rendered into the\n * map\", and a caller raises it so a fixture does not shadow its own housing. That was\n * only ever applied to *casters*, so a surface inside the same distance still went\n * through the comparison \u2014 against a map that, by the caller's own instruction, holds\n * nothing about anything near it.\n *\n * Reported on a ceiling with recessed strip lights hung a hand's width below it: shadows\n * that \"go on and off\" as the camera moves. The seams that made it unmissable are gone;\n * the gate stays, because comparing against a map that holds nothing is still wrong.\n *\n * The gate is the caller's own number rather than a new constant. A consumer that wants\n * the surface right beside its lamp to take a shadow can lower it, which is the same\n * knob and the same meaning it has always had for the other side of the transaction.\n */\n if (dist <= near) return 1.0;\n\n // Modest depth bias only. The heavy lifting is done by offsetting the\n // sample position along the surface normal before this is called \u2014 see the\n // call site \u2014 which is the cure for grazing receivers that depth bias alone\n // cannot fix without peter-panning.\n float bias = 0.04 + dist * 0.015;\n\n /*\n * Penumbra from the emitter's actual size.\n *\n * A shadow's softness is not a constant: it is set by how large the source is\n * and how far the caster stands from the surface it falls on. Find the\n * occluder with a centre tap, then widen the filter by\n * sourceRadius * (receiver - occluder) / occluder \u2014 the real geometry of a\n * penumbra. A bulb stays crisp; a flame goes soft with distance, which is\n * what makes a fire read as a fire rather than a large lamp.\n *\n * textureLod(..., 0.0), not the implicit-derivative texture() call this replaced.\n * pointShadowArray.ts allocates the array with texStorage3D at one storage level,\n * NEAREST both filters \u2014 there is no mip to select, so the two calls fetch the\n * identical texel. Not a quality trade; the output is bit-for-bit the same.\n *\n * It matters because implicit derivatives are only well-defined under *uniform*\n * control flow, and this sits inside the light loop below. See AGENTS.md, 2026-08-07.\n */\n float centreStored = textureLod(maps, vec3(octEncode(toFrag), layer), 0.0).r;\n float occluderDistance = centreStored >= 0.9999 ? dist : centreStored * far;\n float spread = max(dist - occluderDistance, 0.0) / max(occluderDistance, 0.05);\n /*\n * Softness comes from *fading the shadow*, not from widening the filter.\n *\n * Four attempts went into widening it, and the fourth is what identified why\n * none of them worked. The decisive observation was that the light pool looked\n * right until a column entered it. With no occluder the penumbra estimate is zero,\n * the filter stays at its floor, and the light pool is clean. The instant a\n * column is found the filter widens \u2014 and a wide angular filter on a *cube*\n * map is what crossed face seams. The artefact was never the columns' shadows;\n * it was the search for their penumbra.\n *\n * The map has no seams now, so the cap could open. It has not, in this change:\n * the storage moved and nothing else did, and the widening is a picture decision\n * taken against a tree that already renders correctly.\n */\n float radius = clamp(sourceRadius * spread, 0.01, MAX_FILTER_RADIUS) + 0.012;\n\n /*\n * How much of a shadow survives, as well as how soft it is.\n *\n * This is the half that was missing, and it is why widening the filter never\n * fixed anything. A penumbra does not merely blur with distance from its\n * caster \u2014 it *takes over*. Far enough from the occluder, relative to how big\n * the source is, every point on the receiver can see part of the flame and\n * there is no umbra left at all: the shadow is gone, not blurry.\n *\n * Without it, two columns lit by a brazier threw full-strength edges fifteen\n * metres across the terrace, and the gap between them read as a spotlight cone\n * with straight sides rather than as a fire. Three attempts in, the note that\n * unlocked it was that the pool should still fade naturally at its rim \u2014 a\n * description of the falloff, not of the blur.\n */\n float penumbra = clamp(sourceRadius * spread * PENUMBRA_FADE, 0.0, 1.0);\n float strength = 1.0 - penumbra * penumbra;\n\n /*\n * Taps are placed on a disk *perpendicular to the light ray*, turned by half a golden\n * angle on every other column of pixels.\n *\n * Offsetting the ray by fixed 3D vectors was the earlier approach and it has\n * two faults that only show on a wide filter. The offsets are not\n * perpendicular to the ray, so part of each one moves the sample along its own\n * depth instead of across the shadow; and twelve *fixed* taps at a large\n * radius align, so the penumbra breaks into hard straight bands following the\n * tap pattern \u2014 reported, on a brazier behind a rank of columns, as strange\n * straight lines across the light pool.\n *\n * **The cure for that was a per-fragment hash, and it is what made the penumbra\n * stipple.** Twelve taps are a coarse estimate of how much of the emitter this point can\n * see; turning them by an unrelated angle at every pixel makes each pixel's error\n * independent of its neighbour's, which is the definition of noise. Something has to\n * average that back out, and this engine's lit pass is the last thing to touch the frame \u2014\n * there is no blur and no temporal resolve behind it, so the noise reached the screen. Two\n * games reported the same coarse cross-hatch across a light pool.\n *\n * **So the turn comes from a two-pixel tile instead, and the pair is averaged afterwards.**\n * A pixel's own x parity picks one of two tap sets half a golden angle apart, and\n * `main` folds the pair together once the light loop is over \u2014 see the resolve there. The\n * pair's twenty-four taps are the filter; each pixel pays for twelve of them.\n *\n * **A *column* pair rather than a 2x2 square, and that was measured rather than assumed.**\n * Four turns on a square tile, resolved with both derivatives, came back at 3.88 against this\n * pair's 2.46 on the same build \u2014 because the second derivative hands the lower row of a quad\n * the upper row's difference on hardware that answers a coarse derivative, and with four turns\n * that is the wrong difference. Two turns keyed on the column alone make it the right one,\n * which is why the tile's shape and the resolve are one decision rather than two.\n *\n * **Neither half works alone**, which is the same pairing `ambientOcclusion.ts` describes\n * between its rotation tile and its blur. Measured on `demo/dev/pointshadow.html` at\n * `?exposure=6`, as mean absolute luminance difference to the right and down neighbour over\n * the mover's penumbra, on WebGL2: **4.60** for the per-fragment hash this replaces, **2.88**\n * for this tile with no resolve \u2014 and a one-pixel vertical comb in the picture, which is the\n * tile itself on screen \u2014 against **2.37** for the pair resolved. A frame with the shadow\n * switched off measures 0.81, and WebGPU answers 4.56 and 2.33 for the same two builds.\n *\n * **Unchanged by the move to an octahedral map, and that is the point.** The offsets are\n * angular perturbations of a direction, so every tap is still a direction and octEncode is\n * defined on all of them. Nothing offsets in UV, so the map's border needs no wrap\n * arithmetic and a tap that would have crossed a cube join lands on the adjacent texel.\n */\n vec3 fwd = normalize(toFrag);\n vec3 up = abs(fwd.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);\n vec3 tu = normalize(cross(up, fwd));\n vec3 tv = cross(fwd, tu);\n /*\n * Integer arithmetic, because this is a lattice: a shader compiler is free to implement\n * `mod(x, 2.0)` as a multiply by a reciprocal, and a GPU here answers 3 for `3.0 % 3.0`.\n * `gl_FragCoord.x` is the pixel's centre, so truncating it is the pixel's own column.\n */\n float angle = float(int(gl_FragCoord.x) & 1) * PCF_PAIR_TURN;\n float ca = cos(angle);\n float sa = sin(angle);\n\n float lit = 0.0;\n for (int i = 0; i < 12; i++) {\n if (i >= uShadowFilterTaps) break;\n vec2 disk = PCF_OFFSETS[i];\n vec2 turned = vec2(disk.x * ca - disk.y * sa, disk.x * sa + disk.y * ca);\n // Perpendicular to the ray, and *not* scaled by its length: the offsets are\n // an angular perturbation of a direction, which is what the encoding takes.\n vec3 sampleDir = toFrag + (tu * turned.x + tv * turned.y) * radius;\n float stored = textureLod(maps, vec3(octEncode(sampleDir), layer), 0.0).r;\n if (stored >= 0.9999) {\n // Beyond the far plane nothing was rendered: treat as lit.\n lit += 1.0;\n continue;\n }\n float storedDistance = stored * far;\n if (dist - bias > storedDistance) {\n // A point shadow cannot outlive the finite light that casts it, so its\n // occlusion fades smoothly before the light's far plane.\n lit += 1.0 - shadowReach(max(dist - storedDistance, 0.0), far);\n } else {\n lit += 1.0;\n }\n }\n float shaded = lit / float(max(uShadowFilterTaps, 1));\n // Fade the whole shadow toward lit as the penumbra swallows it.\n return mix(1.0, shaded, strength);\n}\n\n/**\n * The same filter for a source that has a *shape* rather than a radius.\n *\n * **One map from the rectangle's centre, and the rectangle's own extent as the filter's shape.**\n * That is the whole difference from `pointShadow` above, and it is what makes the result read as\n * one wide emitter rather than as a lamp: a bulb's penumbra is round, so a row of nine of them\n * gives nine round shadows that pile up darker where they overlap, and a strip's penumbra is a\n * strip \u2014 soft along the cable, tight across it, one shadow with one soft edge.\n *\n * **The taps land on the emitter's silhouette as this fragment sees it**, which is the part a\n * scalar radius cannot express. The rectangle's two axes are projected onto the plane across the\n * light ray and each keeps its own width, so the sample pattern is an ellipse rather than a disk,\n * and a rectangle seen edge-on along one axis has no penumbra in that direction \u2014 which is correct\n * and is what a strip light actually does. Four dot products and two square roots more than the\n * round filter.\n *\n * **The fade is driven by the *narrower* projected half extent, and the reason is a strip.** A\n * penumbra does not only blur a shadow, it takes over: past the point where every part of the\n * receiver can see part of the emitter there is no umbra left. Driven by the wider extent, a\n * three-metre cable would delete its own shadow at a metre of caster clearance \u2014 but across the\n * cable the source is nearly a line, so an umbra band survives there and only the length is\n * smeared. `min` keeps that band; `max` would erase it.\n *\n * **What it costs** is a second copy of the tap loop, about 30 lines, compiled into the eight\n * permutations that carry point shadows. Folding the two into one loop was the alternative and was\n * not taken: the shared form has to multiply the disk offset by a width before scaling the axis\n * rather than after, which is a different rounding order on every tap of the *point* path \u2014 so the\n * saving is paid for by perturbing eight scenes that currently gate at zero pixels, in a change\n * about area lights. `docs/IMPROVEMENTS.md` carries the row.\n *\n * **What would make it wrong** is a rectangle much wider than its distance to the caster, where\n * different points on the emitter genuinely see different silhouettes and no single map from the\n * centre stands in for all of them \u2014 a ceiling-wide panel a hand's width above a table. The honest\n * answer there is several maps across the emitter, which is several bakes.\n */\nfloat areaShadow(\n highp sampler2DArray maps,\n float layer,\n vec3 toFrag,\n float far,\n float near,\n vec3 right,\n vec3 up,\n vec2 halfSize\n) {\n float dist = length(toFrag);\n /* The near plane says nothing this close to the emitter was rendered; see `pointShadow`. */\n if (dist <= near) return 1.0;\n\n float bias = 0.04 + dist * 0.015;\n\n /*\n * The blocker search, one tap along the centre ray, exactly as the round filter does it. Similar\n * triangles turn the two distances into how much wider than the emitter the penumbra is.\n *\n * `textureLod(..., 0.0)` rather than `texture()`: the array carries one storage level and\n * NEAREST both filters, so the two fetch the identical texel \u2014 and this sits inside the area\n * light loop, which is not provably uniform control flow. See AGENTS.md, 2026-08-07.\n */\n float centreStored = textureLod(maps, vec3(octEncode(toFrag), layer), 0.0).r;\n float occluderDistance = centreStored >= 0.9999 ? dist : centreStored * far;\n float spread = max(dist - occluderDistance, 0.0) / max(occluderDistance, 0.05);\n\n vec3 fwd = toFrag / dist;\n /*\n * Each axis with its along-the-ray component removed: the rectangle's outline flattened onto the\n * plane the taps move in. The lengths that come back are the foreshortening \u2014 1 for a rectangle\n * seen face-on, 0 for one seen exactly edge-on along that axis \u2014 so the two widths below carry\n * both the emitter's size and how much of it this fragment can see.\n */\n vec3 acrossX = right - fwd * dot(right, fwd);\n vec3 acrossY = up - fwd * dot(up, fwd);\n float seenX = length(acrossX);\n float seenY = length(acrossY);\n /*\n * A collapsed axis offsets nothing rather than offsetting along an arbitrary direction. Both\n * cannot collapse at once: `right` and `up` are perpendicular, so a ray parallel to one of\n * them is perpendicular to the other.\n */\n vec3 alongX = seenX > 1e-5 ? acrossX / seenX : vec3(0.0);\n vec3 alongY = seenY > 1e-5 ? acrossY / seenY : vec3(0.0);\n\n float halfX = halfSize.x * seenX;\n float halfY = halfSize.y * seenY;\n /* The same ceiling and the same floor the round filter uses, per axis. See MAX_FILTER_RADIUS. */\n float widthX = min(halfX * spread, MAX_FILTER_RADIUS) + 0.012;\n float widthY = min(halfY * spread, MAX_FILTER_RADIUS) + 0.012;\n\n /* The narrower half extent, for the reason in the header: it is what keeps a strip's umbra. */\n float penumbra = clamp(min(halfX, halfY) * spread * PENUMBRA_FADE, 0.0, 1.0);\n float strength = 1.0 - penumbra * penumbra;\n\n /*\n * Turned inside the unit disk *before* the ellipse maps it, so the half-turn that separates\n * the two halves of a pixel pair survives the anisotropy. The same two-pixel tile the round\n * filter uses and for the same reasons \u2014 see `pointShadow`, which carries the measurement;\n * a rectangle's shadow stippled exactly as a lamp's did, because it is the same twelve taps.\n */\n float angle = float(int(gl_FragCoord.x) & 1) * PCF_PAIR_TURN;\n float ca = cos(angle);\n float sa = sin(angle);\n\n float lit = 0.0;\n for (int i = 0; i < 12; i++) {\n if (i >= uShadowFilterTaps) break;\n vec2 disk = PCF_OFFSETS[i];\n vec2 turned = vec2(disk.x * ca - disk.y * sa, disk.x * sa + disk.y * ca);\n vec3 sampleDir = toFrag + alongX * (turned.x * widthX) + alongY * (turned.y * widthY);\n float stored = textureLod(maps, vec3(octEncode(sampleDir), layer), 0.0).r;\n if (stored >= 0.9999) {\n /* Beyond the far plane nothing was rendered: treat as lit. */\n lit += 1.0;\n continue;\n }\n float storedDistance = stored * far;\n if (dist - bias > storedDistance) {\n /* An area light's occlusion cannot outlive the map that carries it either. */\n lit += 1.0 - shadowReach(max(dist - storedDistance, 0.0), far);\n } else {\n lit += 1.0;\n }\n }\n float shaded = lit / float(max(uShadowFilterTaps, 1));\n return mix(1.0, shaded, strength);\n}\n#endif\n\nout vec4 outColor;\n\n\n/** 0 none, 1 sRGB, 2 ACES then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n return linearToSrgb(c);\n}\n\n\n/**\n * A fixed Poisson disk avoids the grid-shaped edge left by square 3x3 PCF.\n * Directional and point shadows consume the same maximum filter-tap budget;\n * their texture sizes differ because one is a 2D projection of a frustum and one\n * is an octahedral projection of the whole sphere, not because one is a lower\n * quality tier.\n */\n#if DIRECTIONAL_SHADOWS\nconst vec2 DIRECTIONAL_PCF_OFFSETS[12] = vec2[12](\n vec2(-0.326, -0.406), vec2( 0.519, 0.767), vec2( 0.962, -0.195), vec2(-0.696, 0.457),\n vec2(-0.840, -0.074), vec2( 0.185, -0.893), vec2( 0.896, 0.412), vec2(-0.203, 0.621),\n vec2( 0.473, -0.480), vec2( 0.507, 0.064), vec2(-0.322, -0.933), vec2(-0.792, -0.598)\n);\n\n/** Anything outside the light frustum or beyond its far plane counts as lit. */";
1
+ export declare const POINTSHADOW_GLSL = "/**\n * How much of one tap's occlusion survives its own penumbra.\n *\n * **How much of a shadow survives, as well as how soft it is.** A penumbra does not merely blur\n * with distance from its caster, it *takes over*: far enough from the occluder, relative to how\n * big the source is, every point on the receiver can see part of the flame and there is no umbra\n * left at all. The shadow is gone, not blurry. Without it, two columns lit by a brazier threw\n * full-strength edges fifteen metres across the terrace, and the gap between them read as a\n * spotlight cone with straight sides rather than as a fire.\n *\n * **Per tap, and it was once for the whole filter, taken from the centre tap alone.** That is a\n * blocker search of one sample standing in for twelve, and it is right wherever the taps agree \u2014\n * inside an umbra they all find the same occluder, so this returns exactly what the shared value\n * did, and the umbra is unchanged to the bit. It is wrong exactly where they disagree, which is\n * the silhouette: there the centre ray *misses*, so the search reports no occluder, the spread is\n * zero and the fade is switched off \u2014 while the taps that do land on the caster then draw at full\n * strength. What that paints is a hard one-texel line around a shadow whose interior has\n * correctly faded to nothing.\n *\n * Reported as shadows \"faded out but NOT shadow outlines, generating long lines around the\n * world\", and on a brazier as a bare square outline lying on the ground with no shadow inside it.\n *\n * **What it costs** is two multiplies and a divide per occluded tap, against a tap that has\n * already paid for a texture fetch. **What would make it wrong** is a filter wide enough that one\n * tap's occluder is not the occluder a neighbouring tap is estimating for, which is the same\n * limit the shared value had and is what `MAX_FILTER_RADIUS` bounds.\n */\nfloat tapStrength(float receiverDistance, float occluderDistance, float sourceRadius) {\n float spread = max(receiverDistance - occluderDistance, 0.0) / max(occluderDistance, 0.05);\n float penumbra = clamp(sourceRadius * spread * PENUMBRA_FADE, 0.0, 1.0);\n return 1.0 - penumbra * penumbra;\n}\n\nfloat pointShadow(\n highp sampler2DArray maps,\n float layer,\n vec3 toFrag,\n float far,\n float near,\n float sourceRadius\n) {\n /*\n * The receiver's own distance, and it is the *radius* now rather than a cube face's local Z.\n *\n * That difference removes two things. Every tap of an angular disk shares this one number,\n * where a cube needed each tap's own face-local Z recomputed \u2014 offsets changed it, and\n * comparing them all against the centre ray drew repeated wedges on large receivers. And the\n * stored value converts with a multiply instead of the perspective divide, which used to\n * magnify whatever error the sample arrived with, worst near the far plane.\n */\n float dist = length(toFrag);\n\n /*\n * A receiver nearer than the near plane is not shadowed at all.\n *\n * The near plane already says \"nothing this close to the source is rendered into the\n * map\", and a caller raises it so a fixture does not shadow its own housing. That was\n * only ever applied to *casters*, so a surface inside the same distance still went\n * through the comparison \u2014 against a map that, by the caller's own instruction, holds\n * nothing about anything near it.\n *\n * Reported on a ceiling with recessed strip lights hung a hand's width below it: shadows\n * that \"go on and off\" as the camera moves. The seams that made it unmissable are gone;\n * the gate stays, because comparing against a map that holds nothing is still wrong.\n *\n * The gate is the caller's own number rather than a new constant. A consumer that wants\n * the surface right beside its lamp to take a shadow can lower it, which is the same\n * knob and the same meaning it has always had for the other side of the transaction.\n */\n if (dist <= near) return 1.0;\n\n // Modest depth bias only. The heavy lifting is done by offsetting the\n // sample position along the surface normal before this is called \u2014 see the\n // call site \u2014 which is the cure for grazing receivers that depth bias alone\n // cannot fix without peter-panning.\n float bias = 0.04 + dist * 0.015;\n\n /*\n * Penumbra from the emitter's actual size.\n *\n * A shadow's softness is not a constant: it is set by how large the source is\n * and how far the caster stands from the surface it falls on. Find the\n * occluder with a centre tap, then widen the filter by\n * sourceRadius * (receiver - occluder) / occluder \u2014 the real geometry of a\n * penumbra. A bulb stays crisp; a flame goes soft with distance, which is\n * what makes a fire read as a fire rather than a large lamp.\n *\n * textureLod(..., 0.0), not the implicit-derivative texture() call this replaced.\n * pointShadowArray.ts allocates the array with texStorage3D at one storage level,\n * NEAREST both filters \u2014 there is no mip to select, so the two calls fetch the\n * identical texel. Not a quality trade; the output is bit-for-bit the same.\n *\n * It matters because implicit derivatives are only well-defined under *uniform*\n * control flow, and this sits inside the light loop below. See AGENTS.md, 2026-08-07.\n */\n float centreStored = textureLod(maps, vec3(octEncode(toFrag), layer), 0.0).r;\n float occluderDistance = centreStored >= 0.9999 ? dist : centreStored * far;\n float spread = max(dist - occluderDistance, 0.0) / max(occluderDistance, 0.05);\n /*\n * Softness comes from *fading the shadow*, not from widening the filter.\n *\n * Four attempts went into widening it, and the fourth is what identified why\n * none of them worked. The decisive observation was that the light pool looked\n * right until a column entered it. With no occluder the penumbra estimate is zero,\n * the filter stays at its floor, and the light pool is clean. The instant a\n * column is found the filter widens \u2014 and a wide angular filter on a *cube*\n * map is what crossed face seams. The artefact was never the columns' shadows;\n * it was the search for their penumbra.\n *\n * The map has no seams now, so the cap could open. It has not, in this change:\n * the storage moved and nothing else did, and the widening is a picture decision\n * taken against a tree that already renders correctly.\n */\n float radius = clamp(sourceRadius * spread, 0.01, MAX_FILTER_RADIUS) + 0.012;\n\n /*\n * Taps are placed on a disk *perpendicular to the light ray*, turned by half a golden\n * angle on every other column of pixels.\n *\n * Offsetting the ray by fixed 3D vectors was the earlier approach and it has\n * two faults that only show on a wide filter. The offsets are not\n * perpendicular to the ray, so part of each one moves the sample along its own\n * depth instead of across the shadow; and twelve *fixed* taps at a large\n * radius align, so the penumbra breaks into hard straight bands following the\n * tap pattern \u2014 reported, on a brazier behind a rank of columns, as strange\n * straight lines across the light pool.\n *\n * **The cure for that was a per-fragment hash, and it is what made the penumbra\n * stipple.** Twelve taps are a coarse estimate of how much of the emitter this point can\n * see; turning them by an unrelated angle at every pixel makes each pixel's error\n * independent of its neighbour's, which is the definition of noise. Something has to\n * average that back out, and this engine's lit pass is the last thing to touch the frame \u2014\n * there is no blur and no temporal resolve behind it, so the noise reached the screen. Two\n * games reported the same coarse cross-hatch across a light pool.\n *\n * **So the turn comes from a two-pixel tile instead, and the pair is averaged afterwards.**\n * A pixel's own x parity picks one of two tap sets half a golden angle apart, and\n * `main` folds the pair together once the light loop is over \u2014 see the resolve there. The\n * pair's twenty-four taps are the filter; each pixel pays for twelve of them.\n *\n * **A *column* pair rather than a 2x2 square, and that was measured rather than assumed.**\n * Four turns on a square tile, resolved with both derivatives, came back at 3.88 against this\n * pair's 2.46 on the same build \u2014 because the second derivative hands the lower row of a quad\n * the upper row's difference on hardware that answers a coarse derivative, and with four turns\n * that is the wrong difference. Two turns keyed on the column alone make it the right one,\n * which is why the tile's shape and the resolve are one decision rather than two.\n *\n * **Neither half works alone**, which is the same pairing `ambientOcclusion.ts` describes\n * between its rotation tile and its blur. Measured on `demo/dev/pointshadow.html` at\n * `?exposure=6`, as mean absolute luminance difference to the right and down neighbour over\n * the mover's penumbra, on WebGL2: **4.60** for the per-fragment hash this replaces, **2.88**\n * for this tile with no resolve \u2014 and a one-pixel vertical comb in the picture, which is the\n * tile itself on screen \u2014 against **2.37** for the pair resolved. A frame with the shadow\n * switched off measures 0.81, and WebGPU answers 4.56 and 2.33 for the same two builds.\n *\n * **Unchanged by the move to an octahedral map, and that is the point.** The offsets are\n * angular perturbations of a direction, so every tap is still a direction and octEncode is\n * defined on all of them. Nothing offsets in UV, so the map's border needs no wrap\n * arithmetic and a tap that would have crossed a cube join lands on the adjacent texel.\n */\n vec3 fwd = normalize(toFrag);\n vec3 up = abs(fwd.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);\n vec3 tu = normalize(cross(up, fwd));\n vec3 tv = cross(fwd, tu);\n /*\n * Integer arithmetic, because this is a lattice: a shader compiler is free to implement\n * `mod(x, 2.0)` as a multiply by a reciprocal, and a GPU here answers 3 for `3.0 % 3.0`.\n * `gl_FragCoord.x` is the pixel's centre, so truncating it is the pixel's own column.\n */\n float angle = float(int(gl_FragCoord.x) & 1) * PCF_PAIR_TURN;\n float ca = cos(angle);\n float sa = sin(angle);\n\n float lit = 0.0;\n for (int i = 0; i < 12; i++) {\n if (i >= uShadowFilterTaps) break;\n vec2 disk = PCF_OFFSETS[i];\n vec2 turned = vec2(disk.x * ca - disk.y * sa, disk.x * sa + disk.y * ca);\n // Perpendicular to the ray, and *not* scaled by its length: the offsets are\n // an angular perturbation of a direction, which is what the encoding takes.\n vec3 sampleDir = toFrag + (tu * turned.x + tv * turned.y) * radius;\n float stored = textureLod(maps, vec3(octEncode(sampleDir), layer), 0.0).r;\n if (stored >= 0.9999) {\n // Beyond the far plane nothing was rendered: treat as lit.\n lit += 1.0;\n continue;\n }\n float storedDistance = stored * far;\n if (dist - bias > storedDistance) {\n // A point shadow cannot outlive the finite light that casts it, so its\n // occlusion fades smoothly before the light's far plane.\n float reach = shadowReach(max(dist - storedDistance, 0.0), far);\n lit += 1.0 - reach * tapStrength(dist, storedDistance, sourceRadius);\n } else {\n lit += 1.0;\n }\n }\n return lit / float(max(uShadowFilterTaps, 1));\n}\n\n/**\n * The same filter for a source that has a *shape* rather than a radius.\n *\n * **One map from the rectangle's centre, and the rectangle's own extent as the filter's shape.**\n * That is the whole difference from `pointShadow` above, and it is what makes the result read as\n * one wide emitter rather than as a lamp: a bulb's penumbra is round, so a row of nine of them\n * gives nine round shadows that pile up darker where they overlap, and a strip's penumbra is a\n * strip \u2014 soft along the cable, tight across it, one shadow with one soft edge.\n *\n * **The taps land on the emitter's silhouette as this fragment sees it**, which is the part a\n * scalar radius cannot express. The rectangle's two axes are projected onto the plane across the\n * light ray and each keeps its own width, so the sample pattern is an ellipse rather than a disk,\n * and a rectangle seen edge-on along one axis has no penumbra in that direction \u2014 which is correct\n * and is what a strip light actually does. Four dot products and two square roots more than the\n * round filter.\n *\n * **The fade is driven by the *narrower* projected half extent, and the reason is a strip.** A\n * penumbra does not only blur a shadow, it takes over: past the point where every part of the\n * receiver can see part of the emitter there is no umbra left. Driven by the wider extent, a\n * three-metre cable would delete its own shadow at a metre of caster clearance \u2014 but across the\n * cable the source is nearly a line, so an umbra band survives there and only the length is\n * smeared. `min` keeps that band; `max` would erase it.\n *\n * **What it costs** is a second copy of the tap loop, about 30 lines, compiled into the eight\n * permutations that carry point shadows. Folding the two into one loop was the alternative and was\n * not taken: the shared form has to multiply the disk offset by a width before scaling the axis\n * rather than after, which is a different rounding order on every tap of the *point* path \u2014 so the\n * saving is paid for by perturbing eight scenes that currently gate at zero pixels, in a change\n * about area lights. `docs/IMPROVEMENTS.md` carries the row.\n *\n * **What would make it wrong** is a rectangle much wider than its distance to the caster, where\n * different points on the emitter genuinely see different silhouettes and no single map from the\n * centre stands in for all of them \u2014 a ceiling-wide panel a hand's width above a table. The honest\n * answer there is several maps across the emitter, which is several bakes.\n */\nfloat areaShadow(\n highp sampler2DArray maps,\n float layer,\n vec3 toFrag,\n float far,\n float near,\n vec3 right,\n vec3 up,\n vec2 halfSize\n) {\n float dist = length(toFrag);\n /* The near plane says nothing this close to the emitter was rendered; see `pointShadow`. */\n if (dist <= near) return 1.0;\n\n float bias = 0.04 + dist * 0.015;\n\n /*\n * The blocker search, one tap along the centre ray, exactly as the round filter does it. Similar\n * triangles turn the two distances into how much wider than the emitter the penumbra is.\n *\n * `textureLod(..., 0.0)` rather than `texture()`: the array carries one storage level and\n * NEAREST both filters, so the two fetch the identical texel \u2014 and this sits inside the area\n * light loop, which is not provably uniform control flow. See AGENTS.md, 2026-08-07.\n */\n float centreStored = textureLod(maps, vec3(octEncode(toFrag), layer), 0.0).r;\n float occluderDistance = centreStored >= 0.9999 ? dist : centreStored * far;\n float spread = max(dist - occluderDistance, 0.0) / max(occluderDistance, 0.05);\n\n vec3 fwd = toFrag / dist;\n /*\n * Each axis with its along-the-ray component removed: the rectangle's outline flattened onto the\n * plane the taps move in. The lengths that come back are the foreshortening \u2014 1 for a rectangle\n * seen face-on, 0 for one seen exactly edge-on along that axis \u2014 so the two widths below carry\n * both the emitter's size and how much of it this fragment can see.\n */\n vec3 acrossX = right - fwd * dot(right, fwd);\n vec3 acrossY = up - fwd * dot(up, fwd);\n float seenX = length(acrossX);\n float seenY = length(acrossY);\n /*\n * A collapsed axis offsets nothing rather than offsetting along an arbitrary direction. Both\n * cannot collapse at once: `right` and `up` are perpendicular, so a ray parallel to one of\n * them is perpendicular to the other.\n */\n vec3 alongX = seenX > 1e-5 ? acrossX / seenX : vec3(0.0);\n vec3 alongY = seenY > 1e-5 ? acrossY / seenY : vec3(0.0);\n\n float halfX = halfSize.x * seenX;\n float halfY = halfSize.y * seenY;\n /* The same ceiling and the same floor the round filter uses, per axis. See MAX_FILTER_RADIUS. */\n float widthX = min(halfX * spread, MAX_FILTER_RADIUS) + 0.012;\n float widthY = min(halfY * spread, MAX_FILTER_RADIUS) + 0.012;\n\n /*\n * Turned inside the unit disk *before* the ellipse maps it, so the half-turn that separates\n * the two halves of a pixel pair survives the anisotropy. The same two-pixel tile the round\n * filter uses and for the same reasons \u2014 see `pointShadow`, which carries the measurement;\n * a rectangle's shadow stippled exactly as a lamp's did, because it is the same twelve taps.\n */\n float angle = float(int(gl_FragCoord.x) & 1) * PCF_PAIR_TURN;\n float ca = cos(angle);\n float sa = sin(angle);\n\n float lit = 0.0;\n for (int i = 0; i < 12; i++) {\n if (i >= uShadowFilterTaps) break;\n vec2 disk = PCF_OFFSETS[i];\n vec2 turned = vec2(disk.x * ca - disk.y * sa, disk.x * sa + disk.y * ca);\n vec3 sampleDir = toFrag + alongX * (turned.x * widthX) + alongY * (turned.y * widthY);\n float stored = textureLod(maps, vec3(octEncode(sampleDir), layer), 0.0).r;\n if (stored >= 0.9999) {\n /* Beyond the far plane nothing was rendered: treat as lit. */\n lit += 1.0;\n continue;\n }\n float storedDistance = stored * far;\n if (dist - bias > storedDistance) {\n /* An area light's occlusion cannot outlive the map that carries it either. */\n float reach = shadowReach(max(dist - storedDistance, 0.0), far);\n /* The narrower half extent, for the reason in the header: it is what keeps a strip's\n umbra. Per tap, for the reason `tapStrength` gives. */\n lit += 1.0 - reach * tapStrength(dist, storedDistance, min(halfX, halfY));\n } else {\n lit += 1.0;\n }\n }\n return lit / float(max(uShadowFilterTaps, 1));\n}\n#endif\n\nout vec4 outColor;\n\n\n/** 0 none, 1 sRGB, 2 ACES then sRGB. See renderQuality.ts. */\nuniform int uOutputTransform;\n/** Scales the scene into the tone curve. 1 is the reference grade. See renderQuality.ts. */\nuniform float uOutputExposure;\n\n/*\n * ACES: the reference fit, not the cheap one.\n *\n * This was Narkowicz's single rational function, on the argument that the difference from\n * the reference curve is invisible next to the gain. That argument holds for a look and\n * fails for a *match*, which is what this option is for \u2014 aces exists so a world ported\n * from three.js reads the same, and three.js applies the full fit: into AP1 through\n * ACESInputMat, the RRT and ODT together, then back out through ACESOutputMat.\n *\n * The two curves are not a shade apart. Narkowicz is markedly brighter through the\n * midtones, which is exactly where an interior scene lives, and it is a large part of a\n * measured ~1.7x that survived correcting the colour space and the missing Lambert pi.\n * An approximation of a standard is the wrong thing to hold when the standard is the\n * specification.\n */\nvec3 rrtAndOdtFit(vec3 v) {\n vec3 a = v * (v + 0.0245786) - 0.000090537;\n vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n}\n\nvec3 acesFilmic(vec3 x) {\n /*\n * Exposure first, because a tone curve is only defined relative to one.\n *\n * The reference RRT and ODT are graded for a dark cinema. Every renderer that ships ACES\n * scales its input to suit whatever it is actually shown on, and the factor each one\n * picks is a *look*, not a standard - so this engine takes no position and reads it from\n * the caller. Neutral by default, which is the reference grade unmodified. three.js's own\n * pick is 1 / 0.6, for a consumer matching one.\n */\n x *= uOutputExposure;\n // Columns, as GLSL reads them: sRGB -> XYZ -> D65_2_D60 -> AP1 -> RRT_SAT.\n const mat3 ACES_INPUT = mat3(\n 0.59719, 0.07600, 0.02840,\n 0.35458, 0.90834, 0.13383,\n 0.04823, 0.01566, 0.83777\n );\n // ODT_SAT -> XYZ -> D60_2_D65 -> sRGB.\n const mat3 ACES_OUTPUT = mat3(\n 1.60475, -0.10208, -0.00327,\n -0.53108, 1.10813, -0.07276,\n -0.07367, -0.00605, 1.07602\n );\n return clamp(ACES_OUTPUT * rrtAndOdtFit(ACES_INPUT * x), 0.0, 1.0);\n}\n\n/*\n * Linear to sRGB. The piecewise form rather than a plain pow: the linear toe near black\n * is where banding lives in an 8-bit buffer, and the cheap approximation puts it in the\n * wrong place.\n */\nvec3 linearToSrgb(vec3 c) {\n vec3 low = c * 12.92;\n vec3 high = 1.055 * pow(max(c, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;\n return mix(high, low, step(c, vec3(0.0031308)));\n}\n\nvec3 applyOutputTransform(vec3 c) {\n if (uOutputTransform == 0) return c;\n if (uOutputTransform == 2) c = acesFilmic(c);\n return linearToSrgb(c);\n}\n\n\n/**\n * A fixed Poisson disk avoids the grid-shaped edge left by square 3x3 PCF.\n * Directional and point shadows consume the same maximum filter-tap budget;\n * their texture sizes differ because one is a 2D projection of a frustum and one\n * is an octahedral projection of the whole sphere, not because one is a lower\n * quality tier.\n */\n#if DIRECTIONAL_SHADOWS\nconst vec2 DIRECTIONAL_PCF_OFFSETS[12] = vec2[12](\n vec2(-0.326, -0.406), vec2( 0.519, 0.767), vec2( 0.962, -0.195), vec2(-0.696, 0.457),\n vec2(-0.840, -0.074), vec2( 0.185, -0.893), vec2( 0.896, 0.412), vec2(-0.203, 0.621),\n vec2( 0.473, -0.480), vec2( 0.507, 0.064), vec2(-0.322, -0.933), vec2(-0.792, -0.598)\n);\n\n/** Anything outside the light frustum or beyond its far plane counts as lit. */";
@@ -14,7 +14,40 @@
14
14
  */
15
15
  import { MAX_SHADOW_FILTER_TAPS } from '../../renderQuality.js';
16
16
  import { OUTPUT_TRANSFORM_GLSL } from '../outputTransform.js';
17
- export const POINTSHADOW_GLSL = `float pointShadow(
17
+ export const POINTSHADOW_GLSL = `/**
18
+ * How much of one tap's occlusion survives its own penumbra.
19
+ *
20
+ * **How much of a shadow survives, as well as how soft it is.** A penumbra does not merely blur
21
+ * with distance from its caster, it *takes over*: far enough from the occluder, relative to how
22
+ * big the source is, every point on the receiver can see part of the flame and there is no umbra
23
+ * left at all. The shadow is gone, not blurry. Without it, two columns lit by a brazier threw
24
+ * full-strength edges fifteen metres across the terrace, and the gap between them read as a
25
+ * spotlight cone with straight sides rather than as a fire.
26
+ *
27
+ * **Per tap, and it was once for the whole filter, taken from the centre tap alone.** That is a
28
+ * blocker search of one sample standing in for twelve, and it is right wherever the taps agree —
29
+ * inside an umbra they all find the same occluder, so this returns exactly what the shared value
30
+ * did, and the umbra is unchanged to the bit. It is wrong exactly where they disagree, which is
31
+ * the silhouette: there the centre ray *misses*, so the search reports no occluder, the spread is
32
+ * zero and the fade is switched off — while the taps that do land on the caster then draw at full
33
+ * strength. What that paints is a hard one-texel line around a shadow whose interior has
34
+ * correctly faded to nothing.
35
+ *
36
+ * Reported as shadows "faded out but NOT shadow outlines, generating long lines around the
37
+ * world", and on a brazier as a bare square outline lying on the ground with no shadow inside it.
38
+ *
39
+ * **What it costs** is two multiplies and a divide per occluded tap, against a tap that has
40
+ * already paid for a texture fetch. **What would make it wrong** is a filter wide enough that one
41
+ * tap's occluder is not the occluder a neighbouring tap is estimating for, which is the same
42
+ * limit the shared value had and is what \`MAX_FILTER_RADIUS\` bounds.
43
+ */
44
+ float tapStrength(float receiverDistance, float occluderDistance, float sourceRadius) {
45
+ float spread = max(receiverDistance - occluderDistance, 0.0) / max(occluderDistance, 0.05);
46
+ float penumbra = clamp(sourceRadius * spread * PENUMBRA_FADE, 0.0, 1.0);
47
+ return 1.0 - penumbra * penumbra;
48
+ }
49
+
50
+ float pointShadow(
18
51
  highp sampler2DArray maps,
19
52
  float layer,
20
53
  vec3 toFrag,
@@ -96,24 +129,6 @@ export const POINTSHADOW_GLSL = `float pointShadow(
96
129
  */
97
130
  float radius = clamp(sourceRadius * spread, 0.01, MAX_FILTER_RADIUS) + 0.012;
98
131
 
99
- /*
100
- * How much of a shadow survives, as well as how soft it is.
101
- *
102
- * This is the half that was missing, and it is why widening the filter never
103
- * fixed anything. A penumbra does not merely blur with distance from its
104
- * caster — it *takes over*. Far enough from the occluder, relative to how big
105
- * the source is, every point on the receiver can see part of the flame and
106
- * there is no umbra left at all: the shadow is gone, not blurry.
107
- *
108
- * Without it, two columns lit by a brazier threw full-strength edges fifteen
109
- * metres across the terrace, and the gap between them read as a spotlight cone
110
- * with straight sides rather than as a fire. Three attempts in, the note that
111
- * unlocked it was that the pool should still fade naturally at its rim — a
112
- * description of the falloff, not of the blur.
113
- */
114
- float penumbra = clamp(sourceRadius * spread * PENUMBRA_FADE, 0.0, 1.0);
115
- float strength = 1.0 - penumbra * penumbra;
116
-
117
132
  /*
118
133
  * Taps are placed on a disk *perpendicular to the light ray*, turned by half a golden
119
134
  * angle on every other column of pixels.
@@ -190,14 +205,13 @@ export const POINTSHADOW_GLSL = `float pointShadow(
190
205
  if (dist - bias > storedDistance) {
191
206
  // A point shadow cannot outlive the finite light that casts it, so its
192
207
  // occlusion fades smoothly before the light's far plane.
193
- lit += 1.0 - shadowReach(max(dist - storedDistance, 0.0), far);
208
+ float reach = shadowReach(max(dist - storedDistance, 0.0), far);
209
+ lit += 1.0 - reach * tapStrength(dist, storedDistance, sourceRadius);
194
210
  } else {
195
211
  lit += 1.0;
196
212
  }
197
213
  }
198
- float shaded = lit / float(max(uShadowFilterTaps, 1));
199
- // Fade the whole shadow toward lit as the penumbra swallows it.
200
- return mix(1.0, shaded, strength);
214
+ return lit / float(max(uShadowFilterTaps, 1));
201
215
  }
202
216
 
203
217
  /**
@@ -288,10 +302,6 @@ float areaShadow(
288
302
  float widthX = min(halfX * spread, MAX_FILTER_RADIUS) + 0.012;
289
303
  float widthY = min(halfY * spread, MAX_FILTER_RADIUS) + 0.012;
290
304
 
291
- /* The narrower half extent, for the reason in the header: it is what keeps a strip's umbra. */
292
- float penumbra = clamp(min(halfX, halfY) * spread * PENUMBRA_FADE, 0.0, 1.0);
293
- float strength = 1.0 - penumbra * penumbra;
294
-
295
305
  /*
296
306
  * Turned inside the unit disk *before* the ellipse maps it, so the half-turn that separates
297
307
  * the two halves of a pixel pair survives the anisotropy. The same two-pixel tile the round
@@ -317,13 +327,15 @@ float areaShadow(
317
327
  float storedDistance = stored * far;
318
328
  if (dist - bias > storedDistance) {
319
329
  /* An area light's occlusion cannot outlive the map that carries it either. */
320
- lit += 1.0 - shadowReach(max(dist - storedDistance, 0.0), far);
330
+ float reach = shadowReach(max(dist - storedDistance, 0.0), far);
331
+ /* The narrower half extent, for the reason in the header: it is what keeps a strip's
332
+ umbra. Per tap, for the reason \`tapStrength\` gives. */
333
+ lit += 1.0 - reach * tapStrength(dist, storedDistance, min(halfX, halfY));
321
334
  } else {
322
335
  lit += 1.0;
323
336
  }
324
337
  }
325
- float shaded = lit / float(max(uShadowFilterTaps, 1));
326
- return mix(1.0, shaded, strength);
338
+ return lit / float(max(uShadowFilterTaps, 1));
327
339
  }
328
340
  #endif
329
341
 
@@ -791,7 +791,30 @@ uniform float uAreaLightTwoSided[MAX_AREA_LIGHTS];
791
791
  #if POINT_SHADOWS
792
792
  /** Which array layer holds this light's shadow, or -1 for none. */
793
793
  uniform int uPointShadowLayer[MAX_LIGHTS];
794
- uniform float uPointShadowFar[MAX_LIGHTS];
794
+ /*
795
+ * **The projection each map was rendered under: \`xyz\` where from, \`w\` how far.**
796
+ *
797
+ * The origin is the half that is new and it is **not** the light's position. A light may drift
798
+ * \`pointShadowRebakeDistance\` from its image before the image is re-rendered, because
799
+ * re-baking six faces of the static world on every frame of a flicker is what made a brazier
800
+ * the most expensive object in a scene. The ray below is built from this point rather than from
801
+ * \`uLightPos\`, so it is the ray the picture was drawn along and the drift costs nothing.
802
+ *
803
+ * **It rides with the far plane because a row is a row.** A default-block \`float[N]\` spends a
804
+ * whole uniform vector per element and uses one of its four components, so the far plane was
805
+ * already paying for three floats it threw away — see \`uniformVectorBudget.ts\`. Declared as a
806
+ * separate \`vec3\` array this would have cost sixteen more rows on each of the two sets, and
807
+ * the ladder answers a 256-vector phone by halving \`MAX_LIGHTS\`: the measured price of a
808
+ * separate array was **eight lights becoming four**. Folded in, the whole fix is free.
809
+ *
810
+ * **What it gives up** is that the shadow stops tracking the flame *within* the tolerance — a
811
+ * flicker no longer nudges the shadow it casts, because the image it is read from did not move
812
+ * either. That is the trade the tolerance was always making, now made honestly instead of by
813
+ * reading a picture from the wrong place. **What would make it wrong** is a tolerance large
814
+ * enough that a shadow visibly lags its light, which is a reason to lower
815
+ * \`pointShadowRebakeDistance\` rather than to sample from a point the image cannot answer for.
816
+ */
817
+ uniform vec4 uPointShadowProjection[MAX_LIGHTS];
795
818
  uniform float uPointShadowNear[MAX_LIGHTS];
796
819
  /** Emitter radius per light — drives how soft its shadows are. */
797
820
  uniform float uPointShadowSize[MAX_LIGHTS];
@@ -822,7 +845,8 @@ uniform highp sampler2DArray uPointShadows; // wgsl:share shadow
822
845
  * light owns at most one of the two at a time.
823
846
  */
824
847
  uniform int uLivePointShadowLayer[MAX_LIGHTS];
825
- uniform float uLivePointShadowFar[MAX_LIGHTS];
848
+ /** The live pair's own projection, by the same rule. See \`uPointShadowProjection\`. */
849
+ uniform vec4 uLivePointShadowProjection[MAX_LIGHTS];
826
850
  uniform float uLivePointShadowNear[MAX_LIGHTS];
827
851
  uniform float uLivePointShadowSize[MAX_LIGHTS];
828
852
  uniform float uLivePointShadowWeight[MAX_LIGHTS];
@@ -833,7 +833,7 @@ export declare const FLAT_BINDINGS: {
833
833
  readonly length: 16;
834
834
  readonly stride: 16;
835
835
  };
836
- readonly uPointShadowFar: {
836
+ readonly uPointShadowProjection: {
837
837
  readonly offset: 3664;
838
838
  readonly size: 256;
839
839
  readonly type: "vec4";
@@ -868,7 +868,7 @@ export declare const FLAT_BINDINGS: {
868
868
  readonly length: 16;
869
869
  readonly stride: 16;
870
870
  };
871
- readonly uLivePointShadowFar: {
871
+ readonly uLivePointShadowProjection: {
872
872
  readonly offset: 4944;
873
873
  readonly size: 256;
874
874
  readonly type: "vec4";
@@ -1915,7 +1915,7 @@ export declare const FLAT_BINDINGS: {
1915
1915
  readonly length: 16;
1916
1916
  readonly stride: 16;
1917
1917
  };
1918
- readonly uPointShadowFar: {
1918
+ readonly uPointShadowProjection: {
1919
1919
  readonly offset: 3696;
1920
1920
  readonly size: 256;
1921
1921
  readonly type: "vec4";
@@ -1950,7 +1950,7 @@ export declare const FLAT_BINDINGS: {
1950
1950
  readonly length: 16;
1951
1951
  readonly stride: 16;
1952
1952
  };
1953
- readonly uLivePointShadowFar: {
1953
+ readonly uLivePointShadowProjection: {
1954
1954
  readonly offset: 4976;
1955
1955
  readonly size: 256;
1956
1956
  readonly type: "vec4";
@@ -3032,7 +3032,7 @@ export declare const FLAT_BINDINGS: {
3032
3032
  readonly length: 16;
3033
3033
  readonly stride: 16;
3034
3034
  };
3035
- readonly uPointShadowFar: {
3035
+ readonly uPointShadowProjection: {
3036
3036
  readonly offset: 3728;
3037
3037
  readonly size: 256;
3038
3038
  readonly type: "vec4";
@@ -3067,7 +3067,7 @@ export declare const FLAT_BINDINGS: {
3067
3067
  readonly length: 16;
3068
3068
  readonly stride: 16;
3069
3069
  };
3070
- readonly uLivePointShadowFar: {
3070
+ readonly uLivePointShadowProjection: {
3071
3071
  readonly offset: 5008;
3072
3072
  readonly size: 256;
3073
3073
  readonly type: "vec4";
@@ -4214,7 +4214,7 @@ export declare const FLAT_BINDINGS: {
4214
4214
  readonly length: 16;
4215
4215
  readonly stride: 16;
4216
4216
  };
4217
- readonly uPointShadowFar: {
4217
+ readonly uPointShadowProjection: {
4218
4218
  readonly offset: 3760;
4219
4219
  readonly size: 256;
4220
4220
  readonly type: "vec4";
@@ -4249,7 +4249,7 @@ export declare const FLAT_BINDINGS: {
4249
4249
  readonly length: 16;
4250
4250
  readonly stride: 16;
4251
4251
  };
4252
- readonly uLivePointShadowFar: {
4252
+ readonly uLivePointShadowProjection: {
4253
4253
  readonly offset: 5040;
4254
4254
  readonly size: 256;
4255
4255
  readonly type: "vec4";
@@ -5251,7 +5251,7 @@ export declare const FLAT_BINDINGS: {
5251
5251
  readonly length: 16;
5252
5252
  readonly stride: 16;
5253
5253
  };
5254
- readonly uPointShadowFar: {
5254
+ readonly uPointShadowProjection: {
5255
5255
  readonly offset: 3664;
5256
5256
  readonly size: 256;
5257
5257
  readonly type: "vec4";
@@ -5286,7 +5286,7 @@ export declare const FLAT_BINDINGS: {
5286
5286
  readonly length: 16;
5287
5287
  readonly stride: 16;
5288
5288
  };
5289
- readonly uLivePointShadowFar: {
5289
+ readonly uLivePointShadowProjection: {
5290
5290
  readonly offset: 4944;
5291
5291
  readonly size: 256;
5292
5292
  readonly type: "vec4";
@@ -6343,7 +6343,7 @@ export declare const FLAT_BINDINGS: {
6343
6343
  readonly length: 16;
6344
6344
  readonly stride: 16;
6345
6345
  };
6346
- readonly uPointShadowFar: {
6346
+ readonly uPointShadowProjection: {
6347
6347
  readonly offset: 3696;
6348
6348
  readonly size: 256;
6349
6349
  readonly type: "vec4";
@@ -6378,7 +6378,7 @@ export declare const FLAT_BINDINGS: {
6378
6378
  readonly length: 16;
6379
6379
  readonly stride: 16;
6380
6380
  };
6381
- readonly uLivePointShadowFar: {
6381
+ readonly uLivePointShadowProjection: {
6382
6382
  readonly offset: 4976;
6383
6383
  readonly size: 256;
6384
6384
  readonly type: "vec4";
@@ -7470,7 +7470,7 @@ export declare const FLAT_BINDINGS: {
7470
7470
  readonly length: 16;
7471
7471
  readonly stride: 16;
7472
7472
  };
7473
- readonly uPointShadowFar: {
7473
+ readonly uPointShadowProjection: {
7474
7474
  readonly offset: 3728;
7475
7475
  readonly size: 256;
7476
7476
  readonly type: "vec4";
@@ -7505,7 +7505,7 @@ export declare const FLAT_BINDINGS: {
7505
7505
  readonly length: 16;
7506
7506
  readonly stride: 16;
7507
7507
  };
7508
- readonly uLivePointShadowFar: {
7508
+ readonly uLivePointShadowProjection: {
7509
7509
  readonly offset: 5008;
7510
7510
  readonly size: 256;
7511
7511
  readonly type: "vec4";
@@ -8662,7 +8662,7 @@ export declare const FLAT_BINDINGS: {
8662
8662
  readonly length: 16;
8663
8663
  readonly stride: 16;
8664
8664
  };
8665
- readonly uPointShadowFar: {
8665
+ readonly uPointShadowProjection: {
8666
8666
  readonly offset: 3760;
8667
8667
  readonly size: 256;
8668
8668
  readonly type: "vec4";
@@ -8697,7 +8697,7 @@ export declare const FLAT_BINDINGS: {
8697
8697
  readonly length: 16;
8698
8698
  readonly stride: 16;
8699
8699
  };
8700
- readonly uLivePointShadowFar: {
8700
+ readonly uLivePointShadowProjection: {
8701
8701
  readonly offset: 5040;
8702
8702
  readonly size: 256;
8703
8703
  readonly type: "vec4";