diff options
author | Dave Parks <davep@lindenlab.com> | 2022-09-27 23:32:02 -0500 |
---|---|---|
committer | Dave Parks <davep@lindenlab.com> | 2022-09-27 23:32:02 -0500 |
commit | aaf7b17db047f0cb2630b479d5468062e6ca815e (patch) | |
tree | a84d5d7668ff65fc6dec3315fd1a760213496e4d /indra/newview/app_settings/shaders/class3/deferred | |
parent | 44f2286e42a10270c23ea11e308143948d1e3288 (diff) |
SL-18190 WIP -- Take 2 on linear space windlight (more methodical approach -- make desired interface but brute force color conversions). Placeholder PBR water and move to deprecate forward rendering shaders.
Diffstat (limited to 'indra/newview/app_settings/shaders/class3/deferred')
-rw-r--r-- | indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 88 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 44 |
2 files changed, 50 insertions, 82 deletions
diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 7c0a11d442..c1f60da7ee 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -41,13 +41,10 @@ uniform int sun_up_factor; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleSoftClipFrag(vec3 l); - -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClip(vec3 light); - -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 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); +vec3 scaleSoftClipFragLinear(vec3 l); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -94,7 +91,7 @@ uniform vec3 light_diffuse[8]; float getAmbientClamp(); -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, float ambiance) { // SL-14895 inverted attenuation work-around // This routine is tweaked to match deferred lighting, but previously used an inverted la value. To reconstruct @@ -172,11 +169,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe vec3 speccol = lit*scol*light_col.rgb*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); col += speccol; - - float cur_glare = max(speccol.r, speccol.g); - cur_glare = max(cur_glare, speccol.b); - glare = max(glare, speccol.r); - glare += max(cur_glare, 0.0); } } } @@ -288,7 +280,7 @@ void main() //forward rendering, output lit linear color diffcol.rgb = srgb_to_linear(diffcol.rgb); - spec.rgb = srgb_to_linear(spec.rgb); + final_specular.rgb = srgb_to_linear(final_specular.rgb); vec3 pos = vary_position; @@ -298,9 +290,7 @@ void main() shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); #endif - spec = final_specular; vec4 diffuse = final_color; - float envIntensity = final_normal.z; vec3 color = vec3(0,0,0); @@ -311,70 +301,62 @@ void main() vec3 amblit; vec3 additive; vec3 atten; - - calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVarsLinear(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - // This call breaks the Mac GLSL compiler/linker for unknown reasons (17Mar2020) - // The call is either a no-op or a pure (pow) gamma adjustment, depending on GPU level - // TODO: determine if we want to re-apply the gamma adjustment, and if so understand & fix Mac breakage - //color = fullbrightScaleSoftClip(color); - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - vec3 ambenv; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, final_specular.a, env_intensity); + // use sky settings ambient or irradiance map sample, whichever is brighter color = max(amblit, ambenv); - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + float ambient = min(abs(dot(norm.xyz, light_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); + float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); vec3 sun_contrib = min(da, shadow) * sunlit; color.rgb += sun_contrib; - color.rgb *= diffuse.rgb; - color *= diffcol.rgb; - float glare = 0.0; + vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - if (spec.a > 0.0) // specular reflection + if (final_specular.a > 0.0) // specular reflection { - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = sunlit * shadow * (texture2D(lightFunc, vec2(sa, spec.a)).r); + float sa = dot(normalize(refnormpersp), light_dir.xyz); + vec3 dumbshiny = sunlit * shadow * (texture2D(lightFunc, vec2(sa, final_specular.a)).r); // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; + vec3 spec_contrib = dumbshiny * final_specular.rgb; bloom = dot(spec_contrib, spec_contrib) / 6; - glare = max(spec_contrib.r, spec_contrib.g); - glare = max(glare, spec_contrib.b); - color += spec_contrib; - applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); + applyGlossEnv(color, glossenv, final_specular, pos.xyz, norm.xyz); } - color = atmosFragLighting(color, additive, atten); - if (envIntensity > 0.0) + color = mix(color.rgb, diffcol.rgb, diffuse.a); + + if (env_intensity > 0.0) { // add environmentmap - applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); + applyLegacyEnv(color, legacyenv, final_specular, pos.xyz, norm.xyz, env_intensity); } - vec3 npos = normalize(-pos.xyz); + color.rgb = mix(atmosFragLightingLinear(color.rgb, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), diffuse.a); + color.rgb = scaleSoftClipFragLinear(color.rgb); - vec3 light = vec3(0, 0, 0); - - final_specular.rgb = final_specular.rgb; // SL-14035 +#ifdef WATER_FOG + vec4 temp = applyWaterFogView(pos, vec4(color, 0.0)); + color = temp.rgb; +#endif - color = mix(color.rgb, diffcol.rgb, diffuse.a); + vec3 npos = normalize(-pos.xyz); + 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, light_attenuation[i].w ); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -386,17 +368,9 @@ void main() color += light; - glare = min(glare, 1.0); - float al = max(diffcol.a, glare)*vertex_color.a; - -#ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color, al)); - color = temp.rgb; - al = temp.a; -#endif + float al = diffcol.a*vertex_color.a; frag_color = vec4(color, al); - #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer // deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index d525b673bf..c7ec1ddde9 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -69,11 +69,10 @@ uniform vec2 screen_res; vec3 getNorm(vec2 pos_screen); vec4 getPositionWithDepth(vec2 pos_screen, float depth); -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 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleSoftClipFrag(vec3 l); -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClip(vec3 light); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); +vec3 scaleSoftClipFragLinear(vec3 l); +vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten); // reflection probe interface void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, @@ -135,7 +134,7 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); + calcAtmosphericVarsLinear(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); vec3 ambenv; vec3 glossenv; @@ -158,7 +157,7 @@ void main() vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); - irradiance = max(amblit*1.725,irradiance); + irradiance = max(amblit*ao,irradiance); vec3 f0 = vec3(0.04); vec3 baseColor = diffuse.rgb; @@ -172,17 +171,14 @@ void main() float NdotV = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); color.rgb += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); - color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit*8.0 * scol; + color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit*2.75 * scol; color.rgb += colorEmissive; - //color = atmosFragLighting(color, additive, atten); - color *= atten.r; - color += additive*2.0; - + color = atmosFragLightingLinear(color, additive, atten); + color = scaleSoftClipFragLinear(color); } else { - // legacy shaders are still writng sRGB to gbuffer diffuse.rgb = srgb_to_linear(diffuse.rgb); spec.rgb = srgb_to_linear(spec.rgb); @@ -197,7 +193,7 @@ void main() // use sky settings ambient or irradiance map sample, whichever is brighter color = max(amblit, ambenv*ambocc); - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + float ambient = min(abs(dot(norm.xyz, light_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); @@ -216,32 +212,30 @@ void main() // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; color.rgb += spec_contrib; - // add reflection map - EXPERIMENTAL WORK IN PROGRESS + // add radiance map applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); - + + if (envIntensity > 0.0) + { // add environment map + applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); + } if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { - color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a); - if (envIntensity > 0.0) - { // add environmentmap - applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); - } - color = mix(color, fullbrightScaleSoftClip(color), diffuse.a); + color = mix(atmosFragLightingLinear(color, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), diffuse.a); + color = scaleSoftClipFragLinear(color); } } #ifdef WATER_FOG vec4 fogged = applyWaterFogView(pos.xyz, vec4(color, bloom)); color = fogged.rgb; - bloom = fogged.a; #endif frag_color.rgb = color.rgb; //output linear since local lights will be added to this shader's results - frag_color.a = bloom; + frag_color.a = 0.0; } |