summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorTofu Linden <tofu.linden@lindenlab.com>2010-01-28 23:58:50 -0800
committerTofu Linden <tofu.linden@lindenlab.com>2010-01-28 23:58:50 -0800
commitfcaca49a9496154419a8f44c17cba16b028d3518 (patch)
tree78ec706dd7c6657e57772ae102d58281340dd560 /indra
parent1237c123873b98f2987d8d9fb573f6f88f8eebc2 (diff)
cheap no-branch goodness for rendering both spotlights and pointlights with the same shader code.
kill already-nerfed quadratic attenuation which it seems we won't be supporting any decade soon.
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl6
-rw-r--r--indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl2
-rw-r--r--indra/newview/pipeline.cpp42
3 files changed, 21 insertions, 29 deletions
diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl
index 4525bf80b2..2e41f24afe 100644
--- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl
+++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl
@@ -47,8 +47,12 @@ float calcPointLight2(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_omnid
//distance attenuation
float da = clamp(1.0/(la * d), 0.0, 1.0);
+ // spotlight coefficient.
+ float spot = max(dot(-ln, lv), is_omnidirectional);
+ da *= spot*spot; // GL_SPOT_EXPONENT=2
+
//angular attenuation
- da *= max(dot(-ln, lv),is_omnidirectional) * calcDirectionalLight(n, lv);
+ da *= calcDirectionalLight(n, lv);
return da;
}
diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl
index e5bf76db55..4577b4be55 100644
--- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl
+++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl
@@ -7,7 +7,7 @@
float calcDirectionalLight(vec3 n, vec3 l);
float calcPointLight(vec3 v, vec3 n, vec4 lp, float la);
-float calcPointLight2(vec3 v, vec3 n, vec4 lp, vec3 ln, float la);
+float calcPointLight2(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_omnidirectional);
vec3 atmosAmbient(vec3 light);
vec3 atmosAffectDirectionalLight(float lightIntensity);
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index e12412c58c..2ad0bad11f 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -4572,40 +4572,30 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
LLVector4 light_pos_gl(light_pos, 1.0f);
F32 light_radius = llmax(light->getLightRadius(), 0.001f);
- F32 atten, quad;
-#if 0 //1.9.1
- if (pool->getVertexShaderLevel() > 0)
- {
- atten = light_radius;
- quad = llmax(light->getLightFalloff(), 0.0001f);
- }
- else
-#endif
- {
- F32 x = (3.f * (1.f + light->getLightFalloff()));
- atten = x / (light_radius); // % of brightness at radius
- quad = 0.0f;
- }
+ F32 x = (3.f * (1.f + light->getLightFalloff()));
+ float linatten = x / (light_radius); // % of brightness at radius
+
mHWLightColors[cur_light] = light_color;
S32 gllight = GL_LIGHT0+cur_light;
glLightfv(gllight, GL_POSITION, light_pos_gl.mV);
glLightfv(gllight, GL_DIFFUSE, light_color.mV);
glLightfv(gllight, GL_AMBIENT, LLColor4::black.mV);
glLightf (gllight, GL_CONSTANT_ATTENUATION, 0.0f);
- glLightf (gllight, GL_LINEAR_ATTENUATION, atten);
- glLightf (gllight, GL_QUADRATIC_ATTENUATION, quad);
+ glLightf (gllight, GL_LINEAR_ATTENUATION, linatten);
+ glLightf (gllight, GL_QUADRATIC_ATTENUATION, 0.0f);
if (light->getLightTexture()) // directional (spot-)light
{
LLVector3 spotparams = light->getSpotLightParams();
LLQuaternion quat = light->getRenderRotation();
LLVector3 at_axis(0,0,-1); // this matches deferred rendering's object light direction
at_axis *= quat;
- llinfos << "SPOT!!!!!!! fov: " << spotparams.mV[0] << " focus: " << spotparams.mV[1] << " dir: " << at_axis << llendl;
+ //llinfos << "SPOT!!!!!!! fov: " << spotparams.mV[0] << " focus: " << spotparams.mV[1] << " dir: " << at_axis << llendl;
glLightfv(gllight, GL_SPOT_DIRECTION, at_axis.mV);
- glLightf (gllight, GL_SPOT_EXPONENT, 1.0f); // 1.0 = good old dot product
+ glLightf (gllight, GL_SPOT_EXPONENT, 2.0f); // 2.0 = good old dot product ^ 2
glLightf (gllight, GL_SPOT_CUTOFF, 90.0f); // hemisphere
- glLightfv(gllight, GL_SPECULAR, LLColor4::black.mV);
+ const float specular[] = {0.f, 0.f, 0.f, 0.f};
+ glLightfv(gllight, GL_SPECULAR, specular);
}
else // omnidirectional (point) light
{
@@ -4615,6 +4605,7 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
// we use specular.w = 1.0 as a cheap hack for the shaders to know that this is omnidirectional rather than a spotlight
const float specular[] = {0.f, 0.f, 0.f, 1.f};
glLightfv(gllight, GL_SPECULAR, specular);
+ //llinfos << "boring light" << llendl;
}
cur_light++;
if (cur_light >= 8)
@@ -4641,13 +4632,10 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
LLVector4 light_pos_gl(light_pos, 1.0f);
F32 light_radius = 16.f;
- F32 atten, quad;
- {
- F32 x = 3.f;
- atten = x / (light_radius); // % of brightness at radius
- quad = 0.0f;
- }
+ F32 x = 3.f;
+ float linatten = x / (light_radius); // % of brightness at radius
+
mHWLightColors[2] = light_color;
S32 gllight = GL_LIGHT2;
glLightfv(gllight, GL_POSITION, light_pos_gl.mV);
@@ -4655,8 +4643,8 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
glLightfv(gllight, GL_AMBIENT, LLColor4::black.mV);
glLightfv(gllight, GL_SPECULAR, LLColor4::black.mV);
glLightf (gllight, GL_CONSTANT_ATTENUATION, 0.0f);
- glLightf (gllight, GL_LINEAR_ATTENUATION, atten);
- glLightf (gllight, GL_QUADRATIC_ATTENUATION, quad);
+ glLightf (gllight, GL_LINEAR_ATTENUATION, linatten);
+ glLightf (gllight, GL_QUADRATIC_ATTENUATION, 0.0f);
glLightf (gllight, GL_SPOT_EXPONENT, 0.0f);
glLightf (gllight, GL_SPOT_CUTOFF, 180.0f);
}