|
@@ -0,0 +1,190 @@
|
|
|
+<html lang="en">
|
|
|
+ <head>
|
|
|
+ <title>Sheen demo (material property)</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">
|
|
|
+ <style>
|
|
|
+ body {
|
|
|
+ color: #333;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+ </head>
|
|
|
+ <body>
|
|
|
+ <div id="info">Sheen demo by <a href="https://github.com/DanielSturk">DanielSturk</a></div>
|
|
|
+ <div id="container"></div>
|
|
|
+
|
|
|
+ <script src="js/libs/ammo.js"></script>
|
|
|
+
|
|
|
+ <script type="module">
|
|
|
+
|
|
|
+ import * as THREE from '../build/three.module.js';
|
|
|
+
|
|
|
+ import * as Nodes from './jsm/nodes/Nodes.js';
|
|
|
+
|
|
|
+ import Stats from './jsm/libs/stats.module.js';
|
|
|
+ import { GUI } from './jsm/libs/dat.gui.module.js';
|
|
|
+
|
|
|
+ import { OrbitControls } from './jsm/controls/OrbitControls.js';
|
|
|
+
|
|
|
+ import { FBXLoader } from './jsm/loaders/FBXLoader.js';
|
|
|
+
|
|
|
+ // Graphics variables
|
|
|
+ var camera, controls, scene, renderer, stats;
|
|
|
+ var directionalLight;
|
|
|
+ var mesh, sphere, material, nodeMaterial;
|
|
|
+
|
|
|
+ var params = {
|
|
|
+ nodeMaterial: true,
|
|
|
+ color: new THREE.Color( 255, 0, 127 ),
|
|
|
+ sheenBRDF: true,
|
|
|
+ sheenColor: new THREE.Color( 10, 10, 10 ), // corresponds to .04 reflectance
|
|
|
+ roughness: .9,
|
|
|
+ exposure: 2,
|
|
|
+ };
|
|
|
+
|
|
|
+ // model
|
|
|
+ new FBXLoader().load( 'models/fbx/cloth.fbx', function ( loadedModel ) {
|
|
|
+
|
|
|
+ mesh = loadedModel.children[0];
|
|
|
+
|
|
|
+ init();
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ function init( ) {
|
|
|
+
|
|
|
+ camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.2, 2000 );
|
|
|
+
|
|
|
+ scene = new THREE.Scene();
|
|
|
+ scene.background = new THREE.Color( 0xbfd1e5 );
|
|
|
+
|
|
|
+ mesh.scale.multiplyScalar( .5 );
|
|
|
+ scene.add( mesh );
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ material = new THREE.MeshPhysicalMaterial();
|
|
|
+ material.side = THREE.DoubleSide;
|
|
|
+ material.metalness = 0;
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ nodeMaterial = new Nodes.StandardNodeMaterial();
|
|
|
+ nodeMaterial.side = THREE.DoubleSide;
|
|
|
+ nodeMaterial.metalness = new Nodes.FloatNode( 0 );
|
|
|
+ nodeMaterial.roughness = new Nodes.FloatNode();
|
|
|
+ nodeMaterial.color = new Nodes.ColorNode( params.color.clone() );
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ sphere = new THREE.Mesh(
|
|
|
+ new THREE.SphereBufferGeometry( 1, 100, 100 ),
|
|
|
+ material
|
|
|
+ );
|
|
|
+ scene.add(sphere);
|
|
|
+
|
|
|
+ camera.position.set( - 12, 7, 4 );
|
|
|
+
|
|
|
+ var container = document.getElementById( 'container' );
|
|
|
+ renderer = new THREE.WebGLRenderer();
|
|
|
+ renderer.setPixelRatio( window.devicePixelRatio );
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
+ renderer.shadowMap.enabled = true;
|
|
|
+ container.appendChild( renderer.domElement );
|
|
|
+
|
|
|
+ controls = new OrbitControls( camera, renderer.domElement );
|
|
|
+ controls.target.set( 0, 2, 0 );
|
|
|
+ controls.update();
|
|
|
+
|
|
|
+ directionalLight = new THREE.DirectionalLight( 0xffffff, .5 );
|
|
|
+ directionalLight.position.set( 0, 10, 0 );
|
|
|
+ directionalLight.castShadow = true;
|
|
|
+ directionalLight.add(
|
|
|
+ new THREE.Mesh(
|
|
|
+ new THREE.SphereBufferGeometry( .5 ),
|
|
|
+ new THREE.MeshBasicMaterial( { color: 0xffffff } )
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ scene.add( directionalLight );
|
|
|
+
|
|
|
+ stats = new Stats();
|
|
|
+ stats.domElement.style.position = 'absolute';
|
|
|
+ stats.domElement.style.top = '0px';
|
|
|
+ container.appendChild( stats.dom );
|
|
|
+
|
|
|
+ window.addEventListener( 'resize', onWindowResize, false );
|
|
|
+
|
|
|
+ var gui = new GUI();
|
|
|
+
|
|
|
+ gui.add( params, 'nodeMaterial' );
|
|
|
+ gui.addColor( params, 'color' );
|
|
|
+ gui.add( params, 'sheenBRDF' );
|
|
|
+ gui.addColor( params, 'sheenColor' );
|
|
|
+ gui.add( params, 'roughness', 0, 1 );
|
|
|
+ gui.add( params, 'exposure', 0, 3 );
|
|
|
+ gui.open();
|
|
|
+
|
|
|
+ animate();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function onWindowResize() {
|
|
|
+
|
|
|
+ camera.aspect = window.innerWidth / window.innerHeight;
|
|
|
+ camera.updateProjectionMatrix();
|
|
|
+
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function animate() {
|
|
|
+
|
|
|
+ requestAnimationFrame( animate );
|
|
|
+
|
|
|
+ render();
|
|
|
+ stats.update();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function render() {
|
|
|
+
|
|
|
+ mesh.material = sphere.material = params.nodeMaterial
|
|
|
+ ? nodeMaterial
|
|
|
+ : material;
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ material.sheenColor = params.sheenBRDF
|
|
|
+ ? new THREE.Color().copy( params.sheenColor ).multiplyScalar( 1 / 255 )
|
|
|
+ : null;
|
|
|
+
|
|
|
+ material.color.copy( params.color ).multiplyScalar( 1 / 255 );
|
|
|
+ material.roughness = params.roughness;
|
|
|
+
|
|
|
+ material.needsUpdate = true;
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ nodeMaterial.sheenColor = params.sheenBRDF
|
|
|
+ ? new Nodes.ColorNode( material.sheenColor )
|
|
|
+ : undefined;
|
|
|
+
|
|
|
+ nodeMaterial.color.value.copy( material.color );
|
|
|
+
|
|
|
+ nodeMaterial.roughness.value = params.roughness;
|
|
|
+
|
|
|
+ nodeMaterial.needsCompile = true;
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ renderer.toneMappingExposure = params.exposure;
|
|
|
+ renderer.render( scene, camera );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ </script>
|
|
|
+
|
|
|
+ </body>
|
|
|
+</html>
|