|
@@ -23576,6 +23576,14 @@ THREE.ShaderUtils = {
|
|
|
|
|
|
"#endif",
|
|
"#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",
|
|
"#if MAX_POINT_LIGHTS > 0",
|
|
|
|
|
|
"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
|
|
"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
|
|
@@ -23843,6 +23851,61 @@ THREE.ShaderUtils = {
|
|
|
|
|
|
"#endif",
|
|
"#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
|
|
// all lights contribution summation
|
|
|
|
|
|
"vec3 totalDiffuse = vec3( 0.0 );",
|
|
"vec3 totalDiffuse = vec3( 0.0 );",
|
|
@@ -23855,6 +23918,13 @@ THREE.ShaderUtils = {
|
|
|
|
|
|
"#endif",
|
|
"#endif",
|
|
|
|
|
|
|
|
+ "#if MAX_HEMI_LIGHTS > 0",
|
|
|
|
+
|
|
|
|
+ "totalDiffuse += hemiDiffuse;",
|
|
|
|
+ "totalSpecular += hemiSpecular;",
|
|
|
|
+
|
|
|
|
+ "#endif",
|
|
|
|
+
|
|
"#if MAX_POINT_LIGHTS > 0",
|
|
"#if MAX_POINT_LIGHTS > 0",
|
|
|
|
|
|
"totalDiffuse += pointDiffuse;",
|
|
"totalDiffuse += pointDiffuse;",
|