Răsfoiți Sursa

Examples: Improve `webgpu_postprocessing_sobel`. (#29934)

* Examples: Improve `webgpu_postprocessing_sobel`.

* E2E: Update exception list.
Michael Herzog 1 an în urmă
părinte
comite
587bf61b09

BIN
examples/screenshots/webgpu_postprocessing_sobel.jpg


+ 35 - 25
examples/webgpu_postprocessing_sobel.html

@@ -7,6 +7,10 @@
 		<link type="text/css" rel="stylesheet" href="main.css">
 	</head>
 	<body>
+		<div id="info">
+			<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - Edge Detection with Sobel
+		</div>
+
 		<script type="importmap">
 			{
 				"imports": {
@@ -20,76 +24,80 @@
 		<script type="module">
 
 			import * as THREE from 'three';
-			import { pass } from 'three/tsl';
+			import { pass, renderOutput } from 'three/tsl';
 			import { sobel } from 'three/addons/tsl/display/SobelOperatorNode.js';
 
 			import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
+			import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
+			import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
 
 			import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
 
-			let camera, scene, renderer;
+			let camera, scene, renderer, controls;
 			let postProcessing;
 
 			const params = {
-				enable: true
+				enabled: true
 			};
 
 			init();
 
-			function init() {
+			async function init() {
 
 				scene = new THREE.Scene();
 
 				camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 100 );
 				camera.position.set( 0, 1, 3 );
-				camera.lookAt( scene.position );
-
-				//
-
-				const ambientLight = new THREE.AmbientLight( 0xe7e7e7 );
-				scene.add( ambientLight );
-
-				const pointLight = new THREE.PointLight( 0xffffff, 20 );
-				camera.add( pointLight );
-				scene.add( camera );
 
 				//
 
-				const geometry = new THREE.TorusKnotGeometry( 1, 0.3, 256, 32 );
-				const material = new THREE.MeshPhongMaterial( { color: 0xffff00 } );
-
-				const mesh = new THREE.Mesh( geometry, material );
-				scene.add( mesh );
+				const loader = new GLTFLoader();
+				const gltf = await loader.loadAsync( 'models/gltf/DragonAttenuation.glb' );
+				const model = gltf.scene.children[ 1 ];
+				model.material = new THREE.MeshStandardNodeMaterial();
 
+				scene.add( model );
+			
 				//
 
 				renderer = new THREE.WebGPURenderer( { antialias: true } );
 				renderer.setPixelRatio( window.devicePixelRatio );
 				renderer.setSize( window.innerWidth, window.innerHeight );
 				renderer.setAnimationLoop( animate );
-				renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
+				renderer.toneMapping = THREE.LinearToneMapping;
 				document.body.appendChild( renderer.domElement );
 
+				await renderer.init();
+
+				const environment = new RoomEnvironment();
+				const pmremGenerator = new THREE.PMREMGenerator( renderer );
+
+				scene.environment = pmremGenerator.fromScene( environment ).texture;
+				pmremGenerator.dispose();
+
 				//
 
-				const controls = new OrbitControls( camera, renderer.domElement );
+				controls = new OrbitControls( camera, renderer.domElement );
+				controls.enableDamping = true;
 				controls.enableZoom = false;
+				controls.target.set( 0, 0.5, 0 );
+				controls.update();
 
 
 				// postprocessing
 
 				postProcessing = new THREE.PostProcessing( renderer );
+				postProcessing.outputColorTransform = false;
 
 				const scenePass = pass( scene, camera );
-				const scenePassColor = scenePass.getTextureNode();
 
-				postProcessing.outputNode = sobel( scenePassColor );
+				postProcessing.outputNode = sobel( renderOutput( scenePass ) );
 
 				//
 
 				const gui = new GUI();
 
-				gui.add( params, 'enable' );
+				gui.add( params, 'enabled' );
 				gui.open();
 
 				//
@@ -110,7 +118,9 @@
 
 			function animate() {
 
-				if ( params.enable === true ) {
+				controls.update();
+
+				if ( params.enabled === true ) {
 
 					postProcessing.render();
 

+ 1 - 0
test/e2e/puppeteer.js

@@ -158,6 +158,7 @@ const exceptionList = [
 	'webgpu_textures_anisotropy',
 	'webgpu_materials_envmaps_bpcem',
 	'webgpu_postprocessing_ssr',
+	'webgpu_postprocessing_sobel',
 
 	// WebGPU idleTime and parseTime too low
 	'webgpu_compute_particles',

粤ICP备19079148号