Skip to content

Commit

Permalink
GTAONode: Implement composite. (mrdoob#28851)
Browse files Browse the repository at this point in the history
* GTAONode: Implement composite.

* Examples: Clean up.
  • Loading branch information
Mugen87 committed Jul 11, 2024
1 parent 3230889 commit 0c11af3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
Binary file modified examples/screenshots/webgpu_postprocessing_ao.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions examples/webgpu_postprocessing_ao.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

import Stats from 'three/addons/libs/stats.module.js';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';

let camera, scene, renderer, postProcessing, controls, clock, stats, mixer;

const params = {
blendIntensity: 1,
enabled: true
};

init();

async function init() {
Expand Down Expand Up @@ -102,6 +108,31 @@

window.addEventListener( 'resize', onWindowResize );

//

const gui = new GUI();
gui.title( 'AO settings' );
gui.add( params, 'blendIntensity' ).min( 0 ).max( 1 ).onChange( ( value ) => {

aoPass.blendIntensity.value = value;

} );
gui.add( params, 'enabled' ).onChange( ( value ) => {

if ( value === true ) {

postProcessing.outputNode = aoPass;

} else {

postProcessing.outputNode = scenePassColor;

}

postProcessing.needsUpdate = true;

} );

}

function onWindowResize() {
Expand Down
25 changes: 12 additions & 13 deletions src/nodes/display/GTAONode.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class GTAONode extends TempNode {
this.distanceExponent = uniform( 1 );
this.distanceFallOff = uniform( 1 );
this.scale = uniform( 1 );
this.blendIntensity = uniform( 1 );
this.noiseNode = texture( generateMagicSquareNoise() );

this.cameraProjectionMatrix = uniform( camera.projectionMatrix );
Expand All @@ -53,12 +54,6 @@ class GTAONode extends TempNode {

}

getTextureNode() {

return this._textureNode;

}

setSize( width, height ) {

this.resolution.value.set( width, height );
Expand Down Expand Up @@ -115,7 +110,7 @@ class GTAONode extends TempNode {

const uvNode = uv();

// const sampleTexture = ( uv ) => textureNode.uv( uv );
const sampleTexture = ( uv ) => textureNode.uv( uv );
const sampleDepth = ( uv ) => this.depthNode.uv( uv ).x;
const sampleNoise = ( uv ) => this.noiseNode.uv( uv );

Expand Down Expand Up @@ -228,18 +223,22 @@ class GTAONode extends TempNode {

} );

const composite = tslFn( () => {

const beauty = sampleTexture( uvNode );
const ao = this._textureNode.uv( uvNode );

return beauty.mul( mix( vec3( 1.0 ), ao, this.blendIntensity ) );

} );

const material = this._material || ( this._material = builder.createNodeMaterial() );
material.fragmentNode = ao().context( builder.getSharedContext() );
material.needsUpdate = true;

//

const properties = builder.getNodeProperties( this );
properties.textureNode = textureNode;

//

return this._textureNode;
return composite();

}

Expand Down

0 comments on commit 0c11af3

Please sign in to comment.