|
@@ -8,6 +8,7 @@ import {
|
|
|
} from '../../../../../build/three.module.js';
|
|
} from '../../../../../build/three.module.js';
|
|
|
|
|
|
|
|
import { Node } from '../../core/Node.js';
|
|
import { Node } from '../../core/Node.js';
|
|
|
|
|
+import { ExpressionNode } from '../../core/ExpressionNode.js';
|
|
|
import { ColorNode } from '../../inputs/ColorNode.js';
|
|
import { ColorNode } from '../../inputs/ColorNode.js';
|
|
|
import { FloatNode } from '../../inputs/FloatNode.js';
|
|
import { FloatNode } from '../../inputs/FloatNode.js';
|
|
|
import { RoughnessToBlinnExponentNode } from '../../bsdfs/RoughnessToBlinnExponentNode.js';
|
|
import { RoughnessToBlinnExponentNode } from '../../bsdfs/RoughnessToBlinnExponentNode.js';
|
|
@@ -32,7 +33,7 @@ StandardNode.prototype.build = function ( builder ) {
|
|
|
|
|
|
|
|
var code;
|
|
var code;
|
|
|
|
|
|
|
|
- builder.define( this.clearCoat || this.clearCoatRoughness ? 'PHYSICAL' : 'STANDARD' );
|
|
|
|
|
|
|
+ builder.define( this.clearcoat || this.clearcoatRoughness || this.clearcoatNormal ? 'PHYSICAL' : 'STANDARD' );
|
|
|
|
|
|
|
|
builder.requires.lights = true;
|
|
builder.requires.lights = true;
|
|
|
|
|
|
|
@@ -122,6 +123,7 @@ StandardNode.prototype.build = function ( builder ) {
|
|
|
|
|
|
|
|
var contextEnvironment = {
|
|
var contextEnvironment = {
|
|
|
bias: RoughnessToBlinnExponentNode,
|
|
bias: RoughnessToBlinnExponentNode,
|
|
|
|
|
+ viewNormal: new ExpressionNode('normal', 'v3'),
|
|
|
gamma: true
|
|
gamma: true
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -129,7 +131,13 @@ StandardNode.prototype.build = function ( builder ) {
|
|
|
gamma: true
|
|
gamma: true
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- var useClearCoat = ! builder.isDefined( 'STANDARD' );
|
|
|
|
|
|
|
+ var contextClearcoatEnvironment = {
|
|
|
|
|
+ bias: RoughnessToBlinnExponentNode,
|
|
|
|
|
+ viewNormal: new ExpressionNode('clearcoatNormal', 'v3'),
|
|
|
|
|
+ gamma: true
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ var useClearcoat = ! builder.isDefined( 'STANDARD' );
|
|
|
|
|
|
|
|
// analyze all nodes to reuse generate codes
|
|
// analyze all nodes to reuse generate codes
|
|
|
|
|
|
|
@@ -143,8 +151,9 @@ StandardNode.prototype.build = function ( builder ) {
|
|
|
|
|
|
|
|
if ( this.normal ) this.normal.analyze( builder );
|
|
if ( this.normal ) this.normal.analyze( builder );
|
|
|
|
|
|
|
|
- if ( this.clearCoat ) this.clearCoat.analyze( builder );
|
|
|
|
|
- if ( this.clearCoatRoughness ) this.clearCoatRoughness.analyze( builder );
|
|
|
|
|
|
|
+ if ( this.clearcoat ) this.clearcoat.analyze( builder );
|
|
|
|
|
+ if ( this.clearcoatRoughness ) this.clearcoatRoughness.analyze( builder );
|
|
|
|
|
+ if ( this.clearcoatNormal ) this.clearcoatNormal.analyze( builder );
|
|
|
|
|
|
|
|
if ( this.reflectivity ) this.reflectivity.analyze( builder );
|
|
if ( this.reflectivity ) this.reflectivity.analyze( builder );
|
|
|
|
|
|
|
@@ -160,16 +169,18 @@ StandardNode.prototype.build = function ( builder ) {
|
|
|
// isolate environment from others inputs ( see TextureNode, CubeTextureNode )
|
|
// isolate environment from others inputs ( see TextureNode, CubeTextureNode )
|
|
|
// environment.analyze will detect if there is a need of calculate irradiance
|
|
// environment.analyze will detect if there is a need of calculate irradiance
|
|
|
|
|
|
|
|
- this.environment.analyze( builder, { cache: 'radiance', context: contextEnvironment, slot: 'radiance' } );
|
|
|
|
|
|
|
+ this.environment.analyze( builder, { cache: 'radiance', context: contextEnvironment, slot: 'radiance' } );
|
|
|
|
|
|
|
|
if ( builder.requires.irradiance ) {
|
|
if ( builder.requires.irradiance ) {
|
|
|
|
|
|
|
|
- this.environment.analyze( builder, { cache: 'irradiance', context: contextEnvironment, slot: 'irradiance' } );
|
|
|
|
|
|
|
+ this.environment.analyze( builder, { cache: 'irradiance', context: contextEnvironment, slot: 'irradiance' } );
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if ( this.sheen ) this.sheen.analyze( builder );
|
|
|
|
|
+
|
|
|
// build code
|
|
// build code
|
|
|
|
|
|
|
|
var mask = this.mask ? this.mask.flow( builder, 'b' ) : undefined;
|
|
var mask = this.mask ? this.mask.flow( builder, 'b' ) : undefined;
|
|
@@ -182,8 +193,9 @@ StandardNode.prototype.build = function ( builder ) {
|
|
|
|
|
|
|
|
var normal = this.normal ? this.normal.flow( builder, 'v3' ) : undefined;
|
|
var normal = this.normal ? this.normal.flow( builder, 'v3' ) : undefined;
|
|
|
|
|
|
|
|
- var clearCoat = this.clearCoat ? this.clearCoat.flow( builder, 'f' ) : undefined;
|
|
|
|
|
- var clearCoatRoughness = this.clearCoatRoughness ? this.clearCoatRoughness.flow( builder, 'f' ) : undefined;
|
|
|
|
|
|
|
+ var clearcoat = this.clearcoat ? this.clearcoat.flow( builder, 'f' ) : undefined;
|
|
|
|
|
+ var clearcoatRoughness = this.clearcoatRoughness ? this.clearcoatRoughness.flow( builder, 'f' ) : undefined;
|
|
|
|
|
+ var clearcoatNormal = this.clearcoatNormal ? this.clearcoatNormal.flow( builder, 'v3' ) : undefined;
|
|
|
|
|
|
|
|
var reflectivity = this.reflectivity ? this.reflectivity.flow( builder, 'f' ) : undefined;
|
|
var reflectivity = this.reflectivity ? this.reflectivity.flow( builder, 'f' ) : undefined;
|
|
|
|
|
|
|
@@ -210,7 +222,9 @@ StandardNode.prototype.build = function ( builder ) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var clearCoatEnv = useClearCoat && environment ? this.environment.flow( builder, 'c', { cache: 'clearCoat', context: contextEnvironment, slot: 'environment' } ) : undefined;
|
|
|
|
|
|
|
+ var clearcoatEnv = useClearcoat && environment ? this.environment.flow( builder, 'c', { cache: 'clearcoat', context: contextClearcoatEnvironment, slot: 'environment' } ) : undefined;
|
|
|
|
|
+
|
|
|
|
|
+ var sheen = this.sheen ? this.sheen.flow( builder, 'c' ) : undefined;
|
|
|
|
|
|
|
|
builder.requires.transparent = alpha !== undefined;
|
|
builder.requires.transparent = alpha !== undefined;
|
|
|
|
|
|
|
@@ -238,6 +252,7 @@ StandardNode.prototype.build = function ( builder ) {
|
|
|
|
|
|
|
|
// add before: prevent undeclared normal
|
|
// add before: prevent undeclared normal
|
|
|
" #include <normal_fragment_begin>",
|
|
" #include <normal_fragment_begin>",
|
|
|
|
|
+ " #include <clearcoat_normal_fragment_begin>",
|
|
|
|
|
|
|
|
// add before: prevent undeclared material
|
|
// add before: prevent undeclared material
|
|
|
" PhysicalMaterial material;",
|
|
" PhysicalMaterial material;",
|
|
@@ -289,6 +304,15 @@ StandardNode.prototype.build = function ( builder ) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if ( clearcoatNormal ) {
|
|
|
|
|
+
|
|
|
|
|
+ output.push(
|
|
|
|
|
+ clearcoatNormal.code,
|
|
|
|
|
+ 'clearcoatNormal = ' + clearcoatNormal.result + ';'
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// optimization for now
|
|
// optimization for now
|
|
|
|
|
|
|
|
output.push(
|
|
output.push(
|
|
@@ -296,29 +320,35 @@ StandardNode.prototype.build = function ( builder ) {
|
|
|
'material.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );'
|
|
'material.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );'
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- if ( clearCoat ) {
|
|
|
|
|
|
|
+ if ( clearcoat ) {
|
|
|
|
|
|
|
|
output.push(
|
|
output.push(
|
|
|
- clearCoat.code,
|
|
|
|
|
- 'material.clearCoat = saturate( ' + clearCoat.result + ' );'
|
|
|
|
|
|
|
+ clearcoat.code,
|
|
|
|
|
+ 'material.clearcoat = saturate( ' + clearcoat.result + ' );'
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- } else if ( useClearCoat ) {
|
|
|
|
|
|
|
+ } else if ( useClearcoat ) {
|
|
|
|
|
|
|
|
- output.push( 'material.clearCoat = 0.0;' );
|
|
|
|
|
|
|
+ output.push( 'material.clearcoat = 0.0;' );
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if ( clearCoatRoughness ) {
|
|
|
|
|
|
|
+ if ( clearcoatRoughness ) {
|
|
|
|
|
|
|
|
output.push(
|
|
output.push(
|
|
|
- clearCoatRoughness.code,
|
|
|
|
|
- 'material.clearCoatRoughness = clamp( ' + clearCoatRoughness.result + ', 0.04, 1.0 );'
|
|
|
|
|
|
|
+ clearcoatRoughness.code,
|
|
|
|
|
+ 'material.clearcoatRoughness = clamp( ' + clearcoatRoughness.result + ', 0.04, 1.0 );'
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- } else if ( useClearCoat ) {
|
|
|
|
|
|
|
+ } else if ( useClearcoat ) {
|
|
|
|
|
|
|
|
- output.push( 'material.clearCoatRoughness = 0.0;' );
|
|
|
|
|
|
|
+ output.push( 'material.clearcoatRoughness = 0.0;' );
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ( sheen ) {
|
|
|
|
|
+
|
|
|
|
|
+ output.push( 'material.sheenColor = ' + sheen.result + ';' );
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -408,11 +438,11 @@ StandardNode.prototype.build = function ( builder ) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if ( clearCoatEnv ) {
|
|
|
|
|
|
|
+ if ( clearcoatEnv ) {
|
|
|
|
|
|
|
|
output.push(
|
|
output.push(
|
|
|
- clearCoatEnv.code,
|
|
|
|
|
- "clearCoatRadiance += " + clearCoatEnv.result + ";"
|
|
|
|
|
|
|
+ clearcoatEnv.code,
|
|
|
|
|
+ "clearcoatRadiance += " + clearcoatEnv.result + ";"
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -479,8 +509,9 @@ StandardNode.prototype.copy = function ( source ) {
|
|
|
|
|
|
|
|
if ( source.normal ) this.normal = source.normal;
|
|
if ( source.normal ) this.normal = source.normal;
|
|
|
|
|
|
|
|
- if ( source.clearCoat ) this.clearCoat = source.clearCoat;
|
|
|
|
|
- if ( source.clearCoatRoughness ) this.clearCoatRoughness = source.clearCoatRoughness;
|
|
|
|
|
|
|
+ if ( source.clearcoat ) this.clearcoat = source.clearcoat;
|
|
|
|
|
+ if ( source.clearcoatRoughness ) this.clearcoatRoughness = source.clearcoatRoughness;
|
|
|
|
|
+ if ( source.clearcoatNormal ) this.clearcoatNormal = source.clearcoatNormal;
|
|
|
|
|
|
|
|
if ( source.reflectivity ) this.reflectivity = source.reflectivity;
|
|
if ( source.reflectivity ) this.reflectivity = source.reflectivity;
|
|
|
|
|
|
|
@@ -494,6 +525,8 @@ StandardNode.prototype.copy = function ( source ) {
|
|
|
|
|
|
|
|
if ( source.environment ) this.environment = source.environment;
|
|
if ( source.environment ) this.environment = source.environment;
|
|
|
|
|
|
|
|
|
|
+ if ( source.sheen ) this.sheen = source.sheen;
|
|
|
|
|
+
|
|
|
return this;
|
|
return this;
|
|
|
|
|
|
|
|
};
|
|
};
|
|
@@ -522,8 +555,9 @@ StandardNode.prototype.toJSON = function ( meta ) {
|
|
|
|
|
|
|
|
if ( this.normal ) data.normal = this.normal.toJSON( meta ).uuid;
|
|
if ( this.normal ) data.normal = this.normal.toJSON( meta ).uuid;
|
|
|
|
|
|
|
|
- if ( this.clearCoat ) data.clearCoat = this.clearCoat.toJSON( meta ).uuid;
|
|
|
|
|
- if ( this.clearCoatRoughness ) data.clearCoatRoughness = this.clearCoatRoughness.toJSON( meta ).uuid;
|
|
|
|
|
|
|
+ if ( this.clearcoat ) data.clearcoat = this.clearcoat.toJSON( meta ).uuid;
|
|
|
|
|
+ if ( this.clearcoatRoughness ) data.clearcoatRoughness = this.clearcoatRoughness.toJSON( meta ).uuid;
|
|
|
|
|
+ if ( this.clearcoatNormal ) data.clearcoatNormal = this.clearcoatNormal.toJSON( meta ).uuid;
|
|
|
|
|
|
|
|
if ( this.reflectivity ) data.reflectivity = this.reflectivity.toJSON( meta ).uuid;
|
|
if ( this.reflectivity ) data.reflectivity = this.reflectivity.toJSON( meta ).uuid;
|
|
|
|
|
|
|
@@ -537,6 +571,8 @@ StandardNode.prototype.toJSON = function ( meta ) {
|
|
|
|
|
|
|
|
if ( this.environment ) data.environment = this.environment.toJSON( meta ).uuid;
|
|
if ( this.environment ) data.environment = this.environment.toJSON( meta ).uuid;
|
|
|
|
|
|
|
|
|
|
+ if ( this.sheen ) data.sheen = this.sheen.toJSON( meta ).uuid;
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
return data;
|