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

further consolidation of different material BRDFs via the same lighting template.

Ben Houston 9 жил өмнө
parent
commit
05118ea6bb

+ 2 - 2
examples/js/ShaderSkin.js

@@ -84,7 +84,7 @@ THREE.ShaderSkin = {
 
 			THREE.ShaderChunk[ "common" ],
 			THREE.ShaderChunk[ "bsdfs" ],
-			THREE.ShaderChunk[ "lights" ],
+			THREE.ShaderChunk[ "lights_pars" ],
 			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
 			THREE.ShaderChunk[ "fog_pars_fragment" ],
 			THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
@@ -373,7 +373,7 @@ THREE.ShaderSkin = {
 			"varying vec3 vViewPosition;",
 
 			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "lights" ],
+			THREE.ShaderChunk[ "lights_pars" ],
 			THREE.ShaderChunk[ "fog_pars_fragment" ],
 
 			"float fresnelReflectance( vec3 H, vec3 V, float F0 ) {",

+ 1 - 1
examples/js/ShaderTerrain.js

@@ -90,7 +90,7 @@ THREE.ShaderTerrain = {
 
 			THREE.ShaderChunk[ "common" ],
 			THREE.ShaderChunk[ "bsdfs" ],
-			THREE.ShaderChunk[ "lights" ],
+			THREE.ShaderChunk[ "lights_pars" ],
 			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
 			THREE.ShaderChunk[ "fog_pars_fragment" ],
 

+ 1 - 1
examples/webgl_shaders_tonemapping.html

@@ -160,7 +160,7 @@
 
 						THREE.ShaderChunk[ "common" ],
 						THREE.ShaderChunk[ "bsdfs" ],
-						THREE.ShaderChunk[ "lights" ],
+						THREE.ShaderChunk[ "lights_pars" ],
 						THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
 
 						"void main() {",

+ 58 - 36
src/renderers/shaders/ShaderChunk/bsdfs.glsl

@@ -1,5 +1,7 @@
 //#define ENERGY_PRESERVING_MONOCHROME
 
+#define DIELECTRIC_SPECULAR_F0 0.20
+
 float calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {
 
 	if ( decayExponent > 0.0 ) {
@@ -27,6 +29,7 @@ void BRDF_Lambert( const in IncidentLight incidentLight, const in GeometricConte
 
 }
 
+// this roughness is a different property than specular roughness used in GGX.
 void BRDF_OrenNayar( const in IncidentLight incidentLight, const in GeometricContext geometryContext, const in vec3 diffuse, const in float roughness, inout ReflectedLight reflectedLight ) {
 
 	vec3 halfDir = normalize( incidentLight.direction + geometryContext.viewDir );
@@ -57,44 +60,39 @@ vec3 F_Schlick( const in vec3 F0, const in float dotLH ) {
 
 // Microfacet Models for Refraction through Rough Surfaces - equation (34)
 // http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
-// alpha is "roughness squared" in Disney’s reparameterization
-float G_SmithSchlick( in float alpha, in float dotNL, in float dotNV ) {
+// roughtness2 is "roughness squared" in Disney’s reparameterization
+float G_SmithSchlick( in float roughtness2, in float dotNL, in float dotNV ) {
 
 	// geometry term = G(l) . G(v) / 4(n . l)(n. v)
 
-	float a2 = alpha * alpha;
-
+	float a2 = roughtness2 * roughtness2;
 	float gl = dotNL + pow( a2 + ( 1.0 - a2 ) * dotNL * dotNL, 0.5 );
-
 	float gv = dotNV + pow( a2 + ( 1.0 - a2 ) * dotNV * dotNV, 0.5 );
 
 	return 1.0 / ( gl * gv );
 
 }
 
+// useful for clear coat surfaces, use with Distribution_GGX.
+float G_Kelemen( float vDotH ) {
+
+	return 1.0 / ( 4.0 * vDotH * vDotH + 0.0000001 );
+
+}
 
 // Microfacet Models for Refraction through Rough Surfaces - equation (33)
 // http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
-// alpha is "roughness squared" in Disney’s reparameterization
-float D_GGX( in float alpha, in float dotNH ) {
+// roughtness2 is "roughness squared" in Disney’s reparameterization
+float D_GGX( in float roughtness2, in float dotNH ) {
 
 	// factor of 1/PI in distribution term omitted
-
-	float a2 = alpha * alpha;
-
-	float denom = dotNH * dotNH * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1
+	float a2 = roughtness2 * roughtness2;
+	float denom = dotNH * dotNH * ( a2 - 1.0 ) + 1.0; // avoid roughtness2 = 0 with dotNH = 1
 
 	return a2 / ( denom * denom );
 
 }
 
-float G_BlinnPhong_Implicit( /* in float dotNL, in float dotNV */ ) {
-
-	// geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)
-	return 0.25;
-
-}
-
 void BRDF_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness2, inout ReflectedLight reflectedLight ) {
 	
 	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
@@ -111,42 +109,66 @@ void BRDF_GGX( const in IncidentLight incidentLight, const in GeometricContext g
 
 }
 
-float D_BlinnPhong( const in float shininess, const in float dotNH ) {
-
-	// factor of 1/PI in distribution term omitted ???
-	return ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
-
-}
-
-void BRDF_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess, inout ReflectedLight reflectedLight ) {
+// this blends the existing reflected light with a clear coat.
+void BRDF_GGX_ClearCoat_Over( const in IncidentLight incidentLight, const in GeometricContext geometry, const in float clearCoatWeight, const in float clearCoatRoughness, inout ReflectedLight reflectedLight ) {
 
 	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
 	float dotNH = saturate( dot( geometry.normal, halfDir ) );
 	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
+	float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );
+	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
 
-	vec3 F = F_Schlick( specularColor, dotLH );
-	float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );
-	float D = D_BlinnPhong( shininess, dotNH );
+	vec3 F = F_Schlick( vec3( DIELECTRIC_SPECULAR_F0 ), dotLH );
+	float G = G_Kelemen( dotNV );
+	float D = D_GGX( clearCoatRoughness, dotNH );
 
-	reflectedLight.specular += incidentLight.color * F * ( G * D );
+	vec3 clearCoatColor = F * ( G * D );
+
+	reflectedLight.diffuse = mix( reflectedLight.diffuse, vec3( 0.0 ), clearCoatWeight );
+	reflectedLight.specular = mix( reflectedLight.specular, clearCoatColor, clearCoatWeight ); 
 
 }
 
 // ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile
-vec3 envBRDFApprox( vec3 specularColor, float roughness, in vec3 normal, in vec3 viewDir  ) {
+vec3 BRDF_GGX_Environment( const in GeometricContext geometry, vec3 specularColor, float roughness  ) {
 
-	float dotNV = saturate( dot( normal, viewDir ) );
+	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
 
 	const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
-
 	const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
-
 	vec4 r = roughness * c0 + c1;
-
 	float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
-
 	vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;
 
 	return specularColor * AB.x + AB.y;
 
+}
+
+
+float G_BlinnPhong_Implicit( /* in float dotNL, in float dotNV */ ) {
+
+	// geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)
+	return 0.25;
+
+}
+
+float D_BlinnPhong( const in float shininess, const in float dotNH ) {
+
+	// factor of 1/PI in distribution term omitted ???
+	return ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
+
+}
+
+void BRDF_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess, inout ReflectedLight reflectedLight ) {
+
+	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
+	float dotNH = saturate( dot( geometry.normal, halfDir ) );
+	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
+
+	vec3 F = F_Schlick( specularColor, dotLH );
+	float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );
+	float D = D_BlinnPhong( shininess, dotNH );
+
+	reflectedLight.specular += incidentLight.color * F * ( G * D );
+
 }

+ 7 - 0
src/renderers/shaders/ShaderChunk/common.glsl

@@ -21,6 +21,13 @@ struct ReflectedLight {
  	vec3 diffuse;
 };
 
+void accumulateReflectedLight( inout ReflectedLight accumulator, const in ReflectedLight item ) {
+
+	accumulator.diffuse += item.diffuse;
+	accumulator.specular += item.specular;
+
+}
+
 struct GeometricContext {
 	vec3 position;
 	vec3 normal;

+ 0 - 0
src/renderers/shaders/ShaderChunk/lights.glsl → src/renderers/shaders/ShaderChunk/lights_pars.glsl


+ 7 - 67
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl

@@ -1,80 +1,20 @@
-vec3 diffuse = diffuseColor.rgb;
+BlinnPhongMaterial material;
+material.specularColor = specular;
+material.specularShininess = shininess;
+material.diffuseColor = diffuseColor.rgb;
 
 #ifdef METAL
 
-	diffuse = vec3( 0.0 );
+	material.diffuseColor = vec3( 0.0 );
 
 #endif
 
 #if defined( ENERGY_PRESERVING_RGB )
 
-	diffuse *= whiteCompliment( specular );
+	material.diffuseColor *= whiteCompliment( specular );
 
 #elif defined( ENERGY_PRESERVING_MONOCHROME )
 
-	diffuse *= whiteCompliment( luminance( specular ) );
+	material.diffuseColor *= whiteCompliment( luminance( specular ) );
 
 #endif
-
-GeometricContext geometry = GeometricContext( -vViewPosition, normalize( normal ), normalize(vViewPosition ) );
-
-ReflectedLight directReflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ) );
-ReflectedLight indirectReflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ) );
-
-#if MAX_POINT_LIGHTS > 0
-
-	for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
-
-		IncidentLight directLight = getPointDirectLight( pointLights[ i ], geometry );
-
-		BRDF_Lambert( directLight, geometry, diffuse, directReflectedLight );
-		//BRDF_OrenNayar( directLight, geometry, diffuse, 0.5, directReflectedLight );
-
-		BRDF_BlinnPhong( directLight, geometry, specular, shininess, directReflectedLight );
-
-	}
-
-#endif
-
-#if MAX_SPOT_LIGHTS > 0
-
-	for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {
-
-		IncidentLight directLight = getSpotDirectLight( spotLights[ i ], geometry );
-
-		BRDF_Lambert( directLight, geometry, diffuse, directReflectedLight );
-		//BRDF_OrenNayar( directLight, geometry, diffuse, 0.5, directReflectedLight );
-
-		BRDF_BlinnPhong( directLight, geometry, specular, shininess, directReflectedLight );
-
-	}
-
-#endif
-
-#if MAX_DIR_LIGHTS > 0
-
-	for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
-
-		IncidentLight directLight = getDirectionalDirectLight( directionalLights[ i ], geometry );
-
-		BRDF_Lambert( directLight, geometry, diffuse, directReflectedLight );
-		//BRDF_OrenNayar( directLight, geometry, diffuse, 0.5, directReflectedLight );
-
-		BRDF_BlinnPhong( directLight, geometry, specular, shininess, directReflectedLight );
-
-	}
-
-#endif
-
-#if MAX_HEMI_LIGHTS > 0
-
-	for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {
-
-		IncidentLight indirectLight = getHemisphereIndirectLight( hemisphereLights[ i ], geometry );
-
-		BRDF_Lambert( indirectLight, geometry, diffuse, indirectReflectedLight );
-		//BRDF_OrenNayar( indirectLight, geometry, diffuse, 0.5, indirectReflectedLight );
-
-	}
-
-#endif

+ 27 - 0
src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl

@@ -12,3 +12,30 @@ varying vec3 vViewPosition;
 
 #endif
 
+
+struct BlinnPhongMaterial {
+	vec3	diffuseColor;
+	float	specularShininess;
+	vec3	specularColor;
+};
+
+void BRDF_BlinnPhongMaterial_DirectLight( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight directReflectedLight ) {
+
+	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ) );
+
+	BRDF_Lambert( directLight, geometry, material.diffuseColor, directReflectedLight );
+	//BRDF_OrenNayar( directLight, geometry, material.diffuseColor, 0.5, directReflectedLight );
+
+	BRDF_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess, directReflectedLight );
+	
+}
+
+
+void BRDF_BlinnPhongMaterial_IndirectLight( const in IncidentLight indirectLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight indirectReflectedLight ) {
+
+	BRDF_Lambert( indirectLight, geometry, material.diffuseColor, indirectReflectedLight );
+
+}
+
+#define BRDF_Material_DirectLight    BRDF_BlinnPhongMaterial_DirectLight
+#define BRDF_Material_IndirectLight    BRDF_BlinnPhongMaterial_IndirectLight

+ 7 - 75
src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl

@@ -1,82 +1,14 @@
-
-// roughness linear remapping
-
-roughnessFactor = roughnessFactor * 0.5 + 0.5; // disney's remapping of [ 0, 1 ] roughness to [ 0.5, 1 ]
-
-
-// metalness effect on color
-
-vec3 specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
-
-diffuseColor.rgb *= ( 1.0 - metalnessFactor );
-
+PhysicalMaterial material;
+material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
+material.specularRoughness = roughnessFactor * 0.5 + 0.5; // disney's remapping of [ 0, 1 ] roughness to [ 0.5, 1 ]
+material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
 
 #if defined( ENERGY_PRESERVING_RGB )
 
-	diffuseColor *= whiteCompliment( specularColor );
+	material.diffuseColor *= whiteCompliment( specularColor );
 
 #elif defined( ENERGY_PRESERVING_MONOCHROME )
 
-	diffuseColor *= whiteCompliment( luminance( specularColor ) );
-
-#endif
-
-GeometricContext geometry = GeometricContext( -vViewPosition, normalize( normal ), normalize(vViewPosition ) );
-
-ReflectedLight directReflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ) );
-ReflectedLight indirectReflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ) );
-
-
-#if MAX_POINT_LIGHTS > 0
-
-	for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
-
-		IncidentLight directLight = getPointDirectLight( pointLights[ i ], geometry );
-
-		BRDF_Lambert( directLight, geometry, diffuseColor, directReflectedLight );
-
-		BRDF_GGX( directLight, geometry, specularColor, roughnessFactor, directReflectedLight );
-
-	}
-
-#endif
-
-#if MAX_SPOT_LIGHTS > 0
-
-	for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {
-
-		IncidentLight directLight = getSpotDirectLight( pointLights[ i ], geometry );
-
-		BRDF_Lambert( directLight, geometry, diffuseColor, directReflectedLight );
-
-		BRDF_GGX( directLight, geometry, specularColor, roughnessFactor, directReflectedLight );
-
-	}
-
-#endif
-
-#if MAX_DIR_LIGHTS > 0
-
-	for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
-
-		IncidentLight directLight = getDirectionalDirectLight( pointLights[ i ], geometry );
-
-		BRDF_Lambert( directLight, geometry, diffuseColor, directReflectedLight );
-
-		BRDF_GGX( directLight, geometry, specularColor, roughnessFactor, directReflectedLight );
-
-	}
-
-#endif
-
-#if MAX_HEMI_LIGHTS > 0
-
-	for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {
-
-		IncidentLight indirectLight = getHemisphereIndirectLight( hemisphereLights[ i ], geometry );
-
-		BRDF_Lambert( indirectLight, geometry, diffuseColor, indirectReflectedLight );
-
-	}
+	material.diffuseColor *= whiteCompliment( luminance( specularColor ) );
 
-#endif
+#endif

+ 36 - 0
src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl

@@ -0,0 +1,36 @@
+struct PhysicalMaterial {
+	vec3	diffuseColor;
+	float	specularRoughness;
+	vec3	specularColor;
+	float	clearCoatWeight;
+	float	clearCoatRoughness;
+};
+
+void BRDF_PhysicalMaterial_DirectLight( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight directReflectedLight ) {
+
+	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ) );
+
+	BRDF_Lambert( directLight, geometry, material.diffuseColor, reflectedLight );
+
+	BRDF_GGX( directLight, geometry, material.specularColor, material.roughness, reflectedLight );
+
+#ifdef CLEARCOAT
+
+	BRDF_GGX_ClearCoat_Over( directLight, geometry, material.clearCoatWeight, material.clearCoatRoughness, reflectedLight );
+
+#endif
+
+	directReflectedLight.diffuse += reflectedLight.diffuse;
+	directReflectedLight.specular += reflectedLight.specular;
+	
+}
+
+
+void BRDF_PhysicalMaterial_IndirectLight( const in IncidentLight indirectLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight indirectReflectedLight ) {
+
+	BRDF_Lambert( indirectLight, geometry, material.diffuseColor, indirectReflectedLight );
+
+}
+
+#define BRDF_Material_DirectLight    BRDF_PhysicalMaterial_DirectLight
+#define BRDF_Material_IndirectLight    BRDF_PhysicalMaterial_IndirectLight

+ 57 - 0
src/renderers/shaders/ShaderChunk/lights_template.glsl

@@ -0,0 +1,57 @@
+// Instructions for use:
+//  - Ensure that both BRDF_Material_DirectLight and BRDF_Material_Indirect light are defined
+//  - Create a material parameter that is to be passed as the third parameter to your lighting functions.
+
+GeometricContext geometry = GeometricContext( -vViewPosition, normalize( normal ), normalize(vViewPosition ) );
+
+ReflectedLight directReflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ) );
+ReflectedLight indirectReflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ) );
+
+
+#if MAX_POINT_LIGHTS > 0
+
+	for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
+
+		IncidentLight directLight = getPointDirectLight( pointLights[ i ], geometry );
+
+		BRDF_Material_DirectLight( directLight, geometry, material, directReflectedLight );
+
+	}
+
+#endif
+
+#if MAX_SPOT_LIGHTS > 0
+
+	for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {
+
+		IncidentLight directLight = getSpotDirectLight( spotLights[ i ], geometry );
+
+		BRDF_Material_DirectLight( directLight, geometry, material, directReflectedLight );
+
+	}
+
+#endif
+
+#if MAX_DIR_LIGHTS > 0
+
+	for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
+
+		IncidentLight directLight = getDirectionalDirectLight( directionalLights[ i ], geometry );
+
+		BRDF_Material_DirectLight( directLight, geometry, material, directReflectedLight );
+		
+	}
+
+#endif
+
+#if MAX_HEMI_LIGHTS > 0
+
+	for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {
+
+		IncidentLight indirectLight = getHemisphereIndirectLight( hemisphereLights[ i ], geometry );
+
+		BRDF_Material_IndirectLight( indirectLight, geometry, material, indirectReflectedLight );
+
+	}
+
+#endif

+ 6 - 4
src/renderers/shaders/ShaderLib.js

@@ -144,7 +144,7 @@ THREE.ShaderLib = {
 			THREE.ShaderChunk[ "uv2_pars_vertex" ],
 			THREE.ShaderChunk[ "envmap_pars_vertex" ],
 			THREE.ShaderChunk[ "bsdfs" ],
-			THREE.ShaderChunk[ "lights" ],
+			THREE.ShaderChunk[ "lights_pars" ],
 			THREE.ShaderChunk[ "color_pars_vertex" ],
 			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
 			THREE.ShaderChunk[ "skinning_pars_vertex" ],
@@ -352,10 +352,9 @@ THREE.ShaderLib = {
 			THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
 			THREE.ShaderChunk[ "envmap_pars_fragment" ],
 			THREE.ShaderChunk[ "fog_pars_fragment" ],
+			THREE.ShaderChunk[ "bsdfs" ],
 			THREE.ShaderChunk[ "lights_pars" ],
 			THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
-			THREE.ShaderChunk[ "bsdfs" ],
-			THREE.ShaderChunk[ "lights" ],
 			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
 			THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
 			THREE.ShaderChunk[ "normalmap_pars_fragment" ],
@@ -382,6 +381,7 @@ THREE.ShaderLib = {
 				THREE.ShaderChunk[ "emissivemap_fragment" ],
 
 				THREE.ShaderChunk[ "lights_phong_fragment" ],
+				THREE.ShaderChunk[ "lights_template" ],
 				THREE.ShaderChunk[ "shadowmap_fragment" ],
 
 				"directReflectedLight.diffuse *= shadowMask;",
@@ -522,8 +522,9 @@ THREE.ShaderLib = {
 			THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
 			THREE.ShaderChunk[ "envmap_pars_fragment" ],
 			THREE.ShaderChunk[ "fog_pars_fragment" ],
+			THREE.ShaderChunk[ "bsdfs" ],
 			THREE.ShaderChunk[ "lights_pars" ],
-			THREE.ShaderChunk[ "lights_phong_pars_fragment" ], // use phong chunk for now
+			THREE.ShaderChunk[ "lights_physical_pars_fragment" ], // use phong chunk for now
 			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
 			THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
 			THREE.ShaderChunk[ "normalmap_pars_fragment" ],
@@ -555,6 +556,7 @@ THREE.ShaderLib = {
 				THREE.ShaderChunk[ "emissivemap_fragment" ],
 
 				THREE.ShaderChunk[ "lights_physical_fragment" ],
+				THREE.ShaderChunk[ "lights_template" ],
 				THREE.ShaderChunk[ "shadowmap_fragment" ],
 
 				"totalDiffuseLight *= shadowMask;",

+ 3 - 1
utils/build/includes/common.json

@@ -130,7 +130,7 @@
 	"src/renderers/shaders/ShaderChunk/envmap_vertex.glsl",
 	"src/renderers/shaders/ShaderChunk/fog_fragment.glsl",
 	"src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl",
-	"src/renderers/shaders/ShaderChunk/lights.glsl",
+	"src/renderers/shaders/ShaderChunk/lights_pars.glsl",
 	"src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl",
 	"src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl",
 	"src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl",
@@ -139,6 +139,8 @@
 	"src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl",
 	"src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl",
 	"src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl",
+	"src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl",
+	"src/renderers/shaders/ShaderChunk/lights_template.glsl",
 	"src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl",
 	"src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl",
 	"src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl",