@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.
Files changed (253) hide show
  1. package/README.md +3 -4
  2. package/build/three.cjs +1192 -522
  3. package/build/three.core.js +345 -219
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +864 -328
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +15 -3
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +3660 -1545
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +3659 -1544
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/controls/MapControls.js +55 -1
  14. package/examples/jsm/controls/OrbitControls.js +6 -6
  15. package/examples/jsm/controls/TrackballControls.js +6 -6
  16. package/examples/jsm/csm/CSM.js +2 -1
  17. package/examples/jsm/environments/RoomEnvironment.js +2 -0
  18. package/examples/jsm/geometries/DecalGeometry.js +1 -1
  19. package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
  20. package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
  21. package/examples/jsm/inspector/Inspector.js +53 -9
  22. package/examples/jsm/inspector/RendererInspector.js +12 -2
  23. package/examples/jsm/inspector/tabs/Console.js +2 -2
  24. package/examples/jsm/inspector/tabs/Parameters.js +2 -2
  25. package/examples/jsm/inspector/tabs/Performance.js +2 -2
  26. package/examples/jsm/inspector/tabs/Viewer.js +4 -4
  27. package/examples/jsm/inspector/ui/Profiler.js +1836 -31
  28. package/examples/jsm/inspector/ui/Style.js +948 -13
  29. package/examples/jsm/inspector/ui/Tab.js +188 -1
  30. package/examples/jsm/inspector/ui/Values.js +17 -1
  31. package/examples/jsm/loaders/3DMLoader.js +5 -4
  32. package/examples/jsm/loaders/DRACOLoader.js +5 -5
  33. package/examples/jsm/loaders/FBXLoader.js +0 -2
  34. package/examples/jsm/loaders/HDRLoader.js +0 -1
  35. package/examples/jsm/loaders/KTX2Loader.js +16 -0
  36. package/examples/jsm/loaders/LDrawLoader.js +2 -3
  37. package/examples/jsm/loaders/PCDLoader.js +1 -0
  38. package/examples/jsm/loaders/SVGLoader.js +1 -1
  39. package/examples/jsm/loaders/TDSLoader.js +0 -2
  40. package/examples/jsm/loaders/TGALoader.js +0 -2
  41. package/examples/jsm/loaders/UltraHDRLoader.js +110 -137
  42. package/examples/jsm/loaders/VOXLoader.js +660 -117
  43. package/examples/jsm/loaders/VRMLLoader.js +2 -2
  44. package/examples/jsm/loaders/usd/USDCParser.js +1 -1
  45. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
  46. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -1
  47. package/examples/jsm/materials/WoodNodeMaterial.js +11 -11
  48. package/examples/jsm/math/Octree.js +131 -1
  49. package/examples/jsm/misc/Volume.js +0 -1
  50. package/examples/jsm/misc/VolumeSlice.js +0 -1
  51. package/examples/jsm/objects/SkyMesh.js +13 -3
  52. package/examples/jsm/physics/AmmoPhysics.js +12 -7
  53. package/examples/jsm/physics/JoltPhysics.js +3 -1
  54. package/examples/jsm/physics/RapierPhysics.js +3 -1
  55. package/examples/jsm/postprocessing/OutputPass.js +9 -0
  56. package/examples/jsm/postprocessing/RenderPass.js +10 -0
  57. package/examples/jsm/postprocessing/UnrealBloomPass.js +48 -18
  58. package/examples/jsm/renderers/Projector.js +268 -30
  59. package/examples/jsm/renderers/SVGRenderer.js +191 -58
  60. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -4
  61. package/examples/jsm/transpiler/AST.js +44 -0
  62. package/examples/jsm/transpiler/GLSLDecoder.js +61 -4
  63. package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -0
  64. package/examples/jsm/transpiler/TSLEncoder.js +46 -3
  65. package/examples/jsm/transpiler/TranspilerUtils.js +3 -3
  66. package/examples/jsm/transpiler/WGSLEncoder.js +27 -0
  67. package/examples/jsm/tsl/display/AnaglyphPassNode.js +2 -0
  68. package/examples/jsm/tsl/display/BloomNode.js +11 -1
  69. package/examples/jsm/tsl/display/GTAONode.js +3 -2
  70. package/examples/jsm/tsl/display/PixelationPassNode.js +2 -1
  71. package/examples/jsm/tsl/display/SSGINode.js +7 -19
  72. package/examples/jsm/tsl/display/SSRNode.js +1 -1
  73. package/examples/jsm/tsl/display/SSSNode.js +4 -2
  74. package/examples/jsm/tsl/display/StereoCompositePassNode.js +8 -1
  75. package/examples/jsm/tsl/display/TRAANode.js +265 -114
  76. package/examples/jsm/tsl/display/radialBlur.js +68 -0
  77. package/examples/jsm/utils/ShadowMapViewer.js +24 -10
  78. package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
  79. package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
  80. package/package.json +14 -12
  81. package/src/Three.Core.js +1 -0
  82. package/src/Three.TSL.js +14 -2
  83. package/src/animation/AnimationUtils.js +1 -12
  84. package/src/animation/KeyframeTrack.js +1 -1
  85. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  86. package/src/animation/tracks/ColorKeyframeTrack.js +1 -1
  87. package/src/animation/tracks/NumberKeyframeTrack.js +1 -1
  88. package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -1
  89. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  90. package/src/animation/tracks/VectorKeyframeTrack.js +1 -1
  91. package/src/constants.js +61 -5
  92. package/src/core/BufferGeometry.js +14 -2
  93. package/src/core/Raycaster.js +2 -2
  94. package/src/extras/PMREMGenerator.js +3 -10
  95. package/src/extras/TextureUtils.js +5 -1
  96. package/src/geometries/ExtrudeGeometry.js +2 -2
  97. package/src/geometries/PolyhedronGeometry.js +1 -1
  98. package/src/helpers/PointLightHelper.js +1 -1
  99. package/src/lights/DirectionalLight.js +13 -0
  100. package/src/lights/HemisphereLight.js +10 -0
  101. package/src/lights/Light.js +1 -11
  102. package/src/lights/LightProbe.js +0 -15
  103. package/src/lights/LightShadow.js +0 -3
  104. package/src/lights/PointLight.js +15 -0
  105. package/src/lights/PointLightShadow.js +0 -86
  106. package/src/lights/SpotLight.js +22 -1
  107. package/src/loaders/MaterialLoader.js +2 -1
  108. package/src/loaders/ObjectLoader.js +3 -1
  109. package/src/loaders/nodes/NodeLoader.js +2 -2
  110. package/src/materials/Material.js +2 -0
  111. package/src/materials/ShaderMaterial.js +20 -1
  112. package/src/materials/nodes/Line2NodeMaterial.js +2 -2
  113. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +3 -2
  114. package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -4
  115. package/src/materials/nodes/NodeMaterial.js +59 -3
  116. package/src/materials/nodes/manager/NodeMaterialObserver.js +1 -1
  117. package/src/math/Matrix4.js +40 -40
  118. package/src/math/Sphere.js +1 -1
  119. package/src/math/Vector3.js +0 -2
  120. package/src/nodes/TSL.js +4 -1
  121. package/src/nodes/accessors/BatchNode.js +10 -10
  122. package/src/nodes/accessors/BufferAttributeNode.js +98 -12
  123. package/src/nodes/accessors/BufferNode.js +29 -2
  124. package/src/nodes/accessors/ClippingNode.js +4 -4
  125. package/src/nodes/accessors/CubeTextureNode.js +20 -1
  126. package/src/nodes/accessors/InstanceNode.js +69 -29
  127. package/src/nodes/accessors/MaterialNode.js +9 -1
  128. package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
  129. package/src/nodes/accessors/ModelNode.js +1 -1
  130. package/src/nodes/accessors/Normal.js +2 -2
  131. package/src/nodes/accessors/ReferenceBaseNode.js +4 -4
  132. package/src/nodes/accessors/ReferenceNode.js +4 -4
  133. package/src/nodes/accessors/RendererReferenceNode.js +1 -2
  134. package/src/nodes/accessors/SkinningNode.js +15 -2
  135. package/src/nodes/accessors/StorageBufferNode.js +4 -2
  136. package/src/nodes/accessors/Tangent.js +1 -11
  137. package/src/nodes/accessors/Texture3DNode.js +26 -1
  138. package/src/nodes/accessors/UniformArrayNode.js +2 -2
  139. package/src/nodes/accessors/UserDataNode.js +1 -2
  140. package/src/nodes/accessors/VertexColorNode.js +1 -2
  141. package/src/nodes/code/FunctionNode.js +1 -2
  142. package/src/nodes/core/ArrayNode.js +20 -1
  143. package/src/nodes/core/AssignNode.js +2 -2
  144. package/src/nodes/core/AttributeNode.js +2 -2
  145. package/src/nodes/core/ContextNode.js +103 -4
  146. package/src/nodes/core/NodeBuilder.js +56 -14
  147. package/src/nodes/core/NodeFrame.js +12 -4
  148. package/src/nodes/core/NodeUtils.js +5 -5
  149. package/src/nodes/core/ParameterNode.js +1 -2
  150. package/src/nodes/core/PropertyNode.js +19 -3
  151. package/src/nodes/core/StackNode.js +56 -8
  152. package/src/nodes/core/StructNode.js +1 -2
  153. package/src/nodes/core/StructTypeNode.js +11 -17
  154. package/src/nodes/core/UniformNode.js +19 -4
  155. package/src/nodes/core/VarNode.js +46 -21
  156. package/src/nodes/display/NormalMapNode.js +37 -2
  157. package/src/nodes/display/PassNode.js +77 -7
  158. package/src/nodes/display/ScreenNode.js +1 -0
  159. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +3 -3
  160. package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
  161. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  162. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
  163. package/src/nodes/functions/PhysicalLightingModel.js +102 -43
  164. package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -2
  165. package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
  166. package/src/nodes/gpgpu/WorkgroupInfoNode.js +2 -3
  167. package/src/nodes/lighting/AnalyticLightNode.js +53 -0
  168. package/src/nodes/lighting/LightsNode.js +2 -2
  169. package/src/nodes/lighting/PointShadowNode.js +141 -140
  170. package/src/nodes/lighting/ShadowFilterNode.js +53 -37
  171. package/src/nodes/lighting/ShadowNode.js +53 -19
  172. package/src/nodes/math/BitcountNode.js +433 -0
  173. package/src/nodes/math/PackFloatNode.js +98 -0
  174. package/src/nodes/math/UnpackFloatNode.js +96 -0
  175. package/src/nodes/pmrem/PMREMNode.js +1 -1
  176. package/src/nodes/tsl/TSLCore.js +4 -4
  177. package/src/nodes/utils/ArrayElementNode.js +13 -0
  178. package/src/nodes/utils/EventNode.js +1 -2
  179. package/src/nodes/utils/Packing.js +13 -1
  180. package/src/nodes/utils/PostProcessingUtils.js +33 -1
  181. package/src/nodes/utils/ReflectorNode.js +1 -1
  182. package/src/nodes/utils/SampleNode.js +1 -1
  183. package/src/nodes/utils/UVUtils.js +26 -0
  184. package/src/objects/BatchedMesh.js +5 -2
  185. package/src/objects/Line.js +1 -1
  186. package/src/objects/Mesh.js +1 -1
  187. package/src/objects/Points.js +1 -1
  188. package/src/objects/Skeleton.js +9 -0
  189. package/src/renderers/WebGLRenderer.js +145 -33
  190. package/src/renderers/common/Backend.js +8 -0
  191. package/src/renderers/common/Background.js +19 -9
  192. package/src/renderers/common/Binding.js +11 -0
  193. package/src/renderers/common/Bindings.js +7 -7
  194. package/src/renderers/common/Buffer.js +40 -0
  195. package/src/renderers/common/ChainMap.js +30 -6
  196. package/src/renderers/common/Geometries.js +12 -0
  197. package/src/renderers/common/RenderContexts.js +8 -1
  198. package/src/renderers/common/RenderObject.js +14 -1
  199. package/src/renderers/common/Renderer.js +53 -35
  200. package/src/renderers/common/Textures.js +1 -1
  201. package/src/renderers/common/UniformsGroup.js +1 -0
  202. package/src/renderers/common/XRManager.js +1 -0
  203. package/src/renderers/common/extras/PMREMGenerator.js +2 -8
  204. package/src/renderers/common/nodes/NodeUniformBuffer.js +52 -0
  205. package/src/renderers/shaders/DFGLUTData.js +19 -34
  206. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
  207. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
  208. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +90 -51
  209. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +194 -186
  210. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
  211. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  212. package/src/renderers/shaders/ShaderChunk.js +3 -3
  213. package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
  214. package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
  215. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +0 -1
  216. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
  217. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -1
  218. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
  219. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
  220. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +0 -1
  221. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
  222. package/src/renderers/shaders/ShaderLib.js +3 -3
  223. package/src/renderers/webgl/WebGLCapabilities.js +3 -4
  224. package/src/renderers/webgl/WebGLLights.js +18 -1
  225. package/src/renderers/webgl/WebGLOutput.js +267 -0
  226. package/src/renderers/webgl/WebGLProgram.js +43 -107
  227. package/src/renderers/webgl/WebGLPrograms.js +35 -45
  228. package/src/renderers/webgl/WebGLShadowMap.js +188 -25
  229. package/src/renderers/webgl/WebGLState.js +20 -20
  230. package/src/renderers/webgl/WebGLTextures.js +89 -28
  231. package/src/renderers/webgl/WebGLUniforms.js +40 -3
  232. package/src/renderers/webgl/WebGLUtils.js +6 -2
  233. package/src/renderers/webgl-fallback/WebGLBackend.js +79 -13
  234. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +59 -7
  235. package/src/renderers/webgl-fallback/utils/WebGLState.js +18 -3
  236. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +5 -3
  237. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -9
  238. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +6 -2
  239. package/src/renderers/webgpu/WebGPUBackend.js +61 -4
  240. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  241. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +65 -23
  242. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -17
  243. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +354 -186
  244. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -0
  245. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +20 -7
  246. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +40 -17
  247. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +7 -7
  248. package/src/renderers/webgpu/utils/WebGPUUtils.js +7 -5
  249. package/src/textures/CubeDepthTexture.js +76 -0
  250. package/src/textures/Source.js +1 -1
  251. package/src/textures/Texture.js +1 -1
  252. package/src/utils.js +13 -1
  253. 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, Loop, int, Fn, min, max, clamp, nodeObject, texture, uniform, uv, vec2, vec4, luminance, convertToTexture, passTexture, velocity, getViewPosition, length } from 'three/tsl';
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
- * The camera the scene is rendered with.
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
- * The jitter index selects the current camera offset value.
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._jitterIndex = 0;
93
+ this.depthThreshold = 0.0005;
94
94
 
95
95
  /**
96
- * A uniform node holding the inverse resolution value.
96
+ * The depth difference within the 3×3 neighborhood to consider a pixel as an edge.
97
97
  *
98
- * @private
99
- * @type {UniformNode<vec2>}
98
+ * @type {number}
99
+ * @default 0.001
100
100
  */
101
- this._invSize = uniform( new Vector2() );
101
+ this.edgeDepthDiff = 0.001;
102
102
 
103
103
  /**
104
- * A uniform node holding the camera world matrix.
104
+ * The history becomes invalid as the pixel length of the velocity approaches this value.
105
105
  *
106
- * @private
107
- * @type {UniformNode<mat4>}
106
+ * @type {number}
107
+ * @default 128
108
108
  */
109
- this._cameraWorldMatrix = uniform( new Matrix4() );
109
+ this.maxVelocityLength = 128;
110
110
 
111
111
  /**
112
- * A uniform node holding the camera projection matrix inverse.
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
- * @private
115
- * @type {UniformNode<mat4>}
115
+ * @type {boolean}
116
+ * @default true
116
117
  */
117
- this._cameraProjectionMatrixInverse = uniform( new Matrix4() );
118
+ this.useSubpixelCorrection = true;
118
119
 
119
120
  /**
120
- * A uniform node holding the previous frame's view matrix.
121
+ * The jitter index selects the current camera offset value.
121
122
  *
122
123
  * @private
123
- * @type {UniformNode<mat4>}
124
+ * @type {number}
125
+ * @default 0
124
126
  */
125
- this._previousCameraWorldMatrix = uniform( new Matrix4() );
127
+ this._jitterIndex = 0;
126
128
 
127
129
  /**
128
- * A uniform node holding the previous frame's projection matrix inverse.
130
+ * A uniform node holding the inverse resolution value.
129
131
  *
130
132
  * @private
131
- * @type {UniformNode<mat4>}
133
+ * @type {UniformNode<vec2>}
132
134
  */
133
- this._previousCameraProjectionMatrixInverse = uniform( new Matrix4() );
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 = _JitterVectors[ this._jitterIndex ];
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 ] * 0.0625, viewOffset.offsetY + jitterOffset[ 1 ] * 0.0625, // 0.0625 = 1 / 16
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 % ( _JitterVectors.length - 1 );
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 historyTexture = texture( this._historyRenderTarget.texture );
407
- const sampleTexture = this.beautyNode;
408
- const depthTexture = this.depthNode;
409
- const velocityTexture = this.velocityNode;
458
+ const currentDepthStruct = struct( {
410
459
 
411
- const resolve = Fn( () => {
460
+ closestDepth: 'float',
461
+ closestPositionTexel: 'vec2',
462
+ farthestDepth: 'float',
412
463
 
413
- const uvNode = uv();
464
+ } );
414
465
 
415
- const minColor = vec4( 10000 ).toVar();
416
- const maxColor = vec4( - 10000 ).toVar();
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
- // sample a 3x3 neighborhood to create a box in color space
422
- // clamping the history color with the resulting min/max colors mitigates ghosting
469
+ const closestDepth = float( 2 ).toVar();
470
+ const closestPositionTexel = vec2( 0 ).toVar();
471
+ const farthestDepth = float( - 1 ).toVar();
423
472
 
424
- Loop( { start: int( - 1 ), end: int( 1 ), type: 'int', condition: '<=', name: 'x' }, ( { x } ) => {
473
+ for ( let x = - 1; x <= 1; ++ x ) {
425
474
 
426
- Loop( { start: int( - 1 ), end: int( 1 ), type: 'int', condition: '<=', name: 'y' }, ( { y } ) => {
475
+ for ( let y = - 1; y <= 1; ++ y ) {
427
476
 
428
- const uvNeighbor = uvNode.add( vec2( float( x ), float( y ) ).mul( this._invSize ) ).toVar();
429
- const colorNeighbor = max( vec4( 0 ), sampleTexture.sample( uvNeighbor ) ).toVar(); // use max() to avoid propagate garbage values
477
+ const neighbor = positionTexel.add( vec2( x, y ) ).toVar();
478
+ const depth = this.depthNode.load( neighbor ).r.toVar();
430
479
 
431
- minColor.assign( min( minColor, colorNeighbor ) );
432
- maxColor.assign( max( maxColor, colorNeighbor ) );
480
+ If( depth.lessThan( closestDepth ), () => {
433
481
 
434
- const currentDepth = depthTexture.sample( uvNeighbor ).r.toVar();
482
+ closestDepth.assign( depth );
483
+ closestPositionTexel.assign( neighbor );
435
484
 
436
- // find the sample position of the closest depth in the neighborhood (used for velocity)
485
+ } );
437
486
 
438
- If( currentDepth.lessThan( closestDepth ), () => {
487
+ If( depth.greaterThan( farthestDepth ), () => {
439
488
 
440
- closestDepth.assign( currentDepth );
441
- closestDepthPixelPosition.assign( uvNeighbor );
489
+ farthestDepth.assign( depth );
442
490
 
443
491
  } );
444
492
 
445
- // find the farthest depth in the neighborhood (used to preserve edge anti-aliasing)
493
+ }
446
494
 
447
- If( currentDepth.greaterThan( farthestDepth ), () => {
495
+ }
448
496
 
449
- farthestDepth.assign( currentDepth );
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
- // sampling/reprojection
510
+ };
458
511
 
459
- const offset = velocityTexture.sample( closestDepthPixelPosition ).xy.mul( vec2( 0.5, - 0.5 ) ); // NDC to uv offset
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
- const currentColor = sampleTexture.sample( uvNode );
462
- const historyColor = historyTexture.sample( uvNode.sub( offset ) );
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
- // clamping
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 clampedHistoryColor = clamp( historyColor, minColor, maxColor );
553
+ const moment1 = currentColor.toVar();
554
+ const moment2 = currentColor.pow2().toVar();
467
555
 
468
- // calculate current frame world position
556
+ for ( const [ x, y ] of offsets ) {
469
557
 
470
- const currentDepth = depthTexture.sample( uvNode ).r;
471
- const currentViewPosition = getViewPosition( uvNode, currentDepth, this._cameraProjectionMatrixInverse );
472
- const currentWorldPosition = this._cameraWorldMatrix.mul( vec4( currentViewPosition, 1.0 ) ).xyz;
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
- // calculate previous frame world position from history UV and previous depth
563
+ }
475
564
 
476
- const historyUV = uvNode.sub( offset );
477
- const previousDepth = this._previousDepthNode.sample( historyUV ).r;
478
- const previousViewPosition = getViewPosition( historyUV, previousDepth, this._previousCameraProjectionMatrixInverse );
479
- const previousWorldPosition = this._previousCameraWorldMatrix.mul( vec4( previousViewPosition, 1.0 ) ).xyz;
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
- // calculate difference in world positions
571
+ return clipAABB( mean.clamp( minColor, maxColor ), historyColor, minColor, maxColor );
482
572
 
483
- const worldPositionDifference = length( currentWorldPosition.sub( previousWorldPosition ) ).toVar();
484
- worldPositionDifference.assign( min( max( worldPositionDifference.sub( 1.0 ), 0.0 ), 1.0 ) );
573
+ } );
485
574
 
486
- // Adaptive blend weights based on velocity magnitude suggested by CLAUDE in #32133
487
- // Higher velocity or position difference = more weight on current frame to reduce ghosting
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
- const velocityMagnitude = length( offset ).toConst();
490
- const motionFactor = max( worldPositionDifference.mul( 0.5 ), velocityMagnitude.mul( 10.0 ) ).toVar();
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 currentWeight = float( 0.05 ).add( motionFactor.mul( 0.25 ) ).toVar();
494
- const historyWeight = currentWeight.oneMinus().toVar();
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
- // zero out history weight if world positions are different (indicating motion) except on edges.
497
- // note that the constants 0.00001 and 0.5 were suggested by CLAUDE in #32133
599
+ const luminanceCurrent = luminance( compressedCurrent.rgb );
600
+ const luminanceHistory = luminance( compressedHistory.rgb );
498
601
 
499
- const isEdge = farthestDepth.sub( closestDepth ).greaterThan( 0.00001 );
500
- const strongDisocclusion = worldPositionDifference.greaterThan( 0.5 ).and( isEdge.not() );
602
+ currentWeight.mulAssign( float( 1 ).div( luminanceCurrent.add( 1 ) ) );
603
+ historyWeight.mulAssign( float( 1 ).div( luminanceHistory.add( 1 ) ) );
501
604
 
502
- If( strongDisocclusion, () => {
605
+ return add( currentColor.mul( currentWeight ), historyColor.mul( historyWeight ) ).div( max( currentWeight.add( historyWeight ), 0.00001 ) ).toVar();
503
606
 
504
- currentWeight.assign( 1.0 );
505
- historyWeight.assign( 0.0 );
607
+ } );
506
608
 
507
- } );
609
+ const historyNode = texture( this._historyRenderTarget.texture );
508
610
 
509
- // flicker reduction based on luminance weighing
611
+ const resolve = Fn( () => {
510
612
 
511
- const compressedCurrent = currentColor.mul( float( 1 ).div( ( max( currentColor.r, currentColor.g, currentColor.b ).add( 1.0 ) ) ) );
512
- const compressedHistory = clampedHistoryColor.mul( float( 1 ).div( ( max( clampedHistoryColor.r, clampedHistoryColor.g, clampedHistoryColor.b ).add( 1.0 ) ) ) );
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
- const luminanceCurrent = luminance( compressedCurrent.rgb );
515
- const luminanceHistory = luminance( compressedHistory.rgb );
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
- currentWeight.mulAssign( float( 1.0 ).div( luminanceCurrent.add( 1 ) ) );
518
- historyWeight.mulAssign( float( 1.0 ).div( luminanceHistory.add( 1 ) ) );
650
+ if ( this.useSubpixelCorrection ) {
519
651
 
520
- const smoothedOutput = add( currentColor.mul( currentWeight ), clampedHistoryColor.mul( historyWeight ) ).div( max( currentWeight.add( historyWeight ), 0.00001 ) ).toVar();
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
- return smoothedOutput;
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
- // These jitter vectors are specified in integers because it is easier.
552
- // I am assuming a [-8,8) integer grid, but it needs to be mapped onto [-0.5,0.5)
553
- // before being used, thus these integers need to be scaled by 1/16.
554
- //
555
- // Sample patterns reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476218%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
556
- const _JitterVectors = [
557
- [ - 4, - 7 ], [ - 7, - 5 ], [ - 3, - 5 ], [ - 5, - 4 ],
558
- [ - 1, - 4 ], [ - 2, - 2 ], [ - 6, - 1 ], [ - 4, 0 ],
559
- [ - 7, 1 ], [ - 1, 2 ], [ - 6, 3 ], [ - 3, 3 ],
560
- [ - 7, 6 ], [ - 3, 6 ], [ - 5, 7 ], [ - 1, 7 ],
561
- [ 5, - 7 ], [ 1, - 6 ], [ 6, - 5 ], [ 4, - 4 ],
562
- [ 2, - 3 ], [ 7, - 2 ], [ 1, - 1 ], [ 4, - 1 ],
563
- [ 2, 1 ], [ 6, 2 ], [ 0, 4 ], [ 4, 4 ],
564
- [ 2, 5 ], [ 7, 5 ], [ 5, 6 ], [ 3, 7 ]
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: uniforms,
65
- vertexShader: shader.vertexShader,
66
- fragmentShader: shader.fragmentShader
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
@@ -9,7 +9,7 @@ import {
9
9
  Scene,
10
10
  DepthTexture,
11
11
  Vector2
12
- } from 'three';
12
+ } from 'three/webgpu';
13
13
  import { uv, uniform, textureLoad } from 'three/tsl';
14
14
 
15
15
  /**
@@ -3,7 +3,7 @@ import {
3
3
  NodeMaterial,
4
4
  WebGPURenderer,
5
5
  CanvasTexture
6
- } from 'three';
6
+ } from 'three/webgpu';
7
7
  import { texture, uv } from 'three/tsl';
8
8
 
9
9
  /**