-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16971 from DanielSturk/sheen
MeshPhysicalMaterial: Added sheen
- Loading branch information
Showing
15 changed files
with
282 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.