@adatechnology/game-vfx-three 0.11.0 → 0.11.2

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/dist/index.d.ts CHANGED
@@ -175,16 +175,16 @@ declare function createMarkLayer(THREE: ThreeLib, options: MarkLayerOptions): Ma
175
175
  * Two changes: the r160 colour-space chunk (`encodings_fragment` of r128 is `colorspace_fragment` now), and soot (a black smoke) keeps a floor of albedo and a rim
176
176
  * lit by the sky, so it reads as a cloud and not as a flat black blob.
177
177
  */
178
- declare const PUFF_VERTEX = "\nfloat h3(vec3 p){p=fract(p*.3183099+.1);p*=17.0;return fract(p.x*p.y*p.z*(p.x+p.y+p.z));}\nfloat vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);\n return mix(mix(mix(h3(i),h3(i+vec3(1,0,0)),f.x),mix(h3(i+vec3(0,1,0)),h3(i+vec3(1,1,0)),f.x),f.y),\n mix(mix(h3(i+vec3(0,0,1)),h3(i+vec3(1,0,1)),f.x),mix(h3(i+vec3(0,1,1)),h3(i+vec3(1,1,1)),f.x),f.y),f.z);}\n\nattribute vec4 aP;attribute vec4 aD;attribute vec3 aC;\nvarying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;\nvoid main(){\n vec3 p=position;\n float s=aD.z;\n float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));\n p*=0.78+0.5*n;\n float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;\n vL=p;\n vec3 wp=aP.xyz+p*aP.w;\n vWP=wp;vD=aD;vC=aC;\n gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);\n}";
179
- declare const PUFF_FRAGMENT = "\nfloat h3(vec3 p){p=fract(p*.3183099+.1);p*=17.0;return fract(p.x*p.y*p.z*(p.x+p.y+p.z));}\nfloat vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);\n return mix(mix(mix(h3(i),h3(i+vec3(1,0,0)),f.x),mix(h3(i+vec3(0,1,0)),h3(i+vec3(1,1,0)),f.x),f.y),\n mix(mix(h3(i+vec3(0,0,1)),h3(i+vec3(1,0,1)),f.x),mix(h3(i+vec3(0,1,1)),h3(i+vec3(1,1,1)),f.x),f.y),f.z);}\n\nuniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;\nvarying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;\nvec3 L(vec3 c){return pow(c,vec3(2.2));}\nvec3 ramp(float h){\n 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));\n if(h<.25)return mix(c0,c1,h/.25);\n if(h<.5)return mix(c1,c2,(h-.25)/.25);\n if(h<.8)return mix(c2,c3,(h-.5)/.3);\n return mix(c3,c4,clamp((h-.8)/.4,0.,1.));\n}\nvoid main(){\n vec3 N=normalize(cross(dFdx(vWP),dFdy(vWP)));\n float age=vD.x,heat=vD.y,kind=vD.w;\n float n=vn(vL*2.4+vD.z*13.0);\n float diss=smoothstep(.5,1.,age);\n if(n<diss*1.08-.04)discard;\n float lam=max(dot(N,uLight),0.);\n float band=lam>.55?1.:lam>.15?.68:.42;\n // 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)\n float dark=1.-smoothstep(.02,.12,dot(vC,vec3(.2126,.7152,.0722)));\n vec3 alb=max(vC,vec3(.055)*dark);\n vec3 col=alb*(vec3(.5,.56,.7)*band*1.05+vec3(.2,.19,.18)+uGround*(.4-.4*N.y));\n float rim=pow(1.-clamp(abs(dot(N,normalize(cameraPosition-vWP))),0.,1.),2.);\n col+=dark*rim*(uSky*.9+alb);\n vec3 tg=uGlowPos-vWP;float dg=length(tg)+.001;\n float gi=uGlowI/(1.+dg*dg*.05)*(.3+.7*max(dot(N,tg/dg),0.));\n col+=uGlowCol*gi*alb*1.6;\n float h=heat*(.72+.56*n)+heat*(-N.y)*.18;\n if(h>.05){\n float hq=floor(h*5.+.5)/5.;\n vec3 fc=ramp(clamp(hq,0.,1.2))*(1.1+3.1*hq);\n col=mix(col,fc,smoothstep(.04,.2,h));\n }\n if(kind>2.5&&kind<3.5){col+=vec3(.02,.025,.03);}\n gl_FragColor=vec4(col,1.);\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n}";
178
+ declare const PUFF_VERTEX: string;
179
+ declare const PUFF_FRAGMENT = "\nfloat h3(vec3 p){p=fract(p*.3183099+.1);p*=17.0;return fract(p.x*p.y*p.z*(p.x+p.y+p.z));}\nfloat vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);\n return mix(mix(mix(h3(i),h3(i+vec3(1,0,0)),f.x),mix(h3(i+vec3(0,1,0)),h3(i+vec3(1,1,0)),f.x),f.y),\n mix(mix(h3(i+vec3(0,0,1)),h3(i+vec3(1,0,1)),f.x),mix(h3(i+vec3(0,1,1)),h3(i+vec3(1,1,1)),f.x),f.y),f.z);}\n\nuniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;\nvarying vec4 vK;varying vec4 vK2;varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;\nvec3 L(vec3 c){return pow(c,vec3(2.2));}\nvec3 ramp(float h){\n 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));\n if(h<.25)return mix(c0,c1,h/.25);\n if(h<.5)return mix(c1,c2,(h-.25)/.25);\n if(h<.8)return mix(c2,c3,(h-.5)/.3);\n return mix(c3,c4,clamp((h-.8)/.4,0.,1.));\n}\nvoid main(){\n // cut at the face of a wall within reach (Puff.cuts): smoke flattens on the wall, it does not show through on its other side\n if(dot(vWP,vK.xyz)<vK.w||dot(vWP,vK2.xyz)<vK2.w)discard;\n vec3 N=normalize(cross(dFdx(vWP),dFdy(vWP)));\n float age=vD.x,heat=vD.y,kind=vD.w;\n float n=vn(vL*2.4+vD.z*13.0);\n float diss=smoothstep(.5,1.,age);\n if(n<diss*1.08-.04)discard;\n float lam=max(dot(N,uLight),0.);\n float band=lam>.55?1.:lam>.15?.68:.42;\n // 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)\n float dark=1.-smoothstep(.02,.12,dot(vC,vec3(.2126,.7152,.0722)));\n vec3 alb=max(vC,vec3(.055)*dark);\n vec3 col=alb*(vec3(.5,.56,.7)*band*1.05+vec3(.2,.19,.18)+uGround*(.4-.4*N.y));\n float rim=pow(1.-clamp(abs(dot(N,normalize(cameraPosition-vWP))),0.,1.),2.);\n col+=dark*rim*(uSky*.9+alb);\n vec3 tg=uGlowPos-vWP;float dg=length(tg)+.001;\n float gi=uGlowI/(1.+dg*dg*.05)*(.3+.7*max(dot(N,tg/dg),0.));\n col+=uGlowCol*gi*alb*1.6;\n float h=heat*(.72+.56*n)+heat*(-N.y)*.18;\n if(h>.05){\n float hq=floor(h*5.+.5)/5.;\n vec3 fc=ramp(clamp(hq,0.,1.2))*(1.1+3.1*hq);\n col=mix(col,fc,smoothstep(.04,.2,h));\n }\n if(kind>2.5&&kind<3.5){col+=vec3(.02,.025,.03);}\n gl_FragColor=vec4(col,1.);\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n}";
180
180
  /**
181
181
  * The soft puff shader (`VfxRendererOptions.puffStyle: 'soft'`), from the Lab's (L130-192): a noise-swollen sphere per puff, the Lab's heat ramp for what still burns. Smoke is soft and seen through: its normal is
182
182
  * the sphere's, roughened by noise (never the flat facets, which read as a grey rock), its light continuous, its edge thins to nothing where the camera grazes it,
183
183
  * and it thins out as it ages instead of being cut away. The hot core of a fireball stays opaque. Soot (a black smoke) keeps a floor of albedo and a rim lit by the
184
184
  * sky, so it reads as a cloud and not as a flat black blob. The r160 colour-space chunk (`encodings_fragment` of r128 is `colorspace_fragment` now).
185
185
  */
186
- declare const SOFT_PUFF_VERTEX = "\nfloat h3(vec3 p){p=fract(p*.3183099+.1);p*=17.0;return fract(p.x*p.y*p.z*(p.x+p.y+p.z));}\nfloat vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);\n return mix(mix(mix(h3(i),h3(i+vec3(1,0,0)),f.x),mix(h3(i+vec3(0,1,0)),h3(i+vec3(1,1,0)),f.x),f.y),\n mix(mix(h3(i+vec3(0,0,1)),h3(i+vec3(1,0,1)),f.x),mix(h3(i+vec3(0,1,1)),h3(i+vec3(1,1,1)),f.x),f.y),f.z);}\n\nattribute vec4 aP;attribute vec4 aD;attribute vec3 aC;\nvarying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;\nvoid main(){\n vec3 p=position;\n vec3 q=normalize(position);\n float s=aD.z;\n float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));\n p*=0.78+0.5*n;\n float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;q.xz=mat2(c,-si,si,c)*q.xz;\n vL=p;vN=q;\n vec3 wp=aP.xyz+p*aP.w;\n vWP=wp;vD=aD;vC=aC;\n gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);\n}";
187
- declare const SOFT_PUFF_FRAGMENT = "\nfloat h3(vec3 p){p=fract(p*.3183099+.1);p*=17.0;return fract(p.x*p.y*p.z*(p.x+p.y+p.z));}\nfloat vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);\n return mix(mix(mix(h3(i),h3(i+vec3(1,0,0)),f.x),mix(h3(i+vec3(0,1,0)),h3(i+vec3(1,1,0)),f.x),f.y),\n mix(mix(h3(i+vec3(0,0,1)),h3(i+vec3(1,0,1)),f.x),mix(h3(i+vec3(0,1,1)),h3(i+vec3(1,1,1)),f.x),f.y),f.z);}\n\nuniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;\nvarying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;\nvec3 L(vec3 c){return pow(c,vec3(2.2));}\nvec3 ramp(float h){\n 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));\n if(h<.25)return mix(c0,c1,h/.25);\n if(h<.5)return mix(c1,c2,(h-.25)/.25);\n if(h<.8)return mix(c2,c3,(h-.5)/.3);\n return mix(c3,c4,clamp((h-.8)/.4,0.,1.));\n}\nvoid main(){\n float age=vD.x,heat=vD.y,kind=vD.w;\n float n=vn(vL*2.4+vD.z*13.0);\n // the sphere's own normal, roughened by the noise: a billowing cloud, never facets\n vec3 g=vec3(vn(vL*3.1+vD.z*5.0),vn(vL*3.1+vD.z*5.0+7.3),vn(vL*3.1+vD.z*5.0+13.7))-.5;\n vec3 N=normalize(normalize(vN)+g*.9);\n vec3 V=normalize(cameraPosition-vWP);\n float lam=max(dot(N,uLight),0.);\n float light=.42+.62*smoothstep(-.1,.9,lam);\n float dark=1.-smoothstep(.02,.12,dot(vC,vec3(.2126,.7152,.0722)));\n vec3 alb=max(vC,vec3(.055)*dark);\n vec3 col=alb*(vec3(.5,.56,.7)*light*1.05+vec3(.2,.19,.18)+uGround*(.4-.4*N.y));\n float rim=pow(1.-clamp(abs(dot(normalize(vN),V)),0.,1.),2.);\n col+=dark*rim*(uSky*.9+alb);\n vec3 tg=uGlowPos-vWP;float dg=length(tg)+.001;\n float gi=uGlowI/(1.+dg*dg*.05)*(.3+.7*max(dot(N,tg/dg),0.));\n col+=uGlowCol*gi*alb*1.6;\n // seen through: thin where the camera grazes the puff, thicker where the noise is, thinning out with age\n float facing=abs(dot(normalize(vN),V));\n float alpha=smoothstep(.0,.75,facing)*(.35+.65*smoothstep(.2,.8,n))*(1.-smoothstep(.3,1.,age))*.78;\n float h=heat*(.72+.56*n)+heat*(-N.y)*.18;\n if(h>.05){\n vec3 fc=ramp(clamp(h,0.,1.2))*(1.1+3.1*h);\n float hot=smoothstep(.04,.2,h);\n col=mix(col,fc,hot);\n alpha=max(alpha,hot*smoothstep(.0,.45,facing)*(1.-smoothstep(.5,1.,age)));\n }\n if(kind>2.5&&kind<3.5){col+=vec3(.02,.025,.03);}\n if(alpha<.01)discard;\n gl_FragColor=vec4(col,alpha);\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n}";
186
+ declare const SOFT_PUFF_VERTEX: string;
187
+ declare const SOFT_PUFF_FRAGMENT = "\nfloat h3(vec3 p){p=fract(p*.3183099+.1);p*=17.0;return fract(p.x*p.y*p.z*(p.x+p.y+p.z));}\nfloat vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);\n return mix(mix(mix(h3(i),h3(i+vec3(1,0,0)),f.x),mix(h3(i+vec3(0,1,0)),h3(i+vec3(1,1,0)),f.x),f.y),\n mix(mix(h3(i+vec3(0,0,1)),h3(i+vec3(1,0,1)),f.x),mix(h3(i+vec3(0,1,1)),h3(i+vec3(1,1,1)),f.x),f.y),f.z);}\n\nuniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;\nvarying vec4 vK;varying vec4 vK2;varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;\nvec3 L(vec3 c){return pow(c,vec3(2.2));}\nvec3 ramp(float h){\n 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));\n if(h<.25)return mix(c0,c1,h/.25);\n if(h<.5)return mix(c1,c2,(h-.25)/.25);\n if(h<.8)return mix(c2,c3,(h-.5)/.3);\n return mix(c3,c4,clamp((h-.8)/.4,0.,1.));\n}\nvoid main(){\n // cut at the face of a wall within reach (Puff.cuts): smoke flattens on the wall, it does not show through on its other side\n if(dot(vWP,vK.xyz)<vK.w||dot(vWP,vK2.xyz)<vK2.w)discard;\n float age=vD.x,heat=vD.y,kind=vD.w;\n float n=vn(vL*2.4+vD.z*13.0);\n // the sphere's own normal, roughened by the noise: a billowing cloud, never facets\n vec3 g=vec3(vn(vL*3.1+vD.z*5.0),vn(vL*3.1+vD.z*5.0+7.3),vn(vL*3.1+vD.z*5.0+13.7))-.5;\n vec3 N=normalize(normalize(vN)+g*.9);\n vec3 V=normalize(cameraPosition-vWP);\n float lam=max(dot(N,uLight),0.);\n float light=.42+.62*smoothstep(-.1,.9,lam);\n float dark=1.-smoothstep(.02,.12,dot(vC,vec3(.2126,.7152,.0722)));\n vec3 alb=max(vC,vec3(.055)*dark);\n vec3 col=alb*(vec3(.5,.56,.7)*light*1.05+vec3(.2,.19,.18)+uGround*(.4-.4*N.y));\n float rim=pow(1.-clamp(abs(dot(normalize(vN),V)),0.,1.),2.);\n col+=dark*rim*(uSky*.9+alb);\n vec3 tg=uGlowPos-vWP;float dg=length(tg)+.001;\n float gi=uGlowI/(1.+dg*dg*.05)*(.3+.7*max(dot(N,tg/dg),0.));\n col+=uGlowCol*gi*alb*1.6;\n // seen through: thin where the camera grazes the puff, thicker where the noise is, thinning out with age\n float facing=abs(dot(normalize(vN),V));\n float alpha=smoothstep(.0,.75,facing)*(.35+.65*smoothstep(.2,.8,n))*(1.-smoothstep(.3,1.,age))*.78;\n float h=heat*(.72+.56*n)+heat*(-N.y)*.18;\n if(h>.05){\n vec3 fc=ramp(clamp(h,0.,1.2))*(1.1+3.1*h);\n float hot=smoothstep(.04,.2,h);\n col=mix(col,fc,hot);\n alpha=max(alpha,hot*smoothstep(.0,.45,facing)*(1.-smoothstep(.5,1.,age)));\n }\n if(kind>2.5&&kind<3.5){col+=vec3(.02,.025,.03);}\n if(alpha<.01)discard;\n gl_FragColor=vec4(col,alpha);\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n}";
188
188
 
189
189
  /** The streak shader of shrapnel, sparks and embers (Lab L255-275), verbatim except for the r160 colour-space chunk. */
190
190
  declare const SPARK_VERTEX = "\nattribute vec3 aPos;attribute vec3 aVel;attribute vec4 aE;varying vec2 vU;varying vec4 vE;\nvoid main(){\n float sp=length(aVel)+1e-4;vec3 d=aVel/sp;\n vec3 tc=normalize(cameraPosition-aPos);\n vec3 sd=normalize(cross(d,tc)+vec3(1e-5));\n float len=max(aE.y*2.5,min(sp*aE.z,2.2));\n vec3 wp=aPos+sd*position.x*aE.y-d*position.y*len;\n vU=position.xy;vE=aE;\n gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.);\n}";