123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgpu - materialx noise</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</a> webgpu - materialx noise
- </div>
- <script type="importmap">
- {
- "imports": {
- "three": "../build/three.webgpu.js",
- "three/tsl": "../build/three.webgpu.js",
- "three/addons/": "./jsm/"
- }
- }
- </script>
- <script type="module">
- import * as THREE from 'three';
- import { normalWorld, timerLocal, mx_noise_vec3, mx_worley_noise_vec3, mx_cell_noise_float, mx_fractal_noise_vec3 } from 'three/tsl';
- import Stats from 'three/addons/libs/stats.module.js';
- import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
- import { HDRCubeTextureLoader } from 'three/addons/loaders/HDRCubeTextureLoader.js';
- let container, stats;
- let camera, scene, renderer;
- let particleLight;
- let group;
- init();
- function init() {
- container = document.createElement( 'div' );
- document.body.appendChild( container );
- camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 1, 1000 );
- camera.position.z = 100;
- scene = new THREE.Scene();
- group = new THREE.Group();
- scene.add( group );
- new HDRCubeTextureLoader()
- .setPath( 'textures/cube/pisaHDR/' )
- .load( [ 'px.hdr', 'nx.hdr', 'py.hdr', 'ny.hdr', 'pz.hdr', 'nz.hdr' ],
- function ( hdrTexture ) {
- const geometry = new THREE.SphereGeometry( 8, 64, 32 );
- const offsetNode = timerLocal();
- const customUV = normalWorld.mul( 10 ).add( offsetNode );
- // left top
- let material = new THREE.MeshPhysicalNodeMaterial();
- material.colorNode = mx_noise_vec3( customUV );
- let mesh = new THREE.Mesh( geometry, material );
- mesh.position.x = - 10;
- mesh.position.y = 10;
- group.add( mesh );
- // right top
- material = new THREE.MeshPhysicalNodeMaterial();
- material.colorNode = mx_cell_noise_float( customUV );
- mesh = new THREE.Mesh( geometry, material );
- mesh.position.x = 10;
- mesh.position.y = 10;
- group.add( mesh );
- // left bottom
- material = new THREE.MeshPhysicalNodeMaterial();
- material.colorNode = mx_worley_noise_vec3( customUV );
- mesh = new THREE.Mesh( geometry, material );
- mesh.position.x = - 10;
- mesh.position.y = - 10;
- group.add( mesh );
- // right bottom
- material = new THREE.MeshPhysicalNodeMaterial();
- material.colorNode = mx_fractal_noise_vec3( customUV.mul( .2 ) );
- mesh = new THREE.Mesh( geometry, material );
- mesh.position.x = 10;
- mesh.position.y = - 10;
- group.add( mesh );
- //
- scene.background = hdrTexture;
- scene.environment = hdrTexture;
- }
- );
- // LIGHTS
- particleLight = new THREE.Mesh(
- new THREE.SphereGeometry( 0.4, 8, 8 ),
- new THREE.MeshBasicMaterial( { color: 0xffffff } )
- );
- scene.add( particleLight );
- particleLight.add( new THREE.PointLight( 0xffffff, 1000 ) );
- renderer = new THREE.WebGPURenderer( { antialias: true } );
- renderer.setAnimationLoop( animate );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- container.appendChild( renderer.domElement );
- //
- renderer.toneMapping = THREE.ACESFilmicToneMapping;
- renderer.toneMappingExposure = 1.25;
- //
- //
- stats = new Stats();
- container.appendChild( stats.dom );
- // EVENTS
- new OrbitControls( camera, renderer.domElement );
- window.addEventListener( 'resize', onWindowResize );
- }
- //
- function onWindowResize() {
- const width = window.innerWidth;
- const height = window.innerHeight;
- camera.aspect = width / height;
- camera.updateProjectionMatrix();
- renderer.setSize( width, height );
- }
- //
- function animate() {
- render();
- stats.update();
- }
- function render() {
- const timer = Date.now() * 0.00025;
- particleLight.position.x = Math.sin( timer * 7 ) * 30;
- particleLight.position.y = Math.cos( timer * 5 ) * 40;
- particleLight.position.z = Math.cos( timer * 3 ) * 30;
- for ( let i = 0; i < group.children.length; i ++ ) {
- const child = group.children[ i ];
- child.rotation.y += 0.005;
- }
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|