@casmo/tree.js 0.3.0 → 0.5.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 (154) hide show
  1. package/README.md +775 -4
  2. package/dist/effects/custom.d.ts +62 -0
  3. package/dist/effects/custom.d.ts.map +1 -0
  4. package/dist/effects/effects.d.ts +92 -6
  5. package/dist/effects/effects.d.ts.map +1 -1
  6. package/dist/effects/glow.d.ts +5 -0
  7. package/dist/effects/glow.d.ts.map +1 -1
  8. package/dist/effects/grade.d.ts +3 -0
  9. package/dist/effects/grade.d.ts.map +1 -1
  10. package/dist/effects/highlight.d.ts +35 -0
  11. package/dist/effects/highlight.d.ts.map +1 -0
  12. package/dist/effects/index.d.ts +7 -1
  13. package/dist/effects/index.d.ts.map +1 -1
  14. package/dist/effects/inner-lines.d.ts +39 -0
  15. package/dist/effects/inner-lines.d.ts.map +1 -0
  16. package/dist/effects/live.d.ts +12 -0
  17. package/dist/effects/live.d.ts.map +1 -0
  18. package/dist/effects/mask.d.ts +32 -12
  19. package/dist/effects/mask.d.ts.map +1 -1
  20. package/dist/effects/outline.d.ts +12 -0
  21. package/dist/effects/outline.d.ts.map +1 -1
  22. package/dist/effects/pass.d.ts +27 -0
  23. package/dist/effects/pass.d.ts.map +1 -0
  24. package/dist/effects/screen.d.ts +31 -0
  25. package/dist/effects/screen.d.ts.map +1 -0
  26. package/dist/effects/suggested.d.ts +5 -0
  27. package/dist/effects/suggested.d.ts.map +1 -1
  28. package/dist/effects/tree-id.d.ts +50 -0
  29. package/dist/effects/tree-id.d.ts.map +1 -0
  30. package/dist/effects-qHx_8Dlk.js +1052 -0
  31. package/dist/effects-qHx_8Dlk.js.map +1 -0
  32. package/dist/effects.js +3 -249
  33. package/dist/forest/Forest.d.ts +82 -4
  34. package/dist/forest/Forest.d.ts.map +1 -1
  35. package/dist/forest/forest-lod.d.ts +70 -0
  36. package/dist/forest/forest-lod.d.ts.map +1 -0
  37. package/dist/forest/impostor-material.d.ts +106 -0
  38. package/dist/forest/impostor-material.d.ts.map +1 -0
  39. package/dist/forest/impostor-season.d.ts +13 -0
  40. package/dist/forest/impostor-season.d.ts.map +1 -0
  41. package/dist/forest/impostor.d.ts +105 -0
  42. package/dist/forest/impostor.d.ts.map +1 -0
  43. package/dist/forest/index.d.ts +1 -0
  44. package/dist/forest/index.d.ts.map +1 -1
  45. package/dist/forest/levels.d.ts +144 -0
  46. package/dist/forest/levels.d.ts.map +1 -0
  47. package/dist/forest/lod.d.ts +106 -0
  48. package/dist/forest/lod.d.ts.map +1 -0
  49. package/dist/forest/nodes.d.ts +42 -1
  50. package/dist/forest/nodes.d.ts.map +1 -1
  51. package/dist/forest/octahedral.d.ts +33 -0
  52. package/dist/forest/octahedral.d.ts.map +1 -0
  53. package/dist/{forest-ChEaWJrf.js → forest-CM5DrklM.js} +1727 -340
  54. package/dist/forest-CM5DrklM.js.map +1 -0
  55. package/dist/generator/fruit.d.ts +2 -0
  56. package/dist/generator/fruit.d.ts.map +1 -1
  57. package/dist/generator/index.d.ts +1 -0
  58. package/dist/generator/index.d.ts.map +1 -1
  59. package/dist/generator/light.d.ts +36 -0
  60. package/dist/generator/light.d.ts.map +1 -0
  61. package/dist/index.d.ts +3 -2
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +5 -2
  64. package/dist/index.js.map +1 -1
  65. package/dist/materials/crown-nodes.d.ts +5 -0
  66. package/dist/materials/crown-nodes.d.ts.map +1 -1
  67. package/dist/materials/leaf-translucency-model.d.ts +6 -1
  68. package/dist/materials/leaf-translucency-model.d.ts.map +1 -1
  69. package/dist/materials/material-features.d.ts +12 -0
  70. package/dist/materials/material-features.d.ts.map +1 -1
  71. package/dist/materials/shader-hooks.d.ts +155 -0
  72. package/dist/materials/shader-hooks.d.ts.map +1 -0
  73. package/dist/motion-Qd7xjeZM.js +276 -0
  74. package/dist/motion-Qd7xjeZM.js.map +1 -0
  75. package/dist/nodes-DxgTyF9B.js +436 -0
  76. package/dist/nodes-DxgTyF9B.js.map +1 -0
  77. package/dist/react/Forest.d.ts +17 -3
  78. package/dist/react/Forest.d.ts.map +1 -1
  79. package/dist/react/ScenePipeline.d.ts +63 -0
  80. package/dist/react/ScenePipeline.d.ts.map +1 -0
  81. package/dist/react/SceneShaderHooks.d.ts +25 -0
  82. package/dist/react/SceneShaderHooks.d.ts.map +1 -0
  83. package/dist/react/Tree.d.ts +9 -2
  84. package/dist/react/Tree.d.ts.map +1 -1
  85. package/dist/react/Weather.d.ts +45 -0
  86. package/dist/react/Weather.d.ts.map +1 -0
  87. package/dist/react/Wind.d.ts +12 -1
  88. package/dist/react/Wind.d.ts.map +1 -1
  89. package/dist/react/index.d.ts +7 -1
  90. package/dist/react/index.d.ts.map +1 -1
  91. package/dist/react.js +347 -10
  92. package/dist/react.js.map +1 -1
  93. package/dist/renderer/index.d.ts +6 -0
  94. package/dist/renderer/index.d.ts.map +1 -1
  95. package/dist/scene/antialias.d.ts +35 -0
  96. package/dist/scene/antialias.d.ts.map +1 -0
  97. package/dist/scene/ao.d.ts +46 -0
  98. package/dist/scene/ao.d.ts.map +1 -0
  99. package/dist/scene/bloom.d.ts +19 -0
  100. package/dist/scene/bloom.d.ts.map +1 -0
  101. package/dist/scene/fog.d.ts +49 -0
  102. package/dist/scene/fog.d.ts.map +1 -0
  103. package/dist/scene/godrays.d.ts +37 -0
  104. package/dist/scene/godrays.d.ts.map +1 -0
  105. package/dist/scene/index.d.ts +14 -0
  106. package/dist/scene/index.d.ts.map +1 -0
  107. package/dist/scene/motion-blur.d.ts +23 -0
  108. package/dist/scene/motion-blur.d.ts.map +1 -0
  109. package/dist/scene/pipeline.d.ts +109 -0
  110. package/dist/scene/pipeline.d.ts.map +1 -0
  111. package/dist/scene/settings.d.ts +36 -0
  112. package/dist/scene/settings.d.ts.map +1 -0
  113. package/dist/scene/stack.d.ts +25 -0
  114. package/dist/scene/stack.d.ts.map +1 -0
  115. package/dist/scene/stage.d.ts +52 -0
  116. package/dist/scene/stage.d.ts.map +1 -0
  117. package/dist/scene/suggested.d.ts +12 -0
  118. package/dist/scene/suggested.d.ts.map +1 -0
  119. package/dist/scene/tone-mapping.d.ts +20 -0
  120. package/dist/scene/tone-mapping.d.ts.map +1 -0
  121. package/dist/scene/velocity.d.ts +34 -0
  122. package/dist/scene/velocity.d.ts.map +1 -0
  123. package/dist/scene.js +889 -0
  124. package/dist/scene.js.map +1 -0
  125. package/dist/season/nodes.d.ts +13 -0
  126. package/dist/season/nodes.d.ts.map +1 -1
  127. package/dist/shader-hooks-BFRtlWGI.js +275 -0
  128. package/dist/shader-hooks-BFRtlWGI.js.map +1 -0
  129. package/dist/tree/Tree.d.ts +8 -3
  130. package/dist/tree/Tree.d.ts.map +1 -1
  131. package/dist/tree/index.d.ts.map +1 -1
  132. package/dist/weather/index.d.ts +3 -0
  133. package/dist/weather/index.d.ts.map +1 -0
  134. package/dist/weather/shared.d.ts +43 -0
  135. package/dist/weather/shared.d.ts.map +1 -0
  136. package/dist/weather/snow.d.ts +87 -0
  137. package/dist/weather/snow.d.ts.map +1 -0
  138. package/dist/weather/wetness.d.ts +75 -0
  139. package/dist/weather/wetness.d.ts.map +1 -0
  140. package/dist/weather.js +288 -0
  141. package/dist/weather.js.map +1 -0
  142. package/dist/wind/Wind.d.ts +100 -5
  143. package/dist/wind/Wind.d.ts.map +1 -1
  144. package/dist/wind/burst.d.ts +28 -0
  145. package/dist/wind/burst.d.ts.map +1 -0
  146. package/dist/wind/index.d.ts +3 -2
  147. package/dist/wind/index.d.ts.map +1 -1
  148. package/dist/wind/motion.d.ts +30 -0
  149. package/dist/wind/motion.d.ts.map +1 -0
  150. package/dist/wind/node.d.ts +17 -3
  151. package/dist/wind/node.d.ts.map +1 -1
  152. package/package.json +9 -1
  153. package/dist/effects.js.map +0 -1
  154. package/dist/forest-ChEaWJrf.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scene.js","names":["DEFAULTS"],"sources":["../src/scene/suggested.ts","../src/scene/settings.ts","../src/scene/stage.ts","../src/scene/godrays.ts","../src/scene/ao.ts","../src/scene/fog.ts","../src/scene/velocity.ts","../src/scene/antialias.ts","../src/scene/bloom.ts","../src/scene/motion-blur.ts","../src/scene/tone-mapping.ts","../src/scene/stack.ts","../src/scene/pipeline.ts"],"sourcesContent":["import type { StyleName } from '../styles/registry';\nimport type { SceneEffectsSettings } from './settings';\n\n/**\n * The suggested Scene Effects for each built-in Style (plain data: read, copy or change it), tuned\n * against the PR #51 concept images on the `examples/scene-pipeline` scene (a tree 10-15 m away in\n * front of a small Forest, a plain sky, a side sun). TRAA and motion blur are never suggested.\n * SMAA for every Style: the Tree ID channel turns MSAA off (ADR 0009), and SMAA keeps low-poly\n * facets and leaf cards sharper than FXAA. Fog in metres: the front trees stay clear and the trees\n * behind them fade a little; scale the distances up for large worlds.\n */\nexport const SUGGESTED_SCENE_EFFECTS: Record<StyleName, SceneEffectsSettings> = {\n // Crisp and flat: Neutral keeps the flat colours close to their base colour; no bloom, no god rays.\n 'low-poly': {\n toneMapping: { mapping: 'neutral' },\n // Light GTAO: a hint of ground contact that keeps the flat shading flat.\n ao: { radius: 1, scale: 0.7, thickness: 1 },\n antialias: 'smaa',\n fog: { near: 15, far: 120 },\n },\n // AgX keeps greens green (ACES shifts them towards yellow) and rolls off bright highlights softly;\n // a little more exposure makes up for AgX's darker mid-tones.\n stylized: {\n toneMapping: { mapping: 'agx', exposure: 1.2 },\n ao: { radius: 1.2, scale: 1.3, thickness: 2 },\n // Soft bloom: a plain light sky (linear luminance about 0.6) glows widely and faintly over the\n // crown edges. Bloom is all-or-nothing per pixel above the threshold, so the strength stays low.\n bloom: { strength: 0.1, radius: 0.6, threshold: 0.55 },\n antialias: 'smaa',\n // Distance fog plus a low mist around the trunks.\n fog: { near: 15, far: 130, mist: { height: 1.5, strength: 0.5, near: 10, far: 50 } },\n },\n realistic: {\n toneMapping: { mapping: 'agx', exposure: 1.2 },\n ao: { radius: 1.2, scale: 1.6, thickness: 2 },\n // Subtle bloom: a narrow glare of the bright sky through the leaves.\n bloom: { strength: 0.06, radius: 0.3, threshold: 0.55 },\n // Warm light shafts (needs the app's shadow-casting `sun`). God rays also light the air between\n // the camera and everything behind it, so low numbers: in the open the shafts stay a faint\n // warm haze, under a dense canopy they read as rays.\n godrays: { density: 0.2, maxDensity: 0.05, distanceAttenuation: 2, color: '#fff0c8' },\n antialias: 'smaa',\n // Distance fog, a height mist and a thin far layer over the whole height.\n fog: { near: 15, far: 140, mist: { height: 2, strength: 0.4, near: 10, far: 60, farLayer: { near: 40, far: 200, strength: 0.2 } } },\n },\n};\n","import type { StyleName } from '../styles/registry';\nimport type { SceneGodraysOptions } from './godrays';\nimport type { SceneAOOptions } from './ao';\nimport type { SceneAntialiasMode } from './antialias';\nimport type { SceneBloomOptions } from './bloom';\nimport type { SceneMotionBlurOptions } from './motion-blur';\nimport type { SceneToneMappingOptions } from './tone-mapping';\nimport type { SceneFogOptions } from './fog';\nimport { SUGGESTED_SCENE_EFFECTS } from './suggested';\n\n/**\n * A combination of Scene Effects; leave an effect out to skip it. `{}` = no Scene Effects.\n * One optional field per Scene Effect (its options type lives in the effect's own file).\n */\nexport interface SceneEffectsSettings {\n /** Tone mapping and the output colour space, applied inside the pipeline. */\n toneMapping?: SceneToneMappingOptions;\n /** God rays through the canopy; need a shadow-casting `sun` (skipped with a warning otherwise). */\n godrays?: SceneGodraysOptions;\n /** Ground-contact ambient occlusion (GTAO) in the scene pass's lighting: darkens ambient light only. */\n ao?: SceneAOOptions;\n /** Motion blur along the Wind-aware velocity (camera, object and Wind motion); never suggested. */\n motionBlur?: SceneMotionBlurOptions;\n /** Bloom: a soft glare around the bright parts of the frame, before tone mapping. */\n bloom?: SceneBloomOptions;\n /**\n * Anti-aliasing; `null` = none. SMAA / FXAA: of the display colours, last in the stack. TRAA:\n * before tone mapping, with the Wind-aware velocity channel (never suggested).\n */\n antialias?: SceneAntialiasMode | null;\n /** Distance fog and height mist, set as `scene.fogNode` (the app's value is restored). */\n fog?: SceneFogOptions;\n}\n\n/** The suggested Scene Effects of a built-in Style, or the settings themselves; `null` = none. */\nexport type SceneEffectsChoice = StyleName | SceneEffectsSettings | null;\n\n/** The settings of a choice; throws for an unknown Style. */\nexport function resolveSceneEffects(choice: SceneEffectsChoice): SceneEffectsSettings {\n if (choice === null) return {};\n if (typeof choice !== 'string') return choice;\n const settings = (SUGGESTED_SCENE_EFFECTS as Record<string, SceneEffectsSettings | undefined>)[choice];\n if (!settings) throw new Error(`No suggested Scene Effects for Style \"${choice}\"`);\n return settings;\n}\n","import type { Camera, Light, Node, TextureNode } from 'three/webgpu';\nimport { convertToTexture } from 'three/tsl';\nimport type { SceneEffectsSettings } from './settings';\n\n/**\n * `color` as a texture an effect can sample around each pixel: itself when it already is one,\n * otherwise rendered into one (a render target the caller owns: dispose it when it is not `color`).\n */\nexport function asTexture(color: Node<'vec4'>): TextureNode {\n return (color as Partial<TextureNode>).isTextureNode ? (color as TextureNode) : convertToTexture(color);\n}\n\n/**\n * What a colour Scene Effect reads: the colour so far, and the scene pass's depth and camera when\n * the stack runs on a scene pass (the ready-made Scene Pipeline always passes them).\n */\nexport interface SceneEffectInput {\n color: Node<'vec4'>;\n depth?: TextureNode;\n camera?: Camera;\n /** The shadow-casting sun for god rays (never changed). */\n sun?: Light;\n /** Wind-aware velocity (NDC units per frame, see `windVelocityMRT`), for TRAA and motion blur. */\n velocity?: TextureNode;\n}\n\n/**\n * A built Scene Effect whose colours and numbers are uniforms: `update()` changes them in place\n * (no new graph). `update()` gets the whole Scene Effects settings; each effect reads its own part.\n */\nexport interface LiveSceneEffect {\n node: Node<'vec4'>;\n update(settings: SceneEffectsSettings): void;\n /** Frees the render targets the effect owns (blur, bloom, AA...), called on a rebuild and on dispose. */\n dispose?(): void;\n}\n\n/**\n * One step of the colour stack of {@link applySceneEffects}. Each Scene Effect file exports one, and\n * `stack.ts` lists them in stack order.\n */\nexport interface SceneEffectStage {\n /**\n * The part of the settings that shapes this step's graph: `undefined` when the step is off,\n * otherwise a JSON-serialisable value that is equal for settings that differ only in uniforms\n * (e.g. tone mapping: the curve; the exposure is a uniform).\n */\n shape(settings: SceneEffectsSettings): unknown;\n /** Builds the step onto `input.color` (only called when `shape()` is not `undefined`). */\n build(input: SceneEffectInput, settings: SceneEffectsSettings): LiveSceneEffect;\n /**\n * The step outputs display colours (tone mapped, in the output colour space), so the\n * RenderPipeline must not apply its own output transform (`outputColorTransform = false`).\n */\n display?: boolean;\n /** The step reads `input.velocity` when on: the Scene Pipeline then renders the velocity channel. */\n needsVelocity?: boolean;\n}\n","import { Color, type Camera, type ColorRepresentation, type DirectionalLight, type Light, type Node, type PointLight, type TextureNode } from 'three/webgpu';\nimport { uniform } from 'three/tsl';\nimport { godrays } from 'three/addons/tsl/display/GodraysNode.js';\nimport { depthAwareBlend } from 'three/addons/tsl/display/depthAwareBlend.js';\nimport { asTexture, type SceneEffectStage } from './stage';\n\n/** God rays settings (all optional; every colour and number is a uniform). */\nexport interface SceneGodraysOptions {\n /** How dense the lit air is: more makes brighter shafts and haze (default 1.5). */\n density?: number;\n /** The most the shafts cover a pixel, 0..1 (default 0.5). */\n maxDensity?: number;\n /** How fast the shafts fade with the distance from the sun's shadow camera (default 0.6). */\n distanceAttenuation?: number;\n /** The colour of the light in the shafts (default '#fff0c8', warm sunlight). */\n color?: ColorRepresentation;\n /** The search radius in pixels for depth edges in the blend, against light leaking around trunks (default 2). */\n edgeRadius?: number;\n /** How far the blend steps away from a depth edge, in pixels (default 2). */\n edgeStrength?: number;\n}\n\n/** A light god rays can use: a directional or point light that casts shadows. */\nexport type SceneGodraysSun = DirectionalLight | PointLight;\n\n/** Why `sun` cannot drive god rays, or `undefined` when it can. */\nexport function godraysSunProblem(sun: Light | undefined): string | undefined {\n if (!sun) return 'no `sun` light was given';\n const { isDirectionalLight, isPointLight } = sun as Partial<DirectionalLight & PointLight>;\n if (!isDirectionalLight && !isPointLight) return 'the `sun` must be a DirectionalLight or a PointLight';\n if (!sun.castShadow) return 'the `sun` does not cast shadows (the pipeline never turns shadows on)';\n return undefined;\n}\n\n/**\n * Scene Effect: god rays, light shafts through the canopy, raymarched through the shadow map of a\n * shadow-casting `sun` and blended depth-aware onto `color` (no light leaking around trunks and\n * leaves). Needs a full shadow setup by the app: `renderer.shadowMap.enabled`, the sun's\n * `castShadow` and casting objects; nothing is changed here. `depth` and `camera` are those of the\n * scene pass. Returns a colour node (not display colours).\n */\nexport function sceneGodrays(\n color: Node<'vec4'>,\n depth: TextureNode,\n camera: Camera,\n sun: SceneGodraysSun,\n options: SceneGodraysOptions = {},\n): Node<'vec4'> {\n return liveSceneGodrays(color, depth, camera, sun, options).node;\n}\n\nfunction liveSceneGodrays(color: Node<'vec4'>, depth: TextureNode, camera: Camera, sun: SceneGodraysSun, options: SceneGodraysOptions) {\n const rays = godrays(depth, camera, sun);\n const tint = uniform(new Color());\n const edgeRadius = uniform(2, 'int');\n const edgeStrength = uniform(2, 'float');\n const update = (o: SceneGodraysOptions): void => {\n rays.density.value = o.density ?? 1.5;\n rays.maxDensity.value = o.maxDensity ?? 0.5;\n rays.distanceAttenuation.value = o.distanceAttenuation ?? 0.6;\n tint.value.set(o.color ?? '#fff0c8');\n edgeRadius.value = Math.round(o.edgeRadius ?? 2);\n edgeStrength.value = o.edgeStrength ?? 2;\n };\n update(options);\n // The blend samples its base around each pixel: a texture (the colour so far rendered to one when needed).\n const base = asTexture(color);\n const node = depthAwareBlend(base, rays.getTextureNode(), depth, camera, { blendColor: tint, edgeRadius, edgeStrength });\n const dispose = (): void => {\n rays.dispose();\n if (base !== color) base.dispose();\n };\n return { node, update, dispose };\n}\n\n/** Warns that god rays are skipped, and why. */\nexport function warnGodraysSkipped(problem: string): void {\n console.warn(`tree.js Scene Effects: god rays skipped, ${problem}.`);\n}\n\n/**\n * The god rays step of the stack. It reads `input.depth`, `input.camera` and `input.sun`; without a\n * usable sun it is skipped with a console warning (the Scene Pipeline leaves it out before, warning once).\n */\nexport const godraysStage: SceneEffectStage = {\n shape: (settings) => (settings.godrays ? true : undefined),\n build(input, settings) {\n const problem = godraysSunProblem(input.sun) ?? (input.depth && input.camera ? undefined : 'the scene depth and camera are missing');\n if (problem) {\n warnGodraysSkipped(problem);\n return { node: input.color, update: () => {} };\n }\n const live = liveSceneGodrays(input.color, input.depth!, input.camera!, input.sun as SceneGodraysSun, settings.godrays!);\n return { node: live.node, update: (s) => live.update(s.godrays!), dispose: live.dispose };\n },\n};\n","import type { Camera, ContextNode, PassNode, Scene } from 'three/webgpu';\nimport { builtinAOContext, mrt, normalView, pass, screenUV } from 'three/tsl';\nimport { ao } from 'three/addons/tsl/display/GTAONode.js';\nimport type GTAONode from 'three/addons/tsl/display/GTAONode.js';\n\n/** Ambient occlusion (GTAO) settings (all optional; every one is a uniform or a per-frame value). */\nexport interface SceneAOOptions {\n /** How far around a pixel occluders are searched, in metres (default 1). */\n radius?: number;\n /** How strong the occlusion is (default 1; lower = lighter). */\n scale?: number;\n /** How thick occluders are assumed to be, in metres (default 1). */\n thickness?: number;\n /** How fast the occlusion falls off with distance (default 1). */\n distanceExponent?: number;\n /** How much occluders far from the pixel count (default 1). */\n distanceFallOff?: number;\n /** Samples per pixel (default 16; more = smoother and slower). */\n samples?: number;\n /** The AO buffer's size relative to the canvas (default 1; e.g. 0.5 for half resolution). */\n resolutionScale?: number;\n}\n\n/** What {@link sceneAO} returns: put the pre-pass and AO in your pipeline through the lighting context. */\nexport interface SceneAO {\n /** The depth + view-normal pre-pass (the scene drawn once more, before the scene pass). */\n prePass: PassNode;\n /** The GTAO node (its result: `node.getTextureNode()`). */\n node: GTAONode;\n /**\n * A built-in AO lighting context: set it as your scene pass's `contextNode`, so the AO only\n * darkens ambient (indirect) light, not direct sunlight.\n */\n context: ContextNode<unknown>;\n}\n\n/**\n * Scene Effect: ground-contact ambient occlusion (GTAO). Returns a depth + view-normal pre-pass,\n * GTAO on it and a lighting context; in your own pipeline set `scenePass.contextNode = context`.\n * The scene is drawn twice while AO is on.\n */\nexport function sceneAO(scene: Scene, camera: Camera, options: SceneAOOptions = {}): SceneAO {\n const { prePass, node, context } = liveSceneAO(scene, camera, options);\n return { prePass, node, context };\n}\n\n/** {@link sceneAO} with `update()` (numbers only) and `dispose()` (the pre-pass and the AO target). */\nexport function liveSceneAO(scene: Scene, camera: Camera, options: SceneAOOptions) {\n const prePass = pass(scene, camera);\n prePass.setMRT(mrt({ output: normalView }));\n const node = ao(prePass.getTextureNode('depth'), prePass.getTextureNode(), camera);\n const update = (o: SceneAOOptions): void => {\n node.radius.value = o.radius ?? 1;\n node.scale.value = o.scale ?? 1;\n node.thickness.value = o.thickness ?? 1;\n node.distanceExponent.value = o.distanceExponent ?? 1;\n node.distanceFallOff.value = o.distanceFallOff ?? 1;\n node.samples.value = o.samples ?? 16;\n node.resolutionScale = o.resolutionScale ?? 1;\n };\n update(options);\n const context = builtinAOContext(node.getTextureNode().sample(screenUV).r);\n return {\n prePass,\n node,\n context,\n update,\n dispose(): void {\n node.dispose();\n prePass.dispose();\n },\n };\n}\n","import { Color, type ColorRepresentation, type Node, type Scene } from 'three/webgpu';\nimport { fog, positionWorld, rangeFogFactor, smoothstep, uniform } from 'three/tsl';\n\n/** A far layer of the height mist: a thinner haze over the whole height, far away (all optional). */\nexport interface SceneMistFarLayerOptions {\n /** Where the far layer starts, in metres from the camera (default 30). */\n near?: number;\n /** Where the far layer reaches its strength, in metres (default 120). */\n far?: number;\n /** Its strength at `far`, 0-1 (default 0.4). */\n strength?: number;\n}\n\n/** A height mist: fog that lies low, below `height` (all optional). */\nexport interface SceneMistOptions {\n /** The mist's top, in metres above y = 0: densest at the ground, gone at this height (default 2). */\n height?: number;\n /** How dense the mist gets far away, 0-1 (default 0.7). */\n strength?: number;\n /** Where the mist starts, in metres from the camera (default 8). */\n near?: number;\n /** Where the mist reaches its strength, in metres from the camera (default 40). */\n far?: number;\n /** A thinner haze far away, over the whole height (`null` / left out = none). */\n farLayer?: SceneMistFarLayerOptions | null;\n}\n\n/**\n * Fog settings, in metres, tuned for a small forest scene (all optional; every number and the\n * colour are uniforms). Scale the distances up for large worlds.\n */\nexport interface SceneFogOptions {\n /** The fog colour. Default: `scene.background` when that is a plain Color, otherwise a pale sky blue. */\n color?: ColorRepresentation;\n /** Where the distance fog starts, in metres from the camera (default 10). */\n near?: number;\n /** Where the distance fog is complete, in metres from the camera (default 80). */\n far?: number;\n /** A low height mist on top of the distance fog (`null` / left out = none). */\n mist?: SceneMistOptions | null;\n}\n\n/** The fog colour when neither the settings nor a plain-colour background give one. */\nconst DEFAULT_COLOR = '#c9d8e2';\n\n/**\n * Scene Effect: distance fog plus an optional low height mist, as a fog node for `scene.fogNode`\n * (three applies it in every material). `background` is the scene's background: when it is a plain\n * Color, that is the default fog colour, so far trees fade into the sky. Pass `scene.background`.\n */\nexport function sceneFog(options: SceneFogOptions = {}, background?: Scene['background']): Node {\n return liveSceneFog(options, background).node;\n}\n\n/** {@link sceneFog} with `update()`: new numbers and colour, the same node (no material recompile). */\nexport function liveSceneFog(options: SceneFogOptions, background?: Scene['background']) {\n const color = uniform(new Color());\n const near = uniform(0);\n const far = uniform(0);\n const mistHeight = uniform(0);\n const mistStrength = uniform(0);\n const mistNear = uniform(0);\n const mistFar = uniform(0);\n const layerNear = uniform(0);\n const layerFar = uniform(0);\n const layerStrength = uniform(0);\n const update = (o: SceneFogOptions, bg?: Scene['background']): void => {\n color.value.set(o.color ?? (bg instanceof Color ? bg : DEFAULT_COLOR));\n near.value = o.near ?? 10;\n far.value = o.far ?? 80;\n // A mist (or far layer) that is off is a strength of 0: the same graph either way.\n const mist = o.mist ?? null;\n mistHeight.value = Math.max(mist?.height ?? 2, 1e-3);\n mistStrength.value = mist ? (mist.strength ?? 0.7) : 0;\n mistNear.value = mist?.near ?? 8;\n mistFar.value = mist?.far ?? 40;\n const layer = mist?.farLayer ?? null;\n layerNear.value = layer?.near ?? 30;\n layerFar.value = layer?.far ?? 120;\n layerStrength.value = layer ? (layer.strength ?? 0.4) : 0;\n };\n update(options, background);\n const distance = rangeFogFactor(near, far);\n const mist = rangeFogFactor(mistNear, mistFar).mul(smoothstep(mistHeight, 0, positionWorld.y)).mul(mistStrength);\n const layer = rangeFogFactor(layerNear, layerFar).mul(layerStrength);\n // Independent layers: each lets through a part of what the others let through.\n const factor = distance.oneMinus().mul(mist.oneMinus()).mul(layer.oneMinus()).oneMinus().clamp(0, 1);\n return { node: fog(color, factor) as unknown as Node, update };\n}\n","import { VelocityNode, type Camera, type Material, type MRTNode, type Node, type NodeBuilder, type NodeFrame, type NodeMaterial, type Object3D, type Scene, type TextureNode } from 'three/webgpu';\nimport { modelViewMatrix, mrt, positionLocal, uniform } from 'three/tsl';\nimport { treeEffectsPass, type TreeEffectsChannels, type TreeEffectsPass } from '../effects/pass';\nimport { windMotionOf, windTimeOf, type WindMotion } from '../wind/motion';\n\n/**\n * Name of the velocity output in a pass's MRT (`scenePass.getTextureNode(WIND_VELOCITY)`). It is\n * `'velocity'` on purpose: three only keeps the previous frame's data (instance matrices, bones)\n * for a scene pass whose MRT has an output of that name.\n */\nexport const WIND_VELOCITY = 'velocity';\n\n/**\n * The Wind time step behind a pinned Wind time (a still), and before a tree's first draw: one\n * frame at 60 fps. A pinned clock thus still shows the Wind's sway as motion, deterministically.\n */\nconst STILL_STEP = 1 / 60;\n\n/** The Wind time each object was last drawn with in a velocity pass. */\nconst lastWindTimes = new WeakMap<Object3D, number>();\n\n/** The Wind time a tree drawn at Wind time `now` was at in the previous frame (see {@link STILL_STEP}). */\nfunction previousWindTime(last: number | undefined, now: number): number {\n return last === undefined || last === now ? now - STILL_STEP : last;\n}\n\n/**\n * three's `velocity` (screen-space motion since the previous frame: camera, object and instance\n * movement), plus the Wind sway of tree.js trees: for a tree material it moves each vertex back by\n * the Wind displacement between the previous frame's Wind time and now (the same Wind formula, with\n * each Forest tree's own phase). Growth and Season are not motion. Other materials get three's\n * velocity unchanged. The tree materials themselves are never changed (ADR 0011).\n */\nclass WindVelocityNode extends VelocityNode {\n /** The previous frame's Wind time of the tree being drawn (set per object). */\n readonly previousWindTime = uniform(0);\n\n override update(frame: NodeFrame): undefined {\n super.update(frame);\n const motion = motionOf(frame);\n if (!motion) return undefined;\n const now = windTimeOf(motion.source, frame.time);\n this.previousWindTime.value = previousWindTime(lastWindTimes.get(frame.object!), now);\n return undefined;\n }\n\n override updateAfter(frame: NodeFrame): undefined {\n super.updateAfter(frame);\n const motion = motionOf(frame);\n if (motion) lastWindTimes.set(frame.object!, windTimeOf(motion.source, frame.time));\n return undefined;\n }\n\n override setup(builder: NodeBuilder): Node<'vec2'> {\n const motion = windMotionOf(positionNodeOf(builder.material));\n if (!motion) return super.setup(builder) as Node<'vec2'>;\n // As three's velocity, with the previous position = this frame's one moved back by the Wind.\n const previousLocal = positionLocal.add(motion.shift(this.previousWindTime).toVarying('v_windVelocityShift'));\n const previousModelView = this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix);\n const current = this.currentProjectionMatrix.mul(modelViewMatrix).mul(positionLocal);\n const previous = this.previousProjectionMatrix.mul(previousModelView).mul(previousLocal);\n return current.xy.div(current.w).sub(previous.xy.div(previous.w));\n }\n}\n\nfunction motionOf(frame: NodeFrame): WindMotion | undefined {\n return frame.object ? windMotionOf(positionNodeOf(frame.material)) : undefined;\n}\n\nfunction positionNodeOf(material: Material | null | undefined): Node | null | undefined {\n return (material as NodeMaterial | null | undefined)?.positionNode;\n}\n\n/**\n * TSL node: Wind-aware velocity (vec2, NDC units per frame), a drop-in for three's `velocity` that\n * also sees the Wind sway of tree.js trees. Use it through {@link windVelocityMRT}.\n */\nexport const windVelocity: Node<'vec2'> = new WindVelocityNode() as unknown as Node<'vec2'>;\n\n/**\n * The MRT output that renders Wind-aware velocity ({@link windVelocity}) to a target named\n * `velocity` (cleared to 0), for TRAA or motion blur in your own pipeline:\n * `scenePass.setMRT(mrt({ output }).merge(windVelocityMRT()))`, then\n * `scenePass.getTextureNode(WIND_VELOCITY)`. Only a scene pass with this output pays for velocity:\n * without it, trees, their geometry and their materials render exactly as before.\n */\nexport function windVelocityMRT(): MRTNode {\n const node = mrt({ [WIND_VELOCITY]: windVelocity });\n node.setClearColor(WIND_VELOCITY, 0x000000, 0);\n return node;\n}\n\n/** The scene pass channels of a Scene Pipeline: the Tree Effects' ones, plus Wind-aware velocity. */\nexport interface ScenePassChannels extends TreeEffectsChannels {\n /** The Wind-aware velocity target ({@link windVelocityMRT}), for TRAA and motion blur. */\n velocity?: boolean;\n}\n\n/** A Scene Pipeline's scene pass: a Tree Effects pass, plus the velocity texture when asked for. */\nexport interface ScenePass extends TreeEffectsPass {\n /** Wind-aware velocity (NDC units per frame), with the `velocity` channel. */\n velocity?: TextureNode;\n}\n\n/** `treeEffectsPass` with the Scene Pipeline's channels (the velocity MRT merged in when asked for). */\nexport function createScenePass(scene: Scene, camera: Camera, selection: readonly Object3D[] | null, channels: ScenePassChannels): ScenePass {\n const { velocity, ...treeChannels } = channels;\n const input: ScenePass = treeEffectsPass(scene, camera, selection, treeChannels);\n if (velocity) {\n input.pass.setMRT(input.pass.getMRT()!.merge(windVelocityMRT()));\n input.velocity = input.pass.getTextureNode(WIND_VELOCITY);\n }\n return input;\n}\n","import type { Matrix4, Node, PassNode, VelocityNode } from 'three/webgpu';\nimport { convertToTexture, renderOutput } from 'three/tsl';\nimport { fxaa } from 'three/addons/tsl/display/FXAANode.js';\nimport { smaa } from 'three/addons/tsl/display/SMAANode.js';\nimport TRAANode from 'three/addons/tsl/display/TRAANode.js';\nimport type { SceneEffectInput, SceneEffectStage } from './stage';\nimport { windVelocity } from './velocity';\n\n/**\n * An anti-aliasing mode: SMAA (sharper, a few passes) or FXAA (one cheap pass, softer), both on\n * display colours, last in the stack; or TRAA (temporal: jittered frames blended over time, the\n * smoothest when still), on linear colours before tone mapping, with the Wind-aware velocity channel.\n */\nexport type SceneAntialiasMode = 'smaa' | 'fxaa' | 'traa';\n\n/** What TRAA reads besides the colour: the scene pass's depth, its Wind-aware velocity and the camera. */\nexport type SceneAntialiasInput = Pick<SceneEffectInput, 'depth' | 'velocity' | 'camera'>;\n\n/** An anti-aliasing node and the texture it samples (`textureNode`). */\ntype AntialiasNode = Node<'vec4'> & { textureNode: Node };\n\ntype PostMode = Exclude<SceneAntialiasMode, 'traa'>;\n\nconst NODES: Record<PostMode, (color: Node) => AntialiasNode> = {\n smaa: (color) => smaa(color) as unknown as AntialiasNode,\n fxaa: (color) => fxaa(color) as unknown as AntialiasNode,\n};\n\nfunction modeOf(mode: SceneAntialiasMode): SceneAntialiasMode {\n if (mode !== 'traa' && !(mode in NODES)) throw new Error(`Unknown anti-aliasing \"${mode}\"`);\n return mode;\n}\n\n/**\n * Scene Effect: anti-aliasing. SMAA and FXAA run on display colours: pass them the tone mapped\n * colour in the output colour space (e.g. the output of {@link sceneToneMapping}, or\n * `renderOutput(color)`), and set `pipeline.outputColorTransform = false`. TRAA runs on linear\n * colours, before tone mapping, and needs `input`: the scene pass's depth, its velocity (from\n * `windVelocityMRT()`, so swaying leaves don't ghost) and the camera (which it jitters while the\n * RenderPipeline renders).\n *\n * Side effect of `'traa'`: it sets `options.samples = 0` on the scene pass `depth` comes from (your\n * `pass(scene, camera)`), turning its MSAA off for good: TRAA copies the depth each frame, which a\n * multisampled depth cannot be (TRAA anti-aliases instead). The Scene Pipeline restores the old value\n * when TRAA goes off; with this function, set `samples` back yourself if you drop TRAA.\n */\nexport function sceneAntialias(color: Node<'vec4'>, mode: SceneAntialiasMode, input?: SceneAntialiasInput): Node<'vec4'> {\n return mode === 'traa' ? liveSceneTRAA(color, input ?? {}).node : liveSceneAntialias(color, mode).node;\n}\n\nfunction liveSceneAntialias(color: Node<'vec4'>, mode: SceneAntialiasMode) {\n // The effect samples a texture: the colour so far is rendered into one (a render target it owns).\n const node = NODES[modeOf(mode) as PostMode](color);\n return {\n node: node as Node<'vec4'>,\n dispose: () => {\n node.dispose();\n if (node.textureNode !== color) node.textureNode.dispose();\n },\n };\n}\n\n/** `TRAANode` with the (untyped) jitter methods it calls around each RenderPipeline render. */\ntype TRAAClass = new (...args: ConstructorParameters<typeof TRAANode>) => TRAANode & {\n setViewOffset(width: number, height: number): void;\n clearViewOffset(): void;\n readonly _originalProjectionMatrix: Matrix4;\n};\n\n/**\n * three's TRAA, which also keeps the Wind-aware velocity unjittered: TRAA gives three's own\n * `velocity` the unjittered projection while it jitters the camera; {@link windVelocity} is another\n * VelocityNode, so it gets the same (otherwise the jitter itself would read as motion).\n */\nclass WindTRAANode extends (TRAANode as unknown as TRAAClass) {\n override setViewOffset(width: number, height: number): void {\n super.setViewOffset(width, height);\n (windVelocity as unknown as VelocityNode).setProjectionMatrix(this._originalProjectionMatrix);\n }\n\n override clearViewOffset(): void {\n super.clearViewOffset();\n (windVelocity as unknown as VelocityNode).setProjectionMatrix(null);\n }\n}\n\nfunction liveSceneTRAA(color: Node<'vec4'>, { depth, velocity, camera }: SceneAntialiasInput) {\n const missing = Object.entries({ depth, velocity, camera }).filter(([, value]) => !value).map(([name]) => name);\n if (missing.length) {\n throw new Error(`TRAA (\"traa\" anti-aliasing) needs the scene pass's ${missing.join(', ')}: pass { depth, velocity, camera } (velocity from windVelocityMRT())`);\n }\n // TRAA keeps the previous frame's depth by copying it, which a multisampled depth cannot be: the\n // scene pass renders without MSAA while TRAA is on (TRAA anti-aliases instead); restored on dispose.\n const scenePass = (depth as { passNode?: PassNode }).passNode;\n const samples = scenePass?.options.samples;\n if (scenePass) scenePass.options.samples = 0;\n // TRAA samples a texture: the colour so far is rendered into one (a render target it owns).\n const beauty = convertToTexture(color);\n const node = new WindTRAANode(beauty, depth!, velocity!, camera!);\n return {\n node: node as unknown as Node<'vec4'>,\n dispose: () => {\n node.dispose();\n if (beauty !== color) beauty.dispose();\n if (scenePass) scenePass.options.samples = samples;\n },\n };\n}\n\n/**\n * The TRAA step of the stack, before tone mapping (as three requires), on the scene pass's depth and\n * Wind-aware velocity (the Scene Pipeline turns the velocity channel on for it).\n */\nexport const traaStage: SceneEffectStage = {\n shape: (settings) => (settings.antialias === 'traa' ? 'traa' : undefined),\n build(input) {\n const live = liveSceneTRAA(input.color, input);\n return { node: live.node, update: () => {}, dispose: live.dispose };\n },\n needsVelocity: true,\n};\n\n/**\n * The SMAA / FXAA step of the stack, last (after tone mapping). Without tone mapping it applies the\n * renderer's output transform itself, so it always runs on (and outputs) display colours.\n */\nexport const antialiasStage: SceneEffectStage = {\n shape: (settings) => {\n const mode = settings.antialias;\n return mode && mode !== 'traa' ? [modeOf(mode), !!settings.toneMapping] : undefined;\n },\n build(input, settings) {\n const display = settings.toneMapping ? input.color : (renderOutput(input.color) as unknown as Node<'vec4'>);\n const live = liveSceneAntialias(display, settings.antialias!);\n return { node: live.node, update: () => {}, dispose: live.dispose };\n },\n display: true,\n};\n","import type { Node } from 'three/webgpu';\nimport { uniform, vec4 } from 'three/tsl';\nimport { bloom } from 'three/addons/tsl/display/BloomNode.js';\nimport type { SceneEffectStage } from './stage';\n\n/** Bloom settings (all optional; all uniforms). */\nexport interface SceneBloomOptions {\n /** How much glare is added (default 0.3). */\n strength?: number;\n /** How far the glare spreads, 0..1 (default 0.5). */\n radius?: number;\n /** Only colours brighter than this (linear luminance, before tone mapping) glow (default 0.6; a plain light sky is about 0.6). */\n threshold?: number;\n}\n\nconst DEFAULTS: Required<SceneBloomOptions> = { strength: 0.3, radius: 0.5, threshold: 0.6 };\n\n/**\n * Scene Effect: bloom, a soft glare around the bright (HDR) parts of the frame, added onto the\n * colour. Use it on linear colours before tone mapping.\n */\nexport function sceneBloom(color: Node<'vec4'>, options: SceneBloomOptions = {}): Node<'vec4'> {\n return liveSceneBloom(color, options).node;\n}\n\nfunction liveSceneBloom(color: Node<'vec4'>, options: SceneBloomOptions) {\n const strength = uniform(0);\n const radius = uniform(0);\n const threshold = uniform(0);\n const update = (o: SceneBloomOptions): void => {\n strength.value = o.strength ?? DEFAULTS.strength;\n radius.value = o.radius ?? DEFAULTS.radius;\n threshold.value = o.threshold ?? DEFAULTS.threshold;\n };\n update(options);\n const glare = bloom(color, strength, radius, threshold);\n // Add the glare's colour only: the frame keeps its own alpha.\n const node = vec4(color.rgb.add(glare.rgb), color.a) as unknown as Node<'vec4'>;\n return { node, update, dispose: () => glare.dispose() };\n}\n\n/** The bloom step of the stack (one graph for all settings: every number is a uniform). */\nexport const bloomStage: SceneEffectStage = {\n shape: (settings) => (settings.bloom ? true : undefined),\n build(input, settings) {\n const live = liveSceneBloom(input.color, settings.bloom!);\n return { node: live.node, update: (s) => live.update(s.bloom!), dispose: live.dispose };\n },\n};\n","import type { Node, TextureNode } from 'three/webgpu';\nimport { float, Fn, int, Loop, uniform, uv, vec2, vec4 } from 'three/tsl';\nimport { asTexture, type SceneEffectStage } from './stage';\n\n/** Motion blur settings (all optional; all uniforms). */\nexport interface SceneMotionBlurOptions {\n /**\n * How long the shutter is open, in frames: the blur streak is this many frames of motion long\n * (default 1). 0 = no blur.\n */\n strength?: number;\n /** Colour samples along each pixel's motion; more is smoother and costs more (default 16). */\n samples?: number;\n}\n\nconst DEFAULTS: Required<SceneMotionBlurOptions> = { strength: 1, samples: 16 };\n\n/**\n * Scene Effect: motion blur. Smears each pixel along its screen-space motion, read from `velocity`\n * (NDC units per frame, as three's `velocity`). Use the scene pass's Wind-aware velocity\n * (`windVelocityMRT()`, or `scenePass.velocity` of a Scene Pipeline with motion blur), so that Wind\n * sway blurs as well as camera and object motion. Use it on linear colours, after god rays and\n * before bloom. Returns a colour node.\n */\nexport function sceneMotionBlur(color: Node<'vec4'>, velocity: TextureNode, options: SceneMotionBlurOptions = {}): Node<'vec4'> {\n return liveSceneMotionBlur(color, velocity, options).node;\n}\n\nfunction liveSceneMotionBlur(color: Node<'vec4'>, velocity: TextureNode | undefined, options: SceneMotionBlurOptions) {\n if (!velocity) {\n throw new Error('tree.js sceneMotionBlur: needs a velocity channel (e.g. a scene pass with windVelocityMRT()).');\n }\n const strength = uniform(0);\n const samples = uniform(0, 'int');\n const update = (o: SceneMotionBlurOptions): void => {\n strength.value = o.strength ?? DEFAULTS.strength;\n samples.value = Math.max(1, Math.round(o.samples ?? DEFAULTS.samples));\n };\n update(options);\n // The blur samples around each pixel: a texture (the colour so far rendered to one when needed).\n const base = asTexture(color);\n const node = Fn(() => {\n const coord = uv();\n // NDC (y up, 2 units across) to texture coordinates (y down, 1 across), as three's TRAA does.\n const streak = velocity.sample(coord).xy.mul(vec2(0.5, -0.5)).mul(strength);\n const sum = vec4(0).toVar();\n // Evenly along the streak, centred on the pixel (the motion while the shutter is open).\n Loop({ start: int(0), end: samples, type: 'int', condition: '<' }, ({ i }) => {\n sum.addAssign(base.sample(coord.add(streak.mul(float(i).add(0.5).div(float(samples)).sub(0.5)))));\n });\n return sum.div(float(samples));\n })() as unknown as Node<'vec4'>;\n const dispose = (): void => {\n if (base !== color) base.dispose();\n };\n return { node, update, dispose };\n}\n\n/** The motion blur step of the stack: reads `input.velocity` (the Scene Pipeline requests it). */\nexport const motionBlurStage: SceneEffectStage = {\n shape: (settings) => (settings.motionBlur ? true : undefined),\n build(input, settings) {\n const live = liveSceneMotionBlur(input.color, input.velocity, settings.motionBlur!);\n return { node: live.node, update: (s) => live.update(s.motionBlur!), dispose: live.dispose };\n },\n needsVelocity: true,\n};\n","import {\n ACESFilmicToneMapping,\n AgXToneMapping,\n CineonToneMapping,\n LinearToneMapping,\n NeutralToneMapping,\n NoToneMapping,\n ReinhardToneMapping,\n type Node,\n type ToneMapping,\n} from 'three/webgpu';\nimport { renderOutput, toneMapping, uniform } from 'three/tsl';\nimport type { SceneEffectStage } from './stage';\n\n/** A tone mapping curve: AgX and Neutral keep foliage green; ACES shifts greens towards yellow. */\nexport type SceneToneMappingCurve = 'agx' | 'neutral' | 'aces' | 'reinhard' | 'cineon' | 'linear';\n\n/** Tone mapping settings (all optional). */\nexport interface SceneToneMappingOptions {\n /** The curve (default 'agx'). Changing it builds a new graph. */\n mapping?: SceneToneMappingCurve;\n /** Exposure before the curve (default 1); a uniform. */\n exposure?: number;\n}\n\nconst CURVES: Record<SceneToneMappingCurve, ToneMapping> = {\n agx: AgXToneMapping,\n neutral: NeutralToneMapping,\n aces: ACESFilmicToneMapping,\n reinhard: ReinhardToneMapping,\n cineon: CineonToneMapping,\n linear: LinearToneMapping,\n};\n\nfunction curveOf(options: SceneToneMappingOptions): SceneToneMappingCurve {\n const mapping = options.mapping ?? 'agx';\n if (!(mapping in CURVES)) throw new Error(`Unknown tone mapping \"${mapping}\"`);\n return mapping;\n}\n\n/**\n * Scene Effect: tone mapping plus the conversion to the renderer's output colour space, inside the\n * pipeline (the renderer's `toneMapping` is not used or changed). Returns display colours: in your\n * own `RenderPipeline`, set `pipeline.outputColorTransform = false` (as for three's `renderOutput`).\n */\nexport function sceneToneMapping(color: Node<'vec4'>, options: SceneToneMappingOptions = {}): Node<'vec4'> {\n return liveSceneToneMapping(color, options).node;\n}\n\nfunction liveSceneToneMapping(color: Node<'vec4'>, options: SceneToneMappingOptions) {\n const exposure = uniform(1);\n const update = (o: SceneToneMappingOptions): void => {\n exposure.value = o.exposure ?? 1;\n };\n update(options);\n // Our own curve with a uniform exposure, then renderOutput with no further tone mapping: only the\n // output colour space (the renderer's, through the pipeline's context).\n const mapped = toneMapping(CURVES[curveOf(options)], exposure, color) as unknown as Node<'vec4'>;\n return { node: renderOutput(mapped, NoToneMapping, null) as unknown as Node<'vec4'>, update };\n}\n\n/** The tone mapping step of the stack. */\nexport const toneMappingStage: SceneEffectStage = {\n shape: (settings) => (settings.toneMapping ? curveOf(settings.toneMapping) : undefined),\n build(input, settings) {\n const live = liveSceneToneMapping(input.color, settings.toneMapping!);\n return { node: live.node, update: (s) => live.update(s.toneMapping!) };\n },\n display: true,\n};\n","import type { Node } from 'three/webgpu';\nimport type { SceneEffectsSettings } from './settings';\nimport type { LiveSceneEffect, SceneEffectInput, SceneEffectStage } from './stage';\nimport { godraysStage } from './godrays';\nimport { antialiasStage, traaStage } from './antialias';\nimport { bloomStage } from './bloom';\nimport { motionBlurStage } from './motion-blur';\nimport { toneMappingStage } from './tone-mapping';\n\n/**\n * The colour steps of the Scene Effects, in stack order. Fog (in the materials) and ambient\n * occlusion (in the scene pass's lighting) are not colour steps; the Tree Effects come before all\n * of these. Order: god rays -> motion blur -> bloom -> (TRAA) -> tone mapping + output colour\n * space -> SMAA / FXAA.\n */\nconst STACK: readonly SceneEffectStage[] = [\n godraysStage,\n motionBlurStage,\n bloomStage,\n traaStage, // TRAA (before tone mapping)\n toneMappingStage,\n antialiasStage, // SMAA / FXAA (on display colours)\n];\n\n/**\n * The shape of a combination: equal for settings whose graphs are the same (that differ only in\n * uniforms).\n */\nexport function sceneEffectsShape(settings: SceneEffectsSettings): string {\n return JSON.stringify(STACK.map((stage) => stage.shape(settings) ?? null));\n}\n\n/** Whether the steps that are on read the Wind-aware velocity channel (`input.velocity`). */\nexport function sceneEffectsNeedVelocity(settings: SceneEffectsSettings): boolean {\n return STACK.some((stage) => stage.needsVelocity === true && stage.shape(settings) !== undefined);\n}\n\n/** The built stack: its colour node, whether that is display colours, `update()` and `dispose()`. */\nexport interface LiveSceneEffects extends Required<LiveSceneEffect> {\n /** The output is display colours (tone mapped, output colour space): no further output transform. */\n display: boolean;\n}\n\n/** {@link applySceneEffects} with every colour and number as a uniform; `update()` needs the same shape. */\nexport function liveSceneEffects(input: SceneEffectInput, settings: SceneEffectsSettings): LiveSceneEffects {\n const built: LiveSceneEffect[] = [];\n let color = input.color;\n let display = false;\n for (const stage of STACK) {\n if (stage.shape(settings) === undefined) continue;\n const live = stage.build({ ...input, color }, settings);\n built.push(live);\n color = live.node;\n display ||= stage.display === true;\n }\n return {\n node: color,\n display,\n update: (s) => built.forEach((live) => live.update(s)),\n dispose: () => built.forEach((live) => live.dispose?.()),\n };\n}\n\n/**\n * Applies a combination of Scene Effects to `input.color` (e.g. the output of `applyTreeEffects`)\n * and returns the resulting colour node, for your own pipeline. Empty settings return\n * `input.color`. With tone mapping the result is display colours: set\n * `pipeline.outputColorTransform = false`.\n */\nexport function applySceneEffects(input: SceneEffectInput, settings: SceneEffectsSettings): Node<'vec4'> {\n return liveSceneEffects(input, settings).node;\n}\n","import { RenderPipeline, type Camera, type Light, type Node, type Object3D, type Renderer, type Scene } from 'three/webgpu';\nimport {\n channelsFor,\n channelsKey,\n collectEffectNodes,\n liveTreeEffects,\n resolveTreeEffects,\n treeEffectsShape,\n} from '../effects/effects';\nimport type { TreeEffectsChoice } from '../effects/effects';\nimport { CustomTreeEffectList, type CustomTreeEffect, type CustomTreeEffectOptions } from '../effects/custom';\nimport type { TreeEffectsSettings } from '../effects/suggested';\nimport { readTreeId, treeFromId } from '../effects/tree-id';\nimport type { LiveTreeEffect } from '../effects/live';\nimport type { StyleName } from '../styles/registry';\nimport type { ForestTree } from '../forest';\nimport type { Tree } from '../tree';\nimport { resolveSceneEffects, type SceneEffectsChoice, type SceneEffectsSettings } from './settings';\nimport { godraysSunProblem, warnGodraysSkipped } from './godrays';\nimport { liveSceneAO } from './ao';\nimport { liveSceneFog } from './fog';\nimport { liveSceneEffects, sceneEffectsNeedVelocity, sceneEffectsShape, type LiveSceneEffects } from './stack';\nimport { createScenePass, type ScenePass, type ScenePassChannels } from './velocity';\n\n/**\n * Which Tree Effects and Scene Effects to render. `style` picks both of that Style's suggestions;\n * `treeEffects` and `sceneEffects` replace a whole group (a Style name, settings or `null` = none;\n * no deep merge: spread the suggestion to change part of it). Nothing set = nothing added.\n */\nexport interface ScenePipelineChoice {\n style?: StyleName;\n treeEffects?: TreeEffectsChoice;\n sceneEffects?: SceneEffectsChoice;\n}\n\nexport interface ScenePipelineOptions extends ScenePipelineChoice {\n /** A shadow-casting light for god rays (never changed by the pipeline). */\n sun?: Light;\n /** The trees to outline (as `TreeEffectsOptions.selection`). Default: every tree. */\n selection?: Object3D[];\n /** Keeps the Tree ID channel on for {@link ScenePipeline.pick} (as `TreeEffectsOptions.treeId`). */\n treeId?: boolean;\n /** The trees the Highlight marks (as `TreeEffectsOptions.highlighted`). */\n highlighted?: (Tree | ForestTree)[];\n /**\n * Keeps the Wind-aware velocity channel on (`scenePass.velocity`, see `windVelocityMRT`), e.g. for\n * your own temporal effects. TRAA and motion blur turn it on by themselves.\n */\n velocity?: boolean;\n}\n\n/** The resolved settings of a Scene Pipeline (`{}` = none in a group). */\nexport interface ScenePipelineSettings {\n treeEffects: TreeEffectsSettings;\n sceneEffects: SceneEffectsSettings;\n}\n\nfunction resolveChoice(choice: ScenePipelineChoice): ScenePipelineSettings {\n const style = choice.style ?? null;\n return {\n treeEffects: resolveTreeEffects(choice.treeEffects !== undefined ? choice.treeEffects : style),\n sceneEffects: resolveSceneEffects(choice.sceneEffects !== undefined ? choice.sceneEffects : style),\n };\n}\n\n/** Nothing is on: every part is left out, `undefined` or `null` (e.g. `{ antialias: null }`). */\nfunction isEmpty(settings: ScenePipelineSettings): boolean {\n return [settings.treeEffects, settings.sceneEffects].every((group) => Object.values(group).every((part) => part == null));\n}\n\n/** The scene pass channels the settings need (with the `treeId` and `velocity` options and the custom effects' channels). */\nfunction channelsOf(settings: ScenePipelineSettings, options: ScenePipelineOptions, custom: CustomTreeEffectList): ScenePassChannels {\n return { ...channelsFor(settings.treeEffects, options, custom), velocity: wantsVelocity(settings, options) };\n}\n\n/** Whether the scene pass renders Wind-aware velocity (ADR 0011): only when something reads it. */\nfunction wantsVelocity(settings: ScenePipelineSettings, options: ScenePipelineOptions): boolean {\n return options.velocity === true || sceneEffectsNeedVelocity(settings.sceneEffects);\n}\n\n/**\n * The Scene Pipeline: renders the scene with Tree Effects and Scene Effects in one `RenderPipeline`.\n * A superset of `TreeEffects` (use it instead). It never changes the renderer (tone mapping and the\n * output colour space are applied inside the pipeline). With nothing set it adds nothing: the\n * same image as `renderer.render(scene, camera)`.\n */\nexport class ScenePipeline {\n readonly pipeline: RenderPipeline;\n /** The trees the Highlight marks (the `highlighted` option, or an empty list): change it in place. */\n readonly highlighted: (Tree | ForestTree)[];\n private current: ScenePipelineSettings = { treeEffects: {}, sceneEffects: {} };\n private readonly custom = new CustomTreeEffectList();\n private graph: {\n shape: string;\n tree: LiveTreeEffect<TreeEffectsSettings>;\n scene: LiveSceneEffects;\n treeNodes: Node[];\n /** GTAO: its pre-pass and AO node, fed into the scene pass's lighting through its context. */\n ao: ReturnType<typeof liveSceneAO> | null;\n } | null = null;\n private input!: { channels: string; pass: ScenePass };\n /** Nothing is on (no effects, no extra channel): render with `renderer.render()` itself. */\n private passThrough = true;\n /** The pipeline's fog while it is on, and the app's `scene.fogNode` it replaced (restored when off). */\n private fog: { live: ReturnType<typeof liveSceneFog>; app: Node | null | undefined } | null = null;\n /** God rays were skipped for want of a shadow-casting sun, and that was said once. */\n private warnedSun = false;\n\n constructor(\n private readonly renderer: Renderer,\n private readonly scene: Scene,\n private readonly camera: Camera,\n private readonly options: ScenePipelineOptions = {},\n ) {\n this.pipeline = new RenderPipeline(renderer);\n this.highlighted = options.highlighted ?? [];\n this.set(options);\n }\n\n /** The scene pass; replaced (the old one disposed) when {@link set} needs another set of channels. */\n get scenePass(): ScenePass {\n return this.input.pass;\n }\n\n /** The active Tree Effects and Scene Effects. */\n get settings(): ScenePipelineSettings {\n return this.current;\n }\n\n /**\n * Switches Style or settings (the same rules as the options). With the same parts on, only\n * uniforms change (no recompile); otherwise a new graph is built and the old one freed.\n */\n set(choice: ScenePipelineChoice): void {\n this.current = resolveChoice(choice);\n this.rebuild();\n }\n\n /** The app's own Tree Effects, in the order they were added (see {@link addEffect}). */\n get customEffects(): readonly CustomTreeEffect<never>[] {\n return this.custom.effects;\n }\n\n /**\n * Adds a Tree Effect of the app's own (as `TreeEffects.addEffect()`): it runs at the place it names\n * among the built-in Tree Effects, so before every Scene Effect. It stays through {@link set} until\n * {@link removeEffect}. Builds a new graph, and a new scene pass if it declares a channel that is not on yet.\n */\n addEffect<Options>(effect: CustomTreeEffect<Options>, ...[options]: CustomTreeEffectOptions<Options>): void {\n this.custom.add(effect, options as Options);\n this.rebuild();\n }\n\n /** Changes the options of an added custom effect live, through its `update()` (no new graph, no recompile). */\n updateEffect<Options>(effect: CustomTreeEffect<Options>, options: Options): void {\n this.custom.update(effect, options);\n }\n\n /** Removes a custom effect (nothing happens if it is not added); its channels go when nothing else needs them. */\n removeEffect<Options>(effect: CustomTreeEffect<Options>): void {\n if (this.custom.remove(effect as CustomTreeEffect<never>)) this.rebuild();\n }\n\n /** Brings the scene pass, the graph and the fog in line with the settings and the custom effects. */\n private rebuild(): void {\n const channels = channelsKey(channelsOf(this.current, this.options, this.custom));\n if (this.input?.channels !== channels) {\n // Other channels: a new scene pass (new MRT, ADR 0009), and a new graph that reads it.\n this.disposeGraph();\n this.input?.pass.pass.dispose();\n this.input = {\n channels,\n pass: createScenePass(this.scene, this.camera, this.options.selection ?? null, channelsOf(this.current, this.options, this.custom)),\n };\n }\n const sceneEffects = this.usableSceneEffects(this.current.sceneEffects);\n this.passThrough = channels === '' && isEmpty({ ...this.current, sceneEffects }) && this.custom.effects.length === 0;\n this.setFog();\n const { ao: aoSettings } = sceneEffects;\n const shape = JSON.stringify([\n treeEffectsShape(this.current.treeEffects, this.scenePass, this.custom),\n sceneEffectsShape(sceneEffects),\n aoSettings !== undefined,\n ]);\n if (this.graph?.shape === shape) {\n this.graph.tree.update(this.current.treeEffects);\n this.graph.scene.update(sceneEffects);\n if (aoSettings) this.graph.ao?.update(aoSettings);\n return;\n }\n this.disposeGraph();\n const tree = liveTreeEffects(this.scenePass, this.current.treeEffects, this.highlighted, this.custom);\n const scene = liveSceneEffects({ ...this.scenePass, color: tree.node, sun: this.options.sun }, sceneEffects);\n // AO only darkens ambient light: a pre-pass, GTAO, and its context on the scene pass's lighting.\n const ao = aoSettings ? liveSceneAO(this.scene, this.camera, aoSettings) : null;\n this.scenePass.pass.contextNode = ao?.context ?? null;\n this.scenePass.pass.needsUpdate = true;\n this.graph = { shape, tree, scene, treeNodes: collectEffectNodes(tree.node, this.scenePass.color), ao };\n this.pipeline.outputNode = scene.node;\n // Display colours from the stack (tone mapping): no output transform of the renderer's.\n this.pipeline.outputColorTransform = !scene.display;\n this.pipeline.needsUpdate = true;\n }\n\n /**\n * GPU picking, as `TreeEffects.pick()`: the Tree or Forest tree under a canvas point (CSS pixels)\n * in the last render. Needs the Tree ID channel (the `treeId: true` option).\n */\n pick(x: number, y: number): Promise<Tree | ForestTree | undefined> {\n const { pass, treeId } = this.scenePass;\n if (!treeId) throw new Error('ScenePipeline.pick() needs the Tree ID channel: create the pipeline with the `treeId: true` option');\n return readTreeId(this.renderer, pass, x, y).then(treeFromId);\n }\n\n /** Renders the scene (call instead of `renderer.render(scene, camera)`). */\n render(): void {\n // Nothing to add: exactly the app's own render (a pass + output transform rounds differently).\n if (this.passThrough) this.renderer.render(this.scene, this.camera);\n else this.pipeline.render();\n }\n\n dispose(): void {\n this.restoreFog();\n this.disposeGraph();\n this.scenePass.pass.dispose();\n this.pipeline.dispose();\n }\n\n /** Fog is the one scene change (ADR 0010): take over `scene.fogNode`, remembering the app's value. */\n private setFog(): void {\n const settings = this.current.sceneEffects.fog;\n if (!settings) return this.restoreFog();\n if (this.fog) return this.fog.live.update(settings, this.scene.background);\n const live = liveSceneFog(settings, this.scene.background);\n this.fog = { live, app: this.scene.fogNode };\n this.scene.fogNode = live.node;\n }\n\n /** Gives `scene.fogNode` back to the app (unless the app replaced the pipeline's fog meanwhile). */\n private restoreFog(): void {\n if (!this.fog) return;\n if (this.scene.fogNode === this.fog.live.node) this.scene.fogNode = this.fog.app;\n this.fog = null;\n }\n\n /**\n * The Scene Effects that can run: without a shadow-casting `sun`, god rays are left out (with one\n * console warning per pipeline). Shadows and lights are never changed.\n */\n private usableSceneEffects(settings: SceneEffectsSettings): SceneEffectsSettings {\n if (!settings.godrays) return settings;\n const problem = godraysSunProblem(this.options.sun);\n if (!problem) return settings;\n if (!this.warnedSun) warnGodraysSkipped(problem);\n this.warnedSun = true;\n return { ...settings, godrays: undefined };\n }\n\n private disposeGraph(): void {\n if (!this.graph) return;\n for (const node of this.graph.treeNodes) node.dispose();\n this.graph.scene.dispose();\n if (this.graph.ao) {\n this.graph.ao.dispose();\n this.scenePass.pass.contextNode = null;\n }\n this.graph = null;\n }\n}\n\n/** Shorthand for `new ScenePipeline(renderer, scene, camera, options)`. */\nexport function createScenePipeline(renderer: Renderer, scene: Scene, camera: Camera, options?: ScenePipelineOptions): ScenePipeline {\n return new ScenePipeline(renderer, scene, camera, options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAWA,IAAa,0BAAmE;CAE9E,YAAY;EACV,aAAa,EAAE,SAAS,UAAU;EAElC,IAAI;GAAE,QAAQ;GAAG,OAAO;GAAK,WAAW;EAAE;EAC1C,WAAW;EACX,KAAK;GAAE,MAAM;GAAI,KAAK;EAAI;CAC5B;CAGA,UAAU;EACR,aAAa;GAAE,SAAS;GAAO,UAAU;EAAI;EAC7C,IAAI;GAAE,QAAQ;GAAK,OAAO;GAAK,WAAW;EAAE;EAG5C,OAAO;GAAE,UAAU;GAAK,QAAQ;GAAK,WAAW;EAAK;EACrD,WAAW;EAEX,KAAK;GAAE,MAAM;GAAI,KAAK;GAAK,MAAM;IAAE,QAAQ;IAAK,UAAU;IAAK,MAAM;IAAI,KAAK;GAAG;EAAE;CACrF;CACA,WAAW;EACT,aAAa;GAAE,SAAS;GAAO,UAAU;EAAI;EAC7C,IAAI;GAAE,QAAQ;GAAK,OAAO;GAAK,WAAW;EAAE;EAE5C,OAAO;GAAE,UAAU;GAAM,QAAQ;GAAK,WAAW;EAAK;EAItD,SAAS;GAAE,SAAS;GAAK,YAAY;GAAM,qBAAqB;GAAG,OAAO;EAAU;EACpF,WAAW;EAEX,KAAK;GAAE,MAAM;GAAI,KAAK;GAAK,MAAM;IAAE,QAAQ;IAAG,UAAU;IAAK,MAAM;IAAI,KAAK;IAAI,UAAU;KAAE,MAAM;KAAI,KAAK;KAAK,UAAU;IAAI;GAAE;EAAE;CACpI;AACF;;;ACPA,SAAgB,oBAAoB,QAAkD;CACpF,IAAI,WAAW,MAAM,OAAO,CAAC;CAC7B,IAAI,OAAO,WAAW,UAAU,OAAO;CACvC,MAAM,WAAY,wB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AG;EAClD,IAAI,CAAC,SAAS,OAAO;EACrB,IAAI,CAAC,KAAK,WAAW,mBAAmB,OAAO;EAC/C,KAAK,YAAY;EACjB,OAAO;GAAE,GAAG;GAAU,SAAS,KAAA;EAAU;CAC3C;CAEA,eAA6B;EAC3B,IAAI,CAAC,KAAK,OAAO;EACjB,KAAK,MAAM,QAAQ,KAAK,MAAM,WAAW,KAAK,QAAQ;EACtD,KAAK,MAAM,MAAM,QAAQ;EACzB,IAAI,KAAK,MAAM,IAAI;GACjB,KAAK,MAAM,GAAG,QAAQ;GACtB,KAAK,UAAU,KAAK,cAAc;EACpC;EACA,KAAK,QAAQ;CACf;AACF;;AAGA,SAAgB,oBAAoB,UAAoB,OAAc,QAAgB,SAA+C;CACnI,OAAO,IAAI,cAAc,UAAU,OAAO,QAAQ,OAAO;AAC3D"}
@@ -3,6 +3,19 @@ import type { SeasonProfileDefinition } from '../definition';
3
3
  /** A float uniform (`.value` is the Season). */
4
4
  export type SeasonUniform = UniformNode<'float', number>;
5
5
  type Node = any;
6
+ /** One leaf at one Season (TSL): see {@link leafSeasonNode}. */
7
+ export interface LeafSeasonNode {
8
+ /** Leaf colour (vec3, linear) at the leaf's shifted Season, or the blossom colour for a blossom. */
9
+ color: Node;
10
+ /** True while the leaf is shown (coverage above its rank, or a blossom). */
11
+ shown: Node;
12
+ }
13
+ /**
14
+ * The TSL twin of `leafSeason` for a Season Profile: returns a function that evaluates one leaf from
15
+ * a Season node and its Season timing (vec3: shift, coverage rank, blossom rank, as `aSeason`). The
16
+ * Profile's uniforms are made once, so it can be called for many leaves (an Impostor's frames).
17
+ */
18
+ export declare function leafSeasonNode(profile: SeasonProfileDefinition): (season: FloatNode<'float'>, part: Node) => LeafSeasonNode;
6
19
  /** The Season nodes of one tree's leaves; `S` is the Season input node (a uniform by default). */
7
20
  export interface SeasonNodes<S extends FloatNode<'float'> = SeasonUniform> {
8
21
  /** Season 0..1 (first day of spring .. last day of winter). For a uniform: write `.value`; nothing recompiles. */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C5C,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,KAAK,EAAE,IAAI,CAAC;IACZ,mEAAmE;IACnE,KAAK,EAAE,IAAI,CAAC;IACZ,sHAAsH;IACtH,QAAQ,EAAE,IAAI,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,uBAAuB,EAChC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,EAC1B,QAAQ,GAAE,IAAoB,GAC7B,gBAAgB,CAYlB;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC,GAAG,IAAI,CAGrH"}
@@ -0,0 +1,275 @@
1
+ import { d as TREE_PARTS, n as windMotionOf, t as setWindMotion } from "./motion-Qd7xjeZM.js";
2
+ import { Group } from "three/webgpu";
3
+ import { Fn, cross, dot, float, materialColor, materialRoughness, modelWorldMatrix, normalWorld, positionWorld, select, varying, varyingProperty, vec3, vec4, vertexColor } from "three/tsl";
4
+ // src/materials/shader-hooks.ts
5
+ var readyMade = /* @__PURE__ */ new WeakSet();
6
+ /**
7
+ * @internal Marks a hook the library ships (Snow Cover, Wetness) as ready-made: in every stack it runs
8
+ * before the app's own hooks (see {@link shaderHookOrder}). Returns the hook.
9
+ */
10
+ function readyMadeShaderHook(hook) {
11
+ readyMade.add(hook);
12
+ return hook;
13
+ }
14
+ var listOf = (value) => value ? typeof value === "function" ? [value] : value : [];
15
+ /**
16
+ * The hooks a tree part runs, in their fixed order: first the ready-made hooks (Snow Cover, Wetness), then
17
+ * the app's own; within each group the scene-wide default's before the Tree's or Forest's own, each in the
18
+ * order given. A hook listed twice runs once (at its first place). A part set to `null` on the Tree or
19
+ * Forest runs none, not even the scene-wide default's.
20
+ */
21
+ function shaderHookOrder(scene, own, part) {
22
+ if (own[part] === null) return [];
23
+ const all = [.../* @__PURE__ */ new Set([...listOf(scene[part]), ...listOf(own[part])])];
24
+ return [...all.filter((h) => readyMade.has(h)), ...all.filter((h) => !readyMade.has(h))];
25
+ }
26
+ /**
27
+ * Stacks sets of hooks into one: per part, the hooks of every set in the given order (as a list), e.g.
28
+ * `stackShaderHooks(snowCover, { leaves: painterly })`. A part that is `null` in a set and has no hook in
29
+ * any set stays `null`.
30
+ */
31
+ function stackShaderHooks(...sets) {
32
+ const stacked = {};
33
+ for (const part of TREE_PARTS) {
34
+ const hooks = sets.flatMap((set) => listOf(set[part]));
35
+ if (hooks.length > 0) stacked[part] = hooks;
36
+ else if (sets.some((set) => set[part] === null)) stacked[part] = null;
37
+ }
38
+ return stacked;
39
+ }
40
+ /** A copy of `hooks` without the parts that are `undefined`. */
41
+ function cleaned(hooks) {
42
+ const copy = {};
43
+ for (const part of TREE_PARTS) {
44
+ const value = hooks[part];
45
+ if (value !== void 0) copy[part] = Array.isArray(value) ? [...value] : value;
46
+ }
47
+ return copy;
48
+ }
49
+ var sceneHooks = {};
50
+ var followers = /* @__PURE__ */ new Set();
51
+ /**
52
+ * Sets the scene-wide default Tree Shader Hooks: every Tree and Forest runs them (now and when created
53
+ * later), before its own hooks, unless it sets that part to `null`. `{}` removes them. Only the parts
54
+ * whose hooks change rebuild their node graphs, once; the geometry is never rebuilt.
55
+ */
56
+ function setSceneShaderHooks(hooks) {
57
+ sceneHooks = cleaned(hooks);
58
+ for (const ref of followers) {
59
+ const live = ref.deref();
60
+ if (live) live.refresh();
61
+ else followers.delete(ref);
62
+ }
63
+ }
64
+ /** The scene-wide default Tree Shader Hooks (a copy), see {@link setSceneShaderHooks}. */
65
+ function getSceneShaderHooks() {
66
+ return cleaned(sceneHooks);
67
+ }
68
+ /**
69
+ * The {@link ShaderHookTarget} of one tree part drawn by `material` from `geometry` (a Tree's part, or a
70
+ * Forest Variant's): it multiplies in vertex colours when the material uses them and the geometry has them.
71
+ */
72
+ function partHookTarget(part, material, geometry, inputs) {
73
+ return {
74
+ parts: [part],
75
+ material,
76
+ vertexColors: material.vertexColors && geometry.hasAttribute("color"),
77
+ ...inputs
78
+ };
79
+ }
80
+ var isNode = (value) => value.isNode === true;
81
+ /**
82
+ * The normal three lights a smooth-shaded fragment with does not move with `positionNode` (only flat
83
+ * shading takes its facets from the moved positions). This turns it by how the Wind turned the surface:
84
+ * from the facet of the unswayed positions to that of the swayed ones (screen-space derivatives, a
85
+ * world-space sway varying), which also covers anything else added to the Wind displacement.
86
+ */
87
+ function swayedNormal(normal, sway) {
88
+ const swayWorld = varying(modelWorldMatrix.mul(vec4(sway, 0)).xyz);
89
+ const moved = positionWorld;
90
+ const still = moved.sub(swayWorld);
91
+ const to = cross(moved.dFdx(), moved.dFdy());
92
+ const from = cross(still.dFdx(), still.dFdy());
93
+ const a = from.normalize();
94
+ const b = to.normalize();
95
+ const axis = cross(a, b);
96
+ const c = dot(a, b);
97
+ const rotated = normal.mul(c).add(cross(axis, normal)).add(axis.mul(dot(axis, normal).div(c.add(1).max(1e-4)))).normalize();
98
+ const valid = dot(from, from).greaterThan(1e-20).and(dot(to, to).greaterThan(1e-20)).and(c.greaterThan(-.5));
99
+ return select(valid, rotated, normal);
100
+ }
101
+ /**
102
+ * The Tree Shader Hooks of a Tree or Forest: applies the hooks of each part (its own stacked after the
103
+ * scene-wide default's, {@link shaderHookOrder}) to that part's materials. A change rebuilds the node graph
104
+ * of the affected materials once (new `colorNode` / `roughnessNode`, `needsUpdate`), never the geometry;
105
+ * removing every hook puts the material's own nodes back as they were. A part whose hooks do not change is
106
+ * left alone. With no hook the materials are never touched (ADR 0008).
107
+ */
108
+ var LiveShaderHooks = class {
109
+ shading;
110
+ own = {};
111
+ stacks = {
112
+ bark: [],
113
+ leaves: [],
114
+ fruit: []
115
+ };
116
+ targets = [];
117
+ originals = /* @__PURE__ */ new Map();
118
+ ref = new WeakRef(this);
119
+ constructor(targets, shading, own = {}) {
120
+ this.shading = shading;
121
+ followers.add(this.ref);
122
+ this.own = cleaned(own);
123
+ this.stacks = this.resolve();
124
+ this.addTargets(targets);
125
+ }
126
+ /** The own hooks per part (a copy), as set. */
127
+ get hooks() {
128
+ return cleaned(this.own);
129
+ }
130
+ set hooks(value) {
131
+ this.own = cleaned(value);
132
+ this.refresh();
133
+ }
134
+ /** Adds materials made later (a Forest's Impostor cards), with the current hooks applied. */
135
+ addTargets(targets) {
136
+ for (const target of targets) {
137
+ this.targets.push(target);
138
+ if (target.parts.some((part) => this.stacks[part].length > 0)) this.apply(target);
139
+ }
140
+ }
141
+ /** Re-resolves the hooks (after the own or the scene-wide default ones changed) and rebuilds what changed. */
142
+ refresh() {
143
+ const next = this.resolve();
144
+ const changed = TREE_PARTS.filter((part) => next[part].length !== this.stacks[part].length || next[part].some((h, i) => h !== this.stacks[part][i]));
145
+ this.stacks = next;
146
+ for (const target of this.targets) if (target.parts.some((part) => changed.includes(part))) this.apply(target);
147
+ }
148
+ /** Stops following the scene-wide default hooks. */
149
+ dispose() {
150
+ followers.delete(this.ref);
151
+ }
152
+ resolve() {
153
+ return {
154
+ bark: shaderHookOrder(sceneHooks, this.own, "bark"),
155
+ leaves: shaderHookOrder(sceneHooks, this.own, "leaves"),
156
+ fruit: shaderHookOrder(sceneHooks, this.own, "fruit")
157
+ };
158
+ }
159
+ apply(target) {
160
+ const { material } = target;
161
+ let original = this.originals.get(material);
162
+ if (!original) {
163
+ original = {
164
+ colorNode: material.colorNode,
165
+ roughnessNode: material.roughnessNode,
166
+ positionNode: material.positionNode,
167
+ vertexColors: material.vertexColors
168
+ };
169
+ this.originals.set(material, original);
170
+ }
171
+ material.colorNode = original.colorNode;
172
+ material.roughnessNode = original.roughnessNode;
173
+ material.positionNode = original.positionNode;
174
+ material.vertexColors = original.vertexColors;
175
+ material.needsUpdate = true;
176
+ if (target.parts.filter((part) => this.stacks[part].length > 0).length === 0) {
177
+ this.originals.delete(material);
178
+ return;
179
+ }
180
+ const base = vec4(original.colorNode ?? materialColor);
181
+ const tinted = target.vertexColors ? base.mul(vertexColor()) : base;
182
+ const roughness = float(original.roughnessNode ?? materialRoughness);
183
+ const lazy = (make) => {
184
+ let value;
185
+ return () => value ??= make();
186
+ };
187
+ const normal = lazy(() => {
188
+ const sway = target.sway === void 0 ? windMotionOf(original.positionNode)?.offset : target.sway;
189
+ return sway && !material.flatShading ? swayedNormal(normalWorld, sway) : normalWorld;
190
+ });
191
+ const treePosition = lazy(() => {
192
+ if (target.treePosition) return target.treePosition;
193
+ if (!target.treeBase) return modelWorldMatrix.mul(vec4(0, 0, 0, 1)).xyz;
194
+ const captured = varyingProperty("vec3", "vTreeBase");
195
+ const treeBase = target.treeBase;
196
+ const position = original.positionNode;
197
+ material.positionNode = Fn(() => {
198
+ captured.assign(treeBase);
199
+ return position;
200
+ })();
201
+ const motion = windMotionOf(position);
202
+ if (motion) setWindMotion(material.positionNode, motion);
203
+ return modelWorldMatrix.mul(vec4(captured, 1)).xyz;
204
+ });
205
+ let color = vec3(0);
206
+ let rough = float(0);
207
+ let roughnessChanged = false;
208
+ for (const part of target.parts) {
209
+ let partColor = tinted.rgb;
210
+ let partRoughness = roughness;
211
+ for (const hook of this.stacks[part]) {
212
+ const input = {
213
+ part,
214
+ shading: this.shading,
215
+ color: partColor,
216
+ roughness: partRoughness,
217
+ position: positionWorld,
218
+ season: target.season,
219
+ growth: target.growth
220
+ };
221
+ Object.defineProperties(input, {
222
+ normal: {
223
+ get: normal,
224
+ enumerable: true
225
+ },
226
+ treePosition: {
227
+ get: treePosition,
228
+ enumerable: true
229
+ }
230
+ });
231
+ const result = hook(input);
232
+ const output = isNode(result) ? { color: result } : result;
233
+ partColor = output.color;
234
+ if (output.roughness) {
235
+ partRoughness = output.roughness;
236
+ roughnessChanged = true;
237
+ }
238
+ }
239
+ if (target.parts.length === 1) {
240
+ color = partColor;
241
+ rough = partRoughness;
242
+ } else {
243
+ const weight = target.partWeight(part);
244
+ color = color.add(partColor.mul(weight));
245
+ rough = rough.add(partRoughness.mul(weight));
246
+ }
247
+ }
248
+ material.colorNode = vec4(color, tinted.a);
249
+ material.vertexColors = false;
250
+ if (roughnessChanged) material.roughnessNode = rough;
251
+ }
252
+ };
253
+ /** @internal What a Tree and a Forest share: a group of tree meshes with Tree Shader Hooks. */
254
+ var ShaderHookedGroup = class extends Group {
255
+ /**
256
+ * The Tree Shader Hook per tree part (GLOSSARY, ADR 0012), e.g. `{ leaves: ({ color }) => color.mul(0.8) }`:
257
+ * a TSL function (or a list of them, which stack) that gets the part's base colour, world normal, world
258
+ * positions, Season and Growth and returns a new colour (optionally with a roughness). Assign a new
259
+ * object to set, change or remove hooks: a part left out has only the scene-wide default hooks
260
+ * (`setSceneShaderHooks`), its own run after those, and `null` runs none at all. Only the parts whose
261
+ * hooks changed rebuild their node graph, once; the geometry is never rebuilt. Without a hook a part is
262
+ * drawn exactly as before. On a Forest they reach every tree at every Detail Level, and the Impostors,
263
+ * which apply them at draw time to their baked colour, normals and Season data (changing a hook never
264
+ * rebakes).
265
+ */
266
+ get shaderHooks() {
267
+ return this.hooks.hooks;
268
+ }
269
+ set shaderHooks(value) {
270
+ this.hooks.hooks = value;
271
+ }
272
+ };
273
+ export { readyMadeShaderHook as a, partHookTarget as i, ShaderHookedGroup as n, setSceneShaderHooks as o, getSceneShaderHooks as r, stackShaderHooks as s, LiveShaderHooks as t };
274
+
275
+ //# sourceMappingURL=shader-hooks-BFRtlWGI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shader-hooks-BFRtlWGI.js","names":[],"sources":["../src/materials/shader-hooks.ts"],"sourcesContent":["import {\n cross,\n dot,\n float,\n Fn,\n materialColor,\n materialRoughness,\n modelWorldMatrix,\n normalWorld,\n positionWorld,\n select,\n varying,\n varyingProperty,\n vec3,\n vec4,\n vertexColor,\n} from 'three/tsl';\nimport { Group, type BufferGeometry, type MeshStandardNodeMaterial, type Node } from 'three/webgpu';\nimport type { Shading } from '../definition';\nimport { TREE_PARTS, type TreePart } from '../effects/mask';\nimport { setWindMotion, windMotionOf } from '../wind/motion';\n\n/** What a {@link TreeShaderHook} is given: TSL nodes of the fragment it shades, and which tree part it shades. */\nexport interface TreeShaderInput {\n /** The tree part the hook shades: 'bark', 'leaves' or 'fruit'. */\n part: TreePart;\n /** The tree's shading model (its Style): 'flat' (low-poly), 'toon' (stylized) or 'standard' (realistic). */\n shading: Shading;\n /**\n * The base colour (linear rgb): after Season, Ground Tint, textures and the Seed's tint, before lighting.\n * In a stack of hooks: the colour the hook before returned.\n */\n color: Node<'vec3'>;\n /** The part's roughness (0..1) before the hook (in a stack: the one the hook before returned, if any). */\n roughness: Node<'float'>;\n /**\n * The world-space normal the fragment is lit with, after Wind (and Wind Bursts) and Growth, with Crown\n * Normals and the bark normal map; facing the viewer on both sides of a leaf card. On an Impostor: its\n * baked normal, turned with the tree and its sway.\n */\n normal: Node<'vec3'>;\n /** The fragment's world position (after Wind and Growth). */\n position: Node<'vec3'>;\n /** The tree's own world position (its origin, at the foot of the trunk). */\n treePosition: Node<'vec3'>;\n /** The tree's Season (0..1). */\n season: Node<'float'>;\n /** The tree's Growth (0..1). */\n growth: Node<'float'>;\n}\n\n/** What a {@link TreeShaderHook} may return instead of a bare colour. */\nexport interface TreeShaderOutput {\n /** The new colour (linear rgb), lit as before. */\n color: Node<'vec3'>;\n /** The new roughness (0..1); the part's own when absent. */\n roughness?: Node<'float'>;\n}\n\n/**\n * A Tree Shader Hook (GLOSSARY, ADR 0012): a TSL function the app hands the library for a tree part. It\n * gets the part's base colour and inputs (see {@link TreeShaderInput}) and returns a new colour, or a\n * colour and a roughness. It is called once each time it is set (to build the node graph), not per frame:\n * animate it with uniforms.\n */\nexport type TreeShaderHook = (input: TreeShaderInput) => Node<'vec3'> | TreeShaderOutput;\n\n/**\n * The Tree Shader Hooks per tree part: one hook, or several that stack (each gets the colour and\n * roughness the one before returned). A part left out (or `undefined`) has only the scene-wide default\n * hooks ({@link setSceneShaderHooks}); a part's own hooks stack after those; `null` overrides them: the\n * part is drawn with no hook at all. See {@link shaderHookOrder} for the order.\n */\nexport type TreeShaderHooks = Partial<Record<TreePart, TreeShaderHook | readonly TreeShaderHook[] | null>>;\n\n// The hooks the library ships (Snow Cover, Wetness): they run before the app's own.\nconst readyMade = new WeakSet<TreeShaderHook>();\n\n/**\n * @internal Marks a hook the library ships (Snow Cover, Wetness) as ready-made: in every stack it runs\n * before the app's own hooks (see {@link shaderHookOrder}). Returns the hook.\n */\nexport function readyMadeShaderHook<T extends TreeShaderHook>(hook: T): T {\n readyMade.add(hook);\n return hook;\n}\n\nconst listOf = (value: TreeShaderHook | readonly TreeShaderHook[] | null | undefined): readonly TreeShaderHook[] =>\n value ? (typeof value === 'function' ? [value] : value) : [];\n\n/**\n * The hooks a tree part runs, in their fixed order: first the ready-made hooks (Snow Cover, Wetness), then\n * the app's own; within each group the scene-wide default's before the Tree's or Forest's own, each in the\n * order given. A hook listed twice runs once (at its first place). A part set to `null` on the Tree or\n * Forest runs none, not even the scene-wide default's.\n */\nexport function shaderHookOrder(scene: TreeShaderHooks, own: TreeShaderHooks, part: TreePart): TreeShaderHook[] {\n if (own[part] === null) return [];\n const all = [...new Set([...listOf(scene[part]), ...listOf(own[part])])];\n return [...all.filter((h) => readyMade.has(h)), ...all.filter((h) => !readyMade.has(h))];\n}\n\n/**\n * Stacks sets of hooks into one: per part, the hooks of every set in the given order (as a list), e.g.\n * `stackShaderHooks(snowCover, { leaves: painterly })`. A part that is `null` in a set and has no hook in\n * any set stays `null`.\n */\nexport function stackShaderHooks(...sets: readonly TreeShaderHooks[]): TreeShaderHooks {\n const stacked: TreeShaderHooks = {};\n for (const part of TREE_PARTS) {\n const hooks = sets.flatMap((set) => listOf(set[part]));\n if (hooks.length > 0) stacked[part] = hooks;\n else if (sets.some((set) => set[part] === null)) stacked[part] = null;\n }\n return stacked;\n}\n\n/** A copy of `hooks` without the parts that are `undefined`. */\nfunction cleaned(hooks: TreeShaderHooks): TreeShaderHooks {\n const copy: TreeShaderHooks = {};\n for (const part of TREE_PARTS) {\n const value = hooks[part];\n if (value !== undefined) copy[part] = Array.isArray(value) ? [...(value as TreeShaderHook[])] : value;\n }\n return copy;\n}\n\n// The scene-wide default hooks, and every Tree's and Forest's hooks that follow them.\nlet sceneHooks: TreeShaderHooks = {};\nconst followers = new Set<WeakRef<LiveShaderHooks>>();\n\n/**\n * Sets the scene-wide default Tree Shader Hooks: every Tree and Forest runs them (now and when created\n * later), before its own hooks, unless it sets that part to `null`. `{}` removes them. Only the parts\n * whose hooks change rebuild their node graphs, once; the geometry is never rebuilt.\n */\nexport function setSceneShaderHooks(hooks: TreeShaderHooks): void {\n sceneHooks = cleaned(hooks);\n for (const ref of followers) {\n const live = ref.deref();\n if (live) live.refresh();\n else followers.delete(ref);\n }\n}\n\n/** The scene-wide default Tree Shader Hooks (a copy), see {@link setSceneShaderHooks}. */\nexport function getSceneShaderHooks(): TreeShaderHooks {\n return cleaned(sceneHooks);\n}\n\n/**\n * One material hooks are applied to: a Tree's part, a Forest Variant's part (drawn at every Detail Level\n * but Impostor), or a Forest Variant's Impostor card, which draws several parts.\n */\nexport interface ShaderHookTarget {\n material: MeshStandardNodeMaterial;\n /** The tree parts the material draws, and (when it draws several) how much of each a fragment is (0..1). */\n parts: readonly TreePart[];\n partWeight?: (part: TreePart) => Node<'float'>;\n /** Whether the material multiplies in per-vertex colours (the Seed's tint): `vertexColors` and a `color` attribute. */\n vertexColors: boolean;\n season: Node<'float'>;\n growth: Node<'float'>;\n /** The tree's world position (a node the fragment stage can read). Default: see `treeBase`. */\n treePosition?: Node<'vec3'>;\n /**\n * The tree's base in the material's object space, as the vertex stage knows it before `positionNode`\n * runs (a Forest instance). It is handed to the fragment stage only when a hook reads `treePosition`.\n * Without it nor `treePosition`: the origin of the drawn object.\n */\n treeBase?: Node<'vec3'>;\n /**\n * The Wind displacement of the vertex in the material's object space (attributes and uniforms only).\n * Default: the one registered with the material's `positionNode` (`setWindMotion`).\n */\n sway?: Node<'vec3'> | null;\n}\n\n/**\n * The {@link ShaderHookTarget} of one tree part drawn by `material` from `geometry` (a Tree's part, or a\n * Forest Variant's): it multiplies in vertex colours when the material uses them and the geometry has them.\n */\nexport function partHookTarget(\n part: TreePart,\n material: MeshStandardNodeMaterial,\n geometry: BufferGeometry,\n inputs: Pick<ShaderHookTarget, 'season' | 'growth' | 'treeBase'>,\n): ShaderHookTarget {\n return { parts: [part], material, vertexColors: material.vertexColors && geometry.hasAttribute('color'), ...inputs };\n}\n\nconst isNode = (value: Node<'vec3'> | TreeShaderOutput): value is Node<'vec3'> => (value as { isNode?: boolean }).isNode === true;\n\n/** The material nodes hooks replace, as they were without one. */\ninterface Original {\n colorNode: MeshStandardNodeMaterial['colorNode'];\n roughnessNode: MeshStandardNodeMaterial['roughnessNode'];\n positionNode: MeshStandardNodeMaterial['positionNode'];\n vertexColors: boolean;\n}\n\n/**\n * The normal three lights a smooth-shaded fragment with does not move with `positionNode` (only flat\n * shading takes its facets from the moved positions). This turns it by how the Wind turned the surface:\n * from the facet of the unswayed positions to that of the swayed ones (screen-space derivatives, a\n * world-space sway varying), which also covers anything else added to the Wind displacement.\n */\nfunction swayedNormal(normal: Node<'vec3'>, sway: Node<'vec3'>): Node<'vec3'> {\n const swayWorld = varying(modelWorldMatrix.mul(vec4(sway, 0)).xyz);\n const moved = positionWorld;\n const still = moved.sub(swayWorld);\n const to = cross(moved.dFdx(), moved.dFdy());\n const from = cross(still.dFdx(), still.dFdy());\n const a = from.normalize();\n const b = to.normalize();\n const axis = cross(a, b);\n const c = dot(a, b);\n // Rodrigues: the rotation that takes a to b, applied to the normal.\n const rotated = normal\n .mul(c)\n .add(cross(axis, normal))\n .add(axis.mul(dot(axis, normal).div(c.add(1).max(1e-4))))\n .normalize();\n const valid = dot(from, from).greaterThan(1e-20).and(dot(to, to).greaterThan(1e-20)).and(c.greaterThan(-0.5));\n return select(valid, rotated, normal);\n}\n\n/**\n * The Tree Shader Hooks of a Tree or Forest: applies the hooks of each part (its own stacked after the\n * scene-wide default's, {@link shaderHookOrder}) to that part's materials. A change rebuilds the node graph\n * of the affected materials once (new `colorNode` / `roughnessNode`, `needsUpdate`), never the geometry;\n * removing every hook puts the material's own nodes back as they were. A part whose hooks do not change is\n * left alone. With no hook the materials are never touched (ADR 0008).\n */\nexport class LiveShaderHooks {\n private own: TreeShaderHooks = {};\n private stacks: Record<TreePart, TreeShaderHook[]> = { bark: [], leaves: [], fruit: [] };\n private readonly targets: ShaderHookTarget[] = [];\n private readonly originals = new Map<MeshStandardNodeMaterial, Original>();\n private readonly ref = new WeakRef(this);\n\n constructor(\n targets: readonly ShaderHookTarget[],\n private readonly shading: Shading,\n own: TreeShaderHooks = {},\n ) {\n followers.add(this.ref);\n this.own = cleaned(own);\n this.stacks = this.resolve();\n this.addTargets(targets);\n }\n\n /** The own hooks per part (a copy), as set. */\n get hooks(): TreeShaderHooks {\n return cleaned(this.own);\n }\n\n set hooks(value: TreeShaderHooks) {\n this.own = cleaned(value);\n this.refresh();\n }\n\n /** Adds materials made later (a Forest's Impostor cards), with the current hooks applied. */\n addTargets(targets: readonly ShaderHookTarget[]): void {\n for (const target of targets) {\n this.targets.push(target);\n if (target.parts.some((part) => this.stacks[part].length > 0)) this.apply(target);\n }\n }\n\n /** Re-resolves the hooks (after the own or the scene-wide default ones changed) and rebuilds what changed. */\n refresh(): void {\n const next = this.resolve();\n const changed = TREE_PARTS.filter((part) => next[part].length !== this.stacks[part].length || next[part].some((h, i) => h !== this.stacks[part][i]));\n this.stacks = next;\n for (const target of this.targets) if (target.parts.some((part) => changed.includes(part))) this.apply(target);\n }\n\n /** Stops following the scene-wide default hooks. */\n dispose(): void {\n followers.delete(this.ref);\n }\n\n private resolve(): Record<TreePart, TreeShaderHook[]> {\n return {\n bark: shaderHookOrder(sceneHooks, this.own, 'bark'),\n leaves: shaderHookOrder(sceneHooks, this.own, 'leaves'),\n fruit: shaderHookOrder(sceneHooks, this.own, 'fruit'),\n };\n }\n\n private apply(target: ShaderHookTarget): void {\n const { material } = target;\n let original = this.originals.get(material);\n if (!original) {\n original = {\n colorNode: material.colorNode,\n roughnessNode: material.roughnessNode,\n positionNode: material.positionNode,\n vertexColors: material.vertexColors,\n };\n this.originals.set(material, original);\n }\n material.colorNode = original.colorNode;\n material.roughnessNode = original.roughnessNode;\n material.positionNode = original.positionNode;\n material.vertexColors = original.vertexColors;\n material.needsUpdate = true;\n const parts = target.parts.filter((part) => this.stacks[part].length > 0);\n if (parts.length === 0) {\n this.originals.delete(material);\n return;\n }\n\n // The colour three would make: the colour node (or material colour) times the vertex colours, which\n // are now multiplied in here so the hooks see them.\n const base = vec4((original.colorNode as Node<'vec4'> | null) ?? (materialColor as unknown as Node<'vec4'>));\n const tinted = target.vertexColors ? base.mul(vertexColor()) : base;\n const roughness = float((original.roughnessNode as Node<'float'> | null) ?? materialRoughness);\n const lazy = <T>(make: () => T): (() => T) => {\n let value: T | undefined;\n return () => (value ??= make());\n };\n const normal = lazy(() => {\n const sway = target.sway === undefined ? windMotionOf(original.positionNode)?.offset : target.sway;\n return sway && !material.flatShading ? swayedNormal(normalWorld, sway) : normalWorld;\n });\n const treePosition = lazy(() => {\n if (target.treePosition) return target.treePosition;\n if (!target.treeBase) return modelWorldMatrix.mul(vec4(0, 0, 0, 1)).xyz;\n // Handed over from the vertex stage before `positionNode` moves the vertex (only now that it is read).\n const captured = varyingProperty('vec3', 'vTreeBase');\n const treeBase = target.treeBase;\n const position = original.positionNode as Node<'vec3'>;\n material.positionNode = Fn(() => {\n captured.assign(treeBase);\n return position;\n })();\n const motion = windMotionOf(position);\n if (motion) setWindMotion(material.positionNode, motion);\n return modelWorldMatrix.mul(vec4(captured, 1)).xyz;\n });\n\n let color: Node<'vec3'> = vec3(0);\n let rough: Node<'float'> = float(0);\n let roughnessChanged = false;\n for (const part of target.parts) {\n let partColor: Node<'vec3'> = tinted.rgb;\n let partRoughness: Node<'float'> = roughness;\n for (const hook of this.stacks[part]) {\n const input = { part, shading: this.shading, color: partColor, roughness: partRoughness, position: positionWorld, season: target.season, growth: target.growth };\n Object.defineProperties(input, {\n normal: { get: normal, enumerable: true },\n treePosition: { get: treePosition, enumerable: true },\n });\n const result = hook(input as TreeShaderInput);\n const output = isNode(result) ? { color: result } : result;\n partColor = output.color;\n if (output.roughness) {\n partRoughness = output.roughness;\n roughnessChanged = true;\n }\n }\n if (target.parts.length === 1) {\n color = partColor;\n rough = partRoughness;\n } else {\n const weight = target.partWeight!(part);\n color = color.add(partColor.mul(weight));\n rough = rough.add(partRoughness.mul(weight));\n }\n }\n material.colorNode = vec4(color, tinted.a);\n material.vertexColors = false;\n if (roughnessChanged) material.roughnessNode = rough;\n }\n}\n\n/** @internal What a Tree and a Forest share: a group of tree meshes with Tree Shader Hooks. */\nexport abstract class ShaderHookedGroup extends Group {\n protected abstract readonly hooks: LiveShaderHooks;\n\n /**\n * The Tree Shader Hook per tree part (GLOSSARY, ADR 0012), e.g. `{ leaves: ({ color }) => color.mul(0.8) }`:\n * a TSL function (or a list of them, which stack) that gets the part's base colour, world normal, world\n * positions, Season and Growth and returns a new colour (optionally with a roughness). Assign a new\n * object to set, change or remove hooks: a part left out has only the scene-wide default hooks\n * (`setSceneShaderHooks`), its own run after those, and `null` runs none at all. Only the parts whose\n * hooks changed rebuild their node graph, once; the geometry is never rebuilt. Without a hook a part is\n * drawn exactly as before. On a Forest they reach every tree at every Detail Level, and the Impostors,\n * which apply them at draw time to their baked colour, normals and Season data (changing a hook never\n * rebakes).\n */\n get shaderHooks(): TreeShaderHooks {\n return this.hooks.hooks;\n }\n\n set shaderHooks(value: TreeShaderHooks) {\n this.hooks.hooks = value;\n }\n}\n"],"mappings":";;;;AA4EA,IAAM,4BAAY,IAAI,QAAwB;;;;;AAM9C,SAAgB,oBAA8C,MAAY;CACxE,UAAU,IAAI,IAAI;CAClB,OAAO;AACT;AAEA,IAAM,UAAU,UACd,QAAS,OAAO,UAAU,aAAa,CAAC,KAAK,IAAI,QAAS,CAAC;;;;;;;AAQ7D,SAAgB,gBAAgB,OAAwB,KAAsB,MAAkC;CAC9G,IAAI,IAAI,UAA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;EAClC,IAAI,mBAAmB;EACvB,KAAK,MAAM,QAAQ,OAAO,OAAO;GAC/B,IAAI,YAA0B,OAAO;GACrC,IAAI,gBAA+B;GACnC,KAAK,MAAM,QAAQ,KAAK,OAAO,OAAO;IACpC,MAAM,QAAQ;KAAE;KAAM,SAAS,KAAK;KAAS,OAAO;KAAW,WAAW;KAAe,UAAU;KAAe,QAAQ,OAAO;KAAQ,QAAQ,OAAO;IAAO;IAC/J,OAAO,iBAAiB,OAAO;KAC7B,QAAQ;MAAE,KAAK;MAAQ,YAAY;KAAK;KACxC,cAAc;MAAE,KAAK;MAAc,YAAY;KAAK;IACtD,CAAC;IACD,MAAM,SAAS,KAAK,KAAwB;IAC5C,MAAM,SAAS,OAAO,MAAM,IAAI,EAAE,OAAO,OAAO,IAAI;IACpD,YAAY,OAAO;IACnB,IAAI,OAAO,WAAW;KACpB,gBAAgB,OAAO;KACvB,mBAAmB;IACrB;GACF;GACA,IAAI,OAAO,MAAM,WAAW,GAAG;IAC7B,QAAQ;IACR,QAAQ;GACV,OAAO;IACL,MAAM,SAAS,OAAO,WAAY,IAAI;IACtC,QAAQ,MAAM,IAAI,UAAU,IAAI,MAAM,CAAC;IACvC,QAAQ,MAAM,IAAI,cAAc,IAAI,MAAM,CAAC;GAC7C;EACF;EACA,SAAS,YAAY,KAAK,OAAO,OAAO,CAAC;EACzC,SAAS,eAAe;EACxB,IAAI,kBAAkB,SAAS,gBAAgB;CACjD;AACF;;AAGA,IAAsB,oBAAtB,cAAgD,MAAM;;;;;;;;;;;;CAcpD,IAAI,cAA+B;EACjC,OAAO,KAAK,MAAM;CACpB;CAEA,IAAI,YAAY,OAAwB;EACtC,KAAK,MAAM,QAAQ;CACrB;AACF"}
@@ -1,6 +1,7 @@
1
- import { BufferGeometry, Group, Mesh, type Material, type MeshStandardNodeMaterial, type UniformNode } from 'three/webgpu';
1
+ import { BufferGeometry, Mesh, type Material, type MeshStandardNodeMaterial, type UniformNode } from 'three/webgpu';
2
2
  import type { MaterialFeatures, TranslucencyDefinition, TreeDefinition } from '../definition';
3
3
  import { type TreeData } from '../generator';
4
+ import { LiveShaderHooks, ShaderHookedGroup, type TreeShaderHooks } from '../materials/shader-hooks';
4
5
  import { type SeasonUniform } from '../season';
5
6
  import { type TextureOptions } from '../textures';
6
7
  import { Wind, WindResponse } from '../wind';
@@ -17,12 +18,14 @@ export interface TreeOptions {
17
18
  * the app-wide `setTextureOptions`. Only Definitions with textures (e.g. the realistic Style) use it.
18
19
  */
19
20
  textures?: TextureOptions;
21
+ /** The Tree Shader Hook per tree part (see {@link Tree.shaderHooks}). Default: none. */
22
+ shaderHooks?: TreeShaderHooks;
20
23
  }
21
24
  /**
22
25
  * A generated tree as a three.js object. Add it to a scene rendered by `WebGPURenderer`.
23
26
  * `growth`, `season` and the Wind only update uniforms: no regeneration, no recompile.
24
27
  */
25
- export declare class Tree extends Group {
28
+ export declare class Tree extends ShaderHookedGroup {
26
29
  readonly isTree = true;
27
30
  readonly definition: TreeDefinition;
28
31
  readonly seed: number;
@@ -42,6 +45,7 @@ export declare class Tree extends Group {
42
45
  readonly windResponse: WindResponse;
43
46
  private readonly windBinding;
44
47
  private readonly features;
48
+ protected readonly hooks: LiveShaderHooks;
45
49
  /**
46
50
  * Resolves once every texture of this tree has loaded (at once for a tree without textures);
47
51
  * rejects if one fails. Await it before a first render that must show the textures.
@@ -76,7 +80,8 @@ export declare class Tree extends Group {
76
80
  set occlusionStrength(value: number);
77
81
  /**
78
82
  * The Wind this tree sways with (shared with every other tree using it). Assigning another
79
- * Wind only rebinds uniforms: no regeneration, no recompile.
83
+ * Wind only rebinds uniforms: no regeneration, no recompile (except the one-time node-graph rebuild
84
+ * when the tree first follows a Wind that has had a Wind Burst, see `Wind.burst`).
80
85
  */
81
86
  get wind(): Wind;
82
87
  set wind(value: Wind);
@@ -1 +1 @@
1
- {"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../src/tree/Tree.ts"],"names":[],"mappings":"AAAA,OAAO,EA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AI,MAAM,CAEnB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAEvB;IAED,sGAAsG;IAC7F,OAAO,IAAI,IAAI;CAYzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tree/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE/F,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAEhD,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,mBAAmB,GAAG,cAAc,EAChD,OAAO,GAAE,iBAAsB,GAC9B,IAAI,CASN"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tree/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE/F,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAEhD,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,mBAAmB,GAAG,cAAc,EAChD,OAAO,GAAE,iBAAsB,GAC9B,IAAI,CAUN"}
@@ -0,0 +1,3 @@
1
+ export { sceneWetness, Wetness, wetnessHooks, type WetnessHooks, type WetnessLook, type WetnessOptions, type WetnessSettings, } from './wetness';
2
+ export { sceneSnow, Snow, snowCoverHooks, snowCoverShading, type SnowCoverHooks, type SnowCoverLook, type SnowCoverSettings, type SnowCoverShadingSettings, type SnowOptions, } from './snow';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/weather/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,SAAS,EACT,IAAI,EACJ,cAAc,EACd,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,WAAW,GACjB,MAAM,QAAQ,CAAC"}