Преглед изворни кода

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

Неке датотеке нису приказане због велике количине промена

粤ICP备19079148号