From 6e006b29964ff6facb832690d3e38918d8434b64 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Mon, 1 Dec 2025 17:55:34 +0000 Subject: [PATCH 1/4] Octree: Fixed typo. --- examples/jsm/math/Octree.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/jsm/math/Octree.js b/examples/jsm/math/Octree.js index 5ced629b7c36ec..6814d33f16d63c 100644 --- a/examples/jsm/math/Octree.js +++ b/examples/jsm/math/Octree.js @@ -20,7 +20,7 @@ const _line2 = new Line3(); const _box = new Box3(); const _sphere = new Sphere(); const _capsule = new Capsule(); -const _center = new Capsule(); +const _center = new Vector3(); const _temp1 = new Vector3(); const _temp2 = new Vector3(); From 9edec1c33b790ae1b4549e6066ec860ded3a2335 Mon Sep 17 00:00:00 2001 From: Michael Herzog Date: Mon, 1 Dec 2025 19:08:58 +0100 Subject: [PATCH 2/4] WebGPURenderer: Refine video texture warning. (#32439) --- src/renderers/common/Textures.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/common/Textures.js b/src/renderers/common/Textures.js index 6512aea6a1817f..b1eab665e9b526 100644 --- a/src/renderers/common/Textures.js +++ b/src/renderers/common/Textures.js @@ -325,7 +325,7 @@ class Textures extends DataMap { // - if ( texture.isVideoTexture && ColorManagement.getTransfer( texture.colorSpace ) !== SRGBTransfer ) { + if ( texture.isVideoTexture && ColorManagement.enabled === true && ColorManagement.getTransfer( texture.colorSpace ) !== SRGBTransfer ) { warn( 'WebGPURenderer: Video textures must use a color space with a sRGB transfer function, e.g. SRGBColorSpace.' ); From c2c5685879290d304c226a493061f6461021864c Mon Sep 17 00:00:00 2001 From: mrdoob Date: Mon, 1 Dec 2025 22:04:23 +0000 Subject: [PATCH 3/4] WebGLRenderer: Use native depth texture for VSM shadow maps (#32443) --- src/constants.js | 8 ------ src/renderers/shaders/ShaderLib/depth.glsl.js | 4 --- src/renderers/shaders/ShaderLib/vsm.glsl.js | 2 +- src/renderers/webgl/WebGLLights.js | 19 +++++++++++++- src/renderers/webgl/WebGLShadowMap.js | 25 +++++++++---------- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/constants.js b/src/constants.js index d4477a3bad2e1b..8536726d09e8f9 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1254,14 +1254,6 @@ export const RGBDepthPacking = 3202; */ export const RGDepthPacking = 3203; -/** - * The depth value is not packed. - * - * @type {number} - * @constant - */ -export const IdentityDepthPacking = 3204; - /** * Normal information is relative to the underlying surface. * diff --git a/src/renderers/shaders/ShaderLib/depth.glsl.js b/src/renderers/shaders/ShaderLib/depth.glsl.js index c025c12bd4ed3e..efacc561631b06 100644 --- a/src/renderers/shaders/ShaderLib/depth.glsl.js +++ b/src/renderers/shaders/ShaderLib/depth.glsl.js @@ -111,10 +111,6 @@ void main() { // TODO Deprecate gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 ); - #elif DEPTH_PACKING == 3204 - - gl_FragColor = vec4( vec3( fragCoordZ ), 1.0 ); - #endif } diff --git a/src/renderers/shaders/ShaderLib/vsm.glsl.js b/src/renderers/shaders/ShaderLib/vsm.glsl.js index 6b4a28a97f0aff..945662a3f9577d 100644 --- a/src/renderers/shaders/ShaderLib/vsm.glsl.js +++ b/src/renderers/shaders/ShaderLib/vsm.glsl.js @@ -43,7 +43,7 @@ void main() { mean = mean / samples; squared_mean = squared_mean / samples; - float std_dev = sqrt( squared_mean - mean * mean ); + float std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) ); gl_FragColor = vec4( mean, std_dev, 0.0, 1.0 ); diff --git a/src/renderers/webgl/WebGLLights.js b/src/renderers/webgl/WebGLLights.js index bd106f34017a10..e24f9266864354 100644 --- a/src/renderers/webgl/WebGLLights.js +++ b/src/renderers/webgl/WebGLLights.js @@ -3,6 +3,7 @@ import { Matrix4 } from '../../math/Matrix4.js'; import { Vector2 } from '../../math/Vector2.js'; import { Vector3 } from '../../math/Vector3.js'; import { UniformsLib } from '../shaders/UniformsLib.js'; +import { RGFormat } from '../../constants.js'; function UniformsCache() { @@ -239,7 +240,23 @@ function WebGLLights( extensions ) { const intensity = light.intensity; const distance = light.distance; - const shadowMap = ( light.shadow && light.shadow.map ) ? ( light.shadow.map.depthTexture || light.shadow.map.texture ) : null; + let shadowMap = null; + + if ( light.shadow && light.shadow.map ) { + + if ( light.shadow.map.texture.format === RGFormat ) { + + // VSM uses color texture with blurred mean/std_dev + shadowMap = light.shadow.map.texture; + + } else { + + // Other types use depth texture + shadowMap = light.shadow.map.depthTexture || light.shadow.map.texture; + + } + + } if ( light.isAmbientLight ) { diff --git a/src/renderers/webgl/WebGLShadowMap.js b/src/renderers/webgl/WebGLShadowMap.js index e38833a78f851b..b82720085af56f 100644 --- a/src/renderers/webgl/WebGLShadowMap.js +++ b/src/renderers/webgl/WebGLShadowMap.js @@ -1,4 +1,4 @@ -import { FrontSide, BackSide, DoubleSide, NearestFilter, LinearFilter, PCFShadowMap, VSMShadowMap, NoBlending, LessEqualCompare, GreaterEqualCompare, DepthFormat, UnsignedIntType, RGFormat, HalfFloatType, PCFSoftShadowMap, IdentityDepthPacking } from '../../constants.js'; +import { FrontSide, BackSide, DoubleSide, NearestFilter, LinearFilter, PCFShadowMap, VSMShadowMap, NoBlending, LessEqualCompare, GreaterEqualCompare, DepthFormat, UnsignedIntType, RGFormat, HalfFloatType, FloatType, PCFSoftShadowMap } from '../../constants.js'; import { WebGLRenderTarget } from '../WebGLRenderTarget.js'; import { WebGLCubeRenderTarget } from '../WebGLCubeRenderTarget.js'; import { MeshDepthMaterial } from '../../materials/MeshDepthMaterial.js'; @@ -26,7 +26,6 @@ function WebGLShadowMap( renderer, objects, capabilities ) { _viewport = new Vector4(), _depthMaterial = new MeshDepthMaterial(), - _depthMaterialVSM = new MeshDepthMaterial( { depthPacking: IdentityDepthPacking } ), _distanceMaterial = new MeshDistanceMaterial(), _materialCache = {}, @@ -215,6 +214,14 @@ function WebGLShadowMap( renderer, objects, capabilities ) { } ); shadow.map.texture.name = light.name + '.shadowMap'; + // Native depth texture for VSM - depth is captured here, then blurred into the color texture + shadow.map.depthTexture = new DepthTexture( _shadowMapSize.x, _shadowMapSize.y, FloatType ); + shadow.map.depthTexture.name = light.name + '.shadowMapDepth'; + shadow.map.depthTexture.format = DepthFormat; + shadow.map.depthTexture.compareFunction = null; // For regular sampling (not shadow comparison) + shadow.map.depthTexture.minFilter = NearestFilter; + shadow.map.depthTexture.magFilter = NearestFilter; + } else { if ( light.isPointLight ) { @@ -339,9 +346,9 @@ function WebGLShadowMap( renderer, objects, capabilities ) { } - // vertical pass + // vertical pass - read from native depth texture - shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture; + shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.depthTexture; shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize; shadowMaterialVertical.uniforms.radius.value = shadow.radius; renderer.setRenderTarget( shadow.mapPass ); @@ -371,15 +378,7 @@ function WebGLShadowMap( renderer, objects, capabilities ) { } else { - if ( type === VSMShadowMap ) { - - result = _depthMaterialVSM; - - } else { - - result = ( light.isPointLight === true ) ? _distanceMaterial : _depthMaterial; - - } + result = ( light.isPointLight === true ) ? _distanceMaterial : _depthMaterial; if ( ( renderer.localClippingEnabled && material.clipShadows === true && Array.isArray( material.clippingPlanes ) && material.clippingPlanes.length !== 0 ) || ( material.displacementMap && material.displacementScale !== 0 ) || From 652ae0f8571d0a1f137cc1136fbd59094760ccf0 Mon Sep 17 00:00:00 2001 From: mrdoob Date: Mon, 1 Dec 2025 22:25:21 +0000 Subject: [PATCH 4/4] WebGLRenderer: Align transmission render target samples with canvas. (#32444) --- src/renderers/WebGLRenderer.js | 2 +- src/renderers/webgl/WebGLCapabilities.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index d5c31af24ffea6..04713b3edc9c37 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -1876,7 +1876,7 @@ class WebGLRenderer { generateMipmaps: true, type: ( extensions.has( 'EXT_color_buffer_half_float' ) || extensions.has( 'EXT_color_buffer_float' ) ) ? HalfFloatType : UnsignedByteType, minFilter: LinearMipmapLinearFilter, - samples: 4, + samples: capabilities.samples, stencilBuffer: stencil, resolveDepthBuffer: false, resolveStencilBuffer: false, diff --git a/src/renderers/webgl/WebGLCapabilities.js b/src/renderers/webgl/WebGLCapabilities.js index bd187d45c3595a..6023a96fe3c932 100644 --- a/src/renderers/webgl/WebGLCapabilities.js +++ b/src/renderers/webgl/WebGLCapabilities.js @@ -108,6 +108,7 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) { const vertexTextures = maxVertexTextures > 0; const maxSamples = gl.getParameter( gl.MAX_SAMPLES ); + const samples = gl.getParameter( gl.SAMPLES ); return { @@ -135,7 +136,9 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) { vertexTextures: vertexTextures, - maxSamples: maxSamples + maxSamples: maxSamples, + + samples: samples };