From 0dedd3fdf357af6a5981c1bbb6b82d44e8528b0f Mon Sep 17 00:00:00 2001 From: alteredq Date: Thu, 20 Dec 2012 03:18:00 +0100 Subject: [PATCH] WebGLDeferredRenderer: added wrap around lighting to spotlights. Also unified wrapRGB in all lights to (1.0, 1.0, 1.0). Still need to figure out some way how not to have this hardcoded. --- examples/js/ShaderDeferred.js | 36 ++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/examples/js/ShaderDeferred.js b/examples/js/ShaderDeferred.js index cde2094993..b11269364a 100644 --- a/examples/js/ShaderDeferred.js +++ b/examples/js/ShaderDeferred.js @@ -478,15 +478,16 @@ THREE.ShaderDeferred = { "vec3 diffuse;", - "float diffuseFull = max( dot( normal, lightDirection ), 0.0 );", + "float dotProduct = dot( normal, lightDirection );", + "float diffuseFull = max( dotProduct, 0.0 );", "if ( wrapAround < 0.0 ) {", // wrap around lighting - "float diffuseHalf = max( 0.5 + 0.5 * dot( normal, lightDirection ), 0.0 );", + "float diffuseHalf = max( 0.5 * dotProduct + 0.5, 0.0 );", - "const vec3 wrapRGB = vec3( 0.6, 0.2, 0.2 );", + "const vec3 wrapRGB = vec3( 1.0, 1.0, 1.0 );", "diffuse = mix( vec3( diffuseFull ), vec3( diffuseHalf ), wrapRGB );", "} else {", @@ -590,7 +591,7 @@ THREE.ShaderDeferred = { // compute light "vec3 surfToLight = normalize( lightPositionVS.xyz - vertexPositionVS.xyz );", - "float dotProduct = max( dot( normal, surfToLight ), 0.0 );", + "float dotProduct = dot( normal, surfToLight );", "float rho = dot( lightDirectionVS, surfToLight );", "float rhoMax = cos( lightAngle * 0.5 );", @@ -617,7 +618,28 @@ THREE.ShaderDeferred = { "}", - "float diffuse = spot * dotProduct;", + // + + "vec3 diffuse;", + + "float diffuseFull = spot * max( dotProduct, 0.0 );", + + "if ( wrapAround < 0.0 ) {", + + // wrap around lighting + + "float diffuseHalf = spot * max( 0.5 * dotProduct + 0.5, 0.0 );", + + "const vec3 wrapRGB = vec3( 1.0, 1.0, 1.0 );", + "diffuse = mix( vec3( diffuseFull ), vec3( diffuseHalf ), wrapRGB );", + + "} else {", + + // simple lighting + + "diffuse = vec3( diffuseFull );", + + "}", "vec3 halfVector = normalize( surfToLight - normalize( vertexPositionVS.xyz ) );", "float dotNormalHalf = max( dot( normal, halfVector ), 0.0 );", @@ -706,9 +728,9 @@ THREE.ShaderDeferred = { // wrap around lighting - "float diffuseHalf = max( 0.5 + 0.5 * dotProduct, 0.0 );", + "float diffuseHalf = max( 0.5 * dotProduct + 0.5, 0.0 );", - "const vec3 wrapRGB = vec3( 0.2, 0.2, 0.2 );", + "const vec3 wrapRGB = vec3( 1.0, 1.0, 1.0 );", "diffuse = mix( vec3( diffuseFull ), vec3( diffuseHalf ), wrapRGB );", "} else {", -- GitLab