|
@@ -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
|
|
|
|