Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTAONode: Implement composite. #28851

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some changes to this PR, I think it's important to keep getTextureNode() for external manipulation level, like adding a custom Denoise filter or just a blur without having to do a new render-pass.

I'm removing blendIntensity too, now with TSL I think it's better that this level of abstraction stays outside the internal Nodes, intensity, blend are things that would only bring more load to the examples since we could use blendIntensity.mix( beauty, beauty.mul( ao ) externally if necessary.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you think the same think <3 #28851 (comment)
I'm reading the comments now :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with your suggested changes. I've only added blendIntensity now so the implementation can be considered as "complete" and usable in apps.


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