Browse Source

Separated the meanings of PHYSICAL

arobertson0 6 years ago
parent
commit
f7ffa206d1

+ 11 - 4
examples/jsm/nodes/materials/nodes/StandardNode.js

@@ -32,7 +32,15 @@ StandardNode.prototype.build = function ( builder ) {
 
 	var code;
 
-	builder.define( this.clearCoat || this.clearCoatRoughness || this.clearCoatNormal ? 'PHYSICAL' : 'STANDARD' );
+	builder.define('PHYSICAL');
+
+	var useClearCoat = this.clearCoat;
+
+	if( useClearCoat ){
+
+		builder.define( 'CLEARCOAT' );
+
+	}
 
 	builder.requires.lights = true;
 
@@ -129,7 +137,6 @@ StandardNode.prototype.build = function ( builder ) {
 			gamma: true
 		};
 
-		var useClearCoat = ! builder.isDefined( 'STANDARD' );
 
 		// analyze all nodes to reuse generate codes
 
@@ -161,11 +168,11 @@ StandardNode.prototype.build = function ( builder ) {
 			// isolate environment from others inputs ( see TextureNode, CubeTextureNode )
 			// 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 ) {
 
-				this.environment.analyze( builder, { cache: 'irradiance', context: contextEnvironment, slot: 'irradiance' } ); 
+				this.environment.analyze( builder, { cache: 'irradiance', context: contextEnvironment, slot: 'irradiance' } );
 
 			}
 

+ 6 - 1
src/materials/MeshPhysicalMaterial.js

@@ -18,7 +18,12 @@ function MeshPhysicalMaterial( parameters ) {
 
 	MeshStandardMaterial.call( this );
 
-	this.defines = { 'PHYSICAL': '' };
+	this.defines = {
+
+		'PHYSICAL': '',
+		'ADVANCED_PHYSICAL': ''
+
+	};
 
 	this.type = 'MeshPhysicalMaterial';
 

+ 1 - 1
src/materials/MeshStandardMaterial.js

@@ -123,7 +123,7 @@ MeshStandardMaterial.prototype.copy = function ( source ) {
 
 	Material.prototype.copy.call( this, source );
 
-	this.defines = { 'STANDARD': '' };
+	this.defines = { 'PHYSICAL': '' };
 
 	this.color.copy( source.color );
 	this.roughness = source.roughness;

+ 1 - 1
src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_begin.glsl.js

@@ -1,5 +1,5 @@
 export default /* glsl */`
-#ifdef PHYSICAL
+#ifdef CLEARCOAT
 
 	vec3 clearCoatNormal = geometryNormal;
 

+ 1 - 1
src/renderers/shaders/ShaderChunk/common.glsl.js

@@ -39,7 +39,7 @@ struct GeometricContext {
 	vec3 position;
 	vec3 normal;
 	vec3 viewDir;
-#ifdef PHYSICAL
+#ifdef CLEARCOAT
 	vec3 clearCoatNormal;
 #endif
 };

+ 1 - 1
src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js

@@ -20,7 +20,7 @@ geometry.position = - vViewPosition;
 geometry.normal = normal;
 geometry.viewDir = normalize( vViewPosition );
 
-#ifdef PHYSICAL
+#ifdef CLEARCOAT
 
 	geometry.clearCoatNormal = clearCoatNormal;
 

+ 1 - 1
src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js

@@ -27,7 +27,7 @@ export default /* glsl */`
 
 	radiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.normal, Material_BlinnShininessExponent( material ), maxMipLevel );
 
-	#ifdef PHYSICAL
+	#ifdef CLEARCOAT
 
 		clearCoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.clearCoatNormal, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );
 

+ 11 - 3
src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js

@@ -2,10 +2,18 @@ export default /* glsl */`
 PhysicalMaterial material;
 material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
 material.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );
-#ifdef STANDARD
-	material.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );
-#else
+
+#ifdef REFLECTIVITY
+
 	material.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );
+
+#else
+
+	material.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );
+
+#endif
+
+#ifdef CLEARCOAT
 	material.clearCoat = saturate( clearCoat ); // Burley clearcoat model
 	material.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );
 #endif

+ 3 - 3
src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js

@@ -5,7 +5,7 @@ struct PhysicalMaterial {
 	float	specularRoughness;
 	vec3	specularColor;
 
-	#ifdef PHYSICAL
+	#ifdef CLEARCOAT
 		float clearCoat;
 		float clearCoatRoughness;
 	#endif
@@ -76,7 +76,7 @@ void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricC
 
 	#endif
 
-	#ifdef PHYSICAL
+	#ifdef CLEARCOAT
 
 		float ccDotNL = saturate( dot( geometry.clearCoatNormal, directLight.direction ) );
 
@@ -111,7 +111,7 @@ void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricCo
 
 void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {
 
-	#ifdef PHYSICAL
+	#ifdef CLEARCOAT
 
 		float ccDotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
 

+ 7 - 1
src/renderers/shaders/ShaderLib/meshphysical_frag.glsl.js

@@ -1,13 +1,19 @@
 export default /* glsl */`
 #define PHYSICAL
 
+#ifdef ADVANCED_PHYSICAL
+	#define REFLECTIVITY
+	#define CLEARCOAT
+	// TODO: ANISOTROPY and SHEEN when merged
+#endif
+
 uniform vec3 diffuse;
 uniform vec3 emissive;
 uniform float roughness;
 uniform float metalness;
 uniform float opacity;
 
-#ifdef PHYSICAL
+#ifdef CLEARCOAT
 	uniform float clearCoat;
 	uniform float clearCoatRoughness;
 #endif