super-three 0.177.0 → 0.179.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 (211) hide show
  1. package/README.md +1 -1
  2. package/build/three.cjs +959 -231
  3. package/build/three.core.js +751 -170
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +210 -64
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +78 -29
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +3269 -1545
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +3093 -1545
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/Addons.js +1 -2
  14. package/examples/jsm/capabilities/WebGL.js +0 -27
  15. package/examples/jsm/capabilities/WebGPU.js +1 -1
  16. package/examples/jsm/controls/ArcballControls.js +1 -1
  17. package/examples/jsm/controls/TransformControls.js +61 -14
  18. package/examples/jsm/csm/CSMShadowNode.js +4 -4
  19. package/examples/jsm/environments/RoomEnvironment.js +8 -3
  20. package/examples/jsm/exporters/USDZExporter.js +676 -299
  21. package/examples/jsm/geometries/RoundedBoxGeometry.js +47 -8
  22. package/examples/jsm/interactive/HTMLMesh.js +5 -3
  23. package/examples/jsm/libs/meshopt_decoder.module.js +75 -58
  24. package/examples/jsm/lights/LightProbeGenerator.js +14 -3
  25. package/examples/jsm/loaders/ColladaLoader.js +1 -1
  26. package/examples/jsm/loaders/EXRLoader.js +210 -22
  27. package/examples/jsm/loaders/FBXLoader.js +2 -2
  28. package/examples/jsm/loaders/MaterialXLoader.js +212 -30
  29. package/examples/jsm/loaders/TTFLoader.js +13 -1
  30. package/examples/jsm/loaders/USDLoader.js +219 -0
  31. package/examples/jsm/loaders/USDZLoader.js +4 -892
  32. package/examples/jsm/loaders/usd/USDAParser.js +741 -0
  33. package/examples/jsm/loaders/usd/USDCParser.js +17 -0
  34. package/examples/jsm/objects/LensflareMesh.js +3 -3
  35. package/examples/jsm/objects/SkyMesh.js +2 -2
  36. package/examples/jsm/physics/RapierPhysics.js +95 -16
  37. package/examples/jsm/postprocessing/GTAOPass.js +10 -9
  38. package/examples/jsm/postprocessing/OutlinePass.js +17 -17
  39. package/examples/jsm/postprocessing/SSAOPass.js +10 -9
  40. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +11 -2
  41. package/examples/jsm/transpiler/AST.js +381 -30
  42. package/examples/jsm/transpiler/GLSLDecoder.js +226 -86
  43. package/examples/jsm/transpiler/Linker.js +327 -0
  44. package/examples/jsm/transpiler/TSLEncoder.js +197 -92
  45. package/examples/jsm/transpiler/Transpiler.js +17 -1
  46. package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
  47. package/examples/jsm/transpiler/WGSLEncoder.js +788 -0
  48. package/examples/jsm/tsl/display/BloomNode.js +8 -7
  49. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +206 -0
  50. package/examples/jsm/tsl/display/GaussianBlurNode.js +8 -10
  51. package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
  52. package/examples/jsm/tsl/display/{TRAAPassNode.js → TRAANode.js} +181 -172
  53. package/examples/jsm/tsl/display/hashBlur.js +3 -3
  54. package/examples/jsm/tsl/lighting/TiledLightsNode.js +1 -1
  55. package/package.json +1 -1
  56. package/src/Three.Core.js +1 -0
  57. package/src/Three.TSL.js +77 -28
  58. package/src/Three.WebGPU.js +2 -0
  59. package/src/animation/KeyframeTrack.js +1 -1
  60. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  61. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  62. package/src/cameras/Camera.js +14 -0
  63. package/src/cameras/OrthographicCamera.js +1 -1
  64. package/src/cameras/PerspectiveCamera.js +1 -1
  65. package/src/constants.js +3 -3
  66. package/src/core/BufferAttribute.js +3 -3
  67. package/src/core/Clock.js +2 -8
  68. package/src/core/GLBufferAttribute.js +13 -1
  69. package/src/core/Object3D.js +1 -1
  70. package/{examples/jsm/misc → src/core}/Timer.js +4 -42
  71. package/src/extras/PMREMGenerator.js +11 -0
  72. package/src/extras/core/Path.js +22 -22
  73. package/src/helpers/CameraHelper.js +41 -11
  74. package/src/helpers/SkeletonHelper.js +35 -6
  75. package/src/lights/LightShadow.js +21 -8
  76. package/src/lights/PointLightShadow.js +1 -1
  77. package/src/loaders/FileLoader.js +27 -4
  78. package/src/loaders/ImageBitmapLoader.js +27 -4
  79. package/src/loaders/ImageLoader.js +55 -8
  80. package/src/loaders/Loader.js +14 -0
  81. package/src/loaders/LoadingManager.js +23 -0
  82. package/src/materials/MeshBasicMaterial.js +1 -1
  83. package/src/materials/nodes/Line2NodeMaterial.js +0 -8
  84. package/src/materials/nodes/MeshBasicNodeMaterial.js +4 -3
  85. package/src/materials/nodes/MeshMatcapNodeMaterial.js +1 -1
  86. package/src/materials/nodes/MeshNormalNodeMaterial.js +2 -2
  87. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +2 -1
  88. package/src/materials/nodes/MeshSSSNodeMaterial.js +2 -2
  89. package/src/materials/nodes/NodeMaterial.js +28 -5
  90. package/src/materials/nodes/PointsNodeMaterial.js +5 -0
  91. package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -2
  92. package/src/math/Frustum.js +25 -9
  93. package/src/math/FrustumArray.js +10 -5
  94. package/src/math/Line3.js +129 -2
  95. package/src/math/Matrix4.js +48 -27
  96. package/src/math/Quaternion.js +1 -1
  97. package/src/math/Spherical.js +2 -2
  98. package/src/nodes/Nodes.js +2 -3
  99. package/src/nodes/TSL.js +5 -3
  100. package/src/nodes/accessors/AccessorsUtils.js +7 -8
  101. package/src/nodes/accessors/Bitangent.js +31 -25
  102. package/src/nodes/accessors/Camera.js +12 -12
  103. package/src/nodes/accessors/Normal.js +95 -29
  104. package/src/nodes/accessors/Object3DNode.js +1 -1
  105. package/src/nodes/accessors/Position.js +7 -7
  106. package/src/nodes/accessors/ReferenceNode.js +18 -3
  107. package/src/nodes/accessors/ReflectVector.js +3 -3
  108. package/src/nodes/accessors/SceneNode.js +1 -1
  109. package/src/nodes/accessors/StorageTextureNode.js +1 -1
  110. package/src/nodes/accessors/Tangent.js +25 -17
  111. package/src/nodes/accessors/TangentUtils.js +46 -0
  112. package/src/nodes/accessors/TextureBicubic.js +21 -3
  113. package/src/nodes/accessors/TextureNode.js +12 -0
  114. package/src/nodes/accessors/UniformArrayNode.js +0 -16
  115. package/src/nodes/core/ArrayNode.js +12 -0
  116. package/src/nodes/core/AssignNode.js +3 -0
  117. package/src/nodes/core/CacheNode.js +0 -14
  118. package/src/nodes/core/ContextNode.js +20 -1
  119. package/src/nodes/core/Node.js +15 -3
  120. package/src/nodes/core/NodeBuilder.js +228 -92
  121. package/src/nodes/core/NodeUtils.js +4 -1
  122. package/src/nodes/core/StackNode.js +49 -29
  123. package/src/nodes/core/SubBuildNode.js +89 -0
  124. package/src/nodes/core/UniformNode.js +63 -5
  125. package/src/nodes/core/VarNode.js +91 -2
  126. package/src/nodes/core/VaryingNode.js +6 -4
  127. package/src/nodes/display/BlendModes.js +2 -2
  128. package/src/nodes/display/FrontFacingNode.js +34 -2
  129. package/src/nodes/display/NormalMapNode.js +19 -50
  130. package/src/nodes/display/PassNode.js +157 -9
  131. package/src/nodes/display/ScreenNode.js +0 -26
  132. package/src/nodes/display/ViewportTextureNode.js +67 -7
  133. package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
  134. package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
  135. package/src/nodes/functions/PhongLightingModel.js +3 -3
  136. package/src/nodes/functions/PhysicalLightingModel.js +16 -16
  137. package/src/nodes/functions/material/getGeometryRoughness.js +2 -2
  138. package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
  139. package/src/nodes/gpgpu/ComputeNode.js +67 -23
  140. package/src/nodes/gpgpu/WorkgroupInfoNode.js +28 -3
  141. package/src/nodes/lighting/EnvironmentNode.js +5 -5
  142. package/src/nodes/lighting/LightsNode.js +4 -4
  143. package/src/nodes/lighting/ProjectorLightNode.js +19 -6
  144. package/src/nodes/lighting/ShadowFilterNode.js +1 -1
  145. package/src/nodes/lighting/ShadowNode.js +2 -2
  146. package/src/nodes/materialx/MaterialXNodes.js +131 -2
  147. package/src/nodes/materialx/lib/mx_noise.js +165 -1
  148. package/src/nodes/math/ConditionalNode.js +1 -20
  149. package/src/nodes/math/MathNode.js +90 -55
  150. package/src/nodes/math/OperatorNode.js +22 -39
  151. package/src/nodes/tsl/TSLBase.js +1 -0
  152. package/src/nodes/tsl/TSLCore.js +114 -55
  153. package/src/nodes/utils/DebugNode.js +1 -1
  154. package/src/nodes/utils/EquirectUV.js +27 -0
  155. package/src/nodes/utils/EventNode.js +83 -0
  156. package/src/nodes/utils/LoopNode.js +0 -17
  157. package/src/nodes/utils/MatcapUV.js +22 -0
  158. package/src/nodes/utils/RTTNode.js +22 -5
  159. package/src/nodes/utils/ReflectorNode.js +11 -4
  160. package/src/nodes/utils/SampleNode.js +81 -0
  161. package/src/nodes/utils/TriplanarTextures.js +65 -0
  162. package/src/objects/BatchedMesh.js +4 -2
  163. package/src/renderers/WebGLRenderer.js +26 -24
  164. package/src/renderers/common/Background.js +2 -2
  165. package/src/renderers/common/Bindings.js +19 -18
  166. package/src/renderers/common/Color4.js +2 -2
  167. package/src/renderers/common/CubeRenderTarget.js +1 -1
  168. package/src/renderers/common/PostProcessing.js +60 -5
  169. package/src/renderers/common/RenderObject.js +68 -3
  170. package/src/renderers/common/Renderer.js +19 -16
  171. package/src/renderers/common/SampledTexture.js +3 -71
  172. package/src/renderers/common/Sampler.js +79 -0
  173. package/src/renderers/common/Storage3DTexture.js +100 -0
  174. package/src/renderers/common/StorageArrayTexture.js +84 -0
  175. package/src/renderers/common/StorageTexture.js +19 -0
  176. package/src/renderers/common/Textures.js +19 -3
  177. package/src/renderers/common/XRManager.js +31 -12
  178. package/src/renderers/common/XRRenderTarget.js +21 -4
  179. package/src/renderers/common/extras/PMREMGenerator.js +1 -1
  180. package/src/renderers/common/nodes/NodeSampledTexture.js +0 -12
  181. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +20 -2
  182. package/src/renderers/shaders/ShaderLib/depth.glsl.js +11 -2
  183. package/src/renderers/webgl/WebGLAttributes.js +4 -0
  184. package/src/renderers/webgl/WebGLCapabilities.js +2 -2
  185. package/src/renderers/webgl/WebGLProgram.js +12 -6
  186. package/src/renderers/webgl/WebGLPrograms.js +6 -4
  187. package/src/renderers/webgl/WebGLShadowMap.js +11 -1
  188. package/src/renderers/webgl/WebGLState.js +4 -4
  189. package/src/renderers/webgl/WebGLTextures.js +19 -7
  190. package/src/renderers/webgl-fallback/WebGLBackend.js +103 -72
  191. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +3 -5
  192. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +4 -0
  193. package/src/renderers/webgl-fallback/utils/WebGLState.js +4 -4
  194. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +2 -0
  195. package/src/renderers/webgpu/WebGPUBackend.js +63 -16
  196. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +64 -79
  197. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -0
  198. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +45 -31
  199. package/src/renderers/webgpu/utils/WebGPUConstants.js +7 -1
  200. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +5 -5
  201. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +12 -65
  202. package/src/renderers/webgpu/utils/WebGPUUtils.js +2 -17
  203. package/src/renderers/webxr/WebXRDepthSensing.js +6 -10
  204. package/src/renderers/webxr/WebXRManager.js +68 -6
  205. package/src/textures/ExternalTexture.js +45 -0
  206. package/src/textures/FramebufferTexture.js +2 -2
  207. package/src/textures/Source.js +11 -1
  208. package/src/textures/VideoTexture.js +30 -2
  209. package/src/nodes/utils/EquirectUVNode.js +0 -65
  210. package/src/nodes/utils/MatcapUVNode.js +0 -49
  211. package/src/nodes/utils/TriplanarTexturesNode.js +0 -148
@@ -0,0 +1,22 @@
1
+ import { normalView } from '../accessors/Normal.js';
2
+ import { positionViewDirection } from '../accessors/Position.js';
3
+ import { Fn, vec2, vec3 } from '../tsl/TSLBase.js';
4
+
5
+ /**
6
+ * TSL function for creating a matcap uv node.
7
+ *
8
+ * Can be used to compute texture coordinates for projecting a
9
+ * matcap onto a mesh. Used by {@link MeshMatcapNodeMaterial}.
10
+ *
11
+ * @tsl
12
+ * @function
13
+ * @returns {Node<vec2>} The matcap UV coordinates.
14
+ */
15
+ export const matcapUV = /*@__PURE__*/ Fn( () => {
16
+
17
+ const x = vec3( positionViewDirection.z, 0, positionViewDirection.x.negate() ).normalize();
18
+ const y = positionViewDirection.cross( x );
19
+
20
+ return vec2( x.dot( normalView ), y.dot( normalView ) ).mul( 0.495 ).add( 0.5 ); // 0.495 to remove artifacts caused by undersized matcap disks
21
+
22
+ } ).once( [ 'NORMAL', 'VERTEX' ] )().toVar( 'matcapUV' );
@@ -41,6 +41,15 @@ class RTTNode extends TextureNode {
41
41
 
42
42
  super( renderTarget.texture, uv() );
43
43
 
44
+ /**
45
+ * This flag can be used for type testing.
46
+ *
47
+ * @type {boolean}
48
+ * @readonly
49
+ * @default true
50
+ */
51
+ this.isRTTNode = true;
52
+
44
53
  /**
45
54
  * The node to render a texture with.
46
55
  *
@@ -131,7 +140,7 @@ class RTTNode extends TextureNode {
131
140
  * @readonly
132
141
  * @default true
133
142
  */
134
- get autoSize() {
143
+ get autoResize() {
135
144
 
136
145
  return this.width === null;
137
146
 
@@ -188,13 +197,21 @@ class RTTNode extends TextureNode {
188
197
 
189
198
  //
190
199
 
191
- if ( this.autoSize === true ) {
192
-
193
- this.pixelRatio = renderer.getPixelRatio();
200
+ if ( this.autoResize === true ) {
194
201
 
202
+ const pixelRatio = renderer.getPixelRatio();
195
203
  const size = renderer.getSize( _size );
196
204
 
197
- this.setSize( size.width, size.height );
205
+ const effectiveWidth = size.width * pixelRatio;
206
+ const effectiveHeight = size.height * pixelRatio;
207
+
208
+ if ( effectiveWidth !== this.renderTarget.width || effectiveHeight !== this.renderTarget.height ) {
209
+
210
+ this.renderTarget.setSize( effectiveWidth, effectiveHeight );
211
+
212
+ this.textureNeedsUpdate = true;
213
+
214
+ }
198
215
 
199
216
  }
200
217
 
@@ -154,10 +154,17 @@ class ReflectorNode extends TextureNode {
154
154
 
155
155
  clone() {
156
156
 
157
- const texture = new this.constructor( this.reflectorNode );
158
- texture._reflectorBaseNode = this._reflectorBaseNode;
159
-
160
- return texture;
157
+ const newNode = new this.constructor( this.reflectorNode );
158
+ newNode.uvNode = this.uvNode;
159
+ newNode.levelNode = this.levelNode;
160
+ newNode.biasNode = this.biasNode;
161
+ newNode.sampler = this.sampler;
162
+ newNode.depthNode = this.depthNode;
163
+ newNode.compareNode = this.compareNode;
164
+ newNode.gradNode = this.gradNode;
165
+ newNode._reflectorBaseNode = this._reflectorBaseNode;
166
+
167
+ return newNode;
161
168
 
162
169
  }
163
170
 
@@ -0,0 +1,81 @@
1
+ import Node from '../core/Node.js';
2
+ import { uv } from '../accessors/UV.js';
3
+ import { nodeObject } from '../tsl/TSLCore.js';
4
+
5
+ /**
6
+ * Class representing a node that samples a value using a provided callback function.
7
+ *
8
+ * @extends Node
9
+ */
10
+ class SampleNode extends Node {
11
+
12
+ /**
13
+ * Returns the type of the node.
14
+ *
15
+ * @type {string}
16
+ * @readonly
17
+ * @static
18
+ */
19
+ static get type() {
20
+
21
+ return 'SampleNode';
22
+
23
+ }
24
+
25
+ /**
26
+ * Creates an instance of SampleNode.
27
+ *
28
+ * @param {Function} callback - The function to be called when sampling. Should accept a UV node and return a value.
29
+ */
30
+ constructor( callback ) {
31
+
32
+ super();
33
+
34
+ this.callback = callback;
35
+
36
+ /**
37
+ * This flag can be used for type testing.
38
+ *
39
+ * @type {boolean}
40
+ * @readonly
41
+ * @default true
42
+ */
43
+ this.isSampleNode = true;
44
+
45
+ }
46
+
47
+ /**
48
+ * Sets up the node by sampling with the default UV accessor.
49
+ *
50
+ * @returns {Node} The result of the callback function when called with the UV node.
51
+ */
52
+ setup() {
53
+
54
+ return this.sample( uv() );
55
+
56
+ }
57
+
58
+ /**
59
+ * Calls the callback function with the provided UV node.
60
+ *
61
+ * @param {Node<vec2>} uv - The UV node or value to be passed to the callback.
62
+ * @returns {Node} The result of the callback function.
63
+ */
64
+ sample( uv ) {
65
+
66
+ return this.callback( uv );
67
+
68
+ }
69
+
70
+ }
71
+
72
+ export default SampleNode;
73
+
74
+ /**
75
+ * Helper function to create a SampleNode wrapped as a node object.
76
+ *
77
+ * @function
78
+ * @param {Function} callback - The function to be called when sampling. Should accept a UV node and return a value.
79
+ * @returns {SampleNode} The created SampleNode instance wrapped as a node object.
80
+ */
81
+ export const sample = ( callback ) => nodeObject( new SampleNode( callback ) );
@@ -0,0 +1,65 @@
1
+ import { add } from '../math/OperatorNode.js';
2
+ import { normalLocal } from '../accessors/Normal.js';
3
+ import { positionLocal } from '../accessors/Position.js';
4
+ import { texture } from '../accessors/TextureNode.js';
5
+ import { float, vec3, Fn } from '../tsl/TSLBase.js';
6
+
7
+ /**
8
+ * TSL function for creating a triplanar textures node.
9
+ *
10
+ * Can be used for triplanar texture mapping.
11
+ *
12
+ * ```js
13
+ * material.colorNode = triplanarTexture( texture( diffuseMap ) );
14
+ * ```
15
+ *
16
+ * @tsl
17
+ * @function
18
+ * @param {Node} textureXNode - First texture node.
19
+ * @param {?Node} [textureYNode=null] - Second texture node. When not set, the shader will sample from `textureXNode` instead.
20
+ * @param {?Node} [textureZNode=null] - Third texture node. When not set, the shader will sample from `textureXNode` instead.
21
+ * @param {?Node<float>} [scaleNode=float(1)] - The scale node.
22
+ * @param {?Node<vec3>} [positionNode=positionLocal] - Vertex positions in local space.
23
+ * @param {?Node<vec3>} [normalNode=normalLocal] - Normals in local space.
24
+ * @returns {Node<vec4>}
25
+ */
26
+ export const triplanarTextures = /*@__PURE__*/ Fn( ( [ textureXNode, textureYNode = null, textureZNode = null, scaleNode = float( 1 ), positionNode = positionLocal, normalNode = normalLocal ] ) => {
27
+
28
+ // Reference: https://github.com/keijiro/StandardTriplanar
29
+
30
+ // Blending factor of triplanar mapping
31
+ let bf = normalNode.abs().normalize();
32
+ bf = bf.div( bf.dot( vec3( 1.0 ) ) );
33
+
34
+ // Triplanar mapping
35
+ const tx = positionNode.yz.mul( scaleNode );
36
+ const ty = positionNode.zx.mul( scaleNode );
37
+ const tz = positionNode.xy.mul( scaleNode );
38
+
39
+ // Base color
40
+ const textureX = textureXNode.value;
41
+ const textureY = textureYNode !== null ? textureYNode.value : textureX;
42
+ const textureZ = textureZNode !== null ? textureZNode.value : textureX;
43
+
44
+ const cx = texture( textureX, tx ).mul( bf.x );
45
+ const cy = texture( textureY, ty ).mul( bf.y );
46
+ const cz = texture( textureZ, tz ).mul( bf.z );
47
+
48
+ return add( cx, cy, cz );
49
+
50
+ } );
51
+
52
+ /**
53
+ * TSL function for creating a triplanar textures node.
54
+ *
55
+ * @tsl
56
+ * @function
57
+ * @param {Node} textureXNode - First texture node.
58
+ * @param {?Node} [textureYNode=null] - Second texture node. When not set, the shader will sample from `textureXNode` instead.
59
+ * @param {?Node} [textureZNode=null] - Third texture node. When not set, the shader will sample from `textureXNode` instead.
60
+ * @param {?Node<float>} [scaleNode=float(1)] - The scale node.
61
+ * @param {?Node<vec3>} [positionNode=positionLocal] - Vertex positions in local space.
62
+ * @param {?Node<vec3>} [normalNode=normalLocal] - Normals in local space.
63
+ * @returns {Node<vec4>}
64
+ */
65
+ export const triplanarTexture = ( ...params ) => triplanarTextures( ...params );
@@ -1251,7 +1251,7 @@ class BatchedMesh extends Mesh {
1251
1251
  const availableInstanceIds = this._availableInstanceIds;
1252
1252
  const instanceInfo = this._instanceInfo;
1253
1253
  availableInstanceIds.sort( ascIdSort );
1254
- while ( availableInstanceIds[ availableInstanceIds.length - 1 ] === instanceInfo.length ) {
1254
+ while ( availableInstanceIds[ availableInstanceIds.length - 1 ] === instanceInfo.length - 1 ) {
1255
1255
 
1256
1256
  instanceInfo.pop();
1257
1257
  availableInstanceIds.pop();
@@ -1529,9 +1529,11 @@ class BatchedMesh extends Mesh {
1529
1529
  _matrix
1530
1530
  .multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse )
1531
1531
  .multiply( this.matrixWorld );
1532
+
1532
1533
  _frustum.setFromProjectionMatrix(
1533
1534
  _matrix,
1534
- renderer.coordinateSystem
1535
+ camera.coordinateSystem,
1536
+ camera.reversedDepth
1535
1537
  );
1536
1538
 
1537
1539
  }
@@ -53,7 +53,7 @@ import { WebGLUtils } from './webgl/WebGLUtils.js';
53
53
  import { WebXRManager } from './webxr/WebXRManager.js';
54
54
  import { WebGLMaterials } from './webgl/WebGLMaterials.js';
55
55
  import { WebGLUniformsGroups } from './webgl/WebGLUniformsGroups.js';
56
- import { createCanvasElement, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, warnOnce } from '../utils.js';
56
+ import { createCanvasElement, probeAsync, warnOnce } from '../utils.js';
57
57
  import { ColorManagement } from '../math/ColorManagement.js';
58
58
 
59
59
  /**
@@ -81,7 +81,7 @@ class WebGLRenderer {
81
81
  preserveDrawingBuffer = false,
82
82
  powerPreference = 'default',
83
83
  failIfMajorPerformanceCaveat = false,
84
- reverseDepthBuffer = false,
84
+ reversedDepthBuffer = false,
85
85
  multiviewStereo = false,
86
86
  } = parameters;
87
87
 
@@ -315,7 +315,6 @@ class WebGLRenderer {
315
315
 
316
316
  // camera matrices cache
317
317
 
318
- const _currentProjectionMatrix = new Matrix4();
319
318
  const _projScreenMatrix = new Matrix4();
320
319
 
321
320
  const _vector3 = new Vector3();
@@ -412,7 +411,7 @@ class WebGLRenderer {
412
411
 
413
412
  state = new WebGLState( _gl, extensions );
414
413
 
415
- if ( capabilities.reverseDepthBuffer && reverseDepthBuffer ) {
414
+ if ( capabilities.reversedDepthBuffer && reversedDepthBuffer ) {
416
415
 
417
416
  state.buffers.depth.setReversed( true );
418
417
 
@@ -1561,7 +1560,7 @@ class WebGLRenderer {
1561
1560
  renderStateStack.push( currentRenderState );
1562
1561
 
1563
1562
  _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
1564
- _frustum.setFromProjectionMatrix( _projScreenMatrix );
1563
+ _frustum.setFromProjectionMatrix( _projScreenMatrix, WebGLCoordinateSystem, camera.reversedDepth );
1565
1564
 
1566
1565
  _localClippingEnabled = this.localClippingEnabled;
1567
1566
  _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled );
@@ -1904,6 +1903,9 @@ class WebGLRenderer {
1904
1903
  //
1905
1904
 
1906
1905
  const currentRenderTarget = _this.getRenderTarget();
1906
+ const currentActiveCubeFace = _this.getActiveCubeFace();
1907
+ const currentActiveMipmapLevel = _this.getActiveMipmapLevel();
1908
+
1907
1909
  _this.setRenderTarget( transmissionRenderTarget );
1908
1910
 
1909
1911
  _this.getClearColor( _currentClearColor );
@@ -1973,7 +1975,7 @@ class WebGLRenderer {
1973
1975
 
1974
1976
  }
1975
1977
 
1976
- _this.setRenderTarget( currentRenderTarget );
1978
+ _this.setRenderTarget( currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel );
1977
1979
 
1978
1980
  _this.setClearColor( _currentClearColor, _currentClearAlpha );
1979
1981
 
@@ -2405,23 +2407,17 @@ class WebGLRenderer {
2405
2407
 
2406
2408
  } else {
2407
2409
 
2408
- const reverseDepthBuffer = state.buffers.depth.getReversed();
2409
-
2410
- if ( reverseDepthBuffer ) {
2410
+ const reversedDepthBuffer = state.buffers.depth.getReversed();
2411
2411
 
2412
- _currentProjectionMatrix.copy( camera.projectionMatrix );
2412
+ if ( reversedDepthBuffer && camera.reversedDepth !== true ) {
2413
2413
 
2414
- toNormalizedProjectionMatrix( _currentProjectionMatrix );
2415
- toReversedProjectionMatrix( _currentProjectionMatrix );
2416
-
2417
- p_uniforms.setValue( _gl, 'projectionMatrix', _currentProjectionMatrix );
2418
-
2419
- } else {
2420
-
2421
- p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
2414
+ camera._reversedDepth = true;
2415
+ camera.updateProjectionMatrix();
2422
2416
 
2423
2417
  }
2424
2418
 
2419
+ p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
2420
+
2425
2421
  p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
2426
2422
 
2427
2423
  }
@@ -2887,9 +2883,15 @@ class WebGLRenderer {
2887
2883
 
2888
2884
  } else if ( isRenderTarget3D ) {
2889
2885
 
2890
- const textureProperties = properties.get( renderTarget.texture );
2891
2886
  const layer = activeCubeFace;
2892
- _gl.framebufferTextureLayer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, activeMipmapLevel, layer );
2887
+
2888
+ for ( let i = 0; i < renderTarget.textures.length; i ++ ) {
2889
+
2890
+ const textureProperties = properties.get( renderTarget.textures[ i ] );
2891
+
2892
+ _gl.framebufferTextureLayer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, textureProperties.__webglTexture, activeMipmapLevel, layer );
2893
+
2894
+ }
2893
2895
 
2894
2896
  } else if ( renderTarget !== null && activeMipmapLevel !== 0 ) {
2895
2897
 
@@ -2961,7 +2963,7 @@ class WebGLRenderer {
2961
2963
 
2962
2964
  if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
2963
2965
 
2964
- // when using MRT, select the corect color buffer for the subsequent read command
2966
+ // when using MRT, select the correct color buffer for the subsequent read command
2965
2967
 
2966
2968
  if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
2967
2969
 
@@ -3041,7 +3043,7 @@ class WebGLRenderer {
3041
3043
  _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
3042
3044
  _gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );
3043
3045
 
3044
- // when using MRT, select the corect color buffer for the subsequent read command
3046
+ // when using MRT, select the correct color buffer for the subsequent read command
3045
3047
 
3046
3048
  if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
3047
3049
 
@@ -3506,7 +3508,7 @@ class WebGLRenderer {
3506
3508
  * @property {boolean} [depth=true] Whether the drawing buffer has a depth buffer of at least 16 bits.
3507
3509
  * @property {boolean} [logarithmicDepthBuffer=false] Whether to use a logarithmic depth buffer. It may be necessary to use this if dealing with huge differences in scale in a single scene.
3508
3510
  * Note that this setting uses `gl_FragDepth` if available which disables the Early Fragment Test optimization and can cause a decrease in performance.
3509
- * @property {boolean} [reverseDepthBuffer=false] Whether to use a reverse depth buffer. Requires the `EXT_clip_control` extension.
3511
+ * @property {boolean} [reversedDepthBuffer=false] Whether to use a reverse depth buffer. Requires the `EXT_clip_control` extension.
3510
3512
  * This is a more faster and accurate version than logarithmic depth buffer.
3511
3513
  **/
3512
3514
 
@@ -3527,7 +3529,7 @@ class WebGLRenderer {
3527
3529
  * @property {number} maxVertexTextures - The number of textures that can be used in a vertex shader.
3528
3530
  * @property {number} maxVertexUniforms - The maximum number of uniforms that can be used in a vertex shader.
3529
3531
  * @property {string} precision - The shader precision currently being used by the renderer.
3530
- * @property {boolean} reverseDepthBuffer - `true` if `reverseDepthBuffer` was set to `true` in the constructor
3532
+ * @property {boolean} reversedDepthBuffer - `true` if `reversedDepthBuffer` was set to `true` in the constructor
3531
3533
  * and the rendering context supports `EXT_clip_control`.
3532
3534
  * @property {boolean} vertexTextures - `true` if vertex textures can be used.
3533
3535
  **/
@@ -1,6 +1,6 @@
1
1
  import DataMap from './DataMap.js';
2
2
  import Color4 from './Color4.js';
3
- import { vec4, context, normalWorld, backgroundBlurriness, backgroundIntensity, backgroundRotation, modelViewProjection } from '../../nodes/TSL.js';
3
+ import { vec4, context, normalWorldGeometry, backgroundBlurriness, backgroundIntensity, backgroundRotation, modelViewProjection } from '../../nodes/TSL.js';
4
4
  import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
5
5
 
6
6
  import { Mesh } from '../../objects/Mesh.js';
@@ -89,7 +89,7 @@ class Background extends DataMap {
89
89
 
90
90
  const backgroundMeshNode = context( vec4( backgroundNode ).mul( backgroundIntensity ), {
91
91
  // @TODO: Add Texture2D support using node context
92
- getUV: () => backgroundRotation.mul( normalWorld ),
92
+ getUV: () => backgroundRotation.mul( normalWorldGeometry ),
93
93
  getTextureLevel: () => backgroundBlurriness
94
94
  } );
95
95
 
@@ -244,24 +244,31 @@ class Bindings extends DataMap {
244
244
 
245
245
  }
246
246
 
247
- } else if ( binding.isSampler ) {
248
-
249
- binding.update();
250
-
251
247
  } else if ( binding.isSampledTexture ) {
252
248
 
253
- const texturesTextureData = this.textures.get( binding.texture );
254
-
255
- if ( binding.needsBindingsUpdate( texturesTextureData.generation ) ) needsBindingsUpdate = true;
256
-
257
249
  const updated = binding.update();
258
250
 
251
+ // get the texture data after the update, to sync the texture reference from node
252
+
259
253
  const texture = binding.texture;
254
+ const texturesTextureData = this.textures.get( texture );
260
255
 
261
256
  if ( updated ) {
262
257
 
258
+ // version: update the texture data or create a new one
259
+
263
260
  this.textures.updateTexture( texture );
264
261
 
262
+ // generation: update the bindings if a new texture has been created
263
+
264
+ if ( binding.generation !== texturesTextureData.generation ) {
265
+
266
+ binding.generation = texturesTextureData.generation;
267
+
268
+ needsBindingsUpdate = true;
269
+
270
+ }
271
+
265
272
  }
266
273
 
267
274
  const textureData = backend.get( texture );
@@ -277,16 +284,6 @@ class Bindings extends DataMap {
277
284
 
278
285
  }
279
286
 
280
- if ( backend.isWebGPUBackend === true && textureData.texture === undefined && textureData.externalTexture === undefined ) {
281
-
282
- // TODO: Remove this once we found why updated === false isn't bound to a texture in the WebGPU backend
283
- console.error( 'Bindings._update: binding should be available:', binding, updated, texture, binding.textureNode.value, needsBindingsUpdate );
284
-
285
- this.textures.updateTexture( texture );
286
- needsBindingsUpdate = true;
287
-
288
- }
289
-
290
287
  if ( texture.isStorageTexture === true ) {
291
288
 
292
289
  const textureData = this.get( texture );
@@ -305,6 +302,10 @@ class Bindings extends DataMap {
305
302
 
306
303
  }
307
304
 
305
+ } else if ( binding.isSampler ) {
306
+
307
+ binding.update();
308
+
308
309
  }
309
310
 
310
311
  }
@@ -34,8 +34,8 @@ class Color4 extends Color {
34
34
  * string argument to this method.
35
35
  *
36
36
  * @param {number|string|Color} r - The red value.
37
- * @param {number} g - The green value.
38
- * @param {number} b - The blue value.
37
+ * @param {number} [g] - The green value.
38
+ * @param {number} [b] - The blue value.
39
39
  * @param {number} [a=1] - The alpha value.
40
40
  * @return {Color4} A reference to this object.
41
41
  */
@@ -1,4 +1,4 @@
1
- import { equirectUV } from '../../nodes/utils/EquirectUVNode.js';
1
+ import { equirectUV } from '../../nodes/utils/EquirectUV.js';
2
2
  import { texture as TSL_Texture } from '../../nodes/accessors/TextureNode.js';
3
3
  import { positionWorldDirection } from '../../nodes/accessors/Position.js';
4
4
  import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
@@ -1,6 +1,7 @@
1
1
  import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
2
+ import { ColorManagement } from '../../math/ColorManagement.js';
2
3
  import { vec4, renderOutput } from '../../nodes/TSL.js';
3
- import { LinearSRGBColorSpace, NoToneMapping } from '../../constants.js';
4
+ import { NoToneMapping } from '../../constants.js';
4
5
  import QuadMesh from '../../renderers/common/QuadMesh.js';
5
6
 
6
7
  /**
@@ -82,6 +83,15 @@ class PostProcessing {
82
83
  */
83
84
  this._quadMesh = new QuadMesh( material );
84
85
 
86
+ /**
87
+ * The context of the post processing stack.
88
+ *
89
+ * @private
90
+ * @type {?Object}
91
+ * @default null
92
+ */
93
+ this._context = null;
94
+
85
95
  }
86
96
 
87
97
  /**
@@ -91,15 +101,17 @@ class PostProcessing {
91
101
  */
92
102
  render() {
93
103
 
104
+ const renderer = this.renderer;
105
+
94
106
  this._update();
95
107
 
96
- const renderer = this.renderer;
108
+ if ( this._context.onBeforePostProcessing !== null ) this._context.onBeforePostProcessing();
97
109
 
98
110
  const toneMapping = renderer.toneMapping;
99
111
  const outputColorSpace = renderer.outputColorSpace;
100
112
 
101
113
  renderer.toneMapping = NoToneMapping;
102
- renderer.outputColorSpace = LinearSRGBColorSpace;
114
+ renderer.outputColorSpace = ColorManagement.workingColorSpace;
103
115
 
104
116
  //
105
117
 
@@ -115,6 +127,20 @@ class PostProcessing {
115
127
  renderer.toneMapping = toneMapping;
116
128
  renderer.outputColorSpace = outputColorSpace;
117
129
 
130
+ if ( this._context.onAfterPostProcessing !== null ) this._context.onAfterPostProcessing();
131
+
132
+ }
133
+
134
+ /**
135
+ * Returns the current context of the post processing stack.
136
+ *
137
+ * @readonly
138
+ * @type {?Object}
139
+ */
140
+ get context() {
141
+
142
+ return this._context;
143
+
118
144
  }
119
145
 
120
146
  /**
@@ -140,7 +166,32 @@ class PostProcessing {
140
166
  const toneMapping = renderer.toneMapping;
141
167
  const outputColorSpace = renderer.outputColorSpace;
142
168
 
143
- this._quadMesh.material.fragmentNode = this.outputColorTransform === true ? renderOutput( this.outputNode, toneMapping, outputColorSpace ) : this.outputNode.context( { toneMapping, outputColorSpace } );
169
+ const context = {
170
+ postProcessing: this,
171
+ onBeforePostProcessing: null,
172
+ onAfterPostProcessing: null
173
+ };
174
+
175
+ let outputNode = this.outputNode;
176
+
177
+ if ( this.outputColorTransform === true ) {
178
+
179
+ outputNode = outputNode.context( context );
180
+
181
+ outputNode = renderOutput( outputNode, toneMapping, outputColorSpace );
182
+
183
+ } else {
184
+
185
+ context.toneMapping = toneMapping;
186
+ context.outputColorSpace = outputColorSpace;
187
+
188
+ outputNode = outputNode.context( context );
189
+
190
+ }
191
+
192
+ this._context = context;
193
+
194
+ this._quadMesh.material.fragmentNode = outputNode;
144
195
  this._quadMesh.material.needsUpdate = true;
145
196
 
146
197
  this.needsUpdate = false;
@@ -161,13 +212,15 @@ class PostProcessing {
161
212
 
162
213
  this._update();
163
214
 
215
+ if ( this._context.onBeforePostProcessing !== null ) this._context.onBeforePostProcessing();
216
+
164
217
  const renderer = this.renderer;
165
218
 
166
219
  const toneMapping = renderer.toneMapping;
167
220
  const outputColorSpace = renderer.outputColorSpace;
168
221
 
169
222
  renderer.toneMapping = NoToneMapping;
170
- renderer.outputColorSpace = LinearSRGBColorSpace;
223
+ renderer.outputColorSpace = ColorManagement.workingColorSpace;
171
224
 
172
225
  //
173
226
 
@@ -183,6 +236,8 @@ class PostProcessing {
183
236
  renderer.toneMapping = toneMapping;
184
237
  renderer.outputColorSpace = outputColorSpace;
185
238
 
239
+ if ( this._context.onAfterPostProcessing !== null ) this._context.onAfterPostProcessing();
240
+
186
241
  }
187
242
 
188
243
  }