super-three 0.162.0 → 0.164.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 (187) hide show
  1. package/build/three.cjs +847 -1226
  2. package/build/three.module.js +846 -1225
  3. package/build/three.module.min.js +2 -2
  4. package/examples/jsm/animation/CCDIKSolver.js +4 -2
  5. package/examples/jsm/controls/TransformControls.js +3 -3
  6. package/examples/jsm/exporters/GLTFExporter.js +66 -5
  7. package/examples/jsm/exporters/USDZExporter.js +22 -1
  8. package/examples/jsm/geometries/TextGeometry.js +10 -2
  9. package/examples/jsm/interactive/HTMLMesh.js +7 -9
  10. package/examples/jsm/libs/draco/README.md +2 -2
  11. package/examples/jsm/libs/fflate.module.js +694 -496
  12. package/examples/jsm/lines/LineMaterial.js +0 -2
  13. package/examples/jsm/loaders/3MFLoader.js +2 -0
  14. package/examples/jsm/loaders/EXRLoader.js +351 -97
  15. package/examples/jsm/loaders/FBXLoader.js +1 -1
  16. package/examples/jsm/loaders/GLTFLoader.js +59 -0
  17. package/examples/jsm/loaders/KTX2Loader.js +3 -10
  18. package/examples/jsm/loaders/LUT3dlLoader.js +0 -15
  19. package/examples/jsm/loaders/LUTCubeLoader.js +0 -14
  20. package/examples/jsm/loaders/LUTImageLoader.js +0 -14
  21. package/examples/jsm/loaders/RGBMLoader.js +16 -0
  22. package/examples/jsm/loaders/VRMLLoader.js +1 -1
  23. package/examples/jsm/loaders/lwo/IFFParser.js +8 -5
  24. package/examples/jsm/materials/MeshGouraudMaterial.js +7 -1
  25. package/examples/jsm/math/Octree.js +26 -20
  26. package/examples/jsm/misc/GPUComputationRenderer.js +0 -6
  27. package/examples/jsm/nodes/Nodes.js +10 -4
  28. package/examples/jsm/nodes/accessors/AccessorsUtils.js +16 -1
  29. package/examples/jsm/nodes/accessors/BatchNode.js +78 -0
  30. package/examples/jsm/nodes/accessors/ClippingNode.js +3 -2
  31. package/examples/jsm/nodes/accessors/InstanceNode.js +25 -2
  32. package/examples/jsm/nodes/accessors/MaterialNode.js +107 -3
  33. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +1 -1
  34. package/examples/jsm/nodes/accessors/MorphNode.js +13 -3
  35. package/examples/jsm/nodes/accessors/NormalNode.js +12 -2
  36. package/examples/jsm/nodes/accessors/ReferenceNode.js +1 -1
  37. package/examples/jsm/nodes/accessors/RendererReferenceNode.js +29 -0
  38. package/examples/jsm/nodes/accessors/StorageBufferNode.js +9 -0
  39. package/examples/jsm/nodes/accessors/TextureNode.js +51 -10
  40. package/examples/jsm/nodes/accessors/TextureSizeNode.js +1 -1
  41. package/examples/jsm/nodes/code/FunctionNode.js +0 -8
  42. package/examples/jsm/nodes/core/Node.js +63 -4
  43. package/examples/jsm/nodes/core/NodeBuilder.js +26 -25
  44. package/examples/jsm/nodes/core/NodeFrame.js +10 -10
  45. package/examples/jsm/nodes/core/NodeUtils.js +2 -2
  46. package/examples/jsm/nodes/core/OutputStructNode.js +2 -1
  47. package/examples/jsm/nodes/core/PropertyNode.js +10 -0
  48. package/examples/jsm/nodes/core/UniformNode.js +20 -0
  49. package/examples/jsm/nodes/display/BumpMapNode.js +7 -26
  50. package/examples/jsm/nodes/display/FrontFacingNode.js +13 -0
  51. package/examples/jsm/nodes/display/PassNode.js +17 -1
  52. package/examples/jsm/nodes/display/ToneMappingNode.js +8 -4
  53. package/examples/jsm/nodes/display/ViewportDepthNode.js +1 -1
  54. package/examples/jsm/nodes/display/ViewportNode.js +4 -2
  55. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +6 -0
  56. package/examples/jsm/nodes/display/ViewportTextureNode.js +4 -1
  57. package/examples/jsm/nodes/fog/FogExp2Node.js +4 -5
  58. package/examples/jsm/nodes/fog/FogNode.js +13 -3
  59. package/examples/jsm/nodes/fog/FogRangeNode.js +4 -3
  60. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +26 -7
  61. package/examples/jsm/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
  62. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +1 -3
  63. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
  64. package/examples/jsm/nodes/functions/PhongLightingModel.js +1 -1
  65. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +164 -10
  66. package/examples/jsm/nodes/functions/ShadowMaskModel.js +31 -0
  67. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +19 -5
  68. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +2 -1
  69. package/examples/jsm/nodes/lighting/EnvironmentNode.js +22 -70
  70. package/examples/jsm/nodes/lighting/IrradianceNode.js +24 -0
  71. package/examples/jsm/nodes/lighting/LightsNode.js +11 -1
  72. package/examples/jsm/nodes/lighting/PointLightNode.js +2 -1
  73. package/examples/jsm/nodes/lighting/SpotLightNode.js +2 -1
  74. package/examples/jsm/nodes/materials/Line2NodeMaterial.js +10 -6
  75. package/examples/jsm/nodes/materials/Materials.js +1 -0
  76. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -2
  77. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
  78. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +76 -5
  79. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +11 -4
  80. package/examples/jsm/nodes/materials/NodeMaterial.js +55 -43
  81. package/examples/jsm/nodes/materials/ShadowNodeMaterial.js +34 -0
  82. package/examples/jsm/nodes/pmrem/PMREMNode.js +193 -0
  83. package/examples/jsm/nodes/pmrem/PMREMUtils.js +288 -0
  84. package/examples/jsm/nodes/shadernode/ShaderNode.js +3 -9
  85. package/examples/jsm/nodes/utils/EquirectUVNode.js +1 -1
  86. package/examples/jsm/objects/QuadMesh.js +7 -23
  87. package/examples/jsm/physics/JoltPhysics.js +281 -0
  88. package/examples/jsm/physics/RapierPhysics.js +4 -4
  89. package/examples/jsm/postprocessing/GlitchPass.js +0 -3
  90. package/examples/jsm/postprocessing/LUTPass.js +5 -71
  91. package/examples/jsm/postprocessing/RenderTransitionPass.js +193 -0
  92. package/examples/jsm/postprocessing/SAOPass.js +0 -1
  93. package/examples/jsm/postprocessing/SSAOPass.js +0 -3
  94. package/examples/jsm/renderers/common/Animation.js +3 -0
  95. package/examples/jsm/renderers/common/Background.js +8 -8
  96. package/examples/jsm/renderers/common/ClippingContext.js +1 -1
  97. package/examples/jsm/renderers/common/Info.js +11 -19
  98. package/examples/jsm/renderers/common/PostProcessing.js +12 -4
  99. package/examples/jsm/renderers/common/RenderContext.js +1 -1
  100. package/examples/jsm/renderers/common/RenderList.js +1 -1
  101. package/examples/jsm/renderers/common/RenderObject.js +47 -5
  102. package/examples/jsm/renderers/common/RenderObjects.js +1 -1
  103. package/examples/jsm/renderers/common/Renderer.js +153 -21
  104. package/examples/jsm/renderers/common/Textures.js +1 -1
  105. package/examples/jsm/renderers/common/extras/PMREMGenerator.js +773 -0
  106. package/examples/jsm/renderers/common/nodes/Nodes.js +34 -63
  107. package/examples/jsm/renderers/webgl/WebGLBackend.js +146 -36
  108. package/examples/jsm/renderers/webgl/WebGLBufferRenderer.js +145 -0
  109. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +9 -3
  110. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +1 -1
  111. package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +1 -0
  112. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +64 -7
  113. package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +6 -23
  114. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +77 -60
  115. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +21 -4
  116. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +29 -1
  117. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +18 -4
  118. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +92 -18
  119. package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
  120. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  121. package/examples/jsm/utils/GPUStatsPanel.js +10 -45
  122. package/examples/jsm/utils/SceneUtils.js +60 -1
  123. package/examples/jsm/utils/TextureUtils.js +1 -1
  124. package/examples/jsm/webxr/OculusHandModel.js +3 -2
  125. package/examples/jsm/webxr/XRHandModelFactory.js +4 -2
  126. package/package.json +1 -1
  127. package/src/Three.js +0 -1
  128. package/src/animation/AnimationClip.js +1 -1
  129. package/src/constants.js +3 -3
  130. package/src/core/Object3D.js +10 -7
  131. package/src/core/RenderTarget.js +8 -0
  132. package/src/extras/PMREMGenerator.js +21 -11
  133. package/src/loaders/FileLoader.js +1 -1
  134. package/src/loaders/MaterialLoader.js +1 -0
  135. package/src/loaders/ObjectLoader.js +2 -0
  136. package/src/materials/Material.js +2 -0
  137. package/src/materials/MeshPhysicalMaterial.js +20 -0
  138. package/src/materials/ShaderMaterial.js +0 -4
  139. package/src/math/Spherical.js +4 -5
  140. package/src/objects/BatchedMesh.js +27 -3
  141. package/src/objects/InstancedMesh.js +10 -0
  142. package/src/objects/Line.js +66 -43
  143. package/src/renderers/WebGLRenderer.js +130 -158
  144. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
  145. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -0
  146. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +2 -2
  147. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
  148. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +2 -10
  149. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +2 -16
  150. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +32 -22
  151. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +17 -9
  152. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  153. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +47 -13
  154. package/src/renderers/shaders/ShaderChunk.js +0 -2
  155. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
  156. package/src/renderers/shaders/ShaderLib.js +2 -1
  157. package/src/renderers/shaders/UniformsUtils.js +10 -1
  158. package/src/renderers/webgl/WebGLAttributes.js +6 -33
  159. package/src/renderers/webgl/WebGLBackground.js +18 -3
  160. package/src/renderers/webgl/WebGLBindingStates.js +14 -51
  161. package/src/renderers/webgl/WebGLBufferRenderer.js +35 -21
  162. package/src/renderers/webgl/WebGLCapabilities.js +35 -13
  163. package/src/renderers/webgl/WebGLCubeUVMaps.js +10 -6
  164. package/src/renderers/webgl/WebGLExtensions.js +4 -19
  165. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +35 -21
  166. package/src/renderers/webgl/WebGLLights.js +6 -32
  167. package/src/renderers/webgl/WebGLMaterials.js +8 -3
  168. package/src/renderers/webgl/WebGLMorphtargets.js +79 -217
  169. package/src/renderers/webgl/WebGLProgram.js +21 -52
  170. package/src/renderers/webgl/WebGLPrograms.js +24 -31
  171. package/src/renderers/webgl/WebGLRenderStates.js +13 -7
  172. package/src/renderers/webgl/WebGLShadowMap.js +25 -25
  173. package/src/renderers/webgl/WebGLState.js +15 -59
  174. package/src/renderers/webgl/WebGLTextures.js +138 -292
  175. package/src/renderers/webgl/WebGLUniformsGroups.js +1 -1
  176. package/src/renderers/webgl/WebGLUtils.js +9 -78
  177. package/src/renderers/webxr/WebXRDepthSensing.js +2 -3
  178. package/src/renderers/webxr/WebXRManager.js +4 -6
  179. package/src/scenes/Scene.js +7 -1
  180. package/src/textures/Texture.js +11 -1
  181. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -37
  182. package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +0 -320
  183. package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +0 -26
  184. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +0 -794
  185. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +0 -51
  186. package/src/renderers/WebGL1Renderer.js +0 -7
  187. package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +0 -10
@@ -273,40 +273,50 @@ export default /* glsl */`
273
273
 
274
274
  float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
275
275
 
276
- vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );
276
+ float shadow = 1.0;
277
277
 
278
278
  // for point lights, the uniform @vShadowCoord is re-purposed to hold
279
279
  // the vector from the light to the world-space position of the fragment.
280
280
  vec3 lightToPosition = shadowCoord.xyz;
281
+
282
+ float lightToPositionLength = length( lightToPosition );
281
283
 
282
- // dp = normalized distance from light to fragment position
283
- float dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); // need to clamp?
284
- dp += shadowBias;
284
+ if ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {
285
285
 
286
- // bd3D = base direction 3D
287
- vec3 bd3D = normalize( lightToPosition );
286
+ // dp = normalized distance from light to fragment position
287
+ float dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); // need to clamp?
288
+ dp += shadowBias;
288
289
 
289
- #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )
290
+ // bd3D = base direction 3D
291
+ vec3 bd3D = normalize( lightToPosition );
290
292
 
291
- vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;
293
+ vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );
292
294
 
293
- return (
294
- texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +
295
- texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +
296
- texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +
297
- texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +
298
- texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +
299
- texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +
300
- texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +
301
- texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +
302
- texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )
303
- ) * ( 1.0 / 9.0 );
295
+ #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )
304
296
 
305
- #else // no percentage-closer filtering
297
+ vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;
306
298
 
307
- return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );
299
+ shadow = (
300
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +
301
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +
302
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +
303
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +
304
+ texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +
305
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +
306
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +
307
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +
308
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )
309
+ ) * ( 1.0 / 9.0 );
308
310
 
309
- #endif
311
+ #else // no percentage-closer filtering
312
+
313
+ shadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );
314
+
315
+ #endif
316
+
317
+ }
318
+
319
+ return shadow;
310
320
 
311
321
  }
312
322
 
@@ -168,24 +168,32 @@ vec3 AgXToneMapping( vec3 color ) {
168
168
  // https://modelviewer.dev/examples/tone-mapping
169
169
 
170
170
  vec3 NeutralToneMapping( vec3 color ) {
171
- float startCompression = 0.8 - 0.04;
172
- float desaturation = 0.15;
171
+
172
+ const float StartCompression = 0.8 - 0.04;
173
+ const float Desaturation = 0.15;
173
174
 
174
175
  color *= toneMappingExposure;
175
176
 
176
- float x = min(color.r, min(color.g, color.b));
177
+ float x = min( color.r, min( color.g, color.b ) );
178
+
177
179
  float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
180
+
178
181
  color -= offset;
179
182
 
180
- float peak = max(color.r, max(color.g, color.b));
181
- if (peak < startCompression) return color;
183
+ float peak = max( color.r, max( color.g, color.b ) );
184
+
185
+ if ( peak < StartCompression ) return color;
186
+
187
+ float d = 1. - StartCompression;
188
+
189
+ float newPeak = 1. - d * d / ( peak + d - StartCompression );
182
190
 
183
- float d = 1. - startCompression;
184
- float newPeak = 1. - d * d / (peak + d - startCompression);
185
191
  color *= newPeak / peak;
186
192
 
187
- float g = 1. - 1. / (desaturation * (peak - newPeak) + 1.);
188
- return mix(color, vec3(1, 1, 1), g);
193
+ float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );
194
+
195
+ return mix( color, vec3( newPeak ), g );
196
+
189
197
  }
190
198
 
191
199
  vec3 CustomToneMapping( vec3 color ) { return color; }
@@ -25,7 +25,7 @@ export default /* glsl */`
25
25
 
26
26
  vec4 transmitted = getIBLVolumeRefraction(
27
27
  n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,
28
- pos, modelMatrix, viewMatrix, projectionMatrix, material.ior, material.thickness,
28
+ pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,
29
29
  material.attenuationColor, material.attenuationDistance );
30
30
 
31
31
  material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );
@@ -169,22 +169,56 @@ export default /* glsl */`
169
169
 
170
170
  vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,
171
171
  const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,
172
- const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness,
172
+ const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,
173
173
  const in vec3 attenuationColor, const in float attenuationDistance ) {
174
174
 
175
- vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
176
- vec3 refractedRayExit = position + transmissionRay;
175
+ vec4 transmittedLight;
176
+ vec3 transmittance;
177
+
178
+ #ifdef USE_DISPERSION
179
+
180
+ float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;
181
+ vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );
182
+
183
+ for ( int i = 0; i < 3; i ++ ) {
184
+
185
+ vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );
186
+ vec3 refractedRayExit = position + transmissionRay;
187
+
188
+ // Project refracted vector on the framebuffer, while mapping to normalized device coordinates.
189
+ vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
190
+ vec2 refractionCoords = ndcPos.xy / ndcPos.w;
191
+ refractionCoords += 1.0;
192
+ refractionCoords /= 2.0;
193
+
194
+ // Sample framebuffer to get pixel the refracted ray hits.
195
+ vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );
196
+ transmittedLight[ i ] = transmissionSample[ i ];
197
+ transmittedLight.a += transmissionSample.a;
198
+
199
+ transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];
200
+
201
+ }
202
+
203
+ transmittedLight.a /= 3.0;
204
+
205
+ #else
206
+
207
+ vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
208
+ vec3 refractedRayExit = position + transmissionRay;
209
+
210
+ // Project refracted vector on the framebuffer, while mapping to normalized device coordinates.
211
+ vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
212
+ vec2 refractionCoords = ndcPos.xy / ndcPos.w;
213
+ refractionCoords += 1.0;
214
+ refractionCoords /= 2.0;
215
+
216
+ // Sample framebuffer to get pixel the refracted ray hits.
217
+ transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
218
+ transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );
219
+
220
+ #endif
177
221
 
178
- // Project refracted vector on the framebuffer, while mapping to normalized device coordinates.
179
- vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
180
- vec2 refractionCoords = ndcPos.xy / ndcPos.w;
181
- refractionCoords += 1.0;
182
- refractionCoords /= 2.0;
183
-
184
- // Sample framebuffer to get pixel the refracted ray hits.
185
- vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
186
-
187
- vec3 transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );
188
222
  vec3 attenuatedColor = transmittance * transmittedLight.rgb;
189
223
 
190
224
  // Get the specular component.
@@ -40,7 +40,6 @@ import fog_pars_vertex from './ShaderChunk/fog_pars_vertex.glsl.js';
40
40
  import fog_fragment from './ShaderChunk/fog_fragment.glsl.js';
41
41
  import fog_pars_fragment from './ShaderChunk/fog_pars_fragment.glsl.js';
42
42
  import gradientmap_pars_fragment from './ShaderChunk/gradientmap_pars_fragment.glsl.js';
43
- import lightmap_fragment from './ShaderChunk/lightmap_fragment.glsl.js';
44
43
  import lightmap_pars_fragment from './ShaderChunk/lightmap_pars_fragment.glsl.js';
45
44
  import lights_lambert_fragment from './ShaderChunk/lights_lambert_fragment.glsl.js';
46
45
  import lights_lambert_pars_fragment from './ShaderChunk/lights_lambert_pars_fragment.glsl.js';
@@ -169,7 +168,6 @@ export const ShaderChunk = {
169
168
  fog_fragment: fog_fragment,
170
169
  fog_pars_fragment: fog_pars_fragment,
171
170
  gradientmap_pars_fragment: gradientmap_pars_fragment,
172
- lightmap_fragment: lightmap_fragment,
173
171
  lightmap_pars_fragment: lightmap_pars_fragment,
174
172
  lights_lambert_fragment: lights_lambert_fragment,
175
173
  lights_lambert_pars_fragment: lights_lambert_pars_fragment,
@@ -95,6 +95,10 @@ uniform float opacity;
95
95
  uniform float clearcoatRoughness;
96
96
  #endif
97
97
 
98
+ #ifdef USE_DISPERSION
99
+ uniform float dispersion;
100
+ #endif
101
+
98
102
  #ifdef USE_IRIDESCENCE
99
103
  uniform float iridescence;
100
104
  uniform float iridescenceIOR;
@@ -93,7 +93,7 @@ const ShaderLib = {
93
93
  emissive: { value: /*@__PURE__*/ new Color( 0x000000 ) },
94
94
  roughness: { value: 1.0 },
95
95
  metalness: { value: 0.0 },
96
- envMapIntensity: { value: 1 } // temporary
96
+ envMapIntensity: { value: 1 }
97
97
  }
98
98
  ] ),
99
99
 
@@ -314,6 +314,7 @@ ShaderLib.physical = {
314
314
  clearcoatRoughness: { value: 0 },
315
315
  clearcoatRoughnessMap: { value: null },
316
316
  clearcoatRoughnessMapTransform: { value: /*@__PURE__*/ new Matrix3() },
317
+ dispersion: { value: 0 },
317
318
  iridescence: { value: 0 },
318
319
  iridescenceMap: { value: null },
319
320
  iridescenceMapTransform: { value: /*@__PURE__*/ new Matrix3() },
@@ -86,13 +86,22 @@ export function cloneUniformsGroups( src ) {
86
86
 
87
87
  export function getUnlitUniformColorSpace( renderer ) {
88
88
 
89
- if ( renderer.getRenderTarget() === null ) {
89
+ const currentRenderTarget = renderer.getRenderTarget();
90
+
91
+ if ( currentRenderTarget === null ) {
90
92
 
91
93
  // https://github.com/mrdoob/three.js/pull/23937#issuecomment-1111067398
92
94
  return renderer.outputColorSpace;
93
95
 
94
96
  }
95
97
 
98
+ // https://github.com/mrdoob/three.js/issues/27868
99
+ if ( currentRenderTarget.isXRRenderTarget === true ) {
100
+
101
+ return currentRenderTarget.texture.colorSpace;
102
+
103
+ }
104
+
96
105
  return ColorManagement.workingColorSpace;
97
106
 
98
107
  }
@@ -1,6 +1,4 @@
1
- function WebGLAttributes( gl, capabilities ) {
2
-
3
- const isWebGL2 = capabilities.isWebGL2;
1
+ function WebGLAttributes( gl ) {
4
2
 
5
3
  const buffers = new WeakMap();
6
4
 
@@ -27,15 +25,7 @@ function WebGLAttributes( gl, capabilities ) {
27
25
 
28
26
  if ( attribute.isFloat16BufferAttribute ) {
29
27
 
30
- if ( isWebGL2 ) {
31
-
32
- type = gl.HALF_FLOAT;
33
-
34
- } else {
35
-
36
- throw new Error( 'THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.' );
37
-
38
- }
28
+ type = gl.HALF_FLOAT;
39
29
 
40
30
  } else {
41
31
 
@@ -103,17 +93,9 @@ function WebGLAttributes( gl, capabilities ) {
103
93
  for ( let i = 0, l = updateRanges.length; i < l; i ++ ) {
104
94
 
105
95
  const range = updateRanges[ i ];
106
- if ( isWebGL2 ) {
107
-
108
- gl.bufferSubData( bufferType, range.start * array.BYTES_PER_ELEMENT,
109
- array, range.start, range.count );
110
-
111
- } else {
112
96
 
113
- gl.bufferSubData( bufferType, range.start * array.BYTES_PER_ELEMENT,
114
- array.subarray( range.start, range.start + range.count ) );
115
-
116
- }
97
+ gl.bufferSubData( bufferType, range.start * array.BYTES_PER_ELEMENT,
98
+ array, range.start, range.count );
117
99
 
118
100
  }
119
101
 
@@ -124,17 +106,8 @@ function WebGLAttributes( gl, capabilities ) {
124
106
  // @deprecated, r159
125
107
  if ( updateRange.count !== - 1 ) {
126
108
 
127
- if ( isWebGL2 ) {
128
-
129
- gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
130
- array, updateRange.offset, updateRange.count );
131
-
132
- } else {
133
-
134
- gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
135
- array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
136
-
137
- }
109
+ gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
110
+ array, updateRange.offset, updateRange.count );
138
111
 
139
112
  updateRange.count = - 1; // reset range
140
113
 
@@ -26,9 +26,8 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
26
26
  let currentBackgroundVersion = 0;
27
27
  let currentTonemapping = null;
28
28
 
29
- function render( renderList, scene ) {
29
+ function getBackground( scene ) {
30
30
 
31
- let forceClear = false;
32
31
  let background = scene.isScene === true ? scene.background : null;
33
32
 
34
33
  if ( background && background.isTexture ) {
@@ -38,6 +37,15 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
38
37
 
39
38
  }
40
39
 
40
+ return background;
41
+
42
+ }
43
+
44
+ function render( scene ) {
45
+
46
+ let forceClear = false;
47
+ const background = getBackground( scene );
48
+
41
49
  if ( background === null ) {
42
50
 
43
51
  setClear( clearColor, clearAlpha );
@@ -67,6 +75,12 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
67
75
 
68
76
  }
69
77
 
78
+ }
79
+
80
+ function addToRenderList( renderList, scene ) {
81
+
82
+ const background = getBackground( scene );
83
+
70
84
  if ( background && ( background.isCubeTexture || background.mapping === CubeUVReflectionMapping ) ) {
71
85
 
72
86
  if ( boxMesh === undefined ) {
@@ -247,7 +261,8 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
247
261
  setClear( clearColor, clearAlpha );
248
262
 
249
263
  },
250
- render: render
264
+ render: render,
265
+ addToRenderList: addToRenderList
251
266
 
252
267
  };
253
268
 
@@ -1,12 +1,9 @@
1
1
  import { IntType } from '../../constants.js';
2
2
 
3
- function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
3
+ function WebGLBindingStates( gl, attributes ) {
4
4
 
5
5
  const maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
6
6
 
7
- const extension = capabilities.isWebGL2 ? null : extensions.get( 'OES_vertex_array_object' );
8
- const vaoAvailable = capabilities.isWebGL2 || extension !== null;
9
-
10
7
  const bindingStates = {};
11
8
 
12
9
  const defaultState = createBindingState( null );
@@ -17,38 +14,18 @@ function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
17
14
 
18
15
  let updateBuffers = false;
19
16
 
20
- if ( vaoAvailable ) {
21
-
22
- const state = getBindingState( geometry, program, material );
23
-
24
- if ( currentState !== state ) {
25
-
26
- currentState = state;
27
- bindVertexArrayObject( currentState.object );
28
-
29
- }
30
-
31
- updateBuffers = needsUpdate( object, geometry, program, index );
32
-
33
- if ( updateBuffers ) saveCache( object, geometry, program, index );
34
-
35
- } else {
36
-
37
- const wireframe = ( material.wireframe === true );
17
+ const state = getBindingState( geometry, program, material );
38
18
 
39
- if ( currentState.geometry !== geometry.id ||
40
- currentState.program !== program.id ||
41
- currentState.wireframe !== wireframe ) {
19
+ if ( currentState !== state ) {
42
20
 
43
- currentState.geometry = geometry.id;
44
- currentState.program = program.id;
45
- currentState.wireframe = wireframe;
21
+ currentState = state;
22
+ bindVertexArrayObject( currentState.object );
46
23
 
47
- updateBuffers = true;
24
+ }
48
25
 
49
- }
26
+ updateBuffers = needsUpdate( object, geometry, program, index );
50
27
 
51
- }
28
+ if ( updateBuffers ) saveCache( object, geometry, program, index );
52
29
 
53
30
  if ( index !== null ) {
54
31
 
@@ -74,25 +51,19 @@ function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
74
51
 
75
52
  function createVertexArrayObject() {
76
53
 
77
- if ( capabilities.isWebGL2 ) return gl.createVertexArray();
78
-
79
- return extension.createVertexArrayOES();
54
+ return gl.createVertexArray();
80
55
 
81
56
  }
82
57
 
83
58
  function bindVertexArrayObject( vao ) {
84
59
 
85
- if ( capabilities.isWebGL2 ) return gl.bindVertexArray( vao );
86
-
87
- return extension.bindVertexArrayOES( vao );
60
+ return gl.bindVertexArray( vao );
88
61
 
89
62
  }
90
63
 
91
64
  function deleteVertexArrayObject( vao ) {
92
65
 
93
- if ( capabilities.isWebGL2 ) return gl.deleteVertexArray( vao );
94
-
95
- return extension.deleteVertexArrayOES( vao );
66
+ return gl.deleteVertexArray( vao );
96
67
 
97
68
  }
98
69
 
@@ -290,9 +261,7 @@ function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
290
261
 
291
262
  if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
292
263
 
293
- const extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
294
-
295
- extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
264
+ gl.vertexAttribDivisor( attribute, meshPerAttribute );
296
265
  attributeDivisors[ attribute ] = meshPerAttribute;
297
266
 
298
267
  }
@@ -333,12 +302,6 @@ function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
333
302
 
334
303
  function setupVertexAttributes( object, material, program, geometry ) {
335
304
 
336
- if ( capabilities.isWebGL2 === false && ( object.isInstancedMesh || geometry.isInstancedBufferGeometry ) ) {
337
-
338
- if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) return;
339
-
340
- }
341
-
342
305
  initAttributes();
343
306
 
344
307
  const geometryAttributes = geometry.attributes;
@@ -377,9 +340,9 @@ function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
377
340
  const type = attribute.type;
378
341
  const bytesPerElement = attribute.bytesPerElement;
379
342
 
380
- // check for integer attributes (WebGL 2 only)
343
+ // check for integer attributes
381
344
 
382
- const integer = ( capabilities.isWebGL2 === true && ( type === gl.INT || type === gl.UNSIGNED_INT || geometryAttribute.gpuType === IntType ) );
345
+ const integer = ( type === gl.INT || type === gl.UNSIGNED_INT || geometryAttribute.gpuType === IntType );
383
346
 
384
347
  if ( geometryAttribute.isInterleavedBufferAttribute ) {
385
348
 
@@ -1,6 +1,4 @@
1
- function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
2
-
3
- const isWebGL2 = capabilities.isWebGL2;
1
+ function WebGLBufferRenderer( gl, extensions, info ) {
4
2
 
5
3
  let mode;
6
4
 
@@ -22,49 +20,60 @@ function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
22
20
 
23
21
  if ( primcount === 0 ) return;
24
22
 
25
- let extension, methodName;
23
+ gl.drawArraysInstanced( mode, start, count, primcount );
26
24
 
27
- if ( isWebGL2 ) {
25
+ info.update( count, mode, primcount );
28
26
 
29
- extension = gl;
30
- methodName = 'drawArraysInstanced';
27
+ }
31
28
 
32
- } else {
29
+ function renderMultiDraw( starts, counts, drawCount ) {
30
+
31
+ if ( drawCount === 0 ) return;
32
+
33
+ const extension = extensions.get( 'WEBGL_multi_draw' );
33
34
 
34
- extension = extensions.get( 'ANGLE_instanced_arrays' );
35
- methodName = 'drawArraysInstancedANGLE';
35
+ if ( extension === null ) {
36
36
 
37
- if ( extension === null ) {
37
+ for ( let i = 0; i < drawCount; i ++ ) {
38
38
 
39
- console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
40
- return;
39
+ this.render( starts[ i ], counts[ i ] );
41
40
 
42
41
  }
43
42
 
44
- }
43
+ } else {
45
44
 
46
- extension[ methodName ]( mode, start, count, primcount );
45
+ extension.multiDrawArraysWEBGL( mode, starts, 0, counts, 0, drawCount );
47
46
 
48
- info.update( count, mode, primcount );
47
+ let elementCount = 0;
48
+ for ( let i = 0; i < drawCount; i ++ ) {
49
+
50
+ elementCount += counts[ i ];
51
+
52
+ }
53
+
54
+ info.update( elementCount, mode, 1 );
55
+
56
+ }
49
57
 
50
58
  }
51
59
 
52
- function renderMultiDraw( starts, counts, drawCount ) {
60
+ function renderMultiDrawInstances( starts, counts, drawCount, primcount ) {
53
61
 
54
62
  if ( drawCount === 0 ) return;
55
63
 
56
64
  const extension = extensions.get( 'WEBGL_multi_draw' );
65
+
57
66
  if ( extension === null ) {
58
67
 
59
- for ( let i = 0; i < drawCount; i ++ ) {
68
+ for ( let i = 0; i < starts.length; i ++ ) {
60
69
 
61
- this.render( starts[ i ], counts[ i ] );
70
+ renderInstances( starts[ i ], counts[ i ], primcount[ i ] );
62
71
 
63
72
  }
64
73
 
65
74
  } else {
66
75
 
67
- extension.multiDrawArraysWEBGL( mode, starts, 0, counts, 0, drawCount );
76
+ extension.multiDrawArraysInstancedWEBGL( mode, starts, 0, counts, 0, primcount, 0, drawCount );
68
77
 
69
78
  let elementCount = 0;
70
79
  for ( let i = 0; i < drawCount; i ++ ) {
@@ -73,7 +82,11 @@ function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
73
82
 
74
83
  }
75
84
 
76
- info.update( elementCount, mode, 1 );
85
+ for ( let i = 0; i < primcount.length; i ++ ) {
86
+
87
+ info.update( elementCount, mode, primcount[ i ] );
88
+
89
+ }
77
90
 
78
91
  }
79
92
 
@@ -85,6 +98,7 @@ function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
85
98
  this.render = render;
86
99
  this.renderInstances = renderInstances;
87
100
  this.renderMultiDraw = renderMultiDraw;
101
+ this.renderMultiDrawInstances = renderMultiDrawInstances;
88
102
 
89
103
  }
90
104