@adatechnology/game-vfx-three 0.9.1 → 0.10.1
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 +4 -0
- package/dist/index.d.ts +32 -2
- package/dist/index.global.js +365 -145
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +187 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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
|
-
|
|
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 };
|