@plastic-software/three 0.181.3 → 0.182.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/README.md +3 -4
- package/build/three.cjs +1192 -522
- package/build/three.core.js +345 -219
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +864 -328
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +15 -3
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +3660 -1545
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +3659 -1544
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/controls/MapControls.js +55 -1
- package/examples/jsm/controls/OrbitControls.js +6 -6
- package/examples/jsm/controls/TrackballControls.js +6 -6
- package/examples/jsm/csm/CSM.js +2 -1
- package/examples/jsm/environments/RoomEnvironment.js +2 -0
- package/examples/jsm/geometries/DecalGeometry.js +1 -1
- package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
- package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
- package/examples/jsm/inspector/Inspector.js +53 -9
- package/examples/jsm/inspector/RendererInspector.js +12 -2
- package/examples/jsm/inspector/tabs/Console.js +2 -2
- package/examples/jsm/inspector/tabs/Parameters.js +2 -2
- package/examples/jsm/inspector/tabs/Performance.js +2 -2
- package/examples/jsm/inspector/tabs/Viewer.js +4 -4
- package/examples/jsm/inspector/ui/Profiler.js +1836 -31
- package/examples/jsm/inspector/ui/Style.js +948 -13
- package/examples/jsm/inspector/ui/Tab.js +188 -1
- package/examples/jsm/inspector/ui/Values.js +17 -1
- package/examples/jsm/loaders/3DMLoader.js +5 -4
- package/examples/jsm/loaders/DRACOLoader.js +5 -5
- package/examples/jsm/loaders/FBXLoader.js +0 -2
- package/examples/jsm/loaders/HDRLoader.js +0 -1
- package/examples/jsm/loaders/KTX2Loader.js +16 -0
- package/examples/jsm/loaders/LDrawLoader.js +2 -3
- package/examples/jsm/loaders/PCDLoader.js +1 -0
- package/examples/jsm/loaders/SVGLoader.js +1 -1
- package/examples/jsm/loaders/TDSLoader.js +0 -2
- package/examples/jsm/loaders/TGALoader.js +0 -2
- package/examples/jsm/loaders/UltraHDRLoader.js +110 -137
- package/examples/jsm/loaders/VOXLoader.js +660 -117
- package/examples/jsm/loaders/VRMLLoader.js +2 -2
- package/examples/jsm/loaders/usd/USDCParser.js +1 -1
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -1
- package/examples/jsm/materials/WoodNodeMaterial.js +11 -11
- package/examples/jsm/math/Octree.js +131 -1
- package/examples/jsm/misc/Volume.js +0 -1
- package/examples/jsm/misc/VolumeSlice.js +0 -1
- package/examples/jsm/objects/SkyMesh.js +13 -3
- package/examples/jsm/physics/AmmoPhysics.js +12 -7
- package/examples/jsm/physics/JoltPhysics.js +3 -1
- package/examples/jsm/physics/RapierPhysics.js +3 -1
- package/examples/jsm/postprocessing/OutputPass.js +9 -0
- package/examples/jsm/postprocessing/RenderPass.js +10 -0
- package/examples/jsm/postprocessing/UnrealBloomPass.js +48 -18
- package/examples/jsm/renderers/Projector.js +268 -30
- package/examples/jsm/renderers/SVGRenderer.js +191 -58
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -4
- package/examples/jsm/transpiler/AST.js +44 -0
- package/examples/jsm/transpiler/GLSLDecoder.js +61 -4
- package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -0
- package/examples/jsm/transpiler/TSLEncoder.js +46 -3
- package/examples/jsm/transpiler/TranspilerUtils.js +3 -3
- package/examples/jsm/transpiler/WGSLEncoder.js +27 -0
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +2 -0
- package/examples/jsm/tsl/display/BloomNode.js +11 -1
- package/examples/jsm/tsl/display/GTAONode.js +3 -2
- package/examples/jsm/tsl/display/PixelationPassNode.js +2 -1
- package/examples/jsm/tsl/display/SSGINode.js +7 -19
- package/examples/jsm/tsl/display/SSRNode.js +1 -1
- package/examples/jsm/tsl/display/SSSNode.js +4 -2
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +8 -1
- package/examples/jsm/tsl/display/TRAANode.js +265 -114
- package/examples/jsm/tsl/display/radialBlur.js +68 -0
- package/examples/jsm/utils/ShadowMapViewer.js +24 -10
- package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
- package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
- package/package.json +14 -12
- package/src/Three.Core.js +1 -0
- package/src/Three.TSL.js +14 -2
- package/src/animation/AnimationUtils.js +1 -12
- package/src/animation/KeyframeTrack.js +1 -1
- package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
- package/src/animation/tracks/ColorKeyframeTrack.js +1 -1
- package/src/animation/tracks/NumberKeyframeTrack.js +1 -1
- package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -1
- package/src/animation/tracks/StringKeyframeTrack.js +1 -1
- package/src/animation/tracks/VectorKeyframeTrack.js +1 -1
- package/src/constants.js +61 -5
- package/src/core/BufferGeometry.js +14 -2
- package/src/core/Raycaster.js +2 -2
- package/src/extras/PMREMGenerator.js +3 -10
- package/src/extras/TextureUtils.js +5 -1
- package/src/geometries/ExtrudeGeometry.js +2 -2
- package/src/geometries/PolyhedronGeometry.js +1 -1
- package/src/helpers/PointLightHelper.js +1 -1
- package/src/lights/DirectionalLight.js +13 -0
- package/src/lights/HemisphereLight.js +10 -0
- package/src/lights/Light.js +1 -11
- package/src/lights/LightProbe.js +0 -15
- package/src/lights/LightShadow.js +0 -3
- package/src/lights/PointLight.js +15 -0
- package/src/lights/PointLightShadow.js +0 -86
- package/src/lights/SpotLight.js +22 -1
- package/src/loaders/MaterialLoader.js +2 -1
- package/src/loaders/ObjectLoader.js +3 -1
- package/src/loaders/nodes/NodeLoader.js +2 -2
- package/src/materials/Material.js +2 -0
- package/src/materials/ShaderMaterial.js +20 -1
- package/src/materials/nodes/Line2NodeMaterial.js +2 -2
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +3 -2
- package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -4
- package/src/materials/nodes/NodeMaterial.js +59 -3
- package/src/materials/nodes/manager/NodeMaterialObserver.js +1 -1
- package/src/math/Matrix4.js +40 -40
- package/src/math/Sphere.js +1 -1
- package/src/math/Vector3.js +0 -2
- package/src/nodes/TSL.js +4 -1
- package/src/nodes/accessors/BatchNode.js +10 -10
- package/src/nodes/accessors/BufferAttributeNode.js +98 -12
- package/src/nodes/accessors/BufferNode.js +29 -2
- package/src/nodes/accessors/ClippingNode.js +4 -4
- package/src/nodes/accessors/CubeTextureNode.js +20 -1
- package/src/nodes/accessors/InstanceNode.js +69 -29
- package/src/nodes/accessors/MaterialNode.js +9 -1
- package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
- package/src/nodes/accessors/ModelNode.js +1 -1
- package/src/nodes/accessors/Normal.js +2 -2
- package/src/nodes/accessors/ReferenceBaseNode.js +4 -4
- package/src/nodes/accessors/ReferenceNode.js +4 -4
- package/src/nodes/accessors/RendererReferenceNode.js +1 -2
- package/src/nodes/accessors/SkinningNode.js +15 -2
- package/src/nodes/accessors/StorageBufferNode.js +4 -2
- package/src/nodes/accessors/Tangent.js +1 -11
- package/src/nodes/accessors/Texture3DNode.js +26 -1
- package/src/nodes/accessors/UniformArrayNode.js +2 -2
- package/src/nodes/accessors/UserDataNode.js +1 -2
- package/src/nodes/accessors/VertexColorNode.js +1 -2
- package/src/nodes/code/FunctionNode.js +1 -2
- package/src/nodes/core/ArrayNode.js +20 -1
- package/src/nodes/core/AssignNode.js +2 -2
- package/src/nodes/core/AttributeNode.js +2 -2
- package/src/nodes/core/ContextNode.js +103 -4
- package/src/nodes/core/NodeBuilder.js +56 -14
- package/src/nodes/core/NodeFrame.js +12 -4
- package/src/nodes/core/NodeUtils.js +5 -5
- package/src/nodes/core/ParameterNode.js +1 -2
- package/src/nodes/core/PropertyNode.js +19 -3
- package/src/nodes/core/StackNode.js +56 -8
- package/src/nodes/core/StructNode.js +1 -2
- package/src/nodes/core/StructTypeNode.js +11 -17
- package/src/nodes/core/UniformNode.js +19 -4
- package/src/nodes/core/VarNode.js +46 -21
- package/src/nodes/display/NormalMapNode.js +37 -2
- package/src/nodes/display/PassNode.js +77 -7
- package/src/nodes/display/ScreenNode.js +1 -0
- package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +3 -3
- package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
- package/src/nodes/functions/PhysicalLightingModel.js +102 -43
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -2
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +2 -3
- package/src/nodes/lighting/AnalyticLightNode.js +53 -0
- package/src/nodes/lighting/LightsNode.js +2 -2
- package/src/nodes/lighting/PointShadowNode.js +141 -140
- package/src/nodes/lighting/ShadowFilterNode.js +53 -37
- package/src/nodes/lighting/ShadowNode.js +53 -19
- package/src/nodes/math/BitcountNode.js +433 -0
- package/src/nodes/math/PackFloatNode.js +98 -0
- package/src/nodes/math/UnpackFloatNode.js +96 -0
- package/src/nodes/pmrem/PMREMNode.js +1 -1
- package/src/nodes/tsl/TSLCore.js +4 -4
- package/src/nodes/utils/ArrayElementNode.js +13 -0
- package/src/nodes/utils/EventNode.js +1 -2
- package/src/nodes/utils/Packing.js +13 -1
- package/src/nodes/utils/PostProcessingUtils.js +33 -1
- package/src/nodes/utils/ReflectorNode.js +1 -1
- package/src/nodes/utils/SampleNode.js +1 -1
- package/src/nodes/utils/UVUtils.js +26 -0
- package/src/objects/BatchedMesh.js +5 -2
- package/src/objects/Line.js +1 -1
- package/src/objects/Mesh.js +1 -1
- package/src/objects/Points.js +1 -1
- package/src/objects/Skeleton.js +9 -0
- package/src/renderers/WebGLRenderer.js +145 -33
- package/src/renderers/common/Backend.js +8 -0
- package/src/renderers/common/Background.js +19 -9
- package/src/renderers/common/Binding.js +11 -0
- package/src/renderers/common/Bindings.js +7 -7
- package/src/renderers/common/Buffer.js +40 -0
- package/src/renderers/common/ChainMap.js +30 -6
- package/src/renderers/common/Geometries.js +12 -0
- package/src/renderers/common/RenderContexts.js +8 -1
- package/src/renderers/common/RenderObject.js +14 -1
- package/src/renderers/common/Renderer.js +53 -35
- package/src/renderers/common/Textures.js +1 -1
- package/src/renderers/common/UniformsGroup.js +1 -0
- package/src/renderers/common/XRManager.js +1 -0
- package/src/renderers/common/extras/PMREMGenerator.js +2 -8
- package/src/renderers/common/nodes/NodeUniformBuffer.js +52 -0
- package/src/renderers/shaders/DFGLUTData.js +19 -34
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +90 -51
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +194 -186
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk.js +3 -3
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
- package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib.js +3 -3
- package/src/renderers/webgl/WebGLCapabilities.js +3 -4
- package/src/renderers/webgl/WebGLLights.js +18 -1
- package/src/renderers/webgl/WebGLOutput.js +267 -0
- package/src/renderers/webgl/WebGLProgram.js +43 -107
- package/src/renderers/webgl/WebGLPrograms.js +35 -45
- package/src/renderers/webgl/WebGLShadowMap.js +188 -25
- package/src/renderers/webgl/WebGLState.js +20 -20
- package/src/renderers/webgl/WebGLTextures.js +89 -28
- package/src/renderers/webgl/WebGLUniforms.js +40 -3
- package/src/renderers/webgl/WebGLUtils.js +6 -2
- package/src/renderers/webgl-fallback/WebGLBackend.js +79 -13
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +59 -7
- package/src/renderers/webgl-fallback/utils/WebGLState.js +18 -3
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +5 -3
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -9
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +6 -2
- package/src/renderers/webgpu/WebGPUBackend.js +61 -4
- package/src/renderers/webgpu/WebGPURenderer.js +1 -1
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +65 -23
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -17
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +354 -186
- package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -0
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +20 -7
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +40 -17
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +7 -7
- package/src/renderers/webgpu/utils/WebGPUUtils.js +7 -5
- package/src/textures/CubeDepthTexture.js +76 -0
- package/src/textures/Source.js +1 -1
- package/src/textures/Texture.js +1 -1
- package/src/utils.js +13 -1
- package/src/nodes/functions/BSDF/DFGApprox.js +0 -71
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HalfFloatType, Vector2, RenderTarget, RendererUtils, QuadMesh, NodeMaterial, TempNode, NodeUpdateType, Matrix4, DepthTexture } from 'three/webgpu';
|
|
2
|
-
import { add, float, If,
|
|
2
|
+
import { add, float, If, Fn, max, nodeObject, texture, uniform, uv, vec2, vec4, luminance, convertToTexture, passTexture, velocity, getViewPosition, viewZToPerspectiveDepth, struct, ivec2, mix } from 'three/tsl';
|
|
3
3
|
|
|
4
4
|
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
5
5
|
const _size = /*@__PURE__*/ new Vector2();
|
|
@@ -77,60 +77,62 @@ class TRAANode extends TempNode {
|
|
|
77
77
|
this.velocityNode = velocityNode;
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
*
|
|
80
|
+
* The camera the scene is rendered with.
|
|
81
81
|
*
|
|
82
82
|
* @type {Camera}
|
|
83
83
|
*/
|
|
84
84
|
this.camera = camera;
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
|
-
*
|
|
87
|
+
* When the difference between the current and previous depth goes above this threshold,
|
|
88
|
+
* the history is considered invalid.
|
|
88
89
|
*
|
|
89
|
-
* @private
|
|
90
90
|
* @type {number}
|
|
91
|
-
* @default 0
|
|
91
|
+
* @default 0.0005
|
|
92
92
|
*/
|
|
93
|
-
this.
|
|
93
|
+
this.depthThreshold = 0.0005;
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
96
|
+
* The depth difference within the 3×3 neighborhood to consider a pixel as an edge.
|
|
97
97
|
*
|
|
98
|
-
* @
|
|
99
|
-
* @
|
|
98
|
+
* @type {number}
|
|
99
|
+
* @default 0.001
|
|
100
100
|
*/
|
|
101
|
-
this.
|
|
101
|
+
this.edgeDepthDiff = 0.001;
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
|
-
*
|
|
104
|
+
* The history becomes invalid as the pixel length of the velocity approaches this value.
|
|
105
105
|
*
|
|
106
|
-
* @
|
|
107
|
-
* @
|
|
106
|
+
* @type {number}
|
|
107
|
+
* @default 128
|
|
108
108
|
*/
|
|
109
|
-
this.
|
|
109
|
+
this.maxVelocityLength = 128;
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
*
|
|
112
|
+
* Whether to decrease the weight on the current frame when the velocity is more subpixel.
|
|
113
|
+
* This reduces blurriness under motion, but can introduce a square pattern artifact.
|
|
113
114
|
*
|
|
114
|
-
* @
|
|
115
|
-
* @
|
|
115
|
+
* @type {boolean}
|
|
116
|
+
* @default true
|
|
116
117
|
*/
|
|
117
|
-
this.
|
|
118
|
+
this.useSubpixelCorrection = true;
|
|
118
119
|
|
|
119
120
|
/**
|
|
120
|
-
*
|
|
121
|
+
* The jitter index selects the current camera offset value.
|
|
121
122
|
*
|
|
122
123
|
* @private
|
|
123
|
-
* @type {
|
|
124
|
+
* @type {number}
|
|
125
|
+
* @default 0
|
|
124
126
|
*/
|
|
125
|
-
this.
|
|
127
|
+
this._jitterIndex = 0;
|
|
126
128
|
|
|
127
129
|
/**
|
|
128
|
-
* A uniform node holding the
|
|
130
|
+
* A uniform node holding the inverse resolution value.
|
|
129
131
|
*
|
|
130
132
|
* @private
|
|
131
|
-
* @type {UniformNode<
|
|
133
|
+
* @type {UniformNode<vec2>}
|
|
132
134
|
*/
|
|
133
|
-
this.
|
|
135
|
+
this._invSize = uniform( new Vector2() );
|
|
134
136
|
|
|
135
137
|
/**
|
|
136
138
|
* The render target that represents the history of frame data.
|
|
@@ -175,6 +177,54 @@ class TRAANode extends TempNode {
|
|
|
175
177
|
*/
|
|
176
178
|
this._originalProjectionMatrix = new Matrix4();
|
|
177
179
|
|
|
180
|
+
/**
|
|
181
|
+
* A uniform node holding the camera's near and far.
|
|
182
|
+
*
|
|
183
|
+
* @private
|
|
184
|
+
* @type {UniformNode<vec2>}
|
|
185
|
+
*/
|
|
186
|
+
this._cameraNearFar = uniform( new Vector2() );
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A uniform node holding the camera world matrix.
|
|
190
|
+
*
|
|
191
|
+
* @private
|
|
192
|
+
* @type {UniformNode<mat4>}
|
|
193
|
+
*/
|
|
194
|
+
this._cameraWorldMatrix = uniform( new Matrix4() );
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* A uniform node holding the camera world matrix inverse.
|
|
198
|
+
*
|
|
199
|
+
* @private
|
|
200
|
+
* @type {UniformNode<mat4>}
|
|
201
|
+
*/
|
|
202
|
+
this._cameraWorldMatrixInverse = uniform( new Matrix4() );
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* A uniform node holding the camera projection matrix inverse.
|
|
206
|
+
*
|
|
207
|
+
* @private
|
|
208
|
+
* @type {UniformNode<mat4>}
|
|
209
|
+
*/
|
|
210
|
+
this._cameraProjectionMatrixInverse = uniform( new Matrix4() );
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* A uniform node holding the previous frame's view matrix.
|
|
214
|
+
*
|
|
215
|
+
* @private
|
|
216
|
+
* @type {UniformNode<mat4>}
|
|
217
|
+
*/
|
|
218
|
+
this._previousCameraWorldMatrix = uniform( new Matrix4() );
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* A uniform node holding the previous frame's projection matrix inverse.
|
|
222
|
+
*
|
|
223
|
+
* @private
|
|
224
|
+
* @type {UniformNode<mat4>}
|
|
225
|
+
*/
|
|
226
|
+
this._previousCameraProjectionMatrixInverse = uniform( new Matrix4() );
|
|
227
|
+
|
|
178
228
|
/**
|
|
179
229
|
* A texture node for the previous depth buffer.
|
|
180
230
|
*
|
|
@@ -247,13 +297,13 @@ class TRAANode extends TempNode {
|
|
|
247
297
|
|
|
248
298
|
};
|
|
249
299
|
|
|
250
|
-
const jitterOffset =
|
|
300
|
+
const jitterOffset = _haltonOffsets[ this._jitterIndex ];
|
|
251
301
|
|
|
252
302
|
this.camera.setViewOffset(
|
|
253
303
|
|
|
254
304
|
viewOffset.fullWidth, viewOffset.fullHeight,
|
|
255
305
|
|
|
256
|
-
viewOffset.offsetX + jitterOffset[ 0 ]
|
|
306
|
+
viewOffset.offsetX + jitterOffset[ 0 ] - 0.5, viewOffset.offsetY + jitterOffset[ 1 ] - 0.5,
|
|
257
307
|
|
|
258
308
|
viewOffset.width, viewOffset.height
|
|
259
309
|
|
|
@@ -273,7 +323,7 @@ class TRAANode extends TempNode {
|
|
|
273
323
|
// update jitter index
|
|
274
324
|
|
|
275
325
|
this._jitterIndex ++;
|
|
276
|
-
this._jitterIndex = this._jitterIndex % (
|
|
326
|
+
this._jitterIndex = this._jitterIndex % ( _haltonOffsets.length - 1 );
|
|
277
327
|
|
|
278
328
|
}
|
|
279
329
|
|
|
@@ -293,7 +343,9 @@ class TRAANode extends TempNode {
|
|
|
293
343
|
|
|
294
344
|
// update camera matrices uniforms
|
|
295
345
|
|
|
346
|
+
this._cameraNearFar.value.set( this.camera.near, this.camera.far );
|
|
296
347
|
this._cameraWorldMatrix.value.copy( this.camera.matrixWorld );
|
|
348
|
+
this._cameraWorldMatrixInverse.value.copy( this.camera.matrixWorldInverse );
|
|
297
349
|
this._cameraProjectionMatrixInverse.value.copy( this.camera.projectionMatrixInverse );
|
|
298
350
|
|
|
299
351
|
// keep the TRAA in sync with the dimensions of the beauty node
|
|
@@ -403,123 +455,217 @@ class TRAANode extends TempNode {
|
|
|
403
455
|
|
|
404
456
|
}
|
|
405
457
|
|
|
406
|
-
const
|
|
407
|
-
const sampleTexture = this.beautyNode;
|
|
408
|
-
const depthTexture = this.depthNode;
|
|
409
|
-
const velocityTexture = this.velocityNode;
|
|
458
|
+
const currentDepthStruct = struct( {
|
|
410
459
|
|
|
411
|
-
|
|
460
|
+
closestDepth: 'float',
|
|
461
|
+
closestPositionTexel: 'vec2',
|
|
462
|
+
farthestDepth: 'float',
|
|
412
463
|
|
|
413
|
-
|
|
464
|
+
} );
|
|
414
465
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
const closestDepth = float( 1 ).toVar();
|
|
418
|
-
const farthestDepth = float( 0 ).toVar();
|
|
419
|
-
const closestDepthPixelPosition = vec2( 0 ).toVar();
|
|
466
|
+
// Samples 3×3 neighborhood pixels and returns the closest and farthest depths.
|
|
467
|
+
const sampleCurrentDepth = Fn( ( [ positionTexel ] ) => {
|
|
420
468
|
|
|
421
|
-
|
|
422
|
-
|
|
469
|
+
const closestDepth = float( 2 ).toVar();
|
|
470
|
+
const closestPositionTexel = vec2( 0 ).toVar();
|
|
471
|
+
const farthestDepth = float( - 1 ).toVar();
|
|
423
472
|
|
|
424
|
-
|
|
473
|
+
for ( let x = - 1; x <= 1; ++ x ) {
|
|
425
474
|
|
|
426
|
-
|
|
475
|
+
for ( let y = - 1; y <= 1; ++ y ) {
|
|
427
476
|
|
|
428
|
-
const
|
|
429
|
-
const
|
|
477
|
+
const neighbor = positionTexel.add( vec2( x, y ) ).toVar();
|
|
478
|
+
const depth = this.depthNode.load( neighbor ).r.toVar();
|
|
430
479
|
|
|
431
|
-
|
|
432
|
-
maxColor.assign( max( maxColor, colorNeighbor ) );
|
|
480
|
+
If( depth.lessThan( closestDepth ), () => {
|
|
433
481
|
|
|
434
|
-
|
|
482
|
+
closestDepth.assign( depth );
|
|
483
|
+
closestPositionTexel.assign( neighbor );
|
|
435
484
|
|
|
436
|
-
|
|
485
|
+
} );
|
|
437
486
|
|
|
438
|
-
If(
|
|
487
|
+
If( depth.greaterThan( farthestDepth ), () => {
|
|
439
488
|
|
|
440
|
-
|
|
441
|
-
closestDepthPixelPosition.assign( uvNeighbor );
|
|
489
|
+
farthestDepth.assign( depth );
|
|
442
490
|
|
|
443
491
|
} );
|
|
444
492
|
|
|
445
|
-
|
|
493
|
+
}
|
|
446
494
|
|
|
447
|
-
|
|
495
|
+
}
|
|
448
496
|
|
|
449
|
-
|
|
497
|
+
return currentDepthStruct( closestDepth, closestPositionTexel, farthestDepth );
|
|
450
498
|
|
|
451
|
-
|
|
499
|
+
} );
|
|
452
500
|
|
|
453
|
-
|
|
501
|
+
// Samples a previous depth and reproject it using the current camera matrices.
|
|
502
|
+
const samplePreviousDepth = ( uv ) => {
|
|
454
503
|
|
|
455
|
-
|
|
504
|
+
const depth = this._previousDepthNode.sample( uv ).r;
|
|
505
|
+
const positionView = getViewPosition( uv, depth, this._previousCameraProjectionMatrixInverse );
|
|
506
|
+
const positionWorld = this._previousCameraWorldMatrix.mul( vec4( positionView, 1 ) ).xyz;
|
|
507
|
+
const viewZ = this._cameraWorldMatrixInverse.mul( vec4( positionWorld, 1 ) ).z;
|
|
508
|
+
return viewZToPerspectiveDepth( viewZ, this._cameraNearFar.x, this._cameraNearFar.y );
|
|
456
509
|
|
|
457
|
-
|
|
510
|
+
};
|
|
458
511
|
|
|
459
|
-
|
|
512
|
+
// Optimized version of AABB clipping.
|
|
513
|
+
// Reference: https://github.com/playdeadgames/temporal
|
|
514
|
+
const clipAABB = Fn( ( [ currentColor, historyColor, minColor, maxColor ] ) => {
|
|
515
|
+
|
|
516
|
+
const pClip = maxColor.rgb.add( minColor.rgb ).mul( 0.5 );
|
|
517
|
+
const eClip = maxColor.rgb.sub( minColor.rgb ).mul( 0.5 ).add( 1e-7 );
|
|
518
|
+
const vClip = historyColor.sub( vec4( pClip, currentColor.a ) );
|
|
519
|
+
const vUnit = vClip.xyz.div( eClip );
|
|
520
|
+
const absUnit = vUnit.abs();
|
|
521
|
+
const maxUnit = max( absUnit.x, absUnit.y, absUnit.z );
|
|
522
|
+
return maxUnit.greaterThan( 1 ).select(
|
|
523
|
+
vec4( pClip, currentColor.a ).add( vClip.div( maxUnit ) ),
|
|
524
|
+
historyColor
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
} ).setLayout( {
|
|
528
|
+
name: 'clipAABB',
|
|
529
|
+
type: 'vec4',
|
|
530
|
+
inputs: [
|
|
531
|
+
{ name: 'currentColor', type: 'vec4' },
|
|
532
|
+
{ name: 'historyColor', type: 'vec4' },
|
|
533
|
+
{ name: 'minColor', type: 'vec4' },
|
|
534
|
+
{ name: 'maxColor', type: 'vec4' }
|
|
535
|
+
]
|
|
536
|
+
} );
|
|
460
537
|
|
|
461
|
-
|
|
462
|
-
|
|
538
|
+
// Performs variance clipping.
|
|
539
|
+
// See: https://developer.download.nvidia.com/gameworks/events/GDC2016/msalvi_temporal_supersampling.pdf
|
|
540
|
+
const varianceClipping = Fn( ( [ positionTexel, currentColor, historyColor, gamma ] ) => {
|
|
463
541
|
|
|
464
|
-
|
|
542
|
+
const offsets = [
|
|
543
|
+
[ - 1, - 1 ],
|
|
544
|
+
[ - 1, 1 ],
|
|
545
|
+
[ 1, - 1 ],
|
|
546
|
+
[ 1, 1 ],
|
|
547
|
+
[ 1, 0 ],
|
|
548
|
+
[ 0, - 1 ],
|
|
549
|
+
[ 0, 1 ],
|
|
550
|
+
[ - 1, 0 ]
|
|
551
|
+
];
|
|
465
552
|
|
|
466
|
-
const
|
|
553
|
+
const moment1 = currentColor.toVar();
|
|
554
|
+
const moment2 = currentColor.pow2().toVar();
|
|
467
555
|
|
|
468
|
-
|
|
556
|
+
for ( const [ x, y ] of offsets ) {
|
|
469
557
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
558
|
+
// Use max() to prevent NaN values from propagating.
|
|
559
|
+
const neighbor = this.beautyNode.offset( ivec2( x, y ) ).load( positionTexel ).max( 0 );
|
|
560
|
+
moment1.addAssign( neighbor );
|
|
561
|
+
moment2.addAssign( neighbor.pow2() );
|
|
473
562
|
|
|
474
|
-
|
|
563
|
+
}
|
|
475
564
|
|
|
476
|
-
const
|
|
477
|
-
const
|
|
478
|
-
const
|
|
479
|
-
const
|
|
565
|
+
const N = float( offsets.length + 1 );
|
|
566
|
+
const mean = moment1.div( N );
|
|
567
|
+
const variance = moment2.div( N ).sub( mean.pow2() ).max( 0 ).sqrt().mul( gamma );
|
|
568
|
+
const minColor = mean.sub( variance );
|
|
569
|
+
const maxColor = mean.add( variance );
|
|
480
570
|
|
|
481
|
-
|
|
571
|
+
return clipAABB( mean.clamp( minColor, maxColor ), historyColor, minColor, maxColor );
|
|
482
572
|
|
|
483
|
-
|
|
484
|
-
worldPositionDifference.assign( min( max( worldPositionDifference.sub( 1.0 ), 0.0 ), 1.0 ) );
|
|
573
|
+
} );
|
|
485
574
|
|
|
486
|
-
|
|
487
|
-
|
|
575
|
+
// Returns the amount of subpixel (expressed within [0, 1]) in the velocity.
|
|
576
|
+
const subpixelCorrection = Fn( ( [ velocityUV, textureSize ] ) => {
|
|
577
|
+
|
|
578
|
+
const velocityTexel = velocityUV.mul( textureSize );
|
|
579
|
+
const phase = velocityTexel.fract().abs();
|
|
580
|
+
const weight = max( phase, phase.oneMinus() );
|
|
581
|
+
return weight.x.mul( weight.y ).oneMinus().div( 0.75 );
|
|
582
|
+
|
|
583
|
+
} ).setLayout( {
|
|
584
|
+
name: 'subpixelCorrection',
|
|
585
|
+
type: 'float',
|
|
586
|
+
inputs: [
|
|
587
|
+
{ name: 'velocityUV', type: 'vec2' },
|
|
588
|
+
{ name: 'textureSize', type: 'ivec2' }
|
|
589
|
+
]
|
|
590
|
+
} );
|
|
488
591
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
motionFactor.assign( min( motionFactor, 1.0 ) );
|
|
592
|
+
// Flicker reduction based on luminance weighing.
|
|
593
|
+
const flickerReduction = Fn( ( [ currentColor, historyColor, currentWeight ] ) => {
|
|
492
594
|
|
|
493
|
-
const
|
|
494
|
-
const
|
|
595
|
+
const historyWeight = currentWeight.oneMinus();
|
|
596
|
+
const compressedCurrent = currentColor.mul( float( 1 ).div( ( max( currentColor.r, currentColor.g, currentColor.b ).add( 1 ) ) ) );
|
|
597
|
+
const compressedHistory = historyColor.mul( float( 1 ).div( ( max( historyColor.r, historyColor.g, historyColor.b ).add( 1 ) ) ) );
|
|
495
598
|
|
|
496
|
-
|
|
497
|
-
|
|
599
|
+
const luminanceCurrent = luminance( compressedCurrent.rgb );
|
|
600
|
+
const luminanceHistory = luminance( compressedHistory.rgb );
|
|
498
601
|
|
|
499
|
-
|
|
500
|
-
|
|
602
|
+
currentWeight.mulAssign( float( 1 ).div( luminanceCurrent.add( 1 ) ) );
|
|
603
|
+
historyWeight.mulAssign( float( 1 ).div( luminanceHistory.add( 1 ) ) );
|
|
501
604
|
|
|
502
|
-
|
|
605
|
+
return add( currentColor.mul( currentWeight ), historyColor.mul( historyWeight ) ).div( max( currentWeight.add( historyWeight ), 0.00001 ) ).toVar();
|
|
503
606
|
|
|
504
|
-
|
|
505
|
-
historyWeight.assign( 0.0 );
|
|
607
|
+
} );
|
|
506
608
|
|
|
507
|
-
|
|
609
|
+
const historyNode = texture( this._historyRenderTarget.texture );
|
|
508
610
|
|
|
509
|
-
|
|
611
|
+
const resolve = Fn( () => {
|
|
510
612
|
|
|
511
|
-
const
|
|
512
|
-
const
|
|
613
|
+
const uvNode = uv();
|
|
614
|
+
const textureSize = this.beautyNode.size(); // Assumes all the buffers share the same size.
|
|
615
|
+
const positionTexel = uvNode.mul( textureSize );
|
|
513
616
|
|
|
514
|
-
|
|
515
|
-
|
|
617
|
+
// sample the closest and farthest depths in the current buffer
|
|
618
|
+
|
|
619
|
+
const currentDepth = sampleCurrentDepth( positionTexel );
|
|
620
|
+
const closestDepth = currentDepth.get( 'closestDepth' );
|
|
621
|
+
const closestPositionTexel = currentDepth.get( 'closestPositionTexel' );
|
|
622
|
+
const farthestDepth = currentDepth.get( 'farthestDepth' );
|
|
623
|
+
|
|
624
|
+
// convert the NDC offset to UV offset
|
|
625
|
+
|
|
626
|
+
const offsetUV = this.velocityNode.load( closestPositionTexel ).xy.mul( vec2( 0.5, - 0.5 ) );
|
|
627
|
+
|
|
628
|
+
// sample the previous depth
|
|
629
|
+
|
|
630
|
+
const historyUV = uvNode.sub( offsetUV );
|
|
631
|
+
const previousDepth = samplePreviousDepth( historyUV );
|
|
632
|
+
|
|
633
|
+
// history is considered valid when the UV is in range and there's no disocclusion except on edges
|
|
634
|
+
|
|
635
|
+
const isValidUV = historyUV.greaterThanEqual( 0 ).all().and( historyUV.lessThanEqual( 1 ).all() );
|
|
636
|
+
const isEdge = farthestDepth.sub( closestDepth ).greaterThan( this.edgeDepthDiff );
|
|
637
|
+
const isDisocclusion = closestDepth.sub( previousDepth ).greaterThan( this.depthThreshold );
|
|
638
|
+
const hasValidHistory = isValidUV.and( isEdge.or( isDisocclusion.not() ) );
|
|
639
|
+
|
|
640
|
+
// sample the current and previous colors
|
|
641
|
+
|
|
642
|
+
const currentColor = this.beautyNode.sample( uvNode );
|
|
643
|
+
const historyColor = historyNode.sample( uvNode.sub( offsetUV ) );
|
|
644
|
+
|
|
645
|
+
// increase the weight towards the current frame under motion
|
|
646
|
+
|
|
647
|
+
const motionFactor = uvNode.sub( historyUV ).mul( textureSize ).length().div( this.maxVelocityLength ).saturate();
|
|
648
|
+
const currentWeight = float( 0.05 ).toVar(); // A minimum weight
|
|
516
649
|
|
|
517
|
-
|
|
518
|
-
historyWeight.mulAssign( float( 1.0 ).div( luminanceHistory.add( 1 ) ) );
|
|
650
|
+
if ( this.useSubpixelCorrection ) {
|
|
519
651
|
|
|
520
|
-
|
|
652
|
+
// Increase the minimum weight towards the current frame when the velocity is more subpixel.
|
|
653
|
+
currentWeight.addAssign( subpixelCorrection( offsetUV, textureSize ).mul( 0.25 ) );
|
|
521
654
|
|
|
522
|
-
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
currentWeight.assign( hasValidHistory.select( currentWeight.add( motionFactor ).saturate(), 1 ) );
|
|
658
|
+
|
|
659
|
+
// Perform neighborhood clipping/clamping. We use variance clipping here.
|
|
660
|
+
|
|
661
|
+
const varianceGamma = mix( 0.5, 1, motionFactor.oneMinus().pow2() ); // Reasonable gamma range is [0.75, 2]
|
|
662
|
+
const clippedHistoryColor = varianceClipping( positionTexel, currentColor, historyColor, varianceGamma );
|
|
663
|
+
|
|
664
|
+
// flicker reduction based on luminance weighing
|
|
665
|
+
|
|
666
|
+
const output = flickerReduction( currentColor, clippedHistoryColor, currentWeight );
|
|
667
|
+
|
|
668
|
+
return output;
|
|
523
669
|
|
|
524
670
|
} );
|
|
525
671
|
|
|
@@ -548,21 +694,26 @@ class TRAANode extends TempNode {
|
|
|
548
694
|
|
|
549
695
|
export default TRAANode;
|
|
550
696
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
697
|
+
function _halton( index, base ) {
|
|
698
|
+
|
|
699
|
+
let fraction = 1;
|
|
700
|
+
let result = 0;
|
|
701
|
+
while ( index > 0 ) {
|
|
702
|
+
|
|
703
|
+
fraction /= base;
|
|
704
|
+
result += fraction * ( index % base );
|
|
705
|
+
index = Math.floor( index / base );
|
|
706
|
+
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
return result;
|
|
710
|
+
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
const _haltonOffsets = /*@__PURE__*/ Array.from(
|
|
714
|
+
{ length: 32 },
|
|
715
|
+
( _, index ) => [ _halton( index + 1, 2 ), _halton( index + 1, 3 ) ]
|
|
716
|
+
);
|
|
566
717
|
|
|
567
718
|
/**
|
|
568
719
|
* TSL function for creating a TRAA node for Temporal Reprojection Anti-Aliasing.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { interleavedGradientNoise, Fn, vec2, vec4, mix, uv, Loop, premultiplyAlpha, unpremultiplyAlpha, int, float, nodeObject, convertToTexture, screenCoordinate } from 'three/tsl';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This TSL function blurs an image in a circular pattern, radiating from a configurable center point in screen space.
|
|
5
|
+
*
|
|
6
|
+
* Radial blurs can be used for different kind of effects like producing simple faked lighting effects also known as
|
|
7
|
+
* "light shafts". The major limitation of this specific usage is the center point can only be defined in 2D so the
|
|
8
|
+
* effect does not honor the depth of 3D objects. Consequently, it is not intended for physically correct lit scenes.
|
|
9
|
+
*
|
|
10
|
+
* @tsl
|
|
11
|
+
* @function
|
|
12
|
+
* @param {Node<vec4>} textureNode - The texture node that should be blurred.
|
|
13
|
+
* @param {Object} [options={}] - Additional options for the radial blur effect.
|
|
14
|
+
* @param {Node<vec2>} [options.center=vec2(0.5, 0.5)] - The center of the light in screen uvs.
|
|
15
|
+
* @param {Node<int>} [options.weight=float(0.9)] - Base weight factor for each sample in the range `[0,1]`.
|
|
16
|
+
* @param {Node<int>} [options.decay=float(0.95)] - Decreases the weight factor so each iteration adds less to the sum. Must be in the range `[0,1]`.
|
|
17
|
+
* If you increase the sample count, you have to increase this option as well to avoid a darking effect.
|
|
18
|
+
* @param {Node<int>} [options.count=int(32)] - The number if iterations. Should be in the range `[16,64]`.
|
|
19
|
+
* @param {Node<int>} [options.exposure=float(5)] - Exposure control of the blur.
|
|
20
|
+
* @return {Node<vec4>} The blurred texture node.
|
|
21
|
+
*/
|
|
22
|
+
export const radialBlur = /*#__PURE__*/ Fn( ( [ textureNode, options = {} ] ) => {
|
|
23
|
+
|
|
24
|
+
textureNode = convertToTexture( textureNode );
|
|
25
|
+
|
|
26
|
+
const center = nodeObject( options.center ) || vec2( 0.5, 0.5 );
|
|
27
|
+
const weight = nodeObject( options.weight ) || float( 0.9 );
|
|
28
|
+
const decay = nodeObject( options.decay ) || float( 0.95 );
|
|
29
|
+
const count = nodeObject( options.count ) || int( 32 );
|
|
30
|
+
const exposure = nodeObject( options.exposure ) || float( 5 );
|
|
31
|
+
const premultipliedAlpha = options.premultipliedAlpha || false;
|
|
32
|
+
|
|
33
|
+
const tap = ( uv ) => {
|
|
34
|
+
|
|
35
|
+
const sample = textureNode.sample( uv );
|
|
36
|
+
|
|
37
|
+
return premultipliedAlpha ? premultiplyAlpha( sample ) : sample;
|
|
38
|
+
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const sampleUv = vec2( textureNode.uvNode || uv() );
|
|
42
|
+
|
|
43
|
+
const base = tap( sampleUv ).toConst();
|
|
44
|
+
const blur = vec4().toVar();
|
|
45
|
+
const offset = center.sub( sampleUv ).div( count ).toConst();
|
|
46
|
+
const w = float( weight ).toVar();
|
|
47
|
+
|
|
48
|
+
const noise = interleavedGradientNoise( screenCoordinate );
|
|
49
|
+
sampleUv.addAssign( offset.mul( noise ) ); // mitigate banding
|
|
50
|
+
|
|
51
|
+
Loop( { start: int( 0 ), end: int( count ), type: 'int', condition: '<' }, () => {
|
|
52
|
+
|
|
53
|
+
sampleUv.addAssign( offset );
|
|
54
|
+
const sample = tap( sampleUv );
|
|
55
|
+
|
|
56
|
+
blur.addAssign( sample.mul( w ) );
|
|
57
|
+
w.mulAssign( decay );
|
|
58
|
+
|
|
59
|
+
} );
|
|
60
|
+
|
|
61
|
+
blur.divAssign( count );
|
|
62
|
+
blur.mulAssign( exposure );
|
|
63
|
+
|
|
64
|
+
const color = mix( blur, base.mul( 2 ), 0.5 );
|
|
65
|
+
|
|
66
|
+
return premultipliedAlpha ? unpremultiplyAlpha( color ) : color;
|
|
67
|
+
|
|
68
|
+
} );
|
|
@@ -6,10 +6,8 @@ import {
|
|
|
6
6
|
OrthographicCamera,
|
|
7
7
|
PlaneGeometry,
|
|
8
8
|
Scene,
|
|
9
|
-
ShaderMaterial
|
|
10
|
-
UniformsUtils
|
|
9
|
+
ShaderMaterial
|
|
11
10
|
} from 'three';
|
|
12
|
-
import { UnpackDepthRGBAShader } from '../shaders/UnpackDepthRGBAShader.js';
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* This is a helper for visualising a given light's shadow map.
|
|
@@ -57,13 +55,29 @@ class ShadowMapViewer {
|
|
|
57
55
|
const scene = new Scene();
|
|
58
56
|
|
|
59
57
|
//HUD for shadow map
|
|
60
|
-
const shader = UnpackDepthRGBAShader;
|
|
61
|
-
|
|
62
|
-
const uniforms = UniformsUtils.clone( shader.uniforms );
|
|
63
58
|
const material = new ShaderMaterial( {
|
|
64
|
-
uniforms:
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
uniforms: {
|
|
60
|
+
tDiffuse: { value: null },
|
|
61
|
+
opacity: { value: 1.0 }
|
|
62
|
+
},
|
|
63
|
+
vertexShader: /* glsl */`
|
|
64
|
+
varying vec2 vUv;
|
|
65
|
+
void main() {
|
|
66
|
+
vUv = uv;
|
|
67
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
68
|
+
}`,
|
|
69
|
+
fragmentShader: /* glsl */`
|
|
70
|
+
uniform float opacity;
|
|
71
|
+
uniform sampler2D tDiffuse;
|
|
72
|
+
varying vec2 vUv;
|
|
73
|
+
void main() {
|
|
74
|
+
float depth = texture2D( tDiffuse, vUv ).r;
|
|
75
|
+
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
76
|
+
gl_FragColor = vec4( vec3( depth ), opacity );
|
|
77
|
+
#else
|
|
78
|
+
gl_FragColor = vec4( vec3( 1.0 - depth ), opacity );
|
|
79
|
+
#endif
|
|
80
|
+
}`
|
|
67
81
|
} );
|
|
68
82
|
const plane = new PlaneGeometry( frame.width, frame.height );
|
|
69
83
|
const mesh = new Mesh( plane, material );
|
|
@@ -177,7 +191,7 @@ class ShadowMapViewer {
|
|
|
177
191
|
//always end up with the scene's first added shadow casting light's shadowMap
|
|
178
192
|
//in the shader
|
|
179
193
|
//See: https://github.com/mrdoob/three.js/issues/5932
|
|
180
|
-
uniforms.tDiffuse.value = light.shadow.map.texture;
|
|
194
|
+
material.uniforms.tDiffuse.value = light.shadow.map.texture;
|
|
181
195
|
|
|
182
196
|
userAutoClearSetting = renderer.autoClear;
|
|
183
197
|
renderer.autoClear = false; // To allow render overlay
|