Преглед изворни кода

Examples: Combine LUT with coffee smoke demo. (#30390)

Michael Herzog пре 1 година
родитељ
комит
0d34438c39

+ 0 - 1
examples/files.json

@@ -431,7 +431,6 @@
 		"webgpu_textures_partialupdate",
 		"webgpu_tonemapping",
 		"webgpu_tsl_angular_slicing",
-		"webgpu_tsl_coffee_smoke",
 		"webgpu_tsl_compute_attractors_particles",
 		"webgpu_tsl_earth",
 		"webgpu_tsl_editor",

BIN
examples/screenshots/webgpu_postprocessing_3dlut.jpg


BIN
examples/screenshots/webgpu_tsl_coffee_smoke.jpg


+ 111 - 45
examples/webgpu_postprocessing_3dlut.html

@@ -6,13 +6,12 @@
 		<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="info">
-			<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - 3D LUTs<br />
-			Battle Damaged Sci-fi Helmet by
-			<a href="https://sketchfab.com/theblueturtle_" target="_blank" rel="noopener">theblueturtle_</a><br />
-			<a href="https://hdrihaven.com/hdri/?h=royal_esplanade" target="_blank" rel="noopener">Royal Esplanade</a> from <a href="https://hdrihaven.com/" target="_blank" rel="noopener">HDRI Haven</a><br />
+			<a href="https://threejs.org" target="_blank" rel="noopener">three.js webgpu</a> - post processing - 3D LUTs<br />
+			Based on <a href="https://threejs-journey.com/lessons/coffee-smoke-shader" target="_blank" rel="noopener">Three.js Journey</a> lesson<br />
+			Perlin noise texture from <a href="http://kitfox.com/projects/perlinNoiseMaker/" target="_blank" rel="noopener">Perlin Noise Maker</a>, 
 			LUTs from <a href="https://www.rocketstock.com/free-after-effects-templates/35-free-luts-for-color-grading-videos/">RocketStock</a>, <a href="https://www.freepresets.com/product/free-luts-cinematic/">FreePresets.com</a>
 		</div>
 
@@ -30,12 +29,11 @@
 		<script type="module">
 
 			import * as THREE from 'three';
-			import { pass, texture3D, uniform, renderOutput } from 'three/tsl';
+			import { mix, mul, oneMinus, positionLocal, smoothstep, texture, time, rotateUV, Fn, uv, vec2, vec3, vec4, pass, texture3D, uniform, renderOutput } from 'three/tsl';
 			import { lut3D } from 'three/addons/tsl/display/Lut3DNode.js';
 
 			import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
 			import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
-			import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
 			import { LUTCubeLoader } from 'three/addons/loaders/LUTCubeLoader.js';
 			import { LUT3dlLoader } from 'three/addons/loaders/LUT3dlLoader.js';
 			import { LUTImageLoader } from 'three/addons/loaders/LUTImageLoader.js';
@@ -58,41 +56,23 @@
 				'NightLUT': null
 			};
 
-			let gui;
-			let camera, scene, renderer;
-			let postProcessing, lutPass;
+			let camera, scene, renderer, postProcessing, controls, lutPass;
 
 			init();
 
 			async function init() {
 
-				const container = document.createElement( 'div' );
-				document.body.appendChild( container );
-
-				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );
-				camera.position.set( - 1.8, 0.6, 2.7 );
+				camera = new THREE.PerspectiveCamera( 25, window.innerWidth / window.innerHeight, 0.1, 100 );
+				camera.position.set( 8, 10, 12 );
 
 				scene = new THREE.Scene();
 
-				new RGBELoader()
-					.setPath( 'textures/equirectangular/' )
-					.load( 'royal_esplanade_1k.hdr', function ( texture ) {
-
-						texture.mapping = THREE.EquirectangularReflectionMapping;
-
-						scene.background = texture;
-						scene.environment = texture;
-
-						// model
+				// Loaders
 
-						const loader = new GLTFLoader().setPath( 'models/gltf/DamagedHelmet/glTF/' );
-						loader.load( 'DamagedHelmet.gltf', function ( gltf ) {
+				const gltfLoader = new GLTFLoader();
+				const textureLoader = new THREE.TextureLoader();
 
-							scene.add( gltf.scene );
-
-						} );
-
-					} );
+				// LUTs
 
 				const lutCubeLoader = new LUTCubeLoader();
 				const lutImageLoader = new LUTImageLoader();
@@ -125,12 +105,97 @@
 
 				}
 
-				renderer = new THREE.WebGPURenderer();
+				// baked model
+
+				gltfLoader.load(
+					'./models/gltf/coffeeMug.glb',
+					( gltf ) => {
+
+        				gltf.scene.getObjectByName( 'baked' ).material.map.anisotropy = 8;
+						scene.add( gltf.scene );
+
+					}
+				);
+
+				// geometry
+
+				const smokeGeometry = new THREE.PlaneGeometry( 1, 1, 16, 64 );
+				smokeGeometry.translate( 0, 0.5, 0 );
+				smokeGeometry.scale( 1.5, 6, 1.5 );
+
+				// texture
+
+				const noiseTexture = textureLoader.load( './textures/noises/perlin/128x128.png' );
+				noiseTexture.wrapS = THREE.RepeatWrapping;
+				noiseTexture.wrapT = THREE.RepeatWrapping;
+
+				// material
+
+				const smokeMaterial = new THREE.MeshBasicNodeMaterial( { transparent: true, side: THREE.DoubleSide, depthWrite: false } );
+
+				// position
+
+				smokeMaterial.positionNode = Fn( () => {
+
+					// twist
+
+					const twistNoiseUv = vec2( 0.5, uv().y.mul( 0.2 ).sub( time.mul( 0.005 ) ).mod( 1 ) );
+					const twist = texture( noiseTexture, twistNoiseUv ).r.mul( 10 );
+					positionLocal.xz.assign( rotateUV( positionLocal.xz, twist, vec2( 0 ) ) );
+
+					// wind
+
+					const windOffset = vec2(
+						texture( noiseTexture, vec2( 0.25, time.mul( 0.01 ) ).mod( 1 ) ).r.sub( 0.5 ),
+						texture( noiseTexture, vec2( 0.75, time.mul( 0.01 ) ).mod( 1 ) ).r.sub( 0.5 ),
+					).mul( uv().y.pow( 2 ).mul( 10 ) );
+					positionLocal.addAssign( windOffset );
+
+					return positionLocal;
+
+				} )();
+
+				// color
+
+				smokeMaterial.colorNode = Fn( () => {
+
+					// alpha
+
+					const alphaNoiseUv = uv().mul( vec2( 0.5, 0.3 ) ).add( vec2( 0, time.mul( 0.03 ).negate() ) );
+					const alpha = mul(
+
+						// pattern
+						texture( noiseTexture, alphaNoiseUv ).r.smoothstep( 0.4, 1 ),
+
+						// edges fade
+						smoothstep( 0, 0.1, uv().x ),
+						smoothstep( 0, 0.1, oneMinus( uv().x ) ),
+						smoothstep( 0, 0.1, uv().y ),
+						smoothstep( 0, 0.1, oneMinus( uv().y ) )
+
+					);
+
+					// color
+
+					const finalColor = mix( vec3( 0.6, 0.3, 0.2 ), vec3( 1, 1, 1 ), alpha.pow( 3 ) );
+
+					return vec4( finalColor, alpha );
+
+				} )();
+
+				// mesh
+
+				const smoke = new THREE.Mesh( smokeGeometry, smokeMaterial );
+				smoke.position.y = 1.83;
+				scene.add( smoke );
+
+				// renderer
+
+				renderer = new THREE.WebGPURenderer( { antialias: true } );
 				renderer.setPixelRatio( window.devicePixelRatio );
 				renderer.setSize( window.innerWidth, window.innerHeight );
 				renderer.setAnimationLoop( animate );
-				renderer.toneMapping = THREE.ACESFilmicToneMapping;
-				container.appendChild( renderer.domElement );
+				document.body.appendChild( renderer.domElement );
 
 				// post processing
 
@@ -151,15 +216,17 @@
 
 				postProcessing.outputNode = lutPass;
 
-				//
+				// controls
 
-				const controls = new OrbitControls( camera, renderer.domElement );
-				controls.minDistance = 2;
-				controls.maxDistance = 10;
-				controls.target.set( 0, 0, - 0.2 );
-				controls.update();
+				controls = new OrbitControls( camera, renderer.domElement );
+				controls.enableDamping = true;
+				controls.minDistance = 0.1;
+				controls.maxDistance = 50;
+				controls.target.y = 3;
+
+				// gui
 
-				gui = new GUI();
+				const gui = new GUI();
 				gui.add( params, 'lut', Object.keys( lutMap ) );
 				gui.add( params, 'intensity' ).min( 0 ).max( 1 );
 
@@ -176,9 +243,9 @@
 
 			}
 
-			//
+			async function animate() {
 
-			function animate() {
+				controls.update();
 
 				lutPass.intensityNode.value = params.intensity;
 
@@ -195,6 +262,5 @@
 			}
 
 		</script>
-
 	</body>
 </html>

+ 0 - 177
examples/webgpu_tsl_coffee_smoke.html

@@ -1,177 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-	<head>
-		<title>three.js webgpu - coffee smoke</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="info">
-			<a href="https://threejs.org" target="_blank" rel="noopener">three.js webgpu</a> - coffee smoke
-			<br>
-			Based on <a href="https://threejs-journey.com/lessons/coffee-smoke-shader" target="_blank" rel="noopener">Three.js Journey</a> lesson
-			<br>
-			Perlin noise texture from <a href="http://kitfox.com/projects/perlinNoiseMaker/" target="_blank" rel="noopener">Perlin Noise Maker</a>
-		</div>
-
-		<script type="importmap">
-			{
-				"imports": {
-					"three": "../build/three.webgpu.js",
-					"three/webgpu": "../build/three.webgpu.js",
-					"three/tsl": "../build/three.tsl.js",
-					"three/addons/": "./jsm/"
-				}
-			}
-		</script>
-
-		<script type="module">
-
-			import * as THREE from 'three';
-			import { mix, mul, oneMinus, positionLocal, smoothstep, texture, time, rotateUV, Fn, uv, vec2, vec3, vec4 } from 'three/tsl';
-
-			import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
-			import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
-
-			let camera, scene, renderer, controls;
-
-			init();
-
-			function init() {
-
-				camera = new THREE.PerspectiveCamera( 25, window.innerWidth / window.innerHeight, 0.1, 100 );
-				camera.position.set( 8, 10, 12 );
-
-				scene = new THREE.Scene();
-
-				// Loaders
-
-				const gltfLoader = new GLTFLoader();
-				const textureLoader = new THREE.TextureLoader();
-
-				// baked model
-
-				gltfLoader.load(
-					'./models/gltf/coffeeMug.glb',
-					( gltf ) => {
-
-        				gltf.scene.getObjectByName( 'baked' ).material.map.anisotropy = 8;
-						scene.add( gltf.scene );
-
-					}
-				);
-
-				// geometry
-
-				const smokeGeometry = new THREE.PlaneGeometry( 1, 1, 16, 64 );
-				smokeGeometry.translate( 0, 0.5, 0 );
-				smokeGeometry.scale( 1.5, 6, 1.5 );
-
-				// texture
-
-				const noiseTexture = textureLoader.load( './textures/noises/perlin/128x128.png' );
-				noiseTexture.wrapS = THREE.RepeatWrapping;
-				noiseTexture.wrapT = THREE.RepeatWrapping;
-
-				// material
-
-				const smokeMaterial = new THREE.MeshBasicNodeMaterial( { transparent: true, side: THREE.DoubleSide, depthWrite: false } );
-
-				// position
-
-				smokeMaterial.positionNode = Fn( () => {
-
-					// twist
-
-					const twistNoiseUv = vec2( 0.5, uv().y.mul( 0.2 ).sub( time.mul( 0.005 ) ).mod( 1 ) );
-					const twist = texture( noiseTexture, twistNoiseUv ).r.mul( 10 );
-					positionLocal.xz.assign( rotateUV( positionLocal.xz, twist, vec2( 0 ) ) );
-
-					// wind
-
-					const windOffset = vec2(
-						texture( noiseTexture, vec2( 0.25, time.mul( 0.01 ) ).mod( 1 ) ).r.sub( 0.5 ),
-						texture( noiseTexture, vec2( 0.75, time.mul( 0.01 ) ).mod( 1 ) ).r.sub( 0.5 ),
-					).mul( uv().y.pow( 2 ).mul( 10 ) );
-					positionLocal.addAssign( windOffset );
-
-					return positionLocal;
-
-				} )();
-
-				// color
-
-				smokeMaterial.colorNode = Fn( () => {
-
-					// alpha
-
-					const alphaNoiseUv = uv().mul( vec2( 0.5, 0.3 ) ).add( vec2( 0, time.mul( 0.03 ).negate() ) );
-					const alpha = mul(
-
-						// pattern
-						texture( noiseTexture, alphaNoiseUv ).r.smoothstep( 0.4, 1 ),
-
-						// edges fade
-						smoothstep( 0, 0.1, uv().x ),
-						smoothstep( 0, 0.1, oneMinus( uv().x ) ),
-						smoothstep( 0, 0.1, uv().y ),
-						smoothstep( 0, 0.1, oneMinus( uv().y ) )
-
-					);
-
-					// color
-
-					const finalColor = mix( vec3( 0.6, 0.3, 0.2 ), vec3( 1, 1, 1 ), alpha.pow( 3 ) );
-
-					return vec4( finalColor, alpha );
-
-				} )();
-
-				// mesh
-
-				const smoke = new THREE.Mesh( smokeGeometry, smokeMaterial );
-				smoke.position.y = 1.83;
-				scene.add( smoke );
-
-				// renderer
-
-				renderer = new THREE.WebGPURenderer( { antialias: true } );
-				renderer.setPixelRatio( window.devicePixelRatio );
-				renderer.setSize( window.innerWidth, window.innerHeight );
-				renderer.setAnimationLoop( animate );
-				document.body.appendChild( renderer.domElement );
-
-				// controls
-
-				controls = new OrbitControls( camera, renderer.domElement );
-				controls.enableDamping = true;
-				controls.minDistance = 0.1;
-				controls.maxDistance = 50;
-				controls.target.y = 3;
-
-				window.addEventListener( 'resize', onWindowResize );
-
-			}
-
-			function onWindowResize() {
-
-				camera.aspect = window.innerWidth / window.innerHeight;
-				camera.updateProjectionMatrix();
-
-				renderer.setSize( window.innerWidth, window.innerHeight );
-
-			}
-
-			async function animate() {
-
-				controls.update();
-
-				renderer.render( scene, camera );
-
-			}
-
-		</script>
-	</body>
-</html>

+ 1 - 1
test/e2e/puppeteer.js

@@ -148,7 +148,6 @@ const exceptionList = [
 	'webgpu_texturegrad',
 	'webgpu_performance_renderbundle',
 	'webgpu_lights_rectarealight',
-	'webgpu_tsl_coffee_smoke',
 	'webgpu_tsl_vfx_flames',
 	'webgpu_tsl_halftone',
 	'webgpu_tsl_vfx_linkedparticles',
@@ -157,6 +156,7 @@ const exceptionList = [
 	'webgpu_rendertarget_2d-array_3d',
 	'webgpu_materials_envmaps_bpcem',
 	'webgpu_postprocessing_sobel',
+	'webgpu_postprocessing_3dlut',
 
 	// WebGPU idleTime and parseTime too low
 	'webgpu_compute_particles',

粤ICP备19079148号