diff options
author | Graham Linden <graham@lindenlab.com> | 2019-02-26 10:09:32 -0800 |
---|---|---|
committer | Graham Linden <graham@lindenlab.com> | 2019-02-26 10:09:32 -0800 |
commit | f9896dc100ccd6dd2d92610cb4f71f61284f76a6 (patch) | |
tree | f008a1d1aa054d2592aed5bdb70c733ba8f757ce /indra/newview/app_settings/shaders | |
parent | 8b0e2e4c82ae598f09a1f0cbf5d216804461155b (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')
4 files changed, 71 insertions, 60 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 diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6dcfaddd44..586926dc01 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -81,7 +81,7 @@ uniform vec3 light_direction[8]; uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; -vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare, float ambiance) +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare, float ambiance, float shadow) { //get light vector vec3 lv = lp.xyz-v; @@ -102,21 +102,24 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe 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 //angular attenuation - da *= max(dot(n, lv), 0.0); + da = dot(n, lv); + da *= clamp(da, 0.0, 1.0); + da *= pow(da, 1.0 / 1.3); - float lit = max(da * dist_atten, 0.0); + float lit = max(min(da,shadow) * dist_atten, 0.0); col = light_col*lit*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.25) * ambiance; amb_da = min(amb_da, 1.0f - lit); col.rgb += amb_da * light_col * diffuse; @@ -144,7 +147,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe cur_glare = max(cur_glare, speccol.b); glare = max(glare, speccol.r); glare += max(cur_glare, 0.0); - //col += spec.rgb; } } } @@ -263,41 +265,42 @@ void main() spec = final_specular; vec4 diffuse = final_color; + + diffuse.rgb = srgb_to_linear(diffuse.rgb); + float envIntensity = final_normal.z; vec3 col = vec3(0.0f,0.0f,0.0f); float bloom = 0.0; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); 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 = max(final_da, diffuse.a); - final_da = max(final_da, 0.0f); - final_da = min(final_da, 1.0f); + float da = dot(norm.xyz, light_dir.xyz); + da = clamp(da, 0.0, 1.0); + da = pow(da, 1.0 / 1.3); col.rgb = amblit; - float ambient = min(abs(final_da), 1.0); + float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb *= min(ambient, max(shadow,0.3)); + ambient = 1.0 - ambient * smoothstep(0.0, 0.3, shadow); - col.rgb += (final_da * sunlit); + vec3 sun_contrib = min(da, shadow) * sunlit; + + col.rgb *= ambient; + col.rgb += sun_contrib; col.rgb *= diffuse.rgb; - + float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -339,8 +342,8 @@ vec3 post_spec = col.rgb; glare += cur_glare; } - //col = atmosFragLighting(col, additive, atten); - //col = scaleSoftClipFrag(col); + col = atmosFragLighting(col, additive, atten); + col = scaleSoftClipFrag(col); vec3 post_atmo= col.rgb; @@ -348,7 +351,7 @@ vec3 post_atmo= col.rgb; 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_attenuation[i].w); + #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_attenuation[i].w, shadow); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -371,6 +374,8 @@ vec3 post_lighting = col.rgb; al = temp.a; #endif + col.rgb = linear_to_srgb(col.rgb); + frag_color.rgb = col.rgb; frag_color.a = al; diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index ad96c84de8..c927c4bf06 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -155,7 +155,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) { return 1.0f; // lit beyond the far split... } - shadow = min(dp_directional_light,shadow); + //shadow = min(dp_directional_light,shadow); return shadow; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 7fd4d7e248..57997245f8 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -51,6 +51,7 @@ uniform vec3 camPosLocal; uniform float cloud_shadow; uniform float max_y; uniform float global_gamma; +uniform float display_gamma; uniform mat3 env_mat; uniform vec4 shadow_clip; uniform mat3 ssao_effect_mat; @@ -93,27 +94,26 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float da = dot(norm.xyz, light_dir.xyz); + float scol = 1.0; + vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; + + float da = dot(normalize(norm.xyz), light_dir.xyz); da = clamp(da, 0.0, 1.0); + float light_gamma = 1.0/1.3; + da = pow(da, light_gamma); + vec4 diffuse = texture2DRect(diffuseRect, tc); - + + scol = max(scol_ambocc.r, diffuse.a); + vec3 col; - float scol = 1.0; float bloom = 0.0; { vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - - vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; - scol_ambocc = pow(scol_ambocc, vec2(global_gamma + 0.3)); - scol = max(scol_ambocc.r, diffuse.a); float ambocc = scol_ambocc.g; - float final_da = da; - final_da = min(final_da, scol); - final_da = pow(final_da, global_gamma + 0.3); - vec3 sunlit; vec3 amblit; vec3 additive; @@ -121,12 +121,12 @@ void main() calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); - float ambient = min(da, 1.0); + float ambient = min(abs(da), 1.0); ambient *= 0.5; ambient *= ambient; - ambient = min(1.0 - ambient,max(scol,0.3)); + ambient = 1.0 - ambient * smoothstep(0.0, 0.3, scol); - vec3 sun_contrib = sunlit * final_da; + vec3 sun_contrib = min(da,scol) * sunlit; col.rgb = amblit; col.rgb *= ambient; |