hex-world
    Preparing search index...

    Function attachSnow

    • Give a stock three.js material (a scatter tree, a rock, anything not one of this library's own shaders) seasonal snow caps.

      Snow is injected at <color_fragment>, not at the end of main() the way attachAtmosphere injects haze. The difference matters: haze sits between the eye and the surface and belongs after tone mapping, but snow is part of the surface. Putting it into diffuseColor means it gets lit, shadowed, and fogged like the rest of the model — a cap added after lighting would glow at midnight. The two patches compose in either order for exactly that reason.

      It goes in after SEASON_COLOR_SLOT, which puts it after the foliage tint however the two were attached — snow settles on autumn leaves rather than turning gold with them.

      Coverage comes from SNOW_GLSL's shared snowCoverage, the same function the terrain shader calls, so a tree whitens at the same moment as the ground it stands in. It is weighted by how far each surface faces the sky, so snow settles on the canopy and leaves the trunk bare.

      Requires a per-instance (or per-vertex) cellIndex attribute to look the cell up — buildScatterMeshes attaches one to every scatter mesh. On a mesh without it, every instance reads cell 0; the effect stays inert until configureSeason supplies a climate either way.

      Safe on a material that already has an onBeforeCompile (the existing hook still runs), and idempotent.

      Parameters

      Returns void

      const trees = new THREE.MeshLambertMaterial({ color: 0x5e8c2a });
      attachSnow(trees);
      configureSeason(trees, climate);