File tree Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -35,8 +35,10 @@ class MeshPostProcessingMaterial extends MeshPhysicalMaterial {
3535 super ( parameters ) ;
3636
3737 this . onBeforeCompile = this . _onBeforeCompile ;
38+ this . customProgramCacheKey = this . _customProgramCacheKey ;
3839 this . _aoPassMap = aoPassMap ;
3940 this . aoPassMapScale = aoPassMapScale ;
41+ this . _shader = null ;
4042
4143 }
4244
@@ -50,12 +52,21 @@ class MeshPostProcessingMaterial extends MeshPhysicalMaterial {
5052
5153 this . _aoPassMap = aoPassMap ;
5254 this . needsUpdate = true ;
55+ this . _setUniforms ( ) ;
56+
57+ }
58+
59+ _customProgramCacheKey ( ) {
60+
61+ return this . _aoPassMap !== undefined && this . _aoPassMap !== null ? 'aoPassMap' : '' ;
5362
5463 }
5564
5665 _onBeforeCompile ( shader ) {
5766
58- if ( this . _aoPassMap !== undefined ) {
67+ this . _shader = shader ;
68+
69+ if ( this . _aoPassMap !== undefined && this . _aoPassMap !== null ) {
5970
6071 shader . fragmentShader = shader . fragmentShader . replace (
6172 '#include <aomap_pars_fragment>' ,
@@ -65,8 +76,19 @@ class MeshPostProcessingMaterial extends MeshPhysicalMaterial {
6576 '#include <aomap_fragment>' ,
6677 aomap_fragment_replacement
6778 ) ;
68- shader . uniforms . tAoPassMap = { value : this . _aoPassMap } ;
69- shader . uniforms . aoPassMapScale = { value : this . aoPassMapScale } ;
79+
80+ }
81+
82+ this . _setUniforms ( ) ;
83+
84+ }
85+
86+ _setUniforms ( ) {
87+
88+ if ( this . _shader ) {
89+
90+ this . _shader . uniforms . tAoPassMap = { value : this . _aoPassMap } ;
91+ this . _shader . uniforms . aoPassMapScale = { value : this . aoPassMapScale } ;
7092
7193 }
7294
Original file line number Diff line number Diff line change 215215 const gui = new GUI ( ) ;
216216 gui . add ( gtaoPasses [ 0 ] , 'output' , {
217217 'Default' : GTAOPass . OUTPUT . Default ,
218- 'Diffuse (right side) ' : GTAOPass . OUTPUT . Diffuse ,
218+ 'Diffuse' : GTAOPass . OUTPUT . Diffuse ,
219219 'AO' : GTAOPass . OUTPUT . Denoise ,
220220
221221 } ) . onChange ( function ( value ) {
222222
223223 gtaoPasses [ 0 ] . output = value ;
224224 gtaoPasses [ 1 ] . output = value === GTAOPass . OUTPUT . Denoise ? value : GTAOPass . OUTPUT . Off ;
225- renderPasses [ 1 ] . enabled = value !== GTAOPass . OUTPUT . Denoise ;
225+ renderPasses . forEach ( pass => pass . enabled = value !== GTAOPass . OUTPUT . Denoise ) ;
226+ groundMaterials [ 1 ] . aoPassMap = value === GTAOPass . OUTPUT . Default ? gtaoPasses [ 1 ] . gtaoMap : null ;
227+ objectMaterials [ 1 ] . aoPassMap = value === GTAOPass . OUTPUT . Default ? gtaoPasses [ 1 ] . gtaoMap : null ;
226228
227229 } ) ;
228230 gui . add ( sceneParameters , 'envMapIntensity' ) . min ( 0 ) . max ( 1 ) . step ( 0.01 ) . onChange ( ( ) => {
You can’t perform that action at this time.
0 commit comments