From 9a007cceeffb1b960ba495cd0e3d592698a52a99 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 4 Feb 2019 12:56:11 -0800 Subject: SL-10461 Pass projector ambiance as the .w element of the light_attenuation uniform so that alpha shader can emulate the behavior of proper spot projectors. --- .../shaders/class1/deferred/alphaF.glsl | 27 ++++++++++++---------- indra/newview/pipeline.cpp | 8 ++++--- 2 files changed, 20 insertions(+), 15 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index f1b7a1312f..772859576f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -63,7 +63,7 @@ uniform vec2 screen_res; uniform vec4 light_position[8]; uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; +uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; #ifdef WATER_FOG @@ -79,7 +79,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); -vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance) { //get light vector vec3 lv = lp.xyz-v; @@ -91,13 +91,16 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec vec3 col = vec3(0); - if (d > 0.0 && la > 0.0 && fa > 0.0) + if (d > 0.0 && fa > 0.0) { //normalize light vector lv = normalize(lv); - + vec3 norm = normalize(n); + + da = max(0.0, dot(norm, lv)); + //distance attenuation - float dist = d/la; + float dist = d; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; @@ -106,17 +109,17 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 - //angular attenuation - da *= max(dot(n, lv), 0.0); - float lit = max(da * dist_atten,0.0); - col = light_col * lit * diffuse; + float amb_da = (da*da*0.5 + 0.5) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + col.rgb += amb_da * light_col * diffuse; // no spec for alpha shader... } - - return max(col, vec3(0.0,0.0,0.0)); + col = max(col, vec3(0)); + return col; } void main() @@ -199,7 +202,7 @@ void main() vec4 light = vec4(0,0,0,0); - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diff.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diff.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); LIGHT_LOOP(1) LIGHT_LOOP(2) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 0784f3acdd..86b9038e3f 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -6482,7 +6482,9 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) light_state->setSpotCutoff(90.f); light_state->setSpotExponent(2.f); - const LLColor4 specular(0.f, 0.f, 0.f, 0.f); + LLVector3 spotParams = light->getSpotLightParams(); + + const LLColor4 specular(0.f, 0.f, 0.f, spotParams[2]); light_state->setSpecular(specular); } else // omnidirectional (point) light @@ -6491,8 +6493,8 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) light_state->setSpotCutoff(180.f); // we use specular.w = 1.0 as a cheap hack for the shaders to know that this is omnidirectional rather than a spotlight - const LLColor4 specular(0.f, 0.f, 0.f, 1.f); - light_state->setSpecular(specular); + const LLColor4 specular(0.f, 0.f, 1.f, 0.f); + light_state->setSpecular(specular); } cur_light++; if (cur_light >= 8) -- cgit v1.2.3