summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class1/deferred
diff options
context:
space:
mode:
authorGraham Linden <graham@lindenlab.com>2013-08-05 06:23:13 -0700
committerGraham Linden <graham@lindenlab.com>2013-08-05 06:23:13 -0700
commit08e429e27df488cb8740eb82f3fb10d5011e6f5d (patch)
tree9920646b55c9ec1f92bd8176a178707e1fedb360 /indra/newview/app_settings/shaders/class1/deferred
parent938ad0c640a72dc7ee8bf39ad138e6d84d1d0a1e (diff)
NORSPEC-285 NORSPEC-293 NORSPEC-298 fix ighting diffs between alpha/non/ALM/non-ALM
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/alphaF.glsl48
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/materialF.glsl108
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl22
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl10
4 files changed, 125 insertions, 63 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
index d11f67ee58..d0c7cc9dde 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
@@ -133,6 +133,23 @@ vec3 linear_to_srgb(vec3 cl)
}
+vec2 encode_normal(vec3 n)
+{
+ float f = sqrt(8 * n.z + 8);
+ return n.xy / f + 0.5;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec2 fenc = enc*4-2;
+ float f = dot(fenc,fenc);
+ float g = sqrt(1-f/4);
+ vec3 n;
+ n.xy = fenc*g;
+ n.z = 1-f/2;
+ return n;
+}
+
vec3 calcDirectionalLight(vec3 n, vec3 l)
{
float a = max(dot(n,l),0.0);
@@ -527,33 +544,42 @@ void main()
vec3 norm = vary_norm;
calcAtmospherics(pos.xyz, 1.0);
-
- float da =dot(norm.xyz, sun_dir.xyz);
+
+ vec2 abnormal = encode_normal(norm.xyz);
+ norm.xyz = decode_normal(abnormal.xy);
+
+ float da = dot(norm.xyz, sun_dir.xyz);
+
float final_da = da;
final_da = min(final_da, shadow);
- final_da = max(final_da, final_alpha);
final_da = max(final_da, 0.0f);
+ final_da = min(final_da, 1.0f);
+ final_da = pow(final_da, 1.0/1.3);
vec4 color = vec4(0,0,0,0);
color.rgb = atmosAmbient(color.rgb);
color.a = final_alpha;
- float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);
+ float ambient = abs(da);
ambient *= 0.5;
ambient *= ambient;
ambient = (1.0-ambient);
color.rgb *= ambient;
- color.rgb += atmosAffectDirectionalLight(pow(final_da, 1.0/1.3));
+ color.rgb += atmosAffectDirectionalLight(final_da);
color.rgb *= gamma_diff.rgb;
- color.rgb = mix(atmosLighting(color.rgb), fullbrightAtmosTransport(color.rgb), diff.a);
- color.rgb = mix(scaleSoftClip(color.rgb), fullbrightScaleSoftClip(color.rgb), diff.a);
+ color.rgb = mix(diff.rgb, color.rgb, final_alpha);
+
+ color.rgb = atmosLighting(color.rgb);
+ color.rgb = scaleSoftClip(color.rgb);
vec4 light = vec4(0,0,0,0);
-
+
+ color.rgb = srgb_to_linear(color.rgb);
+
#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_LOOP(1)
@@ -566,11 +592,11 @@ void main()
// keep it linear
//
- color.rgb = srgb_to_linear(color.rgb) + light.rgb;
+ color.rgb += light.rgb;
- // ramp directly to display gamma as we're POST-deferred
+ // straight to display gamma, we're post-deferred
//
- color.rgb = pow(color.rgb,vec3(display_gamma));
+ color.rgb = linear_to_srgb(color.rgb);
#ifdef WATER_FOG
color = applyWaterFogDeferred(pos.xyz, color);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
index b3ae81d494..8202b4978f 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
@@ -29,6 +29,44 @@
#define DIFFUSE_ALPHA_MODE_EMISSIVE 3
uniform float emissive_brightness;
+uniform float display_gamma;
+
+vec3 srgb_to_linear(vec3 cs)
+{
+ vec3 low_range = cs / vec3(12.92);
+ vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4));
+ bvec3 lte = lessThanEqual(cs,vec3(0.04045));
+
+#ifdef OLD_SELECT
+ vec3 result;
+ result.r = lte.r ? low_range.r : high_range.r;
+ result.g = lte.g ? low_range.g : high_range.g;
+ result.b = lte.b ? low_range.b : high_range.b;
+ return result;
+#else
+ return mix(high_range, low_range, lte);
+#endif
+
+}
+
+vec3 linear_to_srgb(vec3 cl)
+{
+ cl = clamp(cl, vec3(0), vec3(1));
+ vec3 low_range = cl * 12.92;
+ vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055;
+ bvec3 lt = lessThan(cl,vec3(0.0031308));
+
+#ifdef OLD_SELECT
+ vec3 result;
+ result.r = lt.r ? low_range.r : high_range.r;
+ result.g = lt.g ? low_range.g : high_range.g;
+ result.b = lt.b ? low_range.b : high_range.b;
+ return result;
+#else
+ return mix(high_range, low_range, lt);
+#endif
+
+}
#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
@@ -114,43 +152,6 @@ uniform vec3 light_direction[8];
uniform vec3 light_attenuation[8];
uniform vec3 light_diffuse[8];
-vec3 srgb_to_linear(vec3 cs)
-{
- vec3 low_range = cs / vec3(12.92);
- vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4));
- bvec3 lte = lessThanEqual(cs,vec3(0.04045));
-
-#ifdef OLD_SELECT
- vec3 result;
- result.r = lte.r ? low_range.r : high_range.r;
- result.g = lte.g ? low_range.g : high_range.g;
- result.b = lte.b ? low_range.b : high_range.b;
- return result;
-#else
- return mix(high_range, low_range, lte);
-#endif
-
-}
-
-vec3 linear_to_srgb(vec3 cl)
-{
- cl = clamp(cl, vec3(0), vec3(1));
- vec3 low_range = cl * 12.92;
- vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055;
- bvec3 lt = lessThan(cl,vec3(0.0031308));
-
-#ifdef OLD_SELECT
- vec3 result;
- result.r = lt.r ? low_range.r : high_range.r;
- result.g = lt.g ? low_range.g : high_range.g;
- result.b = lt.b ? low_range.b : high_range.b;
- return result;
-#else
- return mix(high_range, low_range, lt);
-#endif
-
-}
-
#ifdef WATER_FOG
uniform vec4 waterPlane;
uniform vec4 waterFogColor;
@@ -571,6 +572,9 @@ void main()
norm.xyz = tnorm;
norm.xyz = normalize(norm.xyz);
+ vec2 abnormal = encode_normal(norm.xyz);
+ norm.xyz = decode_normal(abnormal.xy);
+
vec4 final_color = diffcol;
#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE)
@@ -666,7 +670,7 @@ void main()
vec4 diffuse = final_color;
float envIntensity = final_normal.z;
- vec3 col = vec3(0.0f,0.0f,0.0f);
+ vec3 col = vec3(0.0f,0.0f,0.0f);
float bloom = 0.0;
calcAtmospherics(pos.xyz, 1.0);
@@ -674,23 +678,28 @@ void main()
vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
float da =dot(norm.xyz, sun_dir.xyz);
+
float final_da = da;
final_da = min(final_da, shadow);
- final_da = max(final_da, diffuse.a);
+ //final_da = max(final_da, diffuse.a);
final_da = max(final_da, 0.0f);
+ final_da = min(final_da, 1.0f);
+ final_da = pow(final_da, 1.0/1.3);
col.rgb = atmosAmbient(col);
- float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);
+ float ambient = min(abs(da), 1.0);
ambient *= 0.5;
ambient *= ambient;
ambient = (1.0-ambient);
col.rgb *= ambient;
- col.rgb = col.rgb + atmosAffectDirectionalLight(pow(final_da, 1.0/1.3));
+ col.rgb = col.rgb + atmosAffectDirectionalLight(final_da);
+
col.rgb *= gamma_diff.rgb;
+
float glare = 0.0;
if (spec.a > 0.0) // specular reflection
@@ -711,7 +720,8 @@ void main()
col += spec_contrib;
}
- col = mix(col.rgb, gamma_diff.rgb, diffuse.a);
+
+ col = mix(col.rgb, diffcol.rgb, diffuse.a);
if (envIntensity > 0.0)
{
@@ -729,15 +739,20 @@ void main()
glare += cur_glare;
}
- col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a);
- col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a);
+ //col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a);
+ //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a);
+
+ col = atmosLighting(col);
+ col = scaleSoftClip(col);
//convert to linear space before adding local lights
col = srgb_to_linear(col);
vec3 npos = normalize(-pos.xyz);
- #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare);
+ vec3 light = vec3(0,0,0);
+
+ #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare);
LIGHT_LOOP(1)
LIGHT_LOOP(2)
@@ -747,13 +762,14 @@ void main()
LIGHT_LOOP(6)
LIGHT_LOOP(7)
+ col.rgb += light.rgb;
+
glare = min(glare, 1.0);
float al = max(diffcol.a,glare)*vertex_color.a;
//convert to gamma space for display on screen
col.rgb = linear_to_srgb(col.rgb);
-
#ifdef WATER_FOG
vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al));
col.rgb = temp.rgb;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
index 89530f4082..4e2f98aa29 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
@@ -38,12 +38,30 @@ VARYING vec2 vary_fragcoord;
uniform float display_gamma;
-vec3 linear_to_srgb(vec3 cl);
+vec3 linear_to_srgb(vec3 cl)
+{
+ cl = clamp(cl, vec3(0), vec3(1));
+ vec3 low_range = cl * 12.92;
+ vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055;
+ bvec3 lt = lessThan(cl,vec3(0.0031308));
+
+#ifdef OLD_SELECT
+ vec3 result;
+ result.r = lt.r ? low_range.r : high_range.r;
+ result.g = lt.g ? low_range.g : high_range.g;
+ result.b = lt.b ? low_range.b : high_range.b;
+ return result;
+#else
+ return mix(high_range, low_range, lt);
+#endif
+
+}
+
void main()
{
vec4 diff = texture2DRect(diffuseRect, vary_fragcoord);
- diff.rgb = pow(diff.rgb,vec3(display_gamma));
+ diff.rgb = linear_to_srgb(diff.rgb);
frag_color = diff;
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
index 0febbcd6e0..ebe5e57bb7 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
@@ -98,7 +98,6 @@ vec3 srgb_to_linear(vec3 cs)
vec3 linear_to_srgb(vec3 cl)
{
- cl = clamp(cl, vec3(0), vec3(1));
vec3 low_range = cl * 12.92;
vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055;
bvec3 lt = lessThan(cl,vec3(0.0031308));
@@ -392,8 +391,11 @@ void main()
float envIntensity = norm.z;
norm.xyz = decode_normal(norm.xy); // unpack norm
- float da = max(dot(norm.xyz, sun_dir.xyz), 0.0);
- da = pow(da, 1.0/1.3);
+ float da = dot(norm.xyz, sun_dir.xyz);
+
+ float final_da = max(0.0,da);
+ final_da = min(final_da, 1.0f);
+ final_da = pow(final_da, 1.0/1.3);
vec4 diffuse = texture2DRect(diffuseRect, tc);
@@ -414,7 +416,7 @@ void main()
col.rgb *= ambient;
- col += atmosAffectDirectionalLight(max(min(da, 1.0), 0.0));
+ col += atmosAffectDirectionalLight(final_da);
col *= diffuse.rgb;