From 389245fd60dbfec13eb9889358af34bb92645769 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 24 Aug 2026 20:15:21 -0700 Subject: [PATCH] =?UTF-8?q?docs:=20two=20stale=20references=20in=20the=20g?= =?UTF-8?q?round=20material=20=E2=80=94=20the=20fade's=20name,=20and=20why?= =?UTF-8?q?=20two=20materials=20may=20share=20one=20cache=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5 (1M context) --- src/engine/terrain.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/engine/terrain.ts b/src/engine/terrain.ts index 9c83f97..73f92e0 100644 --- a/src/engine/terrain.ts +++ b/src/engine/terrain.ts @@ -334,9 +334,10 @@ function groundDetailTexture(): THREE.DataTexture { texture.magFilter = THREE.LinearFilter; // Mipmapped for the reason `swellNormalTexture` states: the mip chain of a // normal map converges on flat, so the ground a long way off stops perturbing - // its normal without anything having to decide when — and `GROUND_DETAIL_FAR_M` - // then finishes the job by taking the fetch's *result* to zero rather than - // leaving a residue of the coarsest mip on the horizon. + // its normal without anything having to decide when — and the fade at + // `GROUND_DETAIL_NOISE_PX` then finishes the job by taking the fetch's + // *result* to zero rather than leaving a residue of the coarsest mip on the + // horizon. texture.minFilter = THREE.LinearMipmapLinearFilter; texture.generateMipmaps = true; // Eight, as the sea has: from a map pose the ground is seen at a grazing @@ -537,10 +538,17 @@ mapN.xy *= normalScale * groundFlat * groundSeen; normal = normalize( tbn * mapN );`, ); }; - // Two materials that compile to different programs must not share a cache - // key, and `onBeforeCompile` is invisible to three's default key. Set only - // on the patched branch: an unpatched ground is an ordinary standard - // material and must go on sharing whatever key three gives it. + /* + * `onBeforeCompile` is invisible to three's default key, so a patched + * material that does not declare one gets handed somebody else's program. + * + * The terrain and the shore plate both answer `"tera:ground"` and that is + * correct rather than a collision: `WebGLPrograms.getProgramCacheKey` + * appends this string to the *whole* parameter list, and `vertexColors` + * is in that list — so the two still hash apart, and two boards of the same + * kind still share. Set only on the patched branch: an unpatched ground is + * an ordinary standard material and must go on sharing three's own key. + */ material.customProgramCacheKey = () => "tera:ground"; } return material;