|
@@ -0,0 +1,196 @@
|
|
|
|
+<!DOCTYPE html>
|
|
|
|
+<html lang="en">
|
|
|
|
+ <head>
|
|
|
|
+ <title>three.js - WebGPU - Portal</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 - Portal
|
|
|
|
+ </div>
|
|
|
|
+
|
|
|
|
+ <script type="importmap">
|
|
|
|
+ {
|
|
|
|
+ "imports": {
|
|
|
|
+ "three": "../build/three.module.js",
|
|
|
|
+ "three/addons/": "./jsm/",
|
|
|
|
+ "three/nodes": "./jsm/nodes/Nodes.js"
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ </script>
|
|
|
|
+
|
|
|
|
+ <script type="module">
|
|
|
|
+
|
|
|
|
+ import * as THREE from 'three';
|
|
|
|
+ import { pass, color, mx_worley_noise_float, timerLocal, viewportTopLeft, vec2, uv, normalWorld, mx_fractal_noise_vec3, toneMapping, MeshBasicNodeMaterial } from 'three/nodes';
|
|
|
|
+
|
|
|
|
+ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
|
|
|
+
|
|
|
|
+ import WebGPU from 'three/addons/capabilities/WebGPU.js';
|
|
|
|
+
|
|
|
|
+ import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
|
|
|
|
+
|
|
|
|
+ import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
|
|
+
|
|
|
|
+ let camera, sceneMain, scenePortal, renderer;
|
|
|
|
+ let clock;
|
|
|
|
+
|
|
|
|
+ const mixers = [];
|
|
|
|
+
|
|
|
|
+ init();
|
|
|
|
+
|
|
|
|
+ function init() {
|
|
|
|
+
|
|
|
|
+ if ( WebGPU.isAvailable() === false ) {
|
|
|
|
+
|
|
|
|
+ document.body.appendChild( WebGPU.getErrorMessage() );
|
|
|
|
+
|
|
|
|
+ throw new Error( 'No WebGPU support' );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+
|
|
|
|
+ sceneMain = new THREE.Scene();
|
|
|
|
+ sceneMain.background = new THREE.Color( 0x222222 );
|
|
|
|
+ sceneMain.backgroundNode = normalWorld.y.mix( color( 0x0066ff ), color( 0xff0066 ) );
|
|
|
|
+
|
|
|
|
+ scenePortal = new THREE.Scene();
|
|
|
|
+ scenePortal.backgroundNode = mx_worley_noise_float( normalWorld.mul( 20 ).add( vec2( 0, timerLocal().oneMinus() ) ) ).mul( color( 0x0066ff ) );
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+
|
|
|
|
+ camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.01, 30 );
|
|
|
|
+ camera.position.set( 2.5, 1, 3 );
|
|
|
|
+ camera.position.multiplyScalar( .8 );
|
|
|
|
+ camera.lookAt( 0, 1, 0 );
|
|
|
|
+
|
|
|
|
+ clock = new THREE.Clock();
|
|
|
|
+
|
|
|
|
+ // lights
|
|
|
|
+
|
|
|
|
+ const light = new THREE.PointLight( 0xffffff, 1 );
|
|
|
|
+ light.position.set( 0, 1, 5 );
|
|
|
|
+ light.power = 17000;
|
|
|
|
+
|
|
|
|
+ sceneMain.add( new THREE.HemisphereLight( 0xff0066, 0x0066ff, 7 ) );
|
|
|
|
+ sceneMain.add( light );
|
|
|
|
+ scenePortal.add( light.clone() );
|
|
|
|
+
|
|
|
|
+ // models
|
|
|
|
+
|
|
|
|
+ const loader = new GLTFLoader();
|
|
|
|
+ loader.load( 'models/gltf/Xbot.glb', function ( gltf ) {
|
|
|
|
+
|
|
|
|
+ const createModel = ( colorNode = null ) => {
|
|
|
|
+
|
|
|
|
+ let object;
|
|
|
|
+
|
|
|
|
+ if ( mixers.length === 0 ) {
|
|
|
|
+
|
|
|
|
+ object = gltf.scene;
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ object = gltf.scene.clone();
|
|
|
|
+
|
|
|
|
+ const children = object.children[ 0 ].children;
|
|
|
|
+
|
|
|
|
+ const applyFX = ( index ) => {
|
|
|
|
+
|
|
|
|
+ children[ index ].material = children[ index ].material.clone();
|
|
|
|
+ children[ index ].material.colorNode = colorNode;
|
|
|
|
+ children[ index ].material.wireframe = true;
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ applyFX( 0 );
|
|
|
|
+ applyFX( 1 );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const mixer = new THREE.AnimationMixer( object );
|
|
|
|
+
|
|
|
|
+ const action = mixer.clipAction( gltf.animations[ 6 ] );
|
|
|
|
+ action.play();
|
|
|
|
+
|
|
|
|
+ mixers.push( mixer );
|
|
|
|
+
|
|
|
|
+ return object;
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const colorNode = mx_fractal_noise_vec3( uv().mul( 20 ).add( timerLocal() ) );
|
|
|
|
+
|
|
|
|
+ const modelMain = createModel();
|
|
|
|
+ const modelPortal = createModel( colorNode );
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+
|
|
|
|
+ sceneMain.add( modelMain );
|
|
|
|
+ scenePortal.add( modelPortal );
|
|
|
|
+
|
|
|
|
+ } );
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+
|
|
|
|
+ const geometry = new THREE.PlaneGeometry( 1.7, 2 );
|
|
|
|
+ const material = new MeshBasicNodeMaterial();
|
|
|
|
+ material.colorNode = pass( scenePortal, camera ).context( { getUV: () => viewportTopLeft } );
|
|
|
|
+ material.opacityNode = uv().distance( .5 ).remapClamp( .3, .5 ).oneMinus();
|
|
|
|
+ material.side = THREE.DoubleSide;
|
|
|
|
+ material.transparent = true;
|
|
|
|
+
|
|
|
|
+ const plane = new THREE.Mesh( geometry, material );
|
|
|
|
+ plane.position.set( 0, 1, .8 );
|
|
|
|
+ sceneMain.add( plane );
|
|
|
|
+
|
|
|
|
+ // renderer
|
|
|
|
+
|
|
|
|
+ renderer = new WebGPURenderer( { antialias: true } );
|
|
|
|
+ renderer.setPixelRatio( window.devicePixelRatio );
|
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
+ renderer.setAnimationLoop( animate );
|
|
|
|
+ renderer.toneMappingNode = toneMapping( THREE.LinearToneMapping, .15 );
|
|
|
|
+ document.body.appendChild( renderer.domElement );
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+
|
|
|
|
+ const controls = new OrbitControls( camera, renderer.domElement );
|
|
|
|
+ controls.target.set( 0, 1, 0 );
|
|
|
|
+ controls.update();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ window.addEventListener( 'resize', onWindowResize );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function onWindowResize() {
|
|
|
|
+
|
|
|
|
+ camera.aspect = window.innerWidth / window.innerHeight;
|
|
|
|
+ camera.updateProjectionMatrix();
|
|
|
|
+
|
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function animate() {
|
|
|
|
+
|
|
|
|
+ const delta = clock.getDelta();
|
|
|
|
+
|
|
|
|
+ for ( const mixer of mixers ) {
|
|
|
|
+
|
|
|
|
+ mixer.update( delta );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ renderer.render( sceneMain, camera );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ </script>
|
|
|
|
+ </body>
|
|
|
|
+</html>
|