瀏覽代碼

Added physical specular term also to normal map shader.

alteredq 13 年之前
父節點
當前提交
fc639b2ab6
共有 4 個文件被更改,包括 29 次插入3 次删除
  1. 0 0
      build/Three.js
  2. 0 0
      build/custom/ThreeExtras.js
  3. 1 1
      examples/webgl_materials_normalmap2.html
  4. 28 2
      src/extras/ShaderUtils.js

文件差異過大導致無法顯示
+ 0 - 0
build/Three.js


文件差異過大導致無法顯示
+ 0 - 0
build/custom/ThreeExtras.js


+ 1 - 1
examples/webgl_materials_normalmap2.html

@@ -122,7 +122,7 @@
 
 
 				// material parameters
 				// 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 shader = THREE.ShaderUtils.lib[ "normal" ];
 				var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
 				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 pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
 							"float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 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 dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
 							"float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 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",
 
 
 						"}",
 						"}",
 
 

部分文件因文件數量過多而無法顯示