@threepipe/webgi-plugins 0.8.0 → 0.9.0-r172.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/CHANGELOG.md +29 -0
- package/LICENSE +190 -141
- package/README.md +2 -17
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/index.js +184 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +185 -43
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/buffer/VelocityBufferPlugin.d.ts +23 -0
- package/dist/plugins/buffer/VelocityBufferPlugin.d.ts.map +1 -1
- package/dist/plugins/extras/AnisotropyPlugin.d.ts +1 -1
- package/dist/plugins/extras/AnisotropyPlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/OutlinePlugin.d.ts +3 -0
- package/dist/plugins/postprocessing/OutlinePlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/TemporalAAPlugin.d.ts +14 -0
- package/dist/plugins/postprocessing/TemporalAAPlugin.d.ts.map +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/AdvancedGroundPlugin.html +64 -64
- package/docs/classes/AnisotropyPlugin.html +32 -32
- package/docs/classes/BloomPlugin.html +36 -36
- package/docs/classes/BloomPluginPass.html +28 -28
- package/docs/classes/DepthOfFieldPlugin.html +40 -40
- package/docs/classes/DepthOfFieldPluginPass.html +31 -31
- package/docs/classes/OutlinePlugin.html +64 -64
- package/docs/classes/OutlineRenderPass.html +18 -18
- package/docs/classes/SSContactShadowsPlugin.html +35 -35
- package/docs/classes/SSGIPlugin.html +40 -40
- package/docs/classes/SSGIPluginPass.html +38 -38
- package/docs/classes/SSReflectionPlugin.html +41 -41
- package/docs/classes/SSReflectionPluginPass.html +39 -39
- package/docs/classes/SSVelocityMaterial.html +22 -7
- package/docs/classes/TemporalAAPlugin.html +34 -34
- package/docs/classes/TemporalAAPluginPass.html +68 -28
- package/docs/classes/VelocityBufferPlugin.html +62 -42
- package/docs/classes/WatchHandsPlugin.html +39 -39
- package/docs/types/OutlinePluginPass.html +1 -1
- package/docs/types/OutlinePluginTarget.html +1 -1
- package/docs/types/SSGIPluginTarget.html +1 -1
- package/docs/types/SSReflectionPluginTarget.html +1 -1
- package/docs/types/VelocityBufferPluginPass.html +1 -1
- package/docs/types/VelocityBufferPluginTarget.html +1 -1
- package/docs/variables/anisotropyGLTFExtension.html +3 -3
- package/docs/variables/webgiPlugins.html +1 -1
- package/package.json +6 -3
- package/src/plugins/buffer/VelocityBufferPlugin.ts +119 -8
- package/src/plugins/buffer/shaders/VelocityBufferPlugin.mat.frag.glsl +9 -1
- package/src/plugins/buffer/shaders/VelocityBufferPlugin.mat.vert.glsl +14 -1
- package/src/plugins/extras/AnisotropyPlugin.ts +2 -2
- package/src/plugins/postprocessing/OutlinePlugin.ts +53 -38
- package/src/plugins/postprocessing/SSContactShadowsPlugin.ts +1 -1
- package/src/plugins/postprocessing/TemporalAAPlugin.ts +42 -0
- package/src/utils/shaders/temporalaa.glsl +9 -0
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* @threepipe/webgi-plugins v0.
|
|
3
|
+
* @threepipe/webgi-plugins v0.9.0-r172.1
|
|
4
4
|
* Copyright 2023-2026 repalash <palash@shaders.app> (https://repalash.com)
|
|
5
|
-
*
|
|
5
|
+
* Apache-2.0 License
|
|
6
6
|
* See ./dependencies.txt for any bundled third-party dependencies and licenses.
|
|
7
7
|
*/
|
|
8
|
-
import { AScreenPassExtensionPlugin, AViewerPluginSync, AdditiveBlending, BaseGroundPlugin, BasicShadowMap, Color, CopyShader, DirectionalLight2, DoubleSide, ExtendedShaderMaterial, ExtendedShaderPass, FrameFadePlugin, GBufferPlugin, GBufferRenderPass, HalfFloatType, Layers, LinearFilter, LinearMipmapLinearFilter, LinearSRGBColorSpace, MathUtils, Matrix3, Matrix4, Mesh2, NearestFilter, NoBlending, NoColorSpace, PCFShadowMap, PCFSoftShadowMap, PerspectiveCamera, PickingPlugin, PipelinePassPlugin, Plane, ProgressivePlugin, RGBAFormat, RenderManager, RenderPass, SRGBColorSpace, SSAAPlugin, Serialization, ShaderMaterial, ShaderMaterial2, ShadowMaterial, SimpleEventDispatcher, ThreeSerialization, UnsignedByteType, VSMShadowMap, Vector2, Vector3, Vector4, animateTarget, bindToValue, copyObject3DUserData, generateUiConfig, getOrCall, getTexelDecoding, glsl, makeSamplerUi, matDefine, matDefineBool, now, onChange, onChange2, serialize, shaderReplaceString, shaderUtils, uiButton, uiColor, uiConfig, uiConfigMaterialExtension, uiDropdown, uiFolderContainer, uiImage, uiInput, uiSlider, uiToggle, uiVector, uniform, updateBit, updateMaterialDefines } from "threepipe";
|
|
8
|
+
import { AScreenPassExtensionPlugin, AViewerPluginSync, AdditiveBlending, BaseGroundPlugin, BasicShadowMap, Color, CopyShader, DataTexture, DirectionalLight2, DoubleSide, ExtendedShaderMaterial, ExtendedShaderPass, FloatType, FrameFadePlugin, GBufferPlugin, GBufferRenderPass, HalfFloatType, Layers, LinearFilter, LinearMipmapLinearFilter, LinearSRGBColorSpace, MathUtils, Matrix3, Matrix4, Mesh2, NearestFilter, NoBlending, NoColorSpace, PCFShadowMap, PCFSoftShadowMap, PerspectiveCamera, PickingPlugin, PipelinePassPlugin, Plane, ProgressivePlugin, RGBAFormat, RenderManager, RenderPass, SRGBColorSpace, SSAAPlugin, Serialization, ShaderMaterial, ShaderMaterial2, ShadowMaterial, SimpleEventDispatcher, ThreeSerialization, UnsignedByteType, VSMShadowMap, Vector2, Vector3, Vector4, animateTarget, bindToValue, copyObject3DUserData, generateUiConfig, getOrCall, getTexelDecoding, glsl, makeSamplerUi, matDefine, matDefineBool, now, onChange, onChange2, serialize, shaderReplaceString, shaderUtils, uiButton, uiColor, uiConfig, uiConfigMaterialExtension, uiDropdown, uiFolderContainer, uiImage, uiInput, uiSlider, uiToggle, uiVector, uniform, updateBit, updateMaterialDefines } from "threepipe";
|
|
9
9
|
// src/plugins/buffer/shaders/VelocityBufferPlugin.unpack.glsl
|
|
10
10
|
var VelocityBufferPlugin_unpack_default = "#if defined(HAS_VELOCITY_BUFFER)\nuniform sampler2D tVelocity;vec2 getVelocity(const in vec2 uv){vec2 screenSpaceVelocity=texture2D(tVelocity,uv).xy*2.0-1.0;return sign(screenSpaceVelocity)*pow(abs(screenSpaceVelocity),vec2(4.));}\n#endif\n";
|
|
11
11
|
// src/plugins/buffer/shaders/VelocityBufferPlugin.mat.vert.glsl
|
|
12
|
-
var VelocityBufferPlugin_mat_vert_default = "#ifdef USE_ALPHAMAP\n#define USE_UV\n#endif\n#include <uv_pars_vertex>\n#include <batching_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 modelMatrixPrevious;
|
|
12
|
+
var VelocityBufferPlugin_mat_vert_default = "#ifdef USE_ALPHAMAP\n#define USE_UV\n#endif\n#include <uv_pars_vertex>\n#include <batching_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 modelMatrixPrevious;\n#ifdef USE_INSTANCING\nuniform sampler2D instanceMatrixPrevious;uniform bool hasInstanceMatrixPrevious;mat4 getInstanceMatrixPrevious(){int x=(gl_InstanceID % 1024)*4,y=gl_InstanceID/1024;return mat4(texelFetch(instanceMatrixPrevious,ivec2(x,y),0),texelFetch(instanceMatrixPrevious,ivec2(x+1,y),0),texelFetch(instanceMatrixPrevious,ivec2(x+2,y),0),texelFetch(instanceMatrixPrevious,ivec2(x+3,y),0));}\n#endif\nvoid main(){\n#include <uv_vertex>\n#include <batching_vertex>\n#include <skinbase_vertex>\n#include <begin_vertex>\n#include <morphtarget_vertex>\n#include <skinning_vertex>\n#include <displacementmap_vertex>\nvec4 mvPosition=vec4(transformed,1.0);vec4 previousPosition=mvPosition;\n#ifdef USE_INSTANCING\npreviousPosition=hasInstanceMatrixPrevious ? getInstanceMatrixPrevious()*mvPosition : instanceMatrix*mvPosition;mvPosition=instanceMatrix*mvPosition;\n#endif\nvWorldPosition=(modelMatrix*mvPosition).xyz;vWorldPositionPrevious=(modelMatrixPrevious*previousPosition).xyz;mvPosition=modelViewMatrix*mvPosition;gl_Position=projectionMatrix*mvPosition;\n#include <logdepthbuf_vertex>\n#include <clipping_planes_vertex>\n}";
|
|
13
13
|
// src/plugins/buffer/shaders/VelocityBufferPlugin.mat.frag.glsl
|
|
14
|
-
var VelocityBufferPlugin_mat_frag_default = "#ifdef USE_ALPHAMAP\n#define USE_UV\n#include <packing>\nuniform sampler2D alphaMap;uniform float alphaTest;\n#endif\n#include <uv_pars_fragment>\nvarying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 currentProjectionViewMatrix;uniform mat4 lastProjectionViewMatrix
|
|
14
|
+
var VelocityBufferPlugin_mat_frag_default = "#ifdef USE_ALPHAMAP\n#define USE_UV\n#include <packing>\nuniform sampler2D alphaMap;uniform float alphaTest;\n#endif\n#include <uv_pars_fragment>\nvarying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 currentProjectionViewMatrix;uniform mat4 lastProjectionViewMatrix;\n#ifdef VELOCITY_SPLIT\nuniform float velocitySplitX;\n#endif\nvec2 computeScreenSpaceVelocity2(){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(vWorldPosition,1.0);vec3 previousWorld=vWorldPositionPrevious;\n#ifdef VELOCITY_SPLIT\nif(currentPositionClip.x/currentPositionClip.w*0.5+0.5<velocitySplitX)previousWorld=vWorldPosition;\n#endif\nvec4 prevPositionClip=lastProjectionViewMatrix*vec4(previousWorld,1.0);vec2 currentPositionNDC=currentPositionClip.xy/currentPositionClip.w;vec2 prevPositionNDC=prevPositionClip.xy/prevPositionClip.w;if(prevPositionNDC.x>=1.0||prevPositionNDC.x<=-1.0||prevPositionNDC.x>=1.0||prevPositionNDC.y<=-1.0){return vec2(0.0);}return 0.5*(currentPositionNDC-prevPositionNDC);}void main(){\n#ifdef USE_ALPHAMAP\nfloat alphaMapValue=\n#ifdef ALPHA_I_RGBA_PACKING\n1.-unpackRGBAToDepth(texture2D(alphaMap,vAlphaMapUv));\n#else\ntexture2D(alphaMap,vAlphaMapUv).g;\n#endif\nif(alphaMapValue<alphaTest)discard;\n#endif\nvec2 velocity=clamp(computeScreenSpaceVelocity2(),-1.0,1.0);velocity=sign(velocity)*pow(abs(velocity),vec2(1./4.));velocity=velocity*0.5+0.5;gl_FragColor=vec4(velocity.x,velocity.y,1.,1.);}";
|
|
15
15
|
// src/utils/shaders.ts
|
|
16
16
|
var shadersUtils2 = {
|
|
17
17
|
computeScreenSpaceVelocity: "uniform mat4 lastProjectionViewMatrix;uniform mat4 currentProjectionViewMatrix;vec2 computeScreenSpaceVelocity(const in vec3 worldPosition){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(worldPosition,1.0);vec4 prevPositionClip=lastProjectionViewMatrix*vec4(worldPosition,1.0);vec2 currentPositionNDC=currentPositionClip.xy/currentPositionClip.w;vec2 prevPositionNDC=prevPositionClip.xy/prevPositionClip.w;if(prevPositionNDC.x>=1.0||prevPositionNDC.x<=-1.0||prevPositionNDC.x>=1.0||prevPositionNDC.y<=-1.0){return vec2(0.0);}return 0.5*(currentPositionNDC-prevPositionNDC);}",
|
|
18
18
|
getWorldPositionFromViewZ: "uniform mat4 inverseViewMatrix;vec3 getWorldPositionFromViewZ(const in vec2 uv,const in float viewDepth){vec2 uv_=2.*uv-1.;float xe=-(uv_.x+projection[2][0])*viewDepth/projection[0][0];float ye=-(uv_.y+projection[2][1])*viewDepth/projection[1][1];return(inverseViewMatrix*vec4(xe,ye,viewDepth,1.)).xyz;}",
|
|
19
|
-
temporalAA: "#include <common>\n#include <gbuffer_unpack>\n#ifdef HAS_VELOCITY_BUFFER\n#pragma <velocity_unpack>\n#else\n#define HAS_VELOCITY_BUFFER 0\n#endif\n#include <cameraHelpers>\nvarying vec2 vUv;uniform vec2 previousRTSize;uniform vec2 jitterSample;uniform vec2 feedBack;uniform bool firstFrame
|
|
19
|
+
temporalAA: "#include <common>\n#include <gbuffer_unpack>\n#ifdef HAS_VELOCITY_BUFFER\n#pragma <velocity_unpack>\n#else\n#define HAS_VELOCITY_BUFFER 0\n#endif\n#include <cameraHelpers>\nvarying vec2 vUv;uniform vec2 previousRTSize;uniform vec2 jitterSample;uniform vec2 feedBack;uniform bool firstFrame;\n#ifdef TAA_SPLIT\nuniform float taaSplitX;\n#endif\nvec3 find_closest_fragment_3x3(const in vec2 uv){const vec3 offset=vec3(-1.0,1.0,0.0);vec2 texelSize=1.0/previousRTSize;vec3 dtr=vec3(1,1,getDepth(uv+offset.yy*texelSize));vec3 dtc=vec3(0,1,getDepth(uv+offset.zy*texelSize));vec3 dtl=vec3(-1,1,getDepth(uv+offset.xy*texelSize));vec3 dml=vec3(-1,0,getDepth(uv+offset.xz*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dmr=vec3(1,0,getDepth(uv+offset.yz*texelSize));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.xx*texelSize));vec3 dbc=vec3(0,-1,getDepth(uv+offset.zx*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.yx*texelSize));vec3 dmin=dtl;if(dmin.z>dtc.z)dmin=dtc;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dml.z)dmin=dml;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dmr.z)dmin=dmr;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbc.z)dmin=dbc;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+texelSize.xy*dmin.xy,dmin.z);}vec3 find_closest_fragment_5tap(const in vec2 uv){vec2 texelSize=1.0/previousRTSize;vec2 offset=vec2(1.0,-1.0);vec3 dtl=vec3(-1,1,getDepth(uv+offset.yx*texelSize));vec3 dtr=vec3(1,1,getDepth(uv+offset.xx*texelSize));vec3 dmc=vec3(0,0,getDepth(uv));vec3 dbl=vec3(-1,-1,getDepth(uv+offset.yy*texelSize));vec3 dbr=vec3(1,-1,getDepth(uv+offset.xy*texelSize));vec3 dmin=dtl;if(dmin.z>dtr.z)dmin=dtr;if(dmin.z>dmc.z)dmin=dmc;if(dmin.z>dbl.z)dmin=dbl;if(dmin.z>dbr.z)dmin=dbr;return vec3(uv+dmin.xy*texelSize,dmin.z);}vec4 clip_aabb(const in vec4 aabb_min,const in vec4 aabb_max,vec4 p){const float FLT_EPS=1e-8;vec4 p_clip=0.5*(aabb_max+aabb_min);vec4 e_clip=0.5*(aabb_max-aabb_min)+FLT_EPS;vec4 v_clip=p-p_clip;vec4 v_unit=abs(v_clip/e_clip);float ma_unit=max(v_unit.x,max(v_unit.y,v_unit.z));if(ma_unit>1.0)return p_clip+v_clip/ma_unit;else return p;}\n#if HAS_VELOCITY_BUFFER == 0 || defined(DEBUG_VELOCITY)\n#include <computeScreenSpaceVelocity>\n#include <getWorldPositionFromViewZ>\n#endif\nvec4 currentRTTexelToLinear1(vec4 a){if(isinf(a.x)||isinf(a.y)||isinf(a.z)||isinf(a.w)){return vec4(1.);}return currentRTTexelToLinear(a);}vec4 computeTAA(const in vec2 uv,const in vec2 screenSpaceVelocity,const in float feedbackScale){vec2 uvUnJitter=uv;vec4 currentColor=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter));vec4 previousColor=previousRTTexelToLinear(texture2D(previousRT,uv-screenSpaceVelocity));const vec3 offset=vec3(1.,-1.,0.);vec2 texelSize=1./previousRTSize;float texelSpeed=length(screenSpaceVelocity);vec4 tl=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.yx*texelSize));vec4 tc=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.zx*texelSize));vec4 tr=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.xx*texelSize));vec4 ml=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.yz*texelSize));vec4 mc=currentColor;vec4 mr=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.xz*texelSize));vec4 bl=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.yy*texelSize));vec4 bc=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.zy*texelSize));vec4 br=currentRTTexelToLinear1(texture2D(currentRT,uvUnJitter+offset.xy*texelSize));mc=max(vec4(0.0),mc+0.2718*(4.0*mc-(tl+tr+bl+br)));vec4 min5=min(tc,min(ml,min(mc,min(mr,bc))));vec4 max5=max(tc,max(ml,max(mc,max(mr,bc))));vec4 cmin=min(min5,min(tl,min(tr,min(bl,br))));vec4 cmax=max(min5,max(tl,max(tr,max(bl,br))));;cmin=0.5*(cmin+min5);cmax=0.5*(cmax+max5);\n#ifndef TAA_NO_CLAMP\npreviousColor=clip_aabb(cmin,cmax,previousColor);\n#endif\nfloat lum0=luminance(currentColor.rgb);float lum1=luminance(previousColor.rgb);float unbiased_diff=abs(lum0-lum1)/max(lum0,max(lum1,0.2));float unbiased_weight=1.0-unbiased_diff;float unbiased_weight_sqr=unbiased_weight*unbiased_weight;float k_feedback=mix(feedBack.x,feedBack.y,unbiased_weight_sqr);return mix(currentColor,previousColor,clamp(k_feedback*feedbackScale,0.,1.));}void main(){\n#if HAS_VELOCITY_BUFFER == 0\n#if QUALITY == 1\nvec3 c_frag=find_closest_fragment_3x3(vUv);\n#else\nvec3 c_frag=find_closest_fragment_5tap(vUv);\n#endif\n#else\nvec3 c_frag=vec3(vUv,0.);\n#endif\nbool bg=firstFrame;\n#ifdef TAA_SPLIT\nbg=bg||vUv.x<taaSplitX;\n#endif\n#if BACKGROUND_TAA\nfloat d=c_frag.z;float edgef=min(1.,max(0.,1.-(d*100.-99.)));\n#else\nbg=bg||c_frag.z>0.999;\n#endif\nif(bg){gl_FragColor=currentRTTexelToLinear1(texture2D(currentRT,vUv));}else{\n#if HAS_VELOCITY_BUFFER == 0\nfloat sampleViewZ=mix(-cameraNearFar.x,-cameraNearFar.y,c_frag.z);vec3 worldPosition=getWorldPositionFromViewZ(c_frag.xy,sampleViewZ);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);\n#else\nvec2 screenSpaceVelocity=getVelocity(c_frag.xy);\n#endif\n#if BACKGROUND_TAA\ngl_FragColor=computeTAA(vUv,screenSpaceVelocity*edgef,edgef);\n#else\ngl_FragColor=computeTAA(vUv,screenSpaceVelocity,1.);\n#endif\n}\n#include <colorspace_fragment>\n#ifdef DEBUG_VELOCITY\nfloat sampleViewZ=mix(-cameraNearFar.x,-cameraNearFar.y,c_frag.z);vec3 worldPosition=getWorldPositionFromViewZ(c_frag.xy,sampleViewZ);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);gl_FragColor=vec4(10.*length(screenSpaceVelocity),0.,0.,1.);\n#endif\n}",
|
|
20
20
|
ssReflection: "uniform float currentFrameCount;\n#ifndef D_frameCount\n#define D_frameCount\nuniform float frameCount;\n#endif\nuniform float objectRadius;uniform float radius;uniform float tolerance;uniform float ssrRoughnessFactor;uniform bool autoRadius;\n#ifndef D_sceneBoundingRadius\n#define D_sceneBoundingRadius\nuniform float sceneBoundingRadius;\n#endif\n#if SSREFL_ENABLED == 2\nuniform float ssrSplitX;\n#endif\n#ifdef HAS_VELOCITY_BUFFER\n#pragma <velocity_unpack>\n#else\n#define HAS_VELOCITY_BUFFER 0\n#endif\n#if HAS_VELOCITY_BUFFER == 0\n#include <computeScreenSpaceVelocity>\n#include <getWorldPositionFromViewZ>\n#endif\nvec3 ComputeReflectionL(vec3 N,vec2 E,vec3 V,float rough){float rough4=rough*rough*rough*rough;float phi=2.0*PI*E.x;float cos_theta=pow(max(E.y,0.000001),rough4/(2.0-rough4));float sin_theta=sqrt(max(0.,1.0-cos_theta*cos_theta));vec3 half_vec=vec3(sin_theta*cos(phi),sin_theta*sin(phi),cos_theta);vec3 tangentX=normalize(cross(abs(N.z)<0.999 ? vec3(0.0,0.0,1.0): vec3(1.0,0.0,0.0),N));vec3 tangentY=cross(N,tangentX);half_vec=half_vec.x*tangentX+half_vec.y*tangentY+half_vec.z*N;vec3 ray_dir=(2.0*dot(V,half_vec))*half_vec-V;return ray_dir;}vec2 GetRandomE(float seed){vec2 rand_e;rand_e.x=interleavedGradientNoise(gl_FragCoord.xy,frameCount*34.+seed);rand_e.y=fract(rand_e.x*38.65435);rand_e.y=mix(rand_e.y,1.0,0.7);return rand_e;}vec4 calculateSSR(in float seed,in vec3 screenPos,in vec3 normal,in float radiusFactor,in float roughness){vec3 viewPos=screenToView3(screenPos.xy,screenPos.z);normal=normalize(normal);vec2 E=GetRandomE(seed);vec3 L=ComputeReflectionL(normal,E,-normalize(viewPos),roughness*ssrRoughnessFactor);L=normalize(L);float cameraDist=length(cameraPositionWorld);float rayLen=objectRadius*sceneBoundingRadius;rayLen=autoRadius ?min(max(mix(max(0.0,(cameraDist+rayLen)+viewPos.z),max(0.0,-viewPos.z-max(0.0,cameraDist-rayLen)),L.z*0.5+0.5),rayLen*0.1),rayLen*5.):rayLen;rayLen*=radiusFactor;float r=interleavedGradientNoise(gl_FragCoord.xy,frameCount+seed);rayLen=max(rayLen,0.001);int steps=SSR_STEP_COUNT/(currentFrameCount<float(SSR_LOW_QUALITY_FRAMES)? 2 : 1);vec3 state=vec3(0.,(r+0.5)/float(steps),2.);viewPos+=normal*max(-0.0001*viewPos.z,0.001);vec3 screenHitP=traceRay(viewPos,L*rayLen,tolerance*rayLen,state,steps);if(state.z<0.99){if(currentFrameCount<1.){\n#if HAS_VELOCITY_BUFFER == 0\nvec3 worldPosition=getWorldPositionFromViewZ(screenHitP.xy,screenHitP.z);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);\n#else\nvec2 screenSpaceVelocity=getVelocity(screenHitP.xy);\n#endif\nscreenHitP.xy-=screenSpaceVelocity;}vec3 hitColor=(tLastFrameTexelToLinear(texture2D(tLastFrame,screenHitP.xy))).rgb;float ssrWeight=1.;return vec4(hitColor*ssrWeight,1.);}return vec4(0.);}",
|
|
21
21
|
calculateGI: "uniform float currentFrameCount;uniform float intensity;uniform float objectRadius;uniform float rayCount;uniform float power;uniform float bias;uniform float falloff;uniform float tolerance;uniform bool autoRadius;uniform vec2 screenSize;\n#ifndef D_sceneBoundingRadius\n#define D_sceneBoundingRadius\nuniform float sceneBoundingRadius;\n#endif\n#ifdef HAS_VELOCITY_BUFFER\n#pragma <velocity_unpack>\n#else\n#define HAS_VELOCITY_BUFFER 0\n#endif\n#if HAS_VELOCITY_BUFFER == 0\n#include <computeScreenSpaceVelocity>\n#include <getWorldPositionFromViewZ>\n#endif\nvec3 ComputeUniformL(vec3 N,vec2 E){vec3 L;L.xy=E;L.z=interleavedGradientNoise(gl_FragCoord.xy,currentFrameCount*5.);L=L*2.-1.;return L;}vec2 GetRandomE(float seed){vec2 rand_e;rand_e.x=random3(vec3(gl_FragCoord.xy,currentFrameCount+seed));rand_e.y=random3(vec3(gl_FragCoord.yx,rand_e.x+(currentFrameCount)*7.));return rand_e;}float saturate2(float v,float mx){return max(0.,min(mx,v));}vec4 calculateGI(in float seed,in vec3 screenPos,in vec3 normal,in float radiusFactor){vec3 viewPos=screenToView3(screenPos.xy,screenPos.z);normal=normalize(normal);vec2 E=GetRandomE(seed);vec3 L=ComputeUniformL(normal,E);L=normalize(L);L*=sign(dot(L,normal));float cameraDist=length(cameraPositionWorld);float rayLen=objectRadius*sceneBoundingRadius;rayLen=autoRadius ?min(max(mix(max(0.0,(cameraDist+rayLen)+viewPos.z),max(0.0,-viewPos.z-max(0.0,cameraDist-rayLen)),L.z*0.5+0.5),rayLen*0.1),rayLen*5.):rayLen;rayLen*=radiusFactor;float r=interleavedGradientNoise(gl_FragCoord.xy,currentFrameCount*14.+seed)+0.05;rayLen=max(rayLen,0.001);vec3 state=vec3(1.,(r+0.5)/float(RTAO_STEP_COUNT),2.);viewPos+=normal*max(-0.01*viewPos.z,0.001);vec3 screenHitP=traceRay(viewPos,L*rayLen,tolerance*rayLen,state,RTAO_STEP_COUNT);vec3 viewHitP=screenToView3(screenHitP.xy,screenHitP.z);vec3 LRes=viewHitP-viewPos;if(state.z>1.)LRes=vec3(9999999.);float dist=length(LRes)*falloff;float EPS=0.01;float zBias=(viewPos.z)*bias;float ao=(max(dot(normal,L)+zBias,0.))/(dist*dist+EPS);\n#if defined(SSGI_ENABLED) && SSGI_ENABLED > 0\nif(currentFrameCount<1.){\n#if HAS_VELOCITY_BUFFER == 0\nvec3 worldPosition=getWorldPositionFromViewZ(screenHitP.xy,screenHitP.z);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);\n#else\nvec2 screenSpaceVelocity=getVelocity(screenHitP.xy);\n#endif\nscreenHitP.xy-=screenSpaceVelocity;}vec3 hitColor=tLastFrameTexelToLinear(texture2D(tLastFrame,screenHitP.xy)).rgb;vec3 hitNormal=getViewNormal(screenHitP.xy);float giWeight=1.;giWeight=saturate2(giWeight/(dist+EPS),1.);giWeight*=saturate2((dot(normal,L)),1.0);giWeight*=saturate2((dot(hitNormal,-L)),1.0);return vec4(hitColor*giWeight,ao);\n#endif\nreturn vec4(0,0,0,ao);}float normpdf(in float x,in float sigma){return exp(-0.5*x*x/(sigma*sigma));}vec4 getLastThis(sampler2D tex,float depth,vec3 normal){vec2 direction=vec2(1,1);vec4 color=clamp(tLastThisTexelToLinear(texture2D(tex,vUv.xy)),0.,5.);return color;}void main(){float depth;vec3 normal;getDepthNormal(vUv,depth,normal);if(depth>0.99){discard;gl_FragColor=getLastThis(tLastThis,depth,normal);return;}float viewZ=depthToViewZ(depth);vec3 screenPos=vec3(vUv.x,vUv.y,viewZ);vec4 gi=vec4(0.);gi+=calculateGI(8.,screenPos,normal,1.);if(rayCount>1.5)gi=max(gi,calculateGI(2.,screenPos,normal,0.4));if(rayCount>2.5)gi=max(gi,calculateGI(3.,screenPos,normal,1.5));if(rayCount>3.5)gi=max(gi,calculateGI(1.,screenPos,normal,0.6));if(rayCount>4.5)gi=max(gi,calculateGI(3.,screenPos,normal,1.));gi.a=min(1.,gi.a);gi.a=max(0.,gi.a);gi.rgb=min(vec3(3.),gi.rgb);gi.rgb=max(vec3(0.),gi.rgb);if(currentFrameCount<3.){gl_FragColor=gi;return;}gl_FragColor=(texture2D(tLastThis,vUv));gl_FragColor=((gi+(gl_FragColor)*currentFrameCount)/(currentFrameCount+1.));}",
|
|
22
22
|
["__inited"]: false
|
|
@@ -135,7 +135,8 @@ var TemporalAAPluginPass = class extends ExtendedShaderPass {
|
|
|
135
135
|
projection: { value: new Matrix4() },
|
|
136
136
|
inverseViewMatrix: { value: new Matrix4() },
|
|
137
137
|
jitterSample: { value: new Vector2() },
|
|
138
|
-
firstFrame: { value: true }
|
|
138
|
+
firstFrame: { value: true },
|
|
139
|
+
taaSplitX: { value: 0 }
|
|
139
140
|
},
|
|
140
141
|
defines: {
|
|
141
142
|
["QUALITY"]: 1,
|
|
@@ -149,6 +150,8 @@ var TemporalAAPluginPass = class extends ExtendedShaderPass {
|
|
|
149
150
|
this.taaEnabled = true;
|
|
150
151
|
this.feedBack = new Vector2(.88, .97);
|
|
151
152
|
this.debugVelocity = false;
|
|
153
|
+
this.split = 0;
|
|
154
|
+
this.clamp = true;
|
|
152
155
|
this.uiConfig = {
|
|
153
156
|
type: "folder",
|
|
154
157
|
label: "Temporal AA Pass",
|
|
@@ -190,6 +193,25 @@ var TemporalAAPluginPass = class extends ExtendedShaderPass {
|
|
|
190
193
|
super.setSize(width, height);
|
|
191
194
|
this.onSizeUpdate();
|
|
192
195
|
}
|
|
196
|
+
_clampChanged() {
|
|
197
|
+
const off = !this.clamp;
|
|
198
|
+
if (!!this.material.defines.TAA_NO_CLAMP !== off) {
|
|
199
|
+
if (off) this.material.defines.TAA_NO_CLAMP = 1;
|
|
200
|
+
else delete this.material.defines.TAA_NO_CLAMP;
|
|
201
|
+
this.material.needsUpdate = true;
|
|
202
|
+
}
|
|
203
|
+
this.setDirty();
|
|
204
|
+
}
|
|
205
|
+
_splitChanged() {
|
|
206
|
+
const on = this.split > 0;
|
|
207
|
+
this.uniforms.taaSplitX.value = this.split;
|
|
208
|
+
if (!!this.material.defines.TAA_SPLIT !== on) {
|
|
209
|
+
if (on) this.material.defines.TAA_SPLIT = 1;
|
|
210
|
+
else delete this.material.defines.TAA_SPLIT;
|
|
211
|
+
this.material.needsUpdate = true;
|
|
212
|
+
}
|
|
213
|
+
this.setDirty();
|
|
214
|
+
}
|
|
193
215
|
};
|
|
194
216
|
__decorate([
|
|
195
217
|
serialize(),
|
|
@@ -197,6 +219,16 @@ __decorate([
|
|
|
197
219
|
uiVector("Feedback", void 0, 1e-4)
|
|
198
220
|
], TemporalAAPluginPass.prototype, "feedBack", void 0);
|
|
199
221
|
__decorate([uiToggle(), matDefineBool("DEBUG_VELOCITY", void 0, false, void 0, true)], TemporalAAPluginPass.prototype, "debugVelocity", void 0);
|
|
222
|
+
__decorate([
|
|
223
|
+
uiSlider("Split", [0, 1], .01, { tags: ["debug"] }),
|
|
224
|
+
onChange(TemporalAAPluginPass.prototype._splitChanged),
|
|
225
|
+
serialize()
|
|
226
|
+
], TemporalAAPluginPass.prototype, "split", void 0);
|
|
227
|
+
__decorate([
|
|
228
|
+
uiToggle("Clamp history", { tags: ["debug"] }),
|
|
229
|
+
onChange(TemporalAAPluginPass.prototype._clampChanged),
|
|
230
|
+
serialize()
|
|
231
|
+
], TemporalAAPluginPass.prototype, "clamp", void 0);
|
|
200
232
|
// src/plugins/buffer/VelocityBufferPlugin.ts
|
|
201
233
|
var _VelocityBufferPlugin;
|
|
202
234
|
var VelocityBufferPlugin = class VelocityBufferPlugin extends PipelinePassPlugin {
|
|
@@ -209,6 +241,16 @@ var VelocityBufferPlugin = class VelocityBufferPlugin extends PipelinePassPlugin
|
|
|
209
241
|
static {
|
|
210
242
|
this.OldPluginType = "VelocityBufferPlugin";
|
|
211
243
|
}
|
|
244
|
+
_splitChanged() {
|
|
245
|
+
const m = this.material, on = this.split > 0;
|
|
246
|
+
m.uniforms.velocitySplitX.value = this.split;
|
|
247
|
+
if (!!m.defines.VELOCITY_SPLIT !== on) {
|
|
248
|
+
if (on) m.defines.VELOCITY_SPLIT = 1;
|
|
249
|
+
else delete m.defines.VELOCITY_SPLIT;
|
|
250
|
+
m.needsUpdate = true;
|
|
251
|
+
}
|
|
252
|
+
if (this._viewer) this.setDirty();
|
|
253
|
+
}
|
|
212
254
|
_createTarget(recreate = true) {
|
|
213
255
|
if (!this._viewer) return;
|
|
214
256
|
if (recreate) this._disposeTarget();
|
|
@@ -268,6 +310,7 @@ var VelocityBufferPlugin = class VelocityBufferPlugin extends PipelinePassPlugin
|
|
|
268
310
|
super();
|
|
269
311
|
this.passId = "velocityBuffer";
|
|
270
312
|
this.material = new SSVelocityMaterial();
|
|
313
|
+
this.split = 0;
|
|
271
314
|
this.unpackExtension = {
|
|
272
315
|
shaderExtender: (shader) => {
|
|
273
316
|
if (this.isDisabled()) return;
|
|
@@ -293,6 +336,7 @@ var VelocityBufferPlugin = class VelocityBufferPlugin extends PipelinePassPlugin
|
|
|
293
336
|
}
|
|
294
337
|
onRemove(viewer) {
|
|
295
338
|
this._disposeTarget();
|
|
339
|
+
this.material.dispose();
|
|
296
340
|
return super.onRemove(viewer);
|
|
297
341
|
}
|
|
298
342
|
setDirty() {
|
|
@@ -311,6 +355,11 @@ var VelocityBufferPlugin = class VelocityBufferPlugin extends PipelinePassPlugin
|
|
|
311
355
|
}
|
|
312
356
|
};
|
|
313
357
|
__decorate([uiImage("Velocity Buffer", { readOnly: true })], VelocityBufferPlugin.prototype, "texture", void 0);
|
|
358
|
+
__decorate([
|
|
359
|
+
uiSlider("Split", [0, 1], .01, { tags: ["debug"] }),
|
|
360
|
+
onChange(VelocityBufferPlugin.prototype._splitChanged),
|
|
361
|
+
serialize()
|
|
362
|
+
], VelocityBufferPlugin.prototype, "split", void 0);
|
|
314
363
|
VelocityBufferPlugin = _VelocityBufferPlugin = __decorate([uiFolderContainer("Velocity Buffer Plugin (for TAA)")], VelocityBufferPlugin);
|
|
315
364
|
var SSVelocityMaterial = class extends ShaderMaterial {
|
|
316
365
|
constructor() {
|
|
@@ -323,19 +372,101 @@ var SSVelocityMaterial = class extends ShaderMaterial {
|
|
|
323
372
|
alphaTest: { value: null },
|
|
324
373
|
alphaMapTransform: { value: /* @__PURE__*/ new Matrix3() },
|
|
325
374
|
currentProjectionViewMatrix: { value: new Matrix4() },
|
|
326
|
-
lastProjectionViewMatrix: { value: new Matrix4() }
|
|
375
|
+
lastProjectionViewMatrix: { value: new Matrix4() },
|
|
376
|
+
velocitySplitX: { value: 0 }
|
|
327
377
|
},
|
|
328
378
|
blending: NoBlending
|
|
329
379
|
});
|
|
330
|
-
this.extraUniformsToUpload = {
|
|
380
|
+
this.extraUniformsToUpload = {
|
|
381
|
+
modelMatrixPrevious: { value: new Matrix4().identity() },
|
|
382
|
+
instanceMatrixPrevious: { value: null },
|
|
383
|
+
hasInstanceMatrixPrevious: { value: false }
|
|
384
|
+
};
|
|
331
385
|
this._previousWorldMatrices = {};
|
|
386
|
+
this._previousInstanceMatrices = {};
|
|
387
|
+
this._meshListeners = /* @__PURE__ */ new Map();
|
|
388
|
+
}
|
|
389
|
+
_instancePrevious(object, frame) {
|
|
390
|
+
const capacity = object.instanceMatrix.count;
|
|
391
|
+
let e = this._previousInstanceMatrices[object.uuid];
|
|
392
|
+
if (!e || e.capacity !== capacity) {
|
|
393
|
+
if (e) e.textures.forEach((t) => t.dispose());
|
|
394
|
+
else if (object.addEventListener) {
|
|
395
|
+
const o = object;
|
|
396
|
+
const listener = () => {
|
|
397
|
+
const d = this._previousInstanceMatrices[object.uuid];
|
|
398
|
+
if (d) d.textures.forEach((t) => t.dispose());
|
|
399
|
+
delete this._previousInstanceMatrices[object.uuid];
|
|
400
|
+
delete this._previousWorldMatrices[object.uuid];
|
|
401
|
+
this._meshListeners.delete(object.uuid);
|
|
402
|
+
o.removeEventListener("dispose", listener);
|
|
403
|
+
};
|
|
404
|
+
o.addEventListener("dispose", listener);
|
|
405
|
+
this._meshListeners.set(object.uuid, {
|
|
406
|
+
object: o,
|
|
407
|
+
listener
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
const width = 4 * Math.min(capacity, 1024), height = Math.ceil(capacity / 1024);
|
|
411
|
+
const data = [new Float32Array(width * height * 4), new Float32Array(width * height * 4)];
|
|
412
|
+
const make = (i) => {
|
|
413
|
+
const t = new DataTexture(data[i], width, height, RGBAFormat, FloatType);
|
|
414
|
+
t.minFilter = t.magFilter = NearestFilter;
|
|
415
|
+
t.generateMipmaps = false;
|
|
416
|
+
t.name = "instanceMatrixPrevious";
|
|
417
|
+
return t;
|
|
418
|
+
};
|
|
419
|
+
e = this._previousInstanceMatrices[object.uuid] = {
|
|
420
|
+
textures: [make(0), make(1)],
|
|
421
|
+
data: [data[0], data[1]],
|
|
422
|
+
read: 0,
|
|
423
|
+
valid: false,
|
|
424
|
+
capacity,
|
|
425
|
+
frame: -1,
|
|
426
|
+
readNow: null
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
if (e.frame !== frame) {
|
|
430
|
+
e.frame = frame;
|
|
431
|
+
e.readNow = e.valid ? e.textures[e.read] : null;
|
|
432
|
+
const w = 1 - e.read;
|
|
433
|
+
e.data[w].set(object.instanceMatrix.array);
|
|
434
|
+
e.textures[w].needsUpdate = true;
|
|
435
|
+
e.read = 1 - e.read;
|
|
436
|
+
e.valid = true;
|
|
437
|
+
}
|
|
438
|
+
const u = this.extraUniformsToUpload;
|
|
439
|
+
u.instanceMatrixPrevious.value = e.readNow;
|
|
440
|
+
u.hasInstanceMatrixPrevious.value = !!e.readNow;
|
|
441
|
+
}
|
|
442
|
+
dispose() {
|
|
443
|
+
for (const e of Object.values(this._previousInstanceMatrices)) e.textures.forEach((t) => t.dispose());
|
|
444
|
+
for (const { object, listener } of this._meshListeners.values()) object.removeEventListener("dispose", listener);
|
|
445
|
+
this._meshListeners.clear();
|
|
446
|
+
this._previousInstanceMatrices = {};
|
|
447
|
+
this._previousWorldMatrices = {};
|
|
448
|
+
super.dispose();
|
|
332
449
|
}
|
|
333
450
|
onBeforeRender(_r, _s, _c, _geometry, object, group) {
|
|
334
451
|
super.onBeforeRender(_r, _s, _c, _geometry, object, group);
|
|
335
|
-
const
|
|
336
|
-
this.
|
|
337
|
-
if (
|
|
338
|
-
|
|
452
|
+
const frame = _r.info.render.frame;
|
|
453
|
+
let world = this._previousWorldMatrices[object.uuid];
|
|
454
|
+
if (!world) world = this._previousWorldMatrices[object.uuid] = {
|
|
455
|
+
previous: object.matrixWorld.clone(),
|
|
456
|
+
current: object.matrixWorld.clone(),
|
|
457
|
+
frame
|
|
458
|
+
};
|
|
459
|
+
else if (world.frame !== frame) {
|
|
460
|
+
world.previous.copy(world.current);
|
|
461
|
+
world.current.copy(object.matrixWorld);
|
|
462
|
+
world.frame = frame;
|
|
463
|
+
}
|
|
464
|
+
this.extraUniformsToUpload.modelMatrixPrevious.value.copy(world.previous);
|
|
465
|
+
if (object.isInstancedMesh) this._instancePrevious(object, frame);
|
|
466
|
+
else {
|
|
467
|
+
this.extraUniformsToUpload.instanceMatrixPrevious.value = null;
|
|
468
|
+
this.extraUniformsToUpload.hasInstanceMatrixPrevious.value = false;
|
|
469
|
+
}
|
|
339
470
|
let mat = object.material;
|
|
340
471
|
if (Array.isArray(mat)) mat = mat[0];
|
|
341
472
|
this.uniforms.alphaMap.value = mat?.alphaMap ?? null;
|
|
@@ -1585,6 +1716,31 @@ var OutlinePlugin = class OutlinePlugin extends AScreenPassExtensionPlugin {
|
|
|
1585
1716
|
};
|
|
1586
1717
|
this._shaderPatch = "diffuseColor = outline(diffuseColor);";
|
|
1587
1718
|
this.dependencies = [PickingPlugin, GBufferPlugin];
|
|
1719
|
+
this._onSelectedObjectChanged = () => {
|
|
1720
|
+
if (this._animationCallBack) return;
|
|
1721
|
+
if (this._pickingPlugin?.getSelectedObject()) {
|
|
1722
|
+
if (this.enableDynamicSelection) {
|
|
1723
|
+
this.transparency = 1;
|
|
1724
|
+
this._animationCallBack = this._startTransparencyAnimation(1, this.highlightTransparency, 400);
|
|
1725
|
+
} else this.transparency = this.highlightTransparency;
|
|
1726
|
+
} else this.transparency = 1;
|
|
1727
|
+
};
|
|
1728
|
+
this._onMouseMove = (e) => {
|
|
1729
|
+
if (!this.mouseInOutAnimationEnabled) return;
|
|
1730
|
+
if (!this.enableHighlight) return;
|
|
1731
|
+
const selectedObject = this._pickingPlugin?.getSelectedObject();
|
|
1732
|
+
if (selectedObject && this.enableDynamicSelection) {
|
|
1733
|
+
if (e.target !== this._viewer?.canvas) {
|
|
1734
|
+
if (!this._animationCallBack && this._state === "in") {
|
|
1735
|
+
this._animationCallBack = this._startTransparencyAnimation(this.highlightTransparency, 1, 600);
|
|
1736
|
+
this._state = "out";
|
|
1737
|
+
}
|
|
1738
|
+
} else if (!this._animationCallBack && this._state === "out") {
|
|
1739
|
+
this._animationCallBack = this._startTransparencyAnimation(1, this.highlightTransparency, 600);
|
|
1740
|
+
this._state = "in";
|
|
1741
|
+
}
|
|
1742
|
+
} else this.transparency = selectedObject ? this.highlightTransparency : 1;
|
|
1743
|
+
};
|
|
1588
1744
|
this._pickingWidgetDisabled = false;
|
|
1589
1745
|
this.material = new ShaderMaterial({
|
|
1590
1746
|
uniforms: { "cameraNearFar": { value: new Vector2(.1, 100) } },
|
|
@@ -1619,6 +1775,7 @@ var OutlinePlugin = class OutlinePlugin extends AScreenPassExtensionPlugin {
|
|
|
1619
1775
|
}
|
|
1620
1776
|
setDirty() {
|
|
1621
1777
|
super.setDirty();
|
|
1778
|
+
if (this._pass) this._pass.enabled = !this.isDisabled();
|
|
1622
1779
|
if (!this._viewer) return;
|
|
1623
1780
|
const picking = this._viewer.getPlugin(PickingPlugin);
|
|
1624
1781
|
let enabled = !this.isDisabled();
|
|
@@ -1641,38 +1798,23 @@ var OutlinePlugin = class OutlinePlugin extends AScreenPassExtensionPlugin {
|
|
|
1641
1798
|
super.onAdded(viewer);
|
|
1642
1799
|
this.setDirty();
|
|
1643
1800
|
this._pass = this._createPass();
|
|
1801
|
+
this._pass.enabled = !this.isDisabled();
|
|
1644
1802
|
this._pass.onDirty?.push(viewer.setDirty);
|
|
1645
1803
|
viewer.renderManager.registerPass(this._pass);
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
} else this.transparency = 1;
|
|
1655
|
-
}
|
|
1656
|
-
});
|
|
1657
|
-
document.addEventListener("mousemove", (e) => {
|
|
1658
|
-
if (!this) return;
|
|
1659
|
-
if (!this.mouseInOutAnimationEnabled) return;
|
|
1660
|
-
if (!this.enableHighlight) return;
|
|
1661
|
-
const selectedObject = pickingPlugin?.getSelectedObject();
|
|
1662
|
-
if (selectedObject && this.enableDynamicSelection) {
|
|
1663
|
-
if (e.target !== viewer.canvas) {
|
|
1664
|
-
if (!this._animationCallBack && this._state === "in") {
|
|
1665
|
-
this._animationCallBack = this._startTransparencyAnimation(this.highlightTransparency, 1, 600);
|
|
1666
|
-
this._state = "out";
|
|
1667
|
-
}
|
|
1668
|
-
} else if (!this._animationCallBack && this._state === "out") {
|
|
1669
|
-
this._animationCallBack = this._startTransparencyAnimation(1, this.highlightTransparency, 600);
|
|
1670
|
-
this._state = "in";
|
|
1671
|
-
}
|
|
1672
|
-
} else this.transparency = selectedObject ? this.highlightTransparency : 1;
|
|
1673
|
-
});
|
|
1804
|
+
viewer.forPlugin(PickingPlugin, (p) => {
|
|
1805
|
+
this._pickingPlugin = p;
|
|
1806
|
+
p.addEventListener("selectedObjectChanged", this._onSelectedObjectChanged);
|
|
1807
|
+
}, (p) => {
|
|
1808
|
+
p.removeEventListener("selectedObjectChanged", this._onSelectedObjectChanged);
|
|
1809
|
+
this._pickingPlugin = void 0;
|
|
1810
|
+
}, this);
|
|
1811
|
+
document.addEventListener("mousemove", this._onMouseMove, { passive: true });
|
|
1674
1812
|
}
|
|
1675
1813
|
onRemove(viewer) {
|
|
1814
|
+
document.removeEventListener("mousemove", this._onMouseMove);
|
|
1815
|
+
this._pickingPlugin?.removeEventListener("selectedObjectChanged", this._onSelectedObjectChanged);
|
|
1816
|
+
this._pickingPlugin = void 0;
|
|
1817
|
+
this._animationCallBack = void 0;
|
|
1676
1818
|
this._disposeTarget();
|
|
1677
1819
|
if (this._pass) {
|
|
1678
1820
|
viewer.renderManager.unregisterPass(this._pass);
|
|
@@ -2563,7 +2705,7 @@ var GLTFMaterialsAnisotropyExtensionImport = class {
|
|
|
2563
2705
|
return null;
|
|
2564
2706
|
}
|
|
2565
2707
|
};
|
|
2566
|
-
var glTFMaterialsAnisotropyExtensionExport = (w) => ({
|
|
2708
|
+
var glTFMaterialsAnisotropyExtensionExport = (w) => ({ writeMaterialAsync: async (material, materialDef) => {
|
|
2567
2709
|
if (!material.isMeshStandardMaterial || !material.userData._isAnisotropic) return;
|
|
2568
2710
|
if ((material.userData._anisotropyFactor || 0) < .001) return;
|
|
2569
2711
|
materialDef.extensions = materialDef.extensions || {};
|
|
@@ -2572,7 +2714,7 @@ var glTFMaterialsAnisotropyExtensionExport = (w) => ({ writeMaterial: (material,
|
|
|
2572
2714
|
extensionDef.anisotropyNoiseFactor = material.userData._anisotropyNoise || 0;
|
|
2573
2715
|
extensionDef.anisotropyDirectionMode = material.userData._anisotropyDirectionMode || "CONSTANT";
|
|
2574
2716
|
if (w.checkEmptyMap(material.userData._anisotropyDirectionMap) && extensionDef.anisotropyDirectionMode !== "CONSTANT") {
|
|
2575
|
-
const anisotropyDirectionMapDef = { index: w.
|
|
2717
|
+
const anisotropyDirectionMapDef = { index: await w.processTextureAsync(material.userData._anisotropyDirectionMap) };
|
|
2576
2718
|
w.applyTextureTransform(anisotropyDirectionMapDef, material.userData._anisotropyDirectionMap);
|
|
2577
2719
|
extensionDef.anisotropyDirection = anisotropyDirectionMapDef;
|
|
2578
2720
|
} else {
|