Skip to content

Commit 1d31f7e

Browse files
committed
improve webgpu_backdrop_area example
1 parent d849f33 commit 1d31f7e

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed
4.95 KB
Loading

examples/webgpu_backdrop_area.html

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
<script type="module">
2626

2727
import * as THREE from 'three';
28-
import { color, linearDepth, viewportLinearDepth, viewportSharedTexture, textureBicubic, viewportMipTexture, screenUV, checker, uv, modelScale } from 'three/tsl';
28+
import { color, positionWorld, linearDepth, viewportLinearDepth, viewportSharedTexture, screenUV, hue, time, checker, uv, modelScale } from 'three/tsl';
29+
import { hashBlur } from 'three/addons/tsl/display/hashBlur.js';
2930

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

@@ -44,16 +45,12 @@
4445
camera.position.set( 3, 2, 3 );
4546

4647
scene = new THREE.Scene();
47-
scene.background = new THREE.Color( 0x777777 );
48+
scene.backgroundNode = hue( screenUV.y.mix( color( 0x66bbff ), color( 0x4466ff ) ), time.mul( 0.1 ) );
4849
camera.lookAt( 0, 1, 0 );
4950

5051
clock = new THREE.Clock();
5152

52-
const light = new THREE.PointLight( 0xffffff, 50 );
53-
camera.add( light );
54-
scene.add( camera );
55-
56-
const ambient = new THREE.AmbientLight( 0x4466ff, 1 );
53+
const ambient = new THREE.AmbientLight( 0xffffff, 2 );
5754
scene.add( ambient );
5855

5956
// model
@@ -79,43 +76,42 @@
7976
const depthDistance = viewportLinearDepth.distance( linearDepth() );
8077

8178
const depthAlphaNode = depthDistance.oneMinus().smoothstep( .90, 2 ).mul( 10 ).saturate();
82-
const depthBlurred = textureBicubic( viewportMipTexture(), depthDistance.smoothstep( 0, .6 ).mul( 40 * 5 ).clamp( 0, 5 ) );
79+
const depthBlurred = hashBlur( viewportSharedTexture(), depthDistance.smoothstep( 0, .6 ).mul( 40 ).clamp().mul( .1 ) );
8380

8481
const blurredBlur = new THREE.MeshBasicNodeMaterial();
85-
blurredBlur.backdropNode = depthBlurred.add( depthAlphaNode.mix( color( 0x0066ff ), 0 ) );
82+
blurredBlur.backdropNode = depthBlurred.add( depthAlphaNode.mix( color( 0x003399 ).mul( .3 ), 0 ) );
8683
blurredBlur.transparent = true;
8784
blurredBlur.side = THREE.DoubleSide;
8885

89-
const volumeMaterial = new THREE.MeshBasicNodeMaterial();
90-
volumeMaterial.colorNode = color( 0x0066ff );
91-
volumeMaterial.backdropNode = viewportSharedTexture();
92-
volumeMaterial.backdropAlphaNode = depthAlphaNode;
93-
volumeMaterial.transparent = true;
94-
volumeMaterial.side = THREE.DoubleSide;
95-
9686
const depthMaterial = new THREE.MeshBasicNodeMaterial();
9787
depthMaterial.backdropNode = depthAlphaNode;
9888
depthMaterial.transparent = true;
9989
depthMaterial.side = THREE.DoubleSide;
10090

101-
const bicubicMaterial = new THREE.MeshBasicNodeMaterial();
102-
bicubicMaterial.backdropNode = textureBicubic( viewportMipTexture(), 5 ); // @TODO: Move to alpha value [ 0, 1 ]
103-
bicubicMaterial.backdropAlphaNode = checker( uv().mul( 3 ).mul( modelScale.xy ) );
104-
bicubicMaterial.opacityNode = bicubicMaterial.backdropAlphaNode;
105-
bicubicMaterial.transparent = true;
106-
bicubicMaterial.side = THREE.DoubleSide;
91+
const checkerMaterial = new THREE.MeshBasicNodeMaterial();
92+
checkerMaterial.backdropNode = hashBlur( viewportSharedTexture(), .05 );
93+
checkerMaterial.backdropAlphaNode = checker( uv().mul( 3 ).mul( modelScale.xy ) );
94+
checkerMaterial.opacityNode = checkerMaterial.backdropAlphaNode;
95+
checkerMaterial.transparent = true;
96+
checkerMaterial.side = THREE.DoubleSide;
10797

10898
const pixelMaterial = new THREE.MeshBasicNodeMaterial();
10999
pixelMaterial.backdropNode = viewportSharedTexture( screenUV.mul( 100 ).floor().div( 100 ) );
110100
pixelMaterial.transparent = true;
111101

112102
// box / floor
113103

114-
const box = new THREE.Mesh( new THREE.BoxGeometry( 2, 2, 2 ), volumeMaterial );
104+
const box = new THREE.Mesh( new THREE.BoxGeometry( 2, 2, 2 ), blurredBlur );
115105
box.position.set( 0, 1, 0 );
106+
box.renderOrder = 1;
116107
scene.add( box );
117108

118-
const floor = new THREE.Mesh( new THREE.BoxGeometry( 1.99, .01, 1.99 ), new THREE.MeshBasicNodeMaterial( { color: 0x333333 } ) );
109+
const floor = new THREE.Mesh( new THREE.BoxGeometry( 5, .01, 5 ), new THREE.MeshBasicNodeMaterial( {
110+
color: 0xff6600,
111+
opacityNode: positionWorld.xz.distance( 0 ).oneMinus().clamp(),
112+
transparent: true,
113+
depthWrite: false
114+
} ) );
119115
floor.position.set( 0, 0, 0 );
120116
scene.add( floor );
121117

@@ -125,8 +121,8 @@
125121
renderer.setPixelRatio( window.devicePixelRatio );
126122
renderer.setSize( window.innerWidth, window.innerHeight );
127123
renderer.setAnimationLoop( animate );
128-
renderer.toneMapping = THREE.LinearToneMapping;
129-
renderer.toneMappingExposure = 0.2;
124+
renderer.toneMapping = THREE.NeutralToneMapping;
125+
renderer.toneMappingExposure = .9;
130126
document.body.appendChild( renderer.domElement );
131127

132128
const controls = new OrbitControls( camera, renderer.domElement );
@@ -139,9 +135,8 @@
139135

140136
const materials = {
141137
'blurred': blurredBlur,
142-
'volume': volumeMaterial,
143138
'depth': depthMaterial,
144-
'bicubic': bicubicMaterial,
139+
'checker': checkerMaterial,
145140
'pixel': pixelMaterial
146141
};
147142

0 commit comments

Comments
 (0)