@@ -43,6 +43,7 @@ import { Engine } from '@etherealengine/ecs/src/Engine'
43
43
import { Entity } from '@etherealengine/ecs/src/Entity'
44
44
import { createEntity , removeEntity } from '@etherealengine/ecs/src/EntityFunctions'
45
45
46
+ import { getState } from '@etherealengine/hyperflux'
46
47
import { CameraComponent } from '../../camera/components/CameraComponent'
47
48
import { NameComponent } from '../../common/NameComponent'
48
49
import { Vector3_Zero } from '../../common/constants/MathConstants'
@@ -51,6 +52,7 @@ import { addObjectToGroup } from '../../renderer/components/GroupComponent'
51
52
import { VisibleComponent } from '../../renderer/components/VisibleComponent'
52
53
import { EntityTreeComponent } from '../../transform/components/EntityTree'
53
54
import { TransformComponent } from '../../transform/components/TransformComponent'
55
+ import { RendererState } from '../RendererState'
54
56
import Frustum from './Frustum'
55
57
import Shader from './Shader'
56
58
@@ -319,7 +321,8 @@ export class CSM {
319
321
if ( this . sourceLight ) this . lightDirection . subVectors ( this . sourceLight . target . position , this . sourceLight . position )
320
322
if ( this . needsUpdate ) {
321
323
this . injectInclude ( )
322
- this . updateFrustums ( )
324
+ // Only update uniforms if WebGLRendererSystem isn't already updating them every frame
325
+ this . updateFrustums ( ! getState ( RendererState ) . updateCSMFrustums )
323
326
for ( const light of this . lights ) {
324
327
light . shadow . map ?. dispose ( )
325
328
light . shadow . map = null as any
@@ -439,7 +442,8 @@ export class CSM {
439
442
updateUniforms ( ) : void {
440
443
const camera = getComponent ( Engine . instance . cameraEntity , CameraComponent )
441
444
const far = Math . min ( camera . far , this . maxFar )
442
- this . shaders . forEach ( function ( shader : ShaderType , material : Material ) {
445
+
446
+ for ( const [ material , shader ] of this . shaders . entries ( ) ) {
443
447
const camera = getComponent ( Engine . instance . cameraEntity , CameraComponent )
444
448
445
449
if ( shader !== null ) {
@@ -456,7 +460,7 @@ export class CSM {
456
460
material . defines ! . CSM_FADE = ''
457
461
material . needsUpdate = true
458
462
}
459
- } , this )
463
+ }
460
464
}
461
465
462
466
getExtendedBreaks ( target : Vector2 [ ] ) : void {
@@ -474,11 +478,11 @@ export class CSM {
474
478
}
475
479
}
476
480
477
- updateFrustums ( ) : void {
481
+ updateFrustums ( updateUniforms = true ) : void {
478
482
this . getBreaks ( )
479
483
this . initCascades ( )
480
484
this . updateShadowBounds ( )
481
- this . updateUniforms ( )
485
+ if ( updateUniforms ) this . updateUniforms ( )
482
486
}
483
487
484
488
remove ( ) : void {
0 commit comments