Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 9 additions & 5 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 @@ -143,7 +144,7 @@
// scene context

scenePass.contextNode = context( {
ao: aoPassOutput.sample( screenUV ).r
ao: select( materialTransparent, 1, aoPassOutput.sample( screenUV ).r )
} );

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

//

const transparentMesh = new THREE.Mesh( new THREE.PlaneGeometry( 1.8, 2 ), new THREE.MeshStandardNodeMaterial( { transparent: true, opacity: .1 } ) );
transparentMesh = new THREE.Mesh( new THREE.PlaneGeometry( 1.8, 2 ), new THREE.MeshStandardNodeMaterial( { transparent: true, opacity: params.transparentOpacity } ) );
transparentMesh.material.transparent = true;
transparentMesh.position.z = 0;
transparentMesh.position.y = 0.5;
Expand All @@ -192,6 +193,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 +222,8 @@
aoPass.scale.value = params.scale;
aoPass.thickness.value = params.thickness;

transparentMesh.material.opacity = params.transparentOpacity;

}

function onWindowResize() {
Expand Down
1 change: 1 addition & 0 deletions src/Three.TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export const materialSpecularIntensity = TSL.materialSpecularIntensity;
export const materialSpecularStrength = TSL.materialSpecularStrength;
export const materialThickness = TSL.materialThickness;
export const materialTransmission = TSL.materialTransmission;
export const materialTransparent = TSL.materialTransparent;
export const max = TSL.max;
export const maxMipLevel = TSL.maxMipLevel;
export const mediumpModelViewMatrix = TSL.mediumpModelViewMatrix;
Expand Down
8 changes: 8 additions & 0 deletions src/nodes/accessors/MaterialProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ export const materialEnvRotation = /*@__PURE__*/ uniform( new Matrix4() ).onRefe
return _m1;

} );

/**
* TSL object that represents whether the material is transparent.
*
* @tsl
* @type {UniformNode<bool>}
*/
export const materialTransparent = /*@__PURE__*/ uniform( false ).onReference( ( { material } ) => material ).onObjectUpdate( ( { material } ) => material.transparent );
Loading