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

Examples: Improve webgpu_postprocessing_ssr. #29878

Merged
merged 2 commits into from
Nov 14, 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 added examples/models/gltf/steampunk_camera.glb
Binary file not shown.
Binary file modified examples/screenshots/webgpu_postprocessing_ssr.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 20 additions & 70 deletions examples/webgpu_postprocessing_ssr.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
<head>

<head>
<title>three.js webgpu - postprocessing - Screen Space Reflection</title>
<title>three.js webgpu - postprocessing - Screen Space Reflections (SSR)</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
</head>

<body>
<div id="container"></div>
<div id="info">
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> -
SSR demo by <a href="https://github.com/gonnavis" target="_blank">Vis</a>.<br />
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgpu - postprocessing - screen space reflections<br />
<a href="https://skfb.ly/6tqYD" target="_blank" rel="noopener">Steampunk Camera</a> by
<a href="https://sketchfab.com/lumoize" target="_blank" rel="noopener">dylanheyes</a> is licensed under <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noopener">Creative Commons Attribution</a>.<br />
</div>

<script type="importmap">
{
"imports": {
Expand All @@ -29,92 +28,48 @@

<script type="module">
import * as THREE from 'three';
import { pass, mrt, output, transformedNormalView, metalness, vec4/*, uniform*/ } from 'three/tsl';
import { pass, mrt, output, transformedNormalView, metalness, vec4, screenUV, color } from 'three/tsl';
import { ssr } from 'three/addons/tsl/display/SSRNode.js';

import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
import Stats from 'three/addons/libs/stats.module.js';

const params = {
maxDistance: 0.1,
maxDistance: 0.2,
opacity: 1,
thickness: 0.018,
enabled: true,
autoRotate: false
thickness: 0.015,
enabled: true
};

let camera, scene, renderer, postProcessing, ssrPass;
let gui, stats, controls;

// Configure and create Draco decoder.
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath( 'jsm/libs/draco/' );
dracoLoader.setDecoderConfig( { type: 'js' } );

init();

async function init() {

camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 0.1, 15 );
camera.position.set( 0.1, 0.2, 0.5 );
camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 0.1, 50 );
camera.position.set( 2.5, 2, 2.5 );

scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0x666666, 1, 4 );

// Ground
const plane = new THREE.Mesh(
new THREE.PlaneGeometry( 8, 8 ),
new THREE.MeshStandardNodeMaterial( { color: 0xcbcbcb } )
);

// any node material can write custom MRT metalness values for controlling SSR
scene.backgroundNode = screenUV.distance( .5 ).remap( 0, 0.5 ).mix( color( 0x666666 ), color( 0x393939 ) );

// plane.material.mrtNode = mrt( {
// output: output,
// normal: transformedNormalView,
// metalness: uniform( 0.5 )
// } );
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath( 'jsm/libs/draco/' );
dracoLoader.setDecoderConfig( { type: 'js' } );

plane.rotation.x = - Math.PI / 2;
plane.position.y = - 0.0001;
scene.add( plane );

dracoLoader.load( 'models/draco/bunny.drc', function ( geometry ) {

geometry.computeVertexNormals();
const loader = new GLTFLoader();
loader.setDRACOLoader( dracoLoader );
loader.load( 'models/gltf/steampunk_camera.glb', function ( gltf ) {

const material = new THREE.MeshStandardNodeMaterial( { color: 0xa5a5a5, metalness: 1 } );
const mesh = new THREE.Mesh( geometry, material );
mesh.position.y = - 0.0365;
scene.add( mesh );

dracoLoader.dispose();
scene.add( gltf.scene );

} );

let geometry, material, mesh;

geometry = new THREE.BoxGeometry( 0.05, 0.05, 0.05 );
material = new THREE.MeshStandardNodeMaterial( { color: 'green', metalness: 0.3 } );
mesh = new THREE.Mesh( geometry, material );
mesh.position.set( - 0.12, 0.025, 0.015 );
scene.add( mesh );

geometry = new THREE.IcosahedronGeometry( .025, 4 );
material = new THREE.MeshStandardNodeMaterial( { color: 'cyan', metalness: 0.5 } );
mesh = new THREE.Mesh( geometry, material );
mesh.position.set( - 0.05, 0.025, 0.08 );
scene.add( mesh );

geometry = new THREE.ConeGeometry( 0.025, 0.05, 64 );
material = new THREE.MeshStandardNodeMaterial( { color: 'yellow', metalness: 0.4 } );
mesh = new THREE.Mesh( geometry, material );
mesh.position.set( - 0.05, 0.025, - 0.055 );
scene.add( mesh );

//

renderer = new THREE.WebGPURenderer();
Expand All @@ -128,7 +83,6 @@
const environment = new RoomEnvironment();
const pmremGenerator = new THREE.PMREMGenerator( renderer );

scene.background = new THREE.Color( 0x666666 );
scene.environment = pmremGenerator.fromScene( environment ).texture;
scene.environmentIntensity = 0.75;
pmremGenerator.dispose();
Expand Down Expand Up @@ -162,7 +116,6 @@

controls = new OrbitControls( camera, renderer.domElement );
controls.enableDamping = true;
controls.target.set( 0, 0.05, 0 );
controls.update();

// stats
Expand All @@ -177,7 +130,7 @@
gui = new GUI();
gui.add( params, 'maxDistance' ).min( 0 ).max( 1 ).onChange( updateParameters );
gui.add( params, 'opacity' ).min( 0 ).max( 1 ).onChange( updateParameters );
gui.add( params, 'thickness' ).min( 0 ).max( 0.1 ).onChange( updateParameters );
gui.add( params, 'thickness' ).min( 0 ).max( 0.05 ).onChange( updateParameters );
gui.add( params, 'enabled' ).onChange( () => {

if ( params.enabled === true ) {
Expand All @@ -193,7 +146,6 @@
postProcessing.needsUpdate = true;

} );
gui.add( params, 'autoRotate' );

updateParameters();

Expand Down Expand Up @@ -221,8 +173,6 @@

stats.begin();

controls.autoRotate = params.autoRotate;

controls.update();

postProcessing.render();
Expand Down
1 change: 1 addition & 0 deletions test/e2e/puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const exceptionList = [
'webgpu_tsl_vfx_tornado',
'webgpu_textures_anisotropy',
'webgpu_materials_envmaps_bpcem',
'webgpu_postprocessing_ssr',

// WebGPU idleTime and parseTime too low
'webgpu_compute_particles',
Expand Down