소스 검색

Made normal map shader consistent with Phong shader.

Transplanted hemisphere specular from Phong. Also had to go back to using varying for view position as computing it in the fragment shader wasn't really working :S
alteredq 13 년 전
부모
커밋
0faca8f468
2개의 변경된 파일12개의 추가작업 그리고 9개의 파일을 삭제
  1. 0 1
      build/three.min.js
  2. 12 8
      src/extras/ShaderUtils.js

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 1
build/three.min.js


+ 12 - 8
src/extras/ShaderUtils.js

@@ -219,14 +219,13 @@ THREE.ShaderUtils = {
 				"#endif",
 
 				"varying vec3 vWorldPosition;",
+				"varying vec3 vViewPosition;",
 
 				THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
 				THREE.ShaderChunk[ "fog_pars_fragment" ],
 
 				"void main() {",
 
-					"vec3 vViewPosition = cameraPosition - vWorldPosition;",
-
 					"gl_FragColor = vec4( vec3( 1.0 ), uOpacity );",
 
 					"vec3 specularTex = vec3( 1.0 );",
@@ -483,15 +482,16 @@ THREE.ShaderUtils = {
 							"float dotProduct = dot( normal, lVector );",
 							"float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
 
-							"hemiDiffuse += uDiffuseColor * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
+							"vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
+
+							"hemiDiffuse += uDiffuseColor * hemiColor;",
 
 							// specular (sky light)
 
-							"float hemiSpecularWeight = 0.0;",
 
 							"vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );",
 							"float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
-							"hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfSky, uShininess ), 0.0 );",
+							"float hemiSpecularWeightSky = specularTex.r * max( pow( hemiDotNormalHalfSky, uShininess ), 0.0 );",
 
 							// specular (ground light)
 
@@ -499,21 +499,23 @@ THREE.ShaderUtils = {
 
 							"vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
 							"float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
-							"hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfGround, uShininess ), 0.0 );",
+							"float hemiSpecularWeightGround = specularTex.r * max( pow( hemiDotNormalHalfGround, uShininess ), 0.0 );",
 
 							"#ifdef PHYSICALLY_BASED_SHADING",
 
+								"float dotProductGround = dot( normal, lVectorGround );",
+
 								// 2.0 => 2.0001 is hack to work around ANGLE bug
 
 								"float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
 
 								"vec3 schlickSky = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( lVector, hemiHalfVectorSky ), 5.0 );",
 								"vec3 schlickGround = uSpecularColor + vec3( 1.0 - uSpecularColor ) * 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 += uSpecularColor * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight;",
+								"hemiSpecular += uSpecularColor * hemiColor * ( hemiSpecularWeightSky + hemiSpecularWeightGround ) * hemiDiffuseWeight;",
 
 							"#endif",
 
@@ -622,6 +624,7 @@ THREE.ShaderUtils = {
 				"varying vec2 vUv;",
 
 				"varying vec3 vWorldPosition;",
+				"varying vec3 vViewPosition;",
 
 				THREE.ShaderChunk[ "skinning_pars_vertex" ],
 				THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
@@ -711,6 +714,7 @@ THREE.ShaderUtils = {
 					//
 
 					"vWorldPosition = mPosition.xyz;",
+					"vViewPosition = -mvPosition.xyz;",
 
 					// shadows
 

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.