|
@@ -0,0 +1,209 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+ <head>
|
|
|
+ <title>three.js - WebGPU - Selective Lights</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">
|
|
|
+ <link rel="stylesheet" href="fonts/open-sans/open-sans.css" type="text/css"/>
|
|
|
+ <link rel="stylesheet" href="fonts/tabler-icons/tabler-icons.min.css" type="text/css"/>
|
|
|
+ <!-- WebGPU (For Chrome 94-101), expires 09/01/2022 -->
|
|
|
+ <meta http-equiv="origin-trial" content="AoS1pSJwCV3KRe73TO0YgJkK9FZ/qhmvKeafztp0ofiE8uoGrnKzfxGVKKICvoBfL8dgE0zpkp2g/oEJNS0fDgkAAABeeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJHUFUiLCJleHBpcnkiOjE2NTI4MzE5OTksImlzU3ViZG9tYWluIjp0cnVlfQ==">
|
|
|
+ <style>
|
|
|
+body {
|
|
|
+ overflow: hidden;
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+}
|
|
|
+.renderer {
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ height: 50%;
|
|
|
+ width: 100%;
|
|
|
+}
|
|
|
+flow {
|
|
|
+ position: absolute;
|
|
|
+ top: 50%;
|
|
|
+ left: 0;
|
|
|
+ height: 50%;
|
|
|
+ width: 100%;
|
|
|
+ background: #222;
|
|
|
+ box-shadow: inset 0 0 20px 0px #000000;
|
|
|
+}
|
|
|
+ </style>
|
|
|
+ </head>
|
|
|
+ <body>
|
|
|
+
|
|
|
+ <div id="info">
|
|
|
+ <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - WebGPU - Node Editor ( Playground version )<br />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <script type="importmap">
|
|
|
+ {
|
|
|
+ "imports": {
|
|
|
+ "three": "../build/three.module.js"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ </script>
|
|
|
+ <script type="module">
|
|
|
+
|
|
|
+ import * as THREE from 'three';
|
|
|
+
|
|
|
+ import WebGPURenderer from './jsm/renderers/webgpu/WebGPURenderer.js';
|
|
|
+ import WebGPU from './jsm/renderers/webgpu/WebGPU.js';
|
|
|
+
|
|
|
+ import { NodeEditor } from './jsm/node-editor/NodeEditor.js';
|
|
|
+ import { StandardMaterialEditor } from './jsm/node-editor/materials/StandardMaterialEditor.js';
|
|
|
+
|
|
|
+ import * as Nodes from './jsm/renderers/nodes/Nodes.js';
|
|
|
+
|
|
|
+ import Stats from './jsm/libs/stats.module.js';
|
|
|
+
|
|
|
+ import { OrbitControls } from './jsm/controls/OrbitControls.js';
|
|
|
+ import { FBXLoader } from './jsm/loaders/FBXLoader.js';
|
|
|
+
|
|
|
+ let stats;
|
|
|
+ let camera, scene, renderer;
|
|
|
+ let model;
|
|
|
+ let nodeLights;
|
|
|
+
|
|
|
+ init().then( animate ).catch( error => console.error( error ) );
|
|
|
+
|
|
|
+ async function init() {
|
|
|
+
|
|
|
+ if ( WebGPU.isAvailable() === false ) {
|
|
|
+
|
|
|
+ document.body.appendChild( WebGPU.getErrorMessage() );
|
|
|
+
|
|
|
+ throw 'No WebGPU support';
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 5000 );
|
|
|
+ camera.position.set( 0.0, 300, 400 * 3 );
|
|
|
+
|
|
|
+ scene = new THREE.Scene();
|
|
|
+ scene.background = new THREE.Color( 0x333333 );
|
|
|
+
|
|
|
+ // Lights
|
|
|
+
|
|
|
+ const topLight = new THREE.PointLight( 0xF4F6F0, 1 );
|
|
|
+ topLight.position.set( 0, 100000, 100000 );
|
|
|
+ scene.add( topLight );
|
|
|
+
|
|
|
+ const backLight = new THREE.PointLight( 0x0c1445, 1.4 );
|
|
|
+ backLight.position.set( - 100, 20, - 260 );
|
|
|
+ scene.add( backLight );
|
|
|
+
|
|
|
+ nodeLights = Nodes.LightsNode.fromLights( [ topLight, backLight ] );
|
|
|
+
|
|
|
+ renderer = new WebGPURenderer();
|
|
|
+ renderer.setPixelRatio( window.devicePixelRatio );
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
+ document.body.appendChild( renderer.domElement );
|
|
|
+ renderer.outputEncoding = THREE.sRGBEncoding;
|
|
|
+
|
|
|
+ renderer.domElement.className = 'renderer';
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ stats = new Stats();
|
|
|
+ document.body.appendChild( stats.dom );
|
|
|
+
|
|
|
+ const controls = new OrbitControls( camera, renderer.domElement );
|
|
|
+ controls.minDistance = 500;
|
|
|
+ controls.maxDistance = 3000;
|
|
|
+
|
|
|
+ window.addEventListener( 'resize', onWindowResize );
|
|
|
+
|
|
|
+ onWindowResize();
|
|
|
+
|
|
|
+ initEditor();
|
|
|
+
|
|
|
+ return renderer.init();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function initEditor() {
|
|
|
+
|
|
|
+ const nodeEditor = new NodeEditor();
|
|
|
+
|
|
|
+ nodeEditor.addEventListener( 'new', () => {
|
|
|
+
|
|
|
+ const materialEditor = new StandardMaterialEditor();
|
|
|
+ materialEditor.setPosition( ( window.innerWidth / 2 ) - 150, 100 );
|
|
|
+
|
|
|
+ nodeEditor.add( materialEditor );
|
|
|
+
|
|
|
+ model.material = materialEditor.material;
|
|
|
+ model.material.lightNode = nodeLights;
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ nodeEditor.addEventListener( 'load', () => {
|
|
|
+
|
|
|
+ const materialEditor = nodeEditor.nodes[ 0 ];
|
|
|
+ materialEditor.update(); // need move to deserialization
|
|
|
+
|
|
|
+ model.material = materialEditor.material;
|
|
|
+ model.material.lightNode = nodeLights;
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ document.body.appendChild( nodeEditor.domElement );
|
|
|
+
|
|
|
+ const loaderFBX = new FBXLoader();
|
|
|
+ loaderFBX.load( 'models/fbx/stanford-bunny.fbx', ( object ) => {
|
|
|
+
|
|
|
+ const materialEditor = new StandardMaterialEditor();
|
|
|
+ materialEditor.setPosition( ( window.innerWidth / 2 ) - 150, 100 ); // canvas position
|
|
|
+
|
|
|
+ nodeEditor.add( materialEditor );
|
|
|
+
|
|
|
+ model = object.children[ 0 ];
|
|
|
+ model.position.set( 0, 0, 10 );
|
|
|
+ model.scale.setScalar( 1 );
|
|
|
+ model.material = materialEditor.material;
|
|
|
+ model.material.lightNode = nodeLights;
|
|
|
+ scene.add( model );
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function onWindowResize() {
|
|
|
+
|
|
|
+ const width = window.innerWidth;
|
|
|
+ const height = window.innerHeight / 2;
|
|
|
+
|
|
|
+ camera.aspect = width / height;
|
|
|
+ camera.updateProjectionMatrix();
|
|
|
+
|
|
|
+ renderer.setSize( width, height );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ function animate() {
|
|
|
+
|
|
|
+ requestAnimationFrame( animate );
|
|
|
+
|
|
|
+ render();
|
|
|
+
|
|
|
+ stats.update();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function render() {
|
|
|
+
|
|
|
+ //if ( model ) model.rotation.y = performance.now() / 5000;
|
|
|
+
|
|
|
+ renderer.render( scene, camera );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ </script>
|
|
|
+ </body>
|
|
|
+</html>
|