@adatechnology/game-vfx-three 0.10.14 → 0.11.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.
@@ -29,6 +29,8 @@ var GameVfxThree = (() => {
29
29
  RING_VERTEX: () => RING_VERTEX,
30
30
  SHELL_FRAGMENT: () => SHELL_FRAGMENT,
31
31
  SHELL_VERTEX: () => SHELL_VERTEX,
32
+ SOFT_PUFF_FRAGMENT: () => SOFT_PUFF_FRAGMENT,
33
+ SOFT_PUFF_VERTEX: () => SOFT_PUFF_VERTEX,
32
34
  SPARK_FRAGMENT: () => SPARK_FRAGMENT,
33
35
  SPARK_VERTEX: () => SPARK_VERTEX,
34
36
  SPRITE_FRAGMENT: () => SPRITE_FRAGMENT,
@@ -1911,6 +1913,7 @@ var GameVfxThree = (() => {
1911
1913
  y: 0,
1912
1914
  z: 0,
1913
1915
  r: 0.6,
1916
+ h: 0,
1914
1917
  r0: 0.6,
1915
1918
  grow: 0,
1916
1919
  life: 6,
@@ -1936,6 +1939,7 @@ var GameVfxThree = (() => {
1936
1939
  fire.y = init.y ?? 0;
1937
1940
  fire.z = init.z ?? 0;
1938
1941
  fire.r = init.r ?? 0.6;
1942
+ fire.h = init.h ?? 0;
1939
1943
  fire.r0 = init.startRadius ?? fire.r;
1940
1944
  fire.grow = init.grow ?? 0;
1941
1945
  fire.life = init.life ?? 6;
@@ -1960,19 +1964,23 @@ var GameVfxThree = (() => {
1960
1964
  core.trace?.fire?.(fire);
1961
1965
  return fire;
1962
1966
  }
1967
+ var FLAMES_PER_HEIGHT = 1.5;
1968
+ var SMOKE_PER_HEIGHT = 2;
1963
1969
  function positionOf(follow) {
1964
1970
  return "position" in follow ? follow.position : follow;
1965
1971
  }
1972
+ var heightOf = (fire) => fire.h > 0 ? fire.rng.next() * fire.h : 0;
1973
+ var isBody = (follow) => "radius" in follow && "height" in follow;
1966
1974
  function emitFlames(core, fire, radius, dt) {
1967
1975
  const random = fire.rng;
1968
- fire.acc += dt * fire.rate * (0.5 + radius * 0.9) * fire.fade * core.clock.lod;
1976
+ fire.acc += dt * fire.rate * (0.5 + radius * 0.9) * (1 + fire.h * FLAMES_PER_HEIGHT) * fire.fade * core.clock.lod;
1969
1977
  while (fire.acc >= 1) {
1970
1978
  fire.acc -= 1;
1971
1979
  const angle = random.next() * Math.PI * 2;
1972
1980
  const distance = Math.sqrt(random.next()) * radius;
1973
1981
  addPuff(core, random, {
1974
1982
  x: fire.x + Math.cos(angle) * distance,
1975
- y: fire.y + 0.05,
1983
+ y: fire.y + 0.05 + heightOf(fire),
1976
1984
  z: fire.z + Math.sin(angle) * distance,
1977
1985
  vx: random.between(-0.2, 0.2),
1978
1986
  vy: random.between(0.6, 1.4),
@@ -1994,12 +2002,12 @@ var GameVfxThree = (() => {
1994
2002
  }
1995
2003
  function emitSmoke(core, fire, radius, dt) {
1996
2004
  const random = fire.rng;
1997
- fire.smokeAcc += dt * fire.smoke * (1 + radius * 0.8) * fire.fade * core.clock.lod;
2005
+ fire.smokeAcc += dt * fire.smoke * (1 + radius * 0.8) * (1 + fire.h * SMOKE_PER_HEIGHT) * fire.fade * core.clock.lod;
1998
2006
  while (fire.smokeAcc >= 1 && core.layers.smoke) {
1999
2007
  fire.smokeAcc -= 1;
2000
2008
  addPuff(core, random, {
2001
2009
  x: fire.x + random.between(-radius, radius) * 0.5,
2002
- y: fire.y + 0.6 + radius * 0.3,
2010
+ y: fire.y + fire.h + 0.6 + radius * 0.3,
2003
2011
  z: fire.z + random.between(-radius, radius) * 0.5,
2004
2012
  vy: random.between(0.8, 1.5),
2005
2013
  s0: 0.25,
@@ -2021,7 +2029,7 @@ var GameVfxThree = (() => {
2021
2029
  if (!(random.next() < dt * 6 * fire.fade && core.layers.shrapnel)) return;
2022
2030
  addSpark(core, {
2023
2031
  x: fire.x + random.between(-radius, radius) * 0.6,
2024
- y: fire.y + 0.4,
2032
+ y: fire.y + 0.4 + heightOf(fire),
2025
2033
  z: fire.z + random.between(-radius, radius) * 0.6,
2026
2034
  vx: random.between(-0.4, 0.4),
2027
2035
  vy: random.between(1.5, 3.2),
@@ -2045,6 +2053,10 @@ var GameVfxThree = (() => {
2045
2053
  fire.x = point.x + fire.fx;
2046
2054
  fire.y = point.y + fire.fy;
2047
2055
  fire.z = point.z + fire.fz;
2056
+ if (isBody(fire.follow)) {
2057
+ fire.r = fire.follow.radius;
2058
+ fire.h = fire.follow.height;
2059
+ }
2048
2060
  }
2049
2061
  const radius = fire.grow ? lerp(fire.r0, fire.r, Math.min(1, fire.t / fire.grow)) : fire.r;
2050
2062
  fire.fade = fire.t < fire.life - 1.5 ? Math.min(1, fire.t * 3) : Math.max(0, (fire.life - fire.t) / 1.5);
@@ -7924,10 +7936,11 @@ var GameVfxThree = (() => {
7924
7936
  },
7925
7937
  fire(fireOptions) {
7926
7938
  const handle = ++handles.next;
7927
- const { point, offset, seed, radius, smokeColor, ...rest } = fireOptions;
7939
+ const { point, offset, seed, radius, height, smokeColor, ...rest } = fireOptions;
7928
7940
  addFire(core, streamOf(seed), {
7929
7941
  ...rest,
7930
7942
  r: radius,
7943
+ ...height !== void 0 ? { h: height } : {},
7931
7944
  x: point[0],
7932
7945
  y: point[1],
7933
7946
  z: point[2],
@@ -8893,6 +8906,59 @@ float vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);
8893
8906
  // src/shaders/puff.ts
8894
8907
  var PUFF_VERTEX = `${GL_NOISE}
8895
8908
  attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;
8909
+ varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
8910
+ void main(){
8911
+ vec3 p=position;
8912
+ float s=aD.z;
8913
+ float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));
8914
+ p*=0.78+0.5*n;
8915
+ float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;
8916
+ vL=p;
8917
+ vec3 wp=aP.xyz+p*aP.w;
8918
+ vWP=wp;vD=aD;vC=aC;
8919
+ gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);
8920
+ }`;
8921
+ var PUFF_FRAGMENT = `${GL_NOISE}
8922
+ uniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;
8923
+ varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
8924
+ vec3 L(vec3 c){return pow(c,vec3(2.2));}
8925
+ vec3 ramp(float h){
8926
+ vec3 c0=L(vec3(.36,.07,.03)),c1=L(vec3(.76,.21,.1)),c2=L(vec3(1.,.54,.16)),c3=L(vec3(1.,.83,.42)),c4=L(vec3(1.,.96,.84));
8927
+ if(h<.25)return mix(c0,c1,h/.25);
8928
+ if(h<.5)return mix(c1,c2,(h-.25)/.25);
8929
+ if(h<.8)return mix(c2,c3,(h-.5)/.3);
8930
+ return mix(c3,c4,clamp((h-.8)/.4,0.,1.));
8931
+ }
8932
+ void main(){
8933
+ vec3 N=normalize(cross(dFdx(vWP),dFdy(vWP)));
8934
+ float age=vD.x,heat=vD.y,kind=vD.w;
8935
+ float n=vn(vL*2.4+vD.z*13.0);
8936
+ float diss=smoothstep(.5,1.,age);
8937
+ if(n<diss*1.08-.04)discard;
8938
+ float lam=max(dot(N,uLight),0.);
8939
+ float band=lam>.55?1.:lam>.15?.68:.42;
8940
+ // soot: a dark smoke still scatters some light, so it never goes flat black, and its rim takes the sky so its volume reads (only the dark puffs; the rest as the Lab)
8941
+ float dark=1.-smoothstep(.02,.12,dot(vC,vec3(.2126,.7152,.0722)));
8942
+ vec3 alb=max(vC,vec3(.055)*dark);
8943
+ vec3 col=alb*(vec3(.5,.56,.7)*band*1.05+vec3(.2,.19,.18)+uGround*(.4-.4*N.y));
8944
+ float rim=pow(1.-clamp(abs(dot(N,normalize(cameraPosition-vWP))),0.,1.),2.);
8945
+ col+=dark*rim*(uSky*.9+alb);
8946
+ vec3 tg=uGlowPos-vWP;float dg=length(tg)+.001;
8947
+ float gi=uGlowI/(1.+dg*dg*.05)*(.3+.7*max(dot(N,tg/dg),0.));
8948
+ col+=uGlowCol*gi*alb*1.6;
8949
+ float h=heat*(.72+.56*n)+heat*(-N.y)*.18;
8950
+ if(h>.05){
8951
+ float hq=floor(h*5.+.5)/5.;
8952
+ vec3 fc=ramp(clamp(hq,0.,1.2))*(1.1+3.1*hq);
8953
+ col=mix(col,fc,smoothstep(.04,.2,h));
8954
+ }
8955
+ if(kind>2.5&&kind<3.5){col+=vec3(.02,.025,.03);}
8956
+ gl_FragColor=vec4(col,1.);
8957
+ #include <tonemapping_fragment>
8958
+ #include <colorspace_fragment>
8959
+ }`;
8960
+ var SOFT_PUFF_VERTEX = `${GL_NOISE}
8961
+ attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;
8896
8962
  varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
8897
8963
  void main(){
8898
8964
  vec3 p=position;
@@ -8906,7 +8972,7 @@ void main(){
8906
8972
  vWP=wp;vD=aD;vC=aC;
8907
8973
  gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);
8908
8974
  }`;
8909
- var PUFF_FRAGMENT = `${GL_NOISE}
8975
+ var SOFT_PUFF_FRAGMENT = `${GL_NOISE}
8910
8976
  uniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;
8911
8977
  varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
8912
8978
  vec3 L(vec3 c){return pow(c,vec3(2.2));}
@@ -8985,11 +9051,11 @@ void main(){
8985
9051
  function dynamic(THREE, array, size) {
8986
9052
  return new THREE.InstancedBufferAttribute(array, size).setUsage(THREE.DynamicDrawUsage);
8987
9053
  }
8988
- var PUFF_DETAIL = 2;
8989
- function createPuffLayer(THREE, pool, uniforms) {
9054
+ var PUFF_DETAIL = { faceted: 1, soft: 2 };
9055
+ function createPuffLayer(THREE, pool, uniforms, style = "faceted") {
8990
9056
  const capacity = pool.capacity;
8991
9057
  const geometry = new THREE.InstancedBufferGeometry();
8992
- geometry.setAttribute("position", new THREE.IcosahedronGeometry(1, PUFF_DETAIL).getAttribute("position"));
9058
+ geometry.setAttribute("position", new THREE.IcosahedronGeometry(1, PUFF_DETAIL[style]).getAttribute("position"));
8993
9059
  const a = new Float32Array(capacity * 4);
8994
9060
  const d = new Float32Array(capacity * 4);
8995
9061
  const c = new Float32Array(capacity * 3);
@@ -8998,7 +9064,7 @@ void main(){
8998
9064
  geometry.setAttribute("aD", attributes[1]);
8999
9065
  geometry.setAttribute("aC", attributes[2]);
9000
9066
  geometry.instanceCount = 0;
9001
- const material2 = new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT, transparent: true, depthWrite: false });
9067
+ const material2 = style === "faceted" ? new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT }) : new THREE.ShaderMaterial({ uniforms, vertexShader: SOFT_PUFF_VERTEX, fragmentShader: SOFT_PUFF_FRAGMENT, transparent: true, depthWrite: false });
9002
9068
  const mesh2 = new THREE.Mesh(geometry, material2);
9003
9069
  mesh2.name = "vfx-puffs";
9004
9070
  mesh2.frustumCulled = false;
@@ -10360,7 +10426,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
10360
10426
  uGlowI: { value: 0 },
10361
10427
  uTime: { value: 0 }
10362
10428
  };
10363
- const puffs = createPuffLayer(THREE, pools.puffs, uniforms);
10429
+ const puffs = createPuffLayer(THREE, pools.puffs, uniforms, options.puffStyle ?? "faceted");
10364
10430
  const sparks2 = createSparkLayer(THREE, pools.sparks);
10365
10431
  const glows = createGlowLayer(THREE, pools.glows);
10366
10432
  const rockGeometry = new THREE.DodecahedronGeometry(0.5, 0);