summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorRunitai Linden <davep@lindenlab.com>2020-03-05 16:28:06 -0600
committerRunitai Linden <davep@lindenlab.com>2020-03-05 16:28:06 -0600
commit7c7d71269f5b47397d14bbe44e341e4ac1d96889 (patch)
treeea9ff1c27a6e067d225929b2f28d637db32d20bf /indra/newview
parent90ad38db065877be16371e7814a39618135a30ab (diff)
WIP - Windlight sun lighting should happen in sRGB space, not linear space. This keeps ambient from getting overblown and better matches environment lighting with ALM on/off.
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl10
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/materialF.glsl18
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl18
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl1
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl11
-rw-r--r--indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl3
-rw-r--r--indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl8
-rw-r--r--indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl6
-rw-r--r--indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl3
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl3
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl6
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl2
12 files changed, 53 insertions, 36 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
index 814d5036db..e38eeab370 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
@@ -251,7 +251,7 @@ vec3 post_ambient = color.rgb;
vec3 post_sunlight = color.rgb;
- color.rgb *= diffuse_linear.rgb;
+ color.rgb *= diffuse_srgb.rgb;
vec3 post_diffuse = color.rgb;
@@ -261,6 +261,11 @@ vec3 post_atmo = color.rgb;
vec4 light = vec4(0,0,0,0);
+ color.rgb = scaleSoftClipFrag(color.rgb);
+
+ //convert to linear before applying local lights
+ color.rgb = srgb_to_linear(color.rgb);
+
#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.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)
@@ -275,9 +280,6 @@ vec3 post_atmo = color.rgb;
#if !defined(LOCAL_LIGHT_KILL)
color.rgb += light.rgb;
#endif
-
- color.rgb = scaleSoftClipFrag(color.rgb);
-
// back to sRGB as we're going directly to the final RT post-deferred gamma correction
color.rgb = linear_to_srgb(color.rgb);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
index 18293f4c11..e4ebf0edee 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
@@ -117,7 +117,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe
// spotlight coefficient.
float spot = max(dot(-ln, lv), is_pointlight);
da *= spot*spot; // GL_SPOT_EXPONENT=2
-
+
//angular attenuation
da *= dot(n, lv);
@@ -215,8 +215,7 @@ void main()
vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy);
diffuse_tap.rgb *= vertex_color.rgb;
- //diffuse_tap = vec4(1,1,1,1);
-
+
//#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
vec4 diffuse_srgb = diffuse_tap;
vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a);
@@ -349,7 +348,7 @@ void main()
color.rgb += sun_contrib;
#endif
- color.rgb *= diffuse_linear.rgb;
+ color.rgb *= diffuse_srgb.rgb;
float glare = 0.0;
@@ -397,11 +396,15 @@ void main()
}
color = atmosFragLighting(color, additive, atten);
+ color = scaleSoftClipFrag(color);
vec3 npos = normalize(-pos.xyz);
vec3 light = vec3(0,0,0);
+ //convert to linear before adding local lights
+ color.rgb = srgb_to_linear(color.rgb);
+
#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w );
LIGHT_LOOP(1)
@@ -419,8 +422,9 @@ void main()
color.rgb += light.rgb;
#endif
- color = scaleSoftClipFrag(color);
-
+//convert to srgb as this color is being written post gamma correction
+ color.rgb = linear_to_srgb(color.rgb);
+
#ifdef WATER_FOG
vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al));
color.rgb = temp.rgb;
@@ -429,8 +433,6 @@ void main()
}
- color.rgb = linear_to_srgb(color.rgb);
-
frag_color = vec4(color, al);
#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer
diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl
index a690cc45a8..9bba45bc4e 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl
@@ -163,15 +163,19 @@ void main()
proj_tc.xyz /= proj_tc.w;
float fa = falloff+1.0;
- float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 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;
+
if (dist_atten <= 0.0)
{
discard;
}
+ float noise = texture2D(noiseMap, frag.xy/128.0).b;
+ dist_atten *= noise;
+
lv = proj_origin-pos.xyz;
lv = normalize(lv);
float da = dot(norm, lv);
@@ -179,12 +183,13 @@ void main()
vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
// SL-12005 Projector light pops as we get closer, more objectionable than being in wrong color space.
- // We can't switch to linear here unless we do it everywhere
- //diff_tex.rgb = srgb_to_linear(diff_tex.rgb);
+ // We can't switch to linear here unless we do it everywhere*
+ // *gbuffer is sRGB, convert to linear whenever sampling from it
+ diff_tex.rgb = srgb_to_linear(diff_tex.rgb);
vec3 dlit = vec3(0, 0, 0);
- float noise = texture2D(noiseMap, frag.xy/128.0).b;
+
if (proj_tc.z > 0.0 &&
proj_tc.x < 1.0 &&
proj_tc.y < 1.0 &&
@@ -203,7 +208,7 @@ void main()
dlit = color.rgb * plcol.rgb * plcol.a;
- lit = da * dist_atten * noise;
+ lit = da * dist_atten;
col = dlit*lit*diff_tex;
amb_da += (da*0.5)*proj_ambiance;
@@ -245,7 +250,7 @@ void main()
col += dlit*scol*spec.rgb;
//col += spec.rgb;
}
- }
+ }
if (envIntensity > 0.0)
{
@@ -277,6 +282,7 @@ void main()
}
#endif
+ //output linear, sum of lights will be gamma corrected later
frag_color.rgb = col;
frag_color.a = 0.0;
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
index 966c73ef24..cd37a34e0d 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
@@ -43,6 +43,7 @@ vec3 linear_to_srgb(vec3 cl);
void main()
{
+ //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB)
vec4 diff = texture2DRect(diffuseRect, vary_fragcoord);
//diff.rgb = pow(diff.rgb, vec3(display_gamma));
diff.rgb = linear_to_srgb(diff.rgb);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
index da2eb47e3b..19e737326d 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
@@ -119,7 +119,7 @@ vec3 post_ambient = color.rgb;
vec3 post_sunlight = color.rgb;
- color.rgb *= diffuse_linear.rgb;
+ color.rgb *= diffuse_srgb.rgb;
vec3 post_diffuse = color.rgb;
@@ -199,9 +199,6 @@ vec3 post_atmo = color.rgb;
//color.rgb = post_env;
//color.rgb = post_atmo;
-// convert to linear as fullscreen lights need to sum in linear colorspace
-// and will be gamma (re)corrected downstream...
- //color.rgb = srgb_to_linear(color.rgb);
}
// linear debuggables
@@ -209,7 +206,9 @@ vec3 post_atmo = color.rgb;
//color.rgb = vec3(ambient);
//color.rgb = vec3(scol);
//color.rgb = diffuse_linear.rgb;
-
- frag_color.rgb = color.rgb;
+
+ // convert to linear as fullscreen lights need to sum in linear colorspace
+ // and will be gamma (re)corrected downstream...
+ frag_color.rgb = srgb_to_linear(color.rgb);
frag_color.a = 0.0; //bloom;
}
diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl
index e5f1e11180..dcb02bd1c1 100644
--- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl
+++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl
@@ -46,6 +46,7 @@ float getAmbientClamp()
return 1.0f;
}
+
void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao) {
vec3 P = inPositionEye;
@@ -123,7 +124,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou
temp2.x *= sun_moon_glow_factor;
vec4 amb_color = ambient_color;
-
+
//increase ambient when there are more clouds
vec4 tmpAmbient = amb_color + (vec4(1.) - amb_color) * cloud_shadow * 0.5;
diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl
index 7cde67d11b..5d7a28c359 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl
@@ -192,8 +192,9 @@ void main()
vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
// SL-12005 Projector light pops as we get closer, more objectionable than being in wrong color space.
- // We can't switch to linear here unless we do it everywhere
- //diff_tex.rgb = srgb_to_linear(diff_tex.rgb);
+ // We can't switch to linear here unless we do it everywhere*
+ // *gbuffer IS sRGB, convert to linear since this shader outputs linear
+ diff_tex.rgb = srgb_to_linear(diff_tex.rgb);
vec4 spec = texture2DRect(specularRect, frag.xy);
@@ -296,6 +297,7 @@ void main()
//not sure why, but this line prevents MATBUG-194
col = max(col, vec3(0.0));
- frag_color.rgb = col;
+ //output linear
+ frag_color.rgb = col;
frag_color.a = 0.0;
}
diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
index bacdb6f70f..58d573c724 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
@@ -106,7 +106,7 @@ void main()
vec3 atten;
calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true);
-
+
float ambient = da;
ambient *= 0.5;
ambient *= ambient;
@@ -127,7 +127,7 @@ vec3 post_ambient = color.rgb;
vec3 post_sunlight = color.rgb;
- color.rgb *= diffuse_linear.rgb;
+ color.rgb *= diffuse_srgb.rgb;
vec3 post_diffuse = color.rgb;
@@ -218,6 +218,6 @@ vec3 post_atmo = color.rgb;
//output linear RGB as lights are summed up in linear space and then gamma corrected prior to the
//post deferred passes
- frag_color.rgb = color.rgb;
+ frag_color.rgb = srgb_to_linear(color.rgb);
frag_color.a = bloom;
}
diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl
index 77f6e6f7ac..5ab0b5c5b4 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl
@@ -189,7 +189,7 @@ void main()
lv = normalize(lv);
float da = dot(norm, lv);
- vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
+ vec3 diff_tex = srgb_to_linear(texture2DRect(diffuseRect, frag.xy).rgb);
vec4 spec = texture2DRect(specularRect, frag.xy);
vec3 dlit = vec3(0, 0, 0);
@@ -287,6 +287,7 @@ void main()
//not sure why, but this line prevents MATBUG-194
col = max(col, vec3(0.0));
+ //output linear colors as gamma correction happens down stream
frag_color.rgb = col;
frag_color.a = 0.0;
}
diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl
index 52de7ceaad..9d62b9d180 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl
@@ -183,7 +183,7 @@ void main()
vec3 col = vec3(0,0,0);
- vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
+ vec3 diff_tex = srgb_to_linear(texture2DRect(diffuseRect, frag.xy).rgb);
vec4 spec = texture2DRect(specularRect, frag.xy);
@@ -285,6 +285,7 @@ void main()
col = scaleDownLight(col);
+ //output linear space color as gamma correction happens down stream
frag_color.rgb = col;
frag_color.a = 0.0;
}
diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
index 978c25b86a..7ed9e7b4fc 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
@@ -94,7 +94,8 @@ void main()
float da = max(dot(norm.xyz, sun_dir.xyz), 0.0);
- vec4 diffuse = texture2DRect(diffuseRect, tc); // linear
+ vec4 diffuse = texture2DRect(diffuseRect, tc); // sRGB
+ diffuse.rgb = srgb_to_linear(diffuse.rgb);
vec3 col;
float bloom = 0.0;
@@ -169,7 +170,8 @@ void main()
bloom = fogged.a;
#endif
}
-
+
+ //output linear since gamma correction happens down stream
frag_color.rgb = col;
frag_color.a = bloom;
}
diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl
index bccd819a43..56b0f4e5ce 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl
@@ -182,7 +182,7 @@ void main()
vec3 col = vec3(0,0,0);
- vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
+ vec3 diff_tex = srgb_to_linear(texture2DRect(diffuseRect, frag.xy).rgb);
vec4 spec = texture2DRect(specularRect, frag.xy);