|
@@ -279,7 +279,20 @@ THREE.ShaderUtils = {
|
|
|
"float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
|
|
|
"float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );",
|
|
|
|
|
|
- "pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;",
|
|
|
+ "#ifdef PHYSICALLY_BASED_SHADING",
|
|
|
+
|
|
|
+ // 2.0 => 2.0001 is hack to work around ANGLE bug
|
|
|
+
|
|
|
+ "float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
|
|
|
+
|
|
|
+ "vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( pointVector, pointHalfVector ), 5.0 );",
|
|
|
+ "pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;",
|
|
|
+
|
|
|
+ "#else",
|
|
|
+
|
|
|
+ "pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;",
|
|
|
+
|
|
|
+ "#endif",
|
|
|
|
|
|
"}",
|
|
|
|
|
@@ -320,7 +333,20 @@ THREE.ShaderUtils = {
|
|
|
"float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
|
|
|
"float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );",
|
|
|
|
|
|
- "dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;",
|
|
|
+ "#ifdef PHYSICALLY_BASED_SHADING",
|
|
|
+
|
|
|
+ // 2.0 => 2.0001 is hack to work around ANGLE bug
|
|
|
+
|
|
|
+ "float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
|
|
|
+
|
|
|
+ "vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );",
|
|
|
+ "dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
|
|
|
+
|
|
|
+ "#else",
|
|
|
+
|
|
|
+ "dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;",
|
|
|
+
|
|
|
+ "#endif",
|
|
|
|
|
|
"}",
|
|
|
|