summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class3/deferred
diff options
context:
space:
mode:
authorDave Parks <davep@lindenlab.com>2022-09-26 17:17:34 -0500
committerDave Parks <davep@lindenlab.com>2022-09-26 17:17:34 -0500
commit725d042640f5b0474b58e6a1af0a4063c7e5cfc2 (patch)
treeb79ea04dd68d87776dae0b14d0c99795f5cbcf4a /indra/newview/app_settings/shaders/class3/deferred
parent20f44fb522099e8e14e42ea0d5dedf76b24b9d6c (diff)
SL-18190 WIP - Windlight to linear space proof of concept, better parity between release viewer and materials viewer when reflections disabled. Avoid run-away probe ambiance.
Diffstat (limited to 'indra/newview/app_settings/shaders/class3/deferred')
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/materialF.glsl32
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl20
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl48
3 files changed, 45 insertions, 55 deletions
diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
index 27eb0b9888..7c0a11d442 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
@@ -287,6 +287,9 @@ void main()
#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
//forward rendering, output lit linear color
+ diffcol.rgb = srgb_to_linear(diffcol.rgb);
+ spec.rgb = srgb_to_linear(spec.rgb);
+
vec3 pos = vary_position;
float shadow = 1.0f;
@@ -318,20 +321,23 @@ void main()
vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
- //we're in sRGB space, so gamma correct this dot product so
- // lighting from the sun stays sharp
- float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0);
- da = pow(da, 1.0 / 1.3);
- vec3 sun_contrib = min(da, shadow) * sunlit;
-
vec3 ambenv;
vec3 glossenv;
vec3 legacyenv;
sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity);
- amblit = max(ambenv, amblit);
- color.rgb = amblit;
+ // use sky settings ambient or irradiance map sample, whichever is brighter
+ color = max(amblit, ambenv);
- color += sun_contrib;
+ float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);
+ ambient *= 0.5;
+ ambient *= ambient;
+ ambient = (1.0 - ambient);
+ color.rgb *= ambient;
+
+ float da = clamp(dot(norm.xyz, sun_dir.xyz), 0.0, 1.0);
+ vec3 sun_contrib = min(da, shadow) * sunlit;
+ color.rgb += sun_contrib;
+ color.rgb *= diffuse.rgb;
color *= diffcol.rgb;
@@ -359,18 +365,14 @@ void main()
{ // add environmentmap
applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity);
}
- color = scaleSoftClipFrag(color);
-
- //convert to linear before adding local lights
- color = srgb_to_linear(color);
vec3 npos = normalize(-pos.xyz);
vec3 light = vec3(0, 0, 0);
- final_specular.rgb = srgb_to_linear(final_specular.rgb); // SL-14035
+ final_specular.rgb = final_specular.rgb; // SL-14035
- color = mix(color.rgb, srgb_to_linear(diffcol.rgb), diffuse.a);
+ color = mix(color.rgb, diffcol.rgb, diffuse.a);
#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 );
diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl
index 73b852e008..de18251dc4 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl
@@ -31,8 +31,6 @@
uniform samplerCubeArray reflectionProbes;
uniform samplerCubeArray irradianceProbes;
-vec3 linear_to_srgb(vec3 col);
-
layout (std140) uniform ReflectionProbes
{
// list of OBBs for user override probes
@@ -531,32 +529,28 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout
vec3 refnormpersp = reflect(pos.xyz, norm.xyz);
ambenv = sampleProbeAmbient(pos, norm);
+ ambenv /= 1.725;
if (glossiness > 0.0)
{
float lod = (1.0-glossiness)*reflection_lods;
glossenv = sampleProbes(pos, normalize(refnormpersp), lod, 1.f);
- glossenv = linear_to_srgb(glossenv);
}
if (envIntensity > 0.0)
{
legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0, 1.f);
- legacyenv = linear_to_srgb(legacyenv);
}
-
- // legacy expects values in sRGB space for now
- ambenv = linear_to_srgb(ambenv);
-
}
void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm)
{
- glossenv *= 0.35; // fudge darker
- float fresnel = 1.0+dot(normalize(pos.xyz), norm.xyz);
- float minf = spec.a * 0.1;
- fresnel = fresnel * (1.0-minf) + minf;
- glossenv *= spec.rgb*min(fresnel, 1.0);
+ glossenv *= 0.5; // fudge darker
+ float fresnel = clamp(1.0+dot(normalize(pos.xyz), norm.xyz), 0.3, 1.0);
+ fresnel *= fresnel;
+ fresnel *= spec.a;
+ glossenv *= spec.rgb*fresnel;
+ glossenv *= vec3(1.0) - color; // fake energy conservation
color.rgb += glossenv;
}
diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
index cfdbbdfe2c..9374922494 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
@@ -114,14 +114,12 @@ void main()
vec4 pos = getPositionWithDepth(tc, depth);
vec4 norm = texture2DRect(normalMap, tc);
vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;
- float light_gamma = 1.0 / 1.3;
vec4 diffuse = texture2DRect(diffuseRect, tc);
vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); // NOTE: PBR linear Emissive
#if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO)
vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg;
- scol_ambocc = pow(scol_ambocc, vec2(light_gamma));
float scol = max(scol_ambocc.r, diffuse.a);
float ambocc = scol_ambocc.g;
#else
@@ -159,13 +157,10 @@ void main()
vec3 irradiance = vec3(0);
vec3 radiance = vec3(0);
sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss);
- irradiance = max(srgb_to_linear(amblit),irradiance) * ambocc*4.0;
+ irradiance = max(amblit*1.725,irradiance*ambocc);
vec3 f0 = vec3(0.04);
vec3 baseColor = diffuse.rgb;
-
- //baseColor.rgb = vec3(0,0,0);
- //colorEmissive = srgb_to_linear(norm.xyz*0.5+0.5);
vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0);
diffuseColor *= 1.0 - metallic;
@@ -179,34 +174,37 @@ void main()
color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit*8.0 * scol;
color.rgb += colorEmissive;
- color = linear_to_srgb(color);
+ //color = atmosFragLighting(color, additive, atten);
color *= atten.r;
- color += 2.0*additive;
- color = scaleSoftClipFrag(color);
- color = srgb_to_linear(color);
-
-
- frag_color.rgb = color.rgb; //output linear since local lights will be added to this shader's results
+ color += additive;
+
}
else
{
+
+ // legacy shaders are still writng sRGB to gbuffer
+ diffuse.rgb = srgb_to_linear(diffuse.rgb);
+ spec.rgb = srgb_to_linear(spec.rgb);
+
float envIntensity = norm.z;
norm.xyz = getNorm(tc);
float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0);
- da = pow(da, light_gamma);
-
- //diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035
sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity);
- vec3 debug = legacyenv;
- amblit = max(ambenv, amblit);
- color.rgb = amblit*ambocc;
+ // use sky settings ambient or irradiance map sample, whichever is brighter
+ color = max(amblit, ambenv*ambocc);
+ color = ambenv;
+
+ float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);
+ ambient *= 0.5;
+ ambient *= ambient;
+ ambient = (1.0 - ambient);
+ color.rgb *= ambient;
vec3 sun_contrib = min(da, scol) * sunlit;
color.rgb += sun_contrib;
- color.rgb = min(color.rgb, vec3(1,1,1));
color.rgb *= diffuse.rgb;
vec3 refnormpersp = reflect(pos.xyz, norm.xyz);
@@ -234,8 +232,9 @@ void main()
{ // add environmentmap
applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity);
}
- color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a);
+ color = mix(color, fullbrightScaleSoftClip(color), diffuse.a);
}
+ }
#ifdef WATER_FOG
vec4 fogged = applyWaterFogView(pos.xyz, vec4(color, bloom));
@@ -243,11 +242,6 @@ void main()
bloom = fogged.a;
#endif
- // 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.rgb = color.rgb; //output linear since local lights will be added to this shader's results
frag_color.a = bloom;
}