未验证 提交 99d26d1d 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #18768 from gkjohnson/csm-fixes

CSM: Miscellaneous Fixes
......@@ -53,8 +53,7 @@ export default class CSM {
this.breaks = [];
this.lights = [];
this.shaders = [];
this.materials = [];
this.shaders = new Map();
this.createLights();
this.getBreaks();
......@@ -236,41 +235,41 @@ export default class CSM {
}
const breaksVec2 = [];
this.getExtendedBreaks( breaksVec2 );
const self = this;
const far = Math.min( this.camera.far, this.maxFar );
const shaders = this.shaders;
material.onBeforeCompile = function ( shader ) {
const far = Math.min( self.camera.far, self.maxFar );
self.getExtendedBreaks( breaksVec2 );
shader.uniforms.CSM_cascades = { value: breaksVec2 };
shader.uniforms.cameraNear = { value: self.camera.near };
shader.uniforms.shadowFar = { value: far };
self.shaders.push( shader );
shaders.set( material, shader );
};
this.materials.push( material );
shaders.set( material, null );
}
updateUniforms() {
const far = Math.min( this.camera.far, this.maxFar );
const shaders = this.shaders;
for ( let i = 0; i < this.shaders.length; i ++ ) {
shaders.forEach( function ( shader, material ) {
const shader = this.shaders[ i ];
const uniforms = shader.uniforms;
this.getExtendedBreaks( uniforms.CSM_cascades.value );
uniforms.cameraNear.value = this.camera.near;
uniforms.shadowFar.value = far;
if ( shader !== null ) {
}
const uniforms = shader.uniforms;
this.getExtendedBreaks( uniforms.CSM_cascades.value );
uniforms.cameraNear.value = this.camera.near;
uniforms.shadowFar.value = far;
for ( let i = 0; i < this.materials.length; i ++ ) {
}
const material = this.materials[ i ];
if ( ! this.fade && 'CSM_FADE' in material.defines ) {
delete material.defines.CSM_FADE;
......@@ -283,7 +282,7 @@ export default class CSM {
}
}
}, this );
}
......@@ -387,4 +386,25 @@ export default class CSM {
}
dispose() {
const shaders = this.shaders;
shaders.forEach( function ( shader, material ) {
delete material.onBeforeCompile;
delete material.defines.USE_CSM;
delete material.defines.CSM_CASCADES;
delete material.defines.CSM_FADE;
delete shader.uniforms.CSM_cascades;
delete shader.uniforms.cameraNear;
delete shader.uniforms.shadowFar;
material.needsUpdate = true;
} );
shaders.clear();
}
}
......@@ -140,7 +140,7 @@
gui.add( params, 'fade' ).onChange( function ( value ) {
csm.fade = value;
csm.updateUniforms();
csm.updateFrustums();
} );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册