summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
diff options
context:
space:
mode:
authorGraham Linden <graham@lindenlab.com>2019-02-26 10:09:32 -0800
committerGraham Linden <graham@lindenlab.com>2019-02-26 10:09:32 -0800
commitf9896dc100ccd6dd2d92610cb4f71f61284f76a6 (patch)
treef008a1d1aa054d2592aed5bdb70c733ba8f757ce /indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
parent8b0e2e4c82ae598f09a1f0cbf5d216804461155b (diff)
SL-5186, SL-10612
Fix lighting and gamma correction differences between deferred and forward rendering including materials objects. Verify 10612 and 10500 remain fixed. Make sure all necessary deferred shaders get the atmospheric uniform updates for doing frag-based atmospherics.
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl42
1 files changed, 24 insertions, 18 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
index 948a195b7a..df0ff4e654 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
@@ -70,16 +70,17 @@ uniform vec3 light_diffuse[8];
vec4 applyWaterFogView(vec3 pos, vec4 color);
#endif
+vec3 srgb_to_linear(vec3 c);
+vec3 linear_to_srgb(vec3 c);
+
vec2 encode_normal (vec3 n);
-vec3 scaleSoftClip(vec3 l);
-vec3 atmosFragAmbient(vec3 light, vec3 sunlit);
+vec3 scaleSoftClipFrag(vec3 l);
vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten);
-vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit);
void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive);
float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);
-vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance)
+vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance ,float shadow)
{
//get light vector
vec3 lv = lp.xyz-v;
@@ -96,23 +97,25 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec
vec3 norm = normalize(n);
da = max(0.0, dot(norm, lv));
+ da = clamp(da, 0.0, 1.0);
//distance attenuation
float dist = d/la;
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;
// spotlight coefficient.
float spot = max(dot(-ln, lv), is_pointlight);
da *= spot*spot; // GL_SPOT_EXPONENT=2
// to match spotLight (but not multiSpotLight) *sigh*
- float lit = max(da * dist_atten,0.0);
+ float lit = max(min(da, shadow) * dist_atten,0.0);
col = lit * light_col * diffuse;
- float amb_da = (da*da*0.5 + 0.25) * ambiance;
+ float amb_da = ambiance;
amb_da *= dist_atten;
+ amb_da += (da*0.5) * ambiance;
+ amb_da += (da*da*0.5 + 0.5) * ambiance;
amb_da = min(amb_da, 1.0f - lit);
col.rgb += amb_da * light_col * diffuse;
@@ -165,6 +168,8 @@ void main()
float final_alpha = diff.a;
#endif
+ diff.rgb = srgb_to_linear(diff.rgb);
+
vec3 sunlit;
vec3 amblit;
vec3 additive;
@@ -175,34 +180,32 @@ void main()
vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir;
float da = dot(norm.xyz, light_dir.xyz);
-
- float final_da = da;
- final_da = min(final_da, shadow);
- final_da = clamp(final_da, 0.0f, 1.0f);
- final_da = pow(final_da, 1.0/display_gamma);
+ da = clamp(da, 0.0, 1.0);
vec4 color = vec4(0,0,0,0);
- color.rgb = atmosFragAmbient(color.rgb, amblit);
+ color.rgb = amblit;
color.a = final_alpha;
- float ambient = abs(final_da);
+ float ambient = abs(da);
ambient *= 0.5;
ambient *= ambient;
- ambient = (1.0-ambient);
+ ambient = 1.0 - ambient * smoothstep(0.0, 0.3, shadow);
+
+ vec3 sun_contrib = min(da, shadow) * sunlit;
color.rgb *= ambient;
- color.rgb += (final_da * sunlit);
+ color.rgb += sun_contrib;
color.rgb *= diff.rgb;
//color.rgb = mix(diff.rgb, color.rgb, final_alpha);
color.rgb = atmosFragLighting(color.rgb, additive, atten);
- color.rgb = scaleSoftClip(color.rgb);
+ color.rgb = scaleSoftClipFrag(color.rgb);
vec4 light = vec4(0,0,0,0);
- #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_attenuation[i].w);
+ #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_attenuation[i].w, shadow);
LIGHT_LOOP(1)
LIGHT_LOOP(2)
@@ -215,6 +218,9 @@ void main()
// keep it linear
//
color.rgb += light.rgb;
+
+ color.rgb = linear_to_srgb(color.rgb);
+
#endif
#ifdef WATER_FOG