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

Commit

Permalink
fix multiple csm instances not cleaning itself up from shader chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField committed Sep 11, 2023
1 parent 75f08dc commit d35f5f1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/engine/src/assets/csm/CSM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import { addOBCPlugin, removeOBCPlugin } from '../../common/functions/OnBeforeCo
import Frustum from './Frustum'
import Shader from './Shader'

const originalLightsFragmentBegin = ShaderChunk.lights_fragment_begin
const originalLightsParsBegin = ShaderChunk.lights_pars_begin

const _cameraToLightMatrix = new Matrix4()
const _lightSpaceFrustum = new Frustum()
const _center = new Vector3()
Expand Down Expand Up @@ -336,6 +339,11 @@ export class CSM {
ShaderChunk.lights_pars_begin = Shader.lights_pars_begin()
}

removeInclude(): void {
ShaderChunk.lights_fragment_begin = originalLightsFragmentBegin
ShaderChunk.lights_pars_begin = originalLightsParsBegin
}

setupMaterial(mesh: Mesh): void {
const material = mesh.material as Material
if (!material.userData) material.userData = {}
Expand Down Expand Up @@ -438,5 +446,6 @@ export class CSM {
})
this.shaders.clear()
this.remove()
this.removeInclude()
}
}

0 comments on commit d35f5f1

Please sign in to comment.