Skip to content

Commit 5048f72

Browse files
committed
WebGLRenderer: Pre-allocate texture units for shadow samplers.
1 parent 05c8fa0 commit 5048f72

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/renderers/WebGLRenderer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,6 +2444,30 @@ class WebGLRenderer {
24442444

24452445
}
24462446

2447+
// Pre-allocate texture units for shadow samplers before setting data textures
2448+
if ( materialProperties.needsLights ) {
2449+
2450+
// Set shadow map uniforms first to ensure they get the first texture units
2451+
if ( lights.state.directionalShadowMap.length > 0 ) {
2452+
2453+
p_uniforms.setValue( _gl, 'directionalShadowMap', lights.state.directionalShadowMap, textures );
2454+
2455+
}
2456+
2457+
if ( lights.state.spotShadowMap.length > 0 ) {
2458+
2459+
p_uniforms.setValue( _gl, 'spotShadowMap', lights.state.spotShadowMap, textures );
2460+
2461+
}
2462+
2463+
if ( lights.state.pointShadowMap.length > 0 ) {
2464+
2465+
p_uniforms.setValue( _gl, 'pointShadowMap', lights.state.pointShadowMap, textures );
2466+
2467+
}
2468+
2469+
}
2470+
24472471
// skinning and morph target uniforms must be set even if material didn't change
24482472
// auto-setting of texture unit for bone and morph texture must go before other textures
24492473
// otherwise textures used for skinning and morphing can take over texture units reserved for other material textures

0 commit comments

Comments
 (0)