Browse Source

Added physical specular term also to normal map shader.

alteredq 13 năm trước cách đây
mục cha
commit
fc639b2ab6

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
build/Three.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
build/custom/ThreeExtras.js


+ 1 - 1
examples/webgl_materials_normalmap2.html

@@ -122,7 +122,7 @@
 
 				// material parameters
 
-				var ambient = 0x111111, diffuse = 0xbbbbbb, specular = 0x171717, shininess = 50;
+				var ambient = 0x111111, diffuse = 0xbbbbbb, specular = 0x060606, shininess = 35;
 
 				var shader = THREE.ShaderUtils.lib[ "normal" ];
 				var uniforms = THREE.UniformsUtils.clone( shader.uniforms );

+ 28 - 2
src/extras/ShaderUtils.js

@@ -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",
 
 						"}",
 

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác