summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Parks <davep@lindenlab.com>2013-07-01 10:53:09 -0500
committerDave Parks <davep@lindenlab.com>2013-07-01 10:53:09 -0500
commit1c9a4fc080bee955b5b18750fe8de7c24a3f912f (patch)
tree8cc8d098bbb61765920f3d7b9da7382ee16e9f30
parent7df863265f6f536aeae84dceab9140fb4465213c (diff)
NORSPEC-290 Shader optimization WIP -- remove some more divides and normalizes from various lighting functions, rework flow control based on profile feedback.
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl6
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl86
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl2
-rwxr-xr-xindra/newview/pipeline.cpp6
4 files changed, 46 insertions, 54 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl
index a955ef6e9d..ed51e01a53 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl
@@ -107,14 +107,14 @@ void main()
for (int i = 0; i < LIGHT_COUNT; ++i)
{
vec3 lv = light[i].xyz-pos;
- float dist = length(lv);
- dist /= light[i].w;
+ float d = length(lv);
+ float dist = d * light[i].w;
if (dist <= 1.0)
{
float da = dot(norm, lv);
if (da > 0.0)
{
- lv = normalize(lv);
+ lv /= d;
da = dot(norm, lv);
float fa = light_col[i].a+1.0;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl
index 106d48bd71..f162f70592 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl
@@ -35,7 +35,7 @@ uniform sampler2DRect diffuseRect;
uniform sampler2DRect specularRect;
uniform sampler2DRect normalMap;
uniform samplerCube environmentMap;
-uniform sampler2D noiseMap;
+//uniform sampler2D noiseMap;
uniform sampler2D lightFunc;
uniform sampler2DRect depthMap;
@@ -93,64 +93,56 @@ void main()
vec3 pos = getPosition(frag.xy).xyz;
vec3 lv = trans_center.xyz-pos;
- float dist = length(lv);
- dist /= size;
- if (dist > 1.0)
- {
- discard;
- }
+ float d = length(lv);
- vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
- norm = decode_normal(norm.xy); // unpack norm
- float da = dot(norm, lv);
- if (da < 0.0)
+ float dist = d*size;
+
+ vec3 col = vec3(0.0);
+ if (dist <= 1.0)
{
- discard;
- }
+ vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
+ norm = decode_normal(norm.xy); // unpack norm
+ float da = dot(norm, lv);
- norm = normalize(norm);
- lv = normalize(lv);
- da = dot(norm, lv);
+ norm = normalize(norm);
+ lv = normalize(lv);
+ da = max(dot(norm, lv), 0.0);
- float noise = texture2D(noiseMap, frag.xy/128.0).b;
+ //float noise = texture2D(noiseMap, frag.xy/128.0).b;
- vec3 col = texture2DRect(diffuseRect, frag.xy).rgb;
- float fa = falloff+1.0;
- 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;
+ col = texture2DRect(diffuseRect, frag.xy).rgb;
+ float fa = falloff+1.0;
+ float dist_atten = clamp(1.0-(dist-1.0+fa)/fa, 0.0, 1.0);
+ dist_atten *= dist_atten;
+ dist_atten *= 2.0;
- float lit = da * dist_atten * noise;
+ float lit = da * dist_atten; // * noise;
- col = color.rgb*lit*col;
+ col = color.rgb*lit*col;
- vec4 spec = texture2DRect(specularRect, frag.xy);
- if (spec.a > 0.0)
- {
- lit = min(da*6.0, 1.0) * dist_atten;
-
- vec3 npos = -normalize(pos);
- vec3 h = normalize(lv+npos);
- float nh = dot(norm, h);
- float nv = dot(norm, npos);
- float vh = dot(npos, h);
- float sa = nh;
- float fres = pow(1 - dot(h, npos), 5) * 0.4+0.5;
- float gtdenom = 2 * nh;
- float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh)));
-
- if (nh > 0.0)
+ vec4 spec = texture2DRect(specularRect, frag.xy);
+ if (spec.a > 0.0)
{
- float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
- col += lit*scol*color.rgb*spec.rgb;
+ lit = min(da*6.0, 1.0) * dist_atten;
+
+ vec3 npos = -normalize(pos);
+ vec3 h = normalize(lv+npos);
+ float nh = dot(norm, h);
+ float nv = dot(norm, npos);
+ float vh = dot(npos, h);
+ float sa = nh;
+ float fres = pow(1 - dot(h, npos), 5) * 0.4+0.5;
+ float gtdenom = 2 * nh;
+ float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh)));
+
+ if (nh > 0.0)
+ {
+ float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
+ col += lit*scol*color.rgb*spec.rgb;
+ }
}
}
- if (dot(col, col) <= 0.0)
- {
- discard;
- }
-
frag_color.rgb = col;
frag_color.a = 0.0;
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl
index a5625fbc16..aeef09cf5f 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl
@@ -37,7 +37,7 @@ VARYING vec3 trans_center;
void main()
{
//transform vertex
- vec3 p = position*size+center;
+ vec3 p = position*1.f/size+center;
vec4 pos = modelview_projection_matrix * vec4(p.xyz, 1.0);
vary_fragcoord = pos;
trans_center = (modelview_matrix*vec4(center.xyz, 1.0)).xyz;
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 7072c95c3e..7fa0a972ad 100755
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -8680,7 +8680,7 @@ void LLPipeline::renderDeferredLighting()
LLFastTimer ftm(FTM_LOCAL_LIGHTS);
gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
- gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);
+ gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, 1.f/s);
gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f);
gGL.syncMatrices();
@@ -8701,7 +8701,7 @@ void LLPipeline::renderDeferredLighting()
glh::vec3f tc(c);
mat.mult_matrix_vec(tc);
- fullscreen_lights.push_back(LLVector4(tc.v[0], tc.v[1], tc.v[2], s));
+ fullscreen_lights.push_back(LLVector4(tc.v[0], tc.v[1], tc.v[2], 1.f/s));
light_colors.push_back(LLVector4(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff()*0.5f));
}
}
@@ -8786,7 +8786,7 @@ void LLPipeline::renderDeferredLighting()
col[count].mV[1] = powf(col[count].mV[1], 2.2f);
col[count].mV[2] = powf(col[count].mV[2], 2.2f);*/
- far_z = llmin(light[count].mV[2]-light[count].mV[3], far_z);
+ far_z = llmin(light[count].mV[2]-1.f/light[count].mV[3], far_z);
//col[count] = pow4fsrgb(col[count], 2.2f);
count++;
if (count == max_count || fullscreen_lights.empty())