提交 94894c12 编写于 作者: M Mr.doob

MeshPhysicalMaterial: Initialise sheen by default and only use when is not black.

上级 b67fb442
......@@ -37,7 +37,6 @@
var params = {
nodeMaterial: true,
color: new THREE.Color( 255, 0, 127 ),
sheenBRDF: true,
sheen: new THREE.Color( 10, 10, 10 ), // corresponds to .04 reflectance
roughness: .9,
exposure: 2,
......@@ -46,7 +45,7 @@
// model
new FBXLoader().load( 'models/fbx/cloth.fbx', function ( loadedModel ) {
mesh = loadedModel.children[0];
mesh = loadedModel.children[ 0 ];
init();
......@@ -75,6 +74,7 @@
nodeMaterial.metalness = new Nodes.FloatNode( 0 );
nodeMaterial.roughness = new Nodes.FloatNode();
nodeMaterial.color = new Nodes.ColorNode( params.color.clone() );
nodeMaterial.sheen = new Nodes.ColorNode( params.sheen.clone() );
//
......@@ -82,7 +82,7 @@
new THREE.SphereBufferGeometry( 1, 100, 100 ),
material
);
scene.add(sphere);
scene.add( sphere );
camera.position.set( - 12, 7, 4 );
......@@ -120,28 +120,27 @@
function onUpdate() {
mesh.material = sphere.material = params.nodeMaterial
? nodeMaterial
: material;
mesh.material = sphere.material = params.nodeMaterial ? nodeMaterial : material;
material.sheen = params.sheenBRDF
? new THREE.Color()
: null;
}
function onSheenUpdate() {
var newSheenEnabled = params.color.r > 0 || params.color.g > 0 || params.color.b > 0;
var oldSheenEnabled = material.sheen.r > 0 || material.sheen.g > 0 || material.sheen.b > 0;
material.needsUpdate = true;
if ( newSheenEnabled !== oldSheenEnabled ) {
nodeMaterial.sheen = params.sheenBRDF
? new Nodes.ColorNode( material.sheen )
: undefined;
material.needsUpdate = true;
nodeMaterial.needsCompile = true;
nodeMaterial.needsCompile = true;
}
}
gui.add( params, 'nodeMaterial' ).onChange( onUpdate );
gui.addColor( params, 'color' );
gui.add( params, 'sheenBRDF' ).onChange( onUpdate );
gui.addColor( params, 'sheen' );
gui.addColor( params, 'sheen' ).onChange( onSheenUpdate );
gui.add( params, 'roughness', 0, 1 );
gui.add( params, 'exposure', 0, 3 );
gui.open();
......@@ -172,26 +171,18 @@
function render() {
//
material.color.copy( params.color ).multiplyScalar( 1 / 255 );
material.sheen.copy( params.sheen ).multiplyScalar( 1 / 255 );
material.roughness = params.roughness;
//
nodeMaterial.color.value.copy( material.color );
nodeMaterial.sheen.value.copy( params.sheen ).multiplyScalar( 1 / 255 );
nodeMaterial.roughness.value = params.roughness;
//
if ( params.sheenBRDF ) {
material.sheen.copy( params.sheen ).multiplyScalar( 1 / 255 );
}
//
renderer.toneMappingExposure = params.exposure;
renderer.render( scene, camera );
......
......@@ -169,12 +169,12 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
if ( this.roughness !== undefined ) data.roughness = this.roughness;
if ( this.metalness !== undefined ) data.metalness = this.metalness;
if ( this.sheen && this.sheen.isColor ) data.sheen = this.sheen.getHex();
if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
if ( this.shininess !== undefined ) data.shininess = this.shininess;
if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;
if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;
......@@ -185,6 +185,8 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
}
if ( this.sheen && this.sheen.isColor ) data.sheen = this.sheen.getHex();
if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
......
......@@ -27,7 +27,7 @@ export class MeshPhysicalMaterial extends MeshStandardMaterial {
clearcoat: number;
clearcoatRoughness: number;
sheen: Color | null;
sheen: Color;
clearcoatNormalScale: Vector2;
clearcoatNormalMap: Texture | null;
......
......@@ -35,7 +35,7 @@ function MeshPhysicalMaterial( parameters ) {
this.clearcoat = 0.0;
this.clearcoatRoughness = 0.0;
this.sheen = null; // null will disable sheen bsdf
this.sheen = new Color( 0x000000 );
this.clearcoatNormalScale = new Vector2( 1, 1 );
this.clearcoatNormalMap = null;
......@@ -67,8 +67,7 @@ MeshPhysicalMaterial.prototype.copy = function ( source ) {
this.clearcoat = source.clearcoat;
this.clearcoatRoughness = source.clearcoatRoughness;
if ( source.sheen ) this.sheen = ( this.sheen || new Color() ).copy( source.sheen );
else this.sheen = null;
this.sheen.copy( source.sheen );
this.clearcoatNormalMap = source.clearcoatNormalMap;
this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
......
......@@ -2385,7 +2385,7 @@ function WebGLRenderer( parameters ) {
uniforms.clearcoat.value = material.clearcoat;
uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
if ( material.sheen ) uniforms.sheen.value.copy( material.sheen );
uniforms.sheen.value.copy( material.sheen );
if ( material.clearcoatNormalMap ) {
......
......@@ -179,7 +179,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
gradientMap: !! material.gradientMap,
sheen: !! material.sheen,
sheen: material.sheen && ( material.sheen.r > 0 || material.sheen.g > 0 || material.sheen.b > 0 ),
combine: material.combine,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册