From 50ec54831de88926ca13c9a72d89006ceda6c355 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 1 Jun 2023 19:49:23 -0500 Subject: DRTVWR-559 Revert skies to be very close to release and disable tone mapping when probe ambiance is zero. Hack for desaturating legacy materials has been removed for performance and quality reasons. Adds a new setting for auto adjusting legacy skies. This is the PBR "opt out" button. If disabled, legacy skies will disable tonemapping, automatic probe ambiance, and HDR/exposure. If enabled, legacy skies will behave as if probe ambiance and HDR scale are 1.0, and ambient will be cut in half. HDR scale will act as a sky brightener, but will automatically adjust dynamic exposure so the sky will be properly exposed. If you want relatively even exposure all the time, set HDR Scale to 1.0. If you want a high range of exposures between indoor/dark areas and outdoor/bright areas, increase HDR Scale. Also tuned up SSAO (thanks Rye!). Reviewed with Brad. --- .../class1/windlight/atmosphericsFuncs.glsl | 159 +++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl (limited to 'indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl new file mode 100644 index 0000000000..437fa0a6d5 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -0,0 +1,159 @@ +/** + * @file class2\windlight\atmosphericsFuncs.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +uniform vec3 lightnorm; +uniform vec3 sunlight_color; +uniform vec3 moonlight_color; +uniform int sun_up_factor; +uniform vec3 ambient_color; +uniform vec3 blue_horizon; +uniform vec3 blue_density; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; +uniform vec3 glow; +uniform float scene_light_strength; +uniform float sun_moon_glow_factor; +uniform float sky_hdr_scale; + +float getAmbientClamp() { return 1.0f; } + +vec3 srgb_to_linear(vec3 col); +vec3 legacy_adjust(vec3 col); + +// return colors in sRGB space +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, + out vec3 atten) +{ + vec3 rel_pos = inPositionEye; + + //(TERRAIN) limit altitude + if (abs(rel_pos.y) > max_y) rel_pos *= (max_y / rel_pos.y); + + vec3 rel_pos_norm = normalize(rel_pos); + float rel_pos_len = length(rel_pos); + + vec3 sunlight = (sun_up_factor == 1) ? sunlight_color: moonlight_color; + + // sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); + // I had thought blue_density and haze_density should have equal weighting, + // but attenuation due to haze_density tends to seem too strong + + vec3 combined_haze = blue_density + vec3(haze_density); + vec3 blue_weight = blue_density / combined_haze; + vec3 haze_weight = vec3(haze_density) / combined_haze; + + //(TERRAIN) compute sunlight from lightnorm y component. Factor is roughly cosecant(sun elevation) (for short rays like terrain) + float above_horizon_factor = 1.0 / max(1e-6, lightnorm.y); + sunlight *= exp(-light_atten * above_horizon_factor); // for sun [horizon..overhead] this maps to an exp curve [0..1] + + // main atmospheric scattering line integral + float density_dist = rel_pos_len * density_multiplier; + + // Transparency (-> combined_haze) + // ATI Bugfix -- can't store combined_haze*density_dist*distance_multiplier in a variable because the ati + // compiler gets confused. + combined_haze = exp(-combined_haze * density_dist * distance_multiplier); + + // final atmosphere attenuation factor + atten = combined_haze.rgb; + + // compute haze glow + float haze_glow = dot(rel_pos_norm, lightnorm.xyz); + + // dampen sun additive contrib when not facing it... + // SL-13539: This "if" clause causes an "additive" white artifact at roughly 77 degreees. + // if (length(light_dir) > 0.01) + haze_glow *= max(0.0f, dot(light_dir, rel_pos_norm)); + + haze_glow = 1. - haze_glow; + // haze_glow is 0 at the sun and increases away from sun + haze_glow = max(haze_glow, .001); // set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + haze_glow *= glow.x; + // higher glow.x gives dimmer glow (because next step is 1 / "angle") + haze_glow = pow(haze_glow, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + // add "minimum anti-solar illumination" + haze_glow += .25; + + haze_glow *= sun_moon_glow_factor; + + vec3 amb_color = ambient_color; + + // increase ambient when there are more clouds + vec3 tmpAmbient = amb_color + (vec3(1.) - amb_color) * cloud_shadow * 0.5; + + // Similar/Shared Algorithms: + // indra\llinventory\llsettingssky.cpp -- LLSettingsSky::calculateLightSettings() + // indra\newview\app_settings\shaders\class1\windlight\atmosphericsFuncs.glsl -- calcAtmosphericVars() + // haze color + vec3 cs = sunlight.rgb * (1. - cloud_shadow); + additive = (blue_horizon.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); + + // brightness of surface both sunlight and ambient + + sunlit = sunlight.rgb; + amblit = tmpAmbient; + + additive *= vec3(1.0 - combined_haze); +} + +vec3 srgb_to_linear(vec3 col); + +// provide a touch of lighting in the opposite direction of the sun light + // so areas in shadow don't lose all detail +float ambientLighting(vec3 norm, vec3 light_dir) +{ + float ambient = min(abs(dot(norm.xyz, light_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); + return ambient; +} + + +// return lit amblit in linear space, leave sunlit and additive in sRGB space +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 additive, + out vec3 atten) +{ + calcAtmosphericVars(inPositionEye, light_dir, 1.0, sunlit, amblit, additive, atten); + + // multiply to get similar colors as when the "scaleSoftClip" implementation was doubling color values + // (allows for mixing of light sources other than sunlight e.g. reflection probes) + sunlit *= 1.5; + amblit *= 0.5; + + // override amblit with ambient_color if sky probe ambiance is not zero + amblit = mix(amblit, ambient_color, clamp(sky_hdr_scale-1.0, 0.0, 1.0)); + + amblit = srgb_to_linear(amblit); + amblit *= ambientLighting(norm, light_dir); +} -- cgit v1.2.3