1
0
Эх сурвалжийг харах

SSRNode: Honor `metalness`. (#29605)

Michael Herzog 1 жил өмнө
parent
commit
5e3e26aed8

+ 3 - 1
examples/jsm/tsl/display/SSRNode.js

@@ -293,10 +293,12 @@ class SSRNode extends TempNode {
 
 						} );
 
+						const op = this.opacity.mul( metalness ).toVar();
+
 						// distance attenuation (the reflection should fade out the farther it is away from the surface)
 						const ratio = float( 1 ).sub( distance.div( this.maxDistance ) ).toVar();
 						const attenuation = ratio.mul( ratio );
-						const op = this.opacity.mul( attenuation ).toVar();
+						op.mulAssign( attenuation );
 
 						// fresnel (reflect more light on surfaces that are viewed at grazing angles)
 						const fresnelCoe = div( dot( viewIncidentDir, viewReflectDir ).add( 1 ), 2 );

BIN
examples/screenshots/webgpu_postprocessing_ssr.jpg


+ 36 - 31
examples/webgpu_postprocessing_ssr.html

@@ -29,16 +29,14 @@
 
 	<script type="module">
 		import * as THREE from 'three';
-		import { pass, mrt, output, transformedNormalView, metalness, vec4 } from 'three/tsl';
+		import { pass, mrt, output, transformedNormalView, metalness, vec4/*, uniform*/ } from 'three/tsl';
 		import { ssr } from 'three/addons/tsl/display/SSRNode.js';
 
-		import Stats from 'three/addons/libs/stats.module.js';
-
+		import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.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 { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
+		import Stats from 'three/addons/libs/stats.module.js';
 
 		const params = {
 			maxDistance: 0.1,
@@ -58,40 +56,37 @@
 
 		init();
 
-		function init() {
+		async function init() {
 
 			camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 0.1, 15 );
-			camera.position.set( 0.1, 0.3, 0.5 );
+			camera.position.set( 0.1, 0.2, 0.5 );
 
 			scene = new THREE.Scene();
-			scene.background = new THREE.Color( 0x443333 );
-			scene.fog = new THREE.Fog( 0x443333, 1, 4 );
+			scene.fog = new THREE.Fog( 0x666666, 1, 4 );
 
 			// Ground
 			const plane = new THREE.Mesh(
 				new THREE.PlaneGeometry( 8, 8 ),
-				new THREE.MeshPhongMaterial( { color: 0xcbcbcb } )
+				new THREE.MeshStandardNodeMaterial( { color: 0xcbcbcb } )
 			);
+		
+			// any node material can write custom MRT metalness values for controlling SSR
+
+			// plane.material.mrtNode = mrt( {
+			// 	output: output,
+			// 	normal: transformedNormalView,
+			// 	metalness: uniform( 0.5 )
+			// } );
+		
 			plane.rotation.x = - Math.PI / 2;
 			plane.position.y = - 0.0001;
 			scene.add( plane );
 
-			// Lights
-			const hemiLight = new THREE.HemisphereLight( 0x8d7c7c, 0x494966, 3 );
-			scene.add( hemiLight );
-
-			const spotLight = new THREE.SpotLight();
-			spotLight.intensity = 8;
-			spotLight.angle = Math.PI / 16;
-			spotLight.penumbra = 0.5;
-			spotLight.position.set( - 1, 1, 1 );
-			scene.add( spotLight );
-
 			dracoLoader.load( 'models/draco/bunny.drc', function ( geometry ) {
 
 				geometry.computeVertexNormals();
 
-				const material = new THREE.MeshStandardMaterial( { color: 0xa5a5a5, metalness: 0.01 } );
+				const material = new THREE.MeshStandardNodeMaterial( { color: 0xa5a5a5, metalness: 1 } );
 				const mesh = new THREE.Mesh( geometry, material );
 				mesh.position.y = - 0.0365;
 				scene.add( mesh );
@@ -102,22 +97,22 @@
 
 			let geometry, material, mesh;
 
-			geometry = new THREE.BoxGeometry( .05, .05, .05 );
-			material = new THREE.MeshStandardMaterial( { color: 'green', metalness: 0.01 } );
+			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( - .12, .025, .015 );
+			mesh.position.set( - 0.12, 0.025, 0.015 );
 			scene.add( mesh );
 
 			geometry = new THREE.IcosahedronGeometry( .025, 4 );
-			material = new THREE.MeshStandardMaterial( { color: 'cyan', metalness: 0.01 } );
+			material = new THREE.MeshStandardNodeMaterial( { color: 'cyan', metalness: 0.5 } );
 			mesh = new THREE.Mesh( geometry, material );
-			mesh.position.set( - .05, .025, .08 );
+			mesh.position.set( - 0.05, 0.025, 0.08 );
 			scene.add( mesh );
 		
-			geometry = new THREE.ConeGeometry( .025, .05, 64 );
-			material = new THREE.MeshStandardMaterial( { color: 'yellow', metalness: 0.01 } );
+			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( - .05, .025, - .055 );
+			mesh.position.set( - 0.05, 0.025, - 0.055 );
 			scene.add( mesh );
 
 			//
@@ -128,6 +123,16 @@
 			renderer.setAnimationLoop( animate );
 			document.body.appendChild( renderer.domElement );
 
+			await renderer.init();
+
+			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();
+
 			//
 
 			postProcessing = new THREE.PostProcessing( renderer );

粤ICP备19079148号