From 5d5e034488d704c0061d525495d6ec0d20ed7b6c Mon Sep 17 00:00:00 2001 From: alteredq Date: Fri, 24 Aug 2012 15:48:25 +0200 Subject: [PATCH] Added HemisphereLight support to simple skin shader. --- examples/js/ShaderSkin.js | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/examples/js/ShaderSkin.js b/examples/js/ShaderSkin.js index 7ea9d194a2..ec94fae792 100644 --- a/examples/js/ShaderSkin.js +++ b/examples/js/ShaderSkin.js @@ -92,6 +92,14 @@ THREE.ShaderSkin = { "#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 ];", @@ -239,6 +247,38 @@ THREE.ShaderSkin = { "#endif", + // hemisphere lights + + "#if MAX_HEMI_LIGHTS > 0", + + "vec3 hemiTotal = 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 );", + + "float dotProduct = dot( normal, lVector );", + "float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;", + + "hemiTotal += uDiffuseColor * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );", + + // specular (sky light) + + "float hemiSpecularWeight = 0.0;", + "hemiSpecularWeight += KS_Skin_Specular( normal, lVector, viewPosition, uRoughness, uSpecularBrightness );", + + // specular (ground light) + + "vec3 lVectorGround = normalize( -lPosition.xyz + vViewPosition.xyz );", + "hemiSpecularWeight += KS_Skin_Specular( normal, lVectorGround, viewPosition, uRoughness, uSpecularBrightness );", + + "specularTotal += uSpecularColor * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * specularStrength;", + + "}", + + "#endif", + // all lights contribution summation "vec3 totalLight = vec3( 0.0 );", @@ -251,6 +291,10 @@ THREE.ShaderSkin = { "totalLight += pointTotal;", "#endif", + "#if MAX_HEMI_LIGHTS > 0", + "totalLight += hemiTotal;", + "#endif", + "gl_FragColor.xyz = gl_FragColor.xyz * ( totalLight + ambientLightColor * uAmbientColor ) + specularTotal;", THREE.ShaderChunk[ "shadowmap_fragment" ], -- GitLab