@threepipe/webgi-plugins 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +10 -225
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1199 -917
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/buffer/VelocityBufferPlugin.d.ts +0 -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 +4 -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.
|
|
5
|
-
* Copyright 2022-
|
|
3
|
+
* @threepipe/webgi-plugins v0.2.0
|
|
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(
|
|
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);
|
|
108
77
|
}
|
|
109
|
-
onRemove(
|
|
110
|
-
|
|
78
|
+
onRemove(viewer) {
|
|
79
|
+
viewer.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
|
|
80
|
+
viewer.renderManager.removeEventListener("resize", this._pass.onSizeUpdate);
|
|
81
|
+
super.onRemove(viewer);
|
|
111
82
|
}
|
|
112
|
-
_beforeRender(
|
|
113
|
-
if (!super._beforeRender(
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
if (!
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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,325 @@ 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
|
+
shader.fragmentShader = shaderReplaceString(
|
|
256
|
+
shader.fragmentShader,
|
|
257
|
+
"#pragma <velocity_unpack>",
|
|
258
|
+
"\n" + VelocityBufferUnpack + "\n"
|
|
257
259
|
);
|
|
258
260
|
},
|
|
259
261
|
extraUniforms: {
|
|
260
262
|
tVelocity: () => {
|
|
261
|
-
var
|
|
262
|
-
return { value: (
|
|
263
|
+
var _a2;
|
|
264
|
+
return { value: (_a2 = this.target) == null ? void 0 : _a2.texture };
|
|
263
265
|
}
|
|
264
266
|
},
|
|
265
267
|
extraDefines: {
|
|
266
|
-
HAS_VELOCITY_BUFFER: () => {
|
|
267
|
-
var
|
|
268
|
-
return (
|
|
268
|
+
["HAS_VELOCITY_BUFFER"]: () => {
|
|
269
|
+
var _a2;
|
|
270
|
+
return ((_a2 = this.target) == null ? void 0 : _a2.texture) ? 1 : void 0;
|
|
269
271
|
}
|
|
270
272
|
},
|
|
271
273
|
priority: 100,
|
|
272
|
-
isCompatible: () =>
|
|
273
|
-
}
|
|
274
|
+
isCompatible: () => true
|
|
275
|
+
};
|
|
276
|
+
this.enabled = enabled;
|
|
277
|
+
this.bufferType = bufferType;
|
|
278
|
+
this._attachToTaa = _attachToTaa;
|
|
274
279
|
}
|
|
275
280
|
// cannot be changed after creation (for now)
|
|
276
|
-
_createTarget(
|
|
277
|
-
|
|
281
|
+
_createTarget(recreate = true) {
|
|
282
|
+
if (!this._viewer) return;
|
|
283
|
+
if (recreate) this._disposeTarget();
|
|
284
|
+
if (!this.target) this.target = this._viewer.renderManager.createTarget(
|
|
278
285
|
{
|
|
279
|
-
depthBuffer:
|
|
286
|
+
depthBuffer: true,
|
|
280
287
|
// samples: v.renderManager.composerTarget.samples || 0,
|
|
281
288
|
samples: 0,
|
|
282
289
|
type: this.bufferType,
|
|
283
290
|
// magFilter: NearestFilter,
|
|
284
291
|
// minFilter: NearestFilter,
|
|
285
|
-
generateMipmaps:
|
|
286
|
-
colorSpace:
|
|
292
|
+
generateMipmaps: false,
|
|
293
|
+
colorSpace: LinearSRGBColorSpace
|
|
287
294
|
}
|
|
288
|
-
)
|
|
295
|
+
);
|
|
296
|
+
this.texture = this.target.texture;
|
|
297
|
+
this.texture.name = "velocityBuffer";
|
|
298
|
+
if (this._pass) this._pass.target = this.target;
|
|
289
299
|
}
|
|
290
300
|
_disposeTarget() {
|
|
291
|
-
|
|
301
|
+
if (!this._viewer) return;
|
|
302
|
+
if (this.target) {
|
|
303
|
+
this._viewer.renderManager.disposeTarget(this.target);
|
|
304
|
+
this.target = void 0;
|
|
305
|
+
}
|
|
306
|
+
this.texture = void 0;
|
|
292
307
|
}
|
|
293
308
|
_createPass() {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
this.material.userData.isGBufferMaterial =
|
|
297
|
-
const
|
|
309
|
+
this._createTarget(true);
|
|
310
|
+
if (!this.target) throw new Error("VelocityBufferPlugin: target not created");
|
|
311
|
+
this.material.userData.isGBufferMaterial = true;
|
|
312
|
+
const v = this._viewer;
|
|
313
|
+
const pass = new class extends GBufferRenderPass {
|
|
298
314
|
constructor() {
|
|
299
|
-
super(...arguments)
|
|
315
|
+
super(...arguments);
|
|
316
|
+
this._firstCall = true;
|
|
300
317
|
}
|
|
301
|
-
render(
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
|
|
318
|
+
render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
|
|
319
|
+
if (v.renderManager.frameCount > 0) return;
|
|
320
|
+
if (!this.enabled || !this.camera) return;
|
|
321
|
+
const mat = this.overrideMaterial;
|
|
322
|
+
mat.uniforms.currentProjectionViewMatrix.value.copy(this.camera.projectionMatrix).multiply(this.camera.matrixWorldInverse);
|
|
323
|
+
if (this._firstCall) {
|
|
324
|
+
mat.uniforms.lastProjectionViewMatrix.value.copy(mat.uniforms.currentProjectionViewMatrix.value);
|
|
325
|
+
this._firstCall = false;
|
|
326
|
+
}
|
|
327
|
+
super.render(renderer, writeBuffer, readBuffer, deltaTime, maskActive);
|
|
328
|
+
mat.uniforms.lastProjectionViewMatrix.value.copy(mat.uniforms.currentProjectionViewMatrix.value);
|
|
306
329
|
}
|
|
307
|
-
}(this.passId, this.target, this.material, new
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
330
|
+
}(this.passId, this.target, this.material, new Color(0.5, 0.5, 0.5), 1);
|
|
331
|
+
const preprocessMaterial = pass.preprocessMaterial;
|
|
332
|
+
pass.preprocessMaterial = (m) => {
|
|
333
|
+
var _a2;
|
|
334
|
+
return preprocessMaterial(m, (_a2 = m.userData[VelocityBufferPlugin.PluginType]) == null ? void 0 : _a2.disabled);
|
|
335
|
+
};
|
|
336
|
+
pass.before = ["render"];
|
|
337
|
+
pass.after = [];
|
|
338
|
+
pass.required = ["render"];
|
|
339
|
+
return pass;
|
|
312
340
|
}
|
|
313
|
-
onAdded(
|
|
314
|
-
var
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
341
|
+
onAdded(viewer) {
|
|
342
|
+
var _a2;
|
|
343
|
+
super.onAdded(viewer);
|
|
344
|
+
if (this._attachToTaa) {
|
|
345
|
+
const taa = viewer.getPlugin(TemporalAAPlugin);
|
|
346
|
+
if (taa) (_a2 = taa.pass) == null ? void 0 : _a2.material.registerMaterialExtensions([this.unpackExtension]);
|
|
347
|
+
else viewer.console.warn("VelocityBufferPlugin: TemporalAAPlugin not found, set attachToTaa to false if not required");
|
|
318
348
|
}
|
|
319
349
|
}
|
|
320
|
-
onRemove(
|
|
321
|
-
var
|
|
322
|
-
|
|
350
|
+
onRemove(viewer) {
|
|
351
|
+
var _a2, _b;
|
|
352
|
+
this._disposeTarget();
|
|
353
|
+
if (this._attachToTaa) (_b = (_a2 = viewer.getPlugin(TemporalAAPlugin)) == null ? void 0 : _a2.pass) == null ? void 0 : _b.material.unregisterMaterialExtensions([this.unpackExtension]);
|
|
354
|
+
return super.onRemove(viewer);
|
|
323
355
|
}
|
|
324
|
-
_beforeRender(
|
|
325
|
-
if (!super._beforeRender(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
356
|
+
_beforeRender(scene, camera, renderManager) {
|
|
357
|
+
if (!super._beforeRender(scene, camera, renderManager)) return false;
|
|
358
|
+
const pass = this.pass;
|
|
359
|
+
if (!pass) return false;
|
|
360
|
+
if (renderManager.frameCount > 0) return false;
|
|
361
|
+
pass.scene = scene;
|
|
362
|
+
pass.camera = camera;
|
|
363
|
+
camera.updateShaderProperties(pass.overrideMaterial);
|
|
364
|
+
return true;
|
|
329
365
|
}
|
|
330
366
|
};
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
367
|
+
VelocityBufferPlugin.PluginType = "VelocityBuffer";
|
|
368
|
+
VelocityBufferPlugin.OldPluginType = "VelocityBufferPlugin";
|
|
369
|
+
__decorateClass$4([
|
|
370
|
+
uiImage(
|
|
335
371
|
"Velocity Buffer"
|
|
336
372
|
/* {readOnly: true}*/
|
|
337
373
|
)
|
|
338
|
-
],
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
],
|
|
342
|
-
class
|
|
374
|
+
], VelocityBufferPlugin.prototype, "texture", 2);
|
|
375
|
+
VelocityBufferPlugin = __decorateClass$4([
|
|
376
|
+
uiFolderContainer("Velocity Buffer Plugin (for TAA)")
|
|
377
|
+
], VelocityBufferPlugin);
|
|
378
|
+
class SSVelocityMaterial extends ShaderMaterial {
|
|
343
379
|
constructor() {
|
|
344
380
|
super({
|
|
345
|
-
vertexShader:
|
|
346
|
-
fragmentShader:
|
|
381
|
+
vertexShader: ssVelocityVert,
|
|
382
|
+
fragmentShader: ssVelocityFrag,
|
|
347
383
|
uniforms: {
|
|
348
|
-
cameraNearFar: { value: new
|
|
384
|
+
cameraNearFar: { value: new Vector2(0.1, 1e3) },
|
|
349
385
|
alphaMap: { value: null },
|
|
350
386
|
alphaTest: { value: null },
|
|
351
|
-
alphaMapTransform: { value: /* @__PURE__ */ new
|
|
352
|
-
currentProjectionViewMatrix: { value: new
|
|
353
|
-
lastProjectionViewMatrix: { value: new
|
|
387
|
+
alphaMapTransform: { value: /* @__PURE__ */ new Matrix3() },
|
|
388
|
+
currentProjectionViewMatrix: { value: new Matrix4() },
|
|
389
|
+
lastProjectionViewMatrix: { value: new Matrix4() }
|
|
354
390
|
},
|
|
355
|
-
blending:
|
|
391
|
+
blending: NoBlending
|
|
356
392
|
// todo?
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
|
|
393
|
+
});
|
|
394
|
+
this.extraUniformsToUpload = {
|
|
395
|
+
modelMatrixPrevious: { value: new Matrix4().identity() }
|
|
396
|
+
};
|
|
397
|
+
this._previousWorldMatrices = {};
|
|
360
398
|
}
|
|
361
399
|
// this gets called for each object.
|
|
362
|
-
onBeforeRender(
|
|
363
|
-
const
|
|
364
|
-
this.extraUniformsToUpload.modelMatrixPrevious.value.copy(
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
400
|
+
onBeforeRender(_r, _s, _c, _geometry, object) {
|
|
401
|
+
const prevMatrix = this._previousWorldMatrices[object.uuid];
|
|
402
|
+
this.extraUniformsToUpload.modelMatrixPrevious.value.copy(prevMatrix ?? object.matrixWorld);
|
|
403
|
+
if (prevMatrix) {
|
|
404
|
+
prevMatrix.copy(object.matrixWorld);
|
|
405
|
+
} else {
|
|
406
|
+
this._previousWorldMatrices[object.uuid] = object.matrixWorld.clone();
|
|
407
|
+
}
|
|
408
|
+
let mat = object.material;
|
|
409
|
+
if (Array.isArray(mat)) {
|
|
410
|
+
mat = mat[0];
|
|
411
|
+
}
|
|
412
|
+
this.uniforms.alphaMap.value = (mat == null ? void 0 : mat.alphaMap) ?? null;
|
|
413
|
+
this.uniforms.alphaTest.value = !mat || !mat.alphaTest || mat.alphaTest < 1e-7 ? 1e-3 : mat.alphaTest;
|
|
414
|
+
let x = this.uniforms.alphaMap.value ? 1 : void 0;
|
|
415
|
+
if (x !== this.defines.USE_ALPHAMAP) {
|
|
416
|
+
if (x === void 0) delete this.defines.USE_ALPHAMAP;
|
|
417
|
+
else this.defines.USE_ALPHAMAP = x;
|
|
418
|
+
this.needsUpdate = true;
|
|
419
|
+
}
|
|
420
|
+
x = (mat == null ? void 0 : mat.userData.ALPHA_I_RGBA_PACKING) ? 1 : void 0;
|
|
421
|
+
if (x !== this.defines.ALPHA_I_RGBA_PACKING) {
|
|
422
|
+
if (x === void 0) delete this.defines.ALPHA_I_RGBA_PACKING;
|
|
423
|
+
else this.defines.ALPHA_I_RGBA_PACKING = x;
|
|
424
|
+
this.needsUpdate = true;
|
|
425
|
+
}
|
|
426
|
+
this.side = (mat == null ? void 0 : mat.side) ?? DoubleSide;
|
|
369
427
|
}
|
|
370
428
|
}
|
|
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;
|
|
429
|
+
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}";
|
|
430
|
+
var __defProp$3 = Object.defineProperty;
|
|
431
|
+
var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
|
|
432
|
+
var __decorateClass$3 = (decorators, target, key, kind) => {
|
|
433
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
|
|
434
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
435
|
+
if (decorator = decorators[i])
|
|
436
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
437
|
+
if (kind && result) __defProp$3(target, key, result);
|
|
438
|
+
return result;
|
|
411
439
|
};
|
|
412
|
-
const $
|
|
413
|
-
|
|
414
|
-
const Se = (_ = class extends I {
|
|
440
|
+
const passId$2 = "bloom";
|
|
441
|
+
const _BloomPlugin = (_a = class extends PipelinePassPlugin {
|
|
415
442
|
constructor() {
|
|
416
|
-
super(...arguments)
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
443
|
+
super(...arguments);
|
|
444
|
+
this.passId = passId$2;
|
|
445
|
+
this.materialExtension = uiConfigMaterialExtension(this._getUiConfig.bind(this), _a.PluginType);
|
|
446
|
+
this.dependencies = [GBufferPlugin];
|
|
447
|
+
this._onPluginAdd = (e) => {
|
|
448
|
+
var _a2, _b, _c, _d;
|
|
449
|
+
if (((_b = (_a2 = e.plugin) == null ? void 0 : _a2.constructor) == null ? void 0 : _b.PluginType) !== GBufferPlugin.PluginType) return;
|
|
450
|
+
const gbuffer = e.plugin;
|
|
451
|
+
gbuffer.registerGBufferUpdater(this.constructor.PluginType, this.updateGBufferFlags.bind(this));
|
|
452
|
+
(_c = this._pass) == null ? void 0 : _c.material.registerMaterialExtensions([gbuffer.unpackExtension]);
|
|
453
|
+
(_d = this._viewer) == null ? void 0 : _d.removeEventListener("addPlugin", this._onPluginAdd);
|
|
454
|
+
};
|
|
455
|
+
this.uiConfig = {
|
|
423
456
|
type: "folder",
|
|
424
457
|
label: "Bloom Plugin",
|
|
425
458
|
onChange: this.setDirty.bind(this),
|
|
426
459
|
children: [
|
|
427
|
-
...
|
|
460
|
+
...generateUiConfig(this) || []
|
|
428
461
|
]
|
|
429
462
|
};
|
|
430
463
|
}
|
|
431
464
|
_createPass() {
|
|
432
|
-
|
|
465
|
+
var _a2;
|
|
466
|
+
const pass = new BloomPluginPass(this.passId, Math.min(8, ((_a2 = this._viewer) == null ? void 0 : _a2.renderManager.maxHDRIntensity) || 8));
|
|
467
|
+
return pass;
|
|
433
468
|
}
|
|
434
|
-
onAdded(
|
|
435
|
-
super.onAdded(
|
|
436
|
-
const
|
|
437
|
-
|
|
469
|
+
onAdded(viewer) {
|
|
470
|
+
super.onAdded(viewer);
|
|
471
|
+
const gbuffer = viewer.getPlugin(GBufferPlugin);
|
|
472
|
+
if (gbuffer) {
|
|
473
|
+
gbuffer.registerGBufferUpdater(this.constructor.PluginType, this.updateGBufferFlags.bind(this));
|
|
474
|
+
this._pass.material.registerMaterialExtensions([gbuffer.unpackExtension]);
|
|
475
|
+
} else viewer.addEventListener("addPlugin", this._onPluginAdd);
|
|
476
|
+
viewer.materialManager.registerMaterialExtension(this.materialExtension);
|
|
438
477
|
}
|
|
439
|
-
onRemove(
|
|
440
|
-
var
|
|
441
|
-
|
|
442
|
-
const
|
|
443
|
-
|
|
478
|
+
onRemove(viewer) {
|
|
479
|
+
var _a2;
|
|
480
|
+
viewer.removeEventListener("addPlugin", this._onPluginAdd);
|
|
481
|
+
const gbuffer = viewer.getPlugin(GBufferPlugin);
|
|
482
|
+
gbuffer == null ? void 0 : gbuffer.unregisterGBufferUpdater(this.constructor.PluginType);
|
|
483
|
+
gbuffer && ((_a2 = this._pass) == null ? void 0 : _a2.material.unregisterMaterialExtensions([gbuffer.unpackExtension]));
|
|
484
|
+
viewer.materialManager.unregisterMaterialExtension(this.materialExtension);
|
|
485
|
+
super.onRemove(viewer);
|
|
444
486
|
}
|
|
445
|
-
updateGBufferFlags(
|
|
446
|
-
var
|
|
447
|
-
if (!
|
|
448
|
-
|
|
449
|
-
const
|
|
450
|
-
|
|
487
|
+
updateGBufferFlags(data, c) {
|
|
488
|
+
var _a2;
|
|
489
|
+
if (!c.material || !c.material.userData) return;
|
|
490
|
+
const disabled = ((_a2 = c.material.userData[_a.PluginType]) == null ? void 0 : _a2.enable) === false || c.material.userData.pluginsDisabled;
|
|
491
|
+
const x = disabled ? 0 : 1;
|
|
492
|
+
data.w = updateBit(data.w, 2, x);
|
|
451
493
|
}
|
|
452
|
-
static AddBloomData(
|
|
453
|
-
const
|
|
454
|
-
if (!
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
494
|
+
static AddBloomData(material, params, setDirty = true) {
|
|
495
|
+
const ud = material == null ? void 0 : material.userData;
|
|
496
|
+
if (!ud) return null;
|
|
497
|
+
if (!ud[_a.PluginType]) {
|
|
498
|
+
ud[_a.PluginType] = {};
|
|
499
|
+
}
|
|
500
|
+
const data = ud[_a.PluginType];
|
|
501
|
+
data.enable = true;
|
|
502
|
+
params && Object.assign(data, params);
|
|
503
|
+
if (setDirty && material.setDirty) material.setDirty();
|
|
504
|
+
return data;
|
|
459
505
|
}
|
|
460
506
|
/**
|
|
461
507
|
* This uiConfig is added to each material by extension
|
|
462
508
|
* @param material
|
|
463
509
|
* @private
|
|
464
510
|
*/
|
|
465
|
-
_getUiConfig(
|
|
466
|
-
const
|
|
511
|
+
_getUiConfig(material) {
|
|
512
|
+
const config = {
|
|
467
513
|
type: "folder",
|
|
468
514
|
label: "Bloom",
|
|
469
515
|
children: [
|
|
@@ -471,31 +517,36 @@ const Se = (_ = class extends I {
|
|
|
471
517
|
type: "checkbox",
|
|
472
518
|
label: "Enabled",
|
|
473
519
|
get value() {
|
|
474
|
-
var
|
|
475
|
-
return ((
|
|
520
|
+
var _a2;
|
|
521
|
+
return ((_a2 = material.userData[_a.PluginType]) == null ? void 0 : _a2.enable) ?? true;
|
|
476
522
|
},
|
|
477
|
-
set value(
|
|
478
|
-
var
|
|
479
|
-
let
|
|
480
|
-
|
|
523
|
+
set value(v) {
|
|
524
|
+
var _a2;
|
|
525
|
+
let data = material.userData[_a.PluginType];
|
|
526
|
+
if (v === (data == null ? void 0 : data.enable)) return;
|
|
527
|
+
if (!data) data = _a.AddBloomData(material, void 0, false);
|
|
528
|
+
data.enable = v;
|
|
529
|
+
material.setDirty();
|
|
530
|
+
(_a2 = config.uiRefresh) == null ? void 0 : _a2.call(config, true, "postFrame");
|
|
481
531
|
},
|
|
482
532
|
onChange: this.setDirty
|
|
483
533
|
}
|
|
484
534
|
]
|
|
485
535
|
};
|
|
486
|
-
return
|
|
536
|
+
return config;
|
|
487
537
|
}
|
|
488
|
-
},
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
],
|
|
492
|
-
let
|
|
493
|
-
|
|
538
|
+
}, _a.PluginType = "Bloom", _a.OldPluginType = "BloomPlugin", _a);
|
|
539
|
+
__decorateClass$3([
|
|
540
|
+
uiConfig()
|
|
541
|
+
], _BloomPlugin.prototype, "_pass", 2);
|
|
542
|
+
let BloomPlugin = _BloomPlugin;
|
|
543
|
+
let BloomPluginPass = class extends ExtendedShaderPass {
|
|
544
|
+
constructor(pid, maxIntensity = 16) {
|
|
494
545
|
super({
|
|
495
|
-
vertexShader:
|
|
546
|
+
vertexShader: CopyShader.vertexShader,
|
|
496
547
|
defines: {
|
|
497
|
-
|
|
498
|
-
|
|
548
|
+
["PASS_STEP"]: 1,
|
|
549
|
+
["MAX_INTENSITY"]: Math.min(maxIntensity, 16)
|
|
499
550
|
},
|
|
500
551
|
uniforms: {
|
|
501
552
|
tSource: { value: null },
|
|
@@ -503,213 +554,323 @@ let qe = Se, h = class extends $ {
|
|
|
503
554
|
// intensity: {value: 0.2},
|
|
504
555
|
opacity: { value: 1 },
|
|
505
556
|
// prefilter: {value: new Vector4(1, 0.5, 0, 0)},
|
|
506
|
-
tDiffuseSize: { value: new
|
|
557
|
+
tDiffuseSize: { value: new Vector2() },
|
|
507
558
|
weight: { value: 1 }
|
|
508
559
|
// tNormalDepth: {value: null},
|
|
509
560
|
// tGBufferFlags: {value: null},
|
|
510
561
|
},
|
|
511
|
-
fragmentShader:
|
|
512
|
-
}, "tDiffuse", "tSource")
|
|
562
|
+
fragmentShader: hdrBloom
|
|
563
|
+
}, "tDiffuse", "tSource");
|
|
564
|
+
this.uiConfig = void 0;
|
|
565
|
+
this.before = ["screen"];
|
|
566
|
+
this.after = ["render", "progressive"];
|
|
567
|
+
this.required = ["render"];
|
|
568
|
+
this.prefilter = new Vector4(2, 0.5, 0, 0);
|
|
569
|
+
this.threshold = 2;
|
|
570
|
+
this.softThreshold = 0.5;
|
|
571
|
+
this.intensity = 0.2;
|
|
572
|
+
this.backgroundBloom = false;
|
|
573
|
+
this.bloomIterations = 4;
|
|
574
|
+
this._currentIterations = 0;
|
|
575
|
+
this.radius = 0.6;
|
|
576
|
+
this.power = 1;
|
|
577
|
+
this.bloomDebug = false;
|
|
578
|
+
this._weights = [];
|
|
579
|
+
this.passId = pid;
|
|
580
|
+
this._updateWeights = this._updateWeights.bind(this);
|
|
581
|
+
this._thresholdsUpdated = this._thresholdsUpdated.bind(this);
|
|
582
|
+
this._updateWeights();
|
|
583
|
+
this._thresholdsUpdated();
|
|
584
|
+
this.clear = true;
|
|
513
585
|
}
|
|
514
586
|
_thresholdsUpdated() {
|
|
515
|
-
|
|
587
|
+
var _a2;
|
|
588
|
+
this.prefilter.x = this.threshold;
|
|
589
|
+
this.prefilter.y = this.softThreshold;
|
|
590
|
+
this.prefilter.z = 2 * this.prefilter.x * this.prefilter.y;
|
|
591
|
+
this.prefilter.w = ((_a2 = this.uniforms) == null ? void 0 : _a2.prefilter) ? 0.125 / (this.uniforms.prefilter.value.z + 1e-5) : 0;
|
|
516
592
|
}
|
|
517
|
-
render(
|
|
518
|
-
const
|
|
519
|
-
this.material.defines.PASS_STEP = 0
|
|
520
|
-
|
|
521
|
-
|
|
593
|
+
render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
|
|
594
|
+
const renderManager = renderer.renderManager;
|
|
595
|
+
this.material.defines.PASS_STEP = 0;
|
|
596
|
+
this.clear = true;
|
|
597
|
+
this.needsSwap = false;
|
|
598
|
+
const source = readBuffer;
|
|
599
|
+
if (!source) {
|
|
522
600
|
console.warn("BloomPluginPass: No source to read from");
|
|
523
601
|
return;
|
|
524
602
|
}
|
|
525
|
-
this.needsSwap =
|
|
526
|
-
let
|
|
527
|
-
|
|
528
|
-
let
|
|
529
|
-
|
|
530
|
-
let
|
|
531
|
-
|
|
532
|
-
let
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
603
|
+
this.needsSwap = true;
|
|
604
|
+
let sizeMultiplier = 0.5;
|
|
605
|
+
let width = source.width * sizeMultiplier;
|
|
606
|
+
let height = source.height * sizeMultiplier;
|
|
607
|
+
const textures = [];
|
|
608
|
+
let currentDestination = renderManager.getTempTarget({ sizeMultiplier: 1, type: HalfFloatType });
|
|
609
|
+
textures.push(currentDestination);
|
|
610
|
+
let currentSource = source;
|
|
611
|
+
this.material.needsUpdate = true;
|
|
612
|
+
this.material.uniforms.weight.value = this._weights[0];
|
|
613
|
+
super.render(renderer, currentDestination, currentSource, deltaTime, maskActive);
|
|
614
|
+
currentSource = currentDestination;
|
|
615
|
+
const ci = this._currentIterations;
|
|
616
|
+
let i = 1;
|
|
617
|
+
const iter = Math.max(2, this.bloomIterations);
|
|
618
|
+
for (; i < iter; i++) {
|
|
619
|
+
width /= 2;
|
|
620
|
+
height /= 2;
|
|
621
|
+
sizeMultiplier /= 2;
|
|
622
|
+
if (height < 2 || width < 2) {
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
currentDestination = renderManager.getTempTarget({ sizeMultiplier, type: HalfFloatType });
|
|
626
|
+
textures.push(currentDestination);
|
|
627
|
+
this.material.defines.PASS_STEP = 1;
|
|
628
|
+
let modifiedWeight = this._weights[i];
|
|
629
|
+
{
|
|
630
|
+
modifiedWeight = this._weights[i - 1] !== 0 ? this._weights[i] / this._weights[i - 1] : this._weights[i];
|
|
631
|
+
}
|
|
632
|
+
this.material.uniforms.weight.value = modifiedWeight;
|
|
633
|
+
this.material.needsUpdate = true;
|
|
634
|
+
super.render(renderer, currentDestination, currentSource, deltaTime, maskActive);
|
|
635
|
+
currentSource = currentDestination;
|
|
636
|
+
this._currentIterations = i + 1;
|
|
637
|
+
}
|
|
638
|
+
if (ci !== this._currentIterations)
|
|
639
|
+
this._updateWeights(false);
|
|
640
|
+
this.clear = false;
|
|
641
|
+
const oldAutoClear = renderer.autoClear;
|
|
642
|
+
renderer.autoClear = false;
|
|
643
|
+
for (i -= 2; i >= 0; i--) {
|
|
644
|
+
currentDestination = textures[i];
|
|
645
|
+
textures[i] = void 0;
|
|
646
|
+
this.material.defines.PASS_STEP = 2;
|
|
647
|
+
this.material.transparent = true;
|
|
648
|
+
this.material.blending = AdditiveBlending;
|
|
649
|
+
this.material.needsUpdate = true;
|
|
650
|
+
renderer.autoClear = false;
|
|
651
|
+
super.render(renderer, currentDestination, currentSource, deltaTime, maskActive);
|
|
652
|
+
this.material.blending = NoBlending;
|
|
653
|
+
renderManager.releaseTempTarget(currentSource);
|
|
654
|
+
currentSource = currentDestination;
|
|
537
655
|
}
|
|
538
|
-
this.clear =
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
656
|
+
this.clear = true;
|
|
657
|
+
renderer.autoClear = oldAutoClear;
|
|
658
|
+
renderer.autoClear = true;
|
|
659
|
+
if (this.bloomDebug) {
|
|
660
|
+
this.material.defines.PASS_STEP = 4;
|
|
661
|
+
this.material.needsUpdate = true;
|
|
662
|
+
super.render(renderer, writeBuffer, currentSource, deltaTime, maskActive);
|
|
663
|
+
} else {
|
|
664
|
+
this.uniforms.tSource.value = source.texture;
|
|
665
|
+
this.material.defines.PASS_STEP = 3;
|
|
666
|
+
this.material.needsUpdate = true;
|
|
667
|
+
super.render(renderer, writeBuffer, currentSource, deltaTime, maskActive);
|
|
668
|
+
this.uniforms.tSource.value = null;
|
|
669
|
+
}
|
|
670
|
+
renderManager.releaseTempTarget(currentSource);
|
|
543
671
|
}
|
|
544
|
-
_updateWeights() {
|
|
545
|
-
if (!this._weights)
|
|
546
|
-
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
672
|
+
_updateWeights(setDirty = true) {
|
|
673
|
+
if (!this._weights) return;
|
|
674
|
+
const radius = Math.max(Math.min(this.radius, 1), 0);
|
|
675
|
+
const iter = Math.max(2, this._currentIterations || this.bloomIterations);
|
|
676
|
+
const delta = 1 / (iter - 1);
|
|
677
|
+
for (let i = 0; i < iter; i++) {
|
|
678
|
+
let f = i * delta + 0.1;
|
|
679
|
+
let oneMinusF = 1.2 - f;
|
|
680
|
+
f = Math.pow(f, this.power);
|
|
681
|
+
oneMinusF = Math.pow(oneMinusF, this.power);
|
|
682
|
+
this._weights[i] = oneMinusF * (1 - radius) + f * radius;
|
|
551
683
|
}
|
|
552
|
-
this.setDirty();
|
|
684
|
+
if (setDirty !== false) this.setDirty();
|
|
553
685
|
}
|
|
554
686
|
};
|
|
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;
|
|
687
|
+
__decorateClass$3([
|
|
688
|
+
uniform()
|
|
689
|
+
], BloomPluginPass.prototype, "prefilter", 2);
|
|
690
|
+
__decorateClass$3([
|
|
691
|
+
uiSlider("Threshold", [0, 2]),
|
|
692
|
+
onChange(BloomPluginPass.prototype._thresholdsUpdated),
|
|
693
|
+
serialize()
|
|
694
|
+
], BloomPluginPass.prototype, "threshold", 2);
|
|
695
|
+
__decorateClass$3([
|
|
696
|
+
uiSlider("Soft Threshold", [0, 1]),
|
|
697
|
+
onChange(BloomPluginPass.prototype._thresholdsUpdated),
|
|
698
|
+
serialize()
|
|
699
|
+
], BloomPluginPass.prototype, "softThreshold", 2);
|
|
700
|
+
__decorateClass$3([
|
|
701
|
+
uiSlider("Intensity", [0, 3]),
|
|
702
|
+
serialize(),
|
|
703
|
+
uniform()
|
|
704
|
+
], BloomPluginPass.prototype, "intensity", 2);
|
|
705
|
+
__decorateClass$3([
|
|
706
|
+
uiToggle("Background Bloom"),
|
|
707
|
+
serialize(),
|
|
708
|
+
matDefineBool("BACKGROUND_BLOOM")
|
|
709
|
+
], BloomPluginPass.prototype, "backgroundBloom", 2);
|
|
710
|
+
__decorateClass$3([
|
|
711
|
+
uiSlider("Iterations", [2, 7], 1),
|
|
712
|
+
onChange2(BloomPluginPass.prototype._updateWeights),
|
|
713
|
+
serialize()
|
|
714
|
+
], BloomPluginPass.prototype, "bloomIterations", 2);
|
|
715
|
+
__decorateClass$3([
|
|
716
|
+
uiSlider("Radius", [0, 1], 0.01),
|
|
717
|
+
onChange2(BloomPluginPass.prototype._updateWeights),
|
|
718
|
+
serialize()
|
|
719
|
+
], BloomPluginPass.prototype, "radius", 2);
|
|
720
|
+
__decorateClass$3([
|
|
721
|
+
uiSlider("Power", [0.2, 10], 0.01),
|
|
722
|
+
onChange2(BloomPluginPass.prototype._updateWeights),
|
|
723
|
+
serialize()
|
|
724
|
+
], BloomPluginPass.prototype, "power", 2);
|
|
725
|
+
__decorateClass$3([
|
|
726
|
+
uiToggle("Debug")
|
|
727
|
+
], BloomPluginPass.prototype, "bloomDebug", 2);
|
|
728
|
+
BloomPluginPass = __decorateClass$3([
|
|
729
|
+
uiFolderContainer("Bloom Pass")
|
|
730
|
+
], BloomPluginPass);
|
|
731
|
+
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}";
|
|
732
|
+
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}";
|
|
733
|
+
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);}";
|
|
734
|
+
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}";
|
|
735
|
+
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}";
|
|
736
|
+
var __defProp$2 = Object.defineProperty;
|
|
737
|
+
var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
|
|
738
|
+
var __decorateClass$2 = (decorators, target, key, kind) => {
|
|
739
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
|
|
740
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
741
|
+
if (decorator = decorators[i])
|
|
742
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
743
|
+
if (kind && result) __defProp$2(target, key, result);
|
|
744
|
+
return result;
|
|
634
745
|
};
|
|
635
|
-
const
|
|
746
|
+
const passId$1 = "depthOfField";
|
|
747
|
+
const _DepthOfFieldPlugin = class _DepthOfFieldPlugin extends PipelinePassPlugin {
|
|
636
748
|
// ms
|
|
637
|
-
constructor(
|
|
638
|
-
super()
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
749
|
+
constructor(enabled = true, enableEdit = false) {
|
|
750
|
+
super();
|
|
751
|
+
this.passId = passId$1;
|
|
752
|
+
this.enableEdit = false;
|
|
753
|
+
this._focalPointHit = new Vector3(0, 0, 0);
|
|
754
|
+
this.crossFadeTime = 200;
|
|
755
|
+
this._focalPointHitTime = 0;
|
|
756
|
+
this.dependencies = [GBufferPlugin];
|
|
757
|
+
this._onPluginAdd = (e) => {
|
|
758
|
+
var _a2, _b, _c, _d, _e;
|
|
759
|
+
const plugin = e.plugin;
|
|
760
|
+
if (!plugin) return;
|
|
761
|
+
if (((_a2 = plugin.constructor) == null ? void 0 : _a2.PluginType) === GBufferPlugin.PluginType) {
|
|
762
|
+
const gbuffer = plugin;
|
|
763
|
+
(_b = this._pass) == null ? void 0 : _b.material.registerMaterialExtensions([gbuffer.unpackExtension]);
|
|
764
|
+
(_c = this._pass) == null ? void 0 : _c.computeCocMaterial.registerMaterialExtensions([gbuffer.unpackExtension]);
|
|
765
|
+
(_d = this._pass) == null ? void 0 : _d.expandCocMaterial.registerMaterialExtensions([gbuffer.unpackExtension]);
|
|
647
766
|
}
|
|
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);
|
|
767
|
+
if (((_e = plugin.constructor) == null ? void 0 : _e.PluginType) === PickingPlugin.PluginType) {
|
|
768
|
+
const picking = plugin;
|
|
769
|
+
picking.addEventListener("hitObject", this._onObjectHit);
|
|
657
770
|
}
|
|
658
|
-
}
|
|
771
|
+
};
|
|
772
|
+
this._onPluginRemove = (e) => {
|
|
773
|
+
var _a2, _b, _c, _d, _e;
|
|
774
|
+
const plugin = e.plugin;
|
|
775
|
+
if (!plugin) return;
|
|
776
|
+
if (((_a2 = plugin.constructor) == null ? void 0 : _a2.PluginType) === GBufferPlugin.PluginType) {
|
|
777
|
+
const gbuffer = e.plugin;
|
|
778
|
+
(_b = this._pass) == null ? void 0 : _b.material.unregisterMaterialExtensions([gbuffer.unpackExtension]);
|
|
779
|
+
(_c = this._pass) == null ? void 0 : _c.computeCocMaterial.unregisterMaterialExtensions([gbuffer.unpackExtension]);
|
|
780
|
+
(_d = this._pass) == null ? void 0 : _d.expandCocMaterial.unregisterMaterialExtensions([gbuffer.unpackExtension]);
|
|
781
|
+
}
|
|
782
|
+
if (((_e = plugin.constructor) == null ? void 0 : _e.PluginType) === PickingPlugin.PluginType) {
|
|
783
|
+
const picking = e.plugin;
|
|
784
|
+
picking.removeEventListener("hitObject", this._onObjectHit);
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
this.uiConfig = {
|
|
659
788
|
type: "folder",
|
|
660
789
|
label: "DepthOfField",
|
|
661
790
|
onChange: this.setDirty.bind(this),
|
|
662
791
|
children: [
|
|
663
|
-
...
|
|
792
|
+
...generateUiConfig(this) || [],
|
|
664
793
|
() => {
|
|
665
|
-
var
|
|
666
|
-
return (
|
|
794
|
+
var _a2;
|
|
795
|
+
return (_a2 = this._pass) == null ? void 0 : _a2.uiConfig;
|
|
667
796
|
}
|
|
668
797
|
]
|
|
669
|
-
}
|
|
798
|
+
};
|
|
799
|
+
this._tempVec = new Vector3();
|
|
800
|
+
this.enabled = enabled;
|
|
801
|
+
this.enableEdit = enableEdit;
|
|
802
|
+
this._onObjectHit = this._onObjectHit.bind(this);
|
|
803
|
+
this.setDirty = this.setDirty.bind(this);
|
|
670
804
|
}
|
|
671
805
|
get _frameFadeTime() {
|
|
672
806
|
return this.crossFadeTime * 2.5;
|
|
673
807
|
}
|
|
674
808
|
// todo make this a property.
|
|
675
|
-
setFocalPoint(
|
|
676
|
-
var
|
|
677
|
-
this._focalPointHit.copy(
|
|
809
|
+
setFocalPoint(p, fade = true, showGizmo = false) {
|
|
810
|
+
var _a2, _b;
|
|
811
|
+
this._focalPointHit.copy(p);
|
|
812
|
+
if (fade) (_b = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin("FrameFadePlugin")) == null ? void 0 : _b.startTransition(this._frameFadeTime);
|
|
813
|
+
if (showGizmo) this._focalPointHitTime = now();
|
|
814
|
+
this.setDirty();
|
|
678
815
|
}
|
|
679
816
|
getFocalPoint() {
|
|
680
817
|
return this._focalPointHit;
|
|
681
818
|
}
|
|
682
819
|
_onObjectHit(e) {
|
|
683
|
-
var
|
|
684
|
-
!this._pass || !e.intersects.intersect || this.isDisabled() || !this.enableEdit
|
|
820
|
+
var _a2, _b;
|
|
821
|
+
if (!this._pass || !e.intersects.intersect || this.isDisabled() || !this.enableEdit) return;
|
|
822
|
+
this._focalPointHit.copy(e.intersects.intersect.point);
|
|
823
|
+
this._focalPointHitTime = e.time;
|
|
824
|
+
e.intersects.selectedObject = null;
|
|
825
|
+
(_b = (_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(FrameFadePlugin)) == null ? void 0 : _b.startTransition(this._frameFadeTime);
|
|
826
|
+
this.setDirty();
|
|
685
827
|
}
|
|
686
828
|
_createPass() {
|
|
687
|
-
|
|
829
|
+
const pass = new DepthOfFieldPluginPass(this.passId);
|
|
830
|
+
return pass;
|
|
688
831
|
}
|
|
689
832
|
// todo use gbufferUnpackExtension from render manager to support depth buffer plugin as well.
|
|
690
|
-
onAdded(
|
|
691
|
-
super.onAdded(
|
|
833
|
+
onAdded(viewer) {
|
|
834
|
+
super.onAdded(viewer);
|
|
835
|
+
viewer.addEventListener("addPlugin", this._onPluginAdd);
|
|
836
|
+
viewer.addEventListener("removePlugin", this._onPluginRemove);
|
|
837
|
+
this._onPluginAdd({ plugin: viewer.getPlugin(GBufferPlugin) });
|
|
838
|
+
this._onPluginAdd({ plugin: viewer.getPlugin(PickingPlugin) });
|
|
692
839
|
}
|
|
693
|
-
onRemove(
|
|
694
|
-
|
|
840
|
+
onRemove(viewer) {
|
|
841
|
+
viewer.removeEventListener("addPlugin", this._onPluginAdd);
|
|
842
|
+
viewer.removeEventListener("removePlugin", this._onPluginRemove);
|
|
843
|
+
this._onPluginRemove({ plugin: viewer.getPlugin(GBufferPlugin) });
|
|
844
|
+
this._onPluginRemove({ plugin: viewer.getPlugin(PickingPlugin) });
|
|
845
|
+
super.onRemove(viewer);
|
|
695
846
|
}
|
|
696
|
-
_beforeRender(
|
|
697
|
-
if (!super._beforeRender(
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
if (
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
847
|
+
_beforeRender(scene, camera, renderManager) {
|
|
848
|
+
if (!super._beforeRender(scene, camera, renderManager)) return false;
|
|
849
|
+
const pass = this.pass;
|
|
850
|
+
if (!pass) return false;
|
|
851
|
+
if (pass.dofBlurMaterial.uniforms.frameCount)
|
|
852
|
+
renderManager == null ? void 0 : renderManager.updateShaderProperties(pass.dofBlurMaterial);
|
|
853
|
+
const cam = camera;
|
|
854
|
+
if (!cam) return false;
|
|
855
|
+
cam.updateMatrixWorld(true);
|
|
856
|
+
cam.updateShaderProperties(pass.material);
|
|
857
|
+
cam.getWorldPosition(this._tempVec);
|
|
858
|
+
this._tempVec.subVectors(this._focalPointHit, this._tempVec);
|
|
859
|
+
pass.focalDepthRange.x = this._tempVec.length();
|
|
860
|
+
pass.focalDepthRange.x *= cam.getWorldDirection(new Vector3()).dot(this._tempVec.normalize());
|
|
861
|
+
let crossAlpha = (now() - this._focalPointHitTime) / this.crossFadeTime;
|
|
862
|
+
crossAlpha = 1 - Math.min(1, Math.max(0, crossAlpha));
|
|
863
|
+
if (Math.abs(crossAlpha - pass.crossAlpha) > 0.01) {
|
|
864
|
+
pass.crossAlpha = crossAlpha;
|
|
865
|
+
this.setDirty();
|
|
866
|
+
}
|
|
867
|
+
if (crossAlpha > 0) {
|
|
868
|
+
const projectedPoint = this._tempVec.copy(this._focalPointHit).project(cam).addScalar(1).divideScalar(2);
|
|
869
|
+
pass.crossCenter.set(projectedPoint.x, projectedPoint.y);
|
|
870
|
+
pass.computeCocMaterial.uniformsNeedUpdate = true;
|
|
871
|
+
pass.expandCocMaterial.uniformsNeedUpdate = true;
|
|
711
872
|
}
|
|
712
|
-
return
|
|
873
|
+
return true;
|
|
713
874
|
}
|
|
714
875
|
// region to be done or removed
|
|
715
876
|
// static AddDepthOfFieldData(material: IMaterial, params?: IMaterialUserData['DepthOfField'], setDirty = true): IMaterialUserData['DepthOfField']|null {
|
|
@@ -789,174 +950,213 @@ const rt = "depthOfField", W = class W extends I {
|
|
|
789
950
|
// }
|
|
790
951
|
// endregion
|
|
791
952
|
};
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
953
|
+
_DepthOfFieldPlugin.PluginType = "DepthOfField";
|
|
954
|
+
_DepthOfFieldPlugin.OldPluginType = "DepthOfFieldPlugin";
|
|
955
|
+
let DepthOfFieldPlugin = _DepthOfFieldPlugin;
|
|
956
|
+
__decorateClass$2([
|
|
957
|
+
serialize(),
|
|
958
|
+
uiToggle()
|
|
959
|
+
], DepthOfFieldPlugin.prototype, "enableEdit", 2);
|
|
960
|
+
__decorateClass$2([
|
|
961
|
+
serialize("focalPoint")
|
|
962
|
+
], DepthOfFieldPlugin.prototype, "_focalPointHit", 2);
|
|
963
|
+
__decorateClass$2([
|
|
964
|
+
serialize()
|
|
965
|
+
], DepthOfFieldPlugin.prototype, "crossFadeTime", 2);
|
|
966
|
+
const dofBlurMaterialPoisson = new ExtendedShaderMaterial({
|
|
805
967
|
uniforms: {
|
|
806
968
|
colorTexture: { value: null },
|
|
807
|
-
colorTextureSize: { value: new
|
|
808
|
-
direction: { value: new
|
|
969
|
+
colorTextureSize: { value: new Vector2() },
|
|
970
|
+
direction: { value: new Vector2() },
|
|
809
971
|
frameCount: { value: 0 },
|
|
810
972
|
blurRadius: { value: 16 }
|
|
811
973
|
},
|
|
812
|
-
vertexShader:
|
|
813
|
-
fragmentShader:
|
|
814
|
-
` + Ze,
|
|
974
|
+
vertexShader: shaderUtils.defaultVertex,
|
|
975
|
+
fragmentShader: poissonDiskSamples + "\n" + dofPoissonBox,
|
|
815
976
|
defines: {
|
|
816
|
-
DOF_MODE: 1
|
|
977
|
+
["DOF_MODE"]: 1
|
|
817
978
|
}
|
|
818
979
|
}, ["colorTexture"]);
|
|
819
|
-
let
|
|
820
|
-
constructor(
|
|
980
|
+
let DepthOfFieldPluginPass = class extends ExtendedShaderPass {
|
|
981
|
+
constructor(pid) {
|
|
821
982
|
super({
|
|
822
983
|
uniforms: {
|
|
823
984
|
colorTexture: { value: null },
|
|
824
985
|
blurTexture: { value: null },
|
|
825
986
|
cocTexture: { value: null },
|
|
826
|
-
cocTextureSize: { value: new
|
|
827
|
-
cameraNearFar: { value: new
|
|
987
|
+
cocTextureSize: { value: new Vector2() },
|
|
988
|
+
cameraNearFar: { value: new Vector2() }
|
|
828
989
|
},
|
|
829
|
-
vertexShader:
|
|
830
|
-
fragmentShader:
|
|
831
|
-
}, "colorTexture", "cocTexture", "blurTexture")
|
|
990
|
+
vertexShader: shaderUtils.defaultVertex,
|
|
991
|
+
fragmentShader: dofCombine
|
|
992
|
+
}, "colorTexture", "cocTexture", "blurTexture");
|
|
993
|
+
this.uiConfig = void 0;
|
|
994
|
+
this.before = ["progressive", "screen"];
|
|
995
|
+
this.after = ["render"];
|
|
996
|
+
this.required = ["render"];
|
|
997
|
+
this.dofBlurMaterial = dofBlurMaterialPoisson;
|
|
998
|
+
this.nearFarBlurScale = new Vector2(0.25, 0.25);
|
|
999
|
+
this.focalDepthRange = new Vector2(0.5, 1.5);
|
|
1000
|
+
this.crossCenter = new Vector2(0.5, 0.5);
|
|
1001
|
+
this.crossRadius = 0.04;
|
|
1002
|
+
this.crossAlpha = 1;
|
|
1003
|
+
this.crossColor = new Color(16750848);
|
|
1004
|
+
this.passId = pid;
|
|
1005
|
+
this.computeCocMaterial = new ExtendedShaderMaterial({
|
|
832
1006
|
uniforms: {
|
|
833
1007
|
colorTexture: { value: null },
|
|
834
1008
|
cameraNearFar: this.uniforms.cameraNearFar,
|
|
835
1009
|
nearFarBlurScale: this.uniforms.nearFarBlurScale,
|
|
836
1010
|
focalDepthRange: this.uniforms.focalDepthRange
|
|
837
1011
|
},
|
|
838
|
-
vertexShader:
|
|
839
|
-
fragmentShader:
|
|
840
|
-
}, ["colorTexture"])
|
|
1012
|
+
vertexShader: shaderUtils.defaultVertex,
|
|
1013
|
+
fragmentShader: dofComputeCoC
|
|
1014
|
+
}, ["colorTexture"]);
|
|
1015
|
+
this.expandCocMaterial = new ExtendedShaderMaterial({
|
|
841
1016
|
uniforms: {
|
|
842
1017
|
colorTexture: { value: null },
|
|
843
|
-
colorTextureSize: { value: new
|
|
844
|
-
direction: { value: new
|
|
1018
|
+
colorTextureSize: { value: new Vector2() },
|
|
1019
|
+
direction: { value: new Vector2() },
|
|
845
1020
|
nearFarBlurScale: this.uniforms.nearFarBlurScale
|
|
846
1021
|
},
|
|
847
|
-
vertexShader:
|
|
848
|
-
fragmentShader:
|
|
1022
|
+
vertexShader: shaderUtils.defaultVertex,
|
|
1023
|
+
fragmentShader: dofExpandCoC
|
|
849
1024
|
}, ["colorTexture"]);
|
|
850
1025
|
}
|
|
851
|
-
render(
|
|
852
|
-
if (!this.enabled)
|
|
853
|
-
|
|
854
|
-
if (!i) {
|
|
1026
|
+
render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
|
|
1027
|
+
if (!this.enabled) return;
|
|
1028
|
+
if (!readBuffer) {
|
|
855
1029
|
console.error("DepthOfFieldPluginPass: No readBuffer");
|
|
856
1030
|
return;
|
|
857
1031
|
}
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
|
|
1032
|
+
const renderManager = renderer.renderManager;
|
|
1033
|
+
const halfPars = {
|
|
1034
|
+
minFilter: NearestFilter,
|
|
1035
|
+
magFilter: NearestFilter,
|
|
861
1036
|
// type: UnsignedByteType,
|
|
862
1037
|
// encoding: RGBM16Encoding,
|
|
863
|
-
type:
|
|
1038
|
+
type: HalfFloatType,
|
|
864
1039
|
// encoding: LinearEncoding,
|
|
865
|
-
colorSpace:
|
|
1040
|
+
colorSpace: LinearSRGBColorSpace,
|
|
866
1041
|
sizeMultiplier: 0.5,
|
|
867
1042
|
// samples: 1,
|
|
868
|
-
format:
|
|
869
|
-
depthBuffer:
|
|
870
|
-
generateMipmaps:
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
1043
|
+
format: RGBAFormat,
|
|
1044
|
+
depthBuffer: false,
|
|
1045
|
+
generateMipmaps: false
|
|
1046
|
+
};
|
|
1047
|
+
const cocRt = renderManager.getTempTarget(halfPars);
|
|
1048
|
+
const renderTargetBlurTemp = renderManager.getTempTarget(halfPars);
|
|
1049
|
+
this.computeCocMaterial.uniforms.colorTexture.value = readBuffer.texture;
|
|
1050
|
+
renderManager.blit(cocRt, { material: this.computeCocMaterial });
|
|
1051
|
+
this.expandCocMaterial.uniforms.colorTexture.value = cocRt.texture;
|
|
1052
|
+
this.expandCocMaterial.uniforms.direction.value.set(1, 0);
|
|
1053
|
+
renderManager.blit(renderTargetBlurTemp, { material: this.expandCocMaterial });
|
|
1054
|
+
this.expandCocMaterial.uniforms.colorTexture.value = renderTargetBlurTemp.texture;
|
|
1055
|
+
this.expandCocMaterial.uniforms.direction.value.set(0, 1);
|
|
1056
|
+
renderManager.blit(cocRt, { material: this.expandCocMaterial });
|
|
1057
|
+
if (this.dofBlurMaterial.uniforms.frameCount) {
|
|
1058
|
+
this.dofBlurMaterial.uniforms.colorTexture.value = cocRt.texture;
|
|
1059
|
+
renderManager.blit(renderTargetBlurTemp, { material: this.dofBlurMaterial });
|
|
1060
|
+
} else {
|
|
1061
|
+
const renderTargetBlurTemp2 = renderManager.getTempTarget(halfPars);
|
|
1062
|
+
this.dofBlurMaterial.uniforms.cocTexture.value = cocRt.texture;
|
|
1063
|
+
this.dofBlurMaterial.uniforms.colorTexture.value = cocRt.texture;
|
|
1064
|
+
this.dofBlurMaterial.uniforms.direction.value.set(1, 0);
|
|
1065
|
+
renderManager.blit(renderTargetBlurTemp2, { material: this.dofBlurMaterial });
|
|
1066
|
+
this.dofBlurMaterial.uniforms.colorTexture.value = renderTargetBlurTemp2.texture;
|
|
1067
|
+
this.dofBlurMaterial.uniforms.direction.value.set(0, 1);
|
|
1068
|
+
renderManager.blit(renderTargetBlurTemp, { material: this.dofBlurMaterial });
|
|
1069
|
+
renderManager.releaseTempTarget(renderTargetBlurTemp2);
|
|
877
1070
|
}
|
|
878
|
-
this.material.uniforms.blurTexture.value =
|
|
1071
|
+
this.material.uniforms.blurTexture.value = renderTargetBlurTemp.texture;
|
|
1072
|
+
this.material.uniforms.cocTexture.value = cocRt.texture;
|
|
1073
|
+
super.render(renderer, writeBuffer, readBuffer, deltaTime, maskActive);
|
|
1074
|
+
renderManager.releaseTempTarget(cocRt);
|
|
1075
|
+
renderManager.releaseTempTarget(renderTargetBlurTemp);
|
|
879
1076
|
}
|
|
880
1077
|
};
|
|
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;
|
|
1078
|
+
__decorateClass$2([
|
|
1079
|
+
bindToValue({ obj: "focalDepthRange", key: "y" }),
|
|
1080
|
+
uiSlider("Depth Range", [0.25, 3])
|
|
1081
|
+
], DepthOfFieldPluginPass.prototype, "depthRange", 2);
|
|
1082
|
+
__decorateClass$2([
|
|
1083
|
+
bindToValue({ obj: "nearFarBlurScale", key: "x" }),
|
|
1084
|
+
uiSlider("Near Blur Scale", [0, 1])
|
|
1085
|
+
], DepthOfFieldPluginPass.prototype, "nearBlurScale", 2);
|
|
1086
|
+
__decorateClass$2([
|
|
1087
|
+
bindToValue({ obj: "nearFarBlurScale", key: "y" }),
|
|
1088
|
+
uiSlider("Far Blur Scale", [0, 1])
|
|
1089
|
+
], DepthOfFieldPluginPass.prototype, "farBlurScale", 2);
|
|
1090
|
+
__decorateClass$2([
|
|
1091
|
+
serialize(),
|
|
1092
|
+
uniform()
|
|
1093
|
+
], DepthOfFieldPluginPass.prototype, "nearFarBlurScale", 2);
|
|
1094
|
+
__decorateClass$2([
|
|
1095
|
+
serialize(),
|
|
1096
|
+
uniform()
|
|
1097
|
+
], DepthOfFieldPluginPass.prototype, "focalDepthRange", 2);
|
|
1098
|
+
__decorateClass$2([
|
|
1099
|
+
uniform()
|
|
1100
|
+
], DepthOfFieldPluginPass.prototype, "crossCenter", 2);
|
|
1101
|
+
__decorateClass$2([
|
|
1102
|
+
uniform()
|
|
1103
|
+
], DepthOfFieldPluginPass.prototype, "crossRadius", 2);
|
|
1104
|
+
__decorateClass$2([
|
|
1105
|
+
uniform()
|
|
1106
|
+
], DepthOfFieldPluginPass.prototype, "crossAlpha", 2);
|
|
1107
|
+
__decorateClass$2([
|
|
1108
|
+
uniform()
|
|
1109
|
+
], DepthOfFieldPluginPass.prototype, "crossColor", 2);
|
|
1110
|
+
DepthOfFieldPluginPass = __decorateClass$2([
|
|
1111
|
+
uiFolderContainer("DepthOfField Pass")
|
|
1112
|
+
], DepthOfFieldPluginPass);
|
|
1113
|
+
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";
|
|
1114
|
+
var __defProp$1 = Object.defineProperty;
|
|
1115
|
+
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
1116
|
+
var __decorateClass$1 = (decorators, target, key, kind) => {
|
|
1117
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
|
|
1118
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1119
|
+
if (decorator = decorators[i])
|
|
1120
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
1121
|
+
if (kind && result) __defProp$1(target, key, result);
|
|
1122
|
+
return result;
|
|
933
1123
|
};
|
|
934
|
-
let
|
|
1124
|
+
let SSContactShadowsPlugin = class extends AViewerPluginSync {
|
|
935
1125
|
// private _loaderCreate({loader}: {loader: GLTFLoader2}) {
|
|
936
1126
|
// if (!loader.isGLTFLoader2) return
|
|
937
1127
|
// loader.register((p) => new GLTFMaterialsSSContactShadowsExtensionImport(p))
|
|
938
1128
|
// }
|
|
939
|
-
constructor(
|
|
940
|
-
super()
|
|
1129
|
+
constructor(enabled = true) {
|
|
1130
|
+
super();
|
|
1131
|
+
this.enabled = true;
|
|
1132
|
+
this._uniforms = {
|
|
941
1133
|
sscsRadius: { value: 0.03 },
|
|
942
1134
|
sscsIntensity: { value: 1 },
|
|
943
1135
|
sscsTolerance: { value: 1.5 },
|
|
944
1136
|
// tLastFrame: {value: null}, // not needed since we dont need color
|
|
945
1137
|
frameCount: { value: 0 },
|
|
946
|
-
projection: { value: new
|
|
947
|
-
cameraPositionWorld: { value: new
|
|
948
|
-
cameraNearFar: { value: new
|
|
1138
|
+
projection: { value: new Matrix4() },
|
|
1139
|
+
cameraPositionWorld: { value: new Vector3() },
|
|
1140
|
+
cameraNearFar: { value: new Vector2(0.1, 1e3) },
|
|
949
1141
|
sceneBoundingRadius: { value: 0 }
|
|
950
|
-
}
|
|
951
|
-
|
|
1142
|
+
};
|
|
1143
|
+
this.radius = 0.015;
|
|
1144
|
+
this.intensity = 1;
|
|
1145
|
+
this.tolerance = 1.5;
|
|
1146
|
+
this._defines = {
|
|
1147
|
+
["PERSPECTIVE_CAMERA"]: 1
|
|
952
1148
|
// set in PerspectiveCamera2
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
1149
|
+
};
|
|
1150
|
+
this.onlySSCSDebug = false;
|
|
1151
|
+
this.stepCount = 2;
|
|
1152
|
+
this.dependencies = [GBufferPlugin];
|
|
1153
|
+
this.materialExtension = {
|
|
1154
|
+
uuid: SSContactShadowsPlugin.PluginType,
|
|
1155
|
+
shaderExtender: (shader, _material, _renderer) => {
|
|
1156
|
+
var _a2, _b;
|
|
1157
|
+
if (!shader.defines.SSCS_ENABLED) return;
|
|
1158
|
+
const rsS = "float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {";
|
|
1159
|
+
const lsS = glsl`
|
|
960
1160
|
#ifndef D_sceneBoundingRadius
|
|
961
1161
|
#define D_sceneBoundingRadius
|
|
962
1162
|
uniform float sceneBoundingRadius;
|
|
@@ -974,7 +1174,8 @@ let p = class extends Me {
|
|
|
974
1174
|
#if defined(SSCS_DEBUG) && SSCS_DEBUG > 0
|
|
975
1175
|
return state.z;
|
|
976
1176
|
#endif
|
|
977
|
-
|
|
1177
|
+
`;
|
|
1178
|
+
const shadowChunk = `
|
|
978
1179
|
#if SSCS_ENABLED
|
|
979
1180
|
|
|
980
1181
|
uniform float sscsIntensity;
|
|
@@ -984,37 +1185,44 @@ let p = class extends Me {
|
|
|
984
1185
|
#define THREE_PACKING_INCLUDED // by threejs
|
|
985
1186
|
#include <cameraHelpers>
|
|
986
1187
|
#include <randomHelpers>
|
|
987
|
-
${
|
|
1188
|
+
${ssrtShader}
|
|
988
1189
|
|
|
989
1190
|
#endif
|
|
990
|
-
|
|
991
|
-
` + B(ae.shadowmap_pars_fragment, t, `${s}
|
|
1191
|
+
` + shaderReplaceString(ShaderChunk.shadowmap_pars_fragment, rsS, `${lsS}
|
|
992
1192
|
`).replace("return shadow;", "return min(shadow, state.z);");
|
|
993
|
-
|
|
994
|
-
|
|
1193
|
+
shader.fragmentShader = shaderReplaceString(shader.fragmentShader, "#include <shadowmap_pars_fragment>", shadowChunk);
|
|
1194
|
+
shader.fragmentShader = shader.fragmentShader.replace("#include <lights_fragment_begin>", ShaderChunk.lights_fragment_begin);
|
|
1195
|
+
shader.fragmentShader = shaderReplaceString(
|
|
1196
|
+
shader.fragmentShader,
|
|
995
1197
|
"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;",
|
|
996
1198
|
"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ], directLight.direction ) : 1.0;"
|
|
997
|
-
)
|
|
998
|
-
|
|
1199
|
+
);
|
|
1200
|
+
shader.fragmentShader = shaderReplaceString(
|
|
1201
|
+
shader.fragmentShader,
|
|
999
1202
|
"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;",
|
|
1000
1203
|
"directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ], directLight.direction ) : 1.0;"
|
|
1001
|
-
)
|
|
1204
|
+
);
|
|
1205
|
+
(_b = (_a2 = this._gbufferUnpackExtension) == null ? void 0 : _a2.shaderExtender) == null ? void 0 : _b.call(_a2, shader, _material, _renderer);
|
|
1002
1206
|
},
|
|
1003
|
-
onObjectRender: (
|
|
1004
|
-
var
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1207
|
+
onObjectRender: (_, material, renderer) => {
|
|
1208
|
+
var _a2, _b;
|
|
1209
|
+
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;
|
|
1210
|
+
updateMaterialDefines({
|
|
1007
1211
|
...this._defines,
|
|
1008
|
-
SSCS_ENABLED:
|
|
1009
|
-
},
|
|
1212
|
+
["SSCS_ENABLED"]: enabled2
|
|
1213
|
+
}, material);
|
|
1010
1214
|
},
|
|
1011
1215
|
extraUniforms: {
|
|
1012
1216
|
...this._uniforms
|
|
1013
1217
|
// todo should not be static because of multiple viewers
|
|
1014
1218
|
},
|
|
1015
1219
|
extraDefines: {},
|
|
1016
|
-
computeCacheKey: (
|
|
1017
|
-
|
|
1220
|
+
computeCacheKey: (_) => {
|
|
1221
|
+
return this.isDisabled() ? "0" : "1";
|
|
1222
|
+
},
|
|
1223
|
+
isCompatible: (material1) => {
|
|
1224
|
+
return material1.isPhysicalMaterial;
|
|
1225
|
+
},
|
|
1018
1226
|
// getUiConfig: (material: PhysicalMaterial) => {
|
|
1019
1227
|
// const viewer = this._viewer!
|
|
1020
1228
|
// if (material.userData._clearcoatTint === undefined) material.userData._clearcoatTint = {}
|
|
@@ -1069,185 +1277,210 @@ let p = class extends Me {
|
|
|
1069
1277
|
// return config
|
|
1070
1278
|
// },
|
|
1071
1279
|
updaters: () => {
|
|
1072
|
-
var
|
|
1280
|
+
var _a2, _b, _c, _d;
|
|
1073
1281
|
return [
|
|
1074
1282
|
// this._viewer?.getPlugin(GBufferPlugin),
|
|
1075
|
-
(
|
|
1076
|
-
(
|
|
1077
|
-
(
|
|
1078
|
-
(
|
|
1283
|
+
(_a2 = this._viewer) == null ? void 0 : _a2.getPlugin(ProgressivePlugin),
|
|
1284
|
+
(_b = this._viewer) == null ? void 0 : _b.scene.renderCamera,
|
|
1285
|
+
(_c = this._viewer) == null ? void 0 : _c.renderManager,
|
|
1286
|
+
(_d = this._viewer) == null ? void 0 : _d.scene
|
|
1079
1287
|
];
|
|
1080
1288
|
}
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1289
|
+
};
|
|
1290
|
+
this._gbufferUnpackExtension = void 0;
|
|
1291
|
+
this._gbufferUnpackExtensionChanged = () => {
|
|
1292
|
+
if (!this._viewer) throw new Error("SSContactShadowPlugin: pass/viewer not created yet");
|
|
1293
|
+
const newExtension = this._viewer.renderManager.gbufferUnpackExtension;
|
|
1294
|
+
if (this._gbufferUnpackExtension === newExtension) return;
|
|
1295
|
+
if (this._gbufferUnpackExtension) this.setGBufferUnpackExtension(void 0);
|
|
1296
|
+
this._gbufferUnpackExtension = newExtension;
|
|
1297
|
+
if (this._gbufferUnpackExtension) this.setGBufferUnpackExtension(this._gbufferUnpackExtension);
|
|
1298
|
+
else this._viewer.console.warn("SSContactShadowPlugin: GBuffer unpack extension removed");
|
|
1299
|
+
};
|
|
1300
|
+
this.enabled = enabled;
|
|
1087
1301
|
}
|
|
1088
1302
|
setDirty() {
|
|
1089
|
-
var
|
|
1090
|
-
(
|
|
1303
|
+
var _a2, _b, _c;
|
|
1304
|
+
(_b = (_a2 = this.materialExtension) == null ? void 0 : _a2.setDirty) == null ? void 0 : _b.call(_a2);
|
|
1305
|
+
(_c = this._viewer) == null ? void 0 : _c.setDirty();
|
|
1091
1306
|
}
|
|
1092
|
-
onAdded(
|
|
1093
|
-
super.onAdded(
|
|
1307
|
+
onAdded(v) {
|
|
1308
|
+
super.onAdded(v);
|
|
1309
|
+
v.assetManager.materials.registerMaterialExtension(this.materialExtension);
|
|
1310
|
+
if (v.getPlugin(BaseGroundPlugin)) v.getPlugin(BaseGroundPlugin).material.userData.sscsDisabled = false;
|
|
1311
|
+
this._gbufferUnpackExtensionChanged();
|
|
1312
|
+
v.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
|
|
1094
1313
|
}
|
|
1095
|
-
onRemove(
|
|
1096
|
-
var
|
|
1097
|
-
|
|
1314
|
+
onRemove(v) {
|
|
1315
|
+
var _a2;
|
|
1316
|
+
(_a2 = v.assetManager.materials) == null ? void 0 : _a2.unregisterMaterialExtension(this.materialExtension);
|
|
1317
|
+
v.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
|
|
1318
|
+
return super.onRemove(v);
|
|
1098
1319
|
}
|
|
1099
|
-
setGBufferUnpackExtension(
|
|
1100
|
-
this._gbufferUnpackExtension =
|
|
1320
|
+
setGBufferUnpackExtension(extension) {
|
|
1321
|
+
this._gbufferUnpackExtension = extension;
|
|
1322
|
+
if (!this._gbufferUnpackExtension) return;
|
|
1323
|
+
Object.assign(this.materialExtension.extraUniforms, this._gbufferUnpackExtension.extraUniforms);
|
|
1324
|
+
Object.assign(this.materialExtension.extraDefines, this._gbufferUnpackExtension.extraDefines);
|
|
1101
1325
|
}
|
|
1102
1326
|
// public static readonly CLEARCOAT_TINT_GLTF_EXTENSION = 'WEBGI_materials_clearcoat_tint'
|
|
1103
1327
|
};
|
|
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;
|
|
1328
|
+
SSContactShadowsPlugin.PluginType = "SSContactShadows";
|
|
1329
|
+
SSContactShadowsPlugin.OldPluginType = "SSContactShadowsPlugin";
|
|
1330
|
+
__decorateClass$1([
|
|
1331
|
+
uiToggle("Enabled"),
|
|
1332
|
+
serialize(),
|
|
1333
|
+
onChange(SSContactShadowsPlugin.prototype.setDirty)
|
|
1334
|
+
], SSContactShadowsPlugin.prototype, "enabled", 2);
|
|
1335
|
+
__decorateClass$1([
|
|
1336
|
+
uniform({ propKey: "sscsRadius", onChange: SSContactShadowsPlugin.prototype.setDirty }),
|
|
1337
|
+
uiSlider("Radius", [1e-4, 0.1], 1e-4),
|
|
1338
|
+
serialize()
|
|
1339
|
+
], SSContactShadowsPlugin.prototype, "radius", 2);
|
|
1340
|
+
__decorateClass$1([
|
|
1341
|
+
uniform({ propKey: "sscsIntensity", onChange: SSContactShadowsPlugin.prototype.setDirty }),
|
|
1342
|
+
uiSlider("Intensity", [1e-4, 1], 1e-4),
|
|
1343
|
+
serialize()
|
|
1344
|
+
], SSContactShadowsPlugin.prototype, "intensity", 2);
|
|
1345
|
+
__decorateClass$1([
|
|
1346
|
+
uniform({ propKey: "sscsTolerance", onChange: SSContactShadowsPlugin.prototype.setDirty }),
|
|
1347
|
+
uiSlider("Tolerance", [0.1, 5]),
|
|
1348
|
+
serialize()
|
|
1349
|
+
], SSContactShadowsPlugin.prototype, "tolerance", 2);
|
|
1350
|
+
__decorateClass$1([
|
|
1351
|
+
matDefine("SSCS_DEBUG", void 0, true, SSContactShadowsPlugin.prototype.setDirty),
|
|
1352
|
+
uiToggle("Debug only SSCS"),
|
|
1353
|
+
serialize()
|
|
1354
|
+
], SSContactShadowsPlugin.prototype, "onlySSCSDebug", 2);
|
|
1355
|
+
__decorateClass$1([
|
|
1356
|
+
matDefine("SSCS_STEP_COUNT", void 0, true, SSContactShadowsPlugin.prototype.setDirty),
|
|
1357
|
+
uiSlider("Step count", [1, 8], 1),
|
|
1358
|
+
serialize()
|
|
1359
|
+
], SSContactShadowsPlugin.prototype, "stepCount", 2);
|
|
1360
|
+
SSContactShadowsPlugin = __decorateClass$1([
|
|
1361
|
+
uiFolderContainer("SS Contact Shadows")
|
|
1362
|
+
], SSContactShadowsPlugin);
|
|
1363
|
+
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;}";
|
|
1364
|
+
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.);}";
|
|
1365
|
+
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";
|
|
1366
|
+
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}";
|
|
1367
|
+
var __defProp = Object.defineProperty;
|
|
1368
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
1369
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
1370
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
1371
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1372
|
+
if (decorator = decorators[i])
|
|
1373
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
1374
|
+
if (kind && result) __defProp(target, key, result);
|
|
1375
|
+
return result;
|
|
1174
1376
|
};
|
|
1175
|
-
const
|
|
1176
|
-
let
|
|
1377
|
+
const passId = "ssrefl";
|
|
1378
|
+
let SSReflectionPlugin = class extends PipelinePassPlugin {
|
|
1177
1379
|
// cannot be changed after creation (for now)
|
|
1178
|
-
constructor(
|
|
1179
|
-
super()
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1380
|
+
constructor(inlineShaderRayTrace = true, bufferType = UnsignedByteType, sizeMultiplier = 1, enabled = true) {
|
|
1381
|
+
super();
|
|
1382
|
+
this.inlineShaderRayTrace = inlineShaderRayTrace;
|
|
1383
|
+
this.passId = passId;
|
|
1384
|
+
this.dependencies = [GBufferPlugin, SSAAPlugin];
|
|
1385
|
+
this._gbufferUnpackExtension = void 0;
|
|
1386
|
+
this._gbufferUnpackExtensionChanged = () => {
|
|
1387
|
+
if (!this._pass || !this._viewer) throw new Error("SSReflectionPlugin: pass/viewer not created yet");
|
|
1388
|
+
const newExtension = this._viewer.renderManager.gbufferUnpackExtension;
|
|
1389
|
+
if (this._gbufferUnpackExtension === newExtension) return;
|
|
1390
|
+
if (this._gbufferUnpackExtension) this._pass.setGBufferUnpackExtension(void 0);
|
|
1391
|
+
this._gbufferUnpackExtension = newExtension;
|
|
1392
|
+
if (this._gbufferUnpackExtension) this._pass.setGBufferUnpackExtension(this._gbufferUnpackExtension);
|
|
1393
|
+
else this._viewer.console.warn("SSReflectionPlugin: GBuffer unpack extension removed");
|
|
1394
|
+
};
|
|
1395
|
+
this.enabled = enabled;
|
|
1396
|
+
this.bufferType = bufferType;
|
|
1397
|
+
this.sizeMultiplier = sizeMultiplier;
|
|
1185
1398
|
}
|
|
1186
|
-
_createTarget(
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1399
|
+
_createTarget(recreate = true) {
|
|
1400
|
+
if (!this._viewer) return;
|
|
1401
|
+
if (recreate) this._disposeTarget();
|
|
1402
|
+
if (this.inlineShaderRayTrace) return;
|
|
1403
|
+
if (!this.target)
|
|
1404
|
+
this.target = this._viewer.renderManager.createTarget(
|
|
1405
|
+
{
|
|
1406
|
+
depthBuffer: false,
|
|
1407
|
+
type: this.bufferType,
|
|
1408
|
+
sizeMultiplier: this.sizeMultiplier
|
|
1409
|
+
// magFilter: NearestFilter,
|
|
1410
|
+
// minFilter: NearestFilter,
|
|
1411
|
+
// generateMipmaps: false,
|
|
1412
|
+
// encoding: LinearEncoding,
|
|
1413
|
+
}
|
|
1414
|
+
);
|
|
1415
|
+
this.texture = this.target.texture;
|
|
1416
|
+
this.texture.name = "ssreflBuffer";
|
|
1417
|
+
if (this._pass) this._pass.target = this.target;
|
|
1198
1418
|
}
|
|
1199
1419
|
_disposeTarget() {
|
|
1200
|
-
|
|
1420
|
+
if (!this._viewer) return;
|
|
1421
|
+
if (this.target) {
|
|
1422
|
+
this._viewer.renderManager.disposeTarget(this.target);
|
|
1423
|
+
this.target = void 0;
|
|
1424
|
+
}
|
|
1425
|
+
this.texture = void 0;
|
|
1201
1426
|
}
|
|
1202
1427
|
_createPass() {
|
|
1203
|
-
if (!this._viewer)
|
|
1204
|
-
throw new Error("SSReflectionPlugin: viewer not set");
|
|
1428
|
+
if (!this._viewer) throw new Error("SSReflectionPlugin: viewer not set");
|
|
1205
1429
|
if (!this._viewer.renderManager.gbufferTarget || !this._viewer.renderManager.gbufferUnpackExtension)
|
|
1206
1430
|
throw new Error("SSReflectionPlugin: GBuffer target not created. GBufferPlugin is required.");
|
|
1207
|
-
|
|
1431
|
+
this._createTarget(true);
|
|
1432
|
+
return new SSReflectionPluginPass(this.passId, this.target, this.inlineShaderRayTrace);
|
|
1208
1433
|
}
|
|
1209
|
-
onAdded(
|
|
1210
|
-
super.onAdded(
|
|
1434
|
+
onAdded(viewer) {
|
|
1435
|
+
super.onAdded(viewer);
|
|
1436
|
+
if (viewer.getPlugin("Ground") || viewer.getPlugin("BaseGroundPlugin")) console.error("GroundPlugin must be added after SSReflectionPlugin");
|
|
1437
|
+
this._gbufferUnpackExtensionChanged();
|
|
1438
|
+
viewer.renderManager.addEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
|
|
1211
1439
|
}
|
|
1212
|
-
onRemove(
|
|
1213
|
-
|
|
1440
|
+
onRemove(viewer) {
|
|
1441
|
+
this._disposeTarget();
|
|
1442
|
+
viewer.renderManager.removeEventListener("gbufferUnpackExtensionChanged", this._gbufferUnpackExtensionChanged);
|
|
1443
|
+
return super.onRemove(viewer);
|
|
1214
1444
|
}
|
|
1215
|
-
_beforeRender(
|
|
1216
|
-
var
|
|
1217
|
-
|
|
1445
|
+
_beforeRender(_, _1, _2) {
|
|
1446
|
+
var _a2;
|
|
1447
|
+
if (!this._viewer) return false;
|
|
1448
|
+
(_a2 = this._pass) == null ? void 0 : _a2.updateShaderProperties([this._viewer.getPlugin(ProgressivePlugin)]);
|
|
1449
|
+
return super._beforeRender(_, _1, _2);
|
|
1218
1450
|
}
|
|
1219
1451
|
/**
|
|
1220
1452
|
* @deprecated use {@link target} instead
|
|
1221
1453
|
*/
|
|
1222
1454
|
get ssrTarget() {
|
|
1223
|
-
|
|
1455
|
+
console.warn("SSReflectionPlugin: ssrTarget is deprecated, use target instead");
|
|
1456
|
+
return this.target;
|
|
1224
1457
|
}
|
|
1225
1458
|
};
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1459
|
+
SSReflectionPlugin.PluginType = "SSReflection";
|
|
1460
|
+
SSReflectionPlugin.OldPluginType = "SSReflectionPlugin";
|
|
1461
|
+
__decorateClass([
|
|
1462
|
+
uiImage(
|
|
1230
1463
|
"SSReflection Buffer"
|
|
1231
1464
|
/* {readOnly: true}*/
|
|
1232
1465
|
)
|
|
1233
|
-
],
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
],
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
],
|
|
1240
|
-
let
|
|
1241
|
-
constructor(
|
|
1466
|
+
], SSReflectionPlugin.prototype, "texture", 2);
|
|
1467
|
+
__decorateClass([
|
|
1468
|
+
uiConfig()
|
|
1469
|
+
], SSReflectionPlugin.prototype, "_pass", 2);
|
|
1470
|
+
SSReflectionPlugin = __decorateClass([
|
|
1471
|
+
uiFolderContainer("SSReflection Plugin")
|
|
1472
|
+
], SSReflectionPlugin);
|
|
1473
|
+
let SSReflectionPluginPass = class extends ExtendedShaderPass {
|
|
1474
|
+
constructor(pid, target, inlineShaderRayTrace = true) {
|
|
1242
1475
|
super({
|
|
1243
1476
|
defines: {
|
|
1244
|
-
SSR_STEP_COUNT: 16,
|
|
1245
|
-
SSR_LOW_QUALITY_FRAMES: 2,
|
|
1477
|
+
["SSR_STEP_COUNT"]: 16,
|
|
1478
|
+
["SSR_LOW_QUALITY_FRAMES"]: 2,
|
|
1246
1479
|
// todo: only on mobile
|
|
1247
|
-
SSR_INLINE:
|
|
1480
|
+
["SSR_INLINE"]: inlineShaderRayTrace ? "1" : "0",
|
|
1248
1481
|
// ['SSR_NON_PHYSICAL']: '0', only in inline, so it should not be here
|
|
1249
|
-
SSR_MASK_FRONT_RAYS:
|
|
1250
|
-
PERSPECTIVE_CAMERA: 1
|
|
1482
|
+
["SSR_MASK_FRONT_RAYS"]: true,
|
|
1483
|
+
["PERSPECTIVE_CAMERA"]: 1
|
|
1251
1484
|
// set in PerspectiveCamera2
|
|
1252
1485
|
// ['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
1486
|
},
|
|
@@ -1256,32 +1489,32 @@ let v = class extends $ {
|
|
|
1256
1489
|
tLastFrame: { value: null },
|
|
1257
1490
|
// set in progressive plugin
|
|
1258
1491
|
// TODO required?
|
|
1259
|
-
screenSize: { value: new
|
|
1492
|
+
screenSize: { value: new Vector2(0, 0) },
|
|
1260
1493
|
// set in ExtendedRenderMaterial
|
|
1261
1494
|
currentFrameCount: { value: 0 },
|
|
1262
1495
|
// set in RenderManager
|
|
1263
1496
|
frameCount: { value: 0 },
|
|
1264
1497
|
// set in RenderManager
|
|
1265
|
-
cameraNearFar: { value: new
|
|
1498
|
+
cameraNearFar: { value: new Vector2(0.1, 1e3) },
|
|
1266
1499
|
// set in PerspectiveCamera2
|
|
1267
|
-
cameraPositionWorld: { value: new
|
|
1500
|
+
cameraPositionWorld: { value: new Vector3() },
|
|
1268
1501
|
// set in PerspectiveCamera2
|
|
1269
|
-
projection: { value: new
|
|
1502
|
+
projection: { value: new Matrix4() },
|
|
1270
1503
|
// set in PerspectiveCamera2
|
|
1271
|
-
saoBiasEpsilon: { value: new
|
|
1504
|
+
saoBiasEpsilon: { value: new Vector3(1, 1, 1) },
|
|
1272
1505
|
opacity: { value: 1 },
|
|
1273
1506
|
// todo?
|
|
1274
1507
|
intensity: { value: 0 },
|
|
1275
|
-
boost: { value: new
|
|
1508
|
+
boost: { value: new Vector3(0, 0, 0) },
|
|
1276
1509
|
objectRadius: { value: 0 },
|
|
1277
|
-
autoRadius: { value:
|
|
1510
|
+
autoRadius: { value: false },
|
|
1278
1511
|
power: { value: 0 },
|
|
1279
1512
|
maskFrontFactor: { value: -0.1 },
|
|
1280
1513
|
tolerance: { value: 0 },
|
|
1281
1514
|
sceneBoundingRadius: { value: 0 }
|
|
1282
1515
|
// todo do same in SSAO
|
|
1283
1516
|
},
|
|
1284
|
-
vertexShader:
|
|
1517
|
+
vertexShader: shaderUtils.defaultVertex,
|
|
1285
1518
|
fragmentShader: `
|
|
1286
1519
|
varying vec2 vUv;
|
|
1287
1520
|
|
|
@@ -1290,19 +1523,35 @@ varying vec2 vUv;
|
|
|
1290
1523
|
#define THREE_PACKING_INCLUDED
|
|
1291
1524
|
#include <cameraHelpers>
|
|
1292
1525
|
#include <randomHelpers>
|
|
1293
|
-
${
|
|
1526
|
+
${samplePointHelpers}
|
|
1294
1527
|
|
|
1295
|
-
${
|
|
1528
|
+
${ssrtShader}
|
|
1296
1529
|
|
|
1297
|
-
${
|
|
1530
|
+
${ssrShader}
|
|
1298
1531
|
|
|
1299
|
-
${
|
|
1532
|
+
${ssrShaderMain}
|
|
1300
1533
|
`
|
|
1301
|
-
}, "tDiffuse", "tLastThis", "tLastFrame")
|
|
1534
|
+
}, "tDiffuse", "tLastThis", "tLastFrame");
|
|
1535
|
+
this.target = target;
|
|
1536
|
+
this.inlineShaderRayTrace = inlineShaderRayTrace;
|
|
1537
|
+
this.before = ["render"];
|
|
1538
|
+
this.after = ["gbuffer", "depth"];
|
|
1539
|
+
this.required = ["render", "progressive"];
|
|
1540
|
+
this.intensity = 1;
|
|
1541
|
+
this.boost = new Vector3(1, 1, 1);
|
|
1542
|
+
this.objectRadius = 1;
|
|
1543
|
+
this.autoRadius = true;
|
|
1544
|
+
this.power = 1.1;
|
|
1545
|
+
this.tolerance = 0.5;
|
|
1546
|
+
this.stepCount = 16;
|
|
1547
|
+
this.lowQualityFrames = 0;
|
|
1548
|
+
this.maskFrontRays = true;
|
|
1549
|
+
this.maskFrontFactor = -0.2;
|
|
1550
|
+
this.materialExtension = {
|
|
1302
1551
|
extraUniforms: {
|
|
1303
1552
|
tSSReflMap: () => {
|
|
1304
|
-
var
|
|
1305
|
-
return { value: ((
|
|
1553
|
+
var _a2;
|
|
1554
|
+
return { value: ((_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture) ?? null };
|
|
1306
1555
|
},
|
|
1307
1556
|
ssrPower: this.material.uniforms.power,
|
|
1308
1557
|
ssrIntensity: this.material.uniforms.intensity,
|
|
@@ -1310,20 +1559,19 @@ ${nt}
|
|
|
1310
1559
|
ssrBoost: this.material.uniforms.boost
|
|
1311
1560
|
},
|
|
1312
1561
|
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
|
|
1562
|
+
["SSR_STEP_COUNT"]: () => this.material.defines.SSR_STEP_COUNT,
|
|
1563
|
+
["SSR_LOW_QUALITY_FRAMES"]: () => this.material.defines.SSR_LOW_QUALITY_FRAMES,
|
|
1564
|
+
["SSR_INLINE"]: () => this.material.defines.SSR_INLINE,
|
|
1565
|
+
["SSR_MASK_FRONT_RAYS"]: () => this.material.defines.SSR_MASK_FRONT_RAYS,
|
|
1566
|
+
["PERSPECTIVE_CAMERA"]: () => this.material.defines.PERSPECTIVE_CAMERA
|
|
1318
1567
|
// todo gbuffer stuff
|
|
1319
1568
|
},
|
|
1320
|
-
shaderExtender: (
|
|
1321
|
-
var
|
|
1322
|
-
if (!
|
|
1323
|
-
|
|
1324
|
-
const o = `
|
|
1569
|
+
shaderExtender: (shader, _material, _renderer) => {
|
|
1570
|
+
var _a2, _b;
|
|
1571
|
+
if (!shader.defines.SSREFL_ENABLED) return;
|
|
1572
|
+
const ls = `
|
|
1325
1573
|
|
|
1326
|
-
${
|
|
1574
|
+
${ssreflPatch}
|
|
1327
1575
|
|
|
1328
1576
|
// reflectedLight.directDiffuse = vec3(0.);
|
|
1329
1577
|
// reflectedLight.indirectDiffuse = vec3(0.);
|
|
@@ -1331,21 +1579,30 @@ ${nt}
|
|
|
1331
1579
|
// reflectedLight.indirectSpecular = vec3(0.);
|
|
1332
1580
|
|
|
1333
1581
|
`;
|
|
1334
|
-
|
|
1335
|
-
|
|
1582
|
+
shader.fragmentShader = shaderReplaceString(
|
|
1583
|
+
shader.fragmentShader,
|
|
1336
1584
|
"#glMarker beforeModulation",
|
|
1337
|
-
|
|
1338
|
-
{ prepend:
|
|
1339
|
-
)
|
|
1585
|
+
ls,
|
|
1586
|
+
{ prepend: true }
|
|
1587
|
+
);
|
|
1588
|
+
(_b = (_a2 = this._gbufferUnpackExtension) == null ? void 0 : _a2.shaderExtender) == null ? void 0 : _b.call(_a2, shader, _material, _renderer);
|
|
1340
1589
|
},
|
|
1341
|
-
onObjectRender: (
|
|
1342
|
-
var
|
|
1343
|
-
let
|
|
1344
|
-
|
|
1590
|
+
onObjectRender: (_object, material, renderer) => {
|
|
1591
|
+
var _a2, _b, _c;
|
|
1592
|
+
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;
|
|
1593
|
+
if (material.defines.SSREFL_ENABLED !== x) {
|
|
1594
|
+
material.defines.SSREFL_ENABLED = x;
|
|
1595
|
+
material.needsUpdate = true;
|
|
1596
|
+
}
|
|
1597
|
+
x = ((_c = material.userData) == null ? void 0 : _c.ssreflNonPhysical) ? 1 : 0;
|
|
1598
|
+
if (material.defines.SSR_NON_PHYSICAL !== x) {
|
|
1599
|
+
material.defines.SSR_NON_PHYSICAL = x;
|
|
1600
|
+
material.needsUpdate = true;
|
|
1601
|
+
}
|
|
1345
1602
|
},
|
|
1346
|
-
parsFragmentSnippet: (
|
|
1347
|
-
var
|
|
1348
|
-
return
|
|
1603
|
+
parsFragmentSnippet: (renderer) => {
|
|
1604
|
+
var _a2;
|
|
1605
|
+
return glsl`
|
|
1349
1606
|
#if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0
|
|
1350
1607
|
uniform float ssrPower;
|
|
1351
1608
|
uniform float ssrIntensity;
|
|
@@ -1353,59 +1610,73 @@ ${nt}
|
|
|
1353
1610
|
uniform vec3 ssrBoost;
|
|
1354
1611
|
uniform sampler2D tSSReflMap;
|
|
1355
1612
|
uniform sampler2D tLastFrame;
|
|
1356
|
-
${
|
|
1357
|
-
${
|
|
1358
|
-
${this.inlineShaderRayTrace ? `
|
|
1613
|
+
${getTexelDecoding("tSSReflMap", (_a2 = getOrCall(this.target)) == null ? void 0 : _a2.texture, renderer.capabilities.isWebGL2)}
|
|
1614
|
+
${getTexelDecoding("tLastFrame", this.material.uniforms.tLastFrame.value, renderer.capabilities.isWebGL2)}
|
|
1615
|
+
${!this.inlineShaderRayTrace ? "" : `
|
|
1359
1616
|
#define THREE_PACKING_INCLUDED // by threejs
|
|
1360
1617
|
#include <cameraHelpers>
|
|
1361
1618
|
#include <randomHelpers>
|
|
1362
|
-
${
|
|
1363
|
-
${
|
|
1364
|
-
${
|
|
1365
|
-
`
|
|
1619
|
+
${samplePointHelpers}
|
|
1620
|
+
${ssrtShader}
|
|
1621
|
+
${ssrShader}
|
|
1622
|
+
`}
|
|
1366
1623
|
#include <simpleCameraHelpers>
|
|
1367
1624
|
#endif
|
|
1368
1625
|
`;
|
|
1369
1626
|
},
|
|
1370
1627
|
computeCacheKey: () => {
|
|
1371
|
-
var
|
|
1372
|
-
return this.enabled ? "1" : "0" + ((
|
|
1628
|
+
var _a2, _b;
|
|
1629
|
+
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
1630
|
},
|
|
1374
|
-
uuid:
|
|
1375
|
-
...
|
|
1376
|
-
isCompatible: (
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1631
|
+
uuid: SSReflectionPlugin.PluginType,
|
|
1632
|
+
...uiConfigMaterialExtension(this._getUiConfig.bind(this), SSReflectionPlugin.PluginType),
|
|
1633
|
+
isCompatible: (material) => {
|
|
1634
|
+
return material.isPhysicalMaterial;
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
this.passId = pid;
|
|
1638
|
+
this.needsSwap = false;
|
|
1639
|
+
this.clear = true;
|
|
1640
|
+
if (inlineShaderRayTrace) {
|
|
1641
|
+
Object.assign(this.materialExtension.extraUniforms, {
|
|
1642
|
+
tNormalDepth: this.material.uniforms.tNormalDepth,
|
|
1643
|
+
tLastFrame: this.material.uniforms.tLastFrame,
|
|
1644
|
+
objectRadius: this.material.uniforms.objectRadius,
|
|
1645
|
+
autoRadius: this.material.uniforms.autoRadius,
|
|
1646
|
+
tolerance: this.material.uniforms.tolerance,
|
|
1647
|
+
frameCount: this.material.uniforms.frameCount,
|
|
1648
|
+
// currentFrameCount: this.material.uniforms.currentFrameCount, // todo required?
|
|
1649
|
+
projection: this.material.uniforms.projection,
|
|
1650
|
+
cameraPositionWorld: this.material.uniforms.cameraPositionWorld,
|
|
1651
|
+
cameraNearFar: this.material.uniforms.cameraNearFar,
|
|
1652
|
+
sceneBoundingRadius: this.material.uniforms.sceneBoundingRadius
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1390
1655
|
}
|
|
1391
|
-
render(
|
|
1392
|
-
if (!this.enabled)
|
|
1393
|
-
return;
|
|
1656
|
+
render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
|
|
1657
|
+
if (!this.enabled) return;
|
|
1394
1658
|
if (this.inlineShaderRayTrace) {
|
|
1395
|
-
this.needsSwap =
|
|
1659
|
+
this.needsSwap = false;
|
|
1396
1660
|
return;
|
|
1397
1661
|
}
|
|
1398
|
-
const
|
|
1399
|
-
if (!
|
|
1662
|
+
const target = getOrCall(this.target);
|
|
1663
|
+
if (!target) {
|
|
1400
1664
|
console.warn("SSReflectionPluginPass: target not defined. It must be set when inlineShaderRayTrace is false");
|
|
1401
1665
|
return;
|
|
1402
1666
|
}
|
|
1403
|
-
this.material.defines.HAS_GBUFFER
|
|
1404
|
-
|
|
1405
|
-
}
|
|
1667
|
+
if (!this.material.defines.HAS_GBUFFER) {
|
|
1668
|
+
console.warn("SSReflectionPluginPass: DepthNormalBuffer required for ssrefl");
|
|
1669
|
+
}
|
|
1670
|
+
renderer.renderManager.blit(writeBuffer, {
|
|
1671
|
+
source: target.texture
|
|
1672
|
+
});
|
|
1673
|
+
this.uniforms.tLastThis.value = writeBuffer.texture;
|
|
1674
|
+
super.render(renderer, target, readBuffer, deltaTime, maskActive);
|
|
1675
|
+
this.needsSwap = false;
|
|
1406
1676
|
}
|
|
1407
|
-
beforeRender(
|
|
1408
|
-
this.enabled
|
|
1677
|
+
beforeRender(scene, camera, renderManager) {
|
|
1678
|
+
if (!this.enabled) return;
|
|
1679
|
+
this.updateShaderProperties([scene, camera, renderManager]);
|
|
1409
1680
|
}
|
|
1410
1681
|
/**
|
|
1411
1682
|
* Returns a uiConfig to toggle SSReflection on a material.
|
|
@@ -1413,7 +1684,7 @@ ${le}
|
|
|
1413
1684
|
* @param material
|
|
1414
1685
|
* @private
|
|
1415
1686
|
*/
|
|
1416
|
-
_getUiConfig(
|
|
1687
|
+
_getUiConfig(material) {
|
|
1417
1688
|
return {
|
|
1418
1689
|
type: "folder",
|
|
1419
1690
|
label: "SSReflection",
|
|
@@ -1422,10 +1693,12 @@ ${le}
|
|
|
1422
1693
|
type: "checkbox",
|
|
1423
1694
|
label: "Enabled",
|
|
1424
1695
|
get value() {
|
|
1425
|
-
return !(
|
|
1696
|
+
return !(material.userData.ssreflDisabled ?? false);
|
|
1426
1697
|
},
|
|
1427
|
-
set value(
|
|
1428
|
-
|
|
1698
|
+
set value(v) {
|
|
1699
|
+
if (v === !(material.userData.ssreflDisabled ?? false)) return;
|
|
1700
|
+
material.userData.ssreflDisabled = !v;
|
|
1701
|
+
material.setDirty();
|
|
1429
1702
|
},
|
|
1430
1703
|
onChange: this.setDirty
|
|
1431
1704
|
},
|
|
@@ -1433,96 +1706,105 @@ ${le}
|
|
|
1433
1706
|
type: "checkbox",
|
|
1434
1707
|
label: "Non Physical",
|
|
1435
1708
|
get value() {
|
|
1436
|
-
return
|
|
1709
|
+
return material.userData.ssreflNonPhysical ?? false;
|
|
1437
1710
|
},
|
|
1438
|
-
set value(
|
|
1439
|
-
|
|
1711
|
+
set value(v) {
|
|
1712
|
+
if (v === (material.userData.ssreflNonPhysical ?? false)) return;
|
|
1713
|
+
material.userData.ssreflNonPhysical = v;
|
|
1714
|
+
material.setDirty();
|
|
1440
1715
|
},
|
|
1441
1716
|
onChange: this.setDirty
|
|
1442
1717
|
}
|
|
1443
1718
|
]
|
|
1444
1719
|
};
|
|
1445
1720
|
}
|
|
1446
|
-
set uniformsNeedUpdate(
|
|
1447
|
-
this.material.uniformsNeedUpdate =
|
|
1721
|
+
set uniformsNeedUpdate(value) {
|
|
1722
|
+
this.material.uniformsNeedUpdate = value;
|
|
1723
|
+
this.setDirty();
|
|
1448
1724
|
}
|
|
1449
|
-
setGBufferUnpackExtension(
|
|
1450
|
-
|
|
1725
|
+
setGBufferUnpackExtension(extension) {
|
|
1726
|
+
if (this._gbufferUnpackExtension === extension) return;
|
|
1727
|
+
if (this._gbufferUnpackExtension) this.material.unregisterMaterialExtensions([this._gbufferUnpackExtension]);
|
|
1728
|
+
this._gbufferUnpackExtension = extension;
|
|
1729
|
+
if (this._gbufferUnpackExtension) this.material.registerMaterialExtensions([this._gbufferUnpackExtension]);
|
|
1730
|
+
if (!this._gbufferUnpackExtension) return;
|
|
1731
|
+
Object.assign(this.materialExtension.extraUniforms, this._gbufferUnpackExtension.extraUniforms);
|
|
1732
|
+
Object.assign(this.materialExtension.extraDefines, this._gbufferUnpackExtension.extraDefines);
|
|
1451
1733
|
}
|
|
1452
1734
|
};
|
|
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
|
-
|
|
1735
|
+
__decorateClass([
|
|
1736
|
+
uiSlider("Intensity", [0, 4]),
|
|
1737
|
+
serialize(),
|
|
1738
|
+
uniform()
|
|
1739
|
+
], SSReflectionPluginPass.prototype, "intensity", 2);
|
|
1740
|
+
__decorateClass([
|
|
1741
|
+
uiVector("Boost"),
|
|
1742
|
+
serialize(),
|
|
1743
|
+
uniform()
|
|
1744
|
+
], SSReflectionPluginPass.prototype, "boost", 2);
|
|
1745
|
+
__decorateClass([
|
|
1746
|
+
uiSlider("Object Radius", [0.01, 2]),
|
|
1747
|
+
serialize(),
|
|
1748
|
+
uniform()
|
|
1749
|
+
], SSReflectionPluginPass.prototype, "objectRadius", 2);
|
|
1750
|
+
__decorateClass([
|
|
1751
|
+
uiToggle("Auto radius"),
|
|
1752
|
+
serialize(),
|
|
1753
|
+
uniform()
|
|
1754
|
+
], SSReflectionPluginPass.prototype, "autoRadius", 2);
|
|
1755
|
+
__decorateClass([
|
|
1756
|
+
uiSlider("Power", [0, 3]),
|
|
1757
|
+
serialize(),
|
|
1758
|
+
uniform()
|
|
1759
|
+
], SSReflectionPluginPass.prototype, "power", 2);
|
|
1760
|
+
__decorateClass([
|
|
1761
|
+
uiSlider("Tolerance", [0.1, 5]),
|
|
1762
|
+
serialize(),
|
|
1763
|
+
uniform()
|
|
1764
|
+
], SSReflectionPluginPass.prototype, "tolerance", 2);
|
|
1765
|
+
__decorateClass([
|
|
1766
|
+
uiSlider("Step count", [1, 32], 1),
|
|
1767
|
+
serialize(),
|
|
1768
|
+
matDefine("SSR_STEP_COUNT", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
|
|
1769
|
+
], SSReflectionPluginPass.prototype, "stepCount", 2);
|
|
1770
|
+
__decorateClass([
|
|
1771
|
+
uiSlider("Low Quality Frames", [0, 4], 1),
|
|
1772
|
+
serialize(),
|
|
1773
|
+
matDefine("SSR_LOW_QUALITY_FRAMES", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
|
|
1774
|
+
], SSReflectionPluginPass.prototype, "lowQualityFrames", 2);
|
|
1775
|
+
__decorateClass([
|
|
1776
|
+
uiToggle("Ignore front rays"),
|
|
1777
|
+
serialize(),
|
|
1778
|
+
matDefineBool("SSR_MASK_FRONT_RAYS", void 0, void 0, SSReflectionPluginPass.prototype.setDirty)
|
|
1779
|
+
], SSReflectionPluginPass.prototype, "maskFrontRays", 2);
|
|
1780
|
+
__decorateClass([
|
|
1781
|
+
uiSlider("Mask front rays factor", [-1, 1], 0.01, (that) => ({ hidden: () => !that.maskFrontRays })),
|
|
1782
|
+
serialize(),
|
|
1783
|
+
uniform()
|
|
1784
|
+
], SSReflectionPluginPass.prototype, "maskFrontFactor", 2);
|
|
1785
|
+
SSReflectionPluginPass = __decorateClass([
|
|
1786
|
+
uiFolderContainer("SSReflection Pass")
|
|
1787
|
+
], SSReflectionPluginPass);
|
|
1788
|
+
const webgiPlugins = [
|
|
1789
|
+
TemporalAAPlugin,
|
|
1790
|
+
VelocityBufferPlugin,
|
|
1791
|
+
BloomPlugin,
|
|
1792
|
+
SSReflectionPlugin,
|
|
1793
|
+
SSContactShadowsPlugin,
|
|
1794
|
+
DepthOfFieldPlugin
|
|
1513
1795
|
];
|
|
1514
1796
|
export {
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1797
|
+
BloomPlugin,
|
|
1798
|
+
BloomPluginPass,
|
|
1799
|
+
DepthOfFieldPlugin,
|
|
1800
|
+
DepthOfFieldPluginPass,
|
|
1801
|
+
SSContactShadowsPlugin,
|
|
1802
|
+
SSReflectionPlugin,
|
|
1803
|
+
SSReflectionPluginPass,
|
|
1804
|
+
SSVelocityMaterial,
|
|
1805
|
+
TemporalAAPlugin,
|
|
1806
|
+
TemporalAAPluginPass,
|
|
1807
|
+
VelocityBufferPlugin,
|
|
1808
|
+
webgiPlugins
|
|
1527
1809
|
};
|
|
1528
1810
|
//# sourceMappingURL=index.mjs.map
|