roamwright 0.61.27 → 0.61.28

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.
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Animated dust and falling-water curtain sheets:
3
+ * 1) Concentric rising billowing dust curtains (`dustCurtainGeometry`, `createDustCurtainMaterial`,
4
+ * `createDustCurtain`) shaded with 3D value-noise fBm, silhouette grazing fade, and directional
5
+ * near-side thinning.
6
+ * 2) Glossy streaked falling-water curtains (`createFallingWaterMaterial`, `createFallingWaterSheets`)
7
+ * for fountains, spillways and cascades.
8
+ * @module
9
+ */
10
+
11
+ import * as THREE from 'three';
12
+ import { DUST_CURTAIN_SHAPE, dustCurtainArrays } from '../geometry/curtain-sheets.js';
13
+
14
+ /** Small 3D hash-based value noise and 3-octave fBm GLSL snippet for local-space volumetric sheets. */
15
+ export const VALUE_NOISE_3D_GLSL = /* glsl */ `
16
+ float fh(vec3 p){ p = fract(p * 0.3183099 + 0.1); p *= 17.0; return fract(p.x * p.y * p.z * (p.x + p.y + p.z)); }
17
+ float fn3(vec3 x){
18
+ vec3 i = floor(x), f = fract(x); f = f * f * (3.0 - 2.0 * f);
19
+ return mix(mix(mix(fh(i), fh(i + vec3(1, 0, 0)), f.x), mix(fh(i + vec3(0, 1, 0)), fh(i + vec3(1, 1, 0)), f.x), f.y),
20
+ mix(mix(fh(i + vec3(0, 0, 1)), fh(i + vec3(1, 0, 1)), f.x), mix(fh(i + vec3(0, 1, 1)), fh(i + vec3(1, 1, 1)), f.x), f.y), f.z);
21
+ }
22
+ float ffbm(vec3 p){ return 0.5 * fn3(p) + 0.3 * fn3(p * 2.03 + 7.1) + 0.2 * fn3(p * 4.1 + 3.7); }
23
+ `;
24
+
25
+ /** Default parameters for {@link createDustCurtainMaterial} and {@link createDustCurtain}. */
26
+ export const DUST_CURTAIN_DEFAULTS = Object.freeze({
27
+ ...DUST_CURTAIN_SHAPE,
28
+ beforeOpacity: 0.3,
29
+ renderOrder: 8,
30
+ });
31
+
32
+ /** Default parameters for {@link createFallingWaterMaterial}. */
33
+ export const FALLING_WATER_DEFAULTS = Object.freeze({
34
+ color: 0xe4f0f2,
35
+ roughness: 0.1,
36
+ metalness: 0,
37
+ opacity: 0.42,
38
+ cacheKey: 'falling-water',
39
+ renderOrder: 6,
40
+ });
41
+
42
+ /**
43
+ * Build a Three.js `BufferGeometry` for concentric rising dust curtains using {@link dustCurtainArrays}.
44
+ *
45
+ * @param {Parameters<typeof dustCurtainArrays>[0]} [options]
46
+ * @returns {THREE.BufferGeometry}
47
+ */
48
+ export function dustCurtainGeometry(options = {}) {
49
+ const { position, uv, index } = dustCurtainArrays(options);
50
+ const geo = new THREE.BufferGeometry();
51
+ geo.setAttribute('position', new THREE.BufferAttribute(position, 3));
52
+ geo.setAttribute('uv', new THREE.BufferAttribute(uv, 2));
53
+ geo.setIndex(new THREE.BufferAttribute(index, 1));
54
+ return geo;
55
+ }
56
+
57
+ /**
58
+ * Create the animated billowing dust curtain `THREE.ShaderMaterial`. Callers may supply shared
59
+ * `{ value }` uniform handles (`show`, `time`, `light`, `ahead`) to drive multiple storm elements
60
+ * in lockstep with zero per-frame allocations.
61
+ *
62
+ * @param {object} [options]
63
+ * @param {{ value: number }} [options.show] - Curtain rise/opacity uniform (`0..1`).
64
+ * @param {{ value: number }} [options.time] - Elapsed time uniform in seconds.
65
+ * @param {{ value: THREE.Color }} [options.light] - Ambient tint colour uniform.
66
+ * @param {{ value: THREE.Vector2 }} [options.ahead] - Horizontal unit vector toward the viewer/reference point.
67
+ * @param {number} [options.beforeOpacity=DUST_CURTAIN_DEFAULTS.beforeOpacity] - Opacity multiplier on the near side facing `ahead`.
68
+ * @returns {THREE.ShaderMaterial}
69
+ */
70
+ export function createDustCurtainMaterial({
71
+ show = { value: 1 },
72
+ time = { value: 0 },
73
+ light = { value: new THREE.Color(1, 0.84, 0.66) },
74
+ ahead = { value: new THREE.Vector2(1, 0) },
75
+ beforeOpacity = DUST_CURTAIN_DEFAULTS.beforeOpacity,
76
+ } = {}) {
77
+ return new THREE.ShaderMaterial({
78
+ side: THREE.DoubleSide,
79
+ transparent: true,
80
+ depthWrite: false,
81
+ fog: true,
82
+ uniforms: {
83
+ ...THREE.UniformsUtils.clone(THREE.UniformsLib.fog),
84
+ uShow: show,
85
+ uTime: time,
86
+ uLight: light,
87
+ uAhead: ahead,
88
+ uBefore: { value: beforeOpacity },
89
+ },
90
+ vertexShader: /* glsl */ `
91
+ #include <common>
92
+ #include <fog_pars_vertex>
93
+ uniform vec2 uAhead;
94
+ varying vec2 vSt; varying float vFace, vNear;
95
+ void main(){
96
+ vSt = uv;
97
+ vec3 out_ = normalize(vec3(position.x, 0.0, position.z));
98
+ vNear = dot(out_.xz, uAhead); // +1 on the side toward the spring
99
+ vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
100
+ vFace = abs(dot(normalize(normalMatrix * out_), normalize(-mvPosition.xyz)));
101
+ gl_Position = projectionMatrix * mvPosition;
102
+ #include <fog_vertex>
103
+ }`,
104
+ fragmentShader: /* glsl */ `
105
+ #include <common>
106
+ #include <fog_pars_fragment>
107
+ uniform float uShow, uTime, uBefore; uniform vec3 uLight;
108
+ varying vec2 vSt; varying float vFace, vNear;
109
+ ${VALUE_NOISE_3D_GLSL}
110
+ void main(){
111
+ vec3 p = vec3(vSt.x - uTime * 0.25, vSt.y * 3.2 - uTime * 0.45, uTime * 0.05);
112
+ float n = ffbm(p), fine = fn3(p * 3.7 + n * 2.0), h = vSt.y / (0.35 + 0.65 * uShow); // the storm stands up as it rises
113
+ float crest = 1.0 - smoothstep(0.45 + 0.35 * n, 0.95 + 0.1 * fine, h); // torn into plumes at the top
114
+ float body = smoothstep(0.42, 0.78, n * 0.75 + fine * 0.25 + (1.0 - h) * 0.3); // billows, thicker low
115
+ float a = body * crest * uShow * 0.42 * smoothstep(0.08, 0.5, vFace) * mix(1.0, uBefore, smoothstep(-0.2, 0.5, vNear));
116
+ float lit = smoothstep(0.3, 0.85, n + h * 0.25 - fine * 0.15); // the billows' tops catch the light
117
+ vec3 col = mix(vec3(0.3, 0.19, 0.1), vec3(0.95, 0.72, 0.46), lit) * (0.85 + 0.3 * fine) * uLight;
118
+ gl_FragColor = vec4(col, a);
119
+ #include <tonemapping_fragment>
120
+ #include <colorspace_fragment>
121
+ #include <fog_fragment>
122
+ }`,
123
+ });
124
+ }
125
+
126
+ /**
127
+ * Convenience builder creating a positioned dust-curtain mesh, geometry, material and zero-allocation
128
+ * `update(time, show, day)` helper.
129
+ *
130
+ * @param {object} [options]
131
+ * @param {THREE.Object3D | null} [options.parent=null] - Optional parent group.
132
+ * @param {number} [options.x=0] - World X position in metres.
133
+ * @param {number} [options.y=0] - Base elevation in metres.
134
+ * @param {number} [options.z=0] - World Z position in metres.
135
+ * @param {number} [options.renderOrder=DUST_CURTAIN_DEFAULTS.renderOrder] - Mesh `renderOrder`.
136
+ * @returns {{ mesh: THREE.Mesh, geometry: THREE.BufferGeometry, material: THREE.ShaderMaterial, update: (time: number, show?: number, day?: number) => void, dispose: () => void }}
137
+ */
138
+ export function createDustCurtain(options = {}) {
139
+ const { parent = null, x = 0, y = 0, z = 0, renderOrder = DUST_CURTAIN_DEFAULTS.renderOrder } = options;
140
+ const geometry = dustCurtainGeometry(options);
141
+ const material = createDustCurtainMaterial(options);
142
+ const mesh = new THREE.Mesh(geometry, material);
143
+ mesh.position.set(x, y, z);
144
+ mesh.renderOrder = renderOrder;
145
+ if (parent) parent.add(mesh);
146
+ const u = material.uniforms;
147
+ return {
148
+ mesh,
149
+ geometry,
150
+ material,
151
+ update(time, show = 1, day = 1) {
152
+ u.uTime.value = time;
153
+ u.uShow.value = show;
154
+ u.uLight.value.setRGB(1, 0.84, 0.66).multiplyScalar(0.35 + 0.65 * day);
155
+ mesh.visible = show > 0.002;
156
+ },
157
+ dispose() {
158
+ mesh.removeFromParent();
159
+ geometry.dispose();
160
+ material.dispose();
161
+ },
162
+ };
163
+ }
164
+
165
+ /**
166
+ * Create a glossy, transparent falling-water `MeshStandardMaterial` whose alpha breaks into downward
167
+ * streaming strands driven by `time.value` (seconds).
168
+ *
169
+ * @param {object} [options]
170
+ * @param {{ value: number }} [options.time] - Elapsed time uniform handle in seconds.
171
+ * @param {number} [options.color=FALLING_WATER_DEFAULTS.color] - Base water sRGB hex colour.
172
+ * @param {number} [options.roughness=FALLING_WATER_DEFAULTS.roughness] - Surface roughness.
173
+ * @param {number} [options.metalness=FALLING_WATER_DEFAULTS.metalness] - Metallic factor.
174
+ * @param {number} [options.opacity=FALLING_WATER_DEFAULTS.opacity] - Base sheet opacity.
175
+ * @param {string} [options.cacheKey=FALLING_WATER_DEFAULTS.cacheKey] - `customProgramCacheKey` value.
176
+ * @returns {THREE.MeshStandardMaterial}
177
+ */
178
+ export function createFallingWaterMaterial({
179
+ time = { value: 0 },
180
+ color = FALLING_WATER_DEFAULTS.color,
181
+ roughness = FALLING_WATER_DEFAULTS.roughness,
182
+ metalness = FALLING_WATER_DEFAULTS.metalness,
183
+ opacity = FALLING_WATER_DEFAULTS.opacity,
184
+ cacheKey = FALLING_WATER_DEFAULTS.cacheKey,
185
+ } = {}) {
186
+ const mat = new THREE.MeshStandardMaterial({
187
+ color,
188
+ roughness,
189
+ metalness,
190
+ transparent: true,
191
+ opacity,
192
+ depthWrite: false,
193
+ side: THREE.DoubleSide,
194
+ });
195
+ mat.onBeforeCompile = sh => {
196
+ sh.uniforms.uFall = time;
197
+ sh.vertexShader = sh.vertexShader
198
+ .replace('#include <common>', '#include <common>\nvarying vec2 vFall;')
199
+ .replace('#include <begin_vertex>', '#include <begin_vertex>\nvFall = uv;');
200
+ sh.fragmentShader = sh.fragmentShader
201
+ .replace('#include <common>', '#include <common>\nvarying vec2 vFall;\nuniform float uFall;')
202
+ .replace(
203
+ '#include <alphatest_fragment>',
204
+ `/* glsl */
205
+ float strand = smoothstep(0.2, 0.95, 0.5 + 0.5 * sin(vFall.x * 211.0 + sin(vFall.x * 37.0) * 3.0));
206
+ float run = fract(vFall.y * 2.6 + uFall * 1.7 + sin(vFall.x * 91.0) * 0.4);
207
+ diffuseColor.a *= (0.2 + 0.8 * strand) * (0.4 + 0.6 * smoothstep(0.0, 0.6, run));
208
+ #include <alphatest_fragment>`,
209
+ );
210
+ };
211
+ mat.customProgramCacheKey = () => cacheKey;
212
+ return mat;
213
+ }
214
+
215
+ /**
216
+ * Assemble animated falling-water fountain curtains and foam splash rings sharing one
217
+ * {@link createFallingWaterMaterial} under `parent`.
218
+ *
219
+ * @param {THREE.Object3D | null} parent - Destination group (or `null`).
220
+ * @param {object} options
221
+ * @param {{ x: number, y?: number, z: number }} [options.origin={ x: 0, y: 0, z: 0 }] - World placement offset in metres.
222
+ * @param {Array<{ topRadius: number, bottomRadius: number, height: number, y: number, segments?: number }>} [options.cylinders=[]] - Open-ended conical fall curtains.
223
+ * @param {Array<{ innerRadius: number, outerRadius: number, y: number, segments?: number }>} [options.rings=[]] - Horizontal landing-foam rings.
224
+ * @param {number} [options.renderOrder=FALLING_WATER_DEFAULTS.renderOrder] - Mesh `renderOrder`.
225
+ * @param {string} [options.cacheKey=FALLING_WATER_DEFAULTS.cacheKey] - Shader program cache key.
226
+ * @returns {{ meshes: THREE.Mesh[], material: THREE.MeshStandardMaterial, setTime: (t: number) => void, dispose: () => void }}
227
+ */
228
+ export function createFallingWaterSheets(
229
+ parent,
230
+ {
231
+ origin = { x: 0, y: 0, z: 0 },
232
+ cylinders = [],
233
+ rings = [],
234
+ renderOrder = FALLING_WATER_DEFAULTS.renderOrder,
235
+ cacheKey = FALLING_WATER_DEFAULTS.cacheKey,
236
+ color,
237
+ roughness,
238
+ metalness,
239
+ opacity,
240
+ } = {},
241
+ ) {
242
+ const time = { value: 0 };
243
+ const material = createFallingWaterMaterial({ time, color, roughness, metalness, opacity, cacheKey });
244
+ const geometries = [
245
+ ...cylinders.map(({ topRadius, bottomRadius, height, y, segments = 32 }) =>
246
+ new THREE.CylinderGeometry(topRadius, bottomRadius, height, segments, 1, true).translate(0, y, 0),
247
+ ),
248
+ ...rings.map(({ innerRadius, outerRadius, y, segments = 32 }) =>
249
+ new THREE.RingGeometry(innerRadius, outerRadius, segments).rotateX(-Math.PI / 2).translate(0, y, 0),
250
+ ),
251
+ ];
252
+ const meshes = geometries.map(geo => {
253
+ const m = new THREE.Mesh(geo, material);
254
+ m.position.set(origin.x, origin.y ?? 0, origin.z);
255
+ m.renderOrder = renderOrder;
256
+ if (parent) parent.add(m);
257
+ return m;
258
+ });
259
+ return {
260
+ meshes,
261
+ material,
262
+ setTime: t => {
263
+ time.value = t;
264
+ },
265
+ dispose() {
266
+ for (const m of meshes) m.removeFromParent();
267
+ for (const geo of geometries) geo.dispose();
268
+ material.dispose();
269
+ },
270
+ };
271
+ }
@@ -84,3 +84,108 @@ export function createFlameSources({ kinds = FLAME_KINDS, poolSpread = 1.3, ligh
84
84
 
85
85
  return { sourceOf, flicker, hourShare };
86
86
  }
87
+
88
+ /**
89
+ * Create a fire effect-site record consumed by `createFlameSources` and particle emitters.
90
+ * Only optional keys that are explicitly provided are attached to the returned object.
91
+ *
92
+ * @param {object} options
93
+ * @param {string} [options.space='world'] - Host space id.
94
+ * @param {number} options.x - World X in metres.
95
+ * @param {number} options.y - World Y in metres.
96
+ * @param {number} options.z - World Z in metres.
97
+ * @param {string} [options.kind] - Optional flame kind override (e.g. `'brazier'`).
98
+ * @param {number} [options.rate=6] - Particle emission rate per second.
99
+ * @param {number} [options.size=0.45] - Flame size in metres.
100
+ * @param {number} [options.hot=1] - Heat buoyancy factor.
101
+ * @param {number} [options.soot=0.15] - Soot share.
102
+ * @param {number} [options.lift] - Optional light elevation override in metres.
103
+ * @param {number} [options.light] - Optional light strength override in `lightUnit`s.
104
+ * @returns {object} Fire site record.
105
+ */
106
+ export function createFireSite({ space = 'world', x, y, z, kind, rate = 6, size = 0.45, hot = 1, soot = 0.15, lift, light }) {
107
+ const site = { space, type: 'fire', x, y, z, rate, size, hot, soot };
108
+ if (kind !== undefined) site.kind = kind;
109
+ if (lift !== undefined) site.lift = lift;
110
+ if (light !== undefined) site.light = light;
111
+ return site;
112
+ }
113
+
114
+ /**
115
+ * Create a rising smoke effect-site record paired with a fire or chimney.
116
+ *
117
+ * @param {object} options
118
+ * @param {string} [options.space='world'] - Host space id.
119
+ * @param {number} options.x - World X in metres.
120
+ * @param {number} options.y - World Y in metres.
121
+ * @param {number} options.z - World Z in metres.
122
+ * @param {number} [options.rate=0.8] - Puff emission rate per second.
123
+ * @param {number} [options.size=2] - Puff size in metres.
124
+ * @param {number} [options.heat=0.4] - Rise speed factor.
125
+ * @param {number} [options.dark=0.4] - Smoke darkness factor.
126
+ * @param {number} [options.thin] - Optional opacity multiplier.
127
+ * @returns {object} Smoke site record.
128
+ */
129
+ export function createSmokeSite({ space = 'world', x, y, z, rate = 0.8, size = 2, heat = 0.4, dark = 0.4, thin }) {
130
+ const site = { space, type: 'smoke', x, y, z, rate, size, heat, dark };
131
+ if (thin !== undefined) site.thin = thin;
132
+ return site;
133
+ }
134
+
135
+ /**
136
+ * Append a fire effect site (and an optional paired smoke plume site) to `sites`.
137
+ *
138
+ * @param {object[]} sites - Mutable effect-sites array.
139
+ * @param {object} options
140
+ * @param {string} [options.space='world'] - Host space id.
141
+ * @param {number} options.x - World X in metres.
142
+ * @param {number} options.y - Base ground/hearth elevation in metres.
143
+ * @param {number} options.z - World Z in metres.
144
+ * @param {number} [options.fireY=0.15] - Vertical offset of the fire site above `y` in metres.
145
+ * @param {number} [options.size=0.5] - Flame size in metres.
146
+ * @param {number} [options.rate] - Fire emission rate (defaults to `4 + size * 10`).
147
+ * @param {string} [options.kind] - Optional flame kind override.
148
+ * @param {number} [options.hot=1] - Fire buoyancy factor.
149
+ * @param {number} [options.soot=0.15] - Fire soot share.
150
+ * @param {number} [options.lift] - Optional light height override.
151
+ * @param {number} [options.light] - Optional light strength override.
152
+ * @param {number | false | { y?: number, rate?: number, size?: number, heat?: number, dark?: number }} [options.smoke=1]
153
+ * - Smoke scale (`> 0`), explicit smoke config object, or `false` / `0` for no smoke site.
154
+ * @returns {{ fire: object, smoke: object | null }}
155
+ */
156
+ export function addFireSites(
157
+ sites,
158
+ { space = 'world', x, y, z, fireY = 0.15, size = 0.5, rate = 4 + size * 10, kind, hot = 1, soot = 0.15, lift, light, smoke = 1 },
159
+ ) {
160
+ const fire = createFireSite({ space, x, y: y + fireY, z, kind, rate, size, hot, soot, lift, light });
161
+ sites.push(fire);
162
+ let smokeSite = null;
163
+ if (smoke !== false && smoke !== null && smoke !== 0) {
164
+ if (typeof smoke === 'number') {
165
+ smokeSite = createSmokeSite({
166
+ space,
167
+ x,
168
+ y: y + 1.2,
169
+ z,
170
+ rate: 0.8 * smoke,
171
+ size: 1.6 + size * 2 * smoke,
172
+ heat: 0.4,
173
+ dark: 0.4,
174
+ });
175
+ } else {
176
+ smokeSite = createSmokeSite({
177
+ space,
178
+ x,
179
+ y: y + (smoke.y ?? 1.2),
180
+ z,
181
+ rate: smoke.rate ?? 0.8,
182
+ size: smoke.size ?? 1.6 + size * 2,
183
+ heat: smoke.heat ?? 0.4,
184
+ dark: smoke.dark ?? 0.4,
185
+ thin: smoke.thin,
186
+ });
187
+ }
188
+ sites.push(smokeSite);
189
+ }
190
+ return { fire, smoke: smokeSite };
191
+ }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Procedural weathered glacial ice material (`MeshStandardMaterial` patched via `onBeforeCompile`):
3
+ * refracted internal crack layers, milky cloud, surface rime, dirt/stain vertex-colour channels,
4
+ * derivative micro-relief cups, internal blue-cyan glow, optional height-based mist fade, and a
5
+ * transparent clear-ice variant.
6
+ * @module
7
+ */
8
+
9
+ import * as THREE from 'three';
10
+ import { createNoise } from '../math/noise.js';
11
+ import { createHash } from '../math/random.js';
12
+ import { createSurfaceTextures, fillPixels } from '../math/surface-textures.js';
13
+
14
+ /** Raw GLSL shader snippets injected by {@link createIceMaterial}. */
15
+ export const ICE_SHADER_PARTS = Object.freeze({
16
+ varying: 'varying vec3 vIceAt; varying vec3 vIceFace;',
17
+ pattern: `/* glsl */
18
+ uniform sampler2D uIceSheet; uniform float uIceGlow; uniform float uIceThin; uniform vec3 uIceMist;
19
+ // the sheet of cracks, cloud and grain (engine/texture-fills.js, 'ice') laid on a plane that no face of a cliff lies along
20
+ vec2 icePlane(vec3 p) { return vec2(p.x + 0.4 * p.z, p.y * 0.8 + 0.25 * p.z); }
21
+ vec3 iceSkin = vec3(0.0); float iceWhite = 0.0, iceHeld = 0.0, iceRelief = 0.0, iceCloud = 0.0;`,
22
+ surface: `/* glsl */
23
+ {
24
+ vec3 toEye = normalize(cameraPosition - vIceAt), face = normalize(vIceFace);
25
+ float square = clamp(dot(toEye, face), 0.0, 1.0), graze = pow(1.0 - square, 3.0);
26
+ float far = length(vViewPosition), fine = 1.0 - smoothstep(14.0, 70.0, far);
27
+ vec3 into = refract(-toEye, face, 0.763);
28
+ float thin = 0.012 + 0.0022 * far;
29
+ float cracks = 0.0, cloud = 0.0;
30
+ for (int k = 0; k < 3; k++) {
31
+ float deep = float(k);
32
+ vec4 sheet = texture2D(uIceSheet, icePlane(vIceAt + into * (0.15 + 0.65 * deep)) * (0.04 + 0.012 * deep) + 0.37 * deep);
33
+ cracks += smoothstep(1.0 - thin, 1.0 - 0.35 * thin, sheet.r) * (0.1 + 0.9 * smoothstep(0.45, 0.62, sheet.a)) * (1.0 - 0.3 * deep);
34
+ cloud += sheet.g * (0.5 - 0.12 * deep);
35
+ }
36
+ cracks = min(1.0, cracks);
37
+ vec4 frost = texture2D(uIceSheet, icePlane(vIceAt) * 0.29 + 0.5);
38
+ vec4 run = texture2D(uIceSheet, vec2(vIceAt.x + 0.4 * vIceAt.z, vIceAt.y * 0.08) * 0.13);
39
+ float grain = frost.b, cups = frost.g;
40
+ float rime = smoothstep(0.42, 0.78, face.y * 0.9 + grain * 0.55);
41
+ float skin = clamp(vColor.r * (0.55 + 0.9 * grain) + rime * 0.8, 0.0, 1.0);
42
+ float dirt = vColor.g * smoothstep(0.25, 0.7, run.a + 0.3 * grain);
43
+ float stain = vColor.b * smoothstep(0.3, 0.75, run.g + 0.25 * grain);
44
+ vec3 depths = mix(vec3(0.012, 0.075, 0.15), vec3(0.08, 0.34, 0.5), clamp(cloud * 1.5 - 0.3 + 0.3 * square, 0.0, 1.0));
45
+ vec3 ice = mix(depths, vec3(0.5, 0.74, 0.86), cracks * 0.75);
46
+ ice = mix(ice, vec3(0.74, 0.82, 0.86), max(skin, graze * 0.55));
47
+ ice = mix(ice, vec3(0.2, 0.165, 0.13), dirt * 0.8);
48
+ ice = mix(ice, vec3(0.17, 0.035, 0.03), stain * 0.85);
49
+ diffuseColor.rgb = ice;
50
+ iceWhite = max(skin, max(dirt, stain));
51
+ iceHeld = (1.0 - 0.8 * iceWhite) * (0.35 + 0.65 * square);
52
+ iceSkin = mix(vec3(0.1, 0.4, 0.62), vec3(0.42, 0.72, 0.86), min(1.0, cloud + cracks * 0.6));
53
+ iceRelief = (cups * 0.05 + grain * 0.02 * fine) * (0.4 + 0.6 * skin);
54
+ iceCloud = cloud;
55
+ #ifndef OPAQUE
56
+ diffuseColor.a = clamp(uIceThin + 0.9 * max(iceWhite, cracks * 0.8) + min(1.0, uIceThin * 3.3) * (0.45 * graze + 0.22 * cloud), 0.0, 1.0);
57
+ #endif
58
+ }`,
59
+ relief: `/* glsl */
60
+ {
61
+ vec3 sx = dFdx(-vViewPosition), sy = dFdy(-vViewPosition);
62
+ float hx = dFdx(iceRelief), hy = dFdy(iceRelief);
63
+ vec3 r1 = cross(sy, normal), r2 = cross(normal, sx);
64
+ float det = dot(sx, r1);
65
+ normal = normalize(abs(det) * normal - sign(det) * (hx * r1 + hy * r2));
66
+ }`,
67
+ mist: `/* glsl */
68
+ #ifdef USE_FOG
69
+ gl_FragColor.rgb = mix(gl_FragColor.rgb, fogColor * 1.25 + vec3(0.03, 0.04, 0.055), uIceMist.z * smoothstep(uIceMist.x, uIceMist.y, vIceAt.y + 6.0 * iceCloud));
70
+ #endif`,
71
+ });
72
+
73
+ let fallbackIceTexture = null;
74
+
75
+ /**
76
+ * Create a default 256×256 tileable cracked-ice `THREE.DataTexture` backed by Roamwright's
77
+ * procedural `createSurfaceTextures().crackedIce` generator.
78
+ *
79
+ * @param {object} [options]
80
+ * @param {number} [options.size=256] - Texture width and height in pixels.
81
+ * @param {number} [options.seed=0] - Seed for default noise and hash.
82
+ * @returns {THREE.DataTexture}
83
+ */
84
+ export function createIceSheetTexture({ size = 256, seed = 0 } = {}) {
85
+ const { tfbm, tnoise } = createNoise(seed);
86
+ const hash2 = createHash(seed);
87
+ const surfaces = createSurfaceTextures({ noise: { tfbm, tnoise }, hash2 });
88
+ const data = fillPixels({ size, make: surfaces.crackedIce });
89
+ const tex = new THREE.DataTexture(data, size, size);
90
+ tex.wrapS = tex.wrapT = THREE.RepeatWrapping;
91
+ tex.colorSpace = THREE.NoColorSpace;
92
+ tex.magFilter = THREE.LinearFilter;
93
+ tex.minFilter = THREE.LinearMipmapLinearFilter;
94
+ tex.generateMipmaps = true;
95
+ tex.needsUpdate = true;
96
+ return tex;
97
+ }
98
+
99
+ /**
100
+ * Create a weathered glacial ice `MeshStandardMaterial`. Vertex colours encode `[whiteSkin, dirt, stain]`
101
+ * in RGB. Pass `sheet` (either a `THREE.Texture` or a `{ texture }` handle from `createTextureFills`)
102
+ * to share a worker-filled ice sheet; when omitted, a procedural default texture is created once.
103
+ *
104
+ * @param {object} [options]
105
+ * @param {THREE.Texture | { texture: THREE.Texture }} [options.sheet] - Repeating RGBA crack/cloud/grain data texture.
106
+ * @param {number} [options.glow=0.3] - Internal blue-cyan glow multiplier (`0` for none).
107
+ * @param {boolean} [options.clear=false] - Transparent clear-ice variant (`depthWrite = false`).
108
+ * @param {number} [options.thin=0.3] - Minimum alpha of the clear variant where cracks and frost are absent.
109
+ * @param {[number, number, number]} [options.mist=[0, 1, 0]] - Height-mist fade `[fromY, toY, strength]` in metres.
110
+ * @param {string} [options.cacheKey='ice'] - `customProgramCacheKey` value.
111
+ * @returns {THREE.MeshStandardMaterial}
112
+ */
113
+ export function createIceMaterial({ sheet, glow = 0.3, clear = false, thin = 0.3, mist = [0, 1, 0], cacheKey = 'ice' } = {}) {
114
+ const texture = sheet ? (sheet.texture ?? sheet) : (fallbackIceTexture ??= createIceSheetTexture());
115
+ const material = new THREE.MeshStandardMaterial({
116
+ vertexColors: true,
117
+ roughness: 0.5,
118
+ metalness: 0,
119
+ transparent: clear,
120
+ depthWrite: !clear,
121
+ });
122
+ material.customProgramCacheKey = () => cacheKey;
123
+ material.onBeforeCompile = sh => {
124
+ sh.uniforms.uIceSheet = { value: texture };
125
+ sh.uniforms.uIceGlow = { value: glow };
126
+ sh.uniforms.uIceThin = { value: thin };
127
+ sh.uniforms.uIceMist = { value: new THREE.Vector3(...mist) };
128
+ sh.vertexShader = sh.vertexShader
129
+ .replace('#include <common>', '#include <common>\n' + ICE_SHADER_PARTS.varying)
130
+ .replace(
131
+ '#include <begin_vertex>',
132
+ '#include <begin_vertex>\nvIceAt = (modelMatrix * vec4(position, 1.0)).xyz; vIceFace = normalize(mat3(modelMatrix) * normal);',
133
+ );
134
+ sh.fragmentShader = sh.fragmentShader
135
+ .replace('#include <common>', '#include <common>\n' + ICE_SHADER_PARTS.varying + ICE_SHADER_PARTS.pattern)
136
+ .replace('#include <color_fragment>', ICE_SHADER_PARTS.surface)
137
+ .replace('#include <roughnessmap_fragment>', '#include <roughnessmap_fragment>\nroughnessFactor = mix(0.1, 0.82, iceWhite);')
138
+ .replace('#include <normal_fragment_maps>', '#include <normal_fragment_maps>\n' + ICE_SHADER_PARTS.relief)
139
+ .replace('#include <emissivemap_fragment>', '#include <emissivemap_fragment>\ntotalEmissiveRadiance += uIceGlow * iceHeld * iceSkin;')
140
+ .replace('#include <fog_fragment>', '#include <fog_fragment>\n' + ICE_SHADER_PARTS.mist);
141
+ };
142
+ return material;
143
+ }
@@ -24,10 +24,21 @@ export { createStainMaterial } from './stain-material.js';
24
24
 
25
25
  // ── Terrain & land baking ────────────────────────────────────────────────
26
26
  export { createSimpleWater } from './water-simple.js';
27
+ export { createCrystalMaterial } from './rock-materials.js';
28
+ export { ICE_SHADER_PARTS, createIceMaterial, createIceSheetTexture } from './ice-material.js';
27
29
  export { createStrataCliffs } from './strata-cliffs.js';
28
30
  export { meshTalusStones } from './strata-talus.js';
29
31
  export { MOUND_RUINS_LOD, raiseMoundRuins, registerMoundRuins } from './ruins-mound.js';
30
- export { LIGHT_POOL, addLampStand, addLightPool, addStillPool, addWallLantern, createLightPoolTexture } from './ruins-fittings.js';
32
+ export {
33
+ FLAME_DEFAULTS,
34
+ LIGHT_POOL,
35
+ addFlame,
36
+ addLampStand,
37
+ addLightPool,
38
+ addStillPool,
39
+ addWallLantern,
40
+ createLightPoolTexture,
41
+ } from './ruins-fittings.js';
31
42
  export { GROUND_DRAPE_FRAGMENT, createGroundDrape, createGroundDrapeMaterial } from './ground-drape.js';
32
43
  export { meshStreamBanks } from './stream-banks.js';
33
44
  export { meshSprings } from './stream-springs.js';
@@ -119,10 +130,22 @@ export { createTroopDirector } from './troop-director.js';
119
130
 
120
131
  // ── Effects, audio, pacing & runtime ─────────────────────────────────────
121
132
  export { DEFAULT_PARTICLE_LOOK, createParticleNoiseTexture, createParticleSystem } from './particles.js';
133
+ export { FLAME_KINDS, addFireSites, createFireSite, createFlameSources, createSmokeSite } from './flame-sources.js';
122
134
  export { createFireLightWatch } from './fire-light-watch.js';
123
135
  export { createEffectsFrame, syncEffectsUniforms } from './effects-frame.js';
124
136
  export { createRippleRingMaterial, createWaterRises, fishGeometry } from './effects-water-rises.js';
125
137
  export { STORM_WALL_COLORS, createStormWall, stormWallGeometry, stormWallNoise } from './storm-wall.js';
138
+ export {
139
+ DUST_CURTAIN_DEFAULTS,
140
+ FALLING_WATER_DEFAULTS,
141
+ VALUE_NOISE_3D_GLSL,
142
+ createDustCurtain,
143
+ createDustCurtainMaterial,
144
+ createFallingWaterMaterial,
145
+ createFallingWaterSheets,
146
+ dustCurtainGeometry,
147
+ } from './curtain-sheets.js';
148
+ export { FALLEN_BEAST_DEFAULTS, placeFallenBeasts } from './camp-layout.js';
126
149
  export { createPracticalFlame, createSceneLights } from './scene-lights.js';
127
150
  export { createPerfBox } from './perf-box.js';
128
151
  export { PERF_BOX_DEFAULTS, attachPerfBoxWorker, createPerfBoxRenderer } from './perf-box-worker.js';
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Specialized rock and mineral materials for subterranean and geological sets.
3
+ * @module
4
+ */
5
+
6
+ import * as THREE from 'three';
7
+
8
+ /**
9
+ * Create a glossy, flat-shaded, softly self-lit `MeshStandardMaterial` for faceted cavern crystals.
10
+ *
11
+ * @param {object} [options]
12
+ * @param {number} [options.roughness=0.12] - Surface roughness.
13
+ * @param {number} [options.metalness=0] - Metallic factor.
14
+ * @param {number} [options.emissive=0x2a2838] - Faint inner mineral glow sRGB hex colour.
15
+ * @param {boolean} [options.flatShading=true] - Keep crystal facets crisp.
16
+ * @param {boolean} [options.vertexColors=true] - Read per-prism tints from vertex colours.
17
+ * @returns {THREE.MeshStandardMaterial}
18
+ */
19
+ export function createCrystalMaterial({
20
+ roughness = 0.12,
21
+ metalness = 0,
22
+ emissive = 0x2a2838,
23
+ flatShading = true,
24
+ vertexColors = true,
25
+ } = {}) {
26
+ return new THREE.MeshStandardMaterial({ vertexColors, roughness, metalness, emissive, flatShading });
27
+ }