فهرست منبع

Added handling of HemisphereLight to normal map shader.

alteredq 13 سال پیش
والد
کامیت
0d1c3ac212
3فایلهای تغییر یافته به همراه140 افزوده شده و 1 حذف شده
  1. 70 0
      build/three.js
  2. 0 1
      build/three.min.js
  3. 70 0
      src/extras/ShaderUtils.js

+ 70 - 0
build/three.js

@@ -23576,6 +23576,14 @@ THREE.ShaderUtils = {
 
 				"#endif",
 
+				"#if MAX_HEMI_LIGHTS > 0",
+
+					"uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];",
+					"uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];",
+					"uniform vec3 hemisphereLightPosition[ MAX_HEMI_LIGHTS ];",
+
+				"#endif",
+
 				"#if MAX_POINT_LIGHTS > 0",
 
 					"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
@@ -23843,6 +23851,61 @@ THREE.ShaderUtils = {
 
 					"#endif",
 
+					// hemisphere lights
+
+					"#if MAX_HEMI_LIGHTS > 0",
+
+						"vec3 hemiDiffuse  = vec3( 0.0 );",
+						"vec3 hemiSpecular = vec3( 0.0 );" ,
+
+						"for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {",
+
+							"vec4 lPosition = viewMatrix * vec4( hemisphereLightPosition[ i ], 1.0 );",
+							"vec3 lVector = normalize( lPosition.xyz + vViewPosition.xyz );",
+
+							// diffuse
+
+							"float dotProduct = dot( normal, lVector );",
+							"float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
+
+							"hemiDiffuse += uDiffuseColor * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
+
+							// 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 );",
+
+							// specular (ground light)
+
+							"vec3 lVectorGround = normalize( -lPosition.xyz + vViewPosition.xyz );",
+
+							"vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
+							"float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
+							"hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfGround, uShininess ), 0.0 );",
+
+							"#ifdef PHYSICALLY_BASED_SHADING",
+
+								// 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;",
+
+							"#else",
+
+								"hemiSpecular += uSpecularColor * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight;",
+
+							"#endif",
+
+						"}",
+
+					"#endif",
+
 					// all lights contribution summation
 
 					"vec3 totalDiffuse = vec3( 0.0 );",
@@ -23855,6 +23918,13 @@ THREE.ShaderUtils = {
 
 					"#endif",
 
+					"#if MAX_HEMI_LIGHTS > 0",
+
+						"totalDiffuse += hemiDiffuse;",
+						"totalSpecular += hemiSpecular;",
+
+					"#endif",
+
 					"#if MAX_POINT_LIGHTS > 0",
 
 						"totalDiffuse += pointDiffuse;",

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 1
build/three.min.js


+ 70 - 0
src/extras/ShaderUtils.js

@@ -185,6 +185,14 @@ THREE.ShaderUtils = {
 
 				"#endif",
 
+				"#if MAX_HEMI_LIGHTS > 0",
+
+					"uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];",
+					"uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];",
+					"uniform vec3 hemisphereLightPosition[ MAX_HEMI_LIGHTS ];",
+
+				"#endif",
+
 				"#if MAX_POINT_LIGHTS > 0",
 
 					"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
@@ -452,6 +460,61 @@ THREE.ShaderUtils = {
 
 					"#endif",
 
+					// hemisphere lights
+
+					"#if MAX_HEMI_LIGHTS > 0",
+
+						"vec3 hemiDiffuse  = vec3( 0.0 );",
+						"vec3 hemiSpecular = vec3( 0.0 );" ,
+
+						"for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {",
+
+							"vec4 lPosition = viewMatrix * vec4( hemisphereLightPosition[ i ], 1.0 );",
+							"vec3 lVector = normalize( lPosition.xyz + vViewPosition.xyz );",
+
+							// diffuse
+
+							"float dotProduct = dot( normal, lVector );",
+							"float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
+
+							"hemiDiffuse += uDiffuseColor * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
+
+							// 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 );",
+
+							// specular (ground light)
+
+							"vec3 lVectorGround = normalize( -lPosition.xyz + vViewPosition.xyz );",
+
+							"vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
+							"float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
+							"hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfGround, uShininess ), 0.0 );",
+
+							"#ifdef PHYSICALLY_BASED_SHADING",
+
+								// 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;",
+
+							"#else",
+
+								"hemiSpecular += uSpecularColor * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight;",
+
+							"#endif",
+
+						"}",
+
+					"#endif",
+
 					// all lights contribution summation
 
 					"vec3 totalDiffuse = vec3( 0.0 );",
@@ -464,6 +527,13 @@ THREE.ShaderUtils = {
 
 					"#endif",
 
+					"#if MAX_HEMI_LIGHTS > 0",
+
+						"totalDiffuse += hemiDiffuse;",
+						"totalSpecular += hemiSpecular;",
+
+					"#endif",
+
 					"#if MAX_POINT_LIGHTS > 0",
 
 						"totalDiffuse += pointDiffuse;",

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است