瀏覽代碼

Trying to make less weird specular term for hemisphere light.

This is all just guessing. Other people have only diffuse term for hemisphere lights, but there should be also some specular term, in real world shiny things are shiny no matter which light.
alteredq 13 年之前
父節點
當前提交
f31cc7fe6b
共有 2 個文件被更改,包括 9 次插入7 次删除
  1. 0 0
      build/three.min.js
  2. 9 7
      src/renderers/WebGLShaders.js

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


+ 9 - 7
src/renderers/WebGLShaders.js

@@ -1105,15 +1105,15 @@ THREE.ShaderChunk = {
 				"float dotProduct = dot( normal, lVector );",
 				"float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
 
-				"hemiDiffuse += diffuse * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
+				"vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
 
-				// specular (sky light)
+				"hemiDiffuse += diffuse * hemiColor;",
 
-				"float hemiSpecularWeight = 0.0;",
+				// specular (sky light)
 
 				"vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );",
 				"float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
-				"hemiSpecularWeight += specularStrength * max( pow( hemiDotNormalHalfSky, shininess ), 0.0 );",
+				"float hemiSpecularWeightSky = specularStrength * max( pow( hemiDotNormalHalfSky, shininess ), 0.0 );",
 
 				// specular (ground light)
 
@@ -1121,21 +1121,23 @@ THREE.ShaderChunk = {
 
 				"vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
 				"float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
-				"hemiSpecularWeight += specularStrength * max( pow( hemiDotNormalHalfGround, shininess ), 0.0 );",
+				"float hemiSpecularWeightGround = specularStrength * max( pow( hemiDotNormalHalfGround, shininess ), 0.0 );",
 
 				"#ifdef PHYSICALLY_BASED_SHADING",
 
+					"float dotProductGround = dot( normal, lVectorGround );",
+
 					// 2.0 => 2.0001 is hack to work around ANGLE bug
 
 					"float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
 
 					"vec3 schlickSky = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, hemiHalfVectorSky ), 5.0 );",
 					"vec3 schlickGround = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 5.0 );",
-					"hemiSpecular += ( schlickSky + schlickGround ) * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight * specularNormalization;",
+					"hemiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );",
 
 				"#else",
 
-					"hemiSpecular += specular * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight;",
+					"hemiSpecular += specular * hemiColor * ( hemiSpecularWeightSky + hemiSpecularWeightGround ) * hemiDiffuseWeight;",
 
 				"#endif",
 

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