diff options
author | Graham Linden <graham@lindenlab.com> | 2019-05-02 13:49:35 -0700 |
---|---|---|
committer | Graham Linden <graham@lindenlab.com> | 2019-05-02 13:49:35 -0700 |
commit | c4032528aff8ef1938e897ec583bbf25a3e713e1 (patch) | |
tree | 4addd3b6619e6e911898d09ef446d0d40ef8a73e /indra/newview/app_settings/shaders/class2/deferred | |
parent | 1ff876a961dc00b7f162054ea1a9fed79240bffc (diff) |
Roll back sRGB decode changes from contrib for now.
Fix direct light matching across alpha/blended-material/deferred.
Get diffuse lighting to match from Low to Ultra.
Diffstat (limited to 'indra/newview/app_settings/shaders/class2/deferred')
3 files changed, 75 insertions, 54 deletions
diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 9cd5592d7c..b05d544938 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -71,12 +71,21 @@ uniform vec2 screen_res; uniform mat4 inv_proj; +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); + vec3 getNorm(vec2 pos_screen); -vec3 scaleDownLight(vec3 light); + + +vec4 correctWithGamma(vec4 col) +{ + return vec4(srgb_to_linear(col.rgb), col.a); +} + vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - + ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); float det = min(lod/(proj_lod*0.5), 1.0); @@ -95,6 +104,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -112,6 +122,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = tc-vec2(0.5); @@ -224,10 +235,7 @@ void main() amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); -#ifndef NO_AMBIANCE col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; -#endif - } @@ -288,8 +296,6 @@ void main() //not sure why, but this line prevents MATBUG-194 col = max(col, vec3(0.0)); - col = scaleDownLight(col); - 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 7368b8d80c..a2fbec524e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -45,40 +45,27 @@ uniform float blur_size; uniform float blur_fidelity; // Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; -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; uniform vec3 sun_dir; uniform vec3 moon_dir; uniform int sun_up_factor; - VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; vec3 getNorm(vec2 pos_screen); +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +float getAmbientClamp(); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); -void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); -float getAmbientClamp(); -vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); -vec4 getPositionWithDepth(vec2 pos_screen, float depth); -vec4 getPosition(vec2 pos_screen); - #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); #endif @@ -94,24 +81,24 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float light_gamma = 1.0/1.3; 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, -1.0, 1.0); - vec4 gamma_diff = texture2DRect(diffuseRect, tc); - vec4 diffuse = gamma_diff; - diffuse.rgb = srgb_to_linear(diffuse.rgb); - - scol = max(scol_ambocc.r, diffuse.a); + float final_da = da; final_da = clamp(final_da, 0.0, 1.0); + vec4 diffuse_srgb = texture2DRect(diffuseRect, tc); + vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); + + scol = max(scol_ambocc.r, diffuse_linear.a); + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - vec3 col; + vec3 color = vec3(0); float bloom = 0.0; { float ambocc = scol_ambocc.g; @@ -126,22 +113,23 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; + ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; - vec3 sun_contrib = scol * final_da * sunlit; + vec3 sun_contrib = min(scol, final_da) * sunlit; - col.rgb = amblit; - col.rgb *= ambient; + color.rgb = amblit; + color.rgb *= ambient; -vec3 post_ambient = col.rgb; +vec3 post_ambient = color.rgb; - col.rgb += sun_contrib; + color.rgb += sun_contrib; -vec3 post_sunlight = col.rgb; +vec3 post_sunlight = color.rgb; - col.rgb *= gamma_diff.rgb; + color.rgb *= diffuse_srgb.rgb; -vec3 post_diffuse = col.rgb; +vec3 post_diffuse = color.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -166,31 +154,55 @@ vec3 post_diffuse = col.rgb; vec3 speccol = sun_contrib*scontrib*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); bloom += dot (speccol, speccol) / 6; - col += speccol; + color += speccol; } } - - col.rgb += diffuse.a * gamma_diff.rgb; + + vec3 post_spec = color.rgb; + + color.rgb += diffuse_srgb.a * diffuse_srgb.rgb; if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; - vec3 refcol = textureCube(environmentMap, env_vec).rgb; - col = mix(col.rgb, refcol, envIntensity); + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + color = mix(color.rgb, reflected_color, envIntensity); } +vec3 post_env = color.rgb; + if (norm.w < 1) { - col = atmosFragLighting(col, additive, atten); - col = scaleSoftClipFrag(col); + color = atmosFragLighting(color, additive, atten); + color = scaleSoftClipFrag(color); } +vec3 post_atmo = color.rgb; + #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); - col = fogged.rgb; + vec4 fogged = applyWaterFogView(pos.xyz,vec4(color, bloom)); + color = fogged.rgb; bloom = fogged.a; #endif + +//color.rgb = amblit; +//color.rgb = vec3(ambient); +//color.rgb = sunlit; +//color.rgb = post_ambient; +//color.rgb = vec3(final_da); +//color.rgb = sun_contrib; +//color.rgb = post_sunlight; +//color.rgb = diffuse_srgb.rgb; +//color.rgb = post_diffuse; +//color.rgb = post_spec; +//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); } - frag_color.rgb = col.rgb; + + frag_color.rgb = 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 957ce579c0..a3ff754849 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -72,12 +72,17 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 getNorm(vec2 pos_screen); -vec3 scaleDownLight(vec3 c); +vec3 srgb_to_linear(vec3 c); +vec4 correctWithGamma(vec4 col) +{ + return vec4(srgb_to_linear(col.rgb), col.a); +} vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - + ret = correctWithGamma(ret); + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); float det = min(lod/(proj_lod*0.5), 1.0); @@ -96,6 +101,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -113,6 +119,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = tc-vec2(0.5); @@ -223,9 +230,7 @@ void main() amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); -#ifndef NO_AMBIANCE col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; -#endif } @@ -290,8 +295,6 @@ void main() //not sure why, but this line prevents MATBUG-194 col = max(col, vec3(0.0)); - col = scaleDownLight(col); - frag_color.rgb = col; frag_color.a = 0.0; } |