@threepipe/webgi-plugins 0.1.0 → 0.2.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/dist/index.js +10 -225
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1217 -928
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/buffer/VelocityBufferPlugin.d.ts +1 -1
- package/dist/plugins/buffer/VelocityBufferPlugin.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +0 -1
- package/dist/plugins/postprocessing/BloomPlugin.d.ts +2 -2
- package/dist/plugins/postprocessing/BloomPlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/DepthOfFieldPlugin.d.ts +6 -1
- package/dist/plugins/postprocessing/DepthOfFieldPlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/SSContactShadowsPlugin.d.ts +0 -1
- package/dist/plugins/postprocessing/SSContactShadowsPlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/SSReflectionPlugin.d.ts +0 -1
- package/dist/plugins/postprocessing/SSReflectionPlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/TemporalAAPlugin.d.ts +9 -4
- package/dist/plugins/postprocessing/TemporalAAPlugin.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +5 -6
- package/tsconfig.json +8 -3
package/dist/index.mjs
CHANGED
|
@@ -1,125 +1,100 @@
|
|
|
1
|
-
import { PipelinePassPlugin as I, GBufferPlugin as T, ProgressivePlugin as O, generateUiConfig as Y, uiToggle as R, uiConfig as Q, ExtendedShaderPass as $, CopyShader as ce, Vector2 as d, Matrix4 as E, serialize as c, uniform as f, uiVector as ue, matDefineBool as fe, shaderReplaceString as B, UnsignedByteType as de, LinearSRGBColorSpace as pe, GBufferRenderPass as Te, Color as he, uiImage as ve, uiFolderContainer as z, ShaderMaterial as be, Matrix3 as Pe, NoBlending as me, DoubleSide as Ce, uiConfigMaterialExtension as ge, updateBit as we, Vector4 as Ee, HalfFloatType as K, AdditiveBlending as De, uiSlider as u, onChange as N, matDefine as V, Vector3 as U, PickingPlugin as j, now as re, FrameFadePlugin as Re, ExtendedShaderMaterial as Z, shaderUtils as k, bindToValue as X, NearestFilter as ie, RGBAFormat as Ue, AViewerPluginSync as Me, glsl as _e, ShaderChunk as ae, updateMaterialDefines as Le, BaseGroundPlugin as se, SSAAPlugin as Fe, getOrCall as H, getTexelDecoding as oe } from "threepipe";
|
|
2
1
|
/**
|
|
3
2
|
* @license
|
|
4
|
-
* @threepipe/webgi-plugins v0.1
|
|
5
|
-
* Copyright 2022-
|
|
3
|
+
* @threepipe/webgi-plugins v0.2.1
|
|
4
|
+
* Copyright 2022-2025 repalash <palash@shaders.app>
|
|
6
5
|
* GPL-3.0-only License
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
uniform
|
|
10
|
-
#endif
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
#endif
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
#include <morphtarget_vertex>
|
|
24
|
-
#include <skinning_vertex>
|
|
25
|
-
#include <displacementmap_vertex>
|
|
26
|
-
vec4 mvPosition=vec4(transformed,1.0);
|
|
27
|
-
#ifdef USE_INSTANCING
|
|
28
|
-
mvPosition=instanceMatrix*mvPosition;
|
|
29
|
-
#endif
|
|
30
|
-
vWorldPosition=(modelMatrix*mvPosition).xyz;vWorldPositionPrevious=(modelMatrixPrevious*mvPosition).xyz;mvPosition=modelViewMatrix*mvPosition;gl_Position=projectionMatrix*mvPosition;
|
|
31
|
-
#include <logdepthbuf_vertex>
|
|
32
|
-
#include <clipping_planes_vertex>
|
|
33
|
-
}`, ze = "varying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 currentProjectionViewMatrix;uniform mat4 lastProjectionViewMatrix;vec2 computeScreenSpaceVelocity2(){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(vWorldPosition,1.0);vec4 prevPositionClip=lastProjectionViewMatrix*vec4(vWorldPositionPrevious,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(){vec2 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.);}", Ne = `#include <common>
|
|
34
|
-
#include <gbuffer_unpack>
|
|
35
|
-
#ifdef HAS_VELOCITY_BUFFER
|
|
36
|
-
#endif
|
|
37
|
-
#include <cameraHelpers>
|
|
38
|
-
varying vec2 vUv;uniform vec2 previousRTSize;uniform mat4 lastProjectionViewMatrix;uniform mat4 currentProjectionViewMatrix;uniform mat4 inverseViewMatrix;uniform vec2 jitterSample;uniform vec2 feedBack;uniform bool firstFrame;
|
|
39
|
-
#ifndef HAS_VELOCITY_BUFFER
|
|
40
|
-
#define HAS_VELOCITY_BUFFER 0
|
|
41
|
-
#endif
|
|
42
|
-
vec3 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;}
|
|
43
|
-
#if HAS_VELOCITY_BUFFER == 0
|
|
44
|
-
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);}
|
|
45
|
-
#endif
|
|
46
|
-
vec4 computeTAA(const in vec2 uv,const in vec2 screenSpaceVelocity){vec2 jitterOffset=jitterSample/previousRTSize;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=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.yx*texelSize));vec4 tc=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.zx*texelSize));vec4 tr=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.xx*texelSize));vec4 ml=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.yz*texelSize));vec4 mc=currentColor;vec4 mr=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.xz*texelSize));vec4 bl=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.yy*texelSize));vec4 bc=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.zy*texelSize));vec4 br=currentRTTexelToLinear(texture2D(currentRT,uvUnJitter+offset.xy*texelSize));vec4 corners=2.0*(tr+bl+br+tl)-2.0*mc;mc+=(mc-(corners*0.166667))*2.718282*0.3;mc=max(vec4(0.0),mc);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);previousColor=clip_aabb(cmin,cmax,previousColor);float 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,k_feedback);}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;}void main(){vec2 jitterOffset=jitterSample/previousRTSize;
|
|
47
|
-
#if HAS_VELOCITY_BUFFER == 0
|
|
48
|
-
#if QUALITY == 1
|
|
49
|
-
vec3 c_frag=find_closest_fragment_3x3(vUv);
|
|
50
|
-
#else
|
|
51
|
-
vec3 c_frag=find_closest_fragment_5tap(vUv);
|
|
52
|
-
#endif
|
|
53
|
-
#else
|
|
54
|
-
vec3 c_frag=vec3(0.0);
|
|
55
|
-
#endif
|
|
56
|
-
if(c_frag.z>=0.999){gl_FragColor=currentRTTexelToLinear(texture2D(currentRT,vUv-jitterOffset));}else{
|
|
57
|
-
#if HAS_VELOCITY_BUFFER == 0
|
|
58
|
-
float sampleViewZ=mix(-cameraNearFar.x,-cameraNearFar.y,c_frag.z);vec3 worldPosition=getWorldPositionFromViewZ(c_frag.xy,sampleViewZ);vec2 screenSpaceVelocity=computeScreenSpaceVelocity(worldPosition);
|
|
59
|
-
#else
|
|
60
|
-
screenSpaceVelocity=getVelocity(vUv);
|
|
61
|
-
#endif
|
|
62
|
-
gl_FragColor=firstFrame ? currentRTTexelToLinear(texture2D(currentRT,vUv)): computeTAA(vUv,screenSpaceVelocity);
|
|
63
|
-
#ifdef DEBUG_VELOCITY
|
|
64
|
-
gl_FragColor=vec4(10.*length(screenSpaceVelocity));
|
|
65
|
-
#endif
|
|
66
|
-
}
|
|
67
|
-
#include <encodings_fragment>
|
|
68
|
-
}`;
|
|
69
|
-
var Oe = Object.defineProperty, ke = Object.getOwnPropertyDescriptor, q = (a, e, i, r) => {
|
|
70
|
-
for (var t = r > 1 ? void 0 : r ? ke(e, i) : e, s = a.length - 1, o; s >= 0; s--)
|
|
71
|
-
(o = a[s]) && (t = (r ? o(e, i, t) : o(t)) || t);
|
|
72
|
-
return r && t && Oe(e, i, t), t;
|
|
7
|
+
var _a;
|
|
8
|
+
import { PipelinePassPlugin, GBufferPlugin, ProgressivePlugin, generateUiConfig, uiToggle, uiConfig, ExtendedShaderPass, CopyShader, Vector2, Matrix4, getOrCall, serialize, uniform, uiVector, matDefineBool, shaderReplaceString, UnsignedByteType, LinearSRGBColorSpace, GBufferRenderPass, Color, uiImage, uiFolderContainer, ShaderMaterial, Matrix3, NoBlending, DoubleSide, uiConfigMaterialExtension, updateBit, Vector4, HalfFloatType, AdditiveBlending, uiSlider, onChange, onChange2, Vector3, PickingPlugin, now, FrameFadePlugin, ExtendedShaderMaterial, shaderUtils, bindToValue, NearestFilter, RGBAFormat, AViewerPluginSync, glsl, ShaderChunk, updateMaterialDefines, BaseGroundPlugin, matDefine, SSAAPlugin, getTexelDecoding } from "threepipe";
|
|
9
|
+
const VelocityBufferUnpack = "#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";
|
|
10
|
+
const ssVelocityVert = "#ifdef USE_ALPHAMAP\n#define USE_UV\n#endif\n#include <uv_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;void main(){\n#include <uv_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);\n#ifdef USE_INSTANCING\nmvPosition=instanceMatrix*mvPosition;\n#endif\nvWorldPosition=(modelMatrix*mvPosition).xyz;vWorldPositionPrevious=(modelMatrixPrevious*mvPosition).xyz;mvPosition=modelViewMatrix*mvPosition;gl_Position=projectionMatrix*mvPosition;\n#include <logdepthbuf_vertex>\n#include <clipping_planes_vertex>\n}";
|
|
11
|
+
const ssVelocityFrag = "varying vec3 vWorldPosition;varying vec3 vWorldPositionPrevious;uniform mat4 currentProjectionViewMatrix;uniform mat4 lastProjectionViewMatrix;vec2 computeScreenSpaceVelocity2(){vec4 currentPositionClip=currentProjectionViewMatrix*vec4(vWorldPosition,1.0);vec4 prevPositionClip=lastProjectionViewMatrix*vec4(vWorldPositionPrevious,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(){vec2 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.);}";
|
|
12
|
+
const taaShader = "#include <common>\n#include <gbuffer_unpack>\n#ifdef HAS_VELOCITY_BUFFER\n#pragma <velocity_unpack>\n#endif\n#include <cameraHelpers>\nvarying vec2 vUv;uniform vec2 previousRTSize;uniform mat4 lastProjectionViewMatrix;uniform mat4 currentProjectionViewMatrix;uniform mat4 inverseViewMatrix;uniform vec2 jitterSample;uniform vec2 feedBack;uniform bool firstFrame;\n#ifndef HAS_VELOCITY_BUFFER\n#define HAS_VELOCITY_BUFFER 0\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\nvec2 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);}\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));vec4 corners=2.0*(tr+bl+br+tl)-2.0*mc;mc+=(mc-(corners*0.166667))*2.718282*0.3;mc=max(vec4(0.0),mc);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);previousColor=clip_aabb(cmin,cmax,previousColor);float 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.));}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;}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#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(firstFrame){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 <encodings_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}";
|
|
13
|
+
var __defProp$5 = Object.defineProperty;
|
|
14
|
+
var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
|
|
15
|
+
var __decorateClass$5 = (decorators, target, key, kind) => {
|
|
16
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
|
|
17
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
18
|
+
if (decorator = decorators[i])
|
|
19
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
20
|
+
if (kind && result) __defProp$5(target, key, result);
|
|
21
|
+
return result;
|
|
73
22
|
};
|
|
74
|
-
const
|
|
23
|
+
const passId$3 = "taa";
|
|
24
|
+
const _TemporalAAPlugin = class _TemporalAAPlugin extends PipelinePassPlugin {
|
|
75
25
|
// readonly materialExtension: MaterialExtension = uiConfigMaterialExtension(this._getUiConfig.bind(this), TemporalAAPlugin.PluginType)
|
|
76
|
-
constructor(
|
|
77
|
-
super()
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
26
|
+
constructor(enabled = true) {
|
|
27
|
+
super();
|
|
28
|
+
this.passId = passId$3;
|
|
29
|
+
this._stableNoise = true;
|
|
30
|
+
this._gbufferUnpackExtension = void 0;
|
|
31
|
+
this._gbufferUnpackExtensionChanged = () => {
|
|
32
|
+
if (!this._pass || !this._viewer) throw new Error("TemporalAAPlugin: pass/viewer not created yet");
|
|
33
|
+
const newExtension = this._viewer.renderManager.gbufferUnpackExtension;
|
|
34
|
+
if (this._gbufferUnpackExtension === newExtension) return;
|
|
35
|
+
if (this._gbufferUnpackExtension) this._pass.material.unregisterMaterialExtensions([this._gbufferUnpackExtension]);
|
|
36
|
+
this._gbufferUnpackExtension = newExtension;
|
|
37
|
+
if (this._gbufferUnpackExtension) this._pass.material.registerMaterialExtensions([this._gbufferUnpackExtension]);
|
|
38
|
+
else this._viewer.console.warn("TemporalAAPlugin: GBuffer unpack extension removed");
|
|
39
|
+
};
|
|
40
|
+
this.dependencies = [GBufferPlugin, ProgressivePlugin];
|
|
41
|
+
this.uiConfig = {
|
|
83
42
|
type: "folder",
|
|
84
43
|
label: "TemporalAA Plugin",
|
|
85
44
|
onChange: this.setDirty.bind(this),
|
|
86
45
|
children: [
|
|
87
|
-
...
|
|
46
|
+
...generateUiConfig(this) || []
|
|
88
47
|
]
|
|
89
|
-
}
|
|
48
|
+
};
|
|
49
|
+
this.enabled = enabled;
|
|
50
|
+
this.setDirty = this.setDirty.bind(this);
|
|
90
51
|
}
|
|
91
52
|
get stableNoise() {
|
|
92
|
-
var
|
|
93
|
-
return ((
|
|
53
|
+
var _a2;
|
|
54
|
+
return ((_a2 = this._viewer) == null ? void 0 : _a2.renderManager.stableNoise) ?? this._stableNoise;
|
|
94
55
|
}
|
|
95
|
-
set stableNoise(
|
|
96
|
-
this._viewer
|
|
56
|
+
set stableNoise(v) {
|
|
57
|
+
if (this._viewer) this._viewer.renderManager.stableNoise = v;
|
|
58
|
+
this._stableNoise = v;
|
|
97
59
|
}
|
|
98
60
|
_createPass() {
|
|
99
|
-
if (!this._viewer)
|
|
100
|
-
throw new Error("TemporalAAPlugin: viewer not set");
|
|
61
|
+
if (!this._viewer) throw new Error("TemporalAAPlugin: viewer not set");
|
|
101
62
|
if (!this._viewer.renderManager.gbufferTarget || !this._viewer.renderManager.gbufferUnpackExtension)
|
|
102
63
|
throw new Error("TemporalAAPlugin: GBuffer target not created. GBufferPlugin is required.");
|
|
103
|
-
|
|
64
|
+
const applyOnBackground = !!this._viewer.renderManager.msaa;
|
|
65
|
+
const t = new TemporalAAPluginPass(this.passId, () => {
|
|
66
|
+
var _a2, _b;
|
|
67
|
+
return (_b = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(ProgressivePlugin)) == null ? void 0 : _b.target;
|
|
68
|
+
}, applyOnBackground);
|
|
69
|
+
return t;
|
|
104
70
|
}
|
|
105
71
|
// todo use gbufferUnpackExtension from render manager to support depth buffer plugin as well.
|
|
106
|
-
onAdded(
|
|
107
|
-
super.onAdded(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
72
|
+
onAdded(viewer) {
|
|
73
|
+
super.onAdded(viewer);
|
|
74
|
+
this._gbufferUnpackExtensionChanged();
|
|
75
|
+
viewer.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
|
|
76
|
+
viewer.renderManager.addEventListener("resize", this._pass.onSizeUpdate);
|
|
77
|
+
}
|
|
78
|
+
onRemove(viewer) {
|
|
79
|
+
viewer.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
|
|
80
|
+
viewer.renderManager.removeEventListener("resize", this._pass.onSizeUpdate);
|
|
81
|
+
super.onRemove(viewer);
|
|
82
|
+
}
|
|
83
|
+
_beforeRender(scene, camera, renderManager) {
|
|
84
|
+
if (!super._beforeRender(scene, camera, renderManager)) return false;
|
|
85
|
+
const pass = this.pass;
|
|
86
|
+
const v = this._viewer;
|
|
87
|
+
if (!pass || !v) return false;
|
|
88
|
+
const frame = renderManager.frameCount;
|
|
89
|
+
pass.taaEnabled = frame <= 1 && scene.renderCamera === scene.mainCamera;
|
|
90
|
+
if (!pass.taaEnabled) return false;
|
|
91
|
+
const cam = camera;
|
|
92
|
+
if (!cam) return false;
|
|
93
|
+
cam.updateMatrixWorld(true);
|
|
94
|
+
cam.updateShaderProperties(pass.material);
|
|
95
|
+
pass.updateCameraProperties(cam);
|
|
96
|
+
pass.target = v.getPlugin(ProgressivePlugin).target;
|
|
97
|
+
return true;
|
|
123
98
|
}
|
|
124
99
|
// region to be done or removed
|
|
125
100
|
// static AddTemporalAAData(material: IMaterial, params?: IMaterialUserData['TemporalAA'], setDirty = true): IMaterialUserData['TemporalAA']|null {
|
|
@@ -166,39 +141,46 @@ const Ie = "taa", G = class G extends I {
|
|
|
166
141
|
// }
|
|
167
142
|
// endregion
|
|
168
143
|
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
144
|
+
_TemporalAAPlugin.PluginType = "TAA";
|
|
145
|
+
_TemporalAAPlugin.OldPluginType = "TemporalAAPlugin";
|
|
146
|
+
let TemporalAAPlugin = _TemporalAAPlugin;
|
|
147
|
+
__decorateClass$5([
|
|
148
|
+
uiToggle("Stable Noise (Total frame count)")
|
|
149
|
+
], TemporalAAPlugin.prototype, "stableNoise", 1);
|
|
150
|
+
__decorateClass$5([
|
|
151
|
+
uiConfig()
|
|
152
|
+
], TemporalAAPlugin.prototype, "_pass", 2);
|
|
153
|
+
class TemporalAAPluginPass extends ExtendedShaderPass {
|
|
154
|
+
constructor(pid, target, applyOnBackground = true) {
|
|
155
|
+
var _a2;
|
|
180
156
|
super({
|
|
181
|
-
vertexShader:
|
|
182
|
-
fragmentShader:
|
|
157
|
+
vertexShader: CopyShader.vertexShader,
|
|
158
|
+
fragmentShader: taaShader,
|
|
183
159
|
uniforms: {
|
|
184
160
|
currentRT: { value: null },
|
|
185
161
|
previousRT: { value: null },
|
|
186
|
-
previousRTSize: { value: new
|
|
187
|
-
cameraNearFar: { value: new
|
|
188
|
-
lastProjectionViewMatrix: { value: new
|
|
189
|
-
currentProjectionViewMatrix: { value: new
|
|
190
|
-
projection: { value: new
|
|
191
|
-
inverseViewMatrix: { value: new
|
|
192
|
-
jitterSample: { value: new
|
|
193
|
-
firstFrame: { value:
|
|
162
|
+
previousRTSize: { value: new Vector2() },
|
|
163
|
+
cameraNearFar: { value: new Vector2() },
|
|
164
|
+
lastProjectionViewMatrix: { value: new Matrix4() },
|
|
165
|
+
currentProjectionViewMatrix: { value: new Matrix4() },
|
|
166
|
+
projection: { value: new Matrix4() },
|
|
167
|
+
inverseViewMatrix: { value: new Matrix4() },
|
|
168
|
+
jitterSample: { value: new Vector2() },
|
|
169
|
+
firstFrame: { value: true }
|
|
194
170
|
},
|
|
195
171
|
defines: {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
UNJITTER: 0
|
|
172
|
+
["QUALITY"]: 1,
|
|
173
|
+
["UNJITTER"]: 0,
|
|
174
|
+
["BACKGROUND_TAA"]: applyOnBackground ? 1 : 0
|
|
200
175
|
}
|
|
201
|
-
}, "currentRT", "previousRT")
|
|
176
|
+
}, "currentRT", "previousRT");
|
|
177
|
+
this.before = ["progressive"];
|
|
178
|
+
this.after = [];
|
|
179
|
+
this.required = ["render", "progressive"];
|
|
180
|
+
this.taaEnabled = true;
|
|
181
|
+
this.feedBack = new Vector2(0.88, 0.97);
|
|
182
|
+
this.debugVelocity = false;
|
|
183
|
+
this.uiConfig = {
|
|
202
184
|
type: "folder",
|
|
203
185
|
label: "Temporal AA Pass",
|
|
204
186
|
onChange: this.setDirty,
|
|
@@ -209,261 +191,332 @@ class ee extends $ {
|
|
|
209
191
|
property: [this, "enabled"],
|
|
210
192
|
onChange: () => this.onSizeUpdate()
|
|
211
193
|
},
|
|
212
|
-
...((
|
|
194
|
+
...((_a2 = generateUiConfig(this)) == null ? void 0 : _a2.filter((c) => c && c.label !== "Enabled")) || []
|
|
213
195
|
]
|
|
214
|
-
}
|
|
196
|
+
};
|
|
197
|
+
this.passId = pid;
|
|
198
|
+
this.onSizeUpdate = this.onSizeUpdate.bind(this);
|
|
199
|
+
this.target = target;
|
|
200
|
+
this.clear = false;
|
|
201
|
+
this.needsSwap = true;
|
|
215
202
|
}
|
|
216
|
-
render(
|
|
203
|
+
render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
|
|
204
|
+
var _a2;
|
|
217
205
|
if (!this.taaEnabled || !this.enabled) {
|
|
218
|
-
this.needsSwap =
|
|
206
|
+
this.needsSwap = false;
|
|
219
207
|
return;
|
|
220
208
|
}
|
|
221
|
-
this.needsSwap =
|
|
209
|
+
this.needsSwap = true;
|
|
210
|
+
this.uniforms.previousRT.value = ((_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture) ?? null;
|
|
211
|
+
super.render(renderer, writeBuffer, readBuffer, deltaTime, maskActive);
|
|
212
|
+
this.uniforms.lastProjectionViewMatrix.value.copy(this.uniforms.currentProjectionViewMatrix.value);
|
|
213
|
+
this.uniforms.firstFrame.value = false;
|
|
222
214
|
}
|
|
223
|
-
updateCameraProperties(
|
|
224
|
-
|
|
215
|
+
updateCameraProperties(camera) {
|
|
216
|
+
if (!camera) return;
|
|
217
|
+
this.uniforms.currentProjectionViewMatrix.value.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
|
|
218
|
+
this.uniforms.inverseViewMatrix.value.copy(camera.matrixWorld);
|
|
225
219
|
}
|
|
226
220
|
onSizeUpdate() {
|
|
227
|
-
this.uniforms.firstFrame.value =
|
|
221
|
+
this.uniforms.firstFrame.value = true;
|
|
222
|
+
this.setDirty();
|
|
228
223
|
}
|
|
229
|
-
setSize(
|
|
230
|
-
super.setSize(
|
|
224
|
+
setSize(width, height) {
|
|
225
|
+
super.setSize(width, height);
|
|
226
|
+
this.onSizeUpdate();
|
|
231
227
|
}
|
|
232
228
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
],
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
],
|
|
242
|
-
var
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
229
|
+
__decorateClass$5([
|
|
230
|
+
serialize(),
|
|
231
|
+
uniform(),
|
|
232
|
+
uiVector("Feedback", void 0, 1e-4)
|
|
233
|
+
], TemporalAAPluginPass.prototype, "feedBack", 2);
|
|
234
|
+
__decorateClass$5([
|
|
235
|
+
uiToggle(),
|
|
236
|
+
matDefineBool("DEBUG_VELOCITY", void 0, false, void 0, true)
|
|
237
|
+
], TemporalAAPluginPass.prototype, "debugVelocity", 2);
|
|
238
|
+
var __defProp$4 = Object.defineProperty;
|
|
239
|
+
var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
|
|
240
|
+
var __decorateClass$4 = (decorators, target, key, kind) => {
|
|
241
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
|
|
242
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
243
|
+
if (decorator = decorators[i])
|
|
244
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
245
|
+
if (kind && result) __defProp$4(target, key, result);
|
|
246
|
+
return result;
|
|
246
247
|
};
|
|
247
|
-
let
|
|
248
|
-
constructor(
|
|
249
|
-
super()
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
248
|
+
let VelocityBufferPlugin = class extends PipelinePassPlugin {
|
|
249
|
+
constructor(bufferType = UnsignedByteType, enabled = true, _attachToTaa = true) {
|
|
250
|
+
super();
|
|
251
|
+
this.passId = "velocityBuffer";
|
|
252
|
+
this.material = new SSVelocityMaterial();
|
|
253
|
+
this.unpackExtension = {
|
|
254
|
+
shaderExtender: (shader) => {
|
|
255
|
+
if (this.isDisabled()) return;
|
|
256
|
+
shader.fragmentShader = shaderReplaceString(
|
|
257
|
+
shader.fragmentShader,
|
|
258
|
+
"#pragma <velocity_unpack>",
|
|
259
|
+
"\n" + VelocityBufferUnpack + "\n"
|
|
257
260
|
);
|
|
258
261
|
},
|
|
262
|
+
computeCacheKey: () => this.isDisabled() ? "" : "vb",
|
|
259
263
|
extraUniforms: {
|
|
260
264
|
tVelocity: () => {
|
|
261
|
-
var
|
|
262
|
-
return { value: (
|
|
265
|
+
var _a2;
|
|
266
|
+
return { value: !this.isDisabled() ? (_a2 = this.target) == null ? void 0 : _a2.texture : null };
|
|
263
267
|
}
|
|
264
268
|
},
|
|
265
269
|
extraDefines: {
|
|
266
|
-
HAS_VELOCITY_BUFFER: () => {
|
|
267
|
-
var
|
|
268
|
-
return (
|
|
270
|
+
["HAS_VELOCITY_BUFFER"]: () => {
|
|
271
|
+
var _a2;
|
|
272
|
+
return !this.isDisabled() && ((_a2 = this.target) == null ? void 0 : _a2.texture) ? 1 : void 0;
|
|
269
273
|
}
|
|
270
274
|
},
|
|
271
275
|
priority: 100,
|
|
272
|
-
isCompatible: () =>
|
|
273
|
-
}
|
|
276
|
+
isCompatible: () => true
|
|
277
|
+
};
|
|
278
|
+
this.enabled = enabled;
|
|
279
|
+
this.bufferType = bufferType;
|
|
280
|
+
this._attachToTaa = _attachToTaa;
|
|
274
281
|
}
|
|
275
282
|
// cannot be changed after creation (for now)
|
|
276
|
-
_createTarget(
|
|
277
|
-
|
|
283
|
+
_createTarget(recreate = true) {
|
|
284
|
+
if (!this._viewer) return;
|
|
285
|
+
if (recreate) this._disposeTarget();
|
|
286
|
+
if (!this.target) this.target = this._viewer.renderManager.createTarget(
|
|
278
287
|
{
|
|
279
|
-
depthBuffer:
|
|
288
|
+
depthBuffer: true,
|
|
280
289
|
// samples: v.renderManager.composerTarget.samples || 0,
|
|
281
290
|
samples: 0,
|
|
282
291
|
type: this.bufferType,
|
|
283
292
|
// magFilter: NearestFilter,
|
|
284
293
|
// minFilter: NearestFilter,
|
|
285
|
-
generateMipmaps:
|
|
286
|
-
colorSpace:
|
|
294
|
+
generateMipmaps: false,
|
|
295
|
+
colorSpace: LinearSRGBColorSpace
|
|
287
296
|
}
|
|
288
|
-
)
|
|
297
|
+
);
|
|
298
|
+
this.texture = this.target.texture;
|
|
299
|
+
this.texture.name = "velocityBuffer";
|
|
300
|
+
if (this._pass) this._pass.target = this.target;
|
|
289
301
|
}
|
|
290
302
|
_disposeTarget() {
|
|
291
|
-
|
|
303
|
+
if (!this._viewer) return;
|
|
304
|
+
if (this.target) {
|
|
305
|
+
this._viewer.renderManager.disposeTarget(this.target);
|
|
306
|
+
this.target = void 0;
|
|
307
|
+
}
|
|
308
|
+
this.texture = void 0;
|
|
292
309
|
}
|
|
293
310
|
_createPass() {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
this.material.userData.isGBufferMaterial =
|
|
297
|
-
const
|
|
311
|
+
this._createTarget(true);
|
|
312
|
+
if (!this.target) throw new Error("VelocityBufferPlugin: target not created");
|
|
313
|
+
this.material.userData.isGBufferMaterial = true;
|
|
314
|
+
const v = this._viewer;
|
|
315
|
+
const pass = new class extends GBufferRenderPass {
|
|
298
316
|
constructor() {
|
|
299
|
-
super(...arguments)
|
|
317
|
+
super(...arguments);
|
|
318
|
+
this._firstCall = true;
|
|
300
319
|
}
|
|
301
|
-
render(
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
|
|
320
|
+
render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
|
|
321
|
+
if (v.renderManager.frameCount > 0) return;
|
|
322
|
+
if (!this.enabled || !this.camera) return;
|
|
323
|
+
const mat = this.overrideMaterial;
|
|
324
|
+
mat.uniforms.currentProjectionViewMatrix.value.copy(this.camera.projectionMatrix).multiply(this.camera.matrixWorldInverse);
|
|
325
|
+
if (this._firstCall) {
|
|
326
|
+
mat.uniforms.lastProjectionViewMatrix.value.copy(mat.uniforms.currentProjectionViewMatrix.value);
|
|
327
|
+
this._firstCall = false;
|
|
328
|
+
}
|
|
329
|
+
super.render(renderer, writeBuffer, readBuffer, deltaTime, maskActive);
|
|
330
|
+
mat.uniforms.lastProjectionViewMatrix.value.copy(mat.uniforms.currentProjectionViewMatrix.value);
|
|
306
331
|
}
|
|
307
|
-
}(this.passId, this.target, this.material, new
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
332
|
+
}(this.passId, this.target, this.material, new Color(0.5, 0.5, 0.5), 1);
|
|
333
|
+
const preprocessMaterial = pass.preprocessMaterial;
|
|
334
|
+
pass.preprocessMaterial = (m) => {
|
|
335
|
+
var _a2;
|
|
336
|
+
return preprocessMaterial(m, (_a2 = m.userData[VelocityBufferPlugin.PluginType]) == null ? void 0 : _a2.disabled);
|
|
337
|
+
};
|
|
338
|
+
pass.before = ["render"];
|
|
339
|
+
pass.after = [];
|
|
340
|
+
pass.required = ["render"];
|
|
341
|
+
return pass;
|
|
342
|
+
}
|
|
343
|
+
onAdded(viewer) {
|
|
344
|
+
var _a2;
|
|
345
|
+
super.onAdded(viewer);
|
|
346
|
+
if (this._attachToTaa) {
|
|
347
|
+
const taa = viewer.getPlugin(TemporalAAPlugin);
|
|
348
|
+
if (taa) (_a2 = taa.pass) == null ? void 0 : _a2.material.registerMaterialExtensions([this.unpackExtension]);
|
|
349
|
+
else viewer.console.warn("VelocityBufferPlugin: TemporalAAPlugin not found, set attachToTaa to false if not required");
|
|
318
350
|
}
|
|
319
351
|
}
|
|
320
|
-
onRemove(
|
|
321
|
-
var
|
|
322
|
-
|
|
352
|
+
onRemove(viewer) {
|
|
353
|
+
var _a2, _b;
|
|
354
|
+
this._disposeTarget();
|
|
355
|
+
if (this._attachToTaa) (_b = (_a2 = viewer.getPlugin(TemporalAAPlugin)) == null ? void 0 : _a2.pass) == null ? void 0 : _b.material.unregisterMaterialExtensions([this.unpackExtension]);
|
|
356
|
+
return super.onRemove(viewer);
|
|
357
|
+
}
|
|
358
|
+
setDirty() {
|
|
359
|
+
var _a2, _b;
|
|
360
|
+
super.setDirty();
|
|
361
|
+
(_b = (_a2 = this.unpackExtension).setDirty) == null ? void 0 : _b.call(_a2);
|
|
323
362
|
}
|
|
324
|
-
_beforeRender(
|
|
325
|
-
if (!super._beforeRender(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
363
|
+
_beforeRender(scene, camera, renderManager) {
|
|
364
|
+
if (!super._beforeRender(scene, camera, renderManager)) return false;
|
|
365
|
+
const pass = this.pass;
|
|
366
|
+
if (!pass) return false;
|
|
367
|
+
if (renderManager.frameCount > 0) return false;
|
|
368
|
+
pass.scene = scene;
|
|
369
|
+
pass.camera = camera;
|
|
370
|
+
camera.updateShaderProperties(pass.overrideMaterial);
|
|
371
|
+
return true;
|
|
329
372
|
}
|
|
330
373
|
};
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
374
|
+
VelocityBufferPlugin.PluginType = "VelocityBuffer";
|
|
375
|
+
VelocityBufferPlugin.OldPluginType = "VelocityBufferPlugin";
|
|
376
|
+
__decorateClass$4([
|
|
377
|
+
uiImage(
|
|
335
378
|
"Velocity Buffer"
|
|
336
379
|
/* {readOnly: true}*/
|
|
337
380
|
)
|
|
338
|
-
],
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
],
|
|
342
|
-
class
|
|
381
|
+
], VelocityBufferPlugin.prototype, "texture", 2);
|
|
382
|
+
VelocityBufferPlugin = __decorateClass$4([
|
|
383
|
+
uiFolderContainer("Velocity Buffer Plugin (for TAA)")
|
|
384
|
+
], VelocityBufferPlugin);
|
|
385
|
+
class SSVelocityMaterial extends ShaderMaterial {
|
|
343
386
|
constructor() {
|
|
344
387
|
super({
|
|
345
|
-
vertexShader:
|
|
346
|
-
fragmentShader:
|
|
388
|
+
vertexShader: ssVelocityVert,
|
|
389
|
+
fragmentShader: ssVelocityFrag,
|
|
347
390
|
uniforms: {
|
|
348
|
-
cameraNearFar: { value: new
|
|
391
|
+
cameraNearFar: { value: new Vector2(0.1, 1e3) },
|
|
349
392
|
alphaMap: { value: null },
|
|
350
393
|
alphaTest: { value: null },
|
|
351
|
-
alphaMapTransform: { value: /* @__PURE__ */ new
|
|
352
|
-
currentProjectionViewMatrix: { value: new
|
|
353
|
-
lastProjectionViewMatrix: { value: new
|
|
394
|
+
alphaMapTransform: { value: /* @__PURE__ */ new Matrix3() },
|
|
395
|
+
currentProjectionViewMatrix: { value: new Matrix4() },
|
|
396
|
+
lastProjectionViewMatrix: { value: new Matrix4() }
|
|
354
397
|
},
|
|
355
|
-
blending:
|
|
398
|
+
blending: NoBlending
|
|
356
399
|
// todo?
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
|
|
400
|
+
});
|
|
401
|
+
this.extraUniformsToUpload = {
|
|
402
|
+
modelMatrixPrevious: { value: new Matrix4().identity() }
|
|
403
|
+
};
|
|
404
|
+
this._previousWorldMatrices = {};
|
|
360
405
|
}
|
|
361
406
|
// this gets called for each object.
|
|
362
|
-
onBeforeRender(
|
|
363
|
-
const
|
|
364
|
-
this.extraUniformsToUpload.modelMatrixPrevious.value.copy(
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
407
|
+
onBeforeRender(_r, _s, _c, _geometry, object) {
|
|
408
|
+
const prevMatrix = this._previousWorldMatrices[object.uuid];
|
|
409
|
+
this.extraUniformsToUpload.modelMatrixPrevious.value.copy(prevMatrix ?? object.matrixWorld);
|
|
410
|
+
if (prevMatrix) {
|
|
411
|
+
prevMatrix.copy(object.matrixWorld);
|
|
412
|
+
} else {
|
|
413
|
+
this._previousWorldMatrices[object.uuid] = object.matrixWorld.clone();
|
|
414
|
+
}
|
|
415
|
+
let mat = object.material;
|
|
416
|
+
if (Array.isArray(mat)) {
|
|
417
|
+
mat = mat[0];
|
|
418
|
+
}
|
|
419
|
+
this.uniforms.alphaMap.value = (mat == null ? void 0 : mat.alphaMap) ?? null;
|
|
420
|
+
this.uniforms.alphaTest.value = !mat || !mat.alphaTest || mat.alphaTest < 1e-7 ? 1e-3 : mat.alphaTest;
|
|
421
|
+
let x = this.uniforms.alphaMap.value ? 1 : void 0;
|
|
422
|
+
if (x !== this.defines.USE_ALPHAMAP) {
|
|
423
|
+
if (x === void 0) delete this.defines.USE_ALPHAMAP;
|
|
424
|
+
else this.defines.USE_ALPHAMAP = x;
|
|
425
|
+
this.needsUpdate = true;
|
|
426
|
+
}
|
|
427
|
+
x = (mat == null ? void 0 : mat.userData.ALPHA_I_RGBA_PACKING) ? 1 : void 0;
|
|
428
|
+
if (x !== this.defines.ALPHA_I_RGBA_PACKING) {
|
|
429
|
+
if (x === void 0) delete this.defines.ALPHA_I_RGBA_PACKING;
|
|
430
|
+
else this.defines.ALPHA_I_RGBA_PACKING = x;
|
|
431
|
+
this.needsUpdate = true;
|
|
432
|
+
}
|
|
433
|
+
this.side = (mat == null ? void 0 : mat.side) ?? DoubleSide;
|
|
369
434
|
}
|
|
370
435
|
}
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
if(
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
#endif
|
|
382
|
-
vec4 Sample(vec2 uv){return tDiffuseTexelToLinear(texture2D(tDiffuse,uv));}vec4 SampleBox(vec2 uv,float delta){vec4 o=vec2(-delta,delta).xxyy/tDiffuseSize.xyxy;vec4 s=Sample(uv+o.xy)+Sample(uv+o.zy)+Sample(uv+o.xw)+Sample(uv+o.zw);return s*0.25;}int getBloomBit(in int number){
|
|
383
|
-
#ifdef WebGL2Context
|
|
384
|
-
return(number/4)% 2;
|
|
385
|
-
#else
|
|
386
|
-
return int(mod(floor(float(number)/4.),2.));
|
|
387
|
-
#endif
|
|
388
|
-
}void main(){
|
|
389
|
-
#if PASS_STEP == 0
|
|
390
|
-
#ifdef GBUFFER_HAS_FLAGS
|
|
391
|
-
int doBloom=getBloomBit(getGBufferFlags(vUv).a);
|
|
392
|
-
#else
|
|
393
|
-
int doBloom=1;
|
|
394
|
-
#endif
|
|
395
|
-
gl_FragColor=float(doBloom)*weight*Prefilter(SampleBox(vUv,1.));gl_FragColor.a=1.;
|
|
396
|
-
#elif PASS_STEP == 1
|
|
397
|
-
gl_FragColor=weight*(SampleBox(vUv,1.));gl_FragColor.a=1.;
|
|
398
|
-
#elif PASS_STEP == 2
|
|
399
|
-
gl_FragColor=(SampleBox(vUv,0.5));gl_FragColor.a=1.;
|
|
400
|
-
#elif PASS_STEP == 3
|
|
401
|
-
vec4 texel=tSourceTexelToLinear(texture2D(tSource,vUv));vec4 bloom=intensity*SampleBox(vUv,0.5).rgba;float brightness=max(bloom.r,max(bloom.g,bloom.b));texel.rgb+=bloom.rgb;texel.a=min(1.,texel.a+brightness);gl_FragColor=texel;
|
|
402
|
-
#elif PASS_STEP == 4
|
|
403
|
-
vec4 texel=vec4(0.);texel.rgb+=intensity*SampleBox(vUv,0.5).rgb;texel.a=1.;gl_FragColor=texel;
|
|
404
|
-
#endif
|
|
405
|
-
#include <encodings_fragment>
|
|
406
|
-
}`;
|
|
407
|
-
var We = Object.defineProperty, Ye = Object.getOwnPropertyDescriptor, P = (a, e, i, r) => {
|
|
408
|
-
for (var t = r > 1 ? void 0 : r ? Ye(e, i) : e, s = a.length - 1, o; s >= 0; s--)
|
|
409
|
-
(o = a[s]) && (t = (r ? o(e, i, t) : o(t)) || t);
|
|
410
|
-
return r && t && We(e, i, t), t;
|
|
436
|
+
const hdrBloom = "#include <packing>\nuniform float intensity;uniform float opacity;uniform vec2 tDiffuseSize;varying vec2 vUv;uniform float weight;\n#if PASS_STEP == 0\nuniform vec4 prefilter;vec4 Prefilter(vec4 c){\n#ifdef HAS_GBUFFER\n#if !BACKGROUND_BLOOM\nif(getDepth(vUv)>0.999){return vec4(0.0);}\n#endif\n#endif\nfloat brightness=max(c.r,max(c.g,c.b));float soft=brightness+prefilter.x*(prefilter.y-1.);soft=clamp(soft,0.,prefilter.z);soft=soft*soft*prefilter.w;float contribution=max(soft,brightness-prefilter.x);contribution/=max(brightness,0.001);return vec4(c.rgb*contribution,c.a);}\n#endif\nvec4 Sample(vec2 uv){return min(vec4(MAX_INTENSITY,MAX_INTENSITY,MAX_INTENSITY,1.),tDiffuseTexelToLinear(texture2D(tDiffuse,uv)));}vec4 SampleBox(vec2 uv,float delta){vec4 o=vec2(-delta,delta).xxyy/tDiffuseSize.xyxy;vec4 s=Sample(uv+o.xy)+Sample(uv+o.zy)+Sample(uv+o.xw)+Sample(uv+o.zw);return s*0.25;}int getBloomBit(in int number){\n#ifdef WebGL2Context\nreturn(number/4)% 2;\n#else\nreturn int(mod(floor(float(number)/4.),2.));\n#endif\n}void main(){\n#if PASS_STEP == 0\n#ifdef GBUFFER_HAS_FLAGS\nint doBloom=getBloomBit(getGBufferFlags(vUv).a);\n#else\nint doBloom=1;\n#endif\ngl_FragColor=float(doBloom)*weight*Prefilter(SampleBox(vUv,1.));gl_FragColor.a=1.;\n#elif PASS_STEP == 1\ngl_FragColor=weight*(SampleBox(vUv,1.));gl_FragColor.a=1.;\n#elif PASS_STEP == 2\ngl_FragColor=(SampleBox(vUv,0.5));gl_FragColor.a=1.;\n#elif PASS_STEP == 3\nvec4 texel=tSourceTexelToLinear(texture2D(tSource,vUv));vec4 bloom=intensity*SampleBox(vUv,0.5).rgba;float brightness=max(bloom.r,max(bloom.g,bloom.b));texel.rgb+=bloom.rgb;texel.a=min(1.,texel.a+brightness);gl_FragColor=texel;\n#elif PASS_STEP == 4\nvec4 texel=vec4(0.);texel.rgb+=intensity*SampleBox(vUv,0.5).rgb;texel.a=1.;gl_FragColor=texel;\n#endif\n#include <encodings_fragment>\n}";
|
|
437
|
+
var __defProp$3 = Object.defineProperty;
|
|
438
|
+
var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
|
|
439
|
+
var __decorateClass$3 = (decorators, target, key, kind) => {
|
|
440
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
|
|
441
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
442
|
+
if (decorator = decorators[i])
|
|
443
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
444
|
+
if (kind && result) __defProp$3(target, key, result);
|
|
445
|
+
return result;
|
|
411
446
|
};
|
|
412
|
-
const $
|
|
413
|
-
|
|
414
|
-
const Se = (_ = class extends I {
|
|
447
|
+
const passId$2 = "bloom";
|
|
448
|
+
const _BloomPlugin = (_a = class extends PipelinePassPlugin {
|
|
415
449
|
constructor() {
|
|
416
|
-
super(...arguments)
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
450
|
+
super(...arguments);
|
|
451
|
+
this.passId = passId$2;
|
|
452
|
+
this.materialExtension = uiConfigMaterialExtension(this._getUiConfig.bind(this), _a.PluginType);
|
|
453
|
+
this.dependencies = [GBufferPlugin];
|
|
454
|
+
this._onPluginAdd = (e) => {
|
|
455
|
+
var _a2, _b, _c, _d;
|
|
456
|
+
if (((_b = (_a2 = e.plugin) == null ? void 0 : _a2.constructor) == null ? void 0 : _b.PluginType) !== GBufferPlugin.PluginType) return;
|
|
457
|
+
const gbuffer = e.plugin;
|
|
458
|
+
gbuffer.registerGBufferUpdater(this.constructor.PluginType, this.updateGBufferFlags.bind(this));
|
|
459
|
+
(_c = this._pass) == null ? void 0 : _c.material.registerMaterialExtensions([gbuffer.unpackExtension]);
|
|
460
|
+
(_d = this._viewer) == null ? void 0 : _d.removeEventListener("addPlugin", this._onPluginAdd);
|
|
461
|
+
};
|
|
462
|
+
this.uiConfig = {
|
|
423
463
|
type: "folder",
|
|
424
464
|
label: "Bloom Plugin",
|
|
425
465
|
onChange: this.setDirty.bind(this),
|
|
426
466
|
children: [
|
|
427
|
-
...
|
|
467
|
+
...generateUiConfig(this) || []
|
|
428
468
|
]
|
|
429
469
|
};
|
|
430
470
|
}
|
|
431
471
|
_createPass() {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
super.onAdded(e);
|
|
436
|
-
const i = e.getPlugin(T);
|
|
437
|
-
i ? (i.registerGBufferUpdater(this.constructor.PluginType, this.updateGBufferFlags.bind(this)), this._pass.material.registerMaterialExtensions([i.unpackExtension])) : e.addEventListener("addPlugin", this._onPluginAdd), e.materialManager.registerMaterialExtension(this.materialExtension);
|
|
438
|
-
}
|
|
439
|
-
onRemove(e) {
|
|
440
|
-
var r;
|
|
441
|
-
e.removeEventListener("addPlugin", this._onPluginAdd);
|
|
442
|
-
const i = e.getPlugin(T);
|
|
443
|
-
i == null || i.unregisterGBufferUpdater(this.constructor.PluginType), i && ((r = this._pass) == null || r.material.unregisterMaterialExtensions([i.unpackExtension])), e.materialManager.unregisterMaterialExtension(this.materialExtension), super.onRemove(e);
|
|
444
|
-
}
|
|
445
|
-
updateGBufferFlags(e, i) {
|
|
446
|
-
var s;
|
|
447
|
-
if (!i.material || !i.material.userData)
|
|
448
|
-
return;
|
|
449
|
-
const t = ((s = i.material.userData[_.PluginType]) == null ? void 0 : s.enable) === !1 || i.material.userData.pluginsDisabled ? 0 : 1;
|
|
450
|
-
e.w = we(e.w, 2, t);
|
|
472
|
+
var _a2;
|
|
473
|
+
const pass = new BloomPluginPass(this.passId, Math.min(8, ((_a2 = this._viewer) == null ? void 0 : _a2.renderManager.maxHDRIntensity) || 8));
|
|
474
|
+
return pass;
|
|
451
475
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
476
|
+
onAdded(viewer) {
|
|
477
|
+
super.onAdded(viewer);
|
|
478
|
+
const gbuffer = viewer.getPlugin(GBufferPlugin);
|
|
479
|
+
if (gbuffer) {
|
|
480
|
+
gbuffer.registerGBufferUpdater(this.constructor.PluginType, this.updateGBufferFlags.bind(this));
|
|
481
|
+
this._pass.material.registerMaterialExtensions([gbuffer.unpackExtension]);
|
|
482
|
+
} else viewer.addEventListener("addPlugin", this._onPluginAdd);
|
|
483
|
+
viewer.materialManager.registerMaterialExtension(this.materialExtension);
|
|
484
|
+
}
|
|
485
|
+
onRemove(viewer) {
|
|
486
|
+
var _a2;
|
|
487
|
+
viewer.removeEventListener("addPlugin", this._onPluginAdd);
|
|
488
|
+
const gbuffer = viewer.getPlugin(GBufferPlugin);
|
|
489
|
+
gbuffer == null ? void 0 : gbuffer.unregisterGBufferUpdater(this.constructor.PluginType);
|
|
490
|
+
gbuffer && ((_a2 = this._pass) == null ? void 0 : _a2.material.unregisterMaterialExtensions([gbuffer.unpackExtension]));
|
|
491
|
+
viewer.materialManager.unregisterMaterialExtension(this.materialExtension);
|
|
492
|
+
super.onRemove(viewer);
|
|
493
|
+
}
|
|
494
|
+
updateGBufferFlags(data, c) {
|
|
495
|
+
var _a2;
|
|
496
|
+
if (!c.material || !c.material.userData) return;
|
|
497
|
+
const disabled = ((_a2 = c.material.userData[_a.PluginType]) == null ? void 0 : _a2.enable) === false || c.material.userData.pluginsDisabled;
|
|
498
|
+
const x = disabled ? 0 : 1;
|
|
499
|
+
data.w = updateBit(data.w, 2, x);
|
|
500
|
+
}
|
|
501
|
+
static AddBloomData(material, params, setDirty = true) {
|
|
502
|
+
const ud = material == null ? void 0 : material.userData;
|
|
503
|
+
if (!ud) return null;
|
|
504
|
+
if (!ud[_a.PluginType]) {
|
|
505
|
+
ud[_a.PluginType] = {};
|
|
506
|
+
}
|
|
507
|
+
const data = ud[_a.PluginType];
|
|
508
|
+
data.enable = true;
|
|
509
|
+
params && Object.assign(data, params);
|
|
510
|
+
if (setDirty && material.setDirty) material.setDirty();
|
|
511
|
+
return data;
|
|
459
512
|
}
|
|
460
513
|
/**
|
|
461
514
|
* This uiConfig is added to each material by extension
|
|
462
515
|
* @param material
|
|
463
516
|
* @private
|
|
464
517
|
*/
|
|
465
|
-
_getUiConfig(
|
|
466
|
-
const
|
|
518
|
+
_getUiConfig(material) {
|
|
519
|
+
const config = {
|
|
467
520
|
type: "folder",
|
|
468
521
|
label: "Bloom",
|
|
469
522
|
children: [
|
|
@@ -471,31 +524,36 @@ const Se = (_ = class extends I {
|
|
|
471
524
|
type: "checkbox",
|
|
472
525
|
label: "Enabled",
|
|
473
526
|
get value() {
|
|
474
|
-
var
|
|
475
|
-
return ((
|
|
527
|
+
var _a2;
|
|
528
|
+
return ((_a2 = material.userData[_a.PluginType]) == null ? void 0 : _a2.enable) ?? true;
|
|
476
529
|
},
|
|
477
|
-
set value(
|
|
478
|
-
var
|
|
479
|
-
let
|
|
480
|
-
|
|
530
|
+
set value(v) {
|
|
531
|
+
var _a2;
|
|
532
|
+
let data = material.userData[_a.PluginType];
|
|
533
|
+
if (v === (data == null ? void 0 : data.enable)) return;
|
|
534
|
+
if (!data) data = _a.AddBloomData(material, void 0, false);
|
|
535
|
+
data.enable = v;
|
|
536
|
+
material.setDirty();
|
|
537
|
+
(_a2 = config.uiRefresh) == null ? void 0 : _a2.call(config, true, "postFrame");
|
|
481
538
|
},
|
|
482
539
|
onChange: this.setDirty
|
|
483
540
|
}
|
|
484
541
|
]
|
|
485
542
|
};
|
|
486
|
-
return
|
|
487
|
-
}
|
|
488
|
-
},
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
],
|
|
492
|
-
let
|
|
493
|
-
|
|
543
|
+
return config;
|
|
544
|
+
}
|
|
545
|
+
}, _a.PluginType = "Bloom", _a.OldPluginType = "BloomPlugin", _a);
|
|
546
|
+
__decorateClass$3([
|
|
547
|
+
uiConfig()
|
|
548
|
+
], _BloomPlugin.prototype, "_pass", 2);
|
|
549
|
+
let BloomPlugin = _BloomPlugin;
|
|
550
|
+
let BloomPluginPass = class extends ExtendedShaderPass {
|
|
551
|
+
constructor(pid, maxIntensity = 16) {
|
|
494
552
|
super({
|
|
495
|
-
vertexShader:
|
|
553
|
+
vertexShader: CopyShader.vertexShader,
|
|
496
554
|
defines: {
|
|
497
|
-
|
|
498
|
-
|
|
555
|
+
["PASS_STEP"]: 1,
|
|
556
|
+
["MAX_INTENSITY"]: Math.min(maxIntensity, 16)
|
|
499
557
|
},
|
|
500
558
|
uniforms: {
|
|
501
559
|
tSource: { value: null },
|
|
@@ -503,213 +561,323 @@ let qe = Se, h = class extends $ {
|
|
|
503
561
|
// intensity: {value: 0.2},
|
|
504
562
|
opacity: { value: 1 },
|
|
505
563
|
// prefilter: {value: new Vector4(1, 0.5, 0, 0)},
|
|
506
|
-
tDiffuseSize: { value: new
|
|
564
|
+
tDiffuseSize: { value: new Vector2() },
|
|
507
565
|
weight: { value: 1 }
|
|
508
566
|
// tNormalDepth: {value: null},
|
|
509
567
|
// tGBufferFlags: {value: null},
|
|
510
568
|
},
|
|
511
|
-
fragmentShader:
|
|
512
|
-
}, "tDiffuse", "tSource")
|
|
569
|
+
fragmentShader: hdrBloom
|
|
570
|
+
}, "tDiffuse", "tSource");
|
|
571
|
+
this.uiConfig = void 0;
|
|
572
|
+
this.before = ["screen"];
|
|
573
|
+
this.after = ["render", "progressive"];
|
|
574
|
+
this.required = ["render"];
|
|
575
|
+
this.prefilter = new Vector4(2, 0.5, 0, 0);
|
|
576
|
+
this.threshold = 2;
|
|
577
|
+
this.softThreshold = 0.5;
|
|
578
|
+
this.intensity = 0.2;
|
|
579
|
+
this.backgroundBloom = false;
|
|
580
|
+
this.bloomIterations = 4;
|
|
581
|
+
this._currentIterations = 0;
|
|
582
|
+
this.radius = 0.6;
|
|
583
|
+
this.power = 1;
|
|
584
|
+
this.bloomDebug = false;
|
|
585
|
+
this._weights = [];
|
|
586
|
+
this.passId = pid;
|
|
587
|
+
this._updateWeights = this._updateWeights.bind(this);
|
|
588
|
+
this._thresholdsUpdated = this._thresholdsUpdated.bind(this);
|
|
589
|
+
this._updateWeights();
|
|
590
|
+
this._thresholdsUpdated();
|
|
591
|
+
this.clear = true;
|
|
513
592
|
}
|
|
514
593
|
_thresholdsUpdated() {
|
|
515
|
-
|
|
594
|
+
var _a2;
|
|
595
|
+
this.prefilter.x = this.threshold;
|
|
596
|
+
this.prefilter.y = this.softThreshold;
|
|
597
|
+
this.prefilter.z = 2 * this.prefilter.x * this.prefilter.y;
|
|
598
|
+
this.prefilter.w = ((_a2 = this.uniforms) == null ? void 0 : _a2.prefilter) ? 0.125 / (this.uniforms.prefilter.value.z + 1e-5) : 0;
|
|
516
599
|
}
|
|
517
|
-
render(
|
|
518
|
-
const
|
|
519
|
-
this.material.defines.PASS_STEP = 0
|
|
520
|
-
|
|
521
|
-
|
|
600
|
+
render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
|
|
601
|
+
const renderManager = renderer.renderManager;
|
|
602
|
+
this.material.defines.PASS_STEP = 0;
|
|
603
|
+
this.clear = true;
|
|
604
|
+
this.needsSwap = false;
|
|
605
|
+
const source = readBuffer;
|
|
606
|
+
if (!source) {
|
|
522
607
|
console.warn("BloomPluginPass: No source to read from");
|
|
523
608
|
return;
|
|
524
609
|
}
|
|
525
|
-
this.needsSwap =
|
|
526
|
-
let
|
|
527
|
-
|
|
528
|
-
let
|
|
529
|
-
|
|
530
|
-
let
|
|
531
|
-
|
|
532
|
-
let
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
610
|
+
this.needsSwap = true;
|
|
611
|
+
let sizeMultiplier = 0.5;
|
|
612
|
+
let width = source.width * sizeMultiplier;
|
|
613
|
+
let height = source.height * sizeMultiplier;
|
|
614
|
+
const textures = [];
|
|
615
|
+
let currentDestination = renderManager.getTempTarget({ sizeMultiplier: 1, type: HalfFloatType });
|
|
616
|
+
textures.push(currentDestination);
|
|
617
|
+
let currentSource = source;
|
|
618
|
+
this.material.needsUpdate = true;
|
|
619
|
+
this.material.uniforms.weight.value = this._weights[0];
|
|
620
|
+
super.render(renderer, currentDestination, currentSource, deltaTime, maskActive);
|
|
621
|
+
currentSource = currentDestination;
|
|
622
|
+
const ci = this._currentIterations;
|
|
623
|
+
let i = 1;
|
|
624
|
+
const iter = Math.max(2, this.bloomIterations);
|
|
625
|
+
for (; i < iter; i++) {
|
|
626
|
+
width /= 2;
|
|
627
|
+
height /= 2;
|
|
628
|
+
sizeMultiplier /= 2;
|
|
629
|
+
if (height < 2 || width < 2) {
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
currentDestination = renderManager.getTempTarget({ sizeMultiplier, type: HalfFloatType });
|
|
633
|
+
textures.push(currentDestination);
|
|
634
|
+
this.material.defines.PASS_STEP = 1;
|
|
635
|
+
let modifiedWeight = this._weights[i];
|
|
636
|
+
{
|
|
637
|
+
modifiedWeight = this._weights[i - 1] !== 0 ? this._weights[i] / this._weights[i - 1] : this._weights[i];
|
|
638
|
+
}
|
|
639
|
+
this.material.uniforms.weight.value = modifiedWeight;
|
|
640
|
+
this.material.needsUpdate = true;
|
|
641
|
+
super.render(renderer, currentDestination, currentSource, deltaTime, maskActive);
|
|
642
|
+
currentSource = currentDestination;
|
|
643
|
+
this._currentIterations = i + 1;
|
|
537
644
|
}
|
|
538
|
-
this.
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
645
|
+
if (ci !== this._currentIterations)
|
|
646
|
+
this._updateWeights(false);
|
|
647
|
+
this.clear = false;
|
|
648
|
+
const oldAutoClear = renderer.autoClear;
|
|
649
|
+
renderer.autoClear = false;
|
|
650
|
+
for (i -= 2; i >= 0; i--) {
|
|
651
|
+
currentDestination = textures[i];
|
|
652
|
+
textures[i] = void 0;
|
|
653
|
+
this.material.defines.PASS_STEP = 2;
|
|
654
|
+
this.material.transparent = true;
|
|
655
|
+
this.material.blending = AdditiveBlending;
|
|
656
|
+
this.material.needsUpdate = true;
|
|
657
|
+
renderer.autoClear = false;
|
|
658
|
+
super.render(renderer, currentDestination, currentSource, deltaTime, maskActive);
|
|
659
|
+
this.material.blending = NoBlending;
|
|
660
|
+
renderManager.releaseTempTarget(currentSource);
|
|
661
|
+
currentSource = currentDestination;
|
|
551
662
|
}
|
|
552
|
-
this.
|
|
663
|
+
this.clear = true;
|
|
664
|
+
renderer.autoClear = oldAutoClear;
|
|
665
|
+
renderer.autoClear = true;
|
|
666
|
+
if (this.bloomDebug) {
|
|
667
|
+
this.material.defines.PASS_STEP = 4;
|
|
668
|
+
this.material.needsUpdate = true;
|
|
669
|
+
super.render(renderer, writeBuffer, currentSource, deltaTime, maskActive);
|
|
670
|
+
} else {
|
|
671
|
+
this.uniforms.tSource.value = source.texture;
|
|
672
|
+
this.material.defines.PASS_STEP = 3;
|
|
673
|
+
this.material.needsUpdate = true;
|
|
674
|
+
super.render(renderer, writeBuffer, currentSource, deltaTime, maskActive);
|
|
675
|
+
this.uniforms.tSource.value = null;
|
|
676
|
+
}
|
|
677
|
+
renderManager.releaseTempTarget(currentSource);
|
|
678
|
+
}
|
|
679
|
+
_updateWeights(setDirty = true) {
|
|
680
|
+
if (!this._weights) return;
|
|
681
|
+
const radius = Math.max(Math.min(this.radius, 1), 0);
|
|
682
|
+
const iter = Math.max(2, this._currentIterations || this.bloomIterations);
|
|
683
|
+
const delta = 1 / (iter - 1);
|
|
684
|
+
for (let i = 0; i < iter; i++) {
|
|
685
|
+
let f = i * delta + 0.1;
|
|
686
|
+
let oneMinusF = 1.2 - f;
|
|
687
|
+
f = Math.pow(f, this.power);
|
|
688
|
+
oneMinusF = Math.pow(oneMinusF, this.power);
|
|
689
|
+
this._weights[i] = oneMinusF * (1 - radius) + f * radius;
|
|
690
|
+
}
|
|
691
|
+
if (setDirty !== false) this.setDirty();
|
|
553
692
|
}
|
|
554
693
|
};
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
],
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
],
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
],
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
],
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
],
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
],
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
],
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
],
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
],
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
],
|
|
599
|
-
const
|
|
600
|
-
#include <
|
|
601
|
-
|
|
602
|
-
#include <encodings_fragment
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
for(int i=0;i<16;i++){ofs=poisson_disk_samples[UNROLLED_LOOP_INDEX];ofs=vec2(dot(ofs,rotationMatrix.xy),dot(ofs,rotationMatrix.zw));sampleColor=colorTextureTexelToLinear(texture2D(colorTexture,vUv+blurDist*ofs/colorTextureSize.xy));
|
|
614
|
-
#ifdef DOF_MODE
|
|
615
|
-
sampleColor.a=abs(sampleColor.a*2.0-1.0);sampleColor.a*=sampleColor.a*sampleColor.a;
|
|
616
|
-
#endif
|
|
617
|
-
colorSum+=sampleColor.rgb*sampleColor.a;weightSum+=sampleColor.a;}
|
|
618
|
-
#pragma unroll_loop_end
|
|
619
|
-
colorSum/=weightSum;return vec4(min(vec3(72.),max(vec3(0.),colorSum)),1.0);}void main(){gl_FragColor=CircularBlur();
|
|
620
|
-
#include <encodings_fragment>
|
|
621
|
-
}`, Je = "vec2 poisson_disk_samples[16];void setPds(){poisson_disk_samples[0]=vec2(-0.399691779231,0.728591545584);poisson_disk_samples[1]=vec2(-0.48622557676,-0.84016533712);poisson_disk_samples[2]=vec2(0.770309468987,-0.24906070432);poisson_disk_samples[3]=vec2(0.556596796154,0.820359876432);poisson_disk_samples[4]=vec2(-0.933902004071,0.0600539051593);poisson_disk_samples[5]=vec2(0.330144964342,0.207477293384);poisson_disk_samples[6]=vec2(0.289013230975,-0.686749271417);poisson_disk_samples[7]=vec2(-0.0832470893559,-0.187351643125);poisson_disk_samples[8]=vec2(-0.296314525615,0.254474834305);poisson_disk_samples[9]=vec2(-0.850977666059,0.484642744689);poisson_disk_samples[10]=vec2(0.829287915319,0.2345063545);poisson_disk_samples[11]=vec2(-0.773042143899,-0.543741521254);poisson_disk_samples[12]=vec2(0.0561133030864,0.928419742597);poisson_disk_samples[13]=vec2(-0.205799249508,-0.562072714492);poisson_disk_samples[14]=vec2(-0.526991665882,-0.193690188118);poisson_disk_samples[15]=vec2(-0.051789270667,-0.935374050821);}", Qe = `#include <common>
|
|
622
|
-
#include <packing>
|
|
623
|
-
varying vec2 vUv;uniform vec2 nearFarBlurScale;uniform vec2 cameraNearFar;uniform vec2 focalDepthRange;float computeCoc(){float depth=getDepth(vUv);if(depth==1.0)return max(nearFarBlurScale.x,nearFarBlurScale.y);depth=mix(cameraNearFar.x,cameraNearFar.y,depth);float coc=(depth-focalDepthRange.x)/focalDepthRange.y;coc=clamp(coc,-1.,1.);return(coc>0.0 ? coc*nearFarBlurScale.y : coc*nearFarBlurScale.x);}void main(){gl_FragColor=vec4(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,0.5*computeCoc()+0.5);
|
|
624
|
-
#include <encodings_fragment>
|
|
625
|
-
}`, Xe = `#include <common>
|
|
626
|
-
#include <gbuffer_unpack>
|
|
627
|
-
varying vec2 vUv;uniform vec2 colorTextureSize;uniform vec2 direction;uniform vec2 nearFarBlurScale;const float MAXIMUM_BLUR_SIZE=4.0;float expandNear(const in vec2 offset,const in bool isBackground){float coc=0.0;vec2 sampleOffsets=MAXIMUM_BLUR_SIZE*offset/5.0;float coc0=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv)).a-1.;float coc1=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-5.0*sampleOffsets)).a-1.;float coc2=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-4.0*sampleOffsets)).a-1.;float coc3=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-3.0*sampleOffsets)).a-1.;float coc4=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-2.0*sampleOffsets)).a-1.;float coc5=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-1.0*sampleOffsets)).a-1.;float coc6=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+1.0*sampleOffsets)).a-1.;float coc7=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+2.0*sampleOffsets)).a-1.;float coc8=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+3.0*sampleOffsets)).a-1.;float coc9=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+4.0*sampleOffsets)).a-1.;float coc10=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+5.0*sampleOffsets)).a-1.;if(isBackground){coc=abs(coc0)*0.095474+(abs(coc1)+abs(coc10))*0.084264+(abs(coc2)+abs(coc9))*0.088139+(abs(coc3)+abs(coc8))*0.091276+(abs(coc4)+abs(coc7))*0.093585+(abs(coc5)+abs(coc6))*0.094998;}else{coc=min(coc0,0.0);coc=min(coc1*0.3,coc);coc=min(coc2*0.5,coc);coc=min(coc3*0.75,coc);coc=min(coc4*0.8,coc);coc=min(coc5*0.95,coc);coc=min(coc6*0.95,coc);coc=min(coc7*0.8,coc);coc=min(coc8*0.75,coc);coc=min(coc9*0.5,coc);coc=min(coc10*0.3,coc);if(abs(coc0)>abs(coc))coc=coc0;}return coc;}void main(){vec2 offset=2.*direction/colorTextureSize;bool isBackground=getDepth(vUv)>1.0-0.001;float coc=expandNear(offset,isBackground);gl_FragColor=vec4(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,0.5*coc+0.5);
|
|
628
|
-
#include <encodings_fragment>
|
|
629
|
-
}`;
|
|
630
|
-
var et = Object.defineProperty, tt = Object.getOwnPropertyDescriptor, S = (a, e, i, r) => {
|
|
631
|
-
for (var t = r > 1 ? void 0 : r ? tt(e, i) : e, s = a.length - 1, o; s >= 0; s--)
|
|
632
|
-
(o = a[s]) && (t = (r ? o(e, i, t) : o(t)) || t);
|
|
633
|
-
return r && t && et(e, i, t), t;
|
|
694
|
+
__decorateClass$3([
|
|
695
|
+
uniform()
|
|
696
|
+
], BloomPluginPass.prototype, "prefilter", 2);
|
|
697
|
+
__decorateClass$3([
|
|
698
|
+
uiSlider("Threshold", [0, 2]),
|
|
699
|
+
onChange(BloomPluginPass.prototype._thresholdsUpdated),
|
|
700
|
+
serialize()
|
|
701
|
+
], BloomPluginPass.prototype, "threshold", 2);
|
|
702
|
+
__decorateClass$3([
|
|
703
|
+
uiSlider("Soft Threshold", [0, 1]),
|
|
704
|
+
onChange(BloomPluginPass.prototype._thresholdsUpdated),
|
|
705
|
+
serialize()
|
|
706
|
+
], BloomPluginPass.prototype, "softThreshold", 2);
|
|
707
|
+
__decorateClass$3([
|
|
708
|
+
uiSlider("Intensity", [0, 3]),
|
|
709
|
+
serialize(),
|
|
710
|
+
uniform()
|
|
711
|
+
], BloomPluginPass.prototype, "intensity", 2);
|
|
712
|
+
__decorateClass$3([
|
|
713
|
+
uiToggle("Background Bloom"),
|
|
714
|
+
serialize(),
|
|
715
|
+
matDefineBool("BACKGROUND_BLOOM")
|
|
716
|
+
], BloomPluginPass.prototype, "backgroundBloom", 2);
|
|
717
|
+
__decorateClass$3([
|
|
718
|
+
uiSlider("Iterations", [2, 7], 1),
|
|
719
|
+
onChange2(BloomPluginPass.prototype._updateWeights),
|
|
720
|
+
serialize()
|
|
721
|
+
], BloomPluginPass.prototype, "bloomIterations", 2);
|
|
722
|
+
__decorateClass$3([
|
|
723
|
+
uiSlider("Radius", [0, 1], 0.01),
|
|
724
|
+
onChange2(BloomPluginPass.prototype._updateWeights),
|
|
725
|
+
serialize()
|
|
726
|
+
], BloomPluginPass.prototype, "radius", 2);
|
|
727
|
+
__decorateClass$3([
|
|
728
|
+
uiSlider("Power", [0.2, 10], 0.01),
|
|
729
|
+
onChange2(BloomPluginPass.prototype._updateWeights),
|
|
730
|
+
serialize()
|
|
731
|
+
], BloomPluginPass.prototype, "power", 2);
|
|
732
|
+
__decorateClass$3([
|
|
733
|
+
uiToggle("Debug")
|
|
734
|
+
], BloomPluginPass.prototype, "bloomDebug", 2);
|
|
735
|
+
BloomPluginPass = __decorateClass$3([
|
|
736
|
+
uiFolderContainer("Bloom Pass")
|
|
737
|
+
], BloomPluginPass);
|
|
738
|
+
const dofCombine = "#include <common>\n#include <packing>\nvarying vec2 vUv;uniform vec2 cocTextureSize;uniform vec2 nearFarBlurScale;uniform vec2 cameraNearFar;uniform vec2 focalDepthRange;uniform vec2 crossCenter;uniform float crossRadius;uniform float crossAlpha;uniform vec3 crossColor;float smoothBoundary(float d,float smooothFactor){smooothFactor*=0.5;float value=smoothstep(-smooothFactor,smooothFactor,d);return value;}float circle(vec2 p,float r){return min((length(p)-r),-(length(p)-r-0.01));}float computeCoc(){float depth=getDepth(vUv);if(depth>1.0-0.01)return max(nearFarBlurScale.x,nearFarBlurScale.y);depth=mix(cameraNearFar.x,cameraNearFar.y,depth);float coc=(depth-focalDepthRange.x)/focalDepthRange.y;coc=clamp(coc,-1.,1.);return(coc>0.0 ? coc*nearFarBlurScale.y : coc*nearFarBlurScale.x);}void main(){vec4 blur=blurTextureTexelToLinear(texture2D(blurTexture,vUv));float scale=0.5;blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(1.0,1.0)/cocTextureSize));blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(-1.0,1.0)/cocTextureSize));blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(-1.0,-1.0)/cocTextureSize));blur+=blurTextureTexelToLinear(texture2D(blurTexture,vUv+scale*vec2(1.0,-1.0)/cocTextureSize));blur/=5.0;vec2 uvNearest=(floor(vUv*cocTextureSize)+0.5)/cocTextureSize;float coc=abs(min(2.*cocTextureTexelToLinear(texture2D(cocTexture,uvNearest)).a-1.,computeCoc()));float cocLower=0.005;float cocHigher=0.3;vec4 outColor=vec4(mix(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,blur.rgb,smoothstep(cocLower,cocHigher,coc)),1.0);vec2 d=vUv-crossCenter;if(length(d)>crossRadius+0.05){float dist=circle(d,crossRadius);gl_FragColor=outColor;}else{d.x*=cocTextureSize.x/cocTextureSize.y;float dist=circle(d,crossRadius);dist=smoothBoundary(dist,2.*fwidth(dist));vec4 color=outColor;vec3 dofCircleColor=mix(crossColor,color.rgb,1.-crossAlpha);gl_FragColor=vec4(mix(color.rgb,dofCircleColor,dist),color.a);}\n#include <encodings_fragment>\n}";
|
|
739
|
+
const dofPoissonBox = "#include <randomHelpers>\n#include <common>\nvarying vec2 vUv;uniform vec2 colorTextureSize;uniform float blurRadius;uniform float frameCount;vec4 CircularBlur(){vec4 color=colorTextureTexelToLinear(texture2D(colorTexture,vUv));\n#ifdef DOF_MODE\nfloat blurDist=blurRadius*(2.*color.a-1.);\n#else\nfloat blurDist=blurRadius*color.a;\n#endif\nfloat rnd=PI2*random3(vec3(vUv,frameCount*0.1));float costheta=cos(rnd);float sintheta=sin(rnd);vec4 rotationMatrix=vec4(costheta,-sintheta,sintheta,costheta);vec3 colorSum=vec3(0.0);float weightSum=0.001;vec2 ofs;vec4 sampleColor;setPds();\n#pragma unroll_loop_start\nfor(int i=0;i<16;i++){ofs=poisson_disk_samples[UNROLLED_LOOP_INDEX];ofs=vec2(dot(ofs,rotationMatrix.xy),dot(ofs,rotationMatrix.zw));sampleColor=colorTextureTexelToLinear(texture2D(colorTexture,vUv+blurDist*ofs/colorTextureSize.xy));\n#ifdef DOF_MODE\nsampleColor.a=abs(sampleColor.a*2.0-1.0);sampleColor.a*=sampleColor.a*sampleColor.a;\n#endif\ncolorSum+=sampleColor.rgb*sampleColor.a;weightSum+=sampleColor.a;}\n#pragma unroll_loop_end\ncolorSum/=weightSum;return vec4(min(vec3(72.),max(vec3(0.),colorSum)),1.0);}void main(){gl_FragColor=CircularBlur();\n#include <encodings_fragment>\n}";
|
|
740
|
+
const poissonDiskSamples = "vec2 poisson_disk_samples[16];void setPds(){poisson_disk_samples[0]=vec2(-0.399691779231,0.728591545584);poisson_disk_samples[1]=vec2(-0.48622557676,-0.84016533712);poisson_disk_samples[2]=vec2(0.770309468987,-0.24906070432);poisson_disk_samples[3]=vec2(0.556596796154,0.820359876432);poisson_disk_samples[4]=vec2(-0.933902004071,0.0600539051593);poisson_disk_samples[5]=vec2(0.330144964342,0.207477293384);poisson_disk_samples[6]=vec2(0.289013230975,-0.686749271417);poisson_disk_samples[7]=vec2(-0.0832470893559,-0.187351643125);poisson_disk_samples[8]=vec2(-0.296314525615,0.254474834305);poisson_disk_samples[9]=vec2(-0.850977666059,0.484642744689);poisson_disk_samples[10]=vec2(0.829287915319,0.2345063545);poisson_disk_samples[11]=vec2(-0.773042143899,-0.543741521254);poisson_disk_samples[12]=vec2(0.0561133030864,0.928419742597);poisson_disk_samples[13]=vec2(-0.205799249508,-0.562072714492);poisson_disk_samples[14]=vec2(-0.526991665882,-0.193690188118);poisson_disk_samples[15]=vec2(-0.051789270667,-0.935374050821);}";
|
|
741
|
+
const dofComputeCoC = "#include <common>\n#include <packing>\nvarying vec2 vUv;uniform vec2 nearFarBlurScale;uniform vec2 cameraNearFar;uniform vec2 focalDepthRange;float computeCoc(){float depth=getDepth(vUv);if(depth==1.0)return max(nearFarBlurScale.x,nearFarBlurScale.y);depth=mix(cameraNearFar.x,cameraNearFar.y,depth);float coc=(depth-focalDepthRange.x)/focalDepthRange.y;coc=clamp(coc,-1.,1.);return(coc>0.0 ? coc*nearFarBlurScale.y : coc*nearFarBlurScale.x);}void main(){gl_FragColor=vec4(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,0.5*computeCoc()+0.5);\n#include <encodings_fragment>\n}";
|
|
742
|
+
const dofExpandCoC = "#include <common>\n#include <gbuffer_unpack>\nvarying vec2 vUv;uniform vec2 colorTextureSize;uniform vec2 direction;uniform vec2 nearFarBlurScale;const float MAXIMUM_BLUR_SIZE=4.0;float expandNear(const in vec2 offset,const in bool isBackground){float coc=0.0;vec2 sampleOffsets=MAXIMUM_BLUR_SIZE*offset/5.0;float coc0=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv)).a-1.;float coc1=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-5.0*sampleOffsets)).a-1.;float coc2=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-4.0*sampleOffsets)).a-1.;float coc3=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-3.0*sampleOffsets)).a-1.;float coc4=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-2.0*sampleOffsets)).a-1.;float coc5=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv-1.0*sampleOffsets)).a-1.;float coc6=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+1.0*sampleOffsets)).a-1.;float coc7=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+2.0*sampleOffsets)).a-1.;float coc8=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+3.0*sampleOffsets)).a-1.;float coc9=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+4.0*sampleOffsets)).a-1.;float coc10=2.*colorTextureTexelToLinear(texture2D(colorTexture,vUv+5.0*sampleOffsets)).a-1.;if(isBackground){coc=abs(coc0)*0.095474+(abs(coc1)+abs(coc10))*0.084264+(abs(coc2)+abs(coc9))*0.088139+(abs(coc3)+abs(coc8))*0.091276+(abs(coc4)+abs(coc7))*0.093585+(abs(coc5)+abs(coc6))*0.094998;}else{coc=min(coc0,0.0);coc=min(coc1*0.3,coc);coc=min(coc2*0.5,coc);coc=min(coc3*0.75,coc);coc=min(coc4*0.8,coc);coc=min(coc5*0.95,coc);coc=min(coc6*0.95,coc);coc=min(coc7*0.8,coc);coc=min(coc8*0.75,coc);coc=min(coc9*0.5,coc);coc=min(coc10*0.3,coc);if(abs(coc0)>abs(coc))coc=coc0;}return coc;}void main(){vec2 offset=2.*direction/colorTextureSize;bool isBackground=getDepth(vUv)>1.0-0.001;float coc=expandNear(offset,isBackground);gl_FragColor=vec4(colorTextureTexelToLinear(texture2D(colorTexture,vUv)).rgb,0.5*coc+0.5);\n#include <encodings_fragment>\n}";
|
|
743
|
+
var __defProp$2 = Object.defineProperty;
|
|
744
|
+
var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
|
|
745
|
+
var __decorateClass$2 = (decorators, target, key, kind) => {
|
|
746
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
|
|
747
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
748
|
+
if (decorator = decorators[i])
|
|
749
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
750
|
+
if (kind && result) __defProp$2(target, key, result);
|
|
751
|
+
return result;
|
|
634
752
|
};
|
|
635
|
-
const
|
|
753
|
+
const passId$1 = "depthOfField";
|
|
754
|
+
const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin {
|
|
636
755
|
// ms
|
|
637
|
-
constructor(
|
|
638
|
-
super()
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
756
|
+
constructor(enabled = true, enableEdit = false) {
|
|
757
|
+
super();
|
|
758
|
+
this.passId = passId$1;
|
|
759
|
+
this.enableEdit = false;
|
|
760
|
+
this._focalPointHit = new Vector3(0, 0, 0);
|
|
761
|
+
this.crossFadeTime = 200;
|
|
762
|
+
this._focalPointHitTime = 0;
|
|
763
|
+
this.dependencies = [GBufferPlugin];
|
|
764
|
+
this._onPluginAdd = (e) => {
|
|
765
|
+
var _a2, _b, _c, _d, _e;
|
|
766
|
+
const plugin = e.plugin;
|
|
767
|
+
if (!plugin) return;
|
|
768
|
+
if (((_a2 = plugin.constructor) == null ? void 0 : _a2.PluginType) === GBufferPlugin.PluginType) {
|
|
769
|
+
const gbuffer = plugin;
|
|
770
|
+
(_b = this._pass) == null ? void 0 : _b.material.registerMaterialExtensions([gbuffer.unpackExtension]);
|
|
771
|
+
(_c = this._pass) == null ? void 0 : _c.computeCocMaterial.registerMaterialExtensions([gbuffer.unpackExtension]);
|
|
772
|
+
(_d = this._pass) == null ? void 0 : _d.expandCocMaterial.registerMaterialExtensions([gbuffer.unpackExtension]);
|
|
647
773
|
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
if (t) {
|
|
652
|
-
if (((s = t.constructor) == null ? void 0 : s.PluginType) === T.PluginType) {
|
|
653
|
-
const g = r.plugin;
|
|
654
|
-
(o = this._pass) == null || o.material.unregisterMaterialExtensions([g.unpackExtension]), (n = this._pass) == null || n.computeCocMaterial.unregisterMaterialExtensions([g.unpackExtension]), (l = this._pass) == null || l.expandCocMaterial.unregisterMaterialExtensions([g.unpackExtension]);
|
|
655
|
-
}
|
|
656
|
-
((m = t.constructor) == null ? void 0 : m.PluginType) === j.PluginType && r.plugin.removeEventListener("hitObject", this._onObjectHit);
|
|
774
|
+
if (((_e = plugin.constructor) == null ? void 0 : _e.PluginType) === PickingPlugin.PluginType) {
|
|
775
|
+
const picking = plugin;
|
|
776
|
+
picking.addEventListener("hitObject", this._onObjectHit);
|
|
657
777
|
}
|
|
658
|
-
}
|
|
778
|
+
};
|
|
779
|
+
this._onPluginRemove = (e) => {
|
|
780
|
+
var _a2, _b, _c, _d, _e;
|
|
781
|
+
const plugin = e.plugin;
|
|
782
|
+
if (!plugin) return;
|
|
783
|
+
if (((_a2 = plugin.constructor) == null ? void 0 : _a2.PluginType) === GBufferPlugin.PluginType) {
|
|
784
|
+
const gbuffer = e.plugin;
|
|
785
|
+
(_b = this._pass) == null ? void 0 : _b.material.unregisterMaterialExtensions([gbuffer.unpackExtension]);
|
|
786
|
+
(_c = this._pass) == null ? void 0 : _c.computeCocMaterial.unregisterMaterialExtensions([gbuffer.unpackExtension]);
|
|
787
|
+
(_d = this._pass) == null ? void 0 : _d.expandCocMaterial.unregisterMaterialExtensions([gbuffer.unpackExtension]);
|
|
788
|
+
}
|
|
789
|
+
if (((_e = plugin.constructor) == null ? void 0 : _e.PluginType) === PickingPlugin.PluginType) {
|
|
790
|
+
const picking = e.plugin;
|
|
791
|
+
picking.removeEventListener("hitObject", this._onObjectHit);
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
this.uiConfig = {
|
|
659
795
|
type: "folder",
|
|
660
796
|
label: "DepthOfField",
|
|
661
797
|
onChange: this.setDirty.bind(this),
|
|
662
798
|
children: [
|
|
663
|
-
...
|
|
799
|
+
...generateUiConfig(this) || [],
|
|
664
800
|
() => {
|
|
665
|
-
var
|
|
666
|
-
return (
|
|
801
|
+
var _a2;
|
|
802
|
+
return (_a2 = this._pass) == null ? void 0 : _a2.uiConfig;
|
|
667
803
|
}
|
|
668
804
|
]
|
|
669
|
-
}
|
|
805
|
+
};
|
|
806
|
+
this._tempVec = new Vector3();
|
|
807
|
+
this.enabled = enabled;
|
|
808
|
+
this.enableEdit = enableEdit;
|
|
809
|
+
this._onObjectHit = this._onObjectHit.bind(this);
|
|
810
|
+
this.setDirty = this.setDirty.bind(this);
|
|
670
811
|
}
|
|
671
812
|
get _frameFadeTime() {
|
|
672
813
|
return this.crossFadeTime * 2.5;
|
|
673
814
|
}
|
|
674
815
|
// todo make this a property.
|
|
675
|
-
setFocalPoint(
|
|
676
|
-
var
|
|
677
|
-
this._focalPointHit.copy(
|
|
816
|
+
setFocalPoint(p, fade = true, showGizmo = false) {
|
|
817
|
+
var _a2, _b;
|
|
818
|
+
this._focalPointHit.copy(p);
|
|
819
|
+
if (fade) (_b = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin("FrameFadePlugin")) == null ? void 0 : _b.startTransition(this._frameFadeTime);
|
|
820
|
+
if (showGizmo) this._focalPointHitTime = now();
|
|
821
|
+
this.setDirty();
|
|
678
822
|
}
|
|
679
823
|
getFocalPoint() {
|
|
680
824
|
return this._focalPointHit;
|
|
681
825
|
}
|
|
682
826
|
_onObjectHit(e) {
|
|
683
|
-
var
|
|
684
|
-
!this._pass || !e.intersects.intersect || this.isDisabled() || !this.enableEdit
|
|
827
|
+
var _a2, _b;
|
|
828
|
+
if (!this._pass || !e.intersects.intersect || this.isDisabled() || !this.enableEdit) return;
|
|
829
|
+
this._focalPointHit.copy(e.intersects.intersect.point);
|
|
830
|
+
this._focalPointHitTime = e.time;
|
|
831
|
+
e.intersects.selectedObject = null;
|
|
832
|
+
(_b = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(FrameFadePlugin)) == null ? void 0 : _b.startTransition(this._frameFadeTime);
|
|
833
|
+
this.setDirty();
|
|
685
834
|
}
|
|
686
835
|
_createPass() {
|
|
687
|
-
|
|
836
|
+
const pass = new DepthOfFieldPluginPass(this.passId);
|
|
837
|
+
return pass;
|
|
688
838
|
}
|
|
689
839
|
// todo use gbufferUnpackExtension from render manager to support depth buffer plugin as well.
|
|
690
|
-
onAdded(
|
|
691
|
-
super.onAdded(
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
if (
|
|
709
|
-
|
|
710
|
-
|
|
840
|
+
onAdded(viewer) {
|
|
841
|
+
super.onAdded(viewer);
|
|
842
|
+
viewer.addEventListener("addPlugin", this._onPluginAdd);
|
|
843
|
+
viewer.addEventListener("removePlugin", this._onPluginRemove);
|
|
844
|
+
this._onPluginAdd({ plugin: viewer.getPlugin(GBufferPlugin) });
|
|
845
|
+
this._onPluginAdd({ plugin: viewer.getPlugin(PickingPlugin) });
|
|
846
|
+
}
|
|
847
|
+
onRemove(viewer) {
|
|
848
|
+
viewer.removeEventListener("addPlugin", this._onPluginAdd);
|
|
849
|
+
viewer.removeEventListener("removePlugin", this._onPluginRemove);
|
|
850
|
+
this._onPluginRemove({ plugin: viewer.getPlugin(GBufferPlugin) });
|
|
851
|
+
this._onPluginRemove({ plugin: viewer.getPlugin(PickingPlugin) });
|
|
852
|
+
super.onRemove(viewer);
|
|
853
|
+
}
|
|
854
|
+
_beforeRender(scene, camera, renderManager) {
|
|
855
|
+
if (!super._beforeRender(scene, camera, renderManager)) return false;
|
|
856
|
+
const pass = this.pass;
|
|
857
|
+
if (!pass) return false;
|
|
858
|
+
if (pass.dofBlurMaterial.uniforms.frameCount)
|
|
859
|
+
renderManager == null ? void 0 : renderManager.updateShaderProperties(pass.dofBlurMaterial);
|
|
860
|
+
const cam = camera;
|
|
861
|
+
if (!cam) return false;
|
|
862
|
+
cam.updateMatrixWorld(true);
|
|
863
|
+
cam.updateShaderProperties(pass.material);
|
|
864
|
+
cam.getWorldPosition(this._tempVec);
|
|
865
|
+
this._tempVec.subVectors(this._focalPointHit, this._tempVec);
|
|
866
|
+
pass.focalDepthRange.x = this._tempVec.length();
|
|
867
|
+
pass.focalDepthRange.x *= cam.getWorldDirection(new Vector3()).dot(this._tempVec.normalize());
|
|
868
|
+
let crossAlpha = (now() - this._focalPointHitTime) / this.crossFadeTime;
|
|
869
|
+
crossAlpha = 1 - Math.min(1, Math.max(0, crossAlpha));
|
|
870
|
+
if (Math.abs(crossAlpha - pass.crossAlpha) > 0.01) {
|
|
871
|
+
pass.crossAlpha = crossAlpha;
|
|
872
|
+
this.setDirty();
|
|
873
|
+
}
|
|
874
|
+
if (crossAlpha > 0) {
|
|
875
|
+
const projectedPoint = this._tempVec.copy(this._focalPointHit).project(cam).addScalar(1).divideScalar(2);
|
|
876
|
+
pass.crossCenter.set(projectedPoint.x, projectedPoint.y);
|
|
877
|
+
pass.computeCocMaterial.uniformsNeedUpdate = true;
|
|
878
|
+
pass.expandCocMaterial.uniformsNeedUpdate = true;
|
|
711
879
|
}
|
|
712
|
-
return
|
|
880
|
+
return true;
|
|
713
881
|
}
|
|
714
882
|
// region to be done or removed
|
|
715
883
|
// static AddDepthOfFieldData(material: IMaterial, params?: IMaterialUserData['DepthOfField'], setDirty = true): IMaterialUserData['DepthOfField']|null {
|
|
@@ -789,174 +957,213 @@ const rt = "depthOfField", W = class W extends I {
|
|
|
789
957
|
// }
|
|
790
958
|
// endregion
|
|
791
959
|
};
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
960
|
+
_DepthOfFieldPlugin.PluginType = "DepthOfField";
|
|
961
|
+
_DepthOfFieldPlugin.OldPluginType = "DepthOfFieldPlugin";
|
|
962
|
+
let DepthOfFieldPlugin = _DepthOfFieldPlugin;
|
|
963
|
+
__decorateClass$2([
|
|
964
|
+
serialize(),
|
|
965
|
+
uiToggle()
|
|
966
|
+
], DepthOfFieldPlugin.prototype, "enableEdit", 2);
|
|
967
|
+
__decorateClass$2([
|
|
968
|
+
serialize("focalPoint")
|
|
969
|
+
], DepthOfFieldPlugin.prototype, "_focalPointHit", 2);
|
|
970
|
+
__decorateClass$2([
|
|
971
|
+
serialize()
|
|
972
|
+
], DepthOfFieldPlugin.prototype, "crossFadeTime", 2);
|
|
973
|
+
const dofBlurMaterialPoisson = new ExtendedShaderMaterial({
|
|
805
974
|
uniforms: {
|
|
806
975
|
colorTexture: { value: null },
|
|
807
|
-
colorTextureSize: { value: new
|
|
808
|
-
direction: { value: new
|
|
976
|
+
colorTextureSize: { value: new Vector2() },
|
|
977
|
+
direction: { value: new Vector2() },
|
|
809
978
|
frameCount: { value: 0 },
|
|
810
979
|
blurRadius: { value: 16 }
|
|
811
980
|
},
|
|
812
|
-
vertexShader:
|
|
813
|
-
fragmentShader:
|
|
814
|
-
` + Ze,
|
|
981
|
+
vertexShader: shaderUtils.defaultVertex,
|
|
982
|
+
fragmentShader: poissonDiskSamples + "\n" + dofPoissonBox,
|
|
815
983
|
defines: {
|
|
816
|
-
DOF_MODE: 1
|
|
984
|
+
["DOF_MODE"]: 1
|
|
817
985
|
}
|
|
818
986
|
}, ["colorTexture"]);
|
|
819
|
-
let
|
|
820
|
-
constructor(
|
|
987
|
+
let DepthOfFieldPluginPass = class extends ExtendedShaderPass {
|
|
988
|
+
constructor(pid) {
|
|
821
989
|
super({
|
|
822
990
|
uniforms: {
|
|
823
991
|
colorTexture: { value: null },
|
|
824
992
|
blurTexture: { value: null },
|
|
825
993
|
cocTexture: { value: null },
|
|
826
|
-
cocTextureSize: { value: new
|
|
827
|
-
cameraNearFar: { value: new
|
|
994
|
+
cocTextureSize: { value: new Vector2() },
|
|
995
|
+
cameraNearFar: { value: new Vector2() }
|
|
828
996
|
},
|
|
829
|
-
vertexShader:
|
|
830
|
-
fragmentShader:
|
|
831
|
-
}, "colorTexture", "cocTexture", "blurTexture")
|
|
997
|
+
vertexShader: shaderUtils.defaultVertex,
|
|
998
|
+
fragmentShader: dofCombine
|
|
999
|
+
}, "colorTexture", "cocTexture", "blurTexture");
|
|
1000
|
+
this.uiConfig = void 0;
|
|
1001
|
+
this.before = ["progressive", "screen"];
|
|
1002
|
+
this.after = ["render"];
|
|
1003
|
+
this.required = ["render"];
|
|
1004
|
+
this.dofBlurMaterial = dofBlurMaterialPoisson;
|
|
1005
|
+
this.nearFarBlurScale = new Vector2(0.25, 0.25);
|
|
1006
|
+
this.focalDepthRange = new Vector2(0.5, 1.5);
|
|
1007
|
+
this.crossCenter = new Vector2(0.5, 0.5);
|
|
1008
|
+
this.crossRadius = 0.04;
|
|
1009
|
+
this.crossAlpha = 1;
|
|
1010
|
+
this.crossColor = new Color(16750848);
|
|
1011
|
+
this.passId = pid;
|
|
1012
|
+
this.computeCocMaterial = new ExtendedShaderMaterial({
|
|
832
1013
|
uniforms: {
|
|
833
1014
|
colorTexture: { value: null },
|
|
834
1015
|
cameraNearFar: this.uniforms.cameraNearFar,
|
|
835
1016
|
nearFarBlurScale: this.uniforms.nearFarBlurScale,
|
|
836
1017
|
focalDepthRange: this.uniforms.focalDepthRange
|
|
837
1018
|
},
|
|
838
|
-
vertexShader:
|
|
839
|
-
fragmentShader:
|
|
840
|
-
}, ["colorTexture"])
|
|
1019
|
+
vertexShader: shaderUtils.defaultVertex,
|
|
1020
|
+
fragmentShader: dofComputeCoC
|
|
1021
|
+
}, ["colorTexture"]);
|
|
1022
|
+
this.expandCocMaterial = new ExtendedShaderMaterial({
|
|
841
1023
|
uniforms: {
|
|
842
1024
|
colorTexture: { value: null },
|
|
843
|
-
colorTextureSize: { value: new
|
|
844
|
-
direction: { value: new
|
|
1025
|
+
colorTextureSize: { value: new Vector2() },
|
|
1026
|
+
direction: { value: new Vector2() },
|
|
845
1027
|
nearFarBlurScale: this.uniforms.nearFarBlurScale
|
|
846
1028
|
},
|
|
847
|
-
vertexShader:
|
|
848
|
-
fragmentShader:
|
|
1029
|
+
vertexShader: shaderUtils.defaultVertex,
|
|
1030
|
+
fragmentShader: dofExpandCoC
|
|
849
1031
|
}, ["colorTexture"]);
|
|
850
1032
|
}
|
|
851
|
-
render(
|
|
852
|
-
if (!this.enabled)
|
|
853
|
-
|
|
854
|
-
if (!i) {
|
|
1033
|
+
render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
|
|
1034
|
+
if (!this.enabled) return;
|
|
1035
|
+
if (!readBuffer) {
|
|
855
1036
|
console.error("DepthOfFieldPluginPass: No readBuffer");
|
|
856
1037
|
return;
|
|
857
1038
|
}
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
|
|
1039
|
+
const renderManager = renderer.renderManager;
|
|
1040
|
+
const halfPars = {
|
|
1041
|
+
minFilter: NearestFilter,
|
|
1042
|
+
magFilter: NearestFilter,
|
|
861
1043
|
// type: UnsignedByteType,
|
|
862
1044
|
// encoding: RGBM16Encoding,
|
|
863
|
-
type:
|
|
1045
|
+
type: HalfFloatType,
|
|
864
1046
|
// encoding: LinearEncoding,
|
|
865
|
-
colorSpace:
|
|
1047
|
+
colorSpace: LinearSRGBColorSpace,
|
|
866
1048
|
sizeMultiplier: 0.5,
|
|
867
1049
|
// samples: 1,
|
|
868
|
-
format:
|
|
869
|
-
depthBuffer:
|
|
870
|
-
generateMipmaps:
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
1050
|
+
format: RGBAFormat,
|
|
1051
|
+
depthBuffer: false,
|
|
1052
|
+
generateMipmaps: false
|
|
1053
|
+
};
|
|
1054
|
+
const cocRt = renderManager.getTempTarget(halfPars);
|
|
1055
|
+
const renderTargetBlurTemp = renderManager.getTempTarget(halfPars);
|
|
1056
|
+
this.computeCocMaterial.uniforms.colorTexture.value = readBuffer.texture;
|
|
1057
|
+
renderManager.blit(cocRt, { material: this.computeCocMaterial });
|
|
1058
|
+
this.expandCocMaterial.uniforms.colorTexture.value = cocRt.texture;
|
|
1059
|
+
this.expandCocMaterial.uniforms.direction.value.set(1, 0);
|
|
1060
|
+
renderManager.blit(renderTargetBlurTemp, { material: this.expandCocMaterial });
|
|
1061
|
+
this.expandCocMaterial.uniforms.colorTexture.value = renderTargetBlurTemp.texture;
|
|
1062
|
+
this.expandCocMaterial.uniforms.direction.value.set(0, 1);
|
|
1063
|
+
renderManager.blit(cocRt, { material: this.expandCocMaterial });
|
|
1064
|
+
if (this.dofBlurMaterial.uniforms.frameCount) {
|
|
1065
|
+
this.dofBlurMaterial.uniforms.colorTexture.value = cocRt.texture;
|
|
1066
|
+
renderManager.blit(renderTargetBlurTemp, { material: this.dofBlurMaterial });
|
|
1067
|
+
} else {
|
|
1068
|
+
const renderTargetBlurTemp2 = renderManager.getTempTarget(halfPars);
|
|
1069
|
+
this.dofBlurMaterial.uniforms.cocTexture.value = cocRt.texture;
|
|
1070
|
+
this.dofBlurMaterial.uniforms.colorTexture.value = cocRt.texture;
|
|
1071
|
+
this.dofBlurMaterial.uniforms.direction.value.set(1, 0);
|
|
1072
|
+
renderManager.blit(renderTargetBlurTemp2, { material: this.dofBlurMaterial });
|
|
1073
|
+
this.dofBlurMaterial.uniforms.colorTexture.value = renderTargetBlurTemp2.texture;
|
|
1074
|
+
this.dofBlurMaterial.uniforms.direction.value.set(0, 1);
|
|
1075
|
+
renderManager.blit(renderTargetBlurTemp, { material: this.dofBlurMaterial });
|
|
1076
|
+
renderManager.releaseTempTarget(renderTargetBlurTemp2);
|
|
877
1077
|
}
|
|
878
|
-
this.material.uniforms.blurTexture.value =
|
|
1078
|
+
this.material.uniforms.blurTexture.value = renderTargetBlurTemp.texture;
|
|
1079
|
+
this.material.uniforms.cocTexture.value = cocRt.texture;
|
|
1080
|
+
super.render(renderer, writeBuffer, readBuffer, deltaTime, maskActive);
|
|
1081
|
+
renderManager.releaseTempTarget(cocRt);
|
|
1082
|
+
renderManager.releaseTempTarget(renderTargetBlurTemp);
|
|
879
1083
|
}
|
|
880
1084
|
};
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
],
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
],
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
],
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
],
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
],
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
],
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
],
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
],
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
],
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
],
|
|
916
|
-
const
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
}vec3 traceRay(in vec3 ray_origin_view,in vec3 ray_dir_view,in float tolerance,inout vec3 state,in int _STEP_COUNT){vec4 sample_uv;vec4 ray_origin=viewToScreen3(ray_origin_view);vec3 ray_end_view=ray_origin_view+ray_dir_view;vec4 ray_dir=viewToScreen3(ray_end_view);vec2 clamp_end=clamp(ray_dir.xy,vec2(0.),vec2(1.));vec2 correction=abs(ray_dir.xy-clamp_end);correction=(step(0.01,correction)*correction/(abs(clamp_end-ray_origin.xy)+0.01))+1.;correction.x=1./min(max(correction.y,correction.x),10.);ray_dir=ray_dir-ray_origin;ray_dir.xyw*=correction.x;float iStepCount=1./float(_STEP_COUNT);tolerance*=0.125;_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT,iStepCount);if(_STEP_COUNT>8&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-8,iStepCount);if(_STEP_COUNT>15&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-16,iStepCount);if(_STEP_COUNT>23&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-16,iStepCount);sample_uv=ray_origin+ray_dir*state.z;sample_uv.z/=sample_uv.w;state.z=state.z<0.999 ? state.z : 9999999.;return sample_uv.xyz;}/**for ray clippinga=ray_originb=ray_endc=clamp(b)x=c.y-a.yy=b.y-c.y(c.y-a.y)/(b.y-c.y)=m/(l-m)m/(l-m)=km=kl-kmm=kl/(1+k)((c-a)/(b-c))/(1+(c-a)/(b-c))x/(y*(1+x/y))x/(y+x)1/(y/x+1)x/(y+yx)1/(y/x+y)ray scale=k/(1+k)1/(1/k+1)=1/((b-c)/(c-a)+1)**/
|
|
927
|
-
#endif
|
|
928
|
-
`;
|
|
929
|
-
var at = Object.defineProperty, st = Object.getOwnPropertyDescriptor, F = (a, e, i, r) => {
|
|
930
|
-
for (var t = r > 1 ? void 0 : r ? st(e, i) : e, s = a.length - 1, o; s >= 0; s--)
|
|
931
|
-
(o = a[s]) && (t = (r ? o(e, i, t) : o(t)) || t);
|
|
932
|
-
return r && t && at(e, i, t), t;
|
|
1085
|
+
__decorateClass$2([
|
|
1086
|
+
bindToValue({ obj: "focalDepthRange", key: "y" }),
|
|
1087
|
+
uiSlider("Depth Range", [0.25, 3])
|
|
1088
|
+
], DepthOfFieldPluginPass.prototype, "depthRange", 2);
|
|
1089
|
+
__decorateClass$2([
|
|
1090
|
+
bindToValue({ obj: "nearFarBlurScale", key: "x" }),
|
|
1091
|
+
uiSlider("Near Blur Scale", [0, 1])
|
|
1092
|
+
], DepthOfFieldPluginPass.prototype, "nearBlurScale", 2);
|
|
1093
|
+
__decorateClass$2([
|
|
1094
|
+
bindToValue({ obj: "nearFarBlurScale", key: "y" }),
|
|
1095
|
+
uiSlider("Far Blur Scale", [0, 1])
|
|
1096
|
+
], DepthOfFieldPluginPass.prototype, "farBlurScale", 2);
|
|
1097
|
+
__decorateClass$2([
|
|
1098
|
+
serialize(),
|
|
1099
|
+
uniform()
|
|
1100
|
+
], DepthOfFieldPluginPass.prototype, "nearFarBlurScale", 2);
|
|
1101
|
+
__decorateClass$2([
|
|
1102
|
+
serialize(),
|
|
1103
|
+
uniform()
|
|
1104
|
+
], DepthOfFieldPluginPass.prototype, "focalDepthRange", 2);
|
|
1105
|
+
__decorateClass$2([
|
|
1106
|
+
uniform()
|
|
1107
|
+
], DepthOfFieldPluginPass.prototype, "crossCenter", 2);
|
|
1108
|
+
__decorateClass$2([
|
|
1109
|
+
uniform()
|
|
1110
|
+
], DepthOfFieldPluginPass.prototype, "crossRadius", 2);
|
|
1111
|
+
__decorateClass$2([
|
|
1112
|
+
uniform()
|
|
1113
|
+
], DepthOfFieldPluginPass.prototype, "crossAlpha", 2);
|
|
1114
|
+
__decorateClass$2([
|
|
1115
|
+
uniform()
|
|
1116
|
+
], DepthOfFieldPluginPass.prototype, "crossColor", 2);
|
|
1117
|
+
DepthOfFieldPluginPass = __decorateClass$2([
|
|
1118
|
+
uiFolderContainer("DepthOfField Pass")
|
|
1119
|
+
], DepthOfFieldPluginPass);
|
|
1120
|
+
const ssrtShader = "#ifndef SSRT_PARS_SNIP\n#define SSRT_PARS_SNIP\n#define pow2(a) a*a\nfloat getDepth2(const in vec2 uv,const in float lod){float viewDepth=getDepth(uv);return depthToViewZ(viewDepth);}\n#define LOD_DEPTH 1.0\n#define LOD_COLOR 5.0\nvoid _traceRay(in vec4 ray_origin,in vec4 ray_dir,in float tolerance,inout vec3 state,in int loopMax,in float iStepCount){vec4 sample_uv;float d,hit;float dLod=0.;\n#pragma unroll_loop_start\nfor(int i=0;i<8;i++){if(UNROLLED_LOOP_INDEX<loopMax){sample_uv=ray_origin+ray_dir*state.y;d=getDepth2(sample_uv.xy,dLod);d=sample_uv.z/sample_uv.w-d;if(abs(d+tolerance)<tolerance){hit=clamp(state.x/(state.x-d),0.,1.)-1.;hit=(state.y+hit*iStepCount);state.z=min(state.z,hit);}state.x=d;state.y+=1.*iStepCount;}}\n#pragma unroll_loop_end\n}vec3 traceRay(in vec3 ray_origin_view,in vec3 ray_dir_view,in float tolerance,inout vec3 state,in int _STEP_COUNT){vec4 sample_uv;vec4 ray_origin=viewToScreen3(ray_origin_view);vec3 ray_end_view=ray_origin_view+ray_dir_view;vec4 ray_dir=viewToScreen3(ray_end_view);vec2 clamp_end=clamp(ray_dir.xy,vec2(0.),vec2(1.));vec2 correction=abs(ray_dir.xy-clamp_end);correction=(step(0.01,correction)*correction/(abs(clamp_end-ray_origin.xy)+0.01))+1.;correction.x=1./min(max(correction.y,correction.x),10.);ray_dir=ray_dir-ray_origin;ray_dir.xyw*=correction.x;float iStepCount=1./float(_STEP_COUNT);tolerance*=0.125;_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT,iStepCount);if(_STEP_COUNT>8&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-8,iStepCount);if(_STEP_COUNT>15&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-16,iStepCount);if(_STEP_COUNT>23&&state.z>0.98)_traceRay(ray_origin,ray_dir,tolerance,state,_STEP_COUNT-16,iStepCount);sample_uv=ray_origin+ray_dir*state.z;sample_uv.z/=sample_uv.w;state.z=state.z<0.999 ? state.z : 9999999.;return sample_uv.xyz;}/**for ray clippinga=ray_originb=ray_endc=clamp(b)x=c.y-a.yy=b.y-c.y(c.y-a.y)/(b.y-c.y)=m/(l-m)m/(l-m)=km=kl-kmm=kl/(1+k)((c-a)/(b-c))/(1+(c-a)/(b-c))x/(y*(1+x/y))x/(y+x)1/(y/x+1)x/(y+yx)1/(y/x+y)ray scale=k/(1+k)1/(1/k+1)=1/((b-c)/(c-a)+1)**/\n#endif\n";
|
|
1121
|
+
var __defProp$1 = Object.defineProperty;
|
|
1122
|
+
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
1123
|
+
var __decorateClass$1 = (decorators, target, key, kind) => {
|
|
1124
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
|
|
1125
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1126
|
+
if (decorator = decorators[i])
|
|
1127
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
1128
|
+
if (kind && result) __defProp$1(target, key, result);
|
|
1129
|
+
return result;
|
|
933
1130
|
};
|
|
934
|
-
let
|
|
1131
|
+
let SSContactShadowsPlugin = class extends AViewerPluginSync {
|
|
935
1132
|
// private _loaderCreate({loader}: {loader: GLTFLoader2}) {
|
|
936
1133
|
// if (!loader.isGLTFLoader2) return
|
|
937
1134
|
// loader.register((p) => new GLTFMaterialsSSContactShadowsExtensionImport(p))
|
|
938
1135
|
// }
|
|
939
|
-
constructor(
|
|
940
|
-
super()
|
|
1136
|
+
constructor(enabled = true) {
|
|
1137
|
+
super();
|
|
1138
|
+
this.enabled = true;
|
|
1139
|
+
this._uniforms = {
|
|
941
1140
|
sscsRadius: { value: 0.03 },
|
|
942
1141
|
sscsIntensity: { value: 1 },
|
|
943
1142
|
sscsTolerance: { value: 1.5 },
|
|
944
1143
|
// tLastFrame: {value: null}, // not needed since we dont need color
|
|
945
1144
|
frameCount: { value: 0 },
|
|
946
|
-
projection: { value: new
|
|
947
|
-
cameraPositionWorld: { value: new
|
|
948
|
-
cameraNearFar: { value: new
|
|
1145
|
+
projection: { value: new Matrix4() },
|
|
1146
|
+
cameraPositionWorld: { value: new Vector3() },
|
|
1147
|
+
cameraNearFar: { value: new Vector2(0.1, 1e3) },
|
|
949
1148
|
sceneBoundingRadius: { value: 0 }
|
|
950
|
-
}
|
|
951
|
-
|
|
1149
|
+
};
|
|
1150
|
+
this.radius = 0.015;
|
|
1151
|
+
this.intensity = 1;
|
|
1152
|
+
this.tolerance = 1.5;
|
|
1153
|
+
this._defines = {
|
|
1154
|
+
["PERSPECTIVE_CAMERA"]: 1
|
|
952
1155
|
// set in PerspectiveCamera2
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
1156
|
+
};
|
|
1157
|
+
this.onlySSCSDebug = false;
|
|
1158
|
+
this.stepCount = 2;
|
|
1159
|
+
this.dependencies = [GBufferPlugin];
|
|
1160
|
+
this.materialExtension = {
|
|
1161
|
+
uuid: SSContactShadowsPlugin.PluginType,
|
|
1162
|
+
shaderExtender: (shader, _material, _renderer) => {
|
|
1163
|
+
var _a2, _b;
|
|
1164
|
+
if (!shader.defines.SSCS_ENABLED) return;
|
|
1165
|
+
const rsS = "float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {";
|
|
1166
|
+
const lsS = glsl`
|
|
960
1167
|
#ifndef D_sceneBoundingRadius
|
|
961
1168
|
#define D_sceneBoundingRadius
|
|
962
1169
|
uniform float sceneBoundingRadius;
|
|
@@ -974,7 +1181,8 @@ let p = class extends Me {
|
|
|
974
1181
|
#if defined(SSCS_DEBUG) && SSCS_DEBUG > 0
|
|
975
1182
|
return state.z;
|
|
976
1183
|
#endif
|
|
977
|
-
|
|
1184
|
+
`;
|
|
1185
|
+
const shadowChunk = `
|
|
978
1186
|
#if SSCS_ENABLED
|
|
979
1187
|
|
|
980
1188
|
uniform float sscsIntensity;
|
|
@@ -984,37 +1192,44 @@ let p = class extends Me {
|
|
|
984
1192
|
#define THREE_PACKING_INCLUDED // by threejs
|
|
985
1193
|
#include <cameraHelpers>
|
|
986
1194
|
#include <randomHelpers>
|
|
987
|
-
${
|
|
1195
|
+
${ssrtShader}
|
|
988
1196
|
|
|
989
1197
|
#endif
|
|
990
|
-
|
|
991
|
-
` + B(ae.shadowmap_pars_fragment, t, `${s}
|
|
1198
|
+
` + shaderReplaceString(ShaderChunk.shadowmap_pars_fragment, rsS, `${lsS}
|
|
992
1199
|
`).replace("return shadow;", "return min(shadow, state.z);");
|
|
993
|
-
|
|
994
|
-
|
|
1200
|
+
shader.fragmentShader = shaderReplaceString(shader.fragmentShader, "#include <shadowmap_pars_fragment>", shadowChunk);
|
|
1201
|
+
shader.fragmentShader = shader.fragmentShader.replace("#include <lights_fragment_begin>", ShaderChunk.lights_fragment_begin);
|
|
1202
|
+
shader.fragmentShader = shaderReplaceString(
|
|
1203
|
+
shader.fragmentShader,
|
|
995
1204
|
"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;",
|
|
996
1205
|
"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ], directLight.direction ) : 1.0;"
|
|
997
|
-
)
|
|
998
|
-
|
|
1206
|
+
);
|
|
1207
|
+
shader.fragmentShader = shaderReplaceString(
|
|
1208
|
+
shader.fragmentShader,
|
|
999
1209
|
"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;",
|
|
1000
1210
|
"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ], directLight.direction ) : 1.0;"
|
|
1001
|
-
)
|
|
1211
|
+
);
|
|
1212
|
+
(_b = (_a2 = this._gbufferUnpackExtension) == null ? void 0 : _a2.shaderExtender) == null ? void 0 : _b.call(_a2, shader, _material, _renderer);
|
|
1002
1213
|
},
|
|
1003
|
-
onObjectRender: (
|
|
1004
|
-
var
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1214
|
+
onObjectRender: (_, material, renderer) => {
|
|
1215
|
+
var _a2, _b;
|
|
1216
|
+
const enabled2 = this.enabled && renderer.userData.screenSpaceRendering !== false && !((_a2 = material.userData) == null ? void 0 : _a2.pluginsDisabled) && !((_b = material.userData) == null ? void 0 : _b.sscsDisabled) ? 1 : 0;
|
|
1217
|
+
updateMaterialDefines({
|
|
1007
1218
|
...this._defines,
|
|
1008
|
-
SSCS_ENABLED:
|
|
1009
|
-
},
|
|
1219
|
+
["SSCS_ENABLED"]: enabled2
|
|
1220
|
+
}, material);
|
|
1010
1221
|
},
|
|
1011
1222
|
extraUniforms: {
|
|
1012
1223
|
...this._uniforms
|
|
1013
1224
|
// todo should not be static because of multiple viewers
|
|
1014
1225
|
},
|
|
1015
1226
|
extraDefines: {},
|
|
1016
|
-
computeCacheKey: (
|
|
1017
|
-
|
|
1227
|
+
computeCacheKey: (_) => {
|
|
1228
|
+
return this.isDisabled() ? "0" : "1";
|
|
1229
|
+
},
|
|
1230
|
+
isCompatible: (material1) => {
|
|
1231
|
+
return material1.isPhysicalMaterial;
|
|
1232
|
+
},
|
|
1018
1233
|
// getUiConfig: (material: PhysicalMaterial) => {
|
|
1019
1234
|
// const viewer = this._viewer!
|
|
1020
1235
|
// if (material.userData._clearcoatTint === undefined) material.userData._clearcoatTint = {}
|
|
@@ -1069,185 +1284,210 @@ let p = class extends Me {
|
|
|
1069
1284
|
// return config
|
|
1070
1285
|
// },
|
|
1071
1286
|
updaters: () => {
|
|
1072
|
-
var
|
|
1287
|
+
var _a2, _b, _c, _d;
|
|
1073
1288
|
return [
|
|
1074
1289
|
// this._viewer?.getPlugin(GBufferPlugin),
|
|
1075
|
-
(
|
|
1076
|
-
(
|
|
1077
|
-
(
|
|
1078
|
-
(
|
|
1290
|
+
(_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(ProgressivePlugin),
|
|
1291
|
+
(_b = this._viewer) == null ? void 0 : _b.scene.renderCamera,
|
|
1292
|
+
(_c = this._viewer) == null ? void 0 : _c.renderManager,
|
|
1293
|
+
(_d = this._viewer) == null ? void 0 : _d.scene
|
|
1079
1294
|
];
|
|
1080
1295
|
}
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1296
|
+
};
|
|
1297
|
+
this._gbufferUnpackExtension = void 0;
|
|
1298
|
+
this._gbufferUnpackExtensionChanged = () => {
|
|
1299
|
+
if (!this._viewer) throw new Error("SSContactShadowPlugin: pass/viewer not created yet");
|
|
1300
|
+
const newExtension = this._viewer.renderManager.gbufferUnpackExtension;
|
|
1301
|
+
if (this._gbufferUnpackExtension === newExtension) return;
|
|
1302
|
+
if (this._gbufferUnpackExtension) this.setGBufferUnpackExtension(void 0);
|
|
1303
|
+
this._gbufferUnpackExtension = newExtension;
|
|
1304
|
+
if (this._gbufferUnpackExtension) this.setGBufferUnpackExtension(this._gbufferUnpackExtension);
|
|
1305
|
+
else this._viewer.console.warn("SSContactShadowPlugin: GBuffer unpack extension removed");
|
|
1306
|
+
};
|
|
1307
|
+
this.enabled = enabled;
|
|
1087
1308
|
}
|
|
1088
1309
|
setDirty() {
|
|
1089
|
-
var
|
|
1090
|
-
(
|
|
1310
|
+
var _a2, _b, _c;
|
|
1311
|
+
(_b = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b.call(_a2);
|
|
1312
|
+
(_c = this._viewer) == null ? void 0 : _c.setDirty();
|
|
1091
1313
|
}
|
|
1092
|
-
onAdded(
|
|
1093
|
-
super.onAdded(
|
|
1314
|
+
onAdded(v) {
|
|
1315
|
+
super.onAdded(v);
|
|
1316
|
+
v.assetManager.materials.registerMaterialExtension(this.materialExtension);
|
|
1317
|
+
if (v.getPlugin(BaseGroundPlugin)) v.getPlugin(BaseGroundPlugin).material.userData.sscsDisabled = false;
|
|
1318
|
+
this._gbufferUnpackExtensionChanged();
|
|
1319
|
+
v.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
|
|
1094
1320
|
}
|
|
1095
|
-
onRemove(
|
|
1096
|
-
var
|
|
1097
|
-
|
|
1321
|
+
onRemove(v) {
|
|
1322
|
+
var _a2;
|
|
1323
|
+
(_a2 = v.assetManager.materials) == null ? void 0 : _a2.unregisterMaterialExtension(this.materialExtension);
|
|
1324
|
+
v.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
|
|
1325
|
+
return super.onRemove(v);
|
|
1098
1326
|
}
|
|
1099
|
-
setGBufferUnpackExtension(
|
|
1100
|
-
this._gbufferUnpackExtension =
|
|
1327
|
+
setGBufferUnpackExtension(extension) {
|
|
1328
|
+
this._gbufferUnpackExtension = extension;
|
|
1329
|
+
if (!this._gbufferUnpackExtension) return;
|
|
1330
|
+
Object.assign(this.materialExtension.extraUniforms, this._gbufferUnpackExtension.extraUniforms);
|
|
1331
|
+
Object.assign(this.materialExtension.extraDefines, this._gbufferUnpackExtension.extraDefines);
|
|
1101
1332
|
}
|
|
1102
1333
|
// public static readonly CLEARCOAT_TINT_GLTF_EXTENSION = 'WEBGI_materials_clearcoat_tint'
|
|
1103
1334
|
};
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
],
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
],
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
],
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
],
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
],
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
],
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
],
|
|
1139
|
-
const
|
|
1140
|
-
|
|
1141
|
-
#
|
|
1142
|
-
#
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
alphaModifier*=1.-transmission;
|
|
1153
|
-
#endif
|
|
1154
|
-
float vignette=1.;if(true){float fadeStrength=0.1;float dist=min(min(1.-screenPos.x,1.-screenPos.y),min(screenPos.x,screenPos.y));float fade=dist*dist/(fadeStrength+0.001);fade=clamp(fade,0.0,1.0);fade=pow(fade,0.3);vignette=fade;}alphaModifier*=vignette;vec3 specularColor=EnvironmentBRDF(geometry.normal,geometry.viewDir,material.specularColor.rgb,material.specularF90,material.roughness);if(length(specularColor.rgb)*alphaModifier>0.01&&roughnessFactor<0.9){
|
|
1155
|
-
#if defined(SSR_INLINE) && SSR_INLINE > 0
|
|
1156
|
-
ssrColor=calculateSSR(8.,vec3(screenPos.xy,geometry.position.z),geometry.normal,1.,material.roughness);
|
|
1157
|
-
#else
|
|
1158
|
-
ssrColor=tSSReflMapTexelToLinear(texture2D(tSSReflMap,screenPos.xy));
|
|
1159
|
-
#endif
|
|
1160
|
-
}ssrColor.rgb*=ssrBoost;ssrColor.a*=alphaModifier;ssrColor.rgb=pow(ssrColor.rgb,vec3(ssrPower));ssrColor.a=min(ssrColor.a,1.0);
|
|
1161
|
-
#if defined(SSR_NON_PHYSICAL) && SSR_NON_PHYSICAL > 0
|
|
1162
|
-
diffuseColor.a=max(ssrColor.a,diffuseColor.a*diffuseColor.a);reflectedLight.indirectSpecular=mix(reflectedLight.indirectSpecular,saturate(diffuseColor.rgb*ssrColor.rgb),1.0);reflectedLight.indirectDiffuse=diffuseColor.rgb*(1.0-ssrColor.a);reflectedLight.directDiffuse=vec3(0.0);reflectedLight.directSpecular=vec3(0.0);
|
|
1163
|
-
#else
|
|
1164
|
-
reflectedLight.indirectSpecular=mix(reflectedLight.indirectSpecular,(specularColor.rgb*ssrColor.rgb),ssrColor.a);
|
|
1165
|
-
#endif
|
|
1166
|
-
#endif
|
|
1167
|
-
`, nt = `void main(){vec4 texel=tDiffuseTexelToLinear(texture2D(tDiffuse,vUv));vec4 lastAO=tLastThisTexelToLinear(texture2D(tLastThis,vUv));float depth;vec3 normal;getDepthNormal(vUv,depth,normal);if(depth>=0.999){discard;}float viewZ=depthToViewZ(depth);vec3 screenPos=vec3(vUv.x,vUv.y,viewZ);vec3 viewPos=screenToView3(screenPos.xy,screenPos.z);viewPos.z=viewZ/viewPos.z;vec4 ao=vec4(0.);ao+=calculateSSR(8.,screenPos,normal,1.,0.1);ao.rgb=min(vec3(3.),ao.rgb);ao.rgb=max(vec3(0.),ao.rgb);if(currentFrameCount<2.){gl_FragColor=ao;return;}if(ao.a<0.01){gl_FragColor.rgb=lastAO.rgb;gl_FragColor.a=(((lastAO.a)*currentFrameCount)/(currentFrameCount+1.));}else{gl_FragColor=((ao+(lastAO)*currentFrameCount)/(currentFrameCount+1.));}
|
|
1168
|
-
#include <encodings_fragment>
|
|
1169
|
-
}`;
|
|
1170
|
-
var lt = Object.defineProperty, ct = Object.getOwnPropertyDescriptor, x = (a, e, i, r) => {
|
|
1171
|
-
for (var t = r > 1 ? void 0 : r ? ct(e, i) : e, s = a.length - 1, o; s >= 0; s--)
|
|
1172
|
-
(o = a[s]) && (t = (r ? o(e, i, t) : o(t)) || t);
|
|
1173
|
-
return r && t && lt(e, i, t), t;
|
|
1335
|
+
SSContactShadowsPlugin.PluginType = "SSContactShadows";
|
|
1336
|
+
SSContactShadowsPlugin.OldPluginType = "SSContactShadowsPlugin";
|
|
1337
|
+
__decorateClass$1([
|
|
1338
|
+
uiToggle("Enabled"),
|
|
1339
|
+
serialize(),
|
|
1340
|
+
onChange(SSContactShadowsPlugin.prototype.setDirty)
|
|
1341
|
+
], SSContactShadowsPlugin.prototype, "enabled", 2);
|
|
1342
|
+
__decorateClass$1([
|
|
1343
|
+
uniform({ propKey: "sscsRadius", onChange: SSContactShadowsPlugin.prototype.setDirty }),
|
|
1344
|
+
uiSlider("Radius", [1e-4, 0.1], 1e-4),
|
|
1345
|
+
serialize()
|
|
1346
|
+
], SSContactShadowsPlugin.prototype, "radius", 2);
|
|
1347
|
+
__decorateClass$1([
|
|
1348
|
+
uniform({ propKey: "sscsIntensity", onChange: SSContactShadowsPlugin.prototype.setDirty }),
|
|
1349
|
+
uiSlider("Intensity", [1e-4, 1], 1e-4),
|
|
1350
|
+
serialize()
|
|
1351
|
+
], SSContactShadowsPlugin.prototype, "intensity", 2);
|
|
1352
|
+
__decorateClass$1([
|
|
1353
|
+
uniform({ propKey: "sscsTolerance", onChange: SSContactShadowsPlugin.prototype.setDirty }),
|
|
1354
|
+
uiSlider("Tolerance", [0.1, 5]),
|
|
1355
|
+
serialize()
|
|
1356
|
+
], SSContactShadowsPlugin.prototype, "tolerance", 2);
|
|
1357
|
+
__decorateClass$1([
|
|
1358
|
+
matDefine("SSCS_DEBUG", void 0, true, SSContactShadowsPlugin.prototype.setDirty),
|
|
1359
|
+
uiToggle("Debug only SSCS"),
|
|
1360
|
+
serialize()
|
|
1361
|
+
], SSContactShadowsPlugin.prototype, "onlySSCSDebug", 2);
|
|
1362
|
+
__decorateClass$1([
|
|
1363
|
+
matDefine("SSCS_STEP_COUNT", void 0, true, SSContactShadowsPlugin.prototype.setDirty),
|
|
1364
|
+
uiSlider("Step count", [1, 8], 1),
|
|
1365
|
+
serialize()
|
|
1366
|
+
], SSContactShadowsPlugin.prototype, "stepCount", 2);
|
|
1367
|
+
SSContactShadowsPlugin = __decorateClass$1([
|
|
1368
|
+
uiFolderContainer("SS Contact Shadows")
|
|
1369
|
+
], SSContactShadowsPlugin);
|
|
1370
|
+
const samplePointHelpers = "#define PI 3.141592653589793\nmat3 GetTangentBasis(vec3 TangentZ){vec3 up=vec3(0.0,0.0,1.0);vec3 TangentX=normalize(cross(dot(TangentZ,up)<0.8 ? up : vec3(1.0,0.0,0.0),TangentZ));vec3 TangentY=cross(TangentZ,TangentX);return mat3(TangentX,TangentY,TangentZ);}vec4 CosineSampleHemisphere(vec2 E){float Phi=2.*PI*E.x;float CosTheta=sqrt(E.y);float SinTheta=sqrt(1.-CosTheta*CosTheta);vec3 H;H.x=SinTheta*cos(Phi);H.y=SinTheta*sin(Phi);H.z=CosTheta;float PDF=CosTheta*(1.0/PI);return vec4(H,PDF);}vec4 UniformSampleHemisphere(vec2 E){float Phi=2.*PI*E.x;float CosTheta=E.y;float SinTheta=sqrt(1.-CosTheta*CosTheta);vec3 H;H.x=SinTheta*cos(Phi);H.y=SinTheta*sin(Phi);H.z=CosTheta;float PDF=1.0/(2.*PI);return vec4(H,PDF);}vec2 UniformSampleDiskConcentric(vec2 E){vec2 p=2.*E-1.;float Radius;float Phi;if(abs(p.x)>abs(p.y)){Radius=p.x;Phi=(PI/4.)*(p.y/p.x);}else{Radius=p.y;Phi=(PI/2.)-(PI/4.)*(p.x/p.y);}return vec2(Radius*cos(Phi),Radius*sin(Phi));}vec2 UniformSampleDiskConcentricApprox(vec2 E){vec2 sf=E*sqrt(2.0)-sqrt(0.5);vec2 sq=sf*sf;float root=sqrt(2.0*max(sq.x,sq.y)-min(sq.x,sq.y));if(sq.x>sq.y){sf.x=sf.x>0. ? root :-root;}else{sf.y=sf.y>0. ? root :-root;}return sf;}";
|
|
1371
|
+
const ssrShader = "uniform float currentFrameCount;uniform float frameCount;uniform float objectRadius;uniform float radius;uniform float tolerance;uniform bool autoRadius;\n#ifndef D_sceneBoundingRadius\n#define D_sceneBoundingRadius\nuniform float sceneBoundingRadius;\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*117.);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);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){vec3 hitColor=(tLastFrameTexelToLinear(texture2D(tLastFrame,screenHitP.xy))).rgb;float ssrWeight=1.;return vec4(hitColor*ssrWeight,1.);}return vec4(0.);}";
|
|
1372
|
+
const ssreflPatch = "\n#if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0\nvec3 screenPos=viewToScreen(geometry.position);vec4 ssrColor=vec4(0,0,0,0);float alphaModifier=1.0-clamp(material.roughness*.3,0.,1.);alphaModifier*=ssrIntensity;\n#if defined(SSR_MASK_FRONT_RAYS) && SSR_MASK_FRONT_RAYS > 0\nalphaModifier*=clamp(-4.0*dot(geometry.viewDir,normal)+(4.0+ssrMaskFrontFactor),0.0,1.0);\n#endif\n#ifdef USE_TRANSMISSION\nalphaModifier*=1.-transmission;\n#endif\nfloat vignette=1.;if(true){float fadeStrength=0.1;float dist=max(0.,min(min(1.-screenPos.x,1.-screenPos.y),min(screenPos.x,screenPos.y)));float fade=dist*dist/(fadeStrength+0.001);fade=clamp(fade,0.0,1.0);fade=pow(fade,0.3);vignette=fade;}alphaModifier*=vignette;vec3 specularColor=EnvironmentBRDF(geometry.normal,geometry.viewDir,material.specularColor.rgb,material.specularF90,material.roughness);if(length(specularColor.rgb)*alphaModifier>0.01&&roughnessFactor<0.9){\n#if defined(SSR_INLINE) && SSR_INLINE > 0\nssrColor=calculateSSR(8.,vec3(screenPos.xy,geometry.position.z),geometry.normal,1.,material.roughness);\n#else\nssrColor=tSSReflMapTexelToLinear(texture2D(tSSReflMap,screenPos.xy));\n#endif\n}ssrColor.rgb*=ssrBoost;ssrColor.a*=alphaModifier;ssrColor.rgb=pow(max(vec3(0.),ssrColor.rgb),vec3(ssrPower));ssrColor.a=min(ssrColor.a,1.0);\n#if defined(SSR_NON_PHYSICAL) && SSR_NON_PHYSICAL > 0\ndiffuseColor.a=max(ssrColor.a,diffuseColor.a*diffuseColor.a);reflectedLight.indirectSpecular=mix(reflectedLight.indirectSpecular,saturate(diffuseColor.rgb*ssrColor.rgb),1.0);reflectedLight.indirectDiffuse=diffuseColor.rgb*(1.0-ssrColor.a);reflectedLight.directDiffuse=vec3(0.0);reflectedLight.directSpecular=vec3(0.0);\n#else\nreflectedLight.indirectSpecular=mix(reflectedLight.indirectSpecular,(specularColor.rgb*ssrColor.rgb),ssrColor.a);\n#endif\n#endif\n";
|
|
1373
|
+
const ssrShaderMain = "void main(){vec4 texel=tDiffuseTexelToLinear(texture2D(tDiffuse,vUv));vec4 lastAO=tLastThisTexelToLinear(texture2D(tLastThis,vUv));float depth;vec3 normal;getDepthNormal(vUv,depth,normal);if(depth>=0.999){discard;}float viewZ=depthToViewZ(depth);vec3 screenPos=vec3(vUv.x,vUv.y,viewZ);vec3 viewPos=screenToView3(screenPos.xy,screenPos.z);viewPos.z=viewZ/viewPos.z;vec4 ao=vec4(0.);ao+=calculateSSR(8.,screenPos,normal,1.,0.1);ao.rgb=min(vec3(3.),ao.rgb);ao.rgb=max(vec3(0.),ao.rgb);if(currentFrameCount<2.){gl_FragColor=ao;return;}if(ao.a<0.01){gl_FragColor.rgb=lastAO.rgb;gl_FragColor.a=(((lastAO.a)*currentFrameCount)/(currentFrameCount+1.));}else{gl_FragColor=((ao+(lastAO)*currentFrameCount)/(currentFrameCount+1.));}\n#include <encodings_fragment>\n}";
|
|
1374
|
+
var __defProp = Object.defineProperty;
|
|
1375
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
1376
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
1377
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
1378
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1379
|
+
if (decorator = decorators[i])
|
|
1380
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
1381
|
+
if (kind && result) __defProp(target, key, result);
|
|
1382
|
+
return result;
|
|
1174
1383
|
};
|
|
1175
|
-
const
|
|
1176
|
-
let
|
|
1384
|
+
const passId = "ssrefl";
|
|
1385
|
+
let SSReflectionPlugin = class extends PipelinePassPlugin {
|
|
1177
1386
|
// cannot be changed after creation (for now)
|
|
1178
|
-
constructor(
|
|
1179
|
-
super()
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1387
|
+
constructor(inlineShaderRayTrace = true, bufferType = UnsignedByteType, sizeMultiplier = 1, enabled = true) {
|
|
1388
|
+
super();
|
|
1389
|
+
this.inlineShaderRayTrace = inlineShaderRayTrace;
|
|
1390
|
+
this.passId = passId;
|
|
1391
|
+
this.dependencies = [GBufferPlugin, SSAAPlugin];
|
|
1392
|
+
this._gbufferUnpackExtension = void 0;
|
|
1393
|
+
this._gbufferUnpackExtensionChanged = () => {
|
|
1394
|
+
if (!this._pass || !this._viewer) throw new Error("SSReflectionPlugin: pass/viewer not created yet");
|
|
1395
|
+
const newExtension = this._viewer.renderManager.gbufferUnpackExtension;
|
|
1396
|
+
if (this._gbufferUnpackExtension === newExtension) return;
|
|
1397
|
+
if (this._gbufferUnpackExtension) this._pass.setGBufferUnpackExtension(void 0);
|
|
1398
|
+
this._gbufferUnpackExtension = newExtension;
|
|
1399
|
+
if (this._gbufferUnpackExtension) this._pass.setGBufferUnpackExtension(this._gbufferUnpackExtension);
|
|
1400
|
+
else this._viewer.console.warn("SSReflectionPlugin: GBuffer unpack extension removed");
|
|
1401
|
+
};
|
|
1402
|
+
this.enabled = enabled;
|
|
1403
|
+
this.bufferType = bufferType;
|
|
1404
|
+
this.sizeMultiplier = sizeMultiplier;
|
|
1405
|
+
}
|
|
1406
|
+
_createTarget(recreate = true) {
|
|
1407
|
+
if (!this._viewer) return;
|
|
1408
|
+
if (recreate) this._disposeTarget();
|
|
1409
|
+
if (this.inlineShaderRayTrace) return;
|
|
1410
|
+
if (!this.target)
|
|
1411
|
+
this.target = this._viewer.renderManager.createTarget(
|
|
1412
|
+
{
|
|
1413
|
+
depthBuffer: false,
|
|
1414
|
+
type: this.bufferType,
|
|
1415
|
+
sizeMultiplier: this.sizeMultiplier
|
|
1416
|
+
// magFilter: NearestFilter,
|
|
1417
|
+
// minFilter: NearestFilter,
|
|
1418
|
+
// generateMipmaps: false,
|
|
1419
|
+
// encoding: LinearEncoding,
|
|
1420
|
+
}
|
|
1421
|
+
);
|
|
1422
|
+
this.texture = this.target.texture;
|
|
1423
|
+
this.texture.name = "ssreflBuffer";
|
|
1424
|
+
if (this._pass) this._pass.target = this.target;
|
|
1198
1425
|
}
|
|
1199
1426
|
_disposeTarget() {
|
|
1200
|
-
|
|
1427
|
+
if (!this._viewer) return;
|
|
1428
|
+
if (this.target) {
|
|
1429
|
+
this._viewer.renderManager.disposeTarget(this.target);
|
|
1430
|
+
this.target = void 0;
|
|
1431
|
+
}
|
|
1432
|
+
this.texture = void 0;
|
|
1201
1433
|
}
|
|
1202
1434
|
_createPass() {
|
|
1203
|
-
if (!this._viewer)
|
|
1204
|
-
throw new Error("SSReflectionPlugin: viewer not set");
|
|
1435
|
+
if (!this._viewer) throw new Error("SSReflectionPlugin: viewer not set");
|
|
1205
1436
|
if (!this._viewer.renderManager.gbufferTarget || !this._viewer.renderManager.gbufferUnpackExtension)
|
|
1206
1437
|
throw new Error("SSReflectionPlugin: GBuffer target not created. GBufferPlugin is required.");
|
|
1207
|
-
|
|
1438
|
+
this._createTarget(true);
|
|
1439
|
+
return new SSReflectionPluginPass(this.passId, this.target, this.inlineShaderRayTrace);
|
|
1208
1440
|
}
|
|
1209
|
-
onAdded(
|
|
1210
|
-
super.onAdded(
|
|
1441
|
+
onAdded(viewer) {
|
|
1442
|
+
super.onAdded(viewer);
|
|
1443
|
+
if (viewer.getPlugin("Ground") || viewer.getPlugin("BaseGroundPlugin")) console.error("GroundPlugin must be added after SSReflectionPlugin");
|
|
1444
|
+
this._gbufferUnpackExtensionChanged();
|
|
1445
|
+
viewer.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
|
|
1211
1446
|
}
|
|
1212
|
-
onRemove(
|
|
1213
|
-
|
|
1447
|
+
onRemove(viewer) {
|
|
1448
|
+
this._disposeTarget();
|
|
1449
|
+
viewer.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
|
|
1450
|
+
return super.onRemove(viewer);
|
|
1214
1451
|
}
|
|
1215
|
-
_beforeRender(
|
|
1216
|
-
var
|
|
1217
|
-
|
|
1452
|
+
_beforeRender(_, _1, _2) {
|
|
1453
|
+
var _a2;
|
|
1454
|
+
if (!this._viewer) return false;
|
|
1455
|
+
(_a2 = this._pass) == null ? void 0 : _a2.updateShaderProperties([this._viewer.getPlugin(ProgressivePlugin)]);
|
|
1456
|
+
return super._beforeRender(_, _1, _2);
|
|
1218
1457
|
}
|
|
1219
1458
|
/**
|
|
1220
1459
|
* @deprecated use {@link target} instead
|
|
1221
1460
|
*/
|
|
1222
1461
|
get ssrTarget() {
|
|
1223
|
-
|
|
1462
|
+
console.warn("SSReflectionPlugin: ssrTarget is deprecated, use target instead");
|
|
1463
|
+
return this.target;
|
|
1224
1464
|
}
|
|
1225
1465
|
};
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1466
|
+
SSReflectionPlugin.PluginType = "SSReflection";
|
|
1467
|
+
SSReflectionPlugin.OldPluginType = "SSReflectionPlugin";
|
|
1468
|
+
__decorateClass([
|
|
1469
|
+
uiImage(
|
|
1230
1470
|
"SSReflection Buffer"
|
|
1231
1471
|
/* {readOnly: true}*/
|
|
1232
1472
|
)
|
|
1233
|
-
],
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
],
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
],
|
|
1240
|
-
let
|
|
1241
|
-
constructor(
|
|
1473
|
+
], SSReflectionPlugin.prototype, "texture", 2);
|
|
1474
|
+
__decorateClass([
|
|
1475
|
+
uiConfig()
|
|
1476
|
+
], SSReflectionPlugin.prototype, "_pass", 2);
|
|
1477
|
+
SSReflectionPlugin = __decorateClass([
|
|
1478
|
+
uiFolderContainer("SSReflection Plugin")
|
|
1479
|
+
], SSReflectionPlugin);
|
|
1480
|
+
let SSReflectionPluginPass = class extends ExtendedShaderPass {
|
|
1481
|
+
constructor(pid, target, inlineShaderRayTrace = true) {
|
|
1242
1482
|
super({
|
|
1243
1483
|
defines: {
|
|
1244
|
-
SSR_STEP_COUNT: 16,
|
|
1245
|
-
SSR_LOW_QUALITY_FRAMES: 2,
|
|
1484
|
+
["SSR_STEP_COUNT"]: 16,
|
|
1485
|
+
["SSR_LOW_QUALITY_FRAMES"]: 2,
|
|
1246
1486
|
// todo: only on mobile
|
|
1247
|
-
SSR_INLINE:
|
|
1487
|
+
["SSR_INLINE"]: inlineShaderRayTrace ? "1" : "0",
|
|
1248
1488
|
// ['SSR_NON_PHYSICAL']: '0', only in inline, so it should not be here
|
|
1249
|
-
SSR_MASK_FRONT_RAYS:
|
|
1250
|
-
PERSPECTIVE_CAMERA: 1
|
|
1489
|
+
["SSR_MASK_FRONT_RAYS"]: true,
|
|
1490
|
+
["PERSPECTIVE_CAMERA"]: 1
|
|
1251
1491
|
// set in PerspectiveCamera2
|
|
1252
1492
|
// ['SSREFL_PACKING']: 1, // 1 is (r: ssrefl, gba: depth), 2 is (rgb: ssrefl, a: 1), 3 is (rgba: packed_ssrefl), 4 is (rgb: packed_ssrefl, a: 1)
|
|
1253
1493
|
},
|
|
@@ -1256,32 +1496,32 @@ let v = class extends $ {
|
|
|
1256
1496
|
tLastFrame: { value: null },
|
|
1257
1497
|
// set in progressive plugin
|
|
1258
1498
|
// TODO required?
|
|
1259
|
-
screenSize: { value: new
|
|
1499
|
+
screenSize: { value: new Vector2(0, 0) },
|
|
1260
1500
|
// set in ExtendedRenderMaterial
|
|
1261
1501
|
currentFrameCount: { value: 0 },
|
|
1262
1502
|
// set in RenderManager
|
|
1263
1503
|
frameCount: { value: 0 },
|
|
1264
1504
|
// set in RenderManager
|
|
1265
|
-
cameraNearFar: { value: new
|
|
1505
|
+
cameraNearFar: { value: new Vector2(0.1, 1e3) },
|
|
1266
1506
|
// set in PerspectiveCamera2
|
|
1267
|
-
cameraPositionWorld: { value: new
|
|
1507
|
+
cameraPositionWorld: { value: new Vector3() },
|
|
1268
1508
|
// set in PerspectiveCamera2
|
|
1269
|
-
projection: { value: new
|
|
1509
|
+
projection: { value: new Matrix4() },
|
|
1270
1510
|
// set in PerspectiveCamera2
|
|
1271
|
-
saoBiasEpsilon: { value: new
|
|
1511
|
+
saoBiasEpsilon: { value: new Vector3(1, 1, 1) },
|
|
1272
1512
|
opacity: { value: 1 },
|
|
1273
1513
|
// todo?
|
|
1274
1514
|
intensity: { value: 0 },
|
|
1275
|
-
boost: { value: new
|
|
1515
|
+
boost: { value: new Vector3(0, 0, 0) },
|
|
1276
1516
|
objectRadius: { value: 0 },
|
|
1277
|
-
autoRadius: { value:
|
|
1517
|
+
autoRadius: { value: false },
|
|
1278
1518
|
power: { value: 0 },
|
|
1279
1519
|
maskFrontFactor: { value: -0.1 },
|
|
1280
1520
|
tolerance: { value: 0 },
|
|
1281
1521
|
sceneBoundingRadius: { value: 0 }
|
|
1282
1522
|
// todo do same in SSAO
|
|
1283
1523
|
},
|
|
1284
|
-
vertexShader:
|
|
1524
|
+
vertexShader: shaderUtils.defaultVertex,
|
|
1285
1525
|
fragmentShader: `
|
|
1286
1526
|
varying vec2 vUv;
|
|
1287
1527
|
|
|
@@ -1290,19 +1530,35 @@ varying vec2 vUv;
|
|
|
1290
1530
|
#define THREE_PACKING_INCLUDED
|
|
1291
1531
|
#include <cameraHelpers>
|
|
1292
1532
|
#include <randomHelpers>
|
|
1293
|
-
${
|
|
1533
|
+
${samplePointHelpers}
|
|
1294
1534
|
|
|
1295
|
-
${
|
|
1535
|
+
${ssrtShader}
|
|
1296
1536
|
|
|
1297
|
-
${
|
|
1537
|
+
${ssrShader}
|
|
1298
1538
|
|
|
1299
|
-
${
|
|
1539
|
+
${ssrShaderMain}
|
|
1300
1540
|
`
|
|
1301
|
-
}, "tDiffuse", "tLastThis", "tLastFrame")
|
|
1541
|
+
}, "tDiffuse", "tLastThis", "tLastFrame");
|
|
1542
|
+
this.target = target;
|
|
1543
|
+
this.inlineShaderRayTrace = inlineShaderRayTrace;
|
|
1544
|
+
this.before = ["render"];
|
|
1545
|
+
this.after = ["gbuffer", "depth"];
|
|
1546
|
+
this.required = ["render", "progressive"];
|
|
1547
|
+
this.intensity = 1;
|
|
1548
|
+
this.boost = new Vector3(1, 1, 1);
|
|
1549
|
+
this.objectRadius = 1;
|
|
1550
|
+
this.autoRadius = true;
|
|
1551
|
+
this.power = 1.1;
|
|
1552
|
+
this.tolerance = 0.5;
|
|
1553
|
+
this.stepCount = 16;
|
|
1554
|
+
this.lowQualityFrames = 0;
|
|
1555
|
+
this.maskFrontRays = true;
|
|
1556
|
+
this.maskFrontFactor = -0.2;
|
|
1557
|
+
this.materialExtension = {
|
|
1302
1558
|
extraUniforms: {
|
|
1303
1559
|
tSSReflMap: () => {
|
|
1304
|
-
var
|
|
1305
|
-
return { value: ((
|
|
1560
|
+
var _a2;
|
|
1561
|
+
return { value: ((_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture) ?? null };
|
|
1306
1562
|
},
|
|
1307
1563
|
ssrPower: this.material.uniforms.power,
|
|
1308
1564
|
ssrIntensity: this.material.uniforms.intensity,
|
|
@@ -1310,20 +1566,19 @@ ${nt}
|
|
|
1310
1566
|
ssrBoost: this.material.uniforms.boost
|
|
1311
1567
|
},
|
|
1312
1568
|
extraDefines: {
|
|
1313
|
-
SSR_STEP_COUNT: () => this.material.defines.SSR_STEP_COUNT,
|
|
1314
|
-
SSR_LOW_QUALITY_FRAMES: () => this.material.defines.SSR_LOW_QUALITY_FRAMES,
|
|
1315
|
-
SSR_INLINE: () => this.material.defines.SSR_INLINE,
|
|
1316
|
-
SSR_MASK_FRONT_RAYS: () => this.material.defines.SSR_MASK_FRONT_RAYS,
|
|
1317
|
-
PERSPECTIVE_CAMERA: () => this.material.defines.PERSPECTIVE_CAMERA
|
|
1569
|
+
["SSR_STEP_COUNT"]: () => this.material.defines.SSR_STEP_COUNT,
|
|
1570
|
+
["SSR_LOW_QUALITY_FRAMES"]: () => this.material.defines.SSR_LOW_QUALITY_FRAMES,
|
|
1571
|
+
["SSR_INLINE"]: () => this.material.defines.SSR_INLINE,
|
|
1572
|
+
["SSR_MASK_FRONT_RAYS"]: () => this.material.defines.SSR_MASK_FRONT_RAYS,
|
|
1573
|
+
["PERSPECTIVE_CAMERA"]: () => this.material.defines.PERSPECTIVE_CAMERA
|
|
1318
1574
|
// todo gbuffer stuff
|
|
1319
1575
|
},
|
|
1320
|
-
shaderExtender: (
|
|
1321
|
-
var
|
|
1322
|
-
if (!
|
|
1323
|
-
|
|
1324
|
-
const o = `
|
|
1576
|
+
shaderExtender: (shader, _material, _renderer) => {
|
|
1577
|
+
var _a2, _b;
|
|
1578
|
+
if (!shader.defines.SSREFL_ENABLED) return;
|
|
1579
|
+
const ls = `
|
|
1325
1580
|
|
|
1326
|
-
${
|
|
1581
|
+
${ssreflPatch}
|
|
1327
1582
|
|
|
1328
1583
|
// reflectedLight.directDiffuse = vec3(0.);
|
|
1329
1584
|
// reflectedLight.indirectDiffuse = vec3(0.);
|
|
@@ -1331,21 +1586,30 @@ ${nt}
|
|
|
1331
1586
|
// reflectedLight.indirectSpecular = vec3(0.);
|
|
1332
1587
|
|
|
1333
1588
|
`;
|
|
1334
|
-
|
|
1335
|
-
|
|
1589
|
+
shader.fragmentShader = shaderReplaceString(
|
|
1590
|
+
shader.fragmentShader,
|
|
1336
1591
|
"#glMarker beforeModulation",
|
|
1337
|
-
|
|
1338
|
-
{ prepend:
|
|
1339
|
-
)
|
|
1592
|
+
ls,
|
|
1593
|
+
{ prepend: true }
|
|
1594
|
+
);
|
|
1595
|
+
(_b = (_a2 = this._gbufferUnpackExtension) == null ? void 0 : _a2.shaderExtender) == null ? void 0 : _b.call(_a2, shader, _material, _renderer);
|
|
1340
1596
|
},
|
|
1341
|
-
onObjectRender: (
|
|
1342
|
-
var
|
|
1343
|
-
let
|
|
1344
|
-
|
|
1597
|
+
onObjectRender: (_object, material, renderer) => {
|
|
1598
|
+
var _a2, _b, _c;
|
|
1599
|
+
let x = this.enabled && renderer.userData.screenSpaceRendering !== false && !((_a2 = material.userData) == null ? void 0 : _a2.pluginsDisabled) && !((_b = material.userData) == null ? void 0 : _b.ssreflDisabled) ? 1 : 0;
|
|
1600
|
+
if (material.defines.SSREFL_ENABLED !== x) {
|
|
1601
|
+
material.defines.SSREFL_ENABLED = x;
|
|
1602
|
+
material.needsUpdate = true;
|
|
1603
|
+
}
|
|
1604
|
+
x = ((_c = material.userData) == null ? void 0 : _c.ssreflNonPhysical) ? 1 : 0;
|
|
1605
|
+
if (material.defines.SSR_NON_PHYSICAL !== x) {
|
|
1606
|
+
material.defines.SSR_NON_PHYSICAL = x;
|
|
1607
|
+
material.needsUpdate = true;
|
|
1608
|
+
}
|
|
1345
1609
|
},
|
|
1346
|
-
parsFragmentSnippet: (
|
|
1347
|
-
var
|
|
1348
|
-
return
|
|
1610
|
+
parsFragmentSnippet: (renderer) => {
|
|
1611
|
+
var _a2;
|
|
1612
|
+
return glsl`
|
|
1349
1613
|
#if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0
|
|
1350
1614
|
uniform float ssrPower;
|
|
1351
1615
|
uniform float ssrIntensity;
|
|
@@ -1353,59 +1617,73 @@ ${nt}
|
|
|
1353
1617
|
uniform vec3 ssrBoost;
|
|
1354
1618
|
uniform sampler2D tSSReflMap;
|
|
1355
1619
|
uniform sampler2D tLastFrame;
|
|
1356
|
-
${
|
|
1357
|
-
${
|
|
1358
|
-
${this.inlineShaderRayTrace ? `
|
|
1620
|
+
${getTexelDecoding("tSSReflMap", (_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture, renderer.capabilities.isWebGL2)}
|
|
1621
|
+
${getTexelDecoding("tLastFrame", this.material.uniforms.tLastFrame.value, renderer.capabilities.isWebGL2)}
|
|
1622
|
+
${!this.inlineShaderRayTrace ? "" : `
|
|
1359
1623
|
#define THREE_PACKING_INCLUDED // by threejs
|
|
1360
1624
|
#include <cameraHelpers>
|
|
1361
1625
|
#include <randomHelpers>
|
|
1362
|
-
${
|
|
1363
|
-
${
|
|
1364
|
-
${
|
|
1365
|
-
`
|
|
1626
|
+
${samplePointHelpers}
|
|
1627
|
+
${ssrtShader}
|
|
1628
|
+
${ssrShader}
|
|
1629
|
+
`}
|
|
1366
1630
|
#include <simpleCameraHelpers>
|
|
1367
1631
|
#endif
|
|
1368
1632
|
`;
|
|
1369
1633
|
},
|
|
1370
1634
|
computeCacheKey: () => {
|
|
1371
|
-
var
|
|
1372
|
-
return this.enabled ? "1" : "0" + ((
|
|
1635
|
+
var _a2, _b;
|
|
1636
|
+
return this.enabled ? "1" : "0" + ((_b = (_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture) == null ? void 0 : _b.colorSpace) + Object.values(this.material.defines).map((v) => v + "").join(",");
|
|
1373
1637
|
},
|
|
1374
|
-
uuid:
|
|
1375
|
-
...
|
|
1376
|
-
isCompatible: (
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1638
|
+
uuid: SSReflectionPlugin.PluginType,
|
|
1639
|
+
...uiConfigMaterialExtension(this._getUiConfig.bind(this), SSReflectionPlugin.PluginType),
|
|
1640
|
+
isCompatible: (material) => {
|
|
1641
|
+
return material.isPhysicalMaterial;
|
|
1642
|
+
}
|
|
1643
|
+
};
|
|
1644
|
+
this.passId = pid;
|
|
1645
|
+
this.needsSwap = false;
|
|
1646
|
+
this.clear = true;
|
|
1647
|
+
if (inlineShaderRayTrace) {
|
|
1648
|
+
Object.assign(this.materialExtension.extraUniforms, {
|
|
1649
|
+
tNormalDepth: this.material.uniforms.tNormalDepth,
|
|
1650
|
+
tLastFrame: this.material.uniforms.tLastFrame,
|
|
1651
|
+
objectRadius: this.material.uniforms.objectRadius,
|
|
1652
|
+
autoRadius: this.material.uniforms.autoRadius,
|
|
1653
|
+
tolerance: this.material.uniforms.tolerance,
|
|
1654
|
+
frameCount: this.material.uniforms.frameCount,
|
|
1655
|
+
// currentFrameCount: this.material.uniforms.currentFrameCount, // todo required?
|
|
1656
|
+
projection: this.material.uniforms.projection,
|
|
1657
|
+
cameraPositionWorld: this.material.uniforms.cameraPositionWorld,
|
|
1658
|
+
cameraNearFar: this.material.uniforms.cameraNearFar,
|
|
1659
|
+
sceneBoundingRadius: this.material.uniforms.sceneBoundingRadius
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1390
1662
|
}
|
|
1391
|
-
render(
|
|
1392
|
-
if (!this.enabled)
|
|
1393
|
-
return;
|
|
1663
|
+
render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
|
|
1664
|
+
if (!this.enabled) return;
|
|
1394
1665
|
if (this.inlineShaderRayTrace) {
|
|
1395
|
-
this.needsSwap =
|
|
1666
|
+
this.needsSwap = false;
|
|
1396
1667
|
return;
|
|
1397
1668
|
}
|
|
1398
|
-
const
|
|
1399
|
-
if (!
|
|
1669
|
+
const target = getOrCall(this.target);
|
|
1670
|
+
if (!target) {
|
|
1400
1671
|
console.warn("SSReflectionPluginPass: target not defined. It must be set when inlineShaderRayTrace is false");
|
|
1401
1672
|
return;
|
|
1402
1673
|
}
|
|
1403
|
-
this.material.defines.HAS_GBUFFER
|
|
1404
|
-
|
|
1405
|
-
}
|
|
1674
|
+
if (!this.material.defines.HAS_GBUFFER) {
|
|
1675
|
+
console.warn("SSReflectionPluginPass: DepthNormalBuffer required for ssrefl");
|
|
1676
|
+
}
|
|
1677
|
+
renderer.renderManager.blit(writeBuffer, {
|
|
1678
|
+
source: target.texture
|
|
1679
|
+
});
|
|
1680
|
+
this.uniforms.tLastThis.value = writeBuffer.texture;
|
|
1681
|
+
super.render(renderer, target, readBuffer, deltaTime, maskActive);
|
|
1682
|
+
this.needsSwap = false;
|
|
1406
1683
|
}
|
|
1407
|
-
beforeRender(
|
|
1408
|
-
this.enabled
|
|
1684
|
+
beforeRender(scene, camera, renderManager) {
|
|
1685
|
+
if (!this.enabled) return;
|
|
1686
|
+
this.updateShaderProperties([scene, camera, renderManager]);
|
|
1409
1687
|
}
|
|
1410
1688
|
/**
|
|
1411
1689
|
* Returns a uiConfig to toggle SSReflection on a material.
|
|
@@ -1413,7 +1691,7 @@ ${le}
|
|
|
1413
1691
|
* @param material
|
|
1414
1692
|
* @private
|
|
1415
1693
|
*/
|
|
1416
|
-
_getUiConfig(
|
|
1694
|
+
_getUiConfig(material) {
|
|
1417
1695
|
return {
|
|
1418
1696
|
type: "folder",
|
|
1419
1697
|
label: "SSReflection",
|
|
@@ -1422,10 +1700,12 @@ ${le}
|
|
|
1422
1700
|
type: "checkbox",
|
|
1423
1701
|
label: "Enabled",
|
|
1424
1702
|
get value() {
|
|
1425
|
-
return !(
|
|
1703
|
+
return !(material.userData.ssreflDisabled ?? false);
|
|
1426
1704
|
},
|
|
1427
|
-
set value(
|
|
1428
|
-
|
|
1705
|
+
set value(v) {
|
|
1706
|
+
if (v === !(material.userData.ssreflDisabled ?? false)) return;
|
|
1707
|
+
material.userData.ssreflDisabled = !v;
|
|
1708
|
+
material.setDirty();
|
|
1429
1709
|
},
|
|
1430
1710
|
onChange: this.setDirty
|
|
1431
1711
|
},
|
|
@@ -1433,96 +1713,105 @@ ${le}
|
|
|
1433
1713
|
type: "checkbox",
|
|
1434
1714
|
label: "Non Physical",
|
|
1435
1715
|
get value() {
|
|
1436
|
-
return
|
|
1716
|
+
return material.userData.ssreflNonPhysical ?? false;
|
|
1437
1717
|
},
|
|
1438
|
-
set value(
|
|
1439
|
-
|
|
1718
|
+
set value(v) {
|
|
1719
|
+
if (v === (material.userData.ssreflNonPhysical ?? false)) return;
|
|
1720
|
+
material.userData.ssreflNonPhysical = v;
|
|
1721
|
+
material.setDirty();
|
|
1440
1722
|
},
|
|
1441
1723
|
onChange: this.setDirty
|
|
1442
1724
|
}
|
|
1443
1725
|
]
|
|
1444
1726
|
};
|
|
1445
1727
|
}
|
|
1446
|
-
set uniformsNeedUpdate(
|
|
1447
|
-
this.material.uniformsNeedUpdate =
|
|
1728
|
+
set uniformsNeedUpdate(value) {
|
|
1729
|
+
this.material.uniformsNeedUpdate = value;
|
|
1730
|
+
this.setDirty();
|
|
1448
1731
|
}
|
|
1449
|
-
setGBufferUnpackExtension(
|
|
1450
|
-
|
|
1732
|
+
setGBufferUnpackExtension(extension) {
|
|
1733
|
+
if (this._gbufferUnpackExtension === extension) return;
|
|
1734
|
+
if (this._gbufferUnpackExtension) this.material.unregisterMaterialExtensions([this._gbufferUnpackExtension]);
|
|
1735
|
+
this._gbufferUnpackExtension = extension;
|
|
1736
|
+
if (this._gbufferUnpackExtension) this.material.registerMaterialExtensions([this._gbufferUnpackExtension]);
|
|
1737
|
+
if (!this._gbufferUnpackExtension) return;
|
|
1738
|
+
Object.assign(this.materialExtension.extraUniforms, this._gbufferUnpackExtension.extraUniforms);
|
|
1739
|
+
Object.assign(this.materialExtension.extraDefines, this._gbufferUnpackExtension.extraDefines);
|
|
1451
1740
|
}
|
|
1452
1741
|
};
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
],
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
],
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
],
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
],
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
],
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
],
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
],
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
],
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
],
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
],
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
],
|
|
1506
|
-
const
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1742
|
+
__decorateClass([
|
|
1743
|
+
uiSlider("Intensity", [0, 4]),
|
|
1744
|
+
serialize(),
|
|
1745
|
+
uniform()
|
|
1746
|
+
], SSReflectionPluginPass.prototype, "intensity", 2);
|
|
1747
|
+
__decorateClass([
|
|
1748
|
+
uiVector("Boost"),
|
|
1749
|
+
serialize(),
|
|
1750
|
+
uniform()
|
|
1751
|
+
], SSReflectionPluginPass.prototype, "boost", 2);
|
|
1752
|
+
__decorateClass([
|
|
1753
|
+
uiSlider("Object Radius", [0.01, 2]),
|
|
1754
|
+
serialize(),
|
|
1755
|
+
uniform()
|
|
1756
|
+
], SSReflectionPluginPass.prototype, "objectRadius", 2);
|
|
1757
|
+
__decorateClass([
|
|
1758
|
+
uiToggle("Auto radius"),
|
|
1759
|
+
serialize(),
|
|
1760
|
+
uniform()
|
|
1761
|
+
], SSReflectionPluginPass.prototype, "autoRadius", 2);
|
|
1762
|
+
__decorateClass([
|
|
1763
|
+
uiSlider("Power", [0, 3]),
|
|
1764
|
+
serialize(),
|
|
1765
|
+
uniform()
|
|
1766
|
+
], SSReflectionPluginPass.prototype, "power", 2);
|
|
1767
|
+
__decorateClass([
|
|
1768
|
+
uiSlider("Tolerance", [0.1, 5]),
|
|
1769
|
+
serialize(),
|
|
1770
|
+
uniform()
|
|
1771
|
+
], SSReflectionPluginPass.prototype, "tolerance", 2);
|
|
1772
|
+
__decorateClass([
|
|
1773
|
+
uiSlider("Step count", [1, 32], 1),
|
|
1774
|
+
serialize(),
|
|
1775
|
+
matDefine("SSR_STEP_COUNT", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
|
|
1776
|
+
], SSReflectionPluginPass.prototype, "stepCount", 2);
|
|
1777
|
+
__decorateClass([
|
|
1778
|
+
uiSlider("Low Quality Frames", [0, 4], 1),
|
|
1779
|
+
serialize(),
|
|
1780
|
+
matDefine("SSR_LOW_QUALITY_FRAMES", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
|
|
1781
|
+
], SSReflectionPluginPass.prototype, "lowQualityFrames", 2);
|
|
1782
|
+
__decorateClass([
|
|
1783
|
+
uiToggle("Ignore front rays"),
|
|
1784
|
+
serialize(),
|
|
1785
|
+
matDefineBool("SSR_MASK_FRONT_RAYS", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
|
|
1786
|
+
], SSReflectionPluginPass.prototype, "maskFrontRays", 2);
|
|
1787
|
+
__decorateClass([
|
|
1788
|
+
uiSlider("Mask front rays factor", [-1, 1], 0.01, (that) => ({ hidden: () => !that.maskFrontRays })),
|
|
1789
|
+
serialize(),
|
|
1790
|
+
uniform()
|
|
1791
|
+
], SSReflectionPluginPass.prototype, "maskFrontFactor", 2);
|
|
1792
|
+
SSReflectionPluginPass = __decorateClass([
|
|
1793
|
+
uiFolderContainer("SSReflection Pass")
|
|
1794
|
+
], SSReflectionPluginPass);
|
|
1795
|
+
const webgiPlugins = [
|
|
1796
|
+
TemporalAAPlugin,
|
|
1797
|
+
VelocityBufferPlugin,
|
|
1798
|
+
BloomPlugin,
|
|
1799
|
+
SSReflectionPlugin,
|
|
1800
|
+
SSContactShadowsPlugin,
|
|
1801
|
+
DepthOfFieldPlugin
|
|
1513
1802
|
];
|
|
1514
1803
|
export {
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1804
|
+
BloomPlugin,
|
|
1805
|
+
BloomPluginPass,
|
|
1806
|
+
DepthOfFieldPlugin,
|
|
1807
|
+
DepthOfFieldPluginPass,
|
|
1808
|
+
SSContactShadowsPlugin,
|
|
1809
|
+
SSReflectionPlugin,
|
|
1810
|
+
SSReflectionPluginPass,
|
|
1811
|
+
SSVelocityMaterial,
|
|
1812
|
+
TemporalAAPlugin,
|
|
1813
|
+
TemporalAAPluginPass,
|
|
1814
|
+
VelocityBufferPlugin,
|
|
1815
|
+
webgiPlugins
|
|
1527
1816
|
};
|
|
1528
1817
|
//# sourceMappingURL=index.mjs.map
|