Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
25 changes: 19 additions & 6 deletions examples/webgpu_postprocessing_ao.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<script type="module">

import * as THREE from 'three/webgpu';
import { sample, pass, mrt, context, screenUV, normalView, velocity, vec3, vec4, directionToColor, colorToDirection, colorSpaceToWorking } from 'three/tsl';
import { sample, pass, mrt, context, screenUV, normalView, velocity, vec3, vec4, directionToColor, colorToDirection, colorSpaceToWorking, materialTransparent, select } from 'three/tsl';
import { ao } from 'three/addons/tsl/display/GTAONode.js';
import { traa } from 'three/addons/tsl/display/TRAANode.js';

Expand All @@ -49,7 +49,7 @@

let camera, scene, renderer, postProcessing, controls;

let aoPass, traaPass;
let aoPass, traaPass, transparentMesh;

const params = {
samples: 16,
Expand All @@ -58,7 +58,8 @@
radius: 0.25,
scale: 1,
thickness: 1,
aoOnly: false
aoOnly: false,
transparentOpacity: 0.3
};

init();
Expand Down Expand Up @@ -142,8 +143,18 @@

// scene context

const aoSample = aoPassOutput.sample( screenUV ).r;

scenePass.contextNode = context( {
ao: aoPassOutput.sample( screenUV ).r

getAO: ( node, { material } ) => {

if ( material.transparent === true ) return node;

return node !== null ? node.mul( aoSample ) : aoSample;

}

} );

// final output + traa
Expand All @@ -170,8 +181,7 @@

//

const transparentMesh = new THREE.Mesh( new THREE.PlaneGeometry( 1.8, 2 ), new THREE.MeshStandardNodeMaterial( { transparent: true, opacity: .1 } ) );
transparentMesh.material.transparent = true;
transparentMesh = new THREE.Mesh( new THREE.PlaneGeometry( 1.8, 2 ), new THREE.MeshStandardNodeMaterial( { transparent: true, opacity: params.transparentOpacity } ) );
transparentMesh.position.z = 0;
transparentMesh.position.y = 0.5;
transparentMesh.visible = false;
Expand All @@ -192,6 +202,7 @@
gui.add( params, 'thickness', 0.01, 2 ).onChange( updateParameters );
gui.add( aoPass, 'useTemporalFiltering' ).name( 'temporal filtering' );
gui.add( transparentMesh, 'visible' ).name( 'show transparent mesh' );
gui.add( params, 'transparentOpacity', 0, 1, 0.01 ).name( 'transparent opacity' ).onChange( updateParameters );
gui.add( params, 'aoOnly' ).onChange( ( value ) => {

if ( value === true ) {
Expand Down Expand Up @@ -220,6 +231,8 @@
aoPass.scale.value = params.scale;
aoPass.thickness.value = params.thickness;

transparentMesh.material.opacity = params.transparentOpacity;

}

function onWindowResize() {
Expand Down
18 changes: 13 additions & 5 deletions src/materials/nodes/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,17 +1060,25 @@ class NodeMaterial extends Material {

}

let aoNode = builder.context.ao || null;
let aoNode = this.aoNode;

if ( this.aoNode !== null || builder.material.aoMap ) {
if ( aoNode === null && builder.material.aoMap ) {

const mtlAO = this.aoNode !== null ? this.aoNode : materialAO;
aoNode = materialAO;

aoNode = aoNode !== null ? aoNode.mul( mtlAO ) : mtlAO;
}

if ( builder.context.getAO ) {

aoNode = builder.context.getAO( aoNode, { material: builder.material } );

} else {

aoNode = null;

}

if ( aoNode !== null ) {
if ( aoNode ) {

materialLightsNode.push( new AONode( aoNode ) );

Expand Down
2 changes: 1 addition & 1 deletion src/materials/nodes/manager/NodeMaterialObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class NodeMaterialObserver {

}

if ( builder.context.modelViewMatrix || builder.context.modelNormalViewMatrix || builder.context.ao || builder.context.getShadow )
if ( builder.context.modelViewMatrix || builder.context.modelNormalViewMatrix || builder.context.getAO || builder.context.getShadow )
return true;

return false;
Expand Down
Loading