summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeenz <geenz@geenzo.com>2013-01-25 17:53:43 -0500
committerGeenz <geenz@geenzo.com>2013-01-25 17:53:43 -0500
commitcc7ae8fbd1fc249f77ced95171e5c22e48adedb6 (patch)
tree810aaa0aae47011eb0ff99a8389099b57e7e22f2
parentde0863ed6e91fda0c1b5342b9fecf07c4af47d63 (diff)
Linearize light source colors, and a bit of cook torrance fanciness.
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl13
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl16
-rw-r--r--indra/newview/pipeline.cpp26
3 files changed, 43 insertions, 12 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl
index 9e194cdcd1..ad50690c02 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl
@@ -123,13 +123,20 @@ void main()
if (spec.a > 0.0)
{
//vec3 ref = dot(pos+lv, norm);
+ vec3 h = normalize(lv+npos);
+ float nh = dot(norm, h);
+ float nv = dot(norm, npos);
+ float vh = dot(npos, h);
+ float sa = nh;
+ vec3 fres = spec.rgb + pow(1 - dot(h, npos), 5) * (1 - spec.rgb);
+ float gtdenom = 2 * nh;
+ float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
- float sa = dot(normalize(lv+npos),norm);
if (sa > 0.0)
{
- sa = texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0);
- col += da*sa*light_col[i].rgb*spec.rgb;
+ vec3 scol = (fres * texture2D(lightFunc, vec2(nh, spec.a)).r * gt) / (nh * da);
+ col += lit*scol*light_col[i].rgb;
}
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl
index fa1572e692..03b036375b 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl
@@ -107,12 +107,20 @@ void main()
vec4 spec = texture2DRect(specularRect, frag.xy);
if (spec.a > 0.0)
{
- float sa = dot(normalize(lv-normalize(pos)),norm);
- spec.rgb += pow(1 - dot(-normalize(pos), norm), 2) * da * 3;
+ 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;
+ vec3 fres = spec.rgb + pow(1 - dot(h, npos), 5) * (1 - spec.rgb);
+ float gtdenom = 2 * nh;
+ float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh)));
+
if (sa > 0.0)
{
- sa = texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0);
- col += da*sa*color.rgb*spec.rgb;
+ vec3 scol = (fres * texture2D(lightFunc, vec2(nh, spec.a)).r * gt) / (nh * da);
+ col += lit*scol*color.rgb;
}
}
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 205598060a..07246391e3 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -1196,7 +1196,7 @@ void LLPipeline::createGLBuffers()
for (U32 i = 0; i < 3; i++)
{
- mGlow[i].allocate(512,glow_res,GL_RGBA,FALSE,FALSE);
+ mGlow[i].allocate(512,glow_res,sRenderDeferred ? GL_RGB10_A2 : GL_RGB10_A2,FALSE,FALSE);
}
allocateScreenBuffer(resX,resY);
@@ -7858,6 +7858,22 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 n
}
}
+LLColor3 pow3f(LLColor3 v, F32 f)
+{
+ v.mV[0] = powf(v.mV[0], f);
+ v.mV[1] = powf(v.mV[1], f);
+ v.mV[2] = powf(v.mV[2], f);
+ return v;
+}
+
+LLVector4 pow4fsrgb(LLVector4 v, F32 f)
+{
+ v.mV[0] = powf(v.mV[0], f);
+ v.mV[1] = powf(v.mV[1], f);
+ v.mV[2] = powf(v.mV[2], f);
+ return v;
+}
+
static LLFastTimer::DeclareTimer FTM_GI_TRACE("Trace");
static LLFastTimer::DeclareTimer FTM_GI_GATHER("Gather");
static LLFastTimer::DeclareTimer FTM_SUN_SHADOW("Shadow Map");
@@ -8193,7 +8209,7 @@ void LLPipeline::renderDeferredLighting()
LLFastTimer ftm(FTM_LOCAL_LIGHTS);
gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s*s);
- gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
+ gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, pow3f(col, 2.2f).mV);
gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f);
gGL.syncMatrices();
@@ -8249,7 +8265,7 @@ void LLPipeline::renderDeferredLighting()
gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s*s);
- gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
+ gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, pow3f(col, 2.2f).mV);
gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f);
gGL.syncMatrices();
@@ -8296,7 +8312,7 @@ void LLPipeline::renderDeferredLighting()
light_colors.pop_front();
far_z = llmin(light[count].mV[2]-sqrtf(light[count].mV[3]), far_z);
-
+ col[count] = pow4fsrgb(col[count], 2.2f);
count++;
if (count == max_count || fullscreen_lights.empty())
{
@@ -8340,7 +8356,7 @@ void LLPipeline::renderDeferredLighting()
gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v);
gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s*s);
- gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
+ gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, pow3f(col, 2.2f).mV);
gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f);
mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3);
}