Skip to content

Commit

Permalink
Examples: postprocessing material ao: show diffuse pass on both sides
Browse files Browse the repository at this point in the history
  • Loading branch information
Rabbid76 committed Dec 31, 2023
1 parent 7819ad8 commit 20e5e00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 10 additions & 1 deletion examples/jsm/materials/MeshPostProcessingMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ class MeshPostProcessingMaterial extends MeshPhysicalMaterial {
super( parameters );

this.onBeforeCompile = this._onBeforeCompile;
this.customProgramCacheKey = this._customProgramCacheKey;
this._aoPassMap = aoPassMap;
this.aoPassMapScale = aoPassMapScale;
this._mapVersion = 0;

}

Expand All @@ -50,12 +52,19 @@ class MeshPostProcessingMaterial extends MeshPhysicalMaterial {

this._aoPassMap = aoPassMap;
this.needsUpdate = true;
if ( aoPassMap !== undefined && aoPassMap !== null ) this._mapVersion ++;

}

_customProgramCacheKey() {

return this._aoPassMap !== undefined && this._aoPassMap !== null ? this._aoPassMap.uuid + this._mapVersion : '';

}

_onBeforeCompile( shader ) {

if ( this._aoPassMap !== undefined ) {
if ( this._aoPassMap !== undefined && this._aoPassMap !== null ) {

shader.fragmentShader = shader.fragmentShader.replace(
'#include <aomap_pars_fragment>',
Expand Down
6 changes: 4 additions & 2 deletions examples/webgl_postprocessing_material_ao.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,16 @@
const gui = new GUI();
gui.add( gtaoPasses[ 0 ], 'output', {
'Default': GTAOPass.OUTPUT.Default,
'Diffuse (right side)': GTAOPass.OUTPUT.Diffuse,
'Diffuse': GTAOPass.OUTPUT.Diffuse,
'AO': GTAOPass.OUTPUT.Denoise,

} ).onChange( function ( value ) {

gtaoPasses[ 0 ].output = value;
gtaoPasses[ 1 ].output = value === GTAOPass.OUTPUT.Denoise ? value : GTAOPass.OUTPUT.Off;
renderPasses[ 1 ].enabled = value !== GTAOPass.OUTPUT.Denoise;
renderPasses.forEach( pass => pass.enabled = value !== GTAOPass.OUTPUT.Denoise );
groundMaterials[ 1 ].aoPassMap = value === GTAOPass.OUTPUT.Default ? gtaoPasses[ 1 ].gtaoMap : null;
objectMaterials[ 1 ].aoPassMap = value === GTAOPass.OUTPUT.Default ? gtaoPasses[ 1 ].gtaoMap : null;

} );
gui.add( sceneParameters, 'envMapIntensity' ).min( 0 ).max( 1 ).step( 0.01 ).onChange( () => {
Expand Down

0 comments on commit 20e5e00

Please sign in to comment.