2
0
Эх сурвалжийг харах

Refactoring of cc normal code

arobertson0 6 жил өмнө
parent
commit
b39e2c96e9

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 82 - 205
build/three.js


+ 82 - 205
build/three.module.js

@@ -14489,15 +14489,15 @@ float D_GGX( const in float alpha, const in float dotNH ) {
 }
 
 // GGX Distribution, Schlick Fresnel, GGX-Smith Visibility
-vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
+vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {
 
 	float alpha = pow2( roughness ); // UE4's roughness
 
-	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
+	vec3 halfDir = normalize( incidentLight.direction + viewDir );
 
-	float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );
-	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
-	float dotNH = saturate( dot( geometry.normal, halfDir ) );
+	float dotNL = saturate( dot( normal, incidentLight.direction ) );
+	float dotNV = saturate( dot( normal, viewDir ) );
+	float dotNH = saturate( dot( normal, halfDir ) );
 	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
 
 	vec3 F = F_Schlick( specularColor, dotLH );
@@ -14510,29 +14510,6 @@ vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in Geometric
 
 } // validated
 
-#ifndef STANDARD
-vec3 BRDF_ClearCoat_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
-
-	float alpha = pow2( roughness ); // UE4's roughness
-
-	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
-
-	float dotNL = saturate( dot( geometry.clearCoatNormal, incidentLight.direction ) );
-	float dotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
-	float dotNH = saturate( dot( geometry.clearCoatNormal, halfDir ) );
-	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
-
-	vec3 F = F_Schlick( specularColor, dotLH );
-
-	float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );
-
-	float D = D_GGX( alpha, dotNH );
-
-	return F * ( G * D );
-
-}
-#endif
-
 // Rect Area Light
 
 // Real-Time Polygonal-Light Shading with Linearly Transformed Cosines
@@ -14651,9 +14628,9 @@ vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in m
 // End Rect Area Light
 
 // ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile
-vec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
+vec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {
 
-	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
+	float dotNV = saturate( dot( normal, viewDir ) );
 
 	vec2 brdf = integrateSpecularBRDF( dotNV, roughness );
 
@@ -14661,17 +14638,6 @@ vec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in
 
 } // validated
 
-#ifndef STANDARD
-vec3 BRDF_ClearCoat_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
-
-	float dotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
-
-	vec2 brdf = integrateSpecularBRDF( dotNV, roughness );
-
-	return specularColor * brdf.x + brdf.y;
-}
-#endif
-
 // Fdez-Agüera's "Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting"
 // Approximates multiscattering in order to preserve energy.
 // http://www.jcgt.org/published/0008/01/03/
@@ -14796,8 +14762,12 @@ struct GeometricContext {
 	vec3 normal;
 	vec3 viewDir;
 
-  #ifndef STANDARD
-	vec3 clearCoatNormal;
+	#ifndef STANDARD
+		#ifdef USE_CLEARCOAT_NORMALMAP
+
+			vec3 clearCoatNormal;
+			
+		#endif
   #endif
 };
 
@@ -15107,38 +15077,49 @@ float clearCoatDHRApprox( const in float roughness, const in float dotNL ) {
 #endif
 
 void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
-
+ // TODO: refactor more
 	float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
 	vec3 irradiance = dotNL * directLight.color;
 
-	#ifndef STANDARD
-		float ccDotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
-		float ccDotNL = ccDotNV;
-		vec3 ccIrradiance= ccDotNL * directLight.color;
-	#endif
-
 	#ifndef PHYSICALLY_CORRECT_LIGHTS
 
 		irradiance *= PI; // punctual light
-		#ifndef STANDARD
-			ccIrradiance *= PI; // punctual light
+
+	#endif
+
+	#ifndef STANDARD
+		#ifdef USE_CLEARCOAT_NORMALMAP
+			float ccDotNL = saturate( dot( geometry.clearCoatNormal, directLight.direction ) );
+			vec3 ccIrradiance = ccDotNL * directLight.color;
+
+			#ifndef PHYSICALLY_CORRECT_LIGHTS
+
+				ccIrradiance *= PI; // punctual light
+
+			#endif
 		#endif
 	#endif
 
 	#ifndef STANDARD
-		float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
+		#ifdef USE_CLEARCOAT_NORMALMAP
+			float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
+		#else
+			float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );
+		#endif
 	#else
 		float clearCoatDHR = 0.0;
 	#endif
 
-	reflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );
+	reflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness );
 
 	reflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
 
 	#ifndef STANDARD
-
-		reflectedLight.directSpecular += ccIrradiance * material.clearCoat * BRDF_ClearCoat_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
-
+		#ifdef USE_CLEARCOAT_NORMALMAP
+			reflectedLight.directSpecular += ccIrradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearCoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
+		#else
+			reflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
+		#endif
 	#endif
 
 }
@@ -15158,7 +15139,11 @@ 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) {
 
 	#ifndef STANDARD
-		float ccDotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
+		#ifdef USE_CLEARCOAT_NORMALMAP
+			float ccDotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
+		#else
+			float ccDotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
+		#endif
 		float ccDotNL = ccDotNV;
 		float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
 	#else
@@ -15185,14 +15170,16 @@ void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradia
 
 	#else
 
-		reflectedLight.indirectSpecular += clearCoatInv * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );
+		reflectedLight.indirectSpecular += clearCoatInv * radiance * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness );
 
 	#endif
 
 	#ifndef STANDARD
-
-	reflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_ClearCoat_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
-
+		#ifdef USE_CLEARCOAT_NORMALMAP
+			reflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.clearCoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
+		#else
+			reflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.normal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
+		#endif
 	#endif
 }
 
@@ -15234,8 +15221,14 @@ geometry.position = - vViewPosition;
 geometry.normal = normal;
 geometry.viewDir = normalize( vViewPosition );
 
-#if defined( PHYSICAL ) && !defined( STANDARD )
-	geometry.clearCoatNormal = clearCoatNormal;
+#ifdef PHYSICAL
+	#ifndef STANDARD
+		#ifdef USE_CLEARCOAT_NORMALMAP
+		
+			geometry.clearCoatNormal = clearCoatNormal;
+
+		#endif
+	#endif
 #endif
 IncidentLight directLight;
 
@@ -15339,7 +15332,7 @@ IncidentLight directLight;
 
 	vec3 radiance = vec3( 0.0 );
 	vec3 clearCoatRadiance = vec3( 0.0 );
-
+	
 #endif
 `;
 
@@ -15373,9 +15366,12 @@ var lights_fragment_maps = /* glsl */ `
   radiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.normal, Material_BlinnShininessExponent( material ), maxMipLevel );
 
 	#ifndef STANDARD
-	  clearCoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.clearCoatNormal,Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );
+		#ifdef USE_CLEARCOAT_NORMALMAP
+			clearCoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.clearCoatNormal, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );
+		#else
+			clearCoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.normal, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );
+		#endif
 	#endif
-
 #endif
 `;
 
@@ -15461,7 +15457,7 @@ var normalmap_pars_fragment = /* glsl */ `
 	#endif
 #endif
 
-#if ( defined ( USE_NORMALMAP ) && !defined ( OBJECTSPACE_NORMALMAP )) || ( defined ( USE_CLEARCOAT_NORMALMAP ) && !defined ( OBJECTSPACE_CLEARCOAT_NORMALMAP ) )
+#if ( defined ( USE_NORMALMAP ) && !defined ( OBJECTSPACE_NORMALMAP )) || defined ( USE_CLEARCOAT_NORMALMAP )
 
 		// Per-Pixel Tangent Space Normal Mapping
 		// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
@@ -15493,11 +15489,11 @@ var normalmap_pars_fragment = /* glsl */ `
 #endif
 `;
 
-var clearcoat_normal_fragment_begin = "#ifndef STANDARD\n  vec3 clearCoatNormal = geometryNormal;\n#endif";
+var clearcoat_normal_fragment_begin = "#ifndef STANDARD\n  #ifdef USE_CLEARCOAT_NORMALMAP\n    vec3 clearCoatNormal = geometryNormal;\n  #endif\n#endif";
 
 var clearcoat_normal_fragment_maps = /* glsl */ `
 #ifndef STANDARD
-	#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
+	#ifdef USE_CLEARCOAT_NORMALMAP
 
 		#ifdef USE_TANGENT
 
@@ -15514,124 +15510,17 @@ var clearcoat_normal_fragment_maps = /* glsl */ `
 	#endif
 #endif
 `;
-/*
-#if defined( USE_NORMALMAP )
-
-	#ifdef USE_TANGENT
-
-		mat3 vTBN = mat3( tangent, bitangent, normal );
-		vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
-		mapN.xy = clearCoatnormalScale * mapN.xy;
-		clearCoatNormal = normalize( vTBN * mapN );
-
-	#else
-
-	  clearCoatNormal = perturbClearCoatNormal2Arb( -vViewPosition, clearCoatNormal );
-
-	#endif
-#endif
-*/
-/*
-#if defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )
-
-	//#ifdef OBJECTSPACE_NORMALMAP
-
-		normal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0; // overrides both flatShading and attribute normals
-
-		#ifdef FLIP_SIDED
-
-			normal = - normal;
-
-		#endif
-
-		#ifdef DOUBLE_SIDED
-
-			normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
-
-		#endif
-
-		normal = normalize( normalMatrix * normal );
-
-	//#else // tangent-space normal map
-
-		#ifdef USE_TANGENT
-
-			mat3 vTBN = mat3( tangent, bitangent, normal );
-			vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
-			mapN.xy = normalScale * mapN.xy;
-			normal = normalize( vTBN * mapN );
-
-		#else
-
-			normal = perturbNormal2Arb( -vViewPosition, normal );
-
-		#endif
-
-	//#endif
-
-#elif defined( USE_BUMPMAP )
-
-	normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );
-
-#endif
-*/
 
 var clearcoat_normalmap_pars_fragment = /* glsl */ `
 #ifndef STANDARD
-	#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
-		uniform vec2 clearCoatNormalScale;
-	#endif
 	#ifdef USE_CLEARCOAT_NORMALMAP
-		uniform sampler2D clearCoatNormalMap;
-	#else
-		#define clearCoatNormalMap normalMap
+	
+	  uniform sampler2D clearCoatNormalMap;
+		uniform vec2 clearCoatNormalScale;
+		
 	#endif
 #endif
 `;
-/*
-#ifdef USE_NORMALMAP
-
-	uniform sampler2D normalMap;
-	uniform vec2 normalScale;
-
-	#ifdef OBJECTSPACE_NORMALMAP
-
-		uniform mat3 normalMatrix;
-
-	#else
-
-		// Per-Pixel Tangent Space Normal Mapping
-		// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
-
-		vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {
-
-			// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
-
-			vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
-			vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
-			vec2 st0 = dFdx( vUv.st );
-			vec2 st1 = dFdy( vUv.st );
-
-			float scale = sign( st1.t * st0.s - st0.t * st1.s ); // we do not care about the magnitude
-
-			vec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );
-			vec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );
-			vec3 N = normalize( surf_norm );
-			mat3 tsn = mat3( S, T, N );
-
-			vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
-
-			mapN.xy *= normalScale;
-			mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
-
-			return normalize( tsn * mapN );
-
-		}
-
-	#endif
-
-#endif
-*/
 
 var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256.,  256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}";
 
@@ -15743,7 +15632,6 @@ uniform float opacity;
 #ifndef STANDARD
 	uniform float clearCoat;
 	uniform float clearCoatRoughness;
-	uniform bool clearCoatGeometryNormals;
 #endif
 
 varying vec3 vViewPosition;
@@ -15833,12 +15721,12 @@ void main() {
 
 var meshphysical_vert = "#define PHYSICAL\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
 
-var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || ( defined( USE_CLEARCOAT_NORMALMAP ) && ! defined( OBJECTSPACE_CLEARCOAT_NORMALMAP ) )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";
+var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || defined( USE_CLEARCOAT_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";
 
 var normal_vert = /* glsl */ `
 #define NORMAL
 
-#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || ( defined( USE_CLEARCOAT_NORMALMAP ) && ! defined( OBJECTSPACE_CLEARCOAT_NORMALMAP ) )
+#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || defined( USE_CLEARCOAT_NORMALMAP )
 
 	varying vec3 vViewPosition;
 
@@ -15895,7 +15783,7 @@ void main() {
 	#include <logdepthbuf_vertex>
 	#include <clipping_planes_vertex>
 
-#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || ( defined( USE_CLEARCOAT_NORMALMAP ) && ! defined( OBJECTSPACE_CLEARCOAT_NORMALMAP ) )
+#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || defined( USE_CLEARCOAT_NORMALMAP )
 
 	vViewPosition = - mvPosition.xyz;
 
@@ -16508,9 +16396,8 @@ ShaderLib.physical = {
 		{
 			clearCoat: { value: 0 },
 			clearCoatRoughness: { value: 0 },
-			clearCoatGeometryNormals: { value: false },
+			clearCoatNormalScale: { value: new Vector2( 1, 1 ) },
 			clearCoatNormalMap: { value: null },
-			clearCoatNormalScale: { value: new Vector2( 1, 1 ) }
 		}
 	] ),
 
@@ -19034,7 +18921,7 @@ function generateExtensions( extensions, parameters, rendererExtensions ) {
 	extensions = extensions || {};
 
 	var chunks = [
-		( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || ( parameters.clearCoatNormalMap && ! parameters.objectSpaceClearCoatNormalMap ) || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
+		( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.clearCoatNormalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
 		( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
 		( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
 		( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
@@ -19301,7 +19188,6 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
 			parameters.normalMap ? '#define USE_NORMALMAP' : '',
 			( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
 			parameters.clearCoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
-			( parameters.clearCoatNormalMap && parameters.objectSpaceClearCoatNormalMap ) ? '#define OBJECTSPACE_CLEARCOAT_NORMALMAP' : '',
 			parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
 			parameters.specularMap ? '#define USE_SPECULARMAP' : '',
 			parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
@@ -19419,7 +19305,6 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
 			parameters.normalMap ? '#define USE_NORMALMAP' : '',
 			( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
 			parameters.clearCoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
-			( parameters.clearCoatNormalMap && parameters.objectSpaceClearCoatNormalMap ) ? '#define OBJECTSPACE_CLEARCOAT_NORMALMAP' : '',
 			parameters.specularMap ? '#define USE_SPECULARMAP' : '',
 			parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
 			parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
@@ -19700,7 +19585,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
 
 	var parameterNames = [
 		"precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
-		"lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "clearCoatNormalMap", "objectSpaceClearCoatNormalMap",, "displacementMap", "specularMap",
+		"lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "clearCoatNormalMap", "displacementMap", "specularMap",
 		"roughnessMap", "metalnessMap", "gradientMap",
 		"alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
 		"flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
@@ -19825,7 +19710,6 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
 			normalMap: !! material.normalMap,
 			objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
 			clearCoatNormalMap: !! material.clearCoatNormalMap,
-			objectSpaceClearCoatNormalMap: material.clearCoatNormalMapType === ObjectSpaceNormalMap,
 			displacementMap: !! material.displacementMap,
 			roughnessMap: !! material.roughnessMap,
 			metalnessMap: !! material.metalnessMap,
@@ -26690,12 +26574,11 @@ function WebGLRenderer( parameters ) {
 			}
 
 			uniforms.clearCoatNormalScale.value.copy( material.clearCoatNormalScale );
-			if ( material.side === BackSide ) uniforms.clearCoatNormalScale.value.negate();
+			if ( material.side === BackSide ){
+				uniforms.clearCoatNormalScale.value.negate();
+			}
 
 		}
-
-		uniforms.clearCoatGeometryNormals.value = material.clearCoatGeometryNormals;
-		
 	}
 
 	function refreshUniformsMatcap( uniforms, material ) {
@@ -33571,11 +33454,9 @@ MeshStandardMaterial.prototype.copy = function ( source ) {
  *  reflectivity: <float>
  *  clearCoat: <float>
  *  clearCoatRoughness: <float>
-
- *  clearCoatGeometryNormals: <boolean>
- *  clearCoatNormalMap: new THREE.Texture( <Image> ),
- *  clearCoatNormalMapType: THREE.TangentSpaceNormalMap,
+ *
  *  clearCoatNormalScale: <Vector2>,
+ *  clearCoatNormalMap: new THREE.Texture( <Image> ),
  * }
  */
 
@@ -33592,10 +33473,8 @@ function MeshPhysicalMaterial( parameters ) {
 	this.clearCoat = 0.0;
 	this.clearCoatRoughness = 0.0;
 
-	this.clearCoatGeometryNormals = false;
-	this.clearCoatNormalMap = null;
-	this.clearCoatNormalMapType = TangentSpaceNormalMap;
 	this.clearCoatNormalScale = new Vector2(1, 1);
+	this.clearCoatNormalMap = null;
 
 	this.setValues( parameters );
 
@@ -33617,9 +33496,7 @@ MeshPhysicalMaterial.prototype.copy = function ( source ) {
 	this.clearCoat = source.clearCoat;
 	this.clearCoatRoughness = source.clearCoatRoughness;
 
-	this.clearCoatGeometryNormals = source.clearCoatGeometryNormals;
 	this.clearCoatNormalMap = source.clearCoatNormalMap;
-	this.clearCoatNormalMapType = source.clearCoatNormalMapType;
 	this.clearCoatNormalScale.copy(source.clearCoatNormalScale);
 
 	return this;

+ 5 - 7
examples/_.html

@@ -74,7 +74,6 @@
 
 		const variationsX = [
 			(mat, scale, map) => { mat.clearCoatNormalScale.copy(mat.normalScale); },
-			(mat, scale, map) => { mat.clearCoatNormalScale = new THREE.Vector2(scale, scale); },
 			(mat, scale, map) => {
 				mat.clearCoatNormalScale = new THREE.Vector2(scale, scale);
 				if (mat.clearCoatNormalMap !== map) {
@@ -207,14 +206,13 @@
 			}
 
 
-			addLabel("Normal Map", new THREE.Vector3(-450, 0, 0), 30);
-			addLabel("None", new THREE.Vector3(-350, -100, 0));
-			addLabel("Scaling + Map", new THREE.Vector3(-400, 100, 0));
+			addLabel("Normal Map", new THREE.Vector3(-350, 0, 0), 30);
+			addLabel("None", new THREE.Vector3(-250, -100, 0));
+			addLabel("Map", new THREE.Vector3(-300, 100, 0));
 
 			addLabel("Clearcoat Normal Map", new THREE.Vector3(0, 260, 0), 30);
-			addLabel("None", new THREE.Vector3(- 200, 200, 0));
-			addLabel("Scaling", new THREE.Vector3(0, 200, 0));
-			addLabel("Scaling + Map", new THREE.Vector3(200, 200, 0));
+			addLabel("None", new THREE.Vector3(-100, 200, 0));
+			addLabel("Map", new THREE.Vector3(100, 200, 0));
 
 			// LIGHTS
 

+ 3 - 7
src/materials/MeshPhysicalMaterial.d.ts

@@ -11,11 +11,9 @@ export interface MeshPhysicalMaterialParameters
 	reflectivity?: number;
 	clearCoat?: number;
 	clearCoatRoughness?: number;
-	
-	clearCoatGeometryNormals?: boolean;
-	clearCoatNormalMap?: Texture;
-	clearCoatNormalMapType?: NormalMapTypes;
+
 	clearCoatNormalScale?: Vector2;
+	clearCoatNormalMap?: Texture;
 }
 
 export class MeshPhysicalMaterial extends MeshStandardMaterial {
@@ -27,9 +25,7 @@ export class MeshPhysicalMaterial extends MeshStandardMaterial {
 	clearCoat: number;
 	clearCoatRoughness: number;
 
-	clearCoatGeometryNormals?: boolean;
-	clearCoatNormalMap: Texture | null;
-	clearCoatNormalMapType: NormalMapTypes;
 	clearCoatNormalScale: Vector2;
+	clearCoatNormalMap: Texture | null;
 
 }

+ 3 - 10
src/materials/MeshPhysicalMaterial.js

@@ -1,4 +1,3 @@
-import { TangentSpaceNormalMap } from '../constants.js';
 import { Vector2 } from '../math/Vector2.js';
 import { MeshStandardMaterial } from './MeshStandardMaterial.js';
 
@@ -9,11 +8,9 @@ import { MeshStandardMaterial } from './MeshStandardMaterial.js';
  *  reflectivity: <float>
  *  clearCoat: <float>
  *  clearCoatRoughness: <float>
-
- *  clearCoatGeometryNormals: <boolean>
- *  clearCoatNormalMap: new THREE.Texture( <Image> ),
- *  clearCoatNormalMapType: THREE.TangentSpaceNormalMap,
+ *
  *  clearCoatNormalScale: <Vector2>,
+ *  clearCoatNormalMap: new THREE.Texture( <Image> ),
  * }
  */
 
@@ -30,10 +27,8 @@ function MeshPhysicalMaterial( parameters ) {
 	this.clearCoat = 0.0;
 	this.clearCoatRoughness = 0.0;
 
-	this.clearCoatGeometryNormals = false;
-	this.clearCoatNormalMap = null;
-	this.clearCoatNormalMapType = TangentSpaceNormalMap;
 	this.clearCoatNormalScale = new Vector2(1, 1);
+	this.clearCoatNormalMap = null;
 
 	this.setValues( parameters );
 
@@ -55,9 +50,7 @@ MeshPhysicalMaterial.prototype.copy = function ( source ) {
 	this.clearCoat = source.clearCoat;
 	this.clearCoatRoughness = source.clearCoatRoughness;
 
-	this.clearCoatGeometryNormals = source.clearCoatGeometryNormals;
 	this.clearCoatNormalMap = source.clearCoatNormalMap;
-	this.clearCoatNormalMapType = source.clearCoatNormalMapType;
 	this.clearCoatNormalScale.copy(source.clearCoatNormalScale);
 
 	return this;

+ 3 - 4
src/renderers/WebGLRenderer.js

@@ -2282,12 +2282,11 @@ function WebGLRenderer( parameters ) {
 			}
 
 			uniforms.clearCoatNormalScale.value.copy( material.clearCoatNormalScale );
-			if ( material.side === BackSide ) uniforms.clearCoatNormalScale.value.negate();
+			if ( material.side === BackSide ){
+				uniforms.clearCoatNormalScale.value.negate();
+			}
 
 		}
-
-		uniforms.clearCoatGeometryNormals.value = material.clearCoatGeometryNormals;
-		
 	}
 
 	function refreshUniformsMatcap( uniforms, material ) {

+ 7 - 41
src/renderers/shaders/ShaderChunk/bsdfs.glsl.js

@@ -125,15 +125,15 @@ float D_GGX( const in float alpha, const in float dotNH ) {
 }
 
 // GGX Distribution, Schlick Fresnel, GGX-Smith Visibility
-vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
+vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {
 
 	float alpha = pow2( roughness ); // UE4's roughness
 
-	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
+	vec3 halfDir = normalize( incidentLight.direction + viewDir );
 
-	float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );
-	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
-	float dotNH = saturate( dot( geometry.normal, halfDir ) );
+	float dotNL = saturate( dot( normal, incidentLight.direction ) );
+	float dotNV = saturate( dot( normal, viewDir ) );
+	float dotNH = saturate( dot( normal, halfDir ) );
 	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
 
 	vec3 F = F_Schlick( specularColor, dotLH );
@@ -146,29 +146,6 @@ vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in Geometric
 
 } // validated
 
-#ifndef STANDARD
-vec3 BRDF_ClearCoat_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
-
-	float alpha = pow2( roughness ); // UE4's roughness
-
-	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
-
-	float dotNL = saturate( dot( geometry.clearCoatNormal, incidentLight.direction ) );
-	float dotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
-	float dotNH = saturate( dot( geometry.clearCoatNormal, halfDir ) );
-	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
-
-	vec3 F = F_Schlick( specularColor, dotLH );
-
-	float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );
-
-	float D = D_GGX( alpha, dotNH );
-
-	return F * ( G * D );
-
-}
-#endif
-
 // Rect Area Light
 
 // Real-Time Polygonal-Light Shading with Linearly Transformed Cosines
@@ -287,9 +264,9 @@ vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in m
 // End Rect Area Light
 
 // ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile
-vec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
+vec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {
 
-	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
+	float dotNV = saturate( dot( normal, viewDir ) );
 
 	vec2 brdf = integrateSpecularBRDF( dotNV, roughness );
 
@@ -297,17 +274,6 @@ vec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in
 
 } // validated
 
-#ifndef STANDARD
-vec3 BRDF_ClearCoat_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
-
-	float dotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
-
-	vec2 brdf = integrateSpecularBRDF( dotNV, roughness );
-
-	return specularColor * brdf.x + brdf.y;
-}
-#endif
-
 // Fdez-Agüera's "Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting"
 // Approximates multiscattering in order to preserve energy.
 // http://www.jcgt.org/published/0008/01/03/

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

@@ -1,5 +1,7 @@
 export default /* glsl */`
 #ifndef STANDARD
-  vec3 clearCoatNormal = geometryNormal;
+  #ifdef USE_CLEARCOAT_NORMALMAP
+    vec3 clearCoatNormal = geometryNormal;
+  #endif
 #endif
 `;

+ 1 - 62
src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js

@@ -1,6 +1,6 @@
 export default /* glsl */ `
 #ifndef STANDARD
-	#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
+	#ifdef USE_CLEARCOAT_NORMALMAP
 
 		#ifdef USE_TANGENT
 
@@ -17,64 +17,3 @@ export default /* glsl */ `
 	#endif
 #endif
 `;
-/*
-#if defined( USE_NORMALMAP )
-
-	#ifdef USE_TANGENT
-
-		mat3 vTBN = mat3( tangent, bitangent, normal );
-		vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
-		mapN.xy = clearCoatnormalScale * mapN.xy;
-		clearCoatNormal = normalize( vTBN * mapN );
-
-	#else
-
-	  clearCoatNormal = perturbClearCoatNormal2Arb( -vViewPosition, clearCoatNormal );
-
-	#endif
-#endif
-*/
-/*
-#if defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )
-
-	//#ifdef OBJECTSPACE_NORMALMAP
-
-		normal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0; // overrides both flatShading and attribute normals
-
-		#ifdef FLIP_SIDED
-
-			normal = - normal;
-
-		#endif
-
-		#ifdef DOUBLE_SIDED
-
-			normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
-
-		#endif
-
-		normal = normalize( normalMatrix * normal );
-
-	//#else // tangent-space normal map
-
-		#ifdef USE_TANGENT
-
-			mat3 vTBN = mat3( tangent, bitangent, normal );
-			vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
-			mapN.xy = normalScale * mapN.xy;
-			normal = normalize( vTBN * mapN );
-
-		#else
-
-			normal = perturbNormal2Arb( -vViewPosition, normal );
-
-		#endif
-
-	//#endif
-
-#elif defined( USE_BUMPMAP )
-
-	normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );
-
-#endif
-*/

+ 4 - 50
src/renderers/shaders/ShaderChunk/clearcoat_normalmap_pars_fragment.glsl.js

@@ -1,56 +1,10 @@
 export default /* glsl */ `
 #ifndef STANDARD
-	#if defined( USE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP )
-		uniform vec2 clearCoatNormalScale;
-	#endif
 	#ifdef USE_CLEARCOAT_NORMALMAP
-		uniform sampler2D clearCoatNormalMap;
-	#else
-		#define clearCoatNormalMap normalMap
+	
+	  uniform sampler2D clearCoatNormalMap;
+		uniform vec2 clearCoatNormalScale;
+		
 	#endif
 #endif
 `;
-/*
-#ifdef USE_NORMALMAP
-
-	uniform sampler2D normalMap;
-	uniform vec2 normalScale;
-
-	#ifdef OBJECTSPACE_NORMALMAP
-
-		uniform mat3 normalMatrix;
-
-	#else
-
-		// Per-Pixel Tangent Space Normal Mapping
-		// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
-
-		vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {
-
-			// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
-
-			vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
-			vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
-			vec2 st0 = dFdx( vUv.st );
-			vec2 st1 = dFdy( vUv.st );
-
-			float scale = sign( st1.t * st0.s - st0.t * st1.s ); // we do not care about the magnitude
-
-			vec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );
-			vec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );
-			vec3 N = normalize( surf_norm );
-			mat3 tsn = mat3( S, T, N );
-
-			vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
-
-			mapN.xy *= normalScale;
-			mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
-
-			return normalize( tsn * mapN );
-
-		}
-
-	#endif
-
-#endif
-*/

+ 6 - 2
src/renderers/shaders/ShaderChunk/common.glsl.js

@@ -40,8 +40,12 @@ struct GeometricContext {
 	vec3 normal;
 	vec3 viewDir;
 
-  #ifndef STANDARD
-	vec3 clearCoatNormal;
+	#ifndef STANDARD
+		#ifdef USE_CLEARCOAT_NORMALMAP
+
+			vec3 clearCoatNormal;
+			
+		#endif
   #endif
 };
 

+ 9 - 3
src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js

@@ -20,8 +20,14 @@ geometry.position = - vViewPosition;
 geometry.normal = normal;
 geometry.viewDir = normalize( vViewPosition );
 
-#if defined( PHYSICAL ) && !defined( STANDARD )
-	geometry.clearCoatNormal = clearCoatNormal;
+#ifdef PHYSICAL
+	#ifndef STANDARD
+		#ifdef USE_CLEARCOAT_NORMALMAP
+		
+			geometry.clearCoatNormal = clearCoatNormal;
+
+		#endif
+	#endif
 #endif
 IncidentLight directLight;
 
@@ -125,6 +131,6 @@ IncidentLight directLight;
 
 	vec3 radiance = vec3( 0.0 );
 	vec3 clearCoatRadiance = vec3( 0.0 );
-
+	
 #endif
 `;

+ 5 - 2
src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js

@@ -28,8 +28,11 @@ export default /* glsl */ `
   radiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.normal, Material_BlinnShininessExponent( material ), maxMipLevel );
 
 	#ifndef STANDARD
-	  clearCoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.clearCoatNormal,Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );
+		#ifdef USE_CLEARCOAT_NORMALMAP
+			clearCoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.clearCoatNormal, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );
+		#else
+			clearCoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.normal, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );
+		#endif
 	#endif
-
 #endif
 `;

+ 36 - 19
src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js

@@ -65,38 +65,49 @@ float clearCoatDHRApprox( const in float roughness, const in float dotNL ) {
 #endif
 
 void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
-
+ // TODO: refactor more
 	float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
 	vec3 irradiance = dotNL * directLight.color;
 
-	#ifndef STANDARD
-		float ccDotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
-		float ccDotNL = ccDotNV;
-		vec3 ccIrradiance= ccDotNL * directLight.color;
-	#endif
-
 	#ifndef PHYSICALLY_CORRECT_LIGHTS
 
 		irradiance *= PI; // punctual light
-		#ifndef STANDARD
-			ccIrradiance *= PI; // punctual light
+
+	#endif
+
+	#ifndef STANDARD
+		#ifdef USE_CLEARCOAT_NORMALMAP
+			float ccDotNL = saturate( dot( geometry.clearCoatNormal, directLight.direction ) );
+			vec3 ccIrradiance = ccDotNL * directLight.color;
+
+			#ifndef PHYSICALLY_CORRECT_LIGHTS
+
+				ccIrradiance *= PI; // punctual light
+
+			#endif
 		#endif
 	#endif
 
 	#ifndef STANDARD
-		float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
+		#ifdef USE_CLEARCOAT_NORMALMAP
+			float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
+		#else
+			float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );
+		#endif
 	#else
 		float clearCoatDHR = 0.0;
 	#endif
 
-	reflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );
+	reflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness );
 
 	reflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
 
 	#ifndef STANDARD
-
-		reflectedLight.directSpecular += ccIrradiance * material.clearCoat * BRDF_ClearCoat_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
-
+		#ifdef USE_CLEARCOAT_NORMALMAP
+			reflectedLight.directSpecular += ccIrradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearCoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
+		#else
+			reflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
+		#endif
 	#endif
 
 }
@@ -116,7 +127,11 @@ 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) {
 
 	#ifndef STANDARD
-		float ccDotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
+		#ifdef USE_CLEARCOAT_NORMALMAP
+			float ccDotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );
+		#else
+			float ccDotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
+		#endif
 		float ccDotNL = ccDotNV;
 		float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );
 	#else
@@ -143,14 +158,16 @@ void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradia
 
 	#else
 
-		reflectedLight.indirectSpecular += clearCoatInv * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );
+		reflectedLight.indirectSpecular += clearCoatInv * radiance * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness );
 
 	#endif
 
 	#ifndef STANDARD
-
-	reflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_ClearCoat_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
-
+		#ifdef USE_CLEARCOAT_NORMALMAP
+			reflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.clearCoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
+		#else
+			reflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.normal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );
+		#endif
 	#endif
 }
 

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

@@ -11,7 +11,7 @@ export default /* glsl */ `
 	#endif
 #endif
 
-#if ( defined ( USE_NORMALMAP ) && !defined ( OBJECTSPACE_NORMALMAP )) || ( defined ( USE_CLEARCOAT_NORMALMAP ) && !defined ( OBJECTSPACE_CLEARCOAT_NORMALMAP ) )
+#if ( defined ( USE_NORMALMAP ) && !defined ( OBJECTSPACE_NORMALMAP )) || defined ( USE_CLEARCOAT_NORMALMAP )
 
 		// Per-Pixel Tangent Space Normal Mapping
 		// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html

+ 1 - 2
src/renderers/shaders/ShaderLib.js

@@ -275,9 +275,8 @@ ShaderLib.physical = {
 		{
 			clearCoat: { value: 0 },
 			clearCoatRoughness: { value: 0 },
-			clearCoatGeometryNormals: { value: false },
+			clearCoatNormalScale: { value: new Vector2( 1, 1 ) },
 			clearCoatNormalMap: { value: null },
-			clearCoatNormalScale: { value: new Vector2( 1, 1 ) }
 		}
 	] ),
 

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

@@ -10,7 +10,6 @@ uniform float opacity;
 #ifndef STANDARD
 	uniform float clearCoat;
 	uniform float clearCoatRoughness;
-	uniform bool clearCoatGeometryNormals;
 #endif
 
 varying vec3 vViewPosition;

+ 1 - 1
src/renderers/shaders/ShaderLib/normal_frag.glsl.js

@@ -3,7 +3,7 @@ export default /* glsl */`
 
 uniform float opacity;
 
-#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || ( defined( USE_CLEARCOAT_NORMALMAP ) && ! defined( OBJECTSPACE_CLEARCOAT_NORMALMAP ) )
+#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || defined( USE_CLEARCOAT_NORMALMAP )
 
 	varying vec3 vViewPosition;
 

+ 2 - 2
src/renderers/shaders/ShaderLib/normal_vert.glsl.js

@@ -1,7 +1,7 @@
 export default /* glsl */ `
 #define NORMAL
 
-#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || ( defined( USE_CLEARCOAT_NORMALMAP ) && ! defined( OBJECTSPACE_CLEARCOAT_NORMALMAP ) )
+#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || defined( USE_CLEARCOAT_NORMALMAP )
 
 	varying vec3 vViewPosition;
 
@@ -58,7 +58,7 @@ void main() {
 	#include <logdepthbuf_vertex>
 	#include <clipping_planes_vertex>
 
-#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || ( defined( USE_CLEARCOAT_NORMALMAP ) && ! defined( OBJECTSPACE_CLEARCOAT_NORMALMAP ) )
+#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || defined( USE_CLEARCOAT_NORMALMAP )
 
 	vViewPosition = - mvPosition.xyz;
 

+ 1 - 3
src/renderers/webgl/WebGLProgram.js

@@ -118,7 +118,7 @@ function generateExtensions( extensions, parameters, rendererExtensions ) {
 	extensions = extensions || {};
 
 	var chunks = [
-		( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || ( parameters.clearCoatNormalMap && ! parameters.objectSpaceClearCoatNormalMap ) || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
+		( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.clearCoatNormalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
 		( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
 		( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
 		( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
@@ -385,7 +385,6 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
 			parameters.normalMap ? '#define USE_NORMALMAP' : '',
 			( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
 			parameters.clearCoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
-			( parameters.clearCoatNormalMap && parameters.objectSpaceClearCoatNormalMap ) ? '#define OBJECTSPACE_CLEARCOAT_NORMALMAP' : '',
 			parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
 			parameters.specularMap ? '#define USE_SPECULARMAP' : '',
 			parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
@@ -503,7 +502,6 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
 			parameters.normalMap ? '#define USE_NORMALMAP' : '',
 			( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
 			parameters.clearCoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
-			( parameters.clearCoatNormalMap && parameters.objectSpaceClearCoatNormalMap ) ? '#define OBJECTSPACE_CLEARCOAT_NORMALMAP' : '',
 			parameters.specularMap ? '#define USE_SPECULARMAP' : '',
 			parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
 			parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',

+ 1 - 2
src/renderers/webgl/WebGLPrograms.js

@@ -29,7 +29,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
 
 	var parameterNames = [
 		"precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
-		"lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "clearCoatNormalMap", "objectSpaceClearCoatNormalMap",, "displacementMap", "specularMap",
+		"lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "clearCoatNormalMap", "displacementMap", "specularMap",
 		"roughnessMap", "metalnessMap", "gradientMap",
 		"alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
 		"flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
@@ -154,7 +154,6 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
 			normalMap: !! material.normalMap,
 			objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
 			clearCoatNormalMap: !! material.clearCoatNormalMap,
-			objectSpaceClearCoatNormalMap: material.clearCoatNormalMapType === ObjectSpaceNormalMap,
 			displacementMap: !! material.displacementMap,
 			roughnessMap: !! material.roughnessMap,
 			metalnessMap: !! material.metalnessMap,

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно