Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Commit a3efe4d

Browse files
authored
IR-3602-Changing-CSM-cascade-count-or-tonemapping-spams-errors (#10926)
* Only update uniforms once * Check component exists * revert
1 parent 81404ef commit a3efe4d

File tree

1 file changed

+9
-5
lines changed
  • packages/spatial/src/renderer/csm

1 file changed

+9
-5
lines changed

packages/spatial/src/renderer/csm/CSM.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { Engine } from '@etherealengine/ecs/src/Engine'
4343
import { Entity } from '@etherealengine/ecs/src/Entity'
4444
import { createEntity, removeEntity } from '@etherealengine/ecs/src/EntityFunctions'
4545

46+
import { getState } from '@etherealengine/hyperflux'
4647
import { CameraComponent } from '../../camera/components/CameraComponent'
4748
import { NameComponent } from '../../common/NameComponent'
4849
import { Vector3_Zero } from '../../common/constants/MathConstants'
@@ -51,6 +52,7 @@ import { addObjectToGroup } from '../../renderer/components/GroupComponent'
5152
import { VisibleComponent } from '../../renderer/components/VisibleComponent'
5253
import { EntityTreeComponent } from '../../transform/components/EntityTree'
5354
import { TransformComponent } from '../../transform/components/TransformComponent'
55+
import { RendererState } from '../RendererState'
5456
import Frustum from './Frustum'
5557
import Shader from './Shader'
5658

@@ -319,7 +321,8 @@ export class CSM {
319321
if (this.sourceLight) this.lightDirection.subVectors(this.sourceLight.target.position, this.sourceLight.position)
320322
if (this.needsUpdate) {
321323
this.injectInclude()
322-
this.updateFrustums()
324+
// Only update uniforms if WebGLRendererSystem isn't already updating them every frame
325+
this.updateFrustums(!getState(RendererState).updateCSMFrustums)
323326
for (const light of this.lights) {
324327
light.shadow.map?.dispose()
325328
light.shadow.map = null as any
@@ -439,7 +442,8 @@ export class CSM {
439442
updateUniforms(): void {
440443
const camera = getComponent(Engine.instance.cameraEntity, CameraComponent)
441444
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()) {
443447
const camera = getComponent(Engine.instance.cameraEntity, CameraComponent)
444448

445449
if (shader !== null) {
@@ -456,7 +460,7 @@ export class CSM {
456460
material.defines!.CSM_FADE = ''
457461
material.needsUpdate = true
458462
}
459-
}, this)
463+
}
460464
}
461465

462466
getExtendedBreaks(target: Vector2[]): void {
@@ -474,11 +478,11 @@ export class CSM {
474478
}
475479
}
476480

477-
updateFrustums(): void {
481+
updateFrustums(updateUniforms = true): void {
478482
this.getBreaks()
479483
this.initCascades()
480484
this.updateShadowBounds()
481-
this.updateUniforms()
485+
if (updateUniforms) this.updateUniforms()
482486
}
483487

484488
remove(): void {

0 commit comments

Comments
 (0)