@adatechnology/game-vfx-three 0.9.0 → 0.10.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.
package/README.md CHANGED
@@ -20,6 +20,10 @@ The three.js renderer of [`@adatechnology/game-vfx`](../game-vfx). It draws a `V
20
20
  It plays through `host.effects`, or into a renderer of its own when the host lends none.
21
21
  - Lights use the raw colours of the Lab and are multiplied by `lightScale` (default `Math.PI`: r155+ lights are physical, the Lab's r128 ones were not).
22
22
 
23
+ - **Water**: `createWaterEffectsLayer(THREE, effects)` draws a `WaterEffects` of game-vfx with four instanced meshes (one draw call each): the rings, shock
24
+ rings, wave crests and foam on the surface, the drops, bubbles and mist as sprites facing the camera, and the columns (a ragged open cone that leans
25
+ and flares) and the domes of thrown water. Add `layer.group` to the scene, call `sync()` after `effects.update(dt)`, `dispose()` frees it all.
26
+
23
27
  ```ts
24
28
  import * as THREE from 'three'
25
29
  import { createVfxRenderer } from '@adatechnology/game-vfx-three'
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as THREE_NS from 'three';
2
2
  import { EffectSink, WarmUpProbes } from '@adatechnology/game-contracts';
3
3
  import { LightBudget } from '@adatechnology/game-render-three';
4
- import { VfxWorld, ScreenState, VfxOptions, VfxProfileName, GroundField, SpriteKindSystem, MarkEvent } from '@adatechnology/game-vfx';
4
+ import { VfxWorld, ScreenState, VfxOptions, VfxProfileName, GroundField, SpriteKindSystem, MarkEvent, WaterEffects } from '@adatechnology/game-vfx';
5
5
  export { BenchText, VfxTestModuleOptions, benchText, benchTexts, createVfxTestModule } from './testing.js';
6
6
 
7
7
  /** The only three.js members the renderer needs at runtime. Pass your own `THREE` instance (the whole namespace works). */
@@ -184,4 +184,34 @@ declare const SHELL_FRAGMENT = "uniform float uA;varying vec3 vN;varying vec3 vV
184
184
  declare const RING_VERTEX = "varying vec2 vU;void main(){vU=position.xz;gl_Position=projectionMatrix*viewMatrix*modelMatrix*vec4(position,1.);}";
185
185
  declare const RING_FRAGMENT = "uniform float uA;uniform float uW;uniform vec3 uC;varying vec2 vU;\n float h(vec2 p){return fract(sin(dot(p,vec2(12.9898,78.233)))*43758.5453);}\n void main(){float r=length(vU);float b=smoothstep(1.,1.-uW,r)*smoothstep(1.-uW*3.5,1.-uW,r);float a=atan(vU.y,vU.x);float n=.7+.3*h(vec2(floor(a*14.),1.));gl_FragColor=vec4(uC,b*uA*n);\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n}";
186
186
 
187
- export { type CanvasContextLike, type CanvasLike, GLOW_FRAGMENT, GLOW_VERTEX, type GroundPatch, type GroundPatchOptions, type MarkLayer, type MarkLayerOptions, PUFF_FRAGMENT, PUFF_VERTEX, RING_FRAGMENT, RING_VERTEX, SHELL_FRAGMENT, SHELL_VERTEX, SPARK_FRAGMENT, SPARK_VERTEX, SPRITE_FRAGMENT, SPRITE_VERTEX, type ScreenOverlay, type SpriteLayer, type ThreeLib, VFX_LAYERS, type VfxRenderer, type VfxRendererOptions, type VfxRendererStats, createGroundPatch, createMarkLayer, createScreenOverlay, createSpriteLayer, createVfxRenderer };
187
+ /** The three.js members the water layer needs at runtime. */
188
+ type WaterThree = Pick<typeof THREE_NS, 'Group' | 'Mesh' | 'InstancedBufferGeometry' | 'InstancedBufferAttribute' | 'Float32BufferAttribute' | 'ShaderMaterial' | 'DynamicDrawUsage' | 'CylinderGeometry' | 'SphereGeometry' | 'Vector3' | 'DoubleSide'>;
189
+ interface WaterLayerOptions {
190
+ /** Colour of the white water (linear RGB). */
191
+ readonly foam?: readonly [number, number, number];
192
+ /** Colour of the clear water the drops and the column show at their edges (linear RGB). */
193
+ readonly deep?: readonly [number, number, number];
194
+ /** Drops are drawn this many times their size (spray reads as clumps, not single drops). */
195
+ readonly dropScale?: number;
196
+ }
197
+ /** The water splashes of a `WaterEffects` drawn with four instanced meshes: surface marks, sprites, columns and domes. */
198
+ interface WaterLayer {
199
+ readonly group: THREE_NS.Group;
200
+ /** Copies the pools into the instance buffers; answers how many instances are drawn. */
201
+ sync(): number;
202
+ dispose(): void;
203
+ }
204
+ declare function createWaterEffectsLayer(THREE: WaterThree, effects: WaterEffects, options?: WaterLayerOptions): WaterLayer;
205
+
206
+ /** Shaders of the water splashes: flat marks on the surface, sprites that face the camera, and the columns and domes of thrown water. */
207
+ /** aP: x, y, z, radius. aD: alpha, kind (0 ripple, 1 shock ring, 2 wave crest, 3 foam), seed. */
208
+ declare const WATER_SURFACE_VERTEX = "attribute vec4 aP;attribute vec3 aD;varying vec2 vU;varying vec3 vD;\nvoid main(){vU=position.xz;vD=aD;vec3 w=vec3(aP.x+position.x*aP.w,aP.y+0.012,aP.z+position.z*aP.w);gl_Position=projectionMatrix*viewMatrix*vec4(w,1.);}";
209
+ declare const WATER_SURFACE_FRAGMENT = "uniform vec3 uFoam;varying vec2 vU;varying vec3 vD;float wHash(vec2 p){return fract(sin(dot(p,vec2(12.9898,78.233)))*43758.5453);}\nfloat wNoise(vec2 p){vec2 i=floor(p);vec2 f=fract(p);f=f*f*(3.-2.*f);return mix(mix(wHash(i),wHash(i+vec2(1.,0.)),f.x),mix(wHash(i+vec2(0.,1.)),wHash(i+vec2(1.,1.)),f.x),f.y);}\nvoid main(){float r=length(vU);if(r>1.)discard;float a=atan(vU.y,vU.x);float kind=vD.y;float s=vD.z;float m;\nif(kind>2.5){float n=wNoise(vU*7.+s*13.)*.6+wNoise(vU*19.-s*7.)*.4;m=smoothstep(1.,.55,r)*smoothstep(.25,.6,n);}\nelse{float w=kind>1.5?.16:kind>.5?.05:.09;float band=smoothstep(1.,1.-w,r)*smoothstep(1.-w*3.,1.-w,r);float broken=kind>.5?1.:.65+.35*wNoise(vec2(a*5.+s*20.,s));m=band*broken;}\nfloat alpha=m*vD.x;if(alpha<.004)discard;gl_FragColor=vec4(uFoam,alpha);\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n}";
210
+ /** aP: x, y, z, size. aD: alpha, kind (0 drop, 1 bubble, 2 mist), seed. */
211
+ declare const WATER_SPRITE_VERTEX = "attribute vec4 aP;attribute vec3 aD;varying vec2 vU;varying vec3 vD;\nvoid main(){vU=position.xy;vD=aD;vec3 right=vec3(viewMatrix[0][0],viewMatrix[1][0],viewMatrix[2][0]);vec3 up=vec3(viewMatrix[0][1],viewMatrix[1][1],viewMatrix[2][1]);\nvec3 w=aP.xyz+(right*position.x+up*position.y)*aP.w;gl_Position=projectionMatrix*viewMatrix*vec4(w,1.);}";
212
+ declare const WATER_SPRITE_FRAGMENT = "uniform vec3 uFoam;uniform vec3 uDeep;varying vec2 vU;varying vec3 vD;float wHash(vec2 p){return fract(sin(dot(p,vec2(12.9898,78.233)))*43758.5453);}\nfloat wNoise(vec2 p){vec2 i=floor(p);vec2 f=fract(p);f=f*f*(3.-2.*f);return mix(mix(wHash(i),wHash(i+vec2(1.,0.)),f.x),mix(wHash(i+vec2(0.,1.)),wHash(i+vec2(1.,1.)),f.x),f.y);}\nvoid main(){float r=length(vU);if(r>1.)discard;float kind=vD.y;float m;vec3 c=uFoam;\nif(kind>1.5){m=exp(-r*r*3.)*(.75+.25*wNoise(vU*3.+vD.z*9.));}\nelse if(kind>.5){m=smoothstep(.55,.85,r)*smoothstep(1.,.88,r)+.25*smoothstep(.5,.2,length(vU-vec2(-.3,.3)));c=mix(uDeep,uFoam,.8);}\nelse{m=smoothstep(1.,.6,r);c=mix(uDeep,uFoam,.55+.45*smoothstep(.2,.8,1.-length(vU-vec2(-.3,.35))));}\nfloat alpha=m*vD.x;if(alpha<.004)discard;gl_FragColor=vec4(c,alpha);\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n}";
213
+ /** aP: x, y, z, radius. aD: height, alpha, tilt x, tilt z. aK: dome (0/1), seed. The geometry is a unit open cylinder (y 0..1) or a unit half sphere. */
214
+ declare const WATER_COLUMN_VERTEX = "attribute vec4 aP;attribute vec4 aD;attribute vec2 aK;varying float vY;varying float vA;varying vec2 vK;varying float vF;float wHash(vec2 p){return fract(sin(dot(p,vec2(12.9898,78.233)))*43758.5453);}\nfloat wNoise(vec2 p){vec2 i=floor(p);vec2 f=fract(p);f=f*f*(3.-2.*f);return mix(mix(wHash(i),wHash(i+vec2(1.,0.)),f.x),mix(wHash(i+vec2(0.,1.)),wHash(i+vec2(1.,1.)),f.x),f.y);}\nvoid main(){vY=position.y;float ang=atan(position.z,position.x);vK=aK;\nfloat dome=aK.x;float s=aK.y;float h=position.y;\nfloat jag=.8+.4*wNoise(vec2(ang*3.+s*17.,h*4.+s));\nfloat flare=dome>.5?1.:(.55+.9*h*h)*jag;\nvec3 p=vec3(position.x*aP.w*flare,position.y*aD.x,position.z*aP.w*flare);\np.x+=aD.z*aD.x*h*h;p.z+=aD.w*aD.x*h*h;\nvec3 w=aP.xyz+p;vec3 n=normalize(vec3(position.x,dome>.5?position.y:.25,position.z));\nvec3 v=normalize(cameraPosition-w);vF=abs(dot(n,v));\nvA=aD.y;gl_Position=projectionMatrix*viewMatrix*vec4(w,1.);}";
215
+ declare const WATER_COLUMN_FRAGMENT = "uniform vec3 uFoam;uniform vec3 uDeep;varying float vY;varying float vA;varying vec2 vK;varying float vF;float wHash(vec2 p){return fract(sin(dot(p,vec2(12.9898,78.233)))*43758.5453);}\nfloat wNoise(vec2 p){vec2 i=floor(p);vec2 f=fract(p);f=f*f*(3.-2.*f);return mix(mix(wHash(i),wHash(i+vec2(1.,0.)),f.x),mix(wHash(i+vec2(0.,1.)),wHash(i+vec2(1.,1.)),f.x),f.y);}\nvoid main(){float dome=vK.x;float s=vK.y;\nfloat streak=wNoise(vec2(gl_FragCoord.x*.05+s*31.,vY*6.+s));\nfloat body=dome>.5?mix(.95,.5,vY)*(.6+.4*(1.-vF)):(1.-smoothstep(.55,1.,vY))*(.45+.55*streak)*(.55+.45*(1.-vF*.6));\nvec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)discard;gl_FragColor=vec4(c,alpha);\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n}";
216
+
217
+ export { type CanvasContextLike, type CanvasLike, GLOW_FRAGMENT, GLOW_VERTEX, type GroundPatch, type GroundPatchOptions, type MarkLayer, type MarkLayerOptions, PUFF_FRAGMENT, PUFF_VERTEX, RING_FRAGMENT, RING_VERTEX, SHELL_FRAGMENT, SHELL_VERTEX, SPARK_FRAGMENT, SPARK_VERTEX, SPRITE_FRAGMENT, SPRITE_VERTEX, type ScreenOverlay, type SpriteLayer, type ThreeLib, VFX_LAYERS, type VfxRenderer, type VfxRendererOptions, type VfxRendererStats, WATER_COLUMN_FRAGMENT, WATER_COLUMN_VERTEX, WATER_SPRITE_FRAGMENT, WATER_SPRITE_VERTEX, WATER_SURFACE_FRAGMENT, WATER_SURFACE_VERTEX, type WaterLayer, type WaterLayerOptions, type WaterThree, createGroundPatch, createMarkLayer, createScreenOverlay, createSpriteLayer, createVfxRenderer, createWaterEffectsLayer };
@@ -34,6 +34,12 @@ var GameVfxThree = (() => {
34
34
  SPRITE_FRAGMENT: () => SPRITE_FRAGMENT,
35
35
  SPRITE_VERTEX: () => SPRITE_VERTEX,
36
36
  VFX_LAYERS: () => VFX_LAYERS2,
37
+ WATER_COLUMN_FRAGMENT: () => WATER_COLUMN_FRAGMENT,
38
+ WATER_COLUMN_VERTEX: () => WATER_COLUMN_VERTEX,
39
+ WATER_SPRITE_FRAGMENT: () => WATER_SPRITE_FRAGMENT,
40
+ WATER_SPRITE_VERTEX: () => WATER_SPRITE_VERTEX,
41
+ WATER_SURFACE_FRAGMENT: () => WATER_SURFACE_FRAGMENT,
42
+ WATER_SURFACE_VERTEX: () => WATER_SURFACE_VERTEX,
37
43
  benchText: () => benchText,
38
44
  benchTexts: () => benchTexts,
39
45
  createGroundPatch: () => createGroundPatch,
@@ -41,7 +47,8 @@ var GameVfxThree = (() => {
41
47
  createScreenOverlay: () => createScreenOverlay,
42
48
  createSpriteLayer: () => createSpriteLayer,
43
49
  createVfxRenderer: () => createVfxRenderer,
44
- createVfxTestModule: () => createVfxTestModule
50
+ createVfxTestModule: () => createVfxTestModule,
51
+ createWaterEffectsLayer: () => createWaterEffectsLayer
45
52
  });
46
53
 
47
54
  // ../game-contracts/dist/index.js
@@ -3622,13 +3629,13 @@ var GameVfxThree = (() => {
3622
3629
  var ORIGIN = [0, 0, 0];
3623
3630
  var FORWARD4 = [0, 0, -1];
3624
3631
  var IMPACT_MATERIALS = ["concrete", "metal", "wood", "glass", "flesh", "water"];
3625
- var impactEffect = (material) => ({
3626
- id: `impact_${material}`,
3627
- pageId: `event:impact_${material}`,
3632
+ var impactEffect = (material2) => ({
3633
+ id: `impact_${material2}`,
3634
+ pageId: `event:impact_${material2}`,
3628
3635
  team: "weapons",
3629
3636
  budget: { particles: 40, decals: 1 },
3630
3637
  loop: 2,
3631
- timeline: [call2("impact", material, ORIGIN, FACING4, 1, 0)]
3638
+ timeline: [call2("impact", material2, ORIGIN, FACING4, 1, 0)]
3632
3639
  });
3633
3640
  var muzzleEffect = (weapon) => ({
3634
3641
  id: `muzzle_${weapon}`,
@@ -3954,8 +3961,8 @@ var GameVfxThree = (() => {
3954
3961
  flesh: { dust: 0, chip: 0, spark: 0 },
3955
3962
  water: { dust: 0, chip: 0, spark: 0 }
3956
3963
  };
3957
- function sparkSpec(material) {
3958
- return TABLE[material];
3964
+ function sparkSpec(material2) {
3965
+ return TABLE[material2];
3959
3966
  }
3960
3967
  var BLOOD_COLORS = [9046538, 5901328, 3808274, 1906964];
3961
3968
  var BLEED_BY_AGE = [1, 0.7, 0.35, 0.1];
@@ -3977,26 +3984,26 @@ var GameVfxThree = (() => {
3977
3984
  engine.ring([plus(point, 0, 0.012, 0), 0.02, 0.6, 0.7, 8425640]);
3978
3985
  engine.ring([plus(point, 0, 0.013, 0), 0.02, 0.35, 0.5, 8425640]);
3979
3986
  }
3980
- function impact(engine, material, point, normal, scale = 1, age = 0) {
3981
- if (material === "flesh") return bloodHit(engine, point, negated(normal), age, scale);
3982
- if (material === "water") return waterImpact(engine, point, scale);
3983
- const spec = sparkSpec(material);
3987
+ function impact(engine, material2, point, normal, scale = 1, age = 0) {
3988
+ if (material2 === "flesh") return bloodHit(engine, point, negated(normal), age, scale);
3989
+ if (material2 === "water") return waterImpact(engine, point, scale);
3990
+ const spec = sparkSpec(material2);
3984
3991
  if (spec.dust) engine.burst("normal", 14 * scale, { p: point, dir: normal, cone: 0.6, sp: [0.6, 2.4], drag: 2.5, life: [0.6, 1.2], size: [0.08, 0.16], grow: 4, c0: spec.dust, c1: 3815734, a: 0.55, g: -0.1 });
3985
3992
  if (spec.chip) {
3986
- const size = material === "wood" ? [0.015, 0.015, 0.09] : material === "glass" ? [0.03, 4e-3, 0.03] : [0.03, 0.03, 0.03];
3987
- for (let index = 0; index < engine.scaled(material === "wood" ? 8 : 6) * scale; index++) {
3993
+ const size = material2 === "wood" ? [0.015, 0.015, 0.09] : material2 === "glass" ? [0.03, 4e-3, 0.03] : [0.03, 0.03, 0.03];
3994
+ for (let index = 0; index < engine.scaled(material2 === "wood" ? 8 : 6) * scale; index++) {
3988
3995
  engine.debrisPiece({ p: point, dir: normal, cone: 0.8, sp: [1.5, 4], size, k: [0.6, 1.4], c: spec.chip, life: 6 });
3989
3996
  }
3990
3997
  }
3991
3998
  if (spec.spark && engine.quality < 2) {
3992
- engine.burst("streak", spec.spark * scale, { p: point, dir: normal, cone: material === "metal" ? 0.9 : 0.5, sp: [3, 9], life: [0.15, 0.45], len: 0.025, c0: 16773312, c1: 16734736, g: 9.8, gnd: 2 });
3993
- engine.burst("add", material === "metal" ? 3 : 1, { p: point, size: [0.12, 0.2], life: 0.06, c0: 16769184, fi: 0 });
3994
- if (material === "metal") engine.flash([plusScaled(point, normal, 0.2), 16756832, 2, 0.06, 5]);
3999
+ engine.burst("streak", spec.spark * scale, { p: point, dir: normal, cone: material2 === "metal" ? 0.9 : 0.5, sp: [3, 9], life: [0.15, 0.45], len: 0.025, c0: 16773312, c1: 16734736, g: 9.8, gnd: 2 });
4000
+ engine.burst("add", material2 === "metal" ? 3 : 1, { p: point, size: [0.12, 0.2], life: 0.06, c0: 16769184, fi: 0 });
4001
+ if (material2 === "metal") engine.flash([plusScaled(point, normal, 0.2), 16756832, 2, 0.06, 5]);
3995
4002
  }
3996
- if (material === "glass") engine.burst("add", 5, { p: point, r: 0.15, size: [0.02, 0.05], life: [0.2, 0.5], c0: 16777215, a: 0.9, fi: 0.3 });
4003
+ if (material2 === "glass") engine.burst("add", 5, { p: point, r: 0.15, size: [0.02, 0.05], life: [0.2, 0.5], c0: 16777215, a: 0.9, fi: 0.3 });
3997
4004
  if (engine.quality < 2) {
3998
- const size = material === "glass" ? 0.07 : material === "metal" ? 0.05 : 0.06;
3999
- engine.decal([point[0], point[1], point[2], size, material === "metal" ? 2762018 : 920844, { n: normal, grow: 0, life: 60 }]);
4005
+ const size = material2 === "glass" ? 0.07 : material2 === "metal" ? 0.05 : 0.06;
4006
+ engine.decal([point[0], point[1], point[2], size, material2 === "metal" ? 2762018 : 920844, { n: normal, grow: 0, life: 60 }]);
4000
4007
  }
4001
4008
  }
4002
4009
  var COLUMNS = 6;
@@ -4754,7 +4761,7 @@ var GameVfxThree = (() => {
4754
4761
  }
4755
4762
  var MACROS = {
4756
4763
  blood_hit: ({ engine }, [point, direction, age, scale]) => bloodHit(engine, point, direction, age, scale),
4757
- impact: ({ engine }, [material, point, normal, scale, age]) => impact(engine, material, point, normal, scale, age),
4764
+ impact: ({ engine }, [material2, point, normal, scale, age]) => impact(engine, material2, point, normal, scale, age),
4758
4765
  fire_emit: ({ engine, dt }, [key, centre, radius, factor, options]) => fireEmit(engine, key, dt, centre, radius, factor, options),
4759
4766
  explode: ({ engine, cameraPosition }, [point, scale, chipColor]) => explode(engine, point, scale, cameraPosition, chipColor),
4760
4767
  muzzle: ({ engine }, [weapon, tip, direction]) => muzzle(engine, weapon, tip, direction),
@@ -8523,6 +8530,7 @@ var GameVfxThree = (() => {
8523
8530
  }
8524
8531
  };
8525
8532
  var resolveStrings = (locale) => locales[locale ?? "en"] ?? locales.en;
8533
+ var DEGREES = 180 / Math.PI;
8526
8534
 
8527
8535
  // src/shaders/glow.ts
8528
8536
  var GLOW_VERTEX = `attribute vec4 aP;attribute vec4 aC;varying vec2 vU;varying vec4 vC;
@@ -8642,8 +8650,8 @@ void main(){
8642
8650
  geometry.setAttribute("aD", attributes[1]);
8643
8651
  geometry.setAttribute("aC", attributes[2]);
8644
8652
  geometry.instanceCount = 0;
8645
- const material = new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT });
8646
- const mesh2 = new THREE.Mesh(geometry, material);
8653
+ const material2 = new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT });
8654
+ const mesh2 = new THREE.Mesh(geometry, material2);
8647
8655
  mesh2.name = "vfx-puffs";
8648
8656
  mesh2.frustumCulled = false;
8649
8657
  return {
@@ -8670,7 +8678,7 @@ void main(){
8670
8678
  },
8671
8679
  dispose() {
8672
8680
  geometry.dispose();
8673
- material.dispose();
8681
+ material2.dispose();
8674
8682
  }
8675
8683
  };
8676
8684
  }
@@ -8687,8 +8695,8 @@ void main(){
8687
8695
  geometry.setAttribute("aVel", attributes[1]);
8688
8696
  geometry.setAttribute("aE", attributes[2]);
8689
8697
  geometry.instanceCount = 0;
8690
- const material = new THREE.ShaderMaterial({ transparent: true, depthWrite: false, blending: THREE.AdditiveBlending, vertexShader: SPARK_VERTEX, fragmentShader: SPARK_FRAGMENT });
8691
- const mesh2 = new THREE.Mesh(geometry, material);
8698
+ const material2 = new THREE.ShaderMaterial({ transparent: true, depthWrite: false, blending: THREE.AdditiveBlending, vertexShader: SPARK_VERTEX, fragmentShader: SPARK_FRAGMENT });
8699
+ const mesh2 = new THREE.Mesh(geometry, material2);
8692
8700
  mesh2.name = "vfx-sparks";
8693
8701
  mesh2.frustumCulled = false;
8694
8702
  mesh2.renderOrder = 5;
@@ -8715,7 +8723,7 @@ void main(){
8715
8723
  },
8716
8724
  dispose() {
8717
8725
  geometry.dispose();
8718
- material.dispose();
8726
+ material2.dispose();
8719
8727
  }
8720
8728
  };
8721
8729
  }
@@ -8730,8 +8738,8 @@ void main(){
8730
8738
  geometry.setAttribute("aP", attributes[0]);
8731
8739
  geometry.setAttribute("aC", attributes[1]);
8732
8740
  geometry.instanceCount = 0;
8733
- const material = new THREE.ShaderMaterial({ transparent: true, depthWrite: false, blending: THREE.AdditiveBlending, vertexShader: GLOW_VERTEX, fragmentShader: GLOW_FRAGMENT });
8734
- const mesh2 = new THREE.Mesh(geometry, material);
8741
+ const material2 = new THREE.ShaderMaterial({ transparent: true, depthWrite: false, blending: THREE.AdditiveBlending, vertexShader: GLOW_VERTEX, fragmentShader: GLOW_FRAGMENT });
8742
+ const mesh2 = new THREE.Mesh(geometry, material2);
8735
8743
  mesh2.name = "vfx-glows";
8736
8744
  mesh2.frustumCulled = false;
8737
8745
  mesh2.renderOrder = 6;
@@ -8756,7 +8764,7 @@ void main(){
8756
8764
  },
8757
8765
  dispose() {
8758
8766
  geometry.dispose();
8759
- material.dispose();
8767
+ material2.dispose();
8760
8768
  }
8761
8769
  };
8762
8770
  }
@@ -8764,8 +8772,8 @@ void main(){
8764
8772
  const capacity = pool.capacity;
8765
8773
  const rockMaterial = new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.85, flatShading: true });
8766
8774
  const plateMaterial = rockMaterial.clone();
8767
- const make = (geometry, material) => {
8768
- const mesh2 = new THREE.InstancedMesh(geometry, material, capacity);
8775
+ const make = (geometry, material2) => {
8776
+ const mesh2 = new THREE.InstancedMesh(geometry, material2, capacity);
8769
8777
  mesh2.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
8770
8778
  mesh2.castShadow = true;
8771
8779
  mesh2.receiveShadow = true;
@@ -9015,9 +9023,9 @@ void main(){
9015
9023
  const textures = createMarkTextures(THREE, options.createCanvas);
9016
9024
  const owned = [...textures.scorch, textures.dirt];
9017
9025
  const scorchMaterials = textures.scorch.map((map) => {
9018
- const material = new THREE.MeshStandardMaterial({ map, transparent: true, depthWrite: false, roughness: 1, polygonOffset: true, polygonOffsetFactor: -2, polygonOffsetUnits: -2 });
9019
- owned.push(material);
9020
- return material;
9026
+ const material2 = new THREE.MeshStandardMaterial({ map, transparent: true, depthWrite: false, roughness: 1, polygonOffset: true, polygonOffsetFactor: -2, polygonOffsetUnits: -2 });
9027
+ owned.push(material2);
9028
+ return material2;
9021
9029
  });
9022
9030
  const dirtMaterial = new THREE.MeshStandardMaterial({
9023
9031
  map: textures.dirt,
@@ -9074,8 +9082,8 @@ void main(){
9074
9082
  const scale = new THREE.Vector3();
9075
9083
  const color = new THREE.Color();
9076
9084
  const up = new THREE.Vector3(0, 1, 0);
9077
- function createInstanced(geometry, material, capacity) {
9078
- const mesh2 = new THREE.InstancedMesh(geometry, material, capacity);
9085
+ function createInstanced(geometry, material2, capacity) {
9086
+ const mesh2 = new THREE.InstancedMesh(geometry, material2, capacity);
9079
9087
  mesh2.count = 0;
9080
9088
  mesh2.frustumCulled = false;
9081
9089
  mesh2.receiveShadow = true;
@@ -9102,7 +9110,7 @@ void main(){
9102
9110
  }
9103
9111
  return false;
9104
9112
  }
9105
- function conform(mark, material) {
9113
+ function conform(mark, material2) {
9106
9114
  const radius = mark.radius;
9107
9115
  const dug = options.heightAt !== void 0 && groundDipsUnder(mark.x, mark.z, radius);
9108
9116
  const steps = Math.max(MIN_CONFORM_STEPS, Math.min(dug ? MAX_DUG_STEPS : MAX_FLAT_STEPS, Math.round(radius * (dug ? DUG_STEPS_PER_METRE : FLAT_STEPS_PER_METRE))));
@@ -9124,7 +9132,7 @@ void main(){
9124
9132
  geometry.attributes.normal.needsUpdate = true;
9125
9133
  geometry.boundingSphere = null;
9126
9134
  geometry.boundingBox = null;
9127
- const mesh2 = new THREE.Mesh(geometry, material);
9135
+ const mesh2 = new THREE.Mesh(geometry, material2);
9128
9136
  mesh2.receiveShadow = true;
9129
9137
  group.add(mesh2);
9130
9138
  groundMarks.push({ mesh: mesh2, steps });
@@ -9194,8 +9202,8 @@ void main(){
9194
9202
  },
9195
9203
  probes() {
9196
9204
  probeGeometry ?? (probeGeometry = new THREE.PlaneGeometry(1e-3, 1e-3).rotateX(-Math.PI / 2));
9197
- return [...scorchMaterials, dirtMaterial].map((material) => {
9198
- const mesh2 = new THREE.Mesh(probeGeometry, material);
9205
+ return [...scorchMaterials, dirtMaterial].map((material2) => {
9206
+ const mesh2 = new THREE.Mesh(probeGeometry, material2);
9199
9207
  mesh2.receiveShadow = true;
9200
9208
  mesh2.frustumCulled = false;
9201
9209
  return mesh2;
@@ -9469,7 +9477,7 @@ void main() {
9469
9477
  return attribute;
9470
9478
  });
9471
9479
  geometry.setDrawRange(0, 0);
9472
- const material = new THREE.ShaderMaterial({
9480
+ const material2 = new THREE.ShaderMaterial({
9473
9481
  uniforms: { uScale: { value: pointScale } },
9474
9482
  vertexShader: SPRITE_VERTEX,
9475
9483
  fragmentShader: SPRITE_FRAGMENT,
@@ -9477,7 +9485,7 @@ void main() {
9477
9485
  depthWrite: false,
9478
9486
  blending: additive ? THREE.AdditiveBlending : THREE.NormalBlending
9479
9487
  });
9480
- const points = new THREE.Points(geometry, material);
9488
+ const points = new THREE.Points(geometry, material2);
9481
9489
  points.frustumCulled = false;
9482
9490
  points.name = additive ? "vfx-sprites-additive" : "vfx-sprites";
9483
9491
  points.renderOrder = additive ? 11 : 10;
@@ -9490,7 +9498,7 @@ void main() {
9490
9498
  },
9491
9499
  dispose() {
9492
9500
  geometry.dispose();
9493
- material.dispose();
9501
+ material2.dispose();
9494
9502
  }
9495
9503
  };
9496
9504
  }
@@ -9536,7 +9544,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9536
9544
  return attribute;
9537
9545
  });
9538
9546
  geometry.setDrawRange(0, 0);
9539
- const material = new THREE.ShaderMaterial({
9547
+ const material2 = new THREE.ShaderMaterial({
9540
9548
  uniforms: { uScale: { value: scale }, uSoft: { value: soft } },
9541
9549
  vertexShader: WORKSHOP_SPRITE_VERTEX,
9542
9550
  fragmentShader: WORKSHOP_SPRITE_FRAGMENT,
@@ -9544,7 +9552,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9544
9552
  depthWrite: false,
9545
9553
  blending: additive ? THREE.AdditiveBlending : THREE.NormalBlending
9546
9554
  });
9547
- const points = new THREE.Points(geometry, material);
9555
+ const points = new THREE.Points(geometry, material2);
9548
9556
  points.frustumCulled = false;
9549
9557
  points.renderOrder = additive ? 3 : 2;
9550
9558
  points.name = additive ? "workshop-add" : "workshop-normal";
@@ -9557,7 +9565,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9557
9565
  },
9558
9566
  dispose() {
9559
9567
  geometry.dispose();
9560
- material.dispose();
9568
+ material2.dispose();
9561
9569
  }
9562
9570
  };
9563
9571
  }
@@ -9568,8 +9576,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9568
9576
  geometry.setAttribute("position", position);
9569
9577
  geometry.setAttribute("color", color);
9570
9578
  geometry.setDrawRange(0, 0);
9571
- const material = new THREE.LineBasicMaterial({ vertexColors: true, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false });
9572
- const lines = new THREE.LineSegments(geometry, material);
9579
+ const material2 = new THREE.LineBasicMaterial({ vertexColors: true, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false });
9580
+ const lines = new THREE.LineSegments(geometry, material2);
9573
9581
  lines.frustumCulled = false;
9574
9582
  lines.renderOrder = 4;
9575
9583
  lines.name = "workshop-streaks";
@@ -9582,7 +9590,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9582
9590
  },
9583
9591
  dispose() {
9584
9592
  geometry.dispose();
9585
- material.dispose();
9593
+ material2.dispose();
9586
9594
  }
9587
9595
  };
9588
9596
  }
@@ -9591,8 +9599,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9591
9599
  const position = new THREE.BufferAttribute(rain.positions, 3).setUsage(THREE.DynamicDrawUsage);
9592
9600
  geometry.setAttribute("position", position);
9593
9601
  geometry.setDrawRange(0, 0);
9594
- const material = new THREE.LineBasicMaterial({ color: 10466255, transparent: true, opacity: 0.35, depthWrite: false });
9595
- const lines = new THREE.LineSegments(geometry, material);
9602
+ const material2 = new THREE.LineBasicMaterial({ color: 10466255, transparent: true, opacity: 0.35, depthWrite: false });
9603
+ const lines = new THREE.LineSegments(geometry, material2);
9596
9604
  lines.frustumCulled = false;
9597
9605
  lines.name = "workshop-rain";
9598
9606
  return {
@@ -9606,14 +9614,14 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9606
9614
  },
9607
9615
  dispose() {
9608
9616
  geometry.dispose();
9609
- material.dispose();
9617
+ material2.dispose();
9610
9618
  }
9611
9619
  };
9612
9620
  }
9613
9621
  function debrisLayer(THREE, pool) {
9614
9622
  const geometry = new THREE.BoxGeometry(1, 1, 1);
9615
- const material = new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.45, metalness: 0.25, flatShading: true });
9616
- const mesh2 = new THREE.InstancedMesh(geometry, material, DEBRIS_CAPACITY);
9623
+ const material2 = new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.45, metalness: 0.25, flatShading: true });
9624
+ const mesh2 = new THREE.InstancedMesh(geometry, material2, DEBRIS_CAPACITY);
9617
9625
  mesh2.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
9618
9626
  mesh2.frustumCulled = false;
9619
9627
  mesh2.name = "workshop-debris";
@@ -9650,7 +9658,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9650
9658
  },
9651
9659
  dispose() {
9652
9660
  geometry.dispose();
9653
- material.dispose();
9661
+ material2.dispose();
9654
9662
  }
9655
9663
  };
9656
9664
  }
@@ -9762,8 +9770,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9762
9770
  }
9763
9771
  function ringLayer(THREE, pool) {
9764
9772
  const geometry = new THREE.RingGeometry(0.86, 1, 40);
9765
- const material = new THREE.MeshBasicMaterial({ color: 16777215, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, side: THREE.DoubleSide });
9766
- const mesh2 = new THREE.InstancedMesh(geometry, material, RING_CAPACITY3);
9773
+ const material2 = new THREE.MeshBasicMaterial({ color: 16777215, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, side: THREE.DoubleSide });
9774
+ const mesh2 = new THREE.InstancedMesh(geometry, material2, RING_CAPACITY3);
9767
9775
  mesh2.frustumCulled = false;
9768
9776
  mesh2.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
9769
9777
  mesh2.name = "workshop-rings";
@@ -9801,7 +9809,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9801
9809
  },
9802
9810
  dispose() {
9803
9811
  geometry.dispose();
9804
- material.dispose();
9812
+ material2.dispose();
9805
9813
  }
9806
9814
  };
9807
9815
  }
@@ -10457,8 +10465,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
10457
10465
  const position = geometry.attributes.position;
10458
10466
  const uv = geometry.attributes.uv;
10459
10467
  for (let index = 0; index < position.count; index++) uv.setXY(index, position.getX(index) / metres, position.getZ(index) / metres);
10460
- const material = options.material ?? new THREE.MeshStandardMaterial({ color: 2829359, roughness: 0.93, flatShading: true });
10461
- const mesh2 = new THREE.Mesh(geometry, material);
10468
+ const material2 = options.material ?? new THREE.MeshStandardMaterial({ color: 2829359, roughness: 0.93, flatShading: true });
10469
+ const mesh2 = new THREE.Mesh(geometry, material2);
10462
10470
  mesh2.receiveShadow = true;
10463
10471
  let version = -1;
10464
10472
  function sync() {
@@ -10474,7 +10482,180 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
10474
10482
  sync,
10475
10483
  dispose() {
10476
10484
  geometry.dispose();
10477
- if (!options.material) material.dispose();
10485
+ if (!options.material) material2.dispose();
10486
+ }
10487
+ };
10488
+ }
10489
+
10490
+ // src/shaders/water.ts
10491
+ var NOISE = `float wHash(vec2 p){return fract(sin(dot(p,vec2(12.9898,78.233)))*43758.5453);}
10492
+ float wNoise(vec2 p){vec2 i=floor(p);vec2 f=fract(p);f=f*f*(3.-2.*f);return mix(mix(wHash(i),wHash(i+vec2(1.,0.)),f.x),mix(wHash(i+vec2(0.,1.)),wHash(i+vec2(1.,1.)),f.x),f.y);}`;
10493
+ var OUTPUT = `
10494
+ #include <tonemapping_fragment>
10495
+ #include <colorspace_fragment>`;
10496
+ var WATER_SURFACE_VERTEX = `attribute vec4 aP;attribute vec3 aD;varying vec2 vU;varying vec3 vD;
10497
+ void main(){vU=position.xz;vD=aD;vec3 w=vec3(aP.x+position.x*aP.w,aP.y+0.012,aP.z+position.z*aP.w);gl_Position=projectionMatrix*viewMatrix*vec4(w,1.);}`;
10498
+ var WATER_SURFACE_FRAGMENT = `uniform vec3 uFoam;varying vec2 vU;varying vec3 vD;${NOISE}
10499
+ void main(){float r=length(vU);if(r>1.)discard;float a=atan(vU.y,vU.x);float kind=vD.y;float s=vD.z;float m;
10500
+ if(kind>2.5){float n=wNoise(vU*7.+s*13.)*.6+wNoise(vU*19.-s*7.)*.4;m=smoothstep(1.,.55,r)*smoothstep(.25,.6,n);}
10501
+ else{float w=kind>1.5?.16:kind>.5?.05:.09;float band=smoothstep(1.,1.-w,r)*smoothstep(1.-w*3.,1.-w,r);float broken=kind>.5?1.:.65+.35*wNoise(vec2(a*5.+s*20.,s));m=band*broken;}
10502
+ float alpha=m*vD.x;if(alpha<.004)discard;gl_FragColor=vec4(uFoam,alpha);${OUTPUT}
10503
+ }`;
10504
+ var WATER_SPRITE_VERTEX = `attribute vec4 aP;attribute vec3 aD;varying vec2 vU;varying vec3 vD;
10505
+ void main(){vU=position.xy;vD=aD;vec3 right=vec3(viewMatrix[0][0],viewMatrix[1][0],viewMatrix[2][0]);vec3 up=vec3(viewMatrix[0][1],viewMatrix[1][1],viewMatrix[2][1]);
10506
+ vec3 w=aP.xyz+(right*position.x+up*position.y)*aP.w;gl_Position=projectionMatrix*viewMatrix*vec4(w,1.);}`;
10507
+ var WATER_SPRITE_FRAGMENT = `uniform vec3 uFoam;uniform vec3 uDeep;varying vec2 vU;varying vec3 vD;${NOISE}
10508
+ void main(){float r=length(vU);if(r>1.)discard;float kind=vD.y;float m;vec3 c=uFoam;
10509
+ if(kind>1.5){m=exp(-r*r*3.)*(.75+.25*wNoise(vU*3.+vD.z*9.));}
10510
+ else if(kind>.5){m=smoothstep(.55,.85,r)*smoothstep(1.,.88,r)+.25*smoothstep(.5,.2,length(vU-vec2(-.3,.3)));c=mix(uDeep,uFoam,.8);}
10511
+ else{m=smoothstep(1.,.6,r);c=mix(uDeep,uFoam,.55+.45*smoothstep(.2,.8,1.-length(vU-vec2(-.3,.35))));}
10512
+ float alpha=m*vD.x;if(alpha<.004)discard;gl_FragColor=vec4(c,alpha);${OUTPUT}
10513
+ }`;
10514
+ var WATER_COLUMN_VERTEX = `attribute vec4 aP;attribute vec4 aD;attribute vec2 aK;varying float vY;varying float vA;varying vec2 vK;varying float vF;${NOISE}
10515
+ void main(){vY=position.y;float ang=atan(position.z,position.x);vK=aK;
10516
+ float dome=aK.x;float s=aK.y;float h=position.y;
10517
+ float jag=.8+.4*wNoise(vec2(ang*3.+s*17.,h*4.+s));
10518
+ float flare=dome>.5?1.:(.55+.9*h*h)*jag;
10519
+ vec3 p=vec3(position.x*aP.w*flare,position.y*aD.x,position.z*aP.w*flare);
10520
+ p.x+=aD.z*aD.x*h*h;p.z+=aD.w*aD.x*h*h;
10521
+ vec3 w=aP.xyz+p;vec3 n=normalize(vec3(position.x,dome>.5?position.y:.25,position.z));
10522
+ vec3 v=normalize(cameraPosition-w);vF=abs(dot(n,v));
10523
+ vA=aD.y;gl_Position=projectionMatrix*viewMatrix*vec4(w,1.);}`;
10524
+ var WATER_COLUMN_FRAGMENT = `uniform vec3 uFoam;uniform vec3 uDeep;varying float vY;varying float vA;varying vec2 vK;varying float vF;${NOISE}
10525
+ void main(){float dome=vK.x;float s=vK.y;
10526
+ float streak=wNoise(vec2(gl_FragCoord.x*.05+s*31.,vY*6.+s));
10527
+ float body=dome>.5?mix(.95,.5,vY)*(.6+.4*(1.-vF)):(1.-smoothstep(.55,1.,vY))*(.45+.55*streak)*(.55+.45*(1.-vF*.6));
10528
+ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)discard;gl_FragColor=vec4(c,alpha);${OUTPUT}
10529
+ }`;
10530
+
10531
+ // src/water-layer.ts
10532
+ var SURFACE_RIPPLE = 0;
10533
+ var SURFACE_FOAM = 3;
10534
+ var SPRITE_DROP = 0;
10535
+ var SPRITE_BUBBLE = 1;
10536
+ var SPRITE_MIST = 2;
10537
+ function makeBatch(THREE, base, material2, sizes, capacity) {
10538
+ const geometry = new THREE.InstancedBufferGeometry();
10539
+ geometry.setAttribute("position", base.getAttribute("position"));
10540
+ if (base.index) geometry.setIndex(base.index);
10541
+ const names = ["aP", "aD", "aK"];
10542
+ const arrays = sizes.map((size) => new Float32Array(Math.max(1, capacity) * size));
10543
+ const attributes = sizes.map((size, index) => {
10544
+ const attribute = new THREE.InstancedBufferAttribute(arrays[index], size).setUsage(THREE.DynamicDrawUsage);
10545
+ geometry.setAttribute(names[index], attribute);
10546
+ return attribute;
10547
+ });
10548
+ geometry.instanceCount = 0;
10549
+ base.dispose();
10550
+ const mesh2 = new THREE.Mesh(geometry, material2);
10551
+ mesh2.frustumCulled = false;
10552
+ return { mesh: mesh2, geometry, attributes, arrays };
10553
+ }
10554
+ function material(THREE, vertexShader, fragmentShader, uniforms) {
10555
+ return new THREE.ShaderMaterial({ uniforms, vertexShader, fragmentShader, transparent: true, depthWrite: false });
10556
+ }
10557
+ function quad(THREE, flat) {
10558
+ const geometry = new THREE.InstancedBufferGeometry();
10559
+ const corners = flat ? [-1, 0, -1, 1, 0, -1, 1, 0, 1, -1, 0, 1] : [-1, -1, 0, 1, -1, 0, 1, 1, 0, -1, 1, 0];
10560
+ geometry.setAttribute("position", new THREE.Float32BufferAttribute(corners, 3));
10561
+ geometry.setIndex(flat ? [0, 2, 1, 0, 3, 2] : [0, 1, 2, 0, 2, 3]);
10562
+ return geometry;
10563
+ }
10564
+ var put4 = (array, index, a, b, c, d) => {
10565
+ array[index * 4] = a;
10566
+ array[index * 4 + 1] = b;
10567
+ array[index * 4 + 2] = c;
10568
+ array[index * 4 + 3] = d;
10569
+ };
10570
+ var put3 = (array, index, a, b, c) => {
10571
+ array[index * 3] = a;
10572
+ array[index * 3 + 1] = b;
10573
+ array[index * 3 + 2] = c;
10574
+ };
10575
+ var put2 = (array, index, a, b) => {
10576
+ array[index * 2] = a;
10577
+ array[index * 2 + 1] = b;
10578
+ };
10579
+ function finish(batch, count) {
10580
+ batch.geometry.instanceCount = count;
10581
+ for (const attribute of batch.attributes) attribute.needsUpdate = true;
10582
+ return count;
10583
+ }
10584
+ function createWaterEffectsLayer(THREE, effects, options = {}) {
10585
+ const foam = options.foam ?? [0.86, 0.9, 0.92];
10586
+ const deep = options.deep ?? [0.42, 0.55, 0.6];
10587
+ const dropScale = options.dropScale ?? 2.5;
10588
+ const uniforms = { uFoam: { value: new THREE.Vector3(...foam) }, uDeep: { value: new THREE.Vector3(...deep) } };
10589
+ const { limits } = effects;
10590
+ const surface = makeBatch(THREE, quad(THREE, true), material(THREE, WATER_SURFACE_VERTEX, WATER_SURFACE_FRAGMENT, uniforms), [4, 3], limits.rings + limits.foam);
10591
+ const sprites = makeBatch(THREE, quad(THREE, false), material(THREE, WATER_SPRITE_VERTEX, WATER_SPRITE_FRAGMENT, uniforms), [4, 3], limits.drops + limits.bubbles + limits.mist);
10592
+ const cylinder = new THREE.CylinderGeometry(1, 1, 1, 14, 6, true).translate(0, 0.5, 0);
10593
+ const columns = makeBatch(THREE, cylinder, material(THREE, WATER_COLUMN_VERTEX, WATER_COLUMN_FRAGMENT, uniforms), [4, 4, 2], limits.columns);
10594
+ const hemisphere = new THREE.SphereGeometry(1, 18, 8, 0, Math.PI * 2, 0, Math.PI / 2);
10595
+ const domes = makeBatch(THREE, hemisphere, material(THREE, WATER_COLUMN_VERTEX, WATER_COLUMN_FRAGMENT, uniforms), [4, 4, 2], limits.columns);
10596
+ columns.mesh.material.side = THREE.DoubleSide;
10597
+ surface.mesh.renderOrder = 2;
10598
+ domes.mesh.renderOrder = 3;
10599
+ columns.mesh.renderOrder = 4;
10600
+ sprites.mesh.renderOrder = 5;
10601
+ const group = markKitOrigin(new THREE.Group(), { owner: "game-vfx-three", kind: "effect" });
10602
+ group.name = "water-effects";
10603
+ for (const batch of [surface, sprites, columns, domes]) {
10604
+ batch.mesh.name = "water-effects-batch";
10605
+ group.add(batch.mesh);
10606
+ }
10607
+ const syncSurface = () => {
10608
+ const [p, d] = surface.arrays;
10609
+ let n = 0;
10610
+ for (const ring2 of effects.rings) {
10611
+ if (ring2.alpha <= 4e-3) continue;
10612
+ put4(p, n, ring2.x, ring2.y, ring2.z, ring2.radius);
10613
+ put3(d, n++, ring2.alpha, ring2.kind === 0 ? SURFACE_RIPPLE : ring2.kind, (ring2.x * 7.13 + ring2.z * 3.71) % 1);
10614
+ }
10615
+ for (const patch of effects.foam) {
10616
+ put4(p, n, patch.x, patch.y, patch.z, patch.radius);
10617
+ put3(d, n++, patch.alpha, SURFACE_FOAM, (patch.x * 5.3 + patch.z * 9.1) % 1);
10618
+ }
10619
+ return finish(surface, n);
10620
+ };
10621
+ const syncSprites = () => {
10622
+ const [p, d] = sprites.arrays;
10623
+ let n = 0;
10624
+ for (const drop of effects.drops) {
10625
+ put4(p, n, drop.x, drop.y, drop.z, drop.size * dropScale);
10626
+ put3(d, n++, 0.85, SPRITE_DROP, 0);
10627
+ }
10628
+ for (const bubble of effects.bubbles) {
10629
+ if (bubble.alpha <= 4e-3) continue;
10630
+ put4(p, n, bubble.x, bubble.y, bubble.z, bubble.size);
10631
+ put3(d, n++, bubble.alpha, SPRITE_BUBBLE, 0);
10632
+ }
10633
+ for (const mist of effects.mist) {
10634
+ put4(p, n, mist.x, mist.y, mist.z, mist.size);
10635
+ put3(d, n++, mist.alpha, SPRITE_MIST, mist.x * 3.3 % 1);
10636
+ }
10637
+ return finish(sprites, n);
10638
+ };
10639
+ const syncColumns = (batch, dome) => {
10640
+ const [p, d, k] = batch.arrays;
10641
+ let n = 0;
10642
+ for (const column of effects.columns) {
10643
+ if (column.dome !== dome || column.alpha <= 4e-3 || column.height <= 5e-3) continue;
10644
+ put4(p, n, column.x, column.y, column.z, column.radius);
10645
+ put4(d, n, column.height, column.alpha, column.tiltX, column.tiltZ);
10646
+ put2(k, n++, dome ? 1 : 0, Math.abs(column.x * 1.7 + column.z * 2.3) % 1);
10647
+ }
10648
+ return finish(batch, n);
10649
+ };
10650
+ return {
10651
+ group,
10652
+ sync: () => syncSurface() + syncSprites() + syncColumns(columns, false) + syncColumns(domes, true),
10653
+ dispose() {
10654
+ for (const batch of [surface, sprites, columns, domes]) {
10655
+ batch.geometry.dispose();
10656
+ batch.mesh.material.dispose();
10657
+ }
10658
+ group.removeFromParent();
10478
10659
  }
10479
10660
  };
10480
10661
  }