From e97c52bdd3cfdf12c3eb2e423b193979de816f34 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Wed, 4 Oct 2017 14:36:41 -0700 Subject: Rename uniform "sunlight_color_copy" to sunlight_color in shader. --- .../app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl index 6ff860362c..89b6a52909 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl @@ -23,7 +23,7 @@ * $/LicenseInfo$ */ -uniform vec4 sunlight_color_copy; +uniform vec4 sunlight_color; uniform vec4 light_ambient; vec3 atmosAmbient(vec3 light) @@ -33,12 +33,12 @@ vec3 atmosAmbient(vec3 light) vec3 atmosAffectDirectionalLight(float lightIntensity) { - return sunlight_color_copy.rgb * lightIntensity; + return sunlight_color.rgb * lightIntensity; } vec3 atmosGetDiffuseSunlightColor() { - return sunlight_color_copy.rgb; + return sunlight_color.rgb; } vec3 scaleDownLight(vec3 light) -- cgit v1.2.3 From 99b82d944937ce321f64aa91fb18ab2aedd3992a Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Sun, 18 Feb 2018 15:52:23 +0000 Subject: Atmospherics WIP libatmosphere integrated in indra/llrender/llatmosphere.cpp Still working on runtime shaders to use libatmosphere precomputed atmospherics textures --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 4 +++- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 4 ---- indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 03bdb754b5..7f1a8cce0d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -397,7 +397,9 @@ void main() float da = dot(norm.xyz, sun_dir.xyz); float final_da = max(0.0,da); - final_da = min(final_da, 1.0f); + final_da = min(final_da, 1.0f); + +// why an ad hoc gamma boost here? srgb_to_linear instead? final_da = pow(final_da, 1.0/1.3); vec4 diffuse = texture2DRect(diffuseRect, tc); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index f7832521fa..cf076d156a 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -276,10 +276,6 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + tmpAmbient))); //brightness of surface both sunlight and ambient - /*setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * global_gamma); - setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * global_gamma); - setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * global_gamma);*/ - setSunlitColor(vec3(sunlight * .5)); setAmblitColor(vec3(tmpAmbient * .25)); setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 81af1fdc8a..b2d9de6e73 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -238,8 +238,8 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff+1.0; - float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); + float fa = falloff + 1.0; + float dist_atten = min(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; -- cgit v1.2.3 From 6303ef5763393021d35c55a012cacfa7ee8c650e Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 26 Feb 2018 16:38:50 +0000 Subject: Redo advanced atmo shader integration with SL. --- .../shaders/class3/windlight/advancedAtmoF.glsl | 71 ++++++++++++++++++++++ .../shaders/class3/windlight/advancedAtmoV.glsl | 43 +++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl new file mode 100644 index 0000000000..c71eaf4b13 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl @@ -0,0 +1,71 @@ +/** + * @file advancedAtmoF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +in vec3 view_dir; + +uniform vec3 cameraPosLocal; +uniform vec3 sun_direction; +uniform vec2 sun_size; + +uniform sampler2D cloud_noise_texture; +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D mie_scattering_texture; + +vec3 GetSolarLuminance(); +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 sun_dir, out vec3 transmittance); +vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 sun_dir, out vec3 transmittance); +vec3 GetSunAndSkyIlluminance(vec3 pos, vec3 norm, vec3 sun_dir, out vec3 sky_irradiance); + +void main() +{ + vec3 view_direction = normalize(view_dir); + + vec3 camPos = cameraPosLocal; + vec3 transmittance; + vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); + + radiance *= transmittance; + + // If the view ray intersects the Sun, add the Sun radiance. + if (dot(view_direction, sun_direction) >= sun_size.y) + { + radiance = radiance + transmittance * GetSolarLuminance(); + } + + vec3 color = vec3(1.0) - exp(-radiance); + color = pow(color, vec3(1.0 / 2.2)); + + frag_color.rgb = color; + + frag_color.a = 1.0; +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl new file mode 100644 index 0000000000..52a7595379 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl @@ -0,0 +1,43 @@ +/** + * @file advancedAtmoV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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 mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + +// Inputs +uniform vec3 camPosLocal; + +out vec3 view_dir; + +void main() +{ + // World / view / projection + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + + // this will be normalized in the frag shader... + view_dir = position.xyz - camPosLocal.xyz; +} + -- cgit v1.2.3 From 31017934581437836e847d8fcb5a76489f3baf50 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 26 Feb 2018 16:41:39 +0000 Subject: Add distinct versions of sky, cloud, and transport shaders so they can be different with adv atmo shaders. --- .../shaders/class3/windlight/cloudsF.glsl | 104 +++++++++++ .../shaders/class3/windlight/cloudsV.glsl | 190 +++++++++++++++++++++ .../shaders/class3/windlight/skyF.glsl | 65 +++++++ .../shaders/class3/windlight/skyV.glsl | 156 +++++++++++++++++ .../shaders/class3/windlight/transportF.glsl | 53 ++++++ 5 files changed, 568 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class3/windlight/cloudsF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/windlight/cloudsV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/windlight/skyF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/windlight/skyV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/windlight/transportF.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/cloudsF.glsl new file mode 100644 index 0000000000..96c70651b1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/cloudsF.glsl @@ -0,0 +1,104 @@ +/** + * @file WLCloudsF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +///////////////////////////////////////////////////////////////////////// +// The fragment shader for the sky +///////////////////////////////////////////////////////////////////////// + +VARYING vec4 vary_CloudColorSun; +VARYING vec4 vary_CloudColorAmbient; +VARYING float vary_CloudDensity; +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; + +uniform sampler2D cloud_noise_texture; +uniform vec4 cloud_pos_density1; +uniform vec4 cloud_pos_density2; +uniform vec4 gamma; + +/// Soft clips the light with a gamma correction +vec3 scaleSoftClip(vec3 light) { + //soft clip effect: + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, gamma.xxx); + + return light; +} + +void main() +{ + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + + vec4 cloudColorSun = vary_CloudColorSun; + vec4 cloudColorAmbient = vary_CloudColorAmbient; + float cloudDensity = vary_CloudDensity; + vec2 uv3 = vary_texcoord2.xy; + vec2 uv4 = vary_texcoord3.xy; + + // Offset texture coords + uv1 += cloud_pos_density1.xy; //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow + + + // Compute alpha1, the main cloud opacity + float alpha1 = (texture2D(cloud_noise_texture, uv1).x - 0.5) + (texture2D(cloud_noise_texture, uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.); + + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; + + + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (texture2D(cloud_noise_texture, uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; + + // Combine + vec4 color; + color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); + color *= 2.; + + /// Gamma correct for WL (soft clip effect). + frag_color.rgb = scaleSoftClip(color.rgb); + frag_color.a = alpha1; +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class3/windlight/cloudsV.glsl new file mode 100644 index 0000000000..c1dd45cd67 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/cloudsV.glsl @@ -0,0 +1,190 @@ +/** + * @file WLCloudsV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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 mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +////////////////////////////////////////////////////////////////////////// +// The vertex shader for creating the atmospheric sky +/////////////////////////////////////////////////////////////////////////////// + +// Output parameters +VARYING vec4 vary_CloudColorSun; +VARYING vec4 vary_CloudColorAmbient; +VARYING float vary_CloudDensity; +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; + +// Inputs +uniform vec3 camPosLocal; + +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; + +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float max_y; + +uniform vec4 glow; + +uniform vec4 cloud_color; + +uniform float cloud_scale; + +void main() +{ + + // World / view / projection + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + + vary_texcoord0 = texcoord0; + + // Get relative position + vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); + + // Set altitude + if (P.y > 0.) + { + P *= (max_y / P.y); + } + else + { + P *= (-32000. / P.y); + } + + // Can normalize then + vec3 Pn = normalize(P); + float Plen = length(P); + + // Initialize temp variables + vec4 temp1 = vec4(0.); + vec4 temp2 = vec4(0.); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + + // Calculate relative weights + temp1 = blue_density + haze_density; + blue_weight = blue_density / temp1; + haze_weight = haze_density / temp1; + + // Compute sunlight from P & lightnorm (for long rays like sky) + temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Distance + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z); + + + // Compute haze glow + temp2.x = dot(Pn, lightnorm.xyz); + temp2.x = 1. - temp2.x; + // temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .001); + // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + // Higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + // Add "minimum anti-solar illumination" + temp2.x += .25; + + // Increase ambient when there are more clouds + vec4 tmpAmbient = ambient; + tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + + // Dim sunlight by cloud shadow percentage + sunlight *= (1. - cloud_shadow); + + // Haze color below cloud + vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) + ); + + // CLOUDS + + sunlight = sunlight_color; + temp2.y = max(0., lightnorm.y * 2.); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Cloud color out + vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; + vary_CloudColorAmbient = tmpAmbient * cloud_color; + + // Attenuate cloud color by atmosphere + temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds + vary_CloudColorSun *= temp1; + vary_CloudColorAmbient *= temp1; + vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); + + // Make a nice cloud density based on the cloud_shadow value that was passed in. + vary_CloudDensity = 2. * (cloud_shadow - 0.25); + + + // Texture coords + vary_texcoord0 = texcoord0; + vary_texcoord0.xy -= 0.5; + vary_texcoord0.xy /= cloud_scale; + vary_texcoord0.xy += 0.5; + + vary_texcoord1 = vary_texcoord0; + vary_texcoord1.x += lightnorm.x * 0.0125; + vary_texcoord1.y += lightnorm.z * 0.0125; + + vary_texcoord2 = vary_texcoord0 * 16.; + vary_texcoord3 = vary_texcoord1 * 16.; + + // Combine these to minimize register use + vary_CloudColorAmbient += oHazeColorBelowCloud; + + // needs this to compile on mac + //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); + + // END CLOUDS +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl new file mode 100644 index 0000000000..e2a2367626 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl @@ -0,0 +1,65 @@ +/** + * @file WLSkyF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +///////////////////////////////////////////////////////////////////////// +// The fragment shader for the sky +///////////////////////////////////////////////////////////////////////// + +VARYING vec4 vary_HazeColor; + +uniform sampler2D cloud_noise_texture; +uniform vec4 gamma; + +/// Soft clips the light with a gamma correction +vec3 scaleSoftClip(vec3 light) { + //soft clip effect: + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, gamma.xxx); + + return light; +} + +void main() +{ + // Potential Fill-rate optimization. Add cloud calculation + // back in and output alpha of 0 (so that alpha culling kills + // the fragment) if the sky wouldn't show up because the clouds + // are fully opaque. + + vec4 color; + color = vary_HazeColor; + color *= 2.; + + /// Gamma correct for WL (soft clip effect). + frag_color.rgb = scaleSoftClip(color.rgb); + frag_color.a = 1.0; +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl new file mode 100644 index 0000000000..3788ddaf2d --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl @@ -0,0 +1,156 @@ +/** + * @file WLSkyV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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 mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + +// SKY //////////////////////////////////////////////////////////////////////// +// The vertex shader for creating the atmospheric sky +/////////////////////////////////////////////////////////////////////////////// + +// Output parameters +VARYING vec4 vary_HazeColor; + +// Inputs +uniform vec3 camPosLocal; + +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; + +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float max_y; + +uniform vec4 glow; + +uniform vec4 cloud_color; + +void main() +{ + + // World / view / projection + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + + // Get relative position + vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); + //vec3 P = position.xyz + vec3(0,50,0); + + // Set altitude + if (P.y > 0.) + { + P *= (max_y / P.y); + } + else + { + P *= (-32000. / P.y); + } + + // Can normalize then + vec3 Pn = normalize(P); + float Plen = length(P); + + // Initialize temp variables + vec4 temp1 = vec4(0.); + vec4 temp2 = vec4(0.); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + + // Calculate relative weights + temp1 = blue_density + haze_density; + blue_weight = blue_density / temp1; + haze_weight = haze_density / temp1; + + // Compute sunlight from P & lightnorm (for long rays like sky) + temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Distance + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z); + + + // Compute haze glow + temp2.x = dot(Pn, lightnorm.xyz); + temp2.x = 1. - temp2.x; + // temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .001); + // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + // Higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + // Add "minimum anti-solar illumination" + temp2.x += .25; + + + // Haze color above cloud + vary_HazeColor = ( blue_horizon * blue_weight * (sunlight + ambient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) + ); + + + // Increase ambient when there are more clouds + vec4 tmpAmbient = ambient; + tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + + // Dim sunlight by cloud shadow percentage + sunlight *= (1. - cloud_shadow); + + // Haze color below cloud + vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) + ); + + // Final atmosphere additive + vary_HazeColor *= (1. - temp1); + + // Attenuate cloud color by atmosphere + temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds + + // At horizon, blend high altitude sky color towards the darker color below the clouds + vary_HazeColor += (additiveColorBelowCloud - vary_HazeColor) * (1. - sqrt(temp1)); + + // won't compile on mac without this being set + //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl new file mode 100644 index 0000000000..8a8e4cb0f6 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -0,0 +1,53 @@ +/** + * @file transportF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +////////////////////////////////////////////////////////// +// The fragment shader for the terrain atmospherics +////////////////////////////////////////////////////////// + +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); + +uniform sampler2D cloudMap; +uniform vec4 cloud_pos_density1; + +vec3 atmosTransport(vec3 light) { + light *= getAtmosAttenuation().r; + light += getAdditiveColor() * 2.0; + return light; +} + +vec3 fullbrightAtmosTransport(vec3 light) { + float brightness = dot(light.rgb, vec3(0.33333)); + + return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); +} + +vec3 fullbrightShinyAtmosTransport(vec3 light) { + float brightness = dot(light.rgb, vec3(0.33333)); + + return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness); +} + -- cgit v1.2.3 From 72270213f5eebd019b10bdd6ec15020ba3d2ecf5 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Wed, 28 Feb 2018 21:46:30 +0000 Subject: Add 3p package for adv atmospherics to autobuild. Mark legacy atmospherics code with ifdefs. Fix up legacy uplift to include new atmospherics settings. --- .../shaders/class3/windlight/advancedAtmoF.glsl | 2 - .../shaders/class3/windlight/skyF.glsl | 54 +++++---- .../shaders/class3/windlight/skyV.glsl | 121 +-------------------- 3 files changed, 34 insertions(+), 143 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl index c71eaf4b13..d27363a60c 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl @@ -33,9 +33,7 @@ in vec3 view_dir; uniform vec3 cameraPosLocal; uniform vec3 sun_direction; -uniform vec2 sun_size; -uniform sampler2D cloud_noise_texture; uniform sampler2D transmittance_texture; uniform sampler3D scattering_texture; uniform sampler3D mie_scattering_texture; diff --git a/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl index e2a2367626..c71eaf4b13 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl @@ -1,5 +1,5 @@ /** - * @file WLSkyF.glsl + * @file advancedAtmoF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -29,37 +29,43 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -///////////////////////////////////////////////////////////////////////// -// The fragment shader for the sky -///////////////////////////////////////////////////////////////////////// +in vec3 view_dir; -VARYING vec4 vary_HazeColor; +uniform vec3 cameraPosLocal; +uniform vec3 sun_direction; +uniform vec2 sun_size; uniform sampler2D cloud_noise_texture; -uniform vec4 gamma; +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D mie_scattering_texture; -/// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light) { - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} +vec3 GetSolarLuminance(); +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 sun_dir, out vec3 transmittance); +vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 sun_dir, out vec3 transmittance); +vec3 GetSunAndSkyIlluminance(vec3 pos, vec3 norm, vec3 sun_dir, out vec3 sky_irradiance); void main() { - // Potential Fill-rate optimization. Add cloud calculation - // back in and output alpha of 0 (so that alpha culling kills - // the fragment) if the sky wouldn't show up because the clouds - // are fully opaque. + vec3 view_direction = normalize(view_dir); + + vec3 camPos = cameraPosLocal; + vec3 transmittance; + vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); - vec4 color; - color = vary_HazeColor; - color *= 2.; + radiance *= transmittance; - /// Gamma correct for WL (soft clip effect). - frag_color.rgb = scaleSoftClip(color.rgb); - frag_color.a = 1.0; + // If the view ray intersects the Sun, add the Sun radiance. + if (dot(view_direction, sun_direction) >= sun_size.y) + { + radiance = radiance + transmittance * GetSolarLuminance(); + } + + vec3 color = vec3(1.0) - exp(-radiance); + color = pow(color, vec3(1.0 / 2.2)); + + frag_color.rgb = color; + + frag_color.a = 1.0; } diff --git a/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl index 3788ddaf2d..52a7595379 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl @@ -1,5 +1,5 @@ /** - * @file WLSkyV.glsl + * @file advancedAtmoV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -27,130 +27,17 @@ uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; -// SKY //////////////////////////////////////////////////////////////////////// -// The vertex shader for creating the atmospheric sky -/////////////////////////////////////////////////////////////////////////////// - -// Output parameters -VARYING vec4 vary_HazeColor; - // Inputs uniform vec3 camPosLocal; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; - -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float max_y; - -uniform vec4 glow; - -uniform vec4 cloud_color; +out vec3 view_dir; void main() { - // World / view / projection gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - // Get relative position - vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); - //vec3 P = position.xyz + vec3(0,50,0); - - // Set altitude - if (P.y > 0.) - { - P *= (max_y / P.y); - } - else - { - P *= (-32000. / P.y); - } - - // Can normalize then - vec3 Pn = normalize(P); - float Plen = length(P); - - // Initialize temp variables - vec4 temp1 = vec4(0.); - vec4 temp2 = vec4(0.); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - - // Calculate relative weights - temp1 = blue_density + haze_density; - blue_weight = blue_density / temp1; - haze_weight = haze_density / temp1; - - // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Distance - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); - - - // Compute haze glow - temp2.x = dot(Pn, lightnorm.xyz); - temp2.x = 1. - temp2.x; - // temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .001); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // Add "minimum anti-solar illumination" - temp2.x += .25; - - - // Haze color above cloud - vary_HazeColor = ( blue_horizon * blue_weight * (sunlight + ambient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) - ); - - - // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; - - // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); - - // Haze color below cloud - vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) - ); - - // Final atmosphere additive - vary_HazeColor *= (1. - temp1); - - // Attenuate cloud color by atmosphere - temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds - - // At horizon, blend high altitude sky color towards the darker color below the clouds - vary_HazeColor += (additiveColorBelowCloud - vary_HazeColor) * (1. - sqrt(temp1)); - - // won't compile on mac without this being set - //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); + // this will be normalized in the frag shader... + view_dir = position.xyz - camPosLocal.xyz; } -- cgit v1.2.3 From 84e47f45f6974ac4dad626db3bbdf3bacebd41f8 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Thu, 8 Mar 2018 22:26:31 +0000 Subject: Get libatmosphere shader into link chain for Adv WL shaders. Point autobuild at fixed libatmosphere. --- indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl index d27363a60c..014ab9d11b 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl @@ -33,6 +33,7 @@ in vec3 view_dir; uniform vec3 cameraPosLocal; uniform vec3 sun_direction; +uniform float sun_size; uniform sampler2D transmittance_texture; uniform sampler3D scattering_texture; @@ -54,7 +55,7 @@ void main() radiance *= transmittance; // If the view ray intersects the Sun, add the Sun radiance. - if (dot(view_direction, sun_direction) >= sun_size.y) + if (dot(view_direction, sun_direction) >= sun_size) { radiance = radiance + transmittance * GetSolarLuminance(); } -- cgit v1.2.3 From b2d8d63890e3ba0a5fe303f8e2de7358e4f9fc23 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Fri, 9 Mar 2018 20:59:18 +0000 Subject: Fix warnings from shaders and include EXTRA_CODE_HERE sentinel in places using DEFINE_GL_FRAGCOLOR for consistency. --- .../app_settings/shaders/class1/deferred/attachmentShadowF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl | 2 ++ .../newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl | 4 +++- indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl | 2 +- .../app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl | 2 ++ .../shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl | 2 ++ .../shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl | 2 ++ .../app_settings/shaders/class1/deferred/diffuseIndexedF.glsl | 2 ++ .../app_settings/shaders/class1/deferred/fullbrightShinyF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl | 5 +++-- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 ++ .../app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl | 2 ++ .../app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/skyF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/starsF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/treeF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl | 2 ++ .../newview/app_settings/shaders/class1/interface/glowcombineF.glsl | 4 ++-- 25 files changed, 49 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl index 22c9a4d14e..8e9a5fcd41 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl @@ -22,6 +22,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index 662c762bca..86625a25ae 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl index b809b73973..8e46425ea8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl @@ -22,7 +22,9 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index 58fb01d200..0e95c267bc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -22,6 +22,8 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ + +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 1d8ca04ccd..7b971fcc66 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -22,7 +22,7 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl index 7930b5d18b..e4fff3e21a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index 8525e13333..f3a0fba7cd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl index 37d70a2412..e16ae4844d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl @@ -23,6 +23,7 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index 6befb1bd8b..d8b980c402 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -22,6 +22,8 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ + +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index adc361d7a2..04ec35b308 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index b0db9876d3..30e560450b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -23,7 +23,7 @@ * $/LicenseInfo$ */ - +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index f8fdde43f9..4818afc910 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl index dcf474824d..be1003a7e0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl @@ -22,8 +22,8 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - -uniform sampler2DRect diffuseMap; + +/*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -31,6 +31,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif +uniform sampler2DRect diffuseMap; VARYING vec2 vary_fragcoord; void main() diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 07d28ed4cd..76750c400a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #define DIFFUSE_ALPHA_MODE_IGNORE 0 #define DIFFUSE_ALPHA_MODE_BLEND 1 #define DIFFUSE_ALPHA_MODE_MASK 2 diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 3a3e871ade..b35b3e62c5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -30,14 +30,14 @@ #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else #define frag_color gl_FragColor #endif -/*[EXTRA_CODE_HERE]*/ - uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; uniform sampler2DRect depthMap; diff --git a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl index 018ced4cad..e33254304b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index 91a96977f0..ae1b19a35c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl index 3d1b182875..242aef821d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 22f4729e2e..46bf718270 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 821058804c..029a98e16a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 52a429465f..597fef486e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index 808750496f..3cd791920d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl index d4d2f5f571..e34d75ba1d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index 78f841c733..b173f233a5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else diff --git a/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl b/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl index 5c088b3a3c..b5bbbb5c73 100644 --- a/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl @@ -25,14 +25,14 @@ #extension GL_ARB_texture_rectangle : enable +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else #define frag_color gl_FragColor #endif -/*[EXTRA_CODE_HERE]*/ - uniform sampler2D glowMap; uniform sampler2DRect screenMap; -- cgit v1.2.3 From b6b23926340d8a2ac142b02923f04624b7c6b08e Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Fri, 9 Mar 2018 21:40:46 +0000 Subject: De-duplicate water fog code and modify programs to include the shared object as necessary. --- .../shaders/class1/deferred/alphaF.glsl | 53 ++-------------------- .../shaders/class1/deferred/fullbrightF.glsl | 51 ++------------------- .../shaders/class1/deferred/materialF.glsl | 52 ++------------------- .../shaders/class1/deferred/softenLightF.glsl | 53 ++-------------------- .../shaders/class1/environment/waterFogF.glsl | 12 +++-- 5 files changed, 28 insertions(+), 193 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index b9c8f34cb0..b36016529c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -98,6 +98,10 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif + vec3 srgb_to_linear(vec3 cs) { vec3 low_range = cs / vec3(12.92); @@ -219,52 +223,6 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc) } #endif -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - float es = -(dot(view, waterPlane.xyz)); - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; -} -#endif - vec3 getSunlitColor() { return vary_SunlitColor; @@ -621,9 +579,8 @@ void main() color.rgb = linear_to_srgb(color.rgb); #ifdef WATER_FOG - color = applyWaterFogDeferred(pos.xyz, color); + color = applyWaterFogView(pos.xyz, color); #endif - #endif frag_color = color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 756e625d07..d554377220 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -41,6 +41,9 @@ VARYING vec3 vary_position; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif vec3 srgb_to_linear(vec3 cs) { @@ -94,52 +97,6 @@ vec3 fullbrightScaleSoftClipDeferred(vec3 light) uniform float minimum_alpha; #endif -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - float es = -(dot(view, waterPlane.xyz)); - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; -} -#endif - void main() { #if HAS_DIFFUSE_LOOKUP @@ -166,7 +123,7 @@ void main() #ifdef WATER_FOG vec3 pos = vary_position; - vec4 fogged = applyWaterFogDeferred(pos, vec4(color.rgb, final_alpha)); + vec4 fogged = applyWaterFogView(pos, vec4(color.rgb, final_alpha)); color.rgb = fogged.rgb; color.a = fogged.a; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 76750c400a..6fa625765a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -33,6 +33,10 @@ uniform float emissive_brightness; uniform float display_gamma; +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif + vec3 srgb_to_linear(vec3 cs) { vec3 low_range = cs / vec3(12.92); @@ -154,52 +158,6 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - float es = -(dot(view, waterPlane.xyz)); - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; -} -#endif - vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); @@ -773,7 +731,7 @@ void main() col.rgb = linear_to_srgb(col.rgb); #ifdef WATER_FOG - vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al)); + vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); col.rgb = temp.rgb; al = temp.a; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 7f1a8cce0d..b294dba167 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -81,6 +81,10 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif + vec3 srgb_to_linear(vec3 cs) { vec3 low_range = cs / vec3(12.92); @@ -193,53 +197,6 @@ void setAtmosAttenuation(vec3 v) vary_AtmosAttenuation = v; } - -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - float es = -(dot(view, waterPlane.xyz)); - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; -} -#endif - void calcAtmospherics(vec3 inPositionEye, float ambFactor) { vec3 P = inPositionEye; @@ -462,7 +419,7 @@ void main() } #ifdef WATER_FOG - vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); + vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); col = fogged.rgb; bloom = fogged.a; #endif diff --git a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl index 4bdfce9260..a7c28a1ac3 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl @@ -33,10 +33,10 @@ uniform float waterFogKS; vec3 getPositionEye(); -vec4 applyWaterFog(vec4 color) +vec4 applyWaterFogView(vec3 pos, vec4 color) { + vec3 view = normalize(pos); //normalize view vector - vec3 view = normalize(getPositionEye()); float es = -(dot(view, waterPlane.xyz)); //find intersection point with water plane and eye vector @@ -47,7 +47,7 @@ vec4 applyWaterFog(vec4 color) vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); //get object depth - float depth = length(getPositionEye() - int_v); + float depth = length(pos - int_v); //get "thickness" of water float l = max(depth, 0.1); @@ -72,3 +72,9 @@ vec4 applyWaterFog(vec4 color) return color; } +vec4 applyWaterFog(vec4 color) +{ + //normalize view vector + return applyWaterFogView(getPositionEye(), color); +} + -- cgit v1.2.3 From cf460b13bee894684d0ca1bcb5bbc9eb38df719c Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 12 Mar 2018 16:24:16 +0100 Subject: De-duplicate sRGB conversion funcs from many shaders and unify on using the version that works on OSX. Add more logging to shader loading about fallbacks and loading succcess. Add frag shaders for sharing sRGB and normal encode/decode via GL shader linkage. --- .../shaders/class1/deferred/alphaF.glsl | 40 +------------ .../shaders/class1/deferred/fullbrightF.glsl | 38 +----------- .../shaders/class1/deferred/impostorF.glsl | 36 +----------- .../shaders/class1/deferred/materialF.glsl | 38 +----------- .../shaders/class1/deferred/multiSpotLightF.glsl | 44 +------------- .../shaders/class1/deferred/pointLightF.glsl | 6 -- .../class1/deferred/postDeferredGammaCorrect.glsl | 20 +------ .../shaders/class1/deferred/shadowAlphaBlendF.glsl | 55 ++++++++++++++++++ .../shaders/class1/deferred/shadowAlphaBlendV.glsl | 67 ++++++++++++++++++++++ .../shaders/class1/deferred/softenLightF.glsl | 38 +----------- .../shaders/class1/deferred/spotLightF.glsl | 44 +------------- .../shaders/class1/deferred/srgb_mac.glsl | 54 ----------------- .../shaders/class1/deferred/sunLightSSAOF.glsl | 6 -- .../shaders/class1/deferred/underWaterF.glsl | 38 +----------- .../shaders/class1/deferred/waterF.glsl | 37 +----------- .../shaders/class1/environment/decodeNorm.glsl | 11 ++++ .../shaders/class1/environment/encodeNorm.glsl | 7 +++ .../shaders/class1/environment/srgbF.glsl | 62 ++++++++++++++++++++ .../shaders/class2/deferred/multiSpotLightF.glsl | 38 +----------- .../shaders/class2/deferred/softenLightF.glsl | 38 +----------- .../shaders/class2/deferred/spotLightF.glsl | 38 +----------- 21 files changed, 226 insertions(+), 529 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl create mode 100644 indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl delete mode 100644 indra/newview/app_settings/shaders/class1/deferred/srgb_mac.glsl create mode 100644 indra/newview/app_settings/shaders/class1/environment/decodeNorm.glsl create mode 100644 indra/newview/app_settings/shaders/class1/environment/encodeNorm.glsl create mode 100644 indra/newview/app_settings/shaders/class1/environment/srgbF.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index b36016529c..090aa3d27f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -102,42 +102,8 @@ uniform vec3 light_diffuse[8]; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec2 encode_normal(vec3 n) { @@ -527,7 +493,7 @@ void main() calcAtmospherics(pos.xyz, 1.0); vec2 abnormal = encode_normal(norm.xyz); - norm.xyz = decode_normal(abnormal.xy); + norm.xyz = decode_normal(abnormal.xy); float da = dot(norm.xyz, sun_dir.xyz); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index d554377220..134e9c3b4c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -45,42 +45,8 @@ VARYING vec2 vary_texcoord0; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec3 fullbrightAtmosTransportDeferred(vec3 light) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index 4818afc910..6ba16b169c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -40,41 +40,7 @@ uniform sampler2D specularMap; VARYING vec2 vary_texcoord0; -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 linear_to_srgb(vec3 cl); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6fa625765a..e1b582c08c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -37,42 +37,8 @@ uniform float display_gamma; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index b35b3e62c5..eeb2fe39cc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -72,12 +72,6 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - vec3 decode_normal (vec2 enc) { vec2 fenc = enc*4-2; @@ -88,43 +82,9 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index aba4a01754..4f02365f45 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -56,12 +56,6 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - vec3 decode_normal (vec2 enc) { vec2 fenc = enc*4-2; diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 6669947d1b..cbc19bbba3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -40,25 +40,7 @@ VARYING vec2 vary_fragcoord; uniform float display_gamma; -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} - +vec3 linear_to_srgb(vec3 cl); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl new file mode 100644 index 0000000000..12bc690553 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl @@ -0,0 +1,55 @@ +/** + * @file shadowAlphaMaskF.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2D diffuseMap; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING float pos_w; + +VARYING float target_pos_x; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void main() +{ + float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; + + frag_color = vec4(alpha, alpha, alpha, 1); + +#if !DEPTH_CLAMP + gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); +#endif +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl new file mode 100644 index 0000000000..11411a605c --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl @@ -0,0 +1,67 @@ +/** + * @file shadowAlphaMaskV.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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 mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; +uniform float shadow_target_width; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec4 diffuse_color; +ATTRIBUTE vec2 texcoord0; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING float pos_w; + +VARYING float target_pos_x; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void passTextureIndex(); + +void main() +{ + //transform vertex + vec4 pre_pos = vec4(position.xyz, 1.0); + vec4 pos = modelview_projection_matrix * pre_pos; + target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + + pos_w = pos.w; + +#if !DEPTH_CLAMP + pos_zd2 = pos.z * 0.5; + + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif + + passTextureIndex(); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + vertex_color = diffuse_color; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index b294dba167..0703f75d60 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -85,42 +85,8 @@ uniform vec2 screen_res; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} - +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index f1aec315cc..88e79a8c46 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -70,12 +70,6 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - vec3 decode_normal (vec2 enc) { vec2 fenc = enc*4-2; @@ -87,42 +81,8 @@ vec3 decode_normal (vec2 enc) return n; } -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb_mac.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb_mac.glsl deleted file mode 100644 index 6cc1e6e798..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb_mac.glsl +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @file srgb.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, 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$ - */ - -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - - bvec3 lt = lessThan(cl,vec3(0.0031308)); - - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -} - diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 930255729b..3a31173fab 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -51,12 +51,6 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - vec3 decode_normal (vec2 enc) { vec2 fenc = enc*4-2; diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index b173f233a5..5e676b23f0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -58,42 +58,8 @@ VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec2 encode_normal(vec3 n) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 37dcd3ad34..99c84c67e9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -69,42 +69,7 @@ VARYING vec4 littleWave; VARYING vec4 view; VARYING vec4 vary_position; -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 srgb_to_linear(vec3 cs); vec2 encode_normal(vec3 n) { diff --git a/indra/newview/app_settings/shaders/class1/environment/decodeNorm.glsl b/indra/newview/app_settings/shaders/class1/environment/decodeNorm.glsl new file mode 100644 index 0000000000..0abb1e43db --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/decodeNorm.glsl @@ -0,0 +1,11 @@ +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + diff --git a/indra/newview/app_settings/shaders/class1/environment/encodeNorm.glsl b/indra/newview/app_settings/shaders/class1/environment/encodeNorm.glsl new file mode 100644 index 0000000000..ee21715c1d --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/encodeNorm.glsl @@ -0,0 +1,7 @@ + +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + diff --git a/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl new file mode 100644 index 0000000000..835662732a --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl @@ -0,0 +1,62 @@ +/** + * @file srgbF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} + diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index b9bb522842..ac7329e3eb 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -71,42 +71,8 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec2 encode_normal(vec3 n) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index cf076d156a..9912f30731 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -80,42 +80,8 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec2 encode_normal(vec3 n) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index b2d9de6e73..440f4aa157 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -88,42 +88,8 @@ vec3 decode_normal (vec2 enc) return n; } -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 correctWithGamma(vec4 col) { -- cgit v1.2.3 From 98b2fed85fd459012ed2b859ea40a3f56d27c0e8 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 12 Mar 2018 17:52:04 +0100 Subject: De-duplicate shader code for encoding and decoding normals to/from gbuffer format. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 19 ++----------------- .../app_settings/shaders/class1/deferred/avatarF.glsl | 6 +----- .../shaders/class1/deferred/blurLightF.glsl | 17 +---------------- .../app_settings/shaders/class1/deferred/bumpF.glsl | 6 +----- .../shaders/class1/deferred/diffuseAlphaMaskF.glsl | 6 +----- .../class1/deferred/diffuseAlphaMaskIndexedF.glsl | 6 +----- .../class1/deferred/diffuseAlphaMaskNoColorF.glsl | 6 +----- .../shaders/class1/deferred/diffuseF.glsl | 6 +----- .../shaders/class1/deferred/diffuseIndexedF.glsl | 7 +------ .../shaders/class1/deferred/materialF.glsl | 18 ++---------------- .../shaders/class1/deferred/multiPointLightF.glsl | 17 +---------------- .../shaders/class1/deferred/multiSpotLightF.glsl | 12 +----------- .../shaders/class1/deferred/pointLightF.glsl | 11 +---------- .../shaders/class1/deferred/softenLightF.glsl | 12 +----------- .../shaders/class1/deferred/spotLightF.glsl | 12 +----------- .../shaders/class1/deferred/sunLightSSAOF.glsl | 11 +---------- .../shaders/class1/deferred/terrainF.glsl | 6 +----- .../app_settings/shaders/class1/deferred/treeF.glsl | 6 +----- .../shaders/class1/deferred/underWaterF.glsl | 6 +----- .../app_settings/shaders/class1/deferred/waterF.glsl | 7 +------ .../shaders/class1/environment/decodeNorm.glsl | 11 ----------- .../shaders/class1/environment/decodeNormF.glsl | 11 +++++++++++ .../shaders/class1/environment/encodeNorm.glsl | 7 ------- .../shaders/class1/environment/encodeNormF.glsl | 7 +++++++ .../shaders/class2/deferred/multiSpotLightF.glsl | 18 +----------------- .../shaders/class2/deferred/softenLightF.glsl | 18 +----------------- .../shaders/class2/deferred/spotLightF.glsl | 18 +----------------- .../shaders/class2/deferred/sunLightF.glsl | 17 +---------------- .../shaders/class2/deferred/sunLightSSAOF.glsl | 17 +---------------- 29 files changed, 45 insertions(+), 276 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class1/environment/decodeNorm.glsl create mode 100644 indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl delete mode 100644 indra/newview/app_settings/shaders/class1/environment/encodeNorm.glsl create mode 100644 indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 090aa3d27f..47dadb4ced 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -104,23 +104,8 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 encode_normal (vec2 enc); +vec3 decode_normal (vec2 enc); vec3 calcDirectionalLight(vec3 n, vec3 l) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index 86625a25ae..60d83cc623 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -38,11 +38,7 @@ uniform float minimum_alpha; VARYING vec3 vary_normal; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index cbd8d2ebfc..b56abb66d1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -61,22 +61,7 @@ vec4 getPosition(vec2 pos_screen) return pos; } -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index 0e95c267bc..b5677a07ee 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -42,11 +42,7 @@ VARYING vec3 vary_mat2; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl index e4fff3e21a..b328ee9483 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -39,11 +39,7 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index f3a0fba7cd..fc5c86b4d6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -38,11 +38,7 @@ uniform float minimum_alpha; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl index e16ae4844d..1bb8eb8bd0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl @@ -38,11 +38,7 @@ uniform sampler2D diffuseMap; VARYING vec3 vary_normal; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index d8b980c402..8319e61242 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -37,11 +37,7 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 04ec35b308..828c325c9d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -35,12 +35,7 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index e1b582c08c..d14805eccf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -441,22 +441,8 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec2 encode_normal(vec3 n); +vec3 decode_normal (vec2 enc); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 9974f8f31b..d1ac19270d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -57,22 +57,7 @@ uniform float far_z; uniform mat4 inv_proj; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index eeb2fe39cc..1d75322b4c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -72,17 +72,7 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} - +vec3 decode_normal (vec2 enc); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 4f02365f45..13b803e03e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -56,16 +56,7 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 0703f75d60..5983d74cbc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -87,17 +87,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 getPosition_d(vec2 pos_screen, float depth) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 88e79a8c46..2b6428963d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -70,17 +70,7 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} - +vec3 decode_normal (vec2 enc); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 3a31173fab..403df87853 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -51,16 +51,7 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 597fef486e..0cd90b0d97 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -41,11 +41,7 @@ VARYING vec3 vary_normal; VARYING vec4 vary_texcoord0; VARYING vec4 vary_texcoord1; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index 3cd791920d..89e354558a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -39,11 +39,7 @@ VARYING vec2 vary_texcoord0; uniform float minimum_alpha; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index 5e676b23f0..3a8565ee38 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -61,11 +61,7 @@ VARYING vec4 view; vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); vec4 applyWaterFog(vec4 color, vec3 viewVec) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 99c84c67e9..b321eb508b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -70,12 +70,7 @@ VARYING vec4 view; VARYING vec4 vary_position; vec3 srgb_to_linear(vec3 cs); - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} +vec2 encode_normal(vec3 n); void main() { diff --git a/indra/newview/app_settings/shaders/class1/environment/decodeNorm.glsl b/indra/newview/app_settings/shaders/class1/environment/decodeNorm.glsl deleted file mode 100644 index 0abb1e43db..0000000000 --- a/indra/newview/app_settings/shaders/class1/environment/decodeNorm.glsl +++ /dev/null @@ -1,11 +0,0 @@ -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} - diff --git a/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl b/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl new file mode 100644 index 0000000000..0abb1e43db --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl @@ -0,0 +1,11 @@ +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + diff --git a/indra/newview/app_settings/shaders/class1/environment/encodeNorm.glsl b/indra/newview/app_settings/shaders/class1/environment/encodeNorm.glsl deleted file mode 100644 index ee21715c1d..0000000000 --- a/indra/newview/app_settings/shaders/class1/environment/encodeNorm.glsl +++ /dev/null @@ -1,7 +0,0 @@ - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - diff --git a/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl b/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl new file mode 100644 index 0000000000..ee21715c1d --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl @@ -0,0 +1,7 @@ + +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index ac7329e3eb..864ba4859d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -73,23 +73,7 @@ uniform mat4 inv_proj; vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 9912f30731..fc69f6a69c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -82,23 +82,7 @@ uniform vec2 screen_res; vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 getPosition_d(vec2 pos_screen, float depth) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 440f4aa157..a7da140b31 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -71,23 +71,7 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} - +vec3 decode_normal (vec2 enc); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index 265da8df99..aa5e99a2f7 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -67,22 +67,7 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 5c6fe30daa..58f3f2f91e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -68,22 +68,7 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen) { -- cgit v1.2.3 From d992cff950d69b6935171fae1c304d15ee06e95a Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 12 Mar 2018 18:11:39 +0100 Subject: Fix decl mismatch in alpha shader and mark deferred shaders needing new linkage so ALM works again. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 47dadb4ced..970f39ed02 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -104,7 +104,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); -vec3 encode_normal (vec2 enc); +vec2 encode_normal (vec3 n); vec3 decode_normal (vec2 enc); vec3 calcDirectionalLight(vec3 n, vec3 l) -- cgit v1.2.3 From 4f6682ca29cefb83ac2307657d8605f96051da19 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 12 Mar 2018 22:26:22 +0100 Subject: De-duplicate deferred shader code for atmospherics and transport. --- .../shaders/class1/deferred/alphaF.glsl | 225 ++---------------- .../shaders/class1/deferred/materialF.glsl | 235 ++----------------- .../shaders/class1/deferred/softenLightF.glsl | 235 ++----------------- .../shaders/class1/windlight/atmosphericsF.glsl | 5 + .../shaders/class2/deferred/softenLightF.glsl | 260 ++------------------- .../shaders/class2/windlight/atmosphericsF.glsl | 122 +++++++++- .../class2/windlight/atmosphericsHelpersF.glsl | 49 ++++ .../shaders/class2/windlight/gammaF.glsl | 7 +- .../shaders/class2/windlight/transportF.glsl | 25 +- 9 files changed, 258 insertions(+), 905 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 970f39ed02..2234ceeb53 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -39,19 +39,6 @@ out vec4 frag_color; uniform float display_gamma; uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 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 vec4 glow; -uniform float scene_light_strength; uniform mat3 env_mat; uniform mat3 ssao_effect_mat; @@ -84,12 +71,6 @@ VARYING vec3 vary_norm; VARYING vec4 vertex_color; #endif -vec3 vary_PositionEye; -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - uniform mat4 inv_proj; uniform vec2 screen_res; @@ -107,6 +88,12 @@ vec3 linear_to_srgb(vec3 cl); vec2 encode_normal (vec3 n); vec3 decode_normal (vec2 enc); +vec3 scaleFragSoftClip(vec3 l); +vec3 atmosFragAmbient(vec3 light, vec3 sunlit); +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); + vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); @@ -174,191 +161,6 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc) } #endif -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(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 - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); - vec3 ones = vec3(1.0f, 1.0f, 1.0f); - - light = ones - clamp(light, zeroes, ones); - light = ones - pow(light, gamma.xxx); - - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} void main() { @@ -475,7 +277,12 @@ void main() vec3 norm = vary_norm; - calcAtmospherics(pos.xyz, 1.0); + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); vec2 abnormal = encode_normal(norm.xyz); norm.xyz = decode_normal(abnormal.xy); @@ -490,7 +297,7 @@ void main() vec4 color = vec4(0,0,0,0); - color.rgb = atmosAmbient(color.rgb); + color.rgb = atmosFragAmbient(color.rgb, amblit); color.a = final_alpha; float ambient = abs(da); @@ -499,13 +306,13 @@ void main() ambient = (1.0-ambient); color.rgb *= ambient; - color.rgb += atmosAffectDirectionalLight(final_da); + color.rgb += atmosFragAffectDirectionalLight(final_da, sunlit); color.rgb *= gamma_diff.rgb; //color.rgb = mix(diff.rgb, color.rgb, final_alpha); - color.rgb = atmosLighting(color.rgb); - color.rgb = scaleSoftClip(color.rgb); + color.rgb = atmosFragLighting(color.rgb, additive, atten); + color.rgb = scaleFragSoftClip(color.rgb); vec4 light = vec4(0,0,0,0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d14805eccf..a90e433622 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -40,6 +40,12 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); +vec3 atmosFragAmbient(vec3 l, vec3 ambient); +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleFragSoftClip(vec3 l); +vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); + #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #ifdef DEFINE_GL_FRAGCOLOR @@ -88,19 +94,6 @@ uniform vec4 morphFactor; uniform vec3 camPosLocal; //uniform vec4 camPosWorld; uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 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 vec4 glow; -uniform float scene_light_strength; uniform mat3 env_mat; uniform mat3 ssao_effect_mat; @@ -109,13 +102,6 @@ VARYING vec2 vary_fragcoord; VARYING vec3 vary_position; -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - uniform mat4 inv_proj; uniform vec2 screen_res; @@ -209,198 +195,6 @@ vec4 getPosition_d(vec2 pos_screen, float depth) return pos; } -#ifndef WATER_FOG -vec3 getPositionEye() -{ - return vary_PositionEye; -} -#endif - -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(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 - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); - vec3 ones = vec3(1.0f, 1.0f, 1.0f); - - light = ones - clamp(light, zeroes, ones); - light = ones - pow(light, gamma.xxx); - - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} #else #ifdef DEFINE_GL_FRAGCOLOR @@ -585,7 +379,12 @@ void main() vec3 col = vec3(0.0f,0.0f,0.0f); float bloom = 0.0; - calcAtmospherics(pos.xyz, 1.0); + 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)); @@ -598,7 +397,7 @@ void main() final_da = min(final_da, 1.0f); final_da = pow(final_da, 1.0/1.3); - col.rgb = atmosAmbient(col); + col.rgb = atmosFragAmbient(col, amblit); float ambient = min(abs(da), 1.0); ambient *= 0.5; @@ -607,7 +406,7 @@ void main() col.rgb *= ambient; - col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); + col.rgb = col.rgb + atmosFragAffectDirectionalLight(final_da, sunlit); col.rgb *= gamma_diff.rgb; @@ -620,7 +419,7 @@ void main() // float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); + vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; @@ -654,8 +453,8 @@ void main() //col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - col = atmosLighting(col); - col = scaleSoftClip(col); + col = atmosFragLighting(col, additive, atten); + col = scaleFragSoftClip(col); //convert to linear space before adding local lights col = srgb_to_linear(col); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 5983d74cbc..fbfd43a4da 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -51,33 +51,13 @@ uniform vec4 morphFactor; uniform vec3 camPosLocal; //uniform vec4 camPosWorld; uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 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 vec4 glow; uniform float global_gamma; -uniform float scene_light_strength; uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; VARYING vec2 vary_fragcoord; -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - uniform mat4 inv_proj; uniform vec2 screen_res; @@ -89,6 +69,15 @@ vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); +vec3 atmosFragAmbient(vec3 l, vec3 ambient); +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleFragSoftClip(vec3 l); +vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); +vec3 fullbrightFragAtmosTransport(vec3 l, vec3 additive, vec3 atten); +vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 atten); + +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); + vec4 getPosition_d(vec2 pos_screen, float depth) { vec2 sc = pos_screen.xy*2.0; @@ -107,196 +96,6 @@ vec4 getPosition(vec2 pos_screen) return getPosition_d(pos_screen, depth); } -vec3 getPositionEye() -{ - return vary_PositionEye; -} -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(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 - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - - - -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / scene_light_strength ); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * scene_light_strength); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + light / 2.0; -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * lightIntensity; -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} - - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} void main() { @@ -324,9 +123,13 @@ void main() vec3 col; float bloom = 0.0; { - calcAtmospherics(pos.xyz, 1.0); + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - col = atmosAmbient(vec3(0)); + col = atmosFragAmbient(vec3(0), amblit); float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; @@ -334,7 +137,7 @@ void main() col.rgb *= ambient; - col += atmosAffectDirectionalLight(final_da); + col += atmosFragAffectDirectionalLight(final_da, sunlit); col *= diffuse.rgb; @@ -346,7 +149,7 @@ void main() // float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); + vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; @@ -370,8 +173,8 @@ void main() if (norm.w < 0.5) { - col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + col = mix(atmosFragLighting(col, additive, atten), fullbrightFragAtmosTransport(col, atten, additive), diffuse.a); + col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a); } #ifdef WATER_FOG diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl index aacc503e13..584bd568c5 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl @@ -31,3 +31,8 @@ vec3 atmosLighting(vec3 light) return light; } + +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor) { + /* stub function for fallback compatibility on class1 hardware */ +} + diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index fc69f6a69c..c20092bfe0 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -70,13 +70,6 @@ uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; VARYING vec2 vary_fragcoord; -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - uniform mat4 inv_proj; uniform vec2 screen_res; @@ -84,6 +77,12 @@ vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); +vec3 atmosFragAmbient(vec3 l, vec3 ambient); +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleFragSoftClip(vec3 l); +vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); + vec4 getPosition_d(vec2 pos_screen, float depth) { vec2 sc = pos_screen.xy*2.0; @@ -102,243 +101,11 @@ vec4 getPosition(vec2 pos_screen) return getPosition_d(pos_screen, depth); } -vec3 getPositionEye() -{ - return vary_PositionEye; -} -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(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 - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); -} #ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - float es = -(dot(view, waterPlane.xyz)); - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; -} +vec4 applyWaterFogDeferred(vec3 pos, vec4 color); #endif -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - - - -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / scene_light_strength ); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * scene_light_strength); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + light / 2.0; -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * lightIntensity; -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} - - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} - void main() { vec2 tc = vary_fragcoord.xy; @@ -372,8 +139,13 @@ void main() float ambocc = scol_ambocc.g; + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; - calcAtmospherics(pos.xyz, ambocc); + calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); col = atmosAmbient(vec3(0)); float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); @@ -383,7 +155,7 @@ void main() col.rgb *= ambient; - col += atmosAffectDirectionalLight(max(min(da, scol), 0.0)); + col += atmosFragAffectDirectionalLight(max(min(da, scol), 0.0), sunlit); col *= diffuse.rgb; @@ -419,8 +191,8 @@ void main() if (norm.w < 0.5) { - col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + col = mix(atmosFragLighting(col, additive, atten), fullbrightFragAtmosTransport(col, atten, additive), diffuse.a); + col = mix(scaleFragSoftClip(col), fullbrightFragScaleSoftClip(col), diffuse.a); } #ifdef WATER_FOG diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index fea3cbf69b..fee1a7f311 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -22,23 +22,127 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - - - -////////////////////////////////////////////////////////// -// The fragment shader for the terrain atmospherics -////////////////////////////////////////////////////////// vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); uniform sampler2D cloudMap; +uniform vec4 gamma; uniform vec4 cloud_pos_density1; +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 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 vec4 glow; +uniform float scene_light_strength; +uniform mat3 ssao_effect_mat; -vec3 atmosLighting(vec3 light) +vec3 scaleFragSoftClip(vec3 light) +{ + //soft clip effect: + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, gamma.xxx); + return light; +} + +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); + light *= atten.r; + light += additive; return (2.0 * light); } +vec3 atmosLighting(vec3 light) +{ + return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); +} + +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { + + vec3 P = inPositionEye; + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(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 + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + atten = temp1.rgb; + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + additive = + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient)); + + //brightness of surface both sunlight and ambient + sunlit = vec3(sunlight * .5); + amblit = vec3(tmpAmbient * .25); + additive *= vec3(1.0 - temp1); +} + diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl new file mode 100644 index 0000000000..3582759e62 --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl @@ -0,0 +1,49 @@ +/** + * @file atmosphericsHelpersV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +// Output variables + +uniform float scene_light_strength; + +vec3 atmosFragAmbient(vec3 light, vec3 amblit) +{ + return amblit + light / 2.0; +} + +vec3 atmosFragAffectDirectionalLight(float lightIntensity, vec3 sunlit) +{ + return sunlit * lightIntensity; +} + +vec3 scaleDownLightFrag(vec3 light) +{ + return (light / scene_light_strength ); +} + +vec3 scaleUpLightFrag(vec3 light) +{ + return (light * scene_light_strength); +} + diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index 478373d729..2db633cd01 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -38,7 +38,12 @@ vec3 scaleSoftClip(vec3 light) { return light; } +vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 atten) +{ + return mix(scaleSoftClip(light.rgb), light.rgb, atten); +} + vec3 fullbrightScaleSoftClip(vec3 light) { - return mix(scaleSoftClip(light.rgb), light.rgb, getAtmosAttenuation()); + return fullbrightScaleSoftClipFrag(light.rgb, getAtmosAttenuation()); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 8a8e4cb0f6..82e1d7fe35 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -33,21 +33,30 @@ vec3 getAtmosAttenuation(); uniform sampler2D cloudMap; uniform vec4 cloud_pos_density1; -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; +vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { + light *= atten.r; + light += additive * 2.0; return light; } -vec3 fullbrightAtmosTransport(vec3 light) { +vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); + return mix(atmosFragTransport(light.rgb, atten, additive), light.rgb + additive.rgb, brightness * brightness); } -vec3 fullbrightShinyAtmosTransport(vec3 light) { +vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) { float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosFragTransport(light.rgb, atten, additive), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); +} - return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness); +vec3 atmosTransport(vec3 light) { + return atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); } +vec3 fullbrightAtmosTransport(vec3 light) { + return fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} + +vec3 fullbrightShinyAtmosTransport(vec3 light) { + return fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} -- cgit v1.2.3 From 6bcbc8b553e85d5debe75b08081fb033cf2eacc0 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Mon, 12 Mar 2018 22:43:52 +0100 Subject: Add new shader files missed in last commit. --- .../class1/windlight/atmosphericsHelpersF.glsl | 55 ++++++++ .../shaders/class3/windlight/atmosphericsF.glsl | 148 +++++++++++++++++++++ .../shaders/class3/windlight/atmosphericsV.glsl | 133 ++++++++++++++++++ 3 files changed, 336 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl new file mode 100644 index 0000000000..3f70a8935b --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl @@ -0,0 +1,55 @@ +/** + * @file atmosphericsHelpersF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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 vec4 sunlight_color; +uniform vec4 light_ambient; + +vec3 atmosAmbient(vec3 light) +{ + return light + light_ambient.rgb; +} + +vec3 atmosAffectDirectionalLight(float lightIntensity) +{ + return sunlight_color.rgb * lightIntensity; +} + +vec3 atmosGetDiffuseSunlightColor() +{ + return sunlight_color.rgb; +} + +vec3 scaleDownLight(vec3 light) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + +vec3 scaleUpLight(vec3 light) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl new file mode 100644 index 0000000000..db8ec71b35 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl @@ -0,0 +1,148 @@ +/** + * @file atmosphericsF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 sampler2D cloudMap; +uniform vec4 cloud_pos_density1; +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 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 vec4 glow; +uniform float scene_light_strength; +uniform mat3 ssao_effect_mat; + +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); +void setPositionEye(vec3); +vec3 getPositionEye(); +vec3 getSunlitColor(); +vec3 getAmblitColor(); +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); +void setPositionEye(vec3 v); +void setSunlitColor(vec3 v); +void setAmblitColor(vec3 v); +void setAdditiveColor(vec3 v); +void setAtmosAttenuation(vec3 v); + +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor) { + + vec3 P = inPositionEye; + setPositionEye(P); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(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 + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + setAtmosAttenuation(temp1.rgb); + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + setAdditiveColor( + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient))); + + //brightness of surface both sunlight and ambient + setSunlitColor(vec3(sunlight * .5)); + setAmblitColor(vec3(tmpAmbient * .25)); + setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); +} + +vec3 atmosLighting(vec3 light) +{ + light *= getAtmosAttenuation().r; + light += getAdditiveColor(); + return (2.0 * light); +} diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl new file mode 100644 index 0000000000..c064023858 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl @@ -0,0 +1,133 @@ +/** + * @file atmosphericsV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +// VARYING param funcs +void setSunlitColor(vec3 v); +void setAmblitColor(vec3 v); +void setAdditiveColor(vec3 v); +void setAtmosAttenuation(vec3 v); +void setPositionEye(vec3 v); + +vec3 getAdditiveColor(); + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; + +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 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 vec4 glow; + +void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + + vec3 P = inPositionEye; + setPositionEye(P); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(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 + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + setAtmosAttenuation(temp1.rgb); + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + setAdditiveColor( + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient))); + + //brightness of surface both sunlight and ambient + setSunlitColor(vec3(sunlight * .5)); + setAmblitColor(vec3(tmpAmbient * .25)); + setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); +} -- cgit v1.2.3 From 79e4a8c28ad29b028ddb907a6ea01f4ef71e822a Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Wed, 14 Mar 2018 00:11:19 +0100 Subject: Fix up atmospheric helpers and transport shader for adv atmo path. Basic hook-up of sky settings to llatmosphere model. Moved mie aniso to be a top-level setting instead of a per-mie-layer setting. --- .../shaders/class3/windlight/atmosphericsF.glsl | 62 +++++++++++----------- .../shaders/class3/windlight/atmosphericsV.glsl | 4 +- .../shaders/class3/windlight/skyF.glsl | 6 +-- .../shaders/class3/windlight/transportF.glsl | 25 ++++++--- 4 files changed, 53 insertions(+), 44 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl index db8ec71b35..fee1a7f311 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl @@ -22,9 +22,12 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); uniform sampler2D cloudMap; +uniform vec4 gamma; uniform vec4 cloud_pos_density1; uniform vec4 lightnorm; uniform vec4 sunlight_color; @@ -41,26 +44,29 @@ uniform vec4 glow; uniform float scene_light_strength; uniform mat3 ssao_effect_mat; -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); -void setPositionEye(vec3); -vec3 getPositionEye(); -vec3 getSunlitColor(); -vec3 getAmblitColor(); -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); -void setPositionEye(vec3 v); -void setSunlitColor(vec3 v); -void setAmblitColor(vec3 v); -void setAdditiveColor(vec3 v); -void setAtmosAttenuation(vec3 v); +vec3 scaleFragSoftClip(vec3 light) +{ + //soft clip effect: + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, gamma.xxx); + return light; +} -void calcFragAtmospherics(vec3 inPositionEye, float ambFactor) { +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) +{ + light *= atten.r; + light += additive; + return (2.0 * light); +} + +vec3 atmosLighting(vec3 light) +{ + return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); +} + +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { vec3 P = inPositionEye; - setPositionEye(P); vec3 tmpLightnorm = lightnorm.xyz; @@ -98,7 +104,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor) { temp1 = exp(-temp1 * temp2.z * distance_multiplier); //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); + atten = temp1.rgb; //compute haze glow //(can use temp2.x as temp because we haven't used it yet) @@ -129,20 +135,14 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor) { tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); //haze color - setAdditiveColor( + additive = vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient)); //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); + sunlit = vec3(sunlight * .5); + amblit = vec3(tmpAmbient * .25); + additive *= vec3(1.0 - temp1); } -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl index c064023858..3270c243a4 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl @@ -49,7 +49,7 @@ uniform float distance_multiplier; uniform float max_y; uniform vec4 glow; -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { +void calcAtmospherics(vec3 inPositionEye) { vec3 P = inPositionEye; setPositionEye(P); @@ -118,7 +118,7 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + //tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); //haze color setAdditiveColor( diff --git a/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl index c71eaf4b13..08b6ec3f97 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl @@ -49,16 +49,16 @@ void main() { vec3 view_direction = normalize(view_dir); - vec3 camPos = cameraPosLocal; + vec3 camPos = cameraPosLocal + vec3(0, 0, 6360.0f); vec3 transmittance; vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); - radiance *= transmittance; + //radiance *= transmittance; // If the view ray intersects the Sun, add the Sun radiance. if (dot(view_direction, sun_direction) >= sun_size.y) { - radiance = radiance + transmittance * GetSolarLuminance(); + radiance = radiance + (transmittance * GetSolarLuminance()); } vec3 color = vec3(1.0) - exp(-radiance); diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index 8a8e4cb0f6..82e1d7fe35 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -33,21 +33,30 @@ vec3 getAtmosAttenuation(); uniform sampler2D cloudMap; uniform vec4 cloud_pos_density1; -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; +vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { + light *= atten.r; + light += additive * 2.0; return light; } -vec3 fullbrightAtmosTransport(vec3 light) { +vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); + return mix(atmosFragTransport(light.rgb, atten, additive), light.rgb + additive.rgb, brightness * brightness); } -vec3 fullbrightShinyAtmosTransport(vec3 light) { +vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) { float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosFragTransport(light.rgb, atten, additive), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); +} - return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness); +vec3 atmosTransport(vec3 light) { + return atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); } +vec3 fullbrightAtmosTransport(vec3 light) { + return fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} + +vec3 fullbrightShinyAtmosTransport(vec3 light) { + return fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +} -- cgit v1.2.3 From 0d7fa932d579f3fb6140658db7efb01fcd8f5ceb Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Fri, 20 Apr 2018 18:14:29 +0100 Subject: Move class3 sky/cloud shaders to where they need to be to get picked up by ALM. Modify autobuild.xml to use new libatmo w/ state save/restore fixes (addresses font render glitch). Put in nSight debug support. --- .../app_settings/shaders/class1/deferred/skyF.glsl | 2 +- .../shaders/class2/windlight/skyF.glsl | 2 +- .../shaders/class3/deferred/cloudsF.glsl | 104 +++++++++++ .../shaders/class3/deferred/cloudsV.glsl | 190 +++++++++++++++++++++ .../app_settings/shaders/class3/deferred/skyF.glsl | 69 ++++++++ .../app_settings/shaders/class3/deferred/skyV.glsl | 43 +++++ .../shaders/class3/windlight/cloudsF.glsl | 104 ----------- .../shaders/class3/windlight/cloudsV.glsl | 190 --------------------- .../shaders/class3/windlight/skyF.glsl | 71 -------- .../shaders/class3/windlight/skyV.glsl | 43 ----- 10 files changed, 408 insertions(+), 410 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/skyF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/skyV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/windlight/cloudsF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/windlight/cloudsV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/windlight/skyF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/windlight/skyV.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 46bf718270..4511237e4d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -1,5 +1,5 @@ /** - * @file WLSkyF.glsl + * @file class1/deferred/skyF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl index e2a2367626..2a0ca35278 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl @@ -1,5 +1,5 @@ /** - * @file WLSkyF.glsl + * @file class2/windlight/skyF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl new file mode 100644 index 0000000000..96c70651b1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -0,0 +1,104 @@ +/** + * @file WLCloudsF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +///////////////////////////////////////////////////////////////////////// +// The fragment shader for the sky +///////////////////////////////////////////////////////////////////////// + +VARYING vec4 vary_CloudColorSun; +VARYING vec4 vary_CloudColorAmbient; +VARYING float vary_CloudDensity; +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; + +uniform sampler2D cloud_noise_texture; +uniform vec4 cloud_pos_density1; +uniform vec4 cloud_pos_density2; +uniform vec4 gamma; + +/// Soft clips the light with a gamma correction +vec3 scaleSoftClip(vec3 light) { + //soft clip effect: + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, gamma.xxx); + + return light; +} + +void main() +{ + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + + vec4 cloudColorSun = vary_CloudColorSun; + vec4 cloudColorAmbient = vary_CloudColorAmbient; + float cloudDensity = vary_CloudDensity; + vec2 uv3 = vary_texcoord2.xy; + vec2 uv4 = vary_texcoord3.xy; + + // Offset texture coords + uv1 += cloud_pos_density1.xy; //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow + + + // Compute alpha1, the main cloud opacity + float alpha1 = (texture2D(cloud_noise_texture, uv1).x - 0.5) + (texture2D(cloud_noise_texture, uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.); + + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; + + + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (texture2D(cloud_noise_texture, uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; + + // Combine + vec4 color; + color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); + color *= 2.; + + /// Gamma correct for WL (soft clip effect). + frag_color.rgb = scaleSoftClip(color.rgb); + frag_color.a = alpha1; +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl new file mode 100644 index 0000000000..c1dd45cd67 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl @@ -0,0 +1,190 @@ +/** + * @file WLCloudsV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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 mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +////////////////////////////////////////////////////////////////////////// +// The vertex shader for creating the atmospheric sky +/////////////////////////////////////////////////////////////////////////////// + +// Output parameters +VARYING vec4 vary_CloudColorSun; +VARYING vec4 vary_CloudColorAmbient; +VARYING float vary_CloudDensity; +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; + +// Inputs +uniform vec3 camPosLocal; + +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; + +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float max_y; + +uniform vec4 glow; + +uniform vec4 cloud_color; + +uniform float cloud_scale; + +void main() +{ + + // World / view / projection + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + + vary_texcoord0 = texcoord0; + + // Get relative position + vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); + + // Set altitude + if (P.y > 0.) + { + P *= (max_y / P.y); + } + else + { + P *= (-32000. / P.y); + } + + // Can normalize then + vec3 Pn = normalize(P); + float Plen = length(P); + + // Initialize temp variables + vec4 temp1 = vec4(0.); + vec4 temp2 = vec4(0.); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + + // Calculate relative weights + temp1 = blue_density + haze_density; + blue_weight = blue_density / temp1; + haze_weight = haze_density / temp1; + + // Compute sunlight from P & lightnorm (for long rays like sky) + temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Distance + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z); + + + // Compute haze glow + temp2.x = dot(Pn, lightnorm.xyz); + temp2.x = 1. - temp2.x; + // temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .001); + // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + // Higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + // Add "minimum anti-solar illumination" + temp2.x += .25; + + // Increase ambient when there are more clouds + vec4 tmpAmbient = ambient; + tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + + // Dim sunlight by cloud shadow percentage + sunlight *= (1. - cloud_shadow); + + // Haze color below cloud + vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) + ); + + // CLOUDS + + sunlight = sunlight_color; + temp2.y = max(0., lightnorm.y * 2.); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Cloud color out + vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; + vary_CloudColorAmbient = tmpAmbient * cloud_color; + + // Attenuate cloud color by atmosphere + temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds + vary_CloudColorSun *= temp1; + vary_CloudColorAmbient *= temp1; + vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); + + // Make a nice cloud density based on the cloud_shadow value that was passed in. + vary_CloudDensity = 2. * (cloud_shadow - 0.25); + + + // Texture coords + vary_texcoord0 = texcoord0; + vary_texcoord0.xy -= 0.5; + vary_texcoord0.xy /= cloud_scale; + vary_texcoord0.xy += 0.5; + + vary_texcoord1 = vary_texcoord0; + vary_texcoord1.x += lightnorm.x * 0.0125; + vary_texcoord1.y += lightnorm.z * 0.0125; + + vary_texcoord2 = vary_texcoord0 * 16.; + vary_texcoord3 = vary_texcoord1 * 16.; + + // Combine these to minimize register use + vary_CloudColorAmbient += oHazeColorBelowCloud; + + // needs this to compile on mac + //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); + + // END CLOUDS +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl new file mode 100644 index 0000000000..0223f94e55 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -0,0 +1,69 @@ +/** + * @file advancedAtmoF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +in vec3 view_dir; + +uniform vec3 cameraPosLocal; +uniform vec3 sun_direction; +uniform vec2 sun_size; + +uniform sampler2D cloud_noise_texture; +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D single_mie_scattering_texture; +uniform sampler2D irradiance_texture; + +vec3 GetSolarLuminance(); +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 sun_dir, out vec3 transmittance); +vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 sun_dir, out vec3 transmittance); +vec3 GetSunAndSkyIlluminance(vec3 pos, vec3 norm, vec3 sun_dir, out vec3 sky_irradiance); + +void main() +{ + vec3 view_direction = normalize(view_dir); + + vec3 camPos = cameraPosLocal + vec3(0, 0, 6360.0f); + vec3 transmittance; + vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); + + // If the view ray intersects the Sun, add the Sun radiance. + if (dot(view_direction, sun_direction) >= sun_size.y) + { + radiance = radiance + (transmittance * GetSolarLuminance()); + } + + vec3 color = vec3(1.0) - exp(-radiance); + color = pow(color, vec3(1.0 / 2.2)); + + frag_color.rgb = color; + frag_color.a = 1.0; +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl new file mode 100644 index 0000000000..52a7595379 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl @@ -0,0 +1,43 @@ +/** + * @file advancedAtmoV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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 mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + +// Inputs +uniform vec3 camPosLocal; + +out vec3 view_dir; + +void main() +{ + // World / view / projection + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + + // this will be normalized in the frag shader... + view_dir = position.xyz - camPosLocal.xyz; +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/cloudsF.glsl deleted file mode 100644 index 96c70651b1..0000000000 --- a/indra/newview/app_settings/shaders/class3/windlight/cloudsF.glsl +++ /dev/null @@ -1,104 +0,0 @@ -/** - * @file WLCloudsF.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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$ - */ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -///////////////////////////////////////////////////////////////////////// -// The fragment shader for the sky -///////////////////////////////////////////////////////////////////////// - -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; -VARYING float vary_CloudDensity; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; - -uniform sampler2D cloud_noise_texture; -uniform vec4 cloud_pos_density1; -uniform vec4 cloud_pos_density2; -uniform vec4 gamma; - -/// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light) { - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} - -void main() -{ - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; - - vec4 cloudColorSun = vary_CloudColorSun; - vec4 cloudColorAmbient = vary_CloudColorAmbient; - float cloudDensity = vary_CloudDensity; - vec2 uv3 = vary_texcoord2.xy; - vec2 uv4 = vary_texcoord3.xy; - - // Offset texture coords - uv1 += cloud_pos_density1.xy; //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow - - - // Compute alpha1, the main cloud opacity - float alpha1 = (texture2D(cloud_noise_texture, uv1).x - 0.5) + (texture2D(cloud_noise_texture, uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.); - - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; - - - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (texture2D(cloud_noise_texture, uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; - - // Combine - vec4 color; - color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); - color *= 2.; - - /// Gamma correct for WL (soft clip effect). - frag_color.rgb = scaleSoftClip(color.rgb); - frag_color.a = alpha1; -} - diff --git a/indra/newview/app_settings/shaders/class3/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class3/windlight/cloudsV.glsl deleted file mode 100644 index c1dd45cd67..0000000000 --- a/indra/newview/app_settings/shaders/class3/windlight/cloudsV.glsl +++ /dev/null @@ -1,190 +0,0 @@ -/** - * @file WLCloudsV.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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 mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; - -////////////////////////////////////////////////////////////////////////// -// The vertex shader for creating the atmospheric sky -/////////////////////////////////////////////////////////////////////////////// - -// Output parameters -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; -VARYING float vary_CloudDensity; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; - -// Inputs -uniform vec3 camPosLocal; - -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; - -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float max_y; - -uniform vec4 glow; - -uniform vec4 cloud_color; - -uniform float cloud_scale; - -void main() -{ - - // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - - vary_texcoord0 = texcoord0; - - // Get relative position - vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); - - // Set altitude - if (P.y > 0.) - { - P *= (max_y / P.y); - } - else - { - P *= (-32000. / P.y); - } - - // Can normalize then - vec3 Pn = normalize(P); - float Plen = length(P); - - // Initialize temp variables - vec4 temp1 = vec4(0.); - vec4 temp2 = vec4(0.); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - - // Calculate relative weights - temp1 = blue_density + haze_density; - blue_weight = blue_density / temp1; - haze_weight = haze_density / temp1; - - // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Distance - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); - - - // Compute haze glow - temp2.x = dot(Pn, lightnorm.xyz); - temp2.x = 1. - temp2.x; - // temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .001); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // Add "minimum anti-solar illumination" - temp2.x += .25; - - // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; - - // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); - - // Haze color below cloud - vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) - ); - - // CLOUDS - - sunlight = sunlight_color; - temp2.y = max(0., lightnorm.y * 2.); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Cloud color out - vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; - vary_CloudColorAmbient = tmpAmbient * cloud_color; - - // Attenuate cloud color by atmosphere - temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds - vary_CloudColorSun *= temp1; - vary_CloudColorAmbient *= temp1; - vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); - - // Make a nice cloud density based on the cloud_shadow value that was passed in. - vary_CloudDensity = 2. * (cloud_shadow - 0.25); - - - // Texture coords - vary_texcoord0 = texcoord0; - vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; - vary_texcoord0.xy += 0.5; - - vary_texcoord1 = vary_texcoord0; - vary_texcoord1.x += lightnorm.x * 0.0125; - vary_texcoord1.y += lightnorm.z * 0.0125; - - vary_texcoord2 = vary_texcoord0 * 16.; - vary_texcoord3 = vary_texcoord1 * 16.; - - // Combine these to minimize register use - vary_CloudColorAmbient += oHazeColorBelowCloud; - - // needs this to compile on mac - //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); - - // END CLOUDS -} - diff --git a/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl deleted file mode 100644 index 08b6ec3f97..0000000000 --- a/indra/newview/app_settings/shaders/class3/windlight/skyF.glsl +++ /dev/null @@ -1,71 +0,0 @@ -/** - * @file advancedAtmoF.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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$ - */ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -in vec3 view_dir; - -uniform vec3 cameraPosLocal; -uniform vec3 sun_direction; -uniform vec2 sun_size; - -uniform sampler2D cloud_noise_texture; -uniform sampler2D transmittance_texture; -uniform sampler3D scattering_texture; -uniform sampler3D mie_scattering_texture; - -vec3 GetSolarLuminance(); -vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 sun_dir, out vec3 transmittance); -vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 sun_dir, out vec3 transmittance); -vec3 GetSunAndSkyIlluminance(vec3 pos, vec3 norm, vec3 sun_dir, out vec3 sky_irradiance); - -void main() -{ - vec3 view_direction = normalize(view_dir); - - vec3 camPos = cameraPosLocal + vec3(0, 0, 6360.0f); - vec3 transmittance; - vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); - - //radiance *= transmittance; - - // If the view ray intersects the Sun, add the Sun radiance. - if (dot(view_direction, sun_direction) >= sun_size.y) - { - radiance = radiance + (transmittance * GetSolarLuminance()); - } - - vec3 color = vec3(1.0) - exp(-radiance); - color = pow(color, vec3(1.0 / 2.2)); - - frag_color.rgb = color; - - frag_color.a = 1.0; -} - diff --git a/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl deleted file mode 100644 index 52a7595379..0000000000 --- a/indra/newview/app_settings/shaders/class3/windlight/skyV.glsl +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @file advancedAtmoV.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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 mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; - -// Inputs -uniform vec3 camPosLocal; - -out vec3 view_dir; - -void main() -{ - // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - - // this will be normalized in the frag shader... - view_dir = position.xyz - camPosLocal.xyz; -} - -- cgit v1.2.3 From 3116416fcb8dfd54ef2807e9e75959429c946d79 Mon Sep 17 00:00:00 2001 From: "Graham Linden graham@lindenlab.com" Date: Tue, 1 May 2018 00:10:11 +0100 Subject: Le Merge --- .../app_settings/shaders/class3/deferred/skyF.glsl | 28 +++++++++++++++++----- .../app_settings/shaders/class3/deferred/skyV.glsl | 14 ++++++++--- .../shaders/class3/windlight/advancedAtmoF.glsl | 17 +++++++------ 3 files changed, 43 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index 0223f94e55..5185a9f8f4 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -29,11 +29,12 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif +in vec3 view_pos; in vec3 view_dir; uniform vec3 cameraPosLocal; -uniform vec3 sun_direction; -uniform vec2 sun_size; +uniform vec3 sun_dir; +uniform float sun_size; uniform sampler2D cloud_noise_texture; uniform sampler2D transmittance_texture; @@ -50,20 +51,35 @@ void main() { vec3 view_direction = normalize(view_dir); + vec3 sun_direction = sun_dir; + vec3 camPos = cameraPosLocal + vec3(0, 0, 6360.0f); vec3 transmittance; + vec3 sky_illum; vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); + vec3 radiance2 = GetSunAndSkyIlluminance(camPos, view_direction, sun_direction, sky_illum); + + radiance *= transmittance; + + vec3 solar_luminance = transmittance * GetSolarLuminance(); // If the view ray intersects the Sun, add the Sun radiance. - if (dot(view_direction, sun_direction) >= sun_size.y) + if (dot(view_direction, sun_direction) >= sun_size) { - radiance = radiance + (transmittance * GetSolarLuminance()); + radiance = radiance + solar_luminance; } - vec3 color = vec3(1.0) - exp(-radiance); - color = pow(color, vec3(1.0 / 2.2)); + vec3 color = radiance; + + color = vec3(1.0) - exp(-color * 0.0001); + + //float d = dot(view_direction, sun_direction); + //frag_color.rgb = vec3(d, d >= sun_size ? 1.0f : 0.0f, 0.0f); frag_color.rgb = color; + //frag_color.rgb = vec3(dot(view_direction, sun_direction) > 0.95f ? 1.0 : 0.0, 0,0); + frag_color.rgb = normalize(view_pos); + frag_color.a = 1.0; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl index 52a7595379..cf3eb658fc 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl @@ -23,21 +23,29 @@ * $/LicenseInfo$ */ +uniform vec3 cameraPosLocal; uniform mat4 modelview_projection_matrix; +uniform mat4 modelview_matrix; +uniform mat4 inv_proj; +uniform mat4 inv_modelview; ATTRIBUTE vec3 position; // Inputs uniform vec3 camPosLocal; +out vec3 view_pos; out vec3 view_dir; void main() { - // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + // pass through untransformed fullscreen pos (clipspace) + gl_Position = vec4(position.xyz, 1.0); + + view_pos = (inv_proj * vec4(position, 1.0f)).xyz; // this will be normalized in the frag shader... - view_dir = position.xyz - camPosLocal.xyz; + //view_dir = (inv_modelview * view_pos).xyz; + view_dir = view_pos - camPosLocal; } diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl index 014ab9d11b..fed3edf7de 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl @@ -32,12 +32,13 @@ out vec4 frag_color; in vec3 view_dir; uniform vec3 cameraPosLocal; -uniform vec3 sun_direction; +uniform vec3 sun_dir; uniform float sun_size; uniform sampler2D transmittance_texture; uniform sampler3D scattering_texture; uniform sampler3D mie_scattering_texture; +uniform sampler2D irradiance_texture; vec3 GetSolarLuminance(); vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 sun_dir, out vec3 transmittance); @@ -50,20 +51,22 @@ void main() vec3 camPos = cameraPosLocal; vec3 transmittance; - vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); + vec3 sky_illum; + vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_dir, transmittance); + vec3 radiance2 = GetSunAndSkyIlluminance(camPos, view_direction, sun_dir, sky_illum); - radiance *= transmittance; + //radiance *= transmittance; // If the view ray intersects the Sun, add the Sun radiance. - if (dot(view_direction, sun_direction) >= sun_size) + if (dot(view_direction, sun_dir) >= sun_size) { radiance = radiance + transmittance * GetSolarLuminance(); } - vec3 color = vec3(1.0) - exp(-radiance); - color = pow(color, vec3(1.0 / 2.2)); + //vec3 color = vec3(1.0) - exp(-radiance); + //color = pow(color, vec3(1.0 / 2.2)); - frag_color.rgb = color; + frag_color.rgb = radiance; frag_color.a = 1.0; } -- cgit v1.2.3 From 64302d3000b69b31e72eb6a3bd8a981c80cb88de Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 1 Jun 2018 00:18:36 +0100 Subject: Modify use of sky settings, reduce complexity, and name funcs to indicate coord systems in use. Fix class2 softenLightF shader. --- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index c20092bfe0..371b32406c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -82,6 +82,8 @@ vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleFragSoftClip(vec3 l); vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +vec3 fullbrightFragAtmosTransport(vec3 l, vec3 additive, vec3 atten); +vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 atten); vec4 getPosition_d(vec2 pos_screen, float depth) { @@ -147,7 +149,7 @@ void main() calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); - col = atmosAmbient(vec3(0)); + col = atmosFragAmbient(vec3(0), amblit); float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; @@ -167,7 +169,7 @@ void main() // float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*scol_ambocc.r*(texture2D(lightFunc, vec2(sa, spec.a)).r); + vec3 dumbshiny = sunlit*scol_ambocc.r*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; @@ -192,7 +194,7 @@ void main() if (norm.w < 0.5) { col = mix(atmosFragLighting(col, additive, atten), fullbrightFragAtmosTransport(col, atten, additive), diffuse.a); - col = mix(scaleFragSoftClip(col), fullbrightFragScaleSoftClip(col), diffuse.a); + col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a); } #ifdef WATER_FOG -- cgit v1.2.3 From 363f7f84a149c0bc4fe21df80aead821f02a7ff0 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Thu, 7 Jun 2018 10:24:29 -0700 Subject: Validation fixes. --- .../shaders/class1/environment/decodeNormF.glsl | 25 ++++++++++++++++++++++ .../shaders/class1/environment/encodeNormF.glsl | 24 +++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl b/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl index 0abb1e43db..becc6d89c1 100644 --- a/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl @@ -1,3 +1,28 @@ +/** + * @file decodeNormF.glsl + * + * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2018, 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$ + */ + vec3 decode_normal (vec2 enc) { vec2 fenc = enc*4-2; diff --git a/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl b/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl index ee21715c1d..50e781fa78 100644 --- a/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/encodeNormF.glsl @@ -1,3 +1,27 @@ +/** + * @file encodeNormF.glsl + * + * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2018, 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$ + */ vec2 encode_normal(vec3 n) { -- cgit v1.2.3 From 507c4921826e73635f6ae31087ab0e6cd1280f43 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 8 Jun 2018 22:22:20 +0100 Subject: Add specific shader for the moon to allow different rendering at day vs night. Add MouseMoon positioning ala MouseSun debug setting and accessors to use it. --- .../shaders/class1/windlight/moonF.glsl | 58 ++++++++++++++++++++++ .../shaders/class1/windlight/moonV.glsl | 48 ++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class1/windlight/moonF.glsl create mode 100644 indra/newview/app_settings/shaders/class1/windlight/moonV.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl new file mode 100644 index 0000000000..14b08b1da4 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -0,0 +1,58 @@ +/** + * @file moonF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +vec3 fullbrightAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light); + +uniform vec4 color; +uniform vec4 sunlight_color; +uniform vec3 lumWeights; +uniform float minLuminance; +uniform sampler2D diffuseMap; +VARYING vec2 vary_texcoord0; + +void main() +{ + vec4 c = texture2D(diffuseMap, vary_texcoord0.xy); + c.rgb = fullbrightAtmosTransport(c.rgb); + c.rgb = fullbrightScaleSoftClip(c.rgb); + c.rgb = pow(c.rgb, vec3(0.45f)); + // mix factor which blends when sunlight is brighter + // and shows true moon color at night + float mix = dot(normalize(sunlight_color.rgb), lumWeights); + mix = smoothstep(-0.5f, 2.0f, lum); + frag_color = vec4(c.rgb, mix * c.a); +} + diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl new file mode 100644 index 0000000000..7c4dfbd999 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl @@ -0,0 +1,48 @@ +/** + * @file moonV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 mat4 texture_matrix0; +uniform mat4 modelview_matrix; +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +//void calcAtmospherics(vec3 inPositionEye); + +VARYING vec2 vary_texcoord0; + +void main() +{ + //transform vertex + vec4 vert = vec4(position.xyz, 1.0); + vec4 pos = (modelview_matrix * vert); + + gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + + //calcAtmospherics(pos.xyz); +} -- cgit v1.2.3 From a0598b12656cdcf22ba95cacd01b5ff36f8f1b26 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 11 Jun 2018 17:46:16 +0100 Subject: Fix water fog consolidation in underwater shaders. Add plumbing facilities to allow current and next moon textures to be passed to moon shader. Modify moon shader to blend between current and next moon textures by blend factor. --- .../shaders/class1/environment/underWaterF.glsl | 38 ++-------------------- .../shaders/class1/windlight/moonF.glsl | 9 +++-- .../shaders/class2/deferred/softenLightF.glsl | 4 +-- 3 files changed, 11 insertions(+), 40 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl index 0d8dab0a41..e918bdcb9d 100644 --- a/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl @@ -56,41 +56,7 @@ VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; -vec4 applyWaterFog(vec4 color, vec3 viewVec) -{ - //normalize view vector - vec3 view = normalize(viewVec); - float es = -view.z; - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - //get object depth - float depth = length(viewVec); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - //return vec4(1.0, 0.0, 1.0, 1.0); - return color * D + kc * L; - //depth /= 10.0; - //return vec4(depth,depth,depth,0.0); -} +vec4 applyWaterFogView(vec3 pos, vec4 color); void main() { @@ -108,5 +74,5 @@ void main() vec4 fb = texture2D(screenTex, distort); - frag_color = applyWaterFog(fb,view.xyz); + frag_color = applyWaterFogView(view.xyz, fb); } diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl index 14b08b1da4..4d0d8882b9 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -41,18 +41,23 @@ uniform vec4 sunlight_color; uniform vec3 lumWeights; uniform float minLuminance; uniform sampler2D diffuseMap; +uniform sampler2D altDiffuseMap; +uniform float blend_factor; // interp factor between moon A/B VARYING vec2 vary_texcoord0; void main() { - vec4 c = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); + vec4 c = mix(moonA, moonB, blend_factor); + c.rgb = fullbrightAtmosTransport(c.rgb); c.rgb = fullbrightScaleSoftClip(c.rgb); c.rgb = pow(c.rgb, vec3(0.45f)); // mix factor which blends when sunlight is brighter // and shows true moon color at night float mix = dot(normalize(sunlight_color.rgb), lumWeights); - mix = smoothstep(-0.5f, 2.0f, lum); + mix = smoothstep(-0.5f, 2.0f, mix); frag_color = vec4(c.rgb, mix * c.a); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 371b32406c..9f56bff4c2 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -105,7 +105,7 @@ vec4 getPosition(vec2 pos_screen) #ifdef WATER_FOG -vec4 applyWaterFogDeferred(vec3 pos, vec4 color); +vec4 applyWaterFogView(vec3 pos, vec4 color); #endif void main() @@ -198,7 +198,7 @@ void main() } #ifdef WATER_FOG - vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); + vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); col = fogged.rgb; bloom = fogged.a; #endif -- cgit v1.2.3 From fc8d0de673da0e02915556008a365aca67472eba Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 11 Jun 2018 22:39:57 +0100 Subject: Make cloud rendering use textures defined in sky settings and add code to shaders to lerp between current and next cloud texture. --- .../app_settings/shaders/class1/deferred/cloudsF.glsl | 14 ++++++++++++-- .../app_settings/shaders/class1/deferred/skyF.glsl | 1 - .../app_settings/shaders/class2/windlight/cloudsF.glsl | 14 ++++++++++++-- .../app_settings/shaders/class2/windlight/skyF.glsl | 1 - .../app_settings/shaders/class3/deferred/cloudsF.glsl | 15 +++++++++++++-- .../app_settings/shaders/class3/deferred/skyF.glsl | 1 - 6 files changed, 37 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 7b971fcc66..1a4cdff23d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -39,6 +39,8 @@ VARYING vec4 vary_CloudColorAmbient; VARYING float vary_CloudDensity; uniform sampler2D cloud_noise_texture; +uniform sampler2D cloud_noise_texture_next; +uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; uniform vec4 gamma; @@ -57,6 +59,14 @@ vec3 scaleSoftClip(vec3 light) { return light; } +vec4 cloudNoise(vec2 uv) +{ + vec4 a = texture2D(cloud_noise_texture, uv); + vec4 b = texture2D(cloud_noise_texture_next, uv); + vec4 cloud_noise_sample = mix(a, b, blend_factor); + return cloud_noise_sample; +} + void main() { // Set variables @@ -77,7 +87,7 @@ void main() // Compute alpha1, the main cloud opacity - float alpha1 = (texture2D(cloud_noise_texture, uv1).x - 0.5) + (texture2D(cloud_noise_texture, uv3).x - 0.5) * cloud_pos_density2.z; + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.); // And smooth @@ -87,7 +97,7 @@ void main() // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (texture2D(cloud_noise_texture, uv2).x - 0.5); + float alpha2 = (cloudNoise(uv2).x - 0.5); alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); // And smooth diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 4511237e4d..8e4696cfaa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -37,7 +37,6 @@ out vec4 frag_data[3]; VARYING vec4 vary_HazeColor; -uniform sampler2D cloud_noise_texture; uniform vec4 gamma; /// Soft clips the light with a gamma correction diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index 96c70651b1..e0c7e18a6f 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -42,6 +42,8 @@ VARYING vec2 vary_texcoord2; VARYING vec2 vary_texcoord3; uniform sampler2D cloud_noise_texture; +uniform sampler2D cloud_noise_texture_next; +uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; uniform vec4 gamma; @@ -55,6 +57,14 @@ vec3 scaleSoftClip(vec3 light) { return light; } +vec4 cloudNoise(vec2 uv) +{ + vec4 a = texture2D(cloud_noise_texture, uv); + vec4 b = texture2D(cloud_noise_texture_next, uv); + vec4 samp = mix(a, b, blend_factor); + return samp; +} + void main() { // Set variables @@ -75,7 +85,7 @@ void main() // Compute alpha1, the main cloud opacity - float alpha1 = (texture2D(cloud_noise_texture, uv1).x - 0.5) + (texture2D(cloud_noise_texture, uv3).x - 0.5) * cloud_pos_density2.z; + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.); // And smooth @@ -85,7 +95,7 @@ void main() // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (texture2D(cloud_noise_texture, uv2).x - 0.5); + float alpha2 = (cloudNoise(uv2).x - 0.5); alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); // And smooth diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl index 2a0ca35278..25fd0584f8 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl @@ -35,7 +35,6 @@ out vec4 frag_color; VARYING vec4 vary_HazeColor; -uniform sampler2D cloud_noise_texture; uniform vec4 gamma; /// Soft clips the light with a gamma correction diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl index 96c70651b1..44b41cc0b8 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -42,10 +42,21 @@ VARYING vec2 vary_texcoord2; VARYING vec2 vary_texcoord3; uniform sampler2D cloud_noise_texture; +uniform sampler2D cloud_noise_texture_next; +uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; uniform vec4 gamma; +vec4 cloudNoise(vec2 uv) +{ + vec4 a = texture2D(cloud_noise_texture, uv); + vec4 b = texture2D(cloud_noise_texture_next, uv); + vec4 samp = mix(a, b, blend_factor); + return samp; +} + + /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light) { //soft clip effect: @@ -75,7 +86,7 @@ void main() // Compute alpha1, the main cloud opacity - float alpha1 = (texture2D(cloud_noise_texture, uv1).x - 0.5) + (texture2D(cloud_noise_texture, uv3).x - 0.5) * cloud_pos_density2.z; + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.); // And smooth @@ -85,7 +96,7 @@ void main() // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (texture2D(cloud_noise_texture, uv2).x - 0.5); + float alpha2 = (cloudNoise(uv2).x - 0.5); alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); // And smooth diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index 5185a9f8f4..a439aa64d7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -36,7 +36,6 @@ uniform vec3 cameraPosLocal; uniform vec3 sun_dir; uniform float sun_size; -uniform sampler2D cloud_noise_texture; uniform sampler2D transmittance_texture; uniform sampler3D scattering_texture; uniform sampler3D single_mie_scattering_texture; -- cgit v1.2.3 From 67ab0084f87c40bf31d7fadded55cc9ea6299ca2 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 12 Jun 2018 18:42:07 +0100 Subject: Fix env panel forward action. Make env panel update environment when jumping frame to frame. Add separate funcs for sun/moon vectors in various coord systems. Make haze glow only pay attention to sun (i.e. fix sun glow when moon is near horizon in daytime). --- .../newview/app_settings/shaders/class1/deferred/alphaF.glsl | 6 +++++- .../app_settings/shaders/class1/deferred/materialF.glsl | 10 ++++++++-- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 10 ++++++++-- .../app_settings/shaders/class1/environment/waterFogF.glsl | 1 - .../app_settings/shaders/class2/deferred/softenLightF.glsl | 10 +++++++--- .../app_settings/shaders/class2/deferred/sunLightF.glsl | 9 +++++++-- .../app_settings/shaders/class2/deferred/sunLightSSAOF.glsl | 8 ++++++-- indra/newview/app_settings/shaders/class3/deferred/skyF.glsl | 12 +++++++----- .../app_settings/shaders/class3/windlight/advancedAtmoF.glsl | 1 + 9 files changed, 49 insertions(+), 18 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 2234ceeb53..8dda96984e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -43,6 +43,7 @@ uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; +uniform vec3 moon_dir; #if HAS_SHADOW uniform sampler2DShadow shadowMap0; @@ -287,7 +288,10 @@ void main() vec2 abnormal = encode_normal(norm.xyz); norm.xyz = decode_normal(abnormal.xy); - float da = dot(norm.xyz, sun_dir.xyz); + float da_sun = dot(norm.xyz, sun_dir.xyz); + float da_moon = dot(norm.xyz, moon_dir.xyz); + + float da = max(da_sun, da_moon); float final_da = da; final_da = min(final_da, shadow); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a90e433622..4dc15dbc89 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -98,6 +98,7 @@ uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; +uniform vec3 moon_dir; VARYING vec2 vary_fragcoord; VARYING vec3 vary_position; @@ -388,7 +389,9 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float da =dot(norm.xyz, sun_dir.xyz); + float da_sun =dot(norm.xyz, sun_dir.xyz); + float da_moon =dot(norm.xyz, moon_dir.xyz); + float da = max(da_sun, da_moon); float final_da = da; final_da = min(final_da, shadow); @@ -418,7 +421,10 @@ void main() // the old infinite-sky shiny reflection // - float sa = dot(refnormpersp, sun_dir.xyz); + float sa_sun = dot(refnormpersp, sun_dir.xyz); + float sa_moon = dot(refnormpersp, moon_dir.xyz); + float sa = max(sa_sun, sa_moon); + vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index fbfd43a4da..a4543c325e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -56,6 +56,7 @@ uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; +uniform vec3 moon_dir; VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; @@ -106,7 +107,9 @@ void main() float envIntensity = norm.z; norm.xyz = decode_normal(norm.xy); // unpack norm - float da = dot(norm.xyz, sun_dir.xyz); + float da_sun = dot(norm.xyz, sun_dir.xyz); + float da_moon = dot(norm.xyz, moon_dir.xyz); + float da = max(da_sun, da_moon); float final_da = max(0.0,da); final_da = min(final_da, 1.0f); @@ -148,7 +151,10 @@ void main() // the old infinite-sky shiny reflection // - float sa = dot(refnormpersp, sun_dir.xyz); + float sa_sun = dot(refnormpersp, sun_dir.xyz); + float sa_moon = dot(refnormpersp, moon_dir.xyz); + float sa = max(sa_sun, sa_moon); + vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together diff --git a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl index a7c28a1ac3..68ce2843d0 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl @@ -25,7 +25,6 @@ -uniform vec4 lightnorm; uniform vec4 waterPlane; uniform vec4 waterFogColor; uniform float waterFogDensity; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 9f56bff4c2..5046ede00d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -49,7 +49,6 @@ uniform vec4 morphFactor; uniform vec3 camPosLocal; //uniform vec4 camPosWorld; uniform vec4 gamma; -uniform vec4 lightnorm; uniform vec4 sunlight_color; uniform vec4 ambient; uniform vec4 blue_horizon; @@ -68,6 +67,7 @@ uniform vec4 shadow_clip; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; +uniform vec3 moon_dir; VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; @@ -117,7 +117,9 @@ void main() float envIntensity = norm.z; norm.xyz = decode_normal(norm.xy); // unpack norm - float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); + float da_sun = max(dot(norm.xyz, sun_dir.xyz), 0.0); + float da_moon = max(dot(norm.xyz, moon_dir.xyz), 0.0); + float da = max(da_sun, da_moon); float light_gamma = 1.0/1.3; da = pow(da, light_gamma); @@ -168,7 +170,9 @@ void main() // the old infinite-sky shiny reflection // - float sa = dot(refnormpersp, sun_dir.xyz); + float sa_sun = dot(refnormpersp, sun_dir.xyz); + float sa_moon = dot(refnormpersp, moon_dir.xyz); + float sa = max(sa_sun, sa_moon); vec3 dumbshiny = sunlit*scol_ambocc.r*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index aa5e99a2f7..11ccdf638c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -59,6 +59,7 @@ uniform mat4 inv_proj; uniform vec2 screen_res; uniform vec2 proj_shadow_res; uniform vec3 sun_dir; +uniform vec3 moon_dir; uniform vec2 shadow_res; uniform float shadow_bias; @@ -139,10 +140,14 @@ void main() }*/ float shadow = 0.0; - float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); + float da_sun = dot(norm, sun_dir.xyz); + float da_moon = dot(norm, moon_dir.xyz); + float da = max(da_sun, da_moon); + + float dp_directional_light = max(0.0, da); vec3 shadow_pos = pos.xyz; - vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); + vec3 offset = ((da_sun > da_moon) ? sun_dir.xyz : moon_dir.xyz) * (1.0-dp_directional_light); vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 58f3f2f91e..4fccb1d33c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -59,6 +59,7 @@ uniform mat4 inv_proj; uniform vec2 screen_res; uniform vec2 proj_shadow_res; uniform vec3 sun_dir; +uniform vec3 moon_dir; uniform vec2 shadow_res; @@ -200,10 +201,13 @@ void main() }*/ float shadow = 0.0; - float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); + float da_sun = dot(norm, sun_dir.xyz); + float da_moon = dot(norm, moon_dir.xyz); + float da = max(da_sun, da_moon); + float dp_directional_light = max(0.0, da); vec3 shadow_pos = pos.xyz; - vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); + vec3 offset = ((da_sun > da_moon) ? sun_dir.xyz : moon_dir.xyz) * (1.0-dp_directional_light); vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index a439aa64d7..0fb990611e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -34,6 +34,7 @@ in vec3 view_dir; uniform vec3 cameraPosLocal; uniform vec3 sun_dir; +uniform vec3 moon_dir; uniform float sun_size; uniform sampler2D transmittance_texture; @@ -42,9 +43,9 @@ uniform sampler3D single_mie_scattering_texture; uniform sampler2D irradiance_texture; vec3 GetSolarLuminance(); -vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 sun_dir, out vec3 transmittance); -vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 sun_dir, out vec3 transmittance); -vec3 GetSunAndSkyIlluminance(vec3 pos, vec3 norm, vec3 sun_dir, out vec3 sky_irradiance); +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); +vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); +vec3 GetSunAndSkyIlluminance(vec3 pos, vec3 norm, vec3 dir, out vec3 sky_irradiance); void main() { @@ -55,8 +56,9 @@ void main() vec3 camPos = cameraPosLocal + vec3(0, 0, 6360.0f); vec3 transmittance; vec3 sky_illum; - vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); - vec3 radiance2 = GetSunAndSkyIlluminance(camPos, view_direction, sun_direction, sky_illum); + + vec3 radiance_sun = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); + vec3 radiance2_sun = GetSunAndSkyIlluminance(camPos, view_direction, sun_direction, sky_illum); radiance *= transmittance; diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl index fed3edf7de..bdb54a1d63 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl @@ -33,6 +33,7 @@ in vec3 view_dir; uniform vec3 cameraPosLocal; uniform vec3 sun_dir; +uniform vec3 moon_dir; uniform float sun_size; uniform sampler2D transmittance_texture; -- cgit v1.2.3 From 34865c4bb5cd12219606f44748159fe7cbeea264 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 13 Jun 2018 00:51:39 +0100 Subject: Mods to hook up water settings to water normals for rendering with support for current to next blending. Modify LLSettingsFoo::buildDefaultFoo to use a static and avoid re-validation of default sky/water/daycycle settings. Remove all references to gSun/MoonTextureId globals (they should come from sky settings now). --- .../shaders/class1/deferred/waterF.glsl | 27 +++++++++++++++++++--- .../shaders/class1/environment/waterF.glsl | 26 ++++++++++++++++++--- 2 files changed, 47 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index b321eb508b..98c5030a04 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -37,6 +37,8 @@ vec3 scaleSoftClip(vec3 inColor); vec3 atmosTransport(vec3 inColor); uniform sampler2D bumpMap; +uniform sampler2D bumpMap2; +uniform float blend_factor; uniform sampler2D screenTex; uniform sampler2D refTex; uniform sampler2DRectShadow shadowMap0; @@ -72,6 +74,15 @@ VARYING vec4 vary_position; vec3 srgb_to_linear(vec3 cs); vec2 encode_normal(vec3 n); +vec3 BlendNormal(vec3 bump1, vec3 bump2) +{ + //vec3 normal = bump1.xyz * vec3( 2.0, 2.0, 2.0) - vec3(1.0, 1.0, 0.0); + //vec3 normal2 = bump2.xyz * vec3(-2.0, -2.0, 2.0) + vec3(1.0, 1.0, -1.0); + //vec3 n = normalize(normal * dot(normal, normal2) - (normal2 * normal.z)); + vec3 n = normalize(mix(bump1, bump2, blend_factor)); + return n; +} + void main() { vec4 color; @@ -81,9 +92,19 @@ void main() vec3 viewVec = normalize(view.xyz); //get wave normals - vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; - vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; - vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + + + vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; + + vec3 wave1 = BlendNormal(wave1_a, wave1_b); + vec3 wave2 = BlendNormal(wave2_a, wave2_b); + vec3 wave3 = BlendNormal(wave3_a, wave3_b); + //get base fresnel components vec3 df = vec3( diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index 79bffab745..37f109c637 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -33,6 +33,8 @@ vec3 scaleSoftClip(vec3 inColor); vec3 atmosTransport(vec3 inColor); uniform sampler2D bumpMap; +uniform sampler2D bumpMap2; +uniform float blend_factor; uniform sampler2D screenTex; uniform sampler2D refTex; @@ -55,6 +57,15 @@ VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; +vec3 BlendNormal(vec3 bump1, vec3 bump2) +{ + //vec3 normal = bump1.xyz * vec3( 2.0, 2.0, 2.0) - vec3(1.0, 1.0, 0.0); + //vec3 normal2 = bump2.xyz * vec3(-2.0, -2.0, 2.0) + vec3(1.0, 1.0, -1.0); + //vec3 n = normalize(normal * dot(normal, normal2) - (normal2 * normal.z)); + vec3 n = normalize(mix(bump1, bump2, blend_factor)); + return n; +} + void main() { vec4 color; @@ -65,9 +76,18 @@ void main() vec3 viewVec = normalize(view.xyz); //get wave normals - vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; - vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; - vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + + vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; + + vec3 wave1 = BlendNormal(wave1_a, wave1_b); + vec3 wave2 = BlendNormal(wave2_a, wave2_b); + vec3 wave3 = BlendNormal(wave3_a, wave3_b); + //get base fresnel components vec3 df = vec3( -- cgit v1.2.3 From 5c2f49b86511f88de520f4297f20e6382139a927 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 27 Jun 2018 22:00:50 +0100 Subject: Make distinct ALM moon shader, tweak mix factor for day vs night moon shading, and fix transposed name of daycycle func. --- .../shaders/class1/deferred/moonF.glsl | 64 ++++++++++++++++++++++ .../shaders/class1/deferred/moonV.glsl | 44 +++++++++++++++ .../shaders/class1/windlight/moonF.glsl | 6 +- 3 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/moonF.glsl create mode 100644 indra/newview/app_settings/shaders/class1/deferred/moonV.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl new file mode 100644 index 0000000000..b0fca8ddee --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -0,0 +1,64 @@ +/** + * @file moonF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +vec3 fullbrightAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light); + +uniform vec4 color; +uniform vec4 sunlight_color; +uniform vec3 lumWeights; +uniform float minLuminance; +uniform sampler2D diffuseMap; +uniform sampler2D altDiffuseMap; +uniform float blend_factor; // interp factor between moon A/B +VARYING vec2 vary_texcoord0; + +void main() +{ + vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); + vec4 c = mix(moonA, moonB, blend_factor); + + c.rgb = pow(c.rgb, vec3(0.7f)); + c.rgb = fullbrightAtmosTransport(c.rgb); + c.rgb = fullbrightScaleSoftClip(c.rgb); + + // mix factor which blends when sunlight is brighter + // and shows true moon color at night + vec3 luma_weights = vec3(0.1, 0.3, 0.0); + float mix = 1.0f - dot(sunlight_color.rgb, luma_weights); + frag_color = vec4(c.rgb, mix * c.a); +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl new file mode 100644 index 0000000000..4fcc44ed01 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl @@ -0,0 +1,44 @@ +/** + * @file moonV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 mat4 texture_matrix0; +uniform mat4 modelview_matrix; +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +VARYING vec2 vary_texcoord0; + +void main() +{ + //transform vertex + vec4 vert = vec4(position.xyz, 1.0); + vec4 pos = (modelview_matrix * vert); + + gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +} diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl index 4d0d8882b9..933625986c 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -51,13 +51,13 @@ void main() vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(moonA, moonB, blend_factor); + c.rgb = pow(c.rgb, vec3(0.45f)); c.rgb = fullbrightAtmosTransport(c.rgb); c.rgb = fullbrightScaleSoftClip(c.rgb); - c.rgb = pow(c.rgb, vec3(0.45f)); // mix factor which blends when sunlight is brighter // and shows true moon color at night - float mix = dot(normalize(sunlight_color.rgb), lumWeights); - mix = smoothstep(-0.5f, 2.0f, mix); + vec3 luma_weights = vec3(0.1, 0.3, 0.0); + float mix = 1.0f - dot(sunlight_color.rgb, luma_weights); frag_color = vec4(c.rgb, mix * c.a); } -- cgit v1.2.3 From ec496d5e1abf9681895062f297fd8a62f057986e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sat, 30 Jun 2018 00:22:10 +0100 Subject: MAINT-4019 fix ALM star rendering (make post-deferred and actually blend) --- indra/newview/app_settings/shaders/class1/deferred/starsF.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 029a98e16a..f397a4a151 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -28,19 +28,19 @@ #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else -#define frag_data gl_FragData +#define frag_color gl_FragColor #endif VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; uniform sampler2D diffuseMap; +uniform float custom_alpha; void main() { vec4 col = vertex_color * texture2D(diffuseMap, vary_texcoord0.xy); + col.a *= custom_alpha; - frag_data[0] = col; - frag_data[1] = vec4(0,0,0,0); - frag_data[2] = vec4(0,0,1,0); + frag_color = col; } -- cgit v1.2.3 From 8969b114357d189e1bf39024762698eeddddfc78 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 3 Jul 2018 16:37:32 +0100 Subject: MAINT-8838 render a sun disc if the texture(s) are provided by WL settings (default is no sun disc and just haze) Refactor sky texture optimization to retain building the cubemap used by shiny. --- .../shaders/class1/deferred/moonF.glsl | 2 +- .../shaders/class1/deferred/sunDiscF.glsl | 55 ++++++++++++++++++++++ .../shaders/class1/deferred/sunDiscV.glsl | 44 +++++++++++++++++ .../shaders/class1/windlight/moonF.glsl | 2 +- .../shaders/class1/windlight/sunDiscF.glsl | 54 +++++++++++++++++++++ .../shaders/class1/windlight/sunDiscV.glsl | 44 +++++++++++++++++ 6 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl create mode 100644 indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl create mode 100644 indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl create mode 100644 indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index b0fca8ddee..6562b86aaf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -49,7 +49,7 @@ void main() { vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); - vec4 c = mix(moonA, moonB, blend_factor); + vec4 c = mix(moonB, moonA, blend_factor); c.rgb = pow(c.rgb, vec3(0.7f)); c.rgb = fullbrightAtmosTransport(c.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl new file mode 100644 index 0000000000..d2e3be2720 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -0,0 +1,55 @@ +/** + * @file sunDiscF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +vec3 fullbrightAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light); + +uniform sampler2D diffuseMap; +uniform sampler2D altDiffuseMap; +uniform float blend_factor; // interp factor between sunDisc A/B +VARYING vec2 vary_texcoord0; + +void main() +{ + vec4 sunDiscA = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 sunDiscB = texture2D(altDiffuseMap, vary_texcoord0.xy); + vec4 c = mix(sunDiscB, sunDiscA, blend_factor); + + c.rgb = pow(c.rgb, vec3(0.7f)); + c.rgb = fullbrightAtmosTransport(c.rgb); + c.rgb = fullbrightScaleSoftClip(c.rgb); + frag_color = c; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl new file mode 100644 index 0000000000..3bf50ddd0a --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl @@ -0,0 +1,44 @@ +/** + * @file sunDiscV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 mat4 texture_matrix0; +uniform mat4 modelview_matrix; +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +VARYING vec2 vary_texcoord0; + +void main() +{ + //transform vertex + vec4 vert = vec4(position.xyz, 1.0); + vec4 pos = (modelview_matrix * vert); + + gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +} diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl index 933625986c..480a0e1dc4 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -49,7 +49,7 @@ void main() { vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); - vec4 c = mix(moonA, moonB, blend_factor); + vec4 c = mix(moonB, moonA, blend_factor); c.rgb = pow(c.rgb, vec3(0.45f)); c.rgb = fullbrightAtmosTransport(c.rgb); diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl new file mode 100644 index 0000000000..0eb32b69b8 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl @@ -0,0 +1,54 @@ +/** + * @file sunDiscF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +vec3 fullbrightAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light); + +uniform sampler2D diffuseMap; +uniform sampler2D altDiffuseMap; +uniform float blend_factor; // interp factor between sun A/B +VARYING vec2 vary_texcoord0; + +void main() +{ + vec4 sunA = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 sunB = texture2D(altDiffuseMap, vary_texcoord0.xy); + vec4 c = mix(sunB, sunA, blend_factor); + c.rgb = pow(c.rgb, vec3(0.45f)); + c.rgb = fullbrightAtmosTransport(c.rgb); + c.rgb = fullbrightScaleSoftClip(c.rgb); + frag_color = c; +} + diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl new file mode 100644 index 0000000000..3bf50ddd0a --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl @@ -0,0 +1,44 @@ +/** + * @file sunDiscV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 mat4 texture_matrix0; +uniform mat4 modelview_matrix; +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +VARYING vec2 vary_texcoord0; + +void main() +{ + //transform vertex + vec4 vert = vec4(position.xyz, 1.0); + vec4 pos = (modelview_matrix * vert); + + gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +} -- cgit v1.2.3 From a682d91ea1f7c566269fbad40415639b67cee096 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 3 Jul 2018 23:20:42 +0100 Subject: Fix deferred stars shader output decl. --- indra/newview/app_settings/shaders/class1/deferred/starsF.glsl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index f397a4a151..9260075262 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -26,7 +26,7 @@ /*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; +out vec4 frag_color; #else #define frag_color gl_FragColor #endif @@ -41,6 +41,5 @@ void main() { vec4 col = vertex_color * texture2D(diffuseMap, vary_texcoord0.xy); col.a *= custom_alpha; - frag_color = col; } -- cgit v1.2.3 From 4fde1adbcf7d79bc4e80078c2f553b8ec020a1c3 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 10 Jul 2018 18:23:02 +0100 Subject: Fix star rendering issues in ALM. --- indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl | 4 ++++ indra/newview/app_settings/shaders/class1/deferred/starsF.glsl | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 1a4cdff23d..3f81e3b0af 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -94,6 +94,10 @@ void main() alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; + if (alpha1 < 0.001f) + { + discard; + } // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 9260075262..7f55d020d4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -36,10 +36,12 @@ VARYING vec2 vary_texcoord0; uniform sampler2D diffuseMap; uniform float custom_alpha; +uniform vec4 sunlight_color; void main() { - vec4 col = vertex_color * texture2D(diffuseMap, vary_texcoord0.xy); + vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); + col.rgb *= vertex_color.rgb; col.a *= custom_alpha; frag_color = col; } -- cgit v1.2.3 From a90e61b798711306496c2ed7aa5cce6d096ea466 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 10 Jul 2018 19:08:14 +0100 Subject: Support blending current/next bloom textures in deferred star rendering. --- indra/newview/app_settings/shaders/class1/deferred/starsF.glsl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 7f55d020d4..d6a1edbf42 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -35,12 +35,16 @@ VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; uniform sampler2D diffuseMap; +uniform sampler2D altDiffuseMap; +uniform float blend_factor; uniform float custom_alpha; uniform vec4 sunlight_color; void main() { - vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 col_a = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 col_b = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 col = mix(col_a, col_b, blend_factor); col.rgb *= vertex_color.rgb; col.a *= custom_alpha; frag_color = col; -- cgit v1.2.3 From ffdd6c3d7dad87e9873067a923d4e7ce9e6d4d2c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 10 Jul 2018 23:26:35 +0100 Subject: Make advanced atmo sky shader compile again. Make atmospheric model avoid redundant work when settings don't change. Point autobuild.xml at libatmosphere with op== to compare density profiles. --- indra/newview/app_settings/shaders/class3/deferred/skyF.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index 0fb990611e..43c0505046 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -60,17 +60,17 @@ void main() vec3 radiance_sun = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); vec3 radiance2_sun = GetSunAndSkyIlluminance(camPos, view_direction, sun_direction, sky_illum); - radiance *= transmittance; + radiance_sun *= transmittance; vec3 solar_luminance = transmittance * GetSolarLuminance(); // If the view ray intersects the Sun, add the Sun radiance. if (dot(view_direction, sun_direction) >= sun_size) { - radiance = radiance + solar_luminance; + radiance_sun = radiance_sun + solar_luminance; } - vec3 color = radiance; + vec3 color = radiance_sun; color = vec3(1.0) - exp(-color * 0.0001); @@ -79,7 +79,7 @@ void main() frag_color.rgb = color; //frag_color.rgb = vec3(dot(view_direction, sun_direction) > 0.95f ? 1.0 : 0.0, 0,0); - frag_color.rgb = normalize(view_pos); + //frag_color.rgb = normalize(view_pos); frag_color.a = 1.0; } -- cgit v1.2.3 From 5fade93da8a1b832a1dbfd494a18e7b441b5feab Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 11 Jul 2018 00:01:12 +0100 Subject: Make moon/star rendering handle transitions between settings w defined textures and settings without better. Reverse direction of mix to match blend_factor values in stars shader. --- indra/newview/app_settings/shaders/class1/deferred/starsF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index d6a1edbf42..d7f655709c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -44,7 +44,7 @@ void main() { vec4 col_a = texture2D(diffuseMap, vary_texcoord0.xy); vec4 col_b = texture2D(diffuseMap, vary_texcoord0.xy); - vec4 col = mix(col_a, col_b, blend_factor); + vec4 col = mix(col_b, col_a, blend_factor); col.rgb *= vertex_color.rgb; col.a *= custom_alpha; frag_color = col; -- cgit v1.2.3 From c7478f200cf5f57120148fdd79f76b9d3eff0258 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 11 Jul 2018 18:03:07 +0100 Subject: Make sun/moon vert shaders use calcAtmospherics in hopes it will get OSX GL to link the shaders without complaining about unwritten varying vars. --- indra/newview/app_settings/shaders/class1/deferred/moonV.glsl | 4 ++++ indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl | 3 +++ indra/newview/app_settings/shaders/class1/windlight/moonV.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl | 4 ++++ 4 files changed, 13 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl index 4fcc44ed01..0325ecead9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl @@ -32,6 +32,8 @@ ATTRIBUTE vec2 texcoord0; VARYING vec2 vary_texcoord0; +void calcAtmospherics(vec3 eye_pos); + void main() { //transform vertex @@ -39,6 +41,8 @@ void main() vec4 pos = (modelview_matrix * vert); gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + + calcAtmospherics(pos.xyz); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl index 3bf50ddd0a..c75440cd05 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl @@ -32,6 +32,8 @@ ATTRIBUTE vec2 texcoord0; VARYING vec2 vary_texcoord0; +void calcAtmospherics(vec3 eye_pos); + void main() { //transform vertex @@ -40,5 +42,6 @@ void main() gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + calcAtmospherics(pos.xyz); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl index 7c4dfbd999..aaa6768ed7 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl @@ -30,7 +30,7 @@ uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; ATTRIBUTE vec2 texcoord0; -//void calcAtmospherics(vec3 inPositionEye); +void calcAtmospherics(vec3 inPositionEye); VARYING vec2 vary_texcoord0; @@ -44,5 +44,5 @@ void main() vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - //calcAtmospherics(pos.xyz); + calcAtmospherics(pos.xyz); } diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl index 3bf50ddd0a..5a6e481b18 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl @@ -32,6 +32,8 @@ ATTRIBUTE vec2 texcoord0; VARYING vec2 vary_texcoord0; +void calcAtmospherics(vec3 eye_pos); + void main() { //transform vertex @@ -40,5 +42,7 @@ void main() gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + calcAtmospherics(pos.xyz); + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; } -- cgit v1.2.3 From 5b874db7c0568373a4132f933894d2733bd08ee2 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 19 Jul 2018 20:46:37 +0100 Subject: Modify deferred sun disc and moon shaders to write all deferrred gbuffer channels and fix rendering issue from norm/spec channels during lighting. --- indra/newview/app_settings/shaders/class1/deferred/moonF.glsl | 8 +++++--- .../newview/app_settings/shaders/class1/deferred/sunDiscF.glsl | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 6562b86aaf..2bfc4f3d2f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -28,9 +28,9 @@ /*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; +out vec4 frag_data[3]; #else -#define frag_color gl_FragColor +#define frag_data gl_FragData #endif vec3 fullbrightAtmosTransport(vec3 light); @@ -59,6 +59,8 @@ void main() // and shows true moon color at night vec3 luma_weights = vec3(0.1, 0.3, 0.0); float mix = 1.0f - dot(sunlight_color.rgb, luma_weights); - frag_color = vec4(c.rgb, mix * c.a); + frag_data[0] = vec4(c.rgb, mix * c.a); + frag_data[1] = vec4(0.0); + frag_data[2] = vec4(0.0f); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index d2e3be2720..bbc5049f1c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -28,9 +28,9 @@ /*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; +out vec4 frag_data[3]; #else -#define frag_color gl_FragColor +#define frag_data gl_FragData #endif vec3 fullbrightAtmosTransport(vec3 light); @@ -46,10 +46,12 @@ void main() vec4 sunDiscA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 sunDiscB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(sunDiscB, sunDiscA, blend_factor); - + c.rgb = clamp(c.rgb, vec3(0), vec3(1)); c.rgb = pow(c.rgb, vec3(0.7f)); c.rgb = fullbrightAtmosTransport(c.rgb); c.rgb = fullbrightScaleSoftClip(c.rgb); - frag_color = c; + frag_data[0] = c; + frag_data[1] = vec4(0.0f); + frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); } -- cgit v1.2.3 From facc678391417c5fa8ca659adc1d449bba2fd349 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 9 Aug 2018 22:46:47 +0100 Subject: MAINT-8951 Remove moon_dir related shader code causing sunlight shadow artifacting. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 8 ++------ .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 9 ++------- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 9 ++------- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 9 ++------- .../newview/app_settings/shaders/class2/deferred/sunLightF.glsl | 9 ++------- .../app_settings/shaders/class2/deferred/sunLightSSAOF.glsl | 8 ++------ indra/newview/app_settings/shaders/class3/deferred/skyF.glsl | 1 - .../app_settings/shaders/class3/windlight/advancedAtmoF.glsl | 1 - 8 files changed, 12 insertions(+), 42 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 8dda96984e..7f2c5add16 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -43,7 +43,6 @@ uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; -uniform vec3 moon_dir; #if HAS_SHADOW uniform sampler2DShadow shadowMap0; @@ -286,12 +285,9 @@ void main() calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); vec2 abnormal = encode_normal(norm.xyz); - norm.xyz = decode_normal(abnormal.xy); + norm.xyz = decode_normal(abnormal.xy); - float da_sun = dot(norm.xyz, sun_dir.xyz); - float da_moon = dot(norm.xyz, moon_dir.xyz); - - float da = max(da_sun, da_moon); + float da = dot(norm.xyz, sun_dir.xyz); float final_da = da; final_da = min(final_da, shadow); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4dc15dbc89..6e06453a5b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -98,7 +98,6 @@ uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; -uniform vec3 moon_dir; VARYING vec2 vary_fragcoord; VARYING vec3 vary_position; @@ -389,9 +388,7 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float da_sun =dot(norm.xyz, sun_dir.xyz); - float da_moon =dot(norm.xyz, moon_dir.xyz); - float da = max(da_sun, da_moon); + float da =dot(norm.xyz, sun_dir.xyz); float final_da = da; final_da = min(final_da, shadow); @@ -421,9 +418,7 @@ void main() // the old infinite-sky shiny reflection // - float sa_sun = dot(refnormpersp, sun_dir.xyz); - float sa_moon = dot(refnormpersp, moon_dir.xyz); - float sa = max(sa_sun, sa_moon); + float sa = dot(refnormpersp, sun_dir.xyz); vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index a4543c325e..ec3c0cb68d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -56,7 +56,6 @@ uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; -uniform vec3 moon_dir; VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; @@ -107,9 +106,7 @@ void main() float envIntensity = norm.z; norm.xyz = decode_normal(norm.xy); // unpack norm - float da_sun = dot(norm.xyz, sun_dir.xyz); - float da_moon = dot(norm.xyz, moon_dir.xyz); - float da = max(da_sun, da_moon); + float da = dot(norm.xyz, sun_dir.xyz); float final_da = max(0.0,da); final_da = min(final_da, 1.0f); @@ -151,9 +148,7 @@ void main() // the old infinite-sky shiny reflection // - float sa_sun = dot(refnormpersp, sun_dir.xyz); - float sa_moon = dot(refnormpersp, moon_dir.xyz); - float sa = max(sa_sun, sa_moon); + float sa = dot(refnormpersp, sun_dir.xyz); vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 5046ede00d..1e2c49215f 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -67,7 +67,6 @@ uniform vec4 shadow_clip; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; -uniform vec3 moon_dir; VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; @@ -117,9 +116,7 @@ void main() float envIntensity = norm.z; norm.xyz = decode_normal(norm.xy); // unpack norm - float da_sun = max(dot(norm.xyz, sun_dir.xyz), 0.0); - float da_moon = max(dot(norm.xyz, moon_dir.xyz), 0.0); - float da = max(da_sun, da_moon); + float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); float light_gamma = 1.0/1.3; da = pow(da, light_gamma); @@ -170,9 +167,7 @@ void main() // the old infinite-sky shiny reflection // - float sa_sun = dot(refnormpersp, sun_dir.xyz); - float sa_moon = dot(refnormpersp, moon_dir.xyz); - float sa = max(sa_sun, sa_moon); + float sa = dot(refnormpersp, sun_dir.xyz); vec3 dumbshiny = sunlit*scol_ambocc.r*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index 11ccdf638c..aa5e99a2f7 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -59,7 +59,6 @@ uniform mat4 inv_proj; uniform vec2 screen_res; uniform vec2 proj_shadow_res; uniform vec3 sun_dir; -uniform vec3 moon_dir; uniform vec2 shadow_res; uniform float shadow_bias; @@ -140,14 +139,10 @@ void main() }*/ float shadow = 0.0; - float da_sun = dot(norm, sun_dir.xyz); - float da_moon = dot(norm, moon_dir.xyz); - float da = max(da_sun, da_moon); - - float dp_directional_light = max(0.0, da); + float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); vec3 shadow_pos = pos.xyz; - vec3 offset = ((da_sun > da_moon) ? sun_dir.xyz : moon_dir.xyz) * (1.0-dp_directional_light); + vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 4fccb1d33c..58f3f2f91e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -59,7 +59,6 @@ uniform mat4 inv_proj; uniform vec2 screen_res; uniform vec2 proj_shadow_res; uniform vec3 sun_dir; -uniform vec3 moon_dir; uniform vec2 shadow_res; @@ -201,13 +200,10 @@ void main() }*/ float shadow = 0.0; - float da_sun = dot(norm, sun_dir.xyz); - float da_moon = dot(norm, moon_dir.xyz); - float da = max(da_sun, da_moon); - float dp_directional_light = max(0.0, da); + float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); vec3 shadow_pos = pos.xyz; - vec3 offset = ((da_sun > da_moon) ? sun_dir.xyz : moon_dir.xyz) * (1.0-dp_directional_light); + vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index 43c0505046..47fa0efe06 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -34,7 +34,6 @@ in vec3 view_dir; uniform vec3 cameraPosLocal; uniform vec3 sun_dir; -uniform vec3 moon_dir; uniform float sun_size; uniform sampler2D transmittance_texture; diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl index bdb54a1d63..fed3edf7de 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl @@ -33,7 +33,6 @@ in vec3 view_dir; uniform vec3 cameraPosLocal; uniform vec3 sun_dir; -uniform vec3 moon_dir; uniform float sun_size; uniform sampler2D transmittance_texture; -- cgit v1.2.3 From b86e899e7e51c56252479236df9a74f9bb432670 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 23 Aug 2018 00:53:11 +0100 Subject: MAINT-9006 Make perspective projection consistent between ALM and non-ALM when drawing water (horizon matches). Make perspective projection consistent between ALM and non-ALM when drawing heavenly bodies (sun disc position matches). Make gamma correction of sun disc tex consistent between ALM and non-ALM rendering. --- indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl | 5 +++-- indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl index c75440cd05..5b4302e237 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl @@ -38,10 +38,11 @@ void main() { //transform vertex vec4 vert = vec4(position.xyz, 1.0); - vec4 pos = (modelview_matrix * vert); + vec4 pos = modelview_projection_matrix*vert; - gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + gl_Position = pos; calcAtmospherics(pos.xyz); + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl index 0eb32b69b8..05251e7e96 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl @@ -46,7 +46,7 @@ void main() vec4 sunA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 sunB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(sunB, sunA, blend_factor); - c.rgb = pow(c.rgb, vec3(0.45f)); + c.rgb = pow(c.rgb, vec3(0.7f)); c.rgb = fullbrightAtmosTransport(c.rgb); c.rgb = fullbrightScaleSoftClip(c.rgb); frag_color = c; diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl index 5a6e481b18..90acb5be9e 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl @@ -38,9 +38,9 @@ void main() { //transform vertex vec4 vert = vec4(position.xyz, 1.0); - vec4 pos = (modelview_matrix * vert); + vec4 pos = modelview_projection_matrix*vert; - gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + gl_Position = pos; calcAtmospherics(pos.xyz); -- cgit v1.2.3 From 6dd9dd3ab63cb0daa7682a400ff0408fd894ba77 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 30 Aug 2018 17:54:59 +0100 Subject: MAINT-9064 Fix binding of current/next sun/moon textures. Remove redundant code in GLSLShader determination of tex uniform bindings. Unhack mix calls in sun/moon shaders to reverse sense of blending (was working around reversed bindings). --- indra/newview/app_settings/shaders/class1/deferred/moonF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/moonF.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 2bfc4f3d2f..e86bca3ddd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -49,7 +49,7 @@ void main() { vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); - vec4 c = mix(moonB, moonA, blend_factor); + vec4 c = mix(moonA, moonB, blend_factor); c.rgb = pow(c.rgb, vec3(0.7f)); c.rgb = fullbrightAtmosTransport(c.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index bbc5049f1c..3557c0766e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -45,7 +45,7 @@ void main() { vec4 sunDiscA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 sunDiscB = texture2D(altDiffuseMap, vary_texcoord0.xy); - vec4 c = mix(sunDiscB, sunDiscA, blend_factor); + vec4 c = mix(sunDiscA, sunDiscB, blend_factor); c.rgb = clamp(c.rgb, vec3(0), vec3(1)); c.rgb = pow(c.rgb, vec3(0.7f)); c.rgb = fullbrightAtmosTransport(c.rgb); diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl index 480a0e1dc4..933625986c 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -49,7 +49,7 @@ void main() { vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); - vec4 c = mix(moonB, moonA, blend_factor); + vec4 c = mix(moonA, moonB, blend_factor); c.rgb = pow(c.rgb, vec3(0.45f)); c.rgb = fullbrightAtmosTransport(c.rgb); diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl index 05251e7e96..3f2375ee4d 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl @@ -45,7 +45,7 @@ void main() { vec4 sunA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 sunB = texture2D(altDiffuseMap, vary_texcoord0.xy); - vec4 c = mix(sunB, sunA, blend_factor); + vec4 c = mix(sunA, sunB, blend_factor); c.rgb = pow(c.rgb, vec3(0.7f)); c.rgb = fullbrightAtmosTransport(c.rgb); c.rgb = fullbrightScaleSoftClip(c.rgb); -- cgit v1.2.3 From 2e55eae9cc6ebff303c8f322c71fec9c20e42bd8 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 4 Sep 2018 23:08:20 +0100 Subject: Merge and fix MAINT-9087 and MAINT-9084 --- .../shaders/class1/deferred/starsF.glsl | 21 +++++++++++++++++---- .../shaders/class1/deferred/starsV.glsl | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index d7f655709c..6c616db442 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -26,19 +26,26 @@ /*[EXTRA_CODE_HERE]*/ #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; +out vec4 frag_data[3]; #else -#define frag_color gl_FragColor +#define frag_data gl_FragData #endif VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +VARYING vec2 screenpos; uniform sampler2D diffuseMap; uniform sampler2D altDiffuseMap; uniform float blend_factor; uniform float custom_alpha; uniform vec4 sunlight_color; +uniform float time; + +float twinkle(){ + float d = fract(screenpos.x + screenpos.y); + return abs(d); +} void main() { @@ -46,6 +53,12 @@ void main() vec4 col_b = texture2D(diffuseMap, vary_texcoord0.xy); vec4 col = mix(col_b, col_a, blend_factor); col.rgb *= vertex_color.rgb; - col.a *= custom_alpha; - frag_color = col; + col.a = (col.a * custom_alpha) * 8.0f; + col.a += twinkle() * 2.0f; + col.a = max(0.0f, col.a); + + frag_data[0] = col; + frag_data[1] = vec4(0.0f); + frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); } + diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl index 8bc5b06379..e14d02a4a9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl @@ -25,6 +25,7 @@ uniform mat4 texture_matrix0; uniform mat4 modelview_projection_matrix; +uniform float time; ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; @@ -32,11 +33,14 @@ ATTRIBUTE vec2 texcoord0; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +VARYING vec2 screenpos; void main() { //transform vertex gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + float t = mod(time, 1.25f); + screenpos = position.xy * vec2(t, t); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; vertex_color = diffuse_color; } -- cgit v1.2.3 From 0a78e9271c524c92cb8b1965e9a6081d4f700437 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 4 Sep 2018 23:39:21 +0100 Subject: Make legacy star brightness setting convert to 0-512 range of new settings. Make brightness scale in shader more linear and fix twinkling. --- indra/newview/app_settings/shaders/class1/deferred/starsF.glsl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 6c616db442..4ae3f7b76f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -53,9 +53,11 @@ void main() vec4 col_b = texture2D(diffuseMap, vary_texcoord0.xy); vec4 col = mix(col_b, col_a, blend_factor); col.rgb *= vertex_color.rgb; - col.a = (col.a * custom_alpha) * 8.0f; - col.a += twinkle() * 2.0f; - col.a = max(0.0f, col.a); + + float factor = smoothstep(0.0f, 0.9f, custom_alpha); + + col.a = (col.a * factor) * 32.0f; + col.a *= twinkle(); frag_data[0] = col; frag_data[1] = vec4(0.0f); -- cgit v1.2.3 From 32631f09a57548c2bbf7e09211a2053ff2e4e47d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 4 Sep 2018 23:41:36 +0100 Subject: 8283/4 WIP --- indra/newview/app_settings/shaders/class3/deferred/skyF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index 47fa0efe06..01c873584f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -1,5 +1,5 @@ /** - * @file advancedAtmoF.glsl + * @file class3/skyF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code -- cgit v1.2.3 From 451ab80ca65a7ae75316442086f42b6553ea6bbe Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 6 Sep 2018 22:50:26 +0100 Subject: Fix tex format mismatch between what libatmosphere was generating and what we were claiming to use in rendering. First pass at sky shader using libatmosphere sky radiance lookup. Add atmo density controls to ext daycycle floater tabs. --- .../app_settings/shaders/class3/deferred/skyF.glsl | 49 ++++++++++------------ .../app_settings/shaders/class3/deferred/skyV.glsl | 14 ++----- 2 files changed, 24 insertions(+), 39 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index 01c873584f..ef94190d45 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -24,17 +24,19 @@ */ #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; +out vec4 frag_data[4]; #else -#define frag_color gl_FragColor +#define frag_data gl_FragData #endif -in vec3 view_pos; -in vec3 view_dir; +VARYING vec2 vary_frag; -uniform vec3 cameraPosLocal; +uniform vec3 camPosLocal; uniform vec3 sun_dir; uniform float sun_size; +uniform float far_z; +uniform mat4 inv_proj; +uniform mat4 inv_modelview; uniform sampler2D transmittance_texture; uniform sampler3D scattering_texture; @@ -44,42 +46,33 @@ uniform sampler2D irradiance_texture; vec3 GetSolarLuminance(); vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); -vec3 GetSunAndSkyIlluminance(vec3 pos, vec3 norm, vec3 dir, out vec3 sky_irradiance); void main() { - vec3 view_direction = normalize(view_dir); + vec3 pos = vec3((vary_frag * 2.0) - vec2(1.0, 1.0), 0.0); + vec4 view_pos = (inv_proj * vec4(pos, 1.0f)); + view_pos /= view_pos.w; + vec3 view_ray = (inv_modelview * vec4(view_pos.xyz, 0.0f)).xyz; - vec3 sun_direction = sun_dir; + vec3 view_direction = normalize(view_ray); + vec3 sun_direction = normalize(sun_dir); - vec3 camPos = cameraPosLocal + vec3(0, 0, 6360.0f); + vec3 camPos = (camPosLocal / 1000.0f) + vec3(0, 0, 6360.0f); vec3 transmittance; - vec3 sky_illum; - - vec3 radiance_sun = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); - vec3 radiance2_sun = GetSunAndSkyIlluminance(camPos, view_direction, sun_direction, sky_illum); - - radiance_sun *= transmittance; - + vec3 radiance_sun = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); vec3 solar_luminance = transmittance * GetSolarLuminance(); // If the view ray intersects the Sun, add the Sun radiance. if (dot(view_direction, sun_direction) >= sun_size) { - radiance_sun = radiance_sun + solar_luminance; + radiance_sun += solar_luminance; } - vec3 color = radiance_sun; - - color = vec3(1.0) - exp(-color * 0.0001); - - //float d = dot(view_direction, sun_direction); - //frag_color.rgb = vec3(d, d >= sun_size ? 1.0f : 0.0f, 0.0f); - - frag_color.rgb = color; - //frag_color.rgb = vec3(dot(view_direction, sun_direction) > 0.95f ? 1.0 : 0.0, 0,0); - //frag_color.rgb = normalize(view_pos); + vec3 color = vec3(1.0) - exp(-radiance_sun * 0.0001); + color = pow(color, vec3(1.0 / 2.2)); - frag_color.a = 1.0; + frag_data[0] = vec4(color, 1.0); + frag_data[1] = vec4(0.0); + frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl index cf3eb658fc..90217aed02 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl @@ -30,22 +30,14 @@ uniform mat4 inv_proj; uniform mat4 inv_modelview; ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; -// Inputs -uniform vec3 camPosLocal; - -out vec3 view_pos; -out vec3 view_dir; +VARYING vec2 vary_frag; void main() { // pass through untransformed fullscreen pos (clipspace) gl_Position = vec4(position.xyz, 1.0); - - view_pos = (inv_proj * vec4(position, 1.0f)).xyz; - - // this will be normalized in the frag shader... - //view_dir = (inv_modelview * view_pos).xyz; - view_dir = view_pos - camPosLocal; + vary_frag = texcoord0; } -- cgit v1.2.3 From 4bd2b8b98ba1c562dfd65975a87ef5ee3db35633 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 7 Sep 2018 17:24:29 +0100 Subject: Fix createDensityProfileLayer dropping passed in values. Enable sky density panel to update advanced atmo precomputed textures. Take wild stab at appropriate ranges for density parameters in edit panel UI. Clean up debug-only code that isn't necessary anymore. Point autobuild at latest version of libatmosphere package. --- indra/newview/app_settings/shaders/class3/deferred/skyV.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl index 90217aed02..89873e83ca 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl @@ -36,8 +36,8 @@ VARYING vec2 vary_frag; void main() { - // pass through untransformed fullscreen pos (clipspace) - gl_Position = vec4(position.xyz, 1.0); + // pass through untransformed fullscreen pos at back of frustum for proper sky depth testing + gl_Position = vec4(position.xy, 0.99f, 1.0); vary_frag = texcoord0; } -- cgit v1.2.3 From 642a4ddd60745db292c543a5cea3b1e5fe606795 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 10 Sep 2018 20:39:48 +0100 Subject: Fixes for switching between atmospherics implementations on the fly. --- indra/newview/app_settings/shaders/class3/deferred/skyF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index ef94190d45..cd0efe8cbb 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -24,7 +24,7 @@ */ #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[4]; +out vec4 frag_data[3]; #else #define frag_data gl_FragData #endif -- cgit v1.2.3 From ef2c61275eafa7d1fd3afa3f0eb76397632f12c9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 10 Sep 2018 21:18:37 +0100 Subject: Move fname back inside class loop. grumble stringstream grumble. Fix sky depth-testing with advanced atmospherics. --- indra/newview/app_settings/shaders/class3/deferred/skyV.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl index 89873e83ca..a5cc49ca30 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl @@ -37,7 +37,7 @@ VARYING vec2 vary_frag; void main() { // pass through untransformed fullscreen pos at back of frustum for proper sky depth testing - gl_Position = vec4(position.xy, 0.99f, 1.0); + gl_Position = vec4(position.xy, 1.0f, 1.0); vary_frag = texcoord0; } -- cgit v1.2.3 From 555dfdc6ef0dab37bc4eaf6ae0b00a857f0609da Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 10 Sep 2018 23:21:34 +0100 Subject: Add copies of existing lighting shaders for advanced atmo path. Enable advanced atmo by default. Disable nSight in settings.xml Remove MSVC debug pragmas. --- .../shaders/class3/deferred/multiSpotLightF.glsl | 314 +++++++++++++++++++++ .../app_settings/shaders/class3/deferred/skyF.glsl | 13 +- .../shaders/class3/deferred/softenLightF.glsl | 189 +++++++++++++ .../shaders/class3/deferred/softenLightV.glsl | 42 +++ .../shaders/class3/deferred/spotLightF.glsl | 313 ++++++++++++++++++++ .../shaders/class3/deferred/sunLightF.glsl | 247 ++++++++++++++++ .../shaders/class3/deferred/sunLightSSAOF.glsl | 308 ++++++++++++++++++++ .../shaders/class3/deferred/sunLightV.glsl | 41 +++ 8 files changed, 1463 insertions(+), 4 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/sunLightV.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl new file mode 100644 index 0000000000..864ba4859d --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -0,0 +1,314 @@ +/** + * @file multiSpotLightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +#extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_shader_texture_lod : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +uniform sampler2DRect depthMap; +uniform sampler2DRect normalMap; +uniform samplerCube environmentMap; +uniform sampler2DRect lightMap; +uniform sampler2D noiseMap; +uniform sampler2D projectionMap; +uniform sampler2D lightFunc; + +uniform mat4 proj_mat; //screen space to light space +uniform float proj_near; //near clip for projection +uniform vec3 proj_p; //plane projection is emitting from (in screen space) +uniform vec3 proj_n; +uniform float proj_focus; //distance from plane to begin blurring +uniform float proj_lod; //(number of mips in proj map) +uniform float proj_range; //range between near clip and far clip plane of projection +uniform float proj_ambient_lod; +uniform float proj_ambiance; +uniform float near_clip; +uniform float far_clip; + +uniform vec3 proj_origin; //origin of projection to be used for angular attenuation +uniform float sun_wash; +uniform int proj_shadow_idx; +uniform float shadow_fade; + +uniform vec3 center; +uniform float size; +uniform vec3 color; +uniform float falloff; + +VARYING vec4 vary_fragcoord; +uniform vec2 screen_res; + +uniform mat4 inv_proj; + +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); +vec3 decode_normal (vec2 enc); + +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.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); + + float det = min(lod/(proj_lod*0.5), 1.0); + + float d = min(dist.x, dist.y); + + d *= min(1, d * (proj_lod - lod)); + + float edge = 0.25*det; + + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; +} + +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)); + + float det = min(lod/(proj_lod*0.5), 1.0); + + float d = min(dist.x, dist.y); + + float edge = 0.25*det; + + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; +} + +vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) +{ + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); + + vec2 dist = tc-vec2(0.5); + + float d = dot(dist,dist); + + ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); + + return ret; +} + + +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +void main() +{ + vec4 frag = vary_fragcoord; + frag.xyz /= frag.w; + frag.xyz = frag.xyz*0.5+0.5; + frag.xy *= screen_res; + + vec3 pos = getPosition(frag.xy).xyz; + vec3 lv = center.xyz-pos.xyz; + float dist = length(lv); + dist /= size; + if (dist > 1.0) + { + discard; + } + + float shadow = 1.0; + + if (proj_shadow_idx >= 0) + { + vec4 shd = texture2DRect(lightMap, frag.xy); + float sh[2]; + sh[0] = shd.b; + sh[1] = shd.a; + shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0); + } + + vec3 norm = texture2DRect(normalMap, frag.xy).xyz; + + float envIntensity = norm.z; + + norm = decode_normal(norm.xy); + + norm = normalize(norm); + float l_dist = -dot(lv, proj_n); + + vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); + if (proj_tc.z < 0.0) + { + discard; + } + + proj_tc.xyz /= proj_tc.w; + + float fa = falloff+1.0; + float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0; + if (dist_atten <= 0.0) + { + discard; + } + + lv = proj_origin-pos.xyz; + lv = normalize(lv); + float da = dot(norm, lv); + + vec3 col = vec3(0,0,0); + + vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + + vec4 spec = texture2DRect(specularRect, frag.xy); + + vec3 dlit = vec3(0, 0, 0); + + float noise = texture2D(noiseMap, frag.xy/128.0).b; + if (proj_tc.z > 0.0 && + proj_tc.x < 1.0 && + proj_tc.y < 1.0 && + proj_tc.x > 0.0 && + proj_tc.y > 0.0) + { + float amb_da = proj_ambiance; + float lit = 0.0; + + if (da > 0.0) + { + lit = da * dist_atten * noise; + + float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); + float lod = diff * proj_lod; + + vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); + + dlit = color.rgb * plcol.rgb * plcol.a; + + col = dlit*lit*diff_tex*shadow; + amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; + } + + //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); + vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); + + amb_da += (da*da*0.5+0.5)*proj_ambiance; + + amb_da *= dist_atten * noise; + + amb_da = min(amb_da, 1.0-lit); + + col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; + } + + + if (spec.a > 0.0) + { + vec3 npos = -normalize(pos); + dlit *= min(da*6.0, 1.0) * dist_atten; + + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + col += dlit*scol*spec.rgb*shadow; + //col += spec.rgb; + } + } + + + + + + if (envIntensity > 0.0) + { + vec3 ref = reflect(normalize(pos), norm); + + //project from point pos in direction ref to plane proj_p, proj_n + vec3 pdelta = proj_p-pos; + float ds = dot(ref, proj_n); + + if (ds < 0.0) + { + vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; + + vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + + if (stc.z > 0.0) + { + stc /= stc.w; + + if (stc.x < 1.0 && + stc.y < 1.0 && + stc.x > 0.0 && + stc.y > 0.0) + { + col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; + } + } + } + } + + //not sure why, but this line prevents MATBUG-194 + col = max(col, vec3(0.0)); + + frag_color.rgb = col; + frag_color.a = 0.0; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index cd0efe8cbb..7bfc114383 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -55,7 +55,7 @@ void main() vec3 view_ray = (inv_modelview * vec4(view_pos.xyz, 0.0f)).xyz; vec3 view_direction = normalize(view_ray); - vec3 sun_direction = normalize(sun_dir); + vec3 sun_direction = normalize(sun_dir); vec3 camPos = (camPosLocal / 1000.0f) + vec3(0, 0, 6360.0f); vec3 transmittance; @@ -63,15 +63,20 @@ void main() vec3 solar_luminance = transmittance * GetSolarLuminance(); // If the view ray intersects the Sun, add the Sun radiance. - if (dot(view_direction, sun_direction) >= sun_size) + float s = dot(view_direction, sun_direction); + + // cheesy solar disc... + if (s >= (sun_size * 0.999)) { - radiance_sun += solar_luminance; + radiance_sun += pow(smoothstep(0.0, 1.3, (s - (sun_size * 0.9))), 2.0) * solar_luminance; } + s = smoothstep(0.9, 1.0, s) * 16.0f; vec3 color = vec3(1.0) - exp(-radiance_sun * 0.0001); + color = pow(color, vec3(1.0 / 2.2)); - frag_data[0] = vec4(color, 1.0); + frag_data[0] = vec4(color, 1.0 + s); frag_data[1] = vec4(0.0); frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl new file mode 100644 index 0000000000..bda33c3213 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -0,0 +1,189 @@ +/** + * @file softenLightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +uniform sampler2DRect normalMap; +uniform sampler2DRect lightMap; +uniform sampler2DRect depthMap; +uniform samplerCube environmentMap; +uniform sampler2D lightFunc; + +uniform float blur_size; +uniform float blur_fidelity; + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; +//uniform vec4 camPosWorld; +uniform vec4 gamma; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 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 vec4 glow; +uniform float global_gamma; +uniform float scene_light_strength; +uniform mat3 env_mat; +uniform vec4 shadow_clip; +uniform mat3 ssao_effect_mat; + +uniform vec3 sun_dir; +VARYING vec2 vary_fragcoord; + +uniform mat4 inv_proj; +uniform mat4 inv_modelview; + +uniform vec2 screen_res; + +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); +vec3 decode_normal (vec2 enc); + +vec4 getPosition_d(vec2 pos_screen, float depth) +{ + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec4 getPosition(vec2 pos_screen) +{ //get position in screen space (world units) given window coordinate and depth map + float depth = texture2DRect(depthMap, pos_screen.xy).r; + return getPosition_d(pos_screen, depth); +} + + +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif + +void main() +{ + vec2 tc = vary_fragcoord.xy; + float depth = texture2DRect(depthMap, tc.xy).r; + vec3 pos = getPosition_d(tc, depth).xyz; + vec4 norm = texture2DRect(normalMap, tc); + float envIntensity = norm.z; + norm.xyz = decode_normal(norm.xy); // unpack norm + + float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); + + float light_gamma = 1.0/1.3; + da = pow(da, light_gamma); + + + vec4 diffuse = texture2DRect(diffuseRect, tc); + + //convert to gamma space + diffuse.rgb = linear_to_srgb(diffuse.rgb); + + vec3 col; + 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(light_gamma)); + + float scol = max(scol_ambocc.r, diffuse.a); + + float ambocc = scol_ambocc.g; + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + //calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); + //col += atmosFragAffectDirectionalLight(max(min(da, scol), 0.0), sunlit); + + col *= diffuse.rgb; + + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + + if (spec.a > 0.0) // specular reflection + { + // the old infinite-sky shiny reflection + // + + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + col += spec_contrib; + } + + + col = mix(col, diffuse.rgb, diffuse.a); + + 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); + } + + if (norm.w < 0.5) + { + //col = mix(atmosFragLighting(col, additive, atten), fullbrightFragAtmosTransport(col, atten, additive), diffuse.a); + //col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a); + } + + #ifdef WATER_FOG + vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); + col = fogged.rgb; + bloom = fogged.a; + #endif + + col = srgb_to_linear(col); + } + + frag_color.rgb = col; + frag_color.a = bloom; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl new file mode 100644 index 0000000000..c840d72784 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl @@ -0,0 +1,42 @@ +/** + * @file softenLightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + +uniform vec2 screen_res; + +VARYING vec2 vary_fragcoord; + +void main() +{ + //transform vertex + vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + gl_Position = pos; + + + vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl new file mode 100644 index 0000000000..a7da140b31 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -0,0 +1,313 @@ +/** + * @file spotLightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +#extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_shader_texture_lod : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +uniform sampler2DRect depthMap; +uniform sampler2DRect normalMap; +uniform samplerCube environmentMap; +uniform sampler2DRect lightMap; +uniform sampler2D noiseMap; +uniform sampler2D projectionMap; +uniform sampler2D lightFunc; + +uniform mat4 proj_mat; //screen space to light space +uniform float proj_near; //near clip for projection +uniform vec3 proj_p; //plane projection is emitting from (in screen space) +uniform vec3 proj_n; +uniform float proj_focus; //distance from plane to begin blurring +uniform float proj_lod; //(number of mips in proj map) +uniform float proj_range; //range between near clip and far clip plane of projection +uniform float proj_ambient_lod; +uniform float proj_ambiance; +uniform float near_clip; +uniform float far_clip; + +uniform vec3 proj_origin; //origin of projection to be used for angular attenuation +uniform float sun_wash; +uniform int proj_shadow_idx; +uniform float shadow_fade; + +uniform float size; +uniform vec3 color; +uniform float falloff; + +VARYING vec3 trans_center; +VARYING vec4 vary_fragcoord; +uniform vec2 screen_res; + +uniform mat4 inv_proj; + +vec3 decode_normal (vec2 enc); +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); + +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.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); + + float det = min(lod/(proj_lod*0.5), 1.0); + + float d = min(dist.x, dist.y); + + d *= min(1, d * (proj_lod - lod)); + + float edge = 0.25*det; + + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; +} + +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)); + + float det = min(lod/(proj_lod*0.5), 1.0); + + float d = min(dist.x, dist.y); + + float edge = 0.25*det; + + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; +} + +vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) +{ + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); + + vec2 dist = tc-vec2(0.5); + + float d = dot(dist,dist); + + ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); + + return ret; +} + + +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +void main() +{ + vec4 frag = vary_fragcoord; + frag.xyz /= frag.w; + frag.xyz = frag.xyz*0.5+0.5; + frag.xy *= screen_res; + + vec3 pos = getPosition(frag.xy).xyz; + vec3 lv = trans_center.xyz-pos.xyz; + float dist = length(lv); + dist /= size; + if (dist > 1.0) + { + discard; + } + + float shadow = 1.0; + + if (proj_shadow_idx >= 0) + { + vec4 shd = texture2DRect(lightMap, frag.xy); + float sh[2]; + sh[0] = shd.b; + sh[1] = shd.a; + shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0); + } + + vec3 norm = texture2DRect(normalMap, frag.xy).xyz; + float envIntensity = norm.z; + norm = decode_normal(norm.xy); + + norm = normalize(norm); + float l_dist = -dot(lv, proj_n); + + vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); + if (proj_tc.z < 0.0) + { + discard; + } + + proj_tc.xyz /= proj_tc.w; + + float fa = falloff + 1.0; + float dist_atten = min(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0; + + if (dist_atten <= 0.0) + { + discard; + } + + lv = proj_origin-pos.xyz; + lv = normalize(lv); + float da = dot(norm, lv); + + vec3 col = vec3(0,0,0); + + vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + + vec4 spec = texture2DRect(specularRect, frag.xy); + + vec3 dlit = vec3(0, 0, 0); + + float noise = texture2D(noiseMap, frag.xy/128.0).b; + if (proj_tc.z > 0.0 && + proj_tc.x < 1.0 && + proj_tc.y < 1.0 && + proj_tc.x > 0.0 && + proj_tc.y > 0.0) + { + float amb_da = proj_ambiance; + float lit = 0.0; + + if (da > 0.0) + { + lit = da * dist_atten * noise; + + float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); + float lod = diff * proj_lod; + + vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); + + dlit = color.rgb * plcol.rgb * plcol.a; + + col = dlit*lit*diff_tex*shadow; + amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; + } + + //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); + vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); + + amb_da += (da*da*0.5+0.5)*proj_ambiance; + + amb_da *= dist_atten * noise; + + amb_da = min(amb_da, 1.0-lit); + + col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; + } + + + if (spec.a > 0.0) + { + dlit *= min(da*6.0, 1.0) * dist_atten; + vec3 npos = -normalize(pos); + + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + col += dlit*scol*spec.rgb*shadow; + //col += spec.rgb; + } + } + + + + + + if (envIntensity > 0.0) + { + vec3 ref = reflect(normalize(pos), norm); + + //project from point pos in direction ref to plane proj_p, proj_n + vec3 pdelta = proj_p-pos; + float ds = dot(ref, proj_n); + + if (ds < 0.0) + { + vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; + + vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + + if (stc.z > 0.0) + { + stc /= stc.w; + + if (stc.x < 1.0 && + stc.y < 1.0 && + stc.x > 0.0 && + stc.y > 0.0) + { + col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; + } + } + } + } + + //not sure why, but this line prevents MATBUG-194 + col = max(col, vec3(0.0)); + + frag_color.rgb = col; + frag_color.a = 0.0; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl new file mode 100644 index 0000000000..aa5e99a2f7 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl @@ -0,0 +1,247 @@ +/** + * @file sunLightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +//class 2, shadows, no SSAO + +uniform sampler2DRect depthMap; +uniform sampler2DRect normalMap; +uniform sampler2DShadow shadowMap0; +uniform sampler2DShadow shadowMap1; +uniform sampler2DShadow shadowMap2; +uniform sampler2DShadow shadowMap3; +uniform sampler2DShadow shadowMap4; +uniform sampler2DShadow shadowMap5; + + +// Inputs +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform float ssao_radius; +uniform float ssao_max_radius; +uniform float ssao_factor; +uniform float ssao_factor_inv; + +VARYING vec2 vary_fragcoord; + +uniform mat4 inv_proj; +uniform vec2 screen_res; +uniform vec2 proj_shadow_res; +uniform vec3 sun_dir; + +uniform vec2 shadow_res; +uniform float shadow_bias; +uniform float shadow_offset; + +uniform float spot_shadow_bias; +uniform float spot_shadow_offset; + +vec3 decode_normal (vec2 enc); + +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) +{ + stc.xyz /= stc.w; + stc.z += shadow_bias; + + stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*0.666666666))/shadow_res.x; // add some jitter to X sample pos according to Y to disguise the snapping going on here + float cs = shadow2D(shadowMap, stc.xyz).x; + + float shadow = cs; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + + + return shadow*0.2; +} + +float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) +{ + stc.xyz /= stc.w; + stc.z += spot_shadow_bias*scl; + stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + + vec2 off = 1.0/proj_shadow_res; + off.y *= 1.5; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; + + return shadow*0.2; +} + +void main() +{ + vec2 pos_screen = vary_fragcoord.xy; + + //try doing an unproject here + + vec4 pos = getPosition(pos_screen); + + vec3 norm = texture2DRect(normalMap, pos_screen).xyz; + norm = decode_normal(norm.xy); // unpack norm + + /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL + { + frag_color = vec4(0.0); // doesn't matter + return; + }*/ + + float shadow = 0.0; + float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); + + vec3 shadow_pos = pos.xyz; + vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); + + vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); + + if (spos.z > -shadow_clip.w) + { + if (dp_directional_light == 0.0) + { + // if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup + shadow = 0.0; + } + else + { + vec4 lpos; + + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + if (spos.z < near_split.z) + { + lpos = shadow_matrix[3]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + if (spos.z < near_split.y && spos.z > far_split.z) + { + lpos = shadow_matrix[2]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; + w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen)*w; + weight += w; + } + + if (spos.z < near_split.x && spos.z > far_split.y) + { + lpos = shadow_matrix[1]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; + w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen)*w; + weight += w; + } + + if (spos.z > far_split.x) + { + lpos = shadow_matrix[0]*spos; + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; + weight += w; + } + + + shadow /= weight; + + // take the most-shadowed value out of these two: + // * the blurred sun shadow in the light (shadow) map + // * an unblurred dot product between the sun and this norm + // the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting + shadow = min(shadow, dp_directional_light); + + //lpos.xy /= lpos.w*32.0; + //if (fract(lpos.x) < 0.1 || fract(lpos.y) < 0.1) + //{ + // shadow = 0.0; + //} + + } + } + else + { + // more distant than the shadow map covers + shadow = 1.0; + } + + frag_color[0] = shadow; + frag_color[1] = 1.0; + + spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); + + //spotlight shadow 1 + vec4 lpos = shadow_matrix[4]*spos; + frag_color[2] = pcfSpotShadow(shadowMap4, lpos, 0.8, pos_screen); + + //spotlight shadow 2 + lpos = shadow_matrix[5]*spos; + frag_color[3] = pcfSpotShadow(shadowMap5, lpos, 0.8, pos_screen); + + //frag_color.rgb = pos.xyz; + //frag_color.b = shadow; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl new file mode 100644 index 0000000000..58f3f2f91e --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl @@ -0,0 +1,308 @@ +/** + * @file sunLightSSAOF.glsl + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +//class 2 -- shadows and SSAO + +uniform sampler2DRect depthMap; +uniform sampler2DRect normalMap; +uniform sampler2DShadow shadowMap0; +uniform sampler2DShadow shadowMap1; +uniform sampler2DShadow shadowMap2; +uniform sampler2DShadow shadowMap3; +uniform sampler2DShadow shadowMap4; +uniform sampler2DShadow shadowMap5; +uniform sampler2D noiseMap; + + +// Inputs +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform float ssao_radius; +uniform float ssao_max_radius; +uniform float ssao_factor; +uniform float ssao_factor_inv; + +VARYING vec2 vary_fragcoord; + +uniform mat4 inv_proj; +uniform vec2 screen_res; +uniform vec2 proj_shadow_res; +uniform vec3 sun_dir; + +uniform vec2 shadow_res; + +uniform float shadow_bias; +uniform float shadow_offset; + +uniform float spot_shadow_bias; +uniform float spot_shadow_offset; + +vec3 decode_normal (vec2 enc); + +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec2 getKern(int i) +{ + vec2 kern[8]; + // exponentially (^2) distant occlusion samples spread around origin + kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; + kern[1] = vec2(1.0, 0.0) * 0.250*0.250; + kern[2] = vec2(0.0, 1.0) * 0.375*0.375; + kern[3] = vec2(0.0, -1.0) * 0.500*0.500; + kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; + kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; + kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; + kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; + + return kern[i]; +} + +//calculate decreases in ambient lighting when crowded out (SSAO) +float calcAmbientOcclusion(vec4 pos, vec3 norm) +{ + float ret = 1.0; + + vec2 pos_screen = vary_fragcoord.xy; + vec3 pos_world = pos.xyz; + vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; + + float angle_hidden = 0.0; + float points = 0; + + float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); + + // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) + for (int i = 0; i < 8; i++) + { + vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); + vec3 samppos_world = getPosition(samppos_screen).xyz; + + vec3 diff = pos_world - samppos_world; + float dist2 = dot(diff, diff); + + // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area + // --> solid angle shrinking by the square of distance + //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 + //(k should vary inversely with # of samples, but this is taken care of later) + + float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; + angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); + + // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" + float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; + points = points + diffz_val; + } + + angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); + + float points_val = (points > 0.0) ? 1.0 : 0.0; + ret = (1.0 - (points_val * angle_hidden)); + + ret = max(ret, 0.0); + return min(ret, 1.0); +} + +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) +{ + stc.xyz /= stc.w; + stc.z += shadow_bias; + + stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*0.666666666))/shadow_res.x; + float cs = shadow2D(shadowMap, stc.xyz).x; + + float shadow = cs; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + + return shadow*0.2; +} + +float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) +{ + stc.xyz /= stc.w; + stc.z += spot_shadow_bias*scl; + stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + + vec2 off = 1.0/proj_shadow_res; + off.y *= 1.5; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; + + return shadow*0.2; +} + +void main() +{ + vec2 pos_screen = vary_fragcoord.xy; + + //try doing an unproject here + + vec4 pos = getPosition(pos_screen); + + vec3 norm = texture2DRect(normalMap, pos_screen).xyz; + norm = decode_normal(norm.xy); // unpack norm + + /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL + { + frag_color = vec4(0.0); // doesn't matter + return; + }*/ + + float shadow = 0.0; + float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); + + vec3 shadow_pos = pos.xyz; + vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); + + vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); + + if (spos.z > -shadow_clip.w) + { + if (dp_directional_light == 0.0) + { + // if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup + shadow = 0.0; + } + else + { + vec4 lpos; + + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + if (spos.z < near_split.z) + { + lpos = shadow_matrix[3]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + if (spos.z < near_split.y && spos.z > far_split.z) + { + lpos = shadow_matrix[2]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; + w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen)*w; + weight += w; + } + + if (spos.z < near_split.x && spos.z > far_split.y) + { + lpos = shadow_matrix[1]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; + w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen)*w; + weight += w; + } + + if (spos.z > far_split.x) + { + lpos = shadow_matrix[0]*spos; + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; + weight += w; + } + + + shadow /= weight; + + // take the most-shadowed value out of these two: + // * the blurred sun shadow in the light (shadow) map + // * an unblurred dot product between the sun and this norm + // the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting + shadow = min(shadow, dp_directional_light); + + //lpos.xy /= lpos.w*32.0; + //if (fract(lpos.x) < 0.1 || fract(lpos.y) < 0.1) + //{ + // shadow = 0.0; + //} + + } + } + else + { + // more distant than the shadow map covers + shadow = 1.0; + } + + frag_color[0] = shadow; + frag_color[1] = calcAmbientOcclusion(pos, norm); + + spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); + + //spotlight shadow 1 + vec4 lpos = shadow_matrix[4]*spos; + frag_color[2] = pcfSpotShadow(shadowMap4, lpos, 0.8, pos_screen); + + //spotlight shadow 2 + lpos = shadow_matrix[5]*spos; + frag_color[3] = pcfSpotShadow(shadowMap5, lpos, 0.8, pos_screen); + + //frag_color.rgb = pos.xyz; + //frag_color.b = shadow; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightV.glsl new file mode 100644 index 0000000000..bc5eb5181d --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightV.glsl @@ -0,0 +1,41 @@ +/** + * @file sunLightV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + +VARYING vec2 vary_fragcoord; + +uniform vec2 screen_res; + +void main() +{ + //transform vertex + vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + gl_Position = pos; + + vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res; +} -- cgit v1.2.3 From 2f9d08f48d879b1f8929cff513fe07359e80043d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 13 Sep 2018 22:08:06 +0100 Subject: Spruce up the non-ALM stars too. --- .../newview/app_settings/shaders/class1/interface/customalphaF.glsl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/interface/customalphaF.glsl b/indra/newview/app_settings/shaders/class1/interface/customalphaF.glsl index a96d04cc39..f6b31a5956 100644 --- a/indra/newview/app_settings/shaders/class1/interface/customalphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/customalphaF.glsl @@ -38,7 +38,9 @@ VARYING vec2 vary_texcoord0; void main() { - vec4 color = vertex_color*texture2D(diffuseMap, vary_texcoord0.xy); - color.a *= custom_alpha; + vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); + color.rgb = pow(color.rgb, vec3(0.45)); + color.rgb *= vertex_color.rgb; + color.a *= max(custom_alpha, vertex_color.a); frag_color = color; } -- cgit v1.2.3 From a167f8857fd242e007a6bcbcee80a54a953f29f3 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 14 Sep 2018 18:42:41 +0100 Subject: SL-1491 Fix name at top of the 3 softenLight shaders so we can differentiate which is in use when using nSight debug. Made class2 softenLightF shader modulate the atmospherics additive to only specular shading to fix lens flare on terrain etc. --- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 11 +++-------- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index ec3c0cb68d..4e11a7e2f5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -1,5 +1,5 @@ /** - * @file softenLightF.glsl + * @file class1/deferred/softenLightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 1e2c49215f..c7950a2a31 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -165,8 +165,6 @@ void main() if (spec.a > 0.0) // specular reflection { // the old infinite-sky shiny reflection - // - float sa = dot(refnormpersp, sun_dir.xyz); vec3 dumbshiny = sunlit*scol_ambocc.r*(texture2D(lightFunc, vec2(sa, spec.a)).r); @@ -182,17 +180,14 @@ void main() 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); - + col = mix(col.rgb, refcol, envIntensity); } if (norm.w < 0.5) { - col = mix(atmosFragLighting(col, additive, atten), fullbrightFragAtmosTransport(col, atten, additive), diffuse.a); + vec3 add = additive * spec.a; + col = mix(atmosFragLighting(col, add, atten), fullbrightFragAtmosTransport(col, atten, add), diffuse.a); col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index bda33c3213..d2fd70c9e2 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -1,5 +1,5 @@ /** - * @file softenLightF.glsl + * @file class3/deferred/softenLightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code -- cgit v1.2.3 From 1df7760d315430766bba44d4d4c64480b4a6138f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 14 Sep 2018 21:52:52 +0100 Subject: SL-9632 add uniform and code to supress atmospherics in all shaders that could be used by HUDs Make sky and cloud shaders use common scaleSoftClip implementation in gammaF.glsl --- .../shaders/class1/deferred/cloudsF.glsl | 8 +------- .../shaders/class1/deferred/fullbrightF.glsl | 2 +- .../app_settings/shaders/class1/deferred/skyF.glsl | 8 +------- .../shaders/class1/objects/fullbrightF.glsl | 2 +- .../shaders/class2/windlight/atmosphericsF.glsl | 14 ++++++++++--- .../shaders/class2/windlight/cloudsF.glsl | 8 +------- .../shaders/class2/windlight/gammaF.glsl | 9 ++++++-- .../shaders/class2/windlight/skyF.glsl | 8 +------- .../shaders/class2/windlight/transportF.glsl | 22 +++++++++++++++----- .../shaders/class3/deferred/cloudsF.glsl | 8 +------- .../shaders/class3/windlight/transportF.glsl | 24 ++++++++++++++++------ 11 files changed, 60 insertions(+), 53 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 3f81e3b0af..c1a9a6f454 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -51,13 +51,7 @@ VARYING vec2 vary_texcoord2; VARYING vec2 vary_texcoord3; /// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light) { - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} +vec3 scaleSoftClip(vec3 light); vec4 cloudNoise(vec2 uv) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 134e9c3b4c..0e21e5925d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -1,5 +1,5 @@ /** - * @file fullbrightF.glsl + * @file deferred/fullbrightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 8e4696cfaa..0613111632 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -40,13 +40,7 @@ VARYING vec4 vary_HazeColor; uniform vec4 gamma; /// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light) { - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} +vec3 scaleSoftClip(vec3 light); void main() { diff --git a/indra/newview/app_settings/shaders/class1/objects/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/objects/fullbrightF.glsl index a54c0caf81..31a262f1db 100644 --- a/indra/newview/app_settings/shaders/class1/objects/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/fullbrightF.glsl @@ -1,5 +1,5 @@ /** - * @file fullbrightF.glsl + * @file objects/fullbrightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index fee1a7f311..4ec5691a85 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -43,9 +43,14 @@ uniform float max_y; uniform vec4 glow; uniform float scene_light_strength; uniform mat3 ssao_effect_mat; +uniform int no_atmo; vec3 scaleFragSoftClip(vec3 light) { + if (no_atmo == 1) + { + return light; + } //soft clip effect: light = 1. - clamp(light, vec3(0.), vec3(1.)); light = 1. - pow(light, gamma.xxx); @@ -54,14 +59,17 @@ vec3 scaleFragSoftClip(vec3 light) vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { - light *= atten.r; - light += additive; + if (no_atmo == 0) + { + light *= atten.r; + light += additive; + } return (2.0 * light); } vec3 atmosLighting(vec3 light) { - return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); + return (no_atmo == 1) ? light : atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); } void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index e0c7e18a6f..24fdb45749 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -49,13 +49,7 @@ uniform vec4 cloud_pos_density2; uniform vec4 gamma; /// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light) { - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} +vec3 scaleSoftClip(vec3 light); vec4 cloudNoise(vec2 uv) { diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index 2db633cd01..f2764b72c3 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -26,11 +26,16 @@ uniform vec4 gamma; +uniform int no_atmo; vec3 getAtmosAttenuation(); /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light) { + if (no_atmo == 1) + { + return light; + } //soft clip effect: light = 1. - clamp(light, vec3(0.), vec3(1.)); light = 1. - pow(light, gamma.xxx); @@ -40,10 +45,10 @@ vec3 scaleSoftClip(vec3 light) { vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 atten) { - return mix(scaleSoftClip(light.rgb), light.rgb, atten); + return (no_atmo == 1) ? light : mix(scaleSoftClip(light.rgb), light.rgb, atten); } vec3 fullbrightScaleSoftClip(vec3 light) { - return fullbrightScaleSoftClipFrag(light.rgb, getAtmosAttenuation()); + return (no_atmo == 1) ? light : fullbrightScaleSoftClipFrag(light.rgb, getAtmosAttenuation()); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl index 25fd0584f8..28d185b9af 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl @@ -38,13 +38,7 @@ VARYING vec4 vary_HazeColor; uniform vec4 gamma; /// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light) { - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} +vec3 scaleSoftClip(vec3 light); void main() { diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 82e1d7fe35..9627642b9d 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -32,31 +32,43 @@ vec3 getAtmosAttenuation(); uniform sampler2D cloudMap; uniform vec4 cloud_pos_density1; +uniform int no_atmo; vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { - light *= atten.r; - light += additive * 2.0; + if (no_atmo == 0) + { + light *= atten.r; + light += additive * 2.0; + } return light; } vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { + if (no_atmo == 1) + { + return light; + } float brightness = dot(light.rgb, vec3(0.33333)); return mix(atmosFragTransport(light.rgb, atten, additive), light.rgb + additive.rgb, brightness * brightness); } vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) { + if (no_atmo == 1) + { + return light; + } float brightness = dot(light.rgb, vec3(0.33333)); return mix(atmosFragTransport(light.rgb, atten, additive), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); } vec3 atmosTransport(vec3 light) { - return atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); + return (no_atmo == 1) ? light : atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); } vec3 fullbrightAtmosTransport(vec3 light) { - return fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); + return (no_atmo == 1) ? light : fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); } vec3 fullbrightShinyAtmosTransport(vec3 light) { - return fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); + return (no_atmo == 1) ? light : fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl index 44b41cc0b8..d9fcc0a9ea 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -58,13 +58,7 @@ vec4 cloudNoise(vec2 uv) /// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light) { - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} +vec3 scaleSoftClip(vec3 light); void main() { diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index 82e1d7fe35..e8e9c53c38 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -32,31 +32,43 @@ vec3 getAtmosAttenuation(); uniform sampler2D cloudMap; uniform vec4 cloud_pos_density1; +uniform int no_atmo; vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { - light *= atten.r; - light += additive * 2.0; + if (no_atmo == 0) + { + light *= atten.r; + light += additive * 2.0; + } return light; } vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { - float brightness = dot(light.rgb, vec3(0.33333)); + if (no_atmo) + { + return light; + } + loat brightness = dot(light.rgb, vec3(0.33333)); return mix(atmosFragTransport(light.rgb, atten, additive), light.rgb + additive.rgb, brightness * brightness); } vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) { + if (no_atmo) + { + return light; + } float brightness = dot(light.rgb, vec3(0.33333)); return mix(atmosFragTransport(light.rgb, atten, additive), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); } vec3 atmosTransport(vec3 light) { - return atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); + return no_atmo ? light : atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); } vec3 fullbrightAtmosTransport(vec3 light) { - return fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); + return no_atmo ? light : fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); } vec3 fullbrightShinyAtmosTransport(vec3 light) { - return fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); + return no_atmo ? light : fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); } -- cgit v1.2.3 From 57d89c80945ee0944f745b812487b6e3c16631d2 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 17 Sep 2018 19:40:21 +0100 Subject: SL-1491 take two: fix non-ALM/class2 atmospherics additive artifacts Modulate class1 softenLight atmospheric additive by specular.a (same fix as for class2). Clamp additive color to <= vec3(0.2) to avoid similar artifacts in non-deferred render path. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 3 ++- .../app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 4e11a7e2f5..7a1968efee 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -174,7 +174,8 @@ void main() if (norm.w < 0.5) { - col = mix(atmosFragLighting(col, additive, atten), fullbrightFragAtmosTransport(col, atten, additive), diffuse.a); + vec3 add = additive * spec.a; + col = mix(atmosFragLighting(col, add, atten), fullbrightFragAtmosTransport(col, atten, add), diffuse.a); col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl index 99dbee15ee..3b87c70932 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl @@ -73,6 +73,9 @@ void setAmblitColor(vec3 v) void setAdditiveColor(vec3 v) { + // SL-1491 clamp additive term to something reasonable to prevent + // lens flares over non-reflective surfaces + v = clamp(v, vec3(0), vec3(0.2)); additive_color = v; vary_AdditiveColor = v; } -- cgit v1.2.3 From eb5038fe755fd90b927359cd9fccd9ef2e951ca5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 17 Sep 2018 20:09:58 +0100 Subject: SL-9618 Remove extraneous linear to sRGB conversion causing underwater refracted screen tex to be brighter than it should be. --- indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index 3a8565ee38..db1eab23fb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -115,7 +115,7 @@ void main() vec4 fb = texture2D(screenTex, distort); - frag_data[0] = vec4(linear_to_srgb(fb.rgb), 1.0); // diffuse + frag_data[0] = vec4(fb.rgb, 1.0); // diffuse frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, displace } -- cgit v1.2.3 From 08dd04aa98f9071d87a26573fb2807aaac1852eb Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Sep 2018 19:47:50 +0100 Subject: SL-1176 Tweak position of sun in disc shader to better match the offset applied to the sun glow in atmospherics. --- indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl index 5b4302e237..c67ed8e6d9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl @@ -37,7 +37,7 @@ void calcAtmospherics(vec3 eye_pos); void main() { //transform vertex - vec4 vert = vec4(position.xyz, 1.0); + vec4 vert = vec4(position.xyz - vec3(0, 0, 50), 1.0); vec4 pos = modelview_projection_matrix*vert; gl_Position = pos; diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl index 90acb5be9e..dd33a4be60 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl @@ -37,7 +37,7 @@ void calcAtmospherics(vec3 eye_pos); void main() { //transform vertex - vec4 vert = vec4(position.xyz, 1.0); + vec4 vert = vec4(position.xyz - vec3(0, 0, 50), 1.0); vec4 pos = modelview_projection_matrix*vert; gl_Position = pos; -- cgit v1.2.3 From c9b2759469cb090b76a7d602eb876659c305c7f3 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Sep 2018 21:54:38 +0100 Subject: SL-1475 Make stars use higher alpha and brighten reflected color before mixing to get stars to show up in reflections on water. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 98c5030a04..aeec247514 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -167,6 +167,7 @@ void main() //mix with reflection // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug + refcol.rgb = pow(refcol.rgb, vec3(0.45)); // boost the reflect color a little to get stars to show up SL-1475 color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); vec4 pos = vary_position; -- cgit v1.2.3 From bc787063aaa775349bc3afebbdfda6c977dcadff Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 19 Sep 2018 20:41:14 +0100 Subject: SL-1505 Prepend dir names to comments in water shaders to differentiate them in nSight captures. Fix calc of reflection camera modelview mats to properly reflect the environment. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 2 +- indra/newview/app_settings/shaders/class1/environment/waterF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index aeec247514..a29acb3e7d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -1,5 +1,5 @@ /** - * @file waterF.glsl + * @file class1/deferred/waterF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index 37f109c637..19158f4505 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -1,5 +1,5 @@ /** - * @file waterF.glsl + * @file class1/environment/waterF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code -- cgit v1.2.3 From 501cd7d9022d1ac719fb56d22c6a8e3fd5d122ca Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 24 Sep 2018 19:50:08 +0100 Subject: SL-9711 modify clamping range on atmospheric additive color to balance between maintaining old look of WL settings and fixing SL1491 lens flare bug --- .../app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl index 3b87c70932..414ba3236a 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl @@ -75,7 +75,7 @@ void setAdditiveColor(vec3 v) { // SL-1491 clamp additive term to something reasonable to prevent // lens flares over non-reflective surfaces - v = clamp(v, vec3(0), vec3(0.2)); + v = clamp(v, vec3(0), vec3(0.8)); additive_color = v; vary_AdditiveColor = v; } -- cgit v1.2.3 From 5eed233618abd7020e130799be2abe0f986543f6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 5 Oct 2018 21:32:42 +0100 Subject: SL-1925 More settings for rainbow/halo atmospheric effects, final default asset UUIDs, and shader mods. --- .../app_settings/shaders/class3/deferred/skyF.glsl | 40 +++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index 7bfc114383..2073fc066f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -42,25 +42,46 @@ uniform sampler2D transmittance_texture; uniform sampler3D scattering_texture; uniform sampler3D single_mie_scattering_texture; uniform sampler2D irradiance_texture; +uniform sampler2D rainbow_map; +uniform sampler2D halo_map; + +uniform float moisture_level; +uniform float droplet_radius; +uniform float ice_level; vec3 GetSolarLuminance(); vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); +vec3 rainbow(float d) +{ + float rad = (droplet_radius - 5.0f) / 1024.0f; + return pow(texture2D(rainbow_map, vec2(rad, d)).rgb, vec3(1.8)) * moisture_level; +} + +vec3 halo22(float d) +{ + float v = sqrt(max(0, 1 - (d*d))); + return texture2D(halo_map, vec2(0, v)).rgb * ice_level; +} + void main() { - vec3 pos = vec3((vary_frag * 2.0) - vec2(1.0, 1.0), 0.0); + vec3 pos = vec3((vary_frag * 2.0) - vec2(1.0, 1.0f), 1.0); vec4 view_pos = (inv_proj * vec4(pos, 1.0f)); + view_pos /= view_pos.w; - vec3 view_ray = (inv_modelview * vec4(view_pos.xyz, 0.0f)).xyz; + + vec3 view_ray = (inv_modelview * vec4(view_pos.xyz, 0.0f)).xyz + camPosLocal; vec3 view_direction = normalize(view_ray); vec3 sun_direction = normalize(sun_dir); + vec3 earth_center = vec3(0, 0, -6360.0f); + vec3 camPos = (camPosLocal / 1000.0f) - earth_center; - vec3 camPos = (camPosLocal / 1000.0f) + vec3(0, 0, 6360.0f); vec3 transmittance; vec3 radiance_sun = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); - vec3 solar_luminance = transmittance * GetSolarLuminance(); + vec3 solar_luminance = GetSolarLuminance(); // If the view ray intersects the Sun, add the Sun radiance. float s = dot(view_direction, sun_direction); @@ -68,12 +89,21 @@ void main() // cheesy solar disc... if (s >= (sun_size * 0.999)) { - radiance_sun += pow(smoothstep(0.0, 1.3, (s - (sun_size * 0.9))), 2.0) * solar_luminance; + radiance_sun += pow(smoothstep(0.0, 1.3, (s - (sun_size * 0.9))), 2.0) * solar_luminance * transmittance; } s = smoothstep(0.9, 1.0, s) * 16.0f; vec3 color = vec3(1.0) - exp(-radiance_sun * 0.0001); + float optic_d = dot(view_direction, sun_direction); + + vec3 halo_22 = halo22(optic_d); + + if (optic_d <= 0) + color.rgb += rainbow(optic_d); + + color.rgb += halo_22; + color = pow(color, vec3(1.0 / 2.2)); frag_data[0] = vec4(color, 1.0 + s); -- cgit v1.2.3 From ffc6393309d06446f9d1361f0f0282b2110768ae Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 8 Oct 2018 22:08:35 +0100 Subject: SL-9751 Add optional moon brightness setting --- .../app_settings/shaders/class1/deferred/moonF.glsl | 15 ++++++++++++--- .../app_settings/shaders/class1/windlight/moonF.glsl | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index e86bca3ddd..f65a6eb32b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -39,6 +39,7 @@ vec3 fullbrightScaleSoftClip(vec3 light); uniform vec4 color; uniform vec4 sunlight_color; uniform vec3 lumWeights; +uniform float moon_brightness; uniform float minLuminance; uniform sampler2D diffuseMap; uniform sampler2D altDiffuseMap; @@ -51,15 +52,23 @@ void main() vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(moonA, moonB, blend_factor); + if (c.a < 0.1f) + { + discard; + } + c.rgb = pow(c.rgb, vec3(0.7f)); c.rgb = fullbrightAtmosTransport(c.rgb); c.rgb = fullbrightScaleSoftClip(c.rgb); // mix factor which blends when sunlight is brighter // and shows true moon color at night - vec3 luma_weights = vec3(0.1, 0.3, 0.0); - float mix = 1.0f - dot(sunlight_color.rgb, luma_weights); - frag_data[0] = vec4(c.rgb, mix * c.a); + vec3 luma_weights = vec3(0.2, 0.3, 0.2); + float mix = 1.0f - dot(normalize(sunlight_color.rgb), luma_weights); + + c.rgb = pow(c.rgb, 1.2 - vec3(mix * moon_brightness)); + + frag_data[0] = vec4(c.rgb, mix * (moon_brightness + (c.a * 0.25))); frag_data[1] = vec4(0.0); frag_data[2] = vec4(0.0f); } diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl index 933625986c..8cc7fc3bb5 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -39,6 +39,7 @@ vec3 fullbrightScaleSoftClip(vec3 light); uniform vec4 color; uniform vec4 sunlight_color; uniform vec3 lumWeights; +uniform float moon_brightness; uniform float minLuminance; uniform sampler2D diffuseMap; uniform sampler2D altDiffuseMap; @@ -51,13 +52,22 @@ void main() vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(moonA, moonB, blend_factor); - c.rgb = pow(c.rgb, vec3(0.45f)); + if (c.a < 0.1f) + { + discard; + } + + c.rgb = pow(c.rgb, vec3(0.7f)); c.rgb = fullbrightAtmosTransport(c.rgb); c.rgb = fullbrightScaleSoftClip(c.rgb); + // mix factor which blends when sunlight is brighter // and shows true moon color at night - vec3 luma_weights = vec3(0.1, 0.3, 0.0); - float mix = 1.0f - dot(sunlight_color.rgb, luma_weights); - frag_color = vec4(c.rgb, mix * c.a); + vec3 luma_weights = vec3(0.2, 0.3, 0.2); + float mix = 1.0f - dot(normalize(sunlight_color.rgb), luma_weights); + + c.rgb = pow(c.rgb, 1.2 - vec3(mix * moon_brightness)); + + frag_color = vec4(c.rgb, mix * (moon_brightness + (c.a * 0.25))); } -- cgit v1.2.3 From f8aac192378462b5824d28808ed84833e2cbfe0f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 9 Oct 2018 18:44:43 +0100 Subject: SL-1289 add cloud_variance control for randomized perturbance of clouds to break up tiling monotony --- .../shaders/class1/deferred/cloudsF.glsl | 13 +++++--- .../shaders/class2/windlight/cloudsF.glsl | 31 ++++++++++-------- .../shaders/class3/deferred/cloudsF.glsl | 37 ++++++++++++---------- 3 files changed, 48 insertions(+), 33 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index c1a9a6f454..caedd25221 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -44,6 +44,8 @@ uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; uniform vec4 gamma; +uniform float cloud_scale; +uniform float cloud_variance; VARYING vec2 vary_texcoord0; VARYING vec2 vary_texcoord1; @@ -73,16 +75,19 @@ void main() vec2 uv3 = vary_texcoord2.xy; vec2 uv4 = vary_texcoord3.xy; + vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + // Offset texture coords - uv1 += cloud_pos_density1.xy; //large texture, visible density + uv1 += cloud_pos_density1.xy + disturbance; //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density + uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.); + alpha1 = min(max(alpha1 + cloudDensity, 0.) * (10. + disturbance.y) * cloud_pos_density1.z, 1.); // And smooth alpha1 = 1. - alpha1 * alpha1; @@ -96,7 +101,7 @@ void main() // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * (2.5 + disturbance.x) * cloud_pos_density1.z, 1.); // And smooth alpha2 = 1. - alpha2; diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index 24fdb45749..cdd84faba9 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -36,10 +36,6 @@ out vec4 frag_color; VARYING vec4 vary_CloudColorSun; VARYING vec4 vary_CloudColorAmbient; VARYING float vary_CloudDensity; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; uniform sampler2D cloud_noise_texture; uniform sampler2D cloud_noise_texture_next; @@ -47,16 +43,23 @@ uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; uniform vec4 gamma; +uniform float cloud_scale; +uniform float cloud_variance; + +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); vec4 cloudNoise(vec2 uv) { - vec4 a = texture2D(cloud_noise_texture, uv); - vec4 b = texture2D(cloud_noise_texture_next, uv); - vec4 samp = mix(a, b, blend_factor); - return samp; + vec4 a = texture2D(cloud_noise_texture, uv); + vec4 b = texture2D(cloud_noise_texture_next, uv); + vec4 cloud_noise_sample = mix(a, b, blend_factor); + return cloud_noise_sample; } void main() @@ -71,26 +74,28 @@ void main() vec2 uv3 = vary_texcoord2.xy; vec2 uv4 = vary_texcoord3.xy; + vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + // Offset texture coords - uv1 += cloud_pos_density1.xy; //large texture, visible density + uv1 += cloud_pos_density1.xy + disturbance; //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density + uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.); + alpha1 = min(max(alpha1 + cloudDensity, 0.) * (10. + disturbance.y) * cloud_pos_density1.z, 1.); // And smooth alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; - // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * (2.5 + disturbance.x) * cloud_pos_density1.z, 1.); // And smooth alpha2 = 1. - alpha2; diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl index d9fcc0a9ea..9f06319da3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -36,10 +36,6 @@ out vec4 frag_color; VARYING vec4 vary_CloudColorSun; VARYING vec4 vary_CloudColorAmbient; VARYING float vary_CloudDensity; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; uniform sampler2D cloud_noise_texture; uniform sampler2D cloud_noise_texture_next; @@ -47,19 +43,25 @@ uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; uniform vec4 gamma; +uniform float cloud_scale; +uniform float cloud_variance; -vec4 cloudNoise(vec2 uv) -{ - vec4 a = texture2D(cloud_noise_texture, uv); - vec4 b = texture2D(cloud_noise_texture_next, uv); - vec4 samp = mix(a, b, blend_factor); - return samp; -} - +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); +vec4 cloudNoise(vec2 uv) +{ + vec4 a = texture2D(cloud_noise_texture, uv); + vec4 b = texture2D(cloud_noise_texture_next, uv); + vec4 cloud_noise_sample = mix(a, b, blend_factor); + return cloud_noise_sample; +} + void main() { // Set variables @@ -72,16 +74,19 @@ void main() vec2 uv3 = vary_texcoord2.xy; vec2 uv4 = vary_texcoord3.xy; + vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + // Offset texture coords - uv1 += cloud_pos_density1.xy; //large texture, visible density + uv1 += cloud_pos_density1.xy + disturbance; //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density + uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.); + alpha1 = min(max(alpha1 + cloudDensity, 0.) * (10. + disturbance.y) * cloud_pos_density1.z, 1.); // And smooth alpha1 = 1. - alpha1 * alpha1; @@ -91,7 +96,7 @@ void main() // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * (2.5 + disturbance.x) * cloud_pos_density1.z, 1.); // And smooth alpha2 = 1. - alpha2; -- cgit v1.2.3 From 4b174a31c8db1bf7f378f9b088c1335651a34ec5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Oct 2018 00:44:34 +0100 Subject: Move moisture/ice/droplet radius controls to atmos tab instead of (hidden) density tab. Make frag shader version of vert WL shader to include rainbow/halo effect in non-advanced WL sky. --- .../app_settings/shaders/class2/deferred/skyF.glsl | 197 +++++++++++++++++++++ .../app_settings/shaders/class2/deferred/skyV.glsl | 42 +++++ 2 files changed, 239 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class2/deferred/skyF.glsl create mode 100644 indra/newview/app_settings/shaders/class2/deferred/skyV.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl new file mode 100644 index 0000000000..3232f81cd9 --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -0,0 +1,197 @@ +/** + * @file class2/deferred/skyF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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 mat4 modelview_projection_matrix; + +// SKY //////////////////////////////////////////////////////////////////////// +// The vertex shader for creating the atmospheric sky +/////////////////////////////////////////////////////////////////////////////// + +// Inputs +uniform vec3 camPosLocal; + +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; + +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float max_y; + +uniform vec4 glow; + +uniform vec4 cloud_color; + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif + +VARYING vec3 pos; + +///////////////////////////////////////////////////////////////////////// +// The fragment shader for the sky +///////////////////////////////////////////////////////////////////////// + +uniform vec4 gamma; +uniform sampler2D rainbow_map; +uniform sampler2D halo_map; + +uniform float moisture_level; +uniform float droplet_radius; +uniform float ice_level; + +vec3 rainbow(float d) +{ + float rad = (droplet_radius - 5.0f) / 1024.0f; + return pow(texture2D(rainbow_map, vec2(rad, d)).rgb, vec3(1.8)) * moisture_level; +} + +vec3 halo22(float d) +{ + float v = sqrt(max(0, 1 - (d*d))); + return texture2D(halo_map, vec2(0, v)).rgb * ice_level; +} + +/// Soft clips the light with a gamma correction +vec3 scaleSoftClip(vec3 light); + +void main() +{ + + // World / view / projection + // Get relative position + vec3 P = pos.xyz - camPosLocal.xyz + vec3(0,50,0); + + // Set altitude + if (P.y > 0.) + { + P *= (max_y / P.y); + } + else + { + P *= (-32000. / P.y); + } + + // Can normalize then + vec3 Pn = normalize(P); + float Plen = length(P); + + // Initialize temp variables + vec4 temp1 = vec4(0.); + vec4 temp2 = vec4(0.); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + + // Calculate relative weights + temp1 = blue_density + haze_density; + blue_weight = blue_density / temp1; + haze_weight = haze_density / temp1; + + // Compute sunlight from P & lightnorm (for long rays like sky) + temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Distance + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z); + + + // Compute haze glow + temp2.x = dot(Pn, lightnorm.xyz); + temp2.x = 1. - temp2.x; + // temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .001); + // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + // Higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + // Add "minimum anti-solar illumination" + temp2.x += .25; + + + // Haze color above cloud + vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) + ); + + + // Increase ambient when there are more clouds + vec4 tmpAmbient = ambient; + tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + + // Dim sunlight by cloud shadow percentage + sunlight *= (1. - cloud_shadow); + + // Haze color below cloud + vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) + ); + + // Final atmosphere additive + color *= (1. - temp1); + + // Attenuate cloud color by atmosphere + temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds + + // At horizon, blend high altitude sky color towards the darker color below the clouds + color += (additiveColorBelowCloud - color) * (1. - sqrt(temp1)); + + float optic_d = dot(Pn, lightnorm.xyz); + + vec3 halo_22 = halo22(optic_d); + + if (optic_d <= 0) + color.rgb += rainbow(optic_d); + + color.rgb += halo_22; + + color *= 2.; + + /// Gamma correct for WL (soft clip effect). + frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); + frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog +} + diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyV.glsl new file mode 100644 index 0000000000..bcf775577a --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/deferred/skyV.glsl @@ -0,0 +1,42 @@ +/** + * @file WLSkyV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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 mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + +// SKY //////////////////////////////////////////////////////////////////////// +// The vertex shader for creating the atmospheric sky +/////////////////////////////////////////////////////////////////////////////// + +VARYING vec3 pos; + +void main() +{ + + // World / view / projection + pos = position.xyz; + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); +} -- cgit v1.2.3 From 79d33f9d19a0c6e5ed34ffbd01a31cb2625e1ecc Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Oct 2018 18:44:03 +0100 Subject: Fix names of WATER_BLUR_MULTIPILER. Give wave direction uniforms more meaningful names in shaders. Add comments on glow size/focus conversions for clarity. --- indra/newview/app_settings/shaders/class1/deferred/waterV.glsl | 10 +++++----- .../app_settings/shaders/class1/environment/underWaterF.glsl | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl index 9734acf005..8863869e44 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl @@ -31,8 +31,8 @@ ATTRIBUTE vec3 position; void calcAtmospherics(vec3 inPositionEye); -uniform vec2 d1; -uniform vec2 d2; +uniform vec2 waveDir1; +uniform vec2 waveDir2; uniform float time; uniform vec3 eyeVec; uniform float waterHeight; @@ -88,10 +88,10 @@ void main() calcAtmospherics(pos.xyz); //pass wave parameters to pixel shader - vec2 bigWave = (v.xy) * vec2(0.04,0.04) + d1 * time * 0.055; + vec2 bigWave = (v.xy) * vec2(0.04,0.04) + waveDir1 * time * 0.055; //get two normal map (detail map) texture coordinates - littleWave.xy = (v.xy) * vec2(0.45, 0.9) + d2 * time * 0.13; - littleWave.zw = (v.xy) * vec2(0.1, 0.2) + d1 * time * 0.1; + littleWave.xy = (v.xy) * vec2(0.45, 0.9) + waveDir2 * time * 0.13; + littleWave.zw = (v.xy) * vec2(0.1, 0.2) + waveDir1 * time * 0.1; view.w = bigWave.y; refCoord.w = bigWave.x; diff --git a/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl index e918bdcb9d..20280ab1c5 100644 --- a/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl @@ -47,7 +47,6 @@ uniform float kd; uniform vec4 waterPlane; uniform vec3 eyeVec; uniform vec4 waterFogColor; -uniform float waterFogDensity; uniform float waterFogKS; uniform vec2 screenRes; -- cgit v1.2.3 From ab634a764bef6eb61ffb76db5659253b06c37d5e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Oct 2018 22:11:01 +0100 Subject: Remove some unused atmospherics helpers and forward declarations of unused helper funcs. --- .../app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl | 2 -- indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl | 3 --- indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl | 2 -- .../app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl | 6 ------ .../app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl | 6 ------ .../app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl | 5 ----- .../app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl | 5 ----- indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl | 1 - 8 files changed, 30 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl index c8ddefac26..f2d2300766 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl @@ -38,8 +38,6 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); -vec3 scaleUpLight(vec3 light); VARYING vec3 vary_position; VARYING vec3 vary_ambient; diff --git a/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl b/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl index 115b04797f..7fec3e03e7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl @@ -36,9 +36,6 @@ void calcAtmospherics(vec3 inPositionEye); vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); -vec3 scaleUpLight(vec3 light); - VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl index 8e899e3e0f..816bd0bf3e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -37,8 +37,6 @@ void calcAtmospherics(vec3 inPositionEye); vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); -vec3 scaleUpLight(vec3 light); #ifdef WATER_FOG VARYING vec3 vary_position; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl index 3f70a8935b..c16e3d50a2 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl @@ -47,9 +47,3 @@ vec3 scaleDownLight(vec3 light) return light; } -vec3 scaleUpLight(vec3 light) -{ - /* stub function for fallback compatibility on class1 hardware */ - return light; -} - diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl index 89b6a52909..9f68ca3dfa 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl @@ -47,9 +47,3 @@ vec3 scaleDownLight(vec3 light) return light; } -vec3 scaleUpLight(vec3 light) -{ - /* stub function for fallback compatibility on class1 hardware */ - return light; -} - diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl index 3582759e62..63c683c99e 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl @@ -42,8 +42,3 @@ vec3 scaleDownLightFrag(vec3 light) return (light / scene_light_strength ); } -vec3 scaleUpLightFrag(vec3 light) -{ - return (light * scene_light_strength); -} - diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl index 62a034ce05..617704ff67 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl @@ -54,8 +54,3 @@ vec3 scaleDownLight(vec3 light) return (light / scene_light_strength ); } -vec3 scaleUpLight(vec3 light) -{ - return (light * scene_light_strength); -} - diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index dadff40933..b5dcd2eba2 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -30,7 +30,6 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 scaleDownLight(vec3 light); -vec3 scaleUpLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_direction[8]; -- cgit v1.2.3 From 55d40245b4456ccf6a3f87ed488b0c5d05e54232 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Oct 2018 23:24:48 +0100 Subject: Remove unused uniforms from atmospherics helper shaders. --- indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl | 2 -- indra/newview/app_settings/shaders/class2/windlight/transportF.glsl | 2 -- indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl | 2 -- indra/newview/app_settings/shaders/class3/windlight/transportF.glsl | 2 -- 4 files changed, 8 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 4ec5691a85..770f9a5f4f 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -26,9 +26,7 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); -uniform sampler2D cloudMap; uniform vec4 gamma; -uniform vec4 cloud_pos_density1; uniform vec4 lightnorm; uniform vec4 sunlight_color; uniform vec4 ambient; diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 9627642b9d..976e5066dc 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -30,8 +30,6 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); -uniform sampler2D cloudMap; -uniform vec4 cloud_pos_density1; uniform int no_atmo; vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl index fee1a7f311..c809a41a0f 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl @@ -26,9 +26,7 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); -uniform sampler2D cloudMap; uniform vec4 gamma; -uniform vec4 cloud_pos_density1; uniform vec4 lightnorm; uniform vec4 sunlight_color; uniform vec4 ambient; diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index e8e9c53c38..c2f4c43101 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -30,8 +30,6 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); -uniform sampler2D cloudMap; -uniform vec4 cloud_pos_density1; uniform int no_atmo; vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { -- cgit v1.2.3 From 822adebf898e87d88b4f2992acdc1e92b1ae7b4f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 16 Oct 2018 21:28:21 +0100 Subject: SL-1289 take two at providing cloud variance to break up tiling monotony --- .../app_settings/shaders/class1/deferred/cloudsF.glsl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index caedd25221..fe69233e68 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -75,19 +75,23 @@ void main() vec2 uv3 = vary_texcoord2.xy; vec2 uv4 = vary_texcoord3.xy; - vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy + disturbance; //large texture, visible density + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density + uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + + cloudDensity *= 1.0 - (density_variance * density_variance); // Compute alpha1, the main cloud opacity float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * (10. + disturbance.y) * cloud_pos_density1.z, 1.); + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); // And smooth alpha1 = 1. - alpha1 * alpha1; @@ -101,7 +105,7 @@ void main() // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * (2.5 + disturbance.x) * cloud_pos_density1.z, 1.); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); // And smooth alpha2 = 1. - alpha2; -- cgit v1.2.3 From c06bd45df96c117172b83e7f8b2a8e03c5fd88e5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 19 Oct 2018 22:58:01 +0100 Subject: SL-9928 De-hackify WL additive to get better match between ALM and non-ALM rendering without bringing back SL-1491 lens flare bug. --- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- .../shaders/class2/windlight/atmosphericsF.glsl | 3 ++- .../shaders/class2/windlight/atmosphericsV.glsl | 14 ++++++++++---- .../shaders/class2/windlight/atmosphericsVarsV.glsl | 3 --- 5 files changed, 14 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 7a1968efee..c3827e3a56 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -174,7 +174,7 @@ void main() if (norm.w < 0.5) { - vec3 add = additive * spec.a; + vec3 add = additive; col = mix(atmosFragLighting(col, add, atten), fullbrightFragAtmosTransport(col, atten, add), diffuse.a); col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index c7950a2a31..af199fd78c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -186,7 +186,7 @@ void main() if (norm.w < 0.5) { - vec3 add = additive * spec.a; + vec3 add = additive; col = mix(atmosFragLighting(col, add, atten), fullbrightFragAtmosTransport(col, atten, add), diffuse.a); col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 770f9a5f4f..20c4d82ded 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -149,6 +149,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, //brightness of surface both sunlight and ambient sunlit = vec3(sunlight * .5); amblit = vec3(tmpAmbient * .25); - additive *= vec3(1.0 - temp1); + additive = normalize(additive); + additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index d174805cc0..7a6bcd53a1 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -124,16 +124,22 @@ void calcAtmospherics(vec3 inPositionEye) { //increase ambient when there are more clouds vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - //haze color - setAdditiveColor( + vec3 additive = vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); + + tmpAmbient)); + additive = normalize(additive); + + //haze color + //setAdditiveColor( + // vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + // + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + // + tmpAmbient))); //brightness of surface both sunlight and ambient setSunlitColor(vec3(sunlight * .5)); setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); + setAdditiveColor(additive * vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5); // vary_SunlitColor = vec3(0); // vary_AmblitColor = vec3(0); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl index 414ba3236a..99dbee15ee 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl @@ -73,9 +73,6 @@ void setAmblitColor(vec3 v) void setAdditiveColor(vec3 v) { - // SL-1491 clamp additive term to something reasonable to prevent - // lens flares over non-reflective surfaces - v = clamp(v, vec3(0), vec3(0.8)); additive_color = v; vary_AdditiveColor = v; } -- cgit v1.2.3 From dba9521cf6e2b14a345f7e4a2554e536fb69feff Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 22 Oct 2018 19:23:10 +0100 Subject: SL-9806 Get dome rendering to not assert the depth test state behind deferred render's back. Make clouds write and test depth to give stars something to depth test against. Add z-bias in star vert shader to force some depth testing of stars against clouds. --- indra/newview/app_settings/shaders/class1/deferred/starsV.glsl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl index e14d02a4a9..bb2a2ee72b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl @@ -38,7 +38,13 @@ VARYING vec2 screenpos; void main() { //transform vertex - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vec4 pos = modelview_projection_matrix * vec4(position, 1.0); + +// bias z to fix SL-9806 and get stars to depth test against clouds + pos.z += 0.001f; + + gl_Position = pos; + float t = mod(time, 1.25f); screenpos = position.xy * vec2(t, t); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -- cgit v1.2.3 From 56355cf35412589b0a171f33b7962fd3800c734a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 30 Oct 2018 15:56:08 +0100 Subject: SL-9966 Port over transport, gamma, atmospherics shader stub updates for per-fragment atmospherics. Fix bindings of current/next noise map when current and next are the same (select only one and force blend factor to 0). --- .../shaders/class1/windlight/atmosphericsF.glsl | 21 +++++++++++--- .../shaders/class1/windlight/gammaF.glsl | 21 ++++++++++---- .../shaders/class1/windlight/transportF.glsl | 25 +++++++++++++---- .../shaders/class2/windlight/cloudsF.glsl | 32 +++++++++++++++------- 4 files changed, 75 insertions(+), 24 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl index 584bd568c5..bf0a9048f0 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl @@ -23,16 +23,29 @@ * $/LicenseInfo$ */ +vec3 atmosFragAmbient(vec3 light, vec3 sunlit) +{ + return light; +} - -vec3 atmosLighting(vec3 light) +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { /* stub function for fallback compatibility on class1 hardware */ - return light; + return light; } +vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit) +{ + return light * sunlit; +} -void calcFragAtmospherics(vec3 inPositionEye, float ambFactor) { +vec3 atmosLighting(vec3 light) +{ + return atmosFragLighting(light, vec3(0), vec3(1.0)); +} + +void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive) +{ /* stub function for fallback compatibility on class1 hardware */ } diff --git a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl index 62f4e51449..b7f117fc5f 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl @@ -23,17 +23,28 @@ * $/LicenseInfo$ */ - - +uniform int no_atmo; uniform vec4 gamma; -/// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light) { +vec3 scaleFragSoftClip(vec3 light) +{ // For compatibility with lower cards. Do nothing. return light; } +/// Soft clips the light with a gamma correction +vec3 scaleSoftClip(vec3 light) +{ + // For compatibility with lower cards. Do nothing. + return scaleFragSoftClip(light); +} + +vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 atten) +{ + return (no_atmo == 1) ? light : mix(scaleFragSoftClip(light.rgb), light.rgb, atten); +} + vec3 fullbrightScaleSoftClip(vec3 light) { - return scaleSoftClip(light); + return fullbrightScaleSoftClipFrag(light, vec3(1)); } diff --git a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl index 7c95ecdb14..c3c8329017 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl @@ -22,25 +22,40 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - +uniform int no_atmo; -vec3 atmosTransport(vec3 light) +vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { /* stub function for fallback compatibility on class1 hardware */ return light; } -vec3 fullbrightAtmosTransport(vec3 light) +vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { /* stub function for fallback compatibility on class1 hardware */ return light; } +vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} -vec3 fullbrightShinyAtmosTransport(vec3 light) +vec3 atmosTransport(vec3 light) { /* stub function for fallback compatibility on class1 hardware */ - return light; + return atmosFragTransport(light, vec3(1), vec3(0)); +} + +vec3 fullbrightAtmosTransport(vec3 light) +{ + return fullbrightFragAtmosTransport(light, vec3(1), vec3(0)); +} + +vec3 fullbrightShinyAtmosTransport(vec3 light) +{ + return fullbrightFragShinyAtmosTransport(light, vec3(1), vec3(0)); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index cdd84faba9..e3fa431ddf 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -22,11 +22,13 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + +/*[EXTRA_CODE_HERE]*/ + #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; +out vec4 frag_data[3]; #else -#define frag_color gl_FragColor +#define frag_data gl_FragData #endif ///////////////////////////////////////////////////////////////////////// @@ -74,28 +76,37 @@ void main() vec2 uv3 = vary_texcoord2.xy; vec2 uv4 = vary_texcoord3.xy; - vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy + disturbance; //large texture, visible density + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density + uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + + cloudDensity *= 1.0 - (density_variance * density_variance); // Compute alpha1, the main cloud opacity float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * (10. + disturbance.y) * cloud_pos_density1.z, 1.); + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); // And smooth alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; + if (alpha1 < 0.001f) + { + discard; + } + // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * (2.5 + disturbance.x) * cloud_pos_density1.z, 1.); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); // And smooth alpha2 = 1. - alpha2; @@ -107,7 +118,8 @@ void main() color *= 2.; /// Gamma correct for WL (soft clip effect). - frag_color.rgb = scaleSoftClip(color.rgb); - frag_color.a = alpha1; + frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); + frag_data[2] = vec4(0,0,1,0); } -- cgit v1.2.3 From 9a8e124fdecbeb57f65645d102f5f1767f8e4d16 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 30 Oct 2018 18:17:47 +0100 Subject: SL-9976 change moon blend/brightness handling in shaders and cleanup extraneous GL state management. --- .../app_settings/shaders/class1/deferred/moonF.glsl | 20 +++++--------------- .../app_settings/shaders/class1/windlight/moonF.glsl | 17 +++-------------- 2 files changed, 8 insertions(+), 29 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index f65a6eb32b..8bf4551abc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -33,9 +33,6 @@ out vec4 frag_data[3]; #define frag_data gl_FragData #endif -vec3 fullbrightAtmosTransport(vec3 light); -vec3 fullbrightScaleSoftClip(vec3 light); - uniform vec4 color; uniform vec4 sunlight_color; uniform vec3 lumWeights; @@ -52,23 +49,16 @@ void main() vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(moonA, moonB, blend_factor); - if (c.a < 0.1f) - { - discard; - } - - c.rgb = pow(c.rgb, vec3(0.7f)); - c.rgb = fullbrightAtmosTransport(c.rgb); - c.rgb = fullbrightScaleSoftClip(c.rgb); - // mix factor which blends when sunlight is brighter // and shows true moon color at night vec3 luma_weights = vec3(0.2, 0.3, 0.2); - float mix = 1.0f - dot(normalize(sunlight_color.rgb), luma_weights); - c.rgb = pow(c.rgb, 1.2 - vec3(mix * moon_brightness)); + float mix = 1.0 - dot(normalize(sunlight_color.rgb), luma_weights); + + vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0 - 1.0; + c.rgb = pow(c.rgb, exp); - frag_data[0] = vec4(c.rgb, mix * (moon_brightness + (c.a * 0.25))); + frag_data[0] = vec4(c.rgb, c.a); frag_data[1] = vec4(0.0); frag_data[2] = vec4(0.0f); } diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl index 8cc7fc3bb5..b66b56e0fb 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -33,9 +33,6 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -vec3 fullbrightAtmosTransport(vec3 light); -vec3 fullbrightScaleSoftClip(vec3 light); - uniform vec4 color; uniform vec4 sunlight_color; uniform vec3 lumWeights; @@ -52,22 +49,14 @@ void main() vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(moonA, moonB, blend_factor); - if (c.a < 0.1f) - { - discard; - } - - c.rgb = pow(c.rgb, vec3(0.7f)); - c.rgb = fullbrightAtmosTransport(c.rgb); - c.rgb = fullbrightScaleSoftClip(c.rgb); - // mix factor which blends when sunlight is brighter // and shows true moon color at night vec3 luma_weights = vec3(0.2, 0.3, 0.2); float mix = 1.0f - dot(normalize(sunlight_color.rgb), luma_weights); - c.rgb = pow(c.rgb, 1.2 - vec3(mix * moon_brightness)); + vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0 - 1.0; + c.rgb = pow(c.rgb, exp); - frag_color = vec4(c.rgb, mix * (moon_brightness + (c.a * 0.25))); + frag_color = vec4(c.rgb, c.a); } -- cgit v1.2.3 From fb335cc243581925bb772a1f10112ec493db8552 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 1 Nov 2018 18:26:24 +0100 Subject: SL-10000 fix storing of ambient value when converting legacy settings --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 4 ++-- .../app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- .../shaders/class2/windlight/transportF.glsl | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 7f2c5add16..1cfc19267c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -88,7 +88,7 @@ vec3 linear_to_srgb(vec3 cl); vec2 encode_normal (vec3 n); vec3 decode_normal (vec2 enc); -vec3 scaleFragSoftClip(vec3 l); +vec3 scaleSoftClipFrag(vec3 l); vec3 atmosFragAmbient(vec3 light, vec3 sunlit); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit); @@ -312,7 +312,7 @@ void main() //color.rgb = mix(diff.rgb, color.rgb, final_alpha); color.rgb = atmosFragLighting(color.rgb, additive, atten); - color.rgb = scaleFragSoftClip(color.rgb); + color.rgb = scaleSoftClipFrag(color.rgb); vec4 light = vec4(0,0,0,0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6e06453a5b..9f52e72313 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -42,7 +42,7 @@ vec3 linear_to_srgb(vec3 cl); vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleFragSoftClip(vec3 l); +vec3 scaleSoftClipFrag(vec3 l); vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); @@ -455,7 +455,7 @@ void main() //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); col = atmosFragLighting(col, additive, atten); - col = scaleFragSoftClip(col); + col = scaleSoftClipFrag(col); //convert to linear space before adding local lights col = srgb_to_linear(col); diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 976e5066dc..7f874e0ccf 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -32,7 +32,7 @@ vec3 getAtmosAttenuation(); uniform int no_atmo; -vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { if (no_atmo == 0) { light *= atten.r; @@ -41,32 +41,32 @@ vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { return light; } -vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { if (no_atmo == 1) { return light; } float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosFragTransport(light.rgb, atten, additive), light.rgb + additive.rgb, brightness * brightness); + return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); } -vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) { +vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { if (no_atmo == 1) { return light; } float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosFragTransport(light.rgb, atten, additive), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); + return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); } vec3 atmosTransport(vec3 light) { - return (no_atmo == 1) ? light : atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); + return (no_atmo == 1) ? light : atmosTransportFrag(light, getAtmosAttenuation(), getAdditiveColor()); } vec3 fullbrightAtmosTransport(vec3 light) { - return (no_atmo == 1) ? light : fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); + return (no_atmo == 1) ? light : fullbrightAtmosTransportFrag(light, getAtmosAttenuation(), getAdditiveColor()); } vec3 fullbrightShinyAtmosTransport(vec3 light) { - return (no_atmo == 1) ? light : fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); + return (no_atmo == 1) ? light : fullbrightShinyAtmosTransportFrag(light, getAtmosAttenuation(), getAdditiveColor()); } -- cgit v1.2.3 From a67cf385d763325119f4d2a37beb96c9c6a80282 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 1 Nov 2018 19:04:11 +0100 Subject: Back out unintended shader changes from SL-10000 fix. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 4 ++-- .../app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- .../shaders/class2/windlight/transportF.glsl | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 1cfc19267c..7f2c5add16 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -88,7 +88,7 @@ vec3 linear_to_srgb(vec3 cl); vec2 encode_normal (vec3 n); vec3 decode_normal (vec2 enc); -vec3 scaleSoftClipFrag(vec3 l); +vec3 scaleFragSoftClip(vec3 l); vec3 atmosFragAmbient(vec3 light, vec3 sunlit); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit); @@ -312,7 +312,7 @@ void main() //color.rgb = mix(diff.rgb, color.rgb, final_alpha); color.rgb = atmosFragLighting(color.rgb, additive, atten); - color.rgb = scaleSoftClipFrag(color.rgb); + color.rgb = scaleFragSoftClip(color.rgb); vec4 light = vec4(0,0,0,0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 9f52e72313..6e06453a5b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -42,7 +42,7 @@ vec3 linear_to_srgb(vec3 cl); vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleSoftClipFrag(vec3 l); +vec3 scaleFragSoftClip(vec3 l); vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); @@ -455,7 +455,7 @@ void main() //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); col = atmosFragLighting(col, additive, atten); - col = scaleSoftClipFrag(col); + col = scaleFragSoftClip(col); //convert to linear space before adding local lights col = srgb_to_linear(col); diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 7f874e0ccf..976e5066dc 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -32,7 +32,7 @@ vec3 getAtmosAttenuation(); uniform int no_atmo; -vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { +vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { if (no_atmo == 0) { light *= atten.r; @@ -41,32 +41,32 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { return light; } -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { +vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { if (no_atmo == 1) { return light; } float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); + return mix(atmosFragTransport(light.rgb, atten, additive), light.rgb + additive.rgb, brightness * brightness); } -vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { +vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) { if (no_atmo == 1) { return light; } float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); + return mix(atmosFragTransport(light.rgb, atten, additive), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); } vec3 atmosTransport(vec3 light) { - return (no_atmo == 1) ? light : atmosTransportFrag(light, getAtmosAttenuation(), getAdditiveColor()); + return (no_atmo == 1) ? light : atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); } vec3 fullbrightAtmosTransport(vec3 light) { - return (no_atmo == 1) ? light : fullbrightAtmosTransportFrag(light, getAtmosAttenuation(), getAdditiveColor()); + return (no_atmo == 1) ? light : fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); } vec3 fullbrightShinyAtmosTransport(vec3 light) { - return (no_atmo == 1) ? light : fullbrightShinyAtmosTransportFrag(light, getAtmosAttenuation(), getAdditiveColor()); + return (no_atmo == 1) ? light : fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); } -- cgit v1.2.3 From 4f267a5723e7da2de36b9f2295e4942a4c8bf6c5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 1 Nov 2018 20:28:47 +0100 Subject: SL-9994 Make shaders use consistent naming and parameter order for transport and atmospheric helpers. Share transport and gamma correction code where possible. Add lots of asserts and other validation for when things don't go as planned. Engage dumpShaderSource to get more source output with shader compilation fail. --- .../shaders/class1/deferred/alphaF.glsl | 4 +- .../shaders/class1/deferred/materialF.glsl | 8 +-- .../shaders/class1/deferred/softenLightF.glsl | 29 +++------- .../app_settings/shaders/class1/deferred/srgb.glsl | 18 ++++++ .../shaders/class1/deferred/waterF.glsl | 3 +- .../shaders/class1/environment/srgbF.glsl | 4 ++ .../shaders/class1/environment/terrainF.glsl | 4 +- .../shaders/class1/environment/terrainV.glsl | 2 +- .../shaders/class1/windlight/gammaF.glsl | 17 +++--- .../shaders/class1/windlight/transportF.glsl | 24 +------- .../shaders/class2/deferred/softenLightF.glsl | 67 ++++++++++++++-------- .../shaders/class2/windlight/atmosphericsF.glsl | 12 +--- .../shaders/class2/windlight/gammaF.glsl | 19 +++--- .../shaders/class3/deferred/softenLightF.glsl | 18 +----- .../shaders/class3/windlight/atmosphericsF.glsl | 8 +-- .../shaders/class3/windlight/transportF.glsl | 29 +++++----- 16 files changed, 129 insertions(+), 137 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 7f2c5add16..1cfc19267c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -88,7 +88,7 @@ vec3 linear_to_srgb(vec3 cl); vec2 encode_normal (vec3 n); vec3 decode_normal (vec2 enc); -vec3 scaleFragSoftClip(vec3 l); +vec3 scaleSoftClipFrag(vec3 l); vec3 atmosFragAmbient(vec3 light, vec3 sunlit); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit); @@ -312,7 +312,7 @@ void main() //color.rgb = mix(diff.rgb, color.rgb, final_alpha); color.rgb = atmosFragLighting(color.rgb, additive, atten); - color.rgb = scaleFragSoftClip(color.rgb); + color.rgb = scaleSoftClipFrag(color.rgb); vec4 light = vec4(0,0,0,0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6e06453a5b..c001ff9ac8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -42,8 +42,8 @@ vec3 linear_to_srgb(vec3 cl); vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleFragSoftClip(vec3 l); -vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); +vec3 scaleSoftClipFrag(vec3 l); + void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -406,7 +406,7 @@ void main() col.rgb *= ambient; - col.rgb = col.rgb + atmosFragAffectDirectionalLight(final_da, sunlit); + col.rgb = col.rgb + (final_da * sunlit); col.rgb *= gamma_diff.rgb; @@ -455,7 +455,7 @@ void main() //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); col = atmosFragLighting(col, additive, atten); - col = scaleFragSoftClip(col); + col = scaleSoftClipFrag(col); //convert to linear space before adding local lights col = srgb_to_linear(col); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index c3827e3a56..5627275df6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -69,13 +69,7 @@ vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); -vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleFragSoftClip(vec3 l); -vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); -vec3 fullbrightFragAtmosTransport(vec3 l, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 atten); - void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec4 getPosition_d(vec2 pos_screen, float depth) @@ -123,22 +117,20 @@ void main() vec3 col; 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); - col = atmosFragAmbient(vec3(0), amblit); float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb *= ambient; + ambient = (1.0 - ambient); - col += atmosFragAffectDirectionalLight(final_da, sunlit); - + col = amblit; + col += (final_da * sunlit); + col *= ambient; col *= diffuse.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -174,9 +166,7 @@ void main() if (norm.w < 0.5) { - vec3 add = additive; - col = mix(atmosFragLighting(col, add, atten), fullbrightFragAtmosTransport(col, atten, add), diffuse.a); - col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a); + col = atmosFragLighting(col, additive, atten); } #ifdef WATER_FOG @@ -187,7 +177,6 @@ void main() col = srgb_to_linear(col); - //col = vec3(1,0,1); //col.g = envIntensity; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl index 587f3d5a94..00ba0e8fad 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl @@ -23,6 +23,24 @@ * $/LicenseInfo$ */ +vec3 rgb2hsv(vec3 c) +{ + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + +vec3 hsv2rgb(vec3 c) +{ + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + vec3 srgb_to_linear(vec3 cs) { vec3 low_range = cs / vec3(12.92); diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index a29acb3e7d..73f6d9fec3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -73,6 +73,7 @@ VARYING vec4 vary_position; vec3 srgb_to_linear(vec3 cs); vec2 encode_normal(vec3 n); +vec3 scaleSoftClipFrag(vec3 l); vec3 BlendNormal(vec3 bump1, vec3 bump2) { @@ -175,7 +176,7 @@ void main() color.rgb += spec * specular; color.rgb = atmosTransport(color.rgb); - color.rgb = scaleSoftClip(color.rgb); + color.rgb = scaleSoftClipFrag(color.rgb); color.a = spec * sunAngle2; vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); diff --git a/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl index 835662732a..f98b3a5edf 100644 --- a/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl @@ -60,3 +60,7 @@ vec3 linear_to_srgb(vec3 cl) } +vec3 ColorFromRadiance(vec3 radiance) +{ + return vec3(1.0) - exp(-radiance * 0.0001); +} diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl index 668a710c04..46bde7f308 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl @@ -59,8 +59,10 @@ void main() vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); /// Add WL Components - outColor.rgb = atmosLighting(outColor.rgb * vertex_color.rgb); + //outColor.rgb = atmosLighting(outColor.rgb * vertex_color.rgb); + outColor.rgb = atmosLighting(outColor.rgb); + frag_color = vec4(scaleSoftClip(outColor.rgb), 1.0); } diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl index d09c5f9247..5ffe464172 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl @@ -71,7 +71,7 @@ void main() /// Potentially better without it for water. pos /= pos.w; - vec4 color = calcLighting(pos.xyz, norm, vec4(1,1,1,1), vec4(0)); + vec4 color = calcLighting(pos.xyz, norm, vec4(0), vec4(1)); vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl index b7f117fc5f..768d93f005 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl @@ -26,7 +26,7 @@ uniform int no_atmo; uniform vec4 gamma; -vec3 scaleFragSoftClip(vec3 light) +vec3 scaleSoftClipFrag(vec3 light) { // For compatibility with lower cards. Do nothing. return light; @@ -35,16 +35,19 @@ vec3 scaleFragSoftClip(vec3 light) /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light) { - // For compatibility with lower cards. Do nothing. - return scaleFragSoftClip(light); + // For compatibility with lower cards. Do nothing + return light; } -vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 atten) +vec3 fullbrightScaleSoftClipFrag(vec3 light) { - return (no_atmo == 1) ? light : mix(scaleFragSoftClip(light.rgb), light.rgb, atten); + // For compatibility with lower cards. Do nothing + return light; } -vec3 fullbrightScaleSoftClip(vec3 light) { - return fullbrightScaleSoftClipFrag(light, vec3(1)); +vec3 fullbrightScaleSoftClip(vec3 light) +{ + // For compatibility with lower cards. Do nothing + return light; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl index c3c8329017..ebce9ea91d 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl @@ -25,37 +25,19 @@ uniform int no_atmo; -vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) -{ - /* stub function for fallback compatibility on class1 hardware */ - return light; -} - -vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) -{ - /* stub function for fallback compatibility on class1 hardware */ - return light; -} - -vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) -{ - /* stub function for fallback compatibility on class1 hardware */ - return light; -} - vec3 atmosTransport(vec3 light) { /* stub function for fallback compatibility on class1 hardware */ - return atmosFragTransport(light, vec3(1), vec3(0)); + return light; } vec3 fullbrightAtmosTransport(vec3 light) { - return fullbrightFragAtmosTransport(light, vec3(1), vec3(0)); + return light; } vec3 fullbrightShinyAtmosTransport(vec3 light) { - return fullbrightFragShinyAtmosTransport(light, vec3(1), vec3(0)); + return light; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index af199fd78c..fa81317f3f 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -1,5 +1,5 @@ /** - * @file softenLightF.glsl + * @file class2/deferred/softenLightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -72,17 +72,43 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; +uniform int no_atmo; + vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); -vec3 atmosFragAmbient(vec3 l, vec3 ambient); -vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleFragSoftClip(vec3 l); -vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); -vec3 fullbrightFragAtmosTransport(vec3 l, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 atten); +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 fullbrightScaleSoftClipFrag(vec3 l); +vec3 scaleSoftClipFrag(vec3 l); + +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { + if (no_atmo == 0) + { + light *= atten.r; + light += additive * 2.0; + } + return light; +} + +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { + if (no_atmo == 1) + { + return light; + } + float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); +} + +vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { + if (no_atmo == 1) + { + return light; + } + float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); +} vec4 getPosition_d(vec2 pos_screen, float depth) { @@ -121,7 +147,6 @@ void main() float light_gamma = 1.0/1.3; da = pow(da, light_gamma); - vec4 diffuse = texture2DRect(diffuseRect, tc); //convert to gamma space @@ -136,27 +161,23 @@ void main() scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); float scol = max(scol_ambocc.r, diffuse.a); - - - float ambocc = scol_ambocc.g; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); - - col = atmosFragAmbient(vec3(0), amblit); + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0-ambient); - col.rgb *= ambient; + col.rgb = ambient * amblit; - col += atmosFragAffectDirectionalLight(max(min(da, scol), 0.0), sunlit); + col += sunlit * max(min(da, scol), 0.0); col *= diffuse.rgb; @@ -173,7 +194,6 @@ void main() bloom = dot(spec_contrib, spec_contrib) / 6; col += spec_contrib; } - col = mix(col, diffuse.rgb, diffuse.a); @@ -186,13 +206,12 @@ void main() if (norm.w < 0.5) { - vec3 add = additive; - col = mix(atmosFragLighting(col, add, atten), fullbrightFragAtmosTransport(col, atten, add), diffuse.a); - col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a); + col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); + col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col), diffuse.a); } #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); + vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); col = fogged.rgb; bloom = fogged.a; #endif diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 20c4d82ded..89bdbfc0e6 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -43,17 +43,7 @@ uniform float scene_light_strength; uniform mat3 ssao_effect_mat; uniform int no_atmo; -vec3 scaleFragSoftClip(vec3 light) -{ - if (no_atmo == 1) - { - return light; - } - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - return light; -} +vec3 scaleSoftClipFrag(vec3 light); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index f2764b72c3..187876acf7 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -30,8 +30,8 @@ uniform int no_atmo; vec3 getAtmosAttenuation(); -/// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light) { +vec3 scaleSoftClipFrag(vec3 light) +{ if (no_atmo == 1) { return light; @@ -39,16 +39,21 @@ vec3 scaleSoftClip(vec3 light) { //soft clip effect: light = 1. - clamp(light, vec3(0.), vec3(1.)); light = 1. - pow(light, gamma.xxx); - return light; } -vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 atten) +vec3 scaleSoftClip(vec3 light) +{ + return scaleSoftClipFrag(light); +} + +vec3 fullbrightScaleSoftClipFrag(vec3 light) { - return (no_atmo == 1) ? light : mix(scaleSoftClip(light.rgb), light.rgb, atten); + return scaleSoftClipFrag(light.rgb); } -vec3 fullbrightScaleSoftClip(vec3 light) { - return (no_atmo == 1) ? light : fullbrightScaleSoftClipFrag(light.rgb, getAtmosAttenuation()); +vec3 fullbrightScaleSoftClip(vec3 light) +{ + return fullbrightScaleSoftClipFrag(light.rgb); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index d2fd70c9e2..2615400e52 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -115,7 +115,6 @@ void main() float light_gamma = 1.0/1.3; da = pow(da, light_gamma); - vec4 diffuse = texture2DRect(diffuseRect, tc); //convert to gamma space @@ -133,14 +132,6 @@ void main() float ambocc = scol_ambocc.g; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - - //calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); - //col += atmosFragAffectDirectionalLight(max(min(da, scol), 0.0), sunlit); - col *= diffuse.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -158,8 +149,7 @@ void main() bloom = dot(spec_contrib, spec_contrib) / 6; col += spec_contrib; } - - + col = mix(col, diffuse.rgb, diffuse.a); if (envIntensity > 0.0) @@ -169,12 +159,6 @@ void main() col = mix(col.rgb, refcol, envintensity); } - if (norm.w < 0.5) - { - //col = mix(atmosFragLighting(col, additive, atten), fullbrightFragAtmosTransport(col, atten, additive), diffuse.a); - //col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a); - } - #ifdef WATER_FOG vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); col = fogged.rgb; diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl index c809a41a0f..a1b67fc31e 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl @@ -42,13 +42,7 @@ uniform vec4 glow; uniform float scene_light_strength; uniform mat3 ssao_effect_mat; -vec3 scaleFragSoftClip(vec3 light) -{ - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - return light; -} +vec3 scaleSoftClipFrag(vec3 light); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index c2f4c43101..5c93af386b 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -32,41 +32,42 @@ vec3 getAtmosAttenuation(); uniform int no_atmo; -vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { - if (no_atmo == 0) +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { + if (no_atmo == 1) { - light *= atten.r; - light += additive * 2.0; + return light; } + light *= atten.r; + light += additive * 2.0; return light; } -vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { - if (no_atmo) +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { + if (no_atmo == 1) { return light; } - loat brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosFragTransport(light.rgb, atten, additive), light.rgb + additive.rgb, brightness * brightness); + float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosTransportFrag(light.rgb, additive,a tten), light.rgb + additive.rgb, brightness * brightness); } -vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) { - if (no_atmo) +vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 atten, vec3 additive) { + if (no_atmo == 1) { return light; } float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosFragTransport(light.rgb, atten, additive), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); + return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); } vec3 atmosTransport(vec3 light) { - return no_atmo ? light : atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); + return (no_atmo == 1) ? light : atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } vec3 fullbrightAtmosTransport(vec3 light) { - return no_atmo ? light : fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); + return (no_atmo == 1) ? light : fullbrightAtmosTransportFrag(light, GetAdditiveColor(), getAtmosAttenuation()); } vec3 fullbrightShinyAtmosTransport(vec3 light) { - return no_atmo ? light : fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); + return (no_atmo == 1) ? light : fullbrightShinyAtmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } -- cgit v1.2.3 From 8c1aefc17c710b55ed7a72bd9de14cbed58ccd31 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 6 Nov 2018 16:38:06 +0000 Subject: Remove scaleDownLight funcs and eliminate unused copy-pasted funcs in lighting shaders. Also fix terrain response to atmospherics shaders (was failing to apply ambient on low end even when atmospherics was on). --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 7 ------- .../shaders/class1/deferred/avatarAlphaNoColorV.glsl | 7 ------- .../app_settings/shaders/class1/deferred/materialF.glsl | 7 ------- .../app_settings/shaders/class1/environment/terrainF.glsl | 4 +--- .../app_settings/shaders/class1/environment/terrainV.glsl | 2 +- .../shaders/class1/lighting/lightFuncSpecularV.glsl | 8 -------- .../shaders/class1/lighting/sumLightsSpecularV.glsl | 2 -- .../app_settings/shaders/class1/lighting/sumLightsV.glsl | 2 -- .../app_settings/shaders/class1/windlight/atmosphericsF.glsl | 10 ++++++---- .../shaders/class1/windlight/atmosphericsHelpersF.glsl | 6 ------ .../shaders/class1/windlight/atmosphericsHelpersV.glsl | 6 ------ .../app_settings/shaders/class2/deferred/softenLightF.glsl | 10 +++++----- .../shaders/class2/lighting/sumLightsSpecularV.glsl | 2 -- .../app_settings/shaders/class2/lighting/sumLightsV.glsl | 3 --- .../app_settings/shaders/class2/windlight/atmosphericsF.glsl | 9 +++++---- .../shaders/class2/windlight/atmosphericsHelpersF.glsl | 5 ----- .../shaders/class2/windlight/atmosphericsHelpersV.glsl | 5 ----- .../app_settings/shaders/class2/windlight/transportF.glsl | 10 +++++----- .../shaders/class3/lighting/sumLightsSpecularV.glsl | 2 -- .../app_settings/shaders/class3/lighting/sumLightsV.glsl | 2 -- .../app_settings/shaders/class3/windlight/transportF.glsl | 7 +++---- indra/newview/app_settings/shaders/shader_hierarchy.txt | 5 ----- 22 files changed, 26 insertions(+), 95 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 1cfc19267c..3ec2ea12da 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -94,13 +94,6 @@ 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); -vec3 calcDirectionalLight(vec3 n, vec3 l) -{ - float a = max(dot(n,l),0.0); - a = pow(a, 1.0/1.3); - return vec3(a,a,a); -} - vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) { //get light vector diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl index f2d2300766..e68b082d43 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl @@ -34,7 +34,6 @@ mat4 getSkinnedTransform(); void calcAtmospherics(vec3 inPositionEye); float calcDirectionalLight(vec3 n, vec3 l); -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight); vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); @@ -57,12 +56,6 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -float calcDirectionalLight(vec3 n, vec3 l) -{ - float a = max(dot(n,l),0.0); - return a; -} - float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) { //get light vector diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c001ff9ac8..c1c17532b8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -110,13 +110,6 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -vec3 calcDirectionalLight(vec3 n, vec3 l) -{ - float a = max(dot(n,l),0.0); - return vec3(a,a,a); -} - - 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) { //get light vector diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl index 46bde7f308..668a710c04 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl @@ -59,10 +59,8 @@ void main() vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); /// Add WL Components - //outColor.rgb = atmosLighting(outColor.rgb * vertex_color.rgb); + outColor.rgb = atmosLighting(outColor.rgb * vertex_color.rgb); - outColor.rgb = atmosLighting(outColor.rgb); - frag_color = vec4(scaleSoftClip(outColor.rgb), 1.0); } diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl index 5ffe464172..4d6f0c67a5 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl @@ -71,7 +71,7 @@ void main() /// Potentially better without it for water. pos /= pos.w; - vec4 color = calcLighting(pos.xyz, norm, vec4(0), vec4(1)); + vec4 color = calcLighting(pos.xyz, norm, vec4(1), vec4(0)); vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl index 85cddc647d..20e44d74d5 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl @@ -23,14 +23,6 @@ * $/LicenseInfo$ */ - - -float calcDirectionalLight(vec3 n, vec3 l) -{ - float a = max(dot(n,l),0.0); - return a; -} - float calcDirectionalSpecular(vec3 view, vec3 n, vec3 l) { return pow(max(dot(reflect(view, n),l), 0.0),8.0); diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl index 7059ff31ae..10958025ac 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl @@ -29,7 +29,6 @@ float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 atmosGetDiffuseSunlightColor(); -vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_diffuse[8]; @@ -44,7 +43,6 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor vec4 specularSum = vec4(0.0); col.rgb += light_diffuse[1].rgb * calcDirectionalLightSpecular(specularColor, view, norm, light_position[1].xyz,light_diffuse[1].rgb, 1.0); - col.rgb = scaleDownLight(col.rgb); col.rgb += atmosAmbient(baseCol.rgb); col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz,atmosGetDiffuseSunlightColor()*baseCol.a, 1.0)); diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl index 41288c21c1..569b629ef8 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl @@ -30,7 +30,6 @@ float calcDirectionalLight(vec3 n, vec3 l); vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) { @@ -38,7 +37,6 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) col.a = color.a; col.rgb = light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); - col.rgb = scaleDownLight(col.rgb); col.rgb += atmosAmbient(baseLight.rgb); col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl index bf0a9048f0..c1cc3679a7 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl @@ -25,13 +25,14 @@ vec3 atmosFragAmbient(vec3 light, vec3 sunlit) { - return light; + /* stub function for fallback compatibility on class1 hardware */ + return light; } vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { - /* stub function for fallback compatibility on class1 hardware */ - return light; + /* stub function for fallback compatibility on class1 hardware */ + return light; } vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit) @@ -41,7 +42,8 @@ vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit) vec3 atmosLighting(vec3 light) { - return atmosFragLighting(light, vec3(0), vec3(1.0)); + /* stub function for fallback compatibility on class1 hardware */ + return light; } void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive) diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl index c16e3d50a2..9e5893d32a 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl @@ -41,9 +41,3 @@ vec3 atmosGetDiffuseSunlightColor() return sunlight_color.rgb; } -vec3 scaleDownLight(vec3 light) -{ - /* stub function for fallback compatibility on class1 hardware */ - return light; -} - diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl index 9f68ca3dfa..01f19087ff 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl @@ -41,9 +41,3 @@ vec3 atmosGetDiffuseSunlightColor() return sunlight_color.rgb; } -vec3 scaleDownLight(vec3 light) -{ - /* stub function for fallback compatibility on class1 hardware */ - return light; -} - diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index fa81317f3f..c92dbda185 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -83,13 +83,13 @@ vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 fullbrightScaleSoftClipFrag(vec3 l); vec3 scaleSoftClipFrag(vec3 l); -vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 0) +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ + if (no_atmo == 1) { - light *= atten.r; - light += additive * 2.0; + return light; } - return light; + return (light + additive) * atten.r * 2.0; } vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl index 3acf9fe883..eef259349f 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl @@ -31,7 +31,6 @@ vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 atmosGetDiffuseSunlightColor(); -vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_attenuation[8]; @@ -50,7 +49,6 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor col.rgb += light_diffuse[1].rgb * calcDirectionalLightSpecular(specularColor, view, norm, light_position[1].xyz,light_diffuse[1].rgb, 1.0); col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[2].xyz, light_attenuation[2].x, light_attenuation[2].y, light_diffuse[2].rgb); col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[3].xyz, light_attenuation[3].x, light_attenuation[3].y, light_diffuse[3].rgb); - col.rgb = scaleDownLight(col.rgb); // Add windlight lights col.rgb += atmosAmbient(baseCol.rgb); diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl index c9987ef3b9..b42506dd40 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl @@ -28,7 +28,6 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_direction[8]; @@ -45,8 +44,6 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); - col.rgb = scaleDownLight(col.rgb); - // Add windlight lights col.rgb += atmosAmbient(baseLight.rgb); col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 89bdbfc0e6..229f8073b0 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -47,12 +47,13 @@ vec3 scaleSoftClipFrag(vec3 light); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 0) + if (no_atmo == 1) { - light *= atten.r; - light += additive; + return light; } - return (2.0 * light); + light *= atten.r; + light += additive; + return light; } vec3 atmosLighting(vec3 light) diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl index 63c683c99e..8648c38501 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl @@ -37,8 +37,3 @@ vec3 atmosFragAffectDirectionalLight(float lightIntensity, vec3 sunlit) return sunlit * lightIntensity; } -vec3 scaleDownLightFrag(vec3 light) -{ - return (light / scene_light_strength ); -} - diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl index 617704ff67..a83aa95f95 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl @@ -49,8 +49,3 @@ vec3 atmosGetDiffuseSunlightColor() return getSunlitColor(); } -vec3 scaleDownLight(vec3 light) -{ - return (light / scene_light_strength ); -} - diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 976e5066dc..bf64605014 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -32,13 +32,13 @@ vec3 getAtmosAttenuation(); uniform int no_atmo; -vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) { - if (no_atmo == 0) +vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) +{ + if (no_atmo == 1) { - light *= atten.r; - light += additive * 2.0; + return light; } - return light; + return (light + additive) * atten * 2.0; } vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl index e043ac873e..7870d0516f 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl @@ -29,7 +29,6 @@ vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 atmosGetDiffuseSunlightColor(); -vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_attenuation[8]; @@ -52,7 +51,6 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[5].xyz, light_attenuation[5].x, light_attenuation[5].y, light_diffuse[5].rgb); col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[6].xyz, light_attenuation[6].x, light_attenuation[6].y, light_diffuse[6].rgb); col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[7].xyz, light_attenuation[7].x, light_attenuation[7].y, light_diffuse[7].rgb); - col.rgb = scaleDownLight(col.rgb); // Add windlight lights col.rgb += atmosAmbient(baseCol.rgb); diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index b5dcd2eba2..9842d9ba93 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -29,7 +29,6 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_direction[8]; @@ -50,7 +49,6 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].z); col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].z); col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz); - col.rgb = scaleDownLight(col.rgb); // Add windlight lights col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index 5c93af386b..8195801be6 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -32,14 +32,13 @@ vec3 getAtmosAttenuation(); uniform int no_atmo; -vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ if (no_atmo == 1) { return light; } - light *= atten.r; - light += additive * 2.0; - return light; + return (light + additive) * atten * 2.0; } vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { diff --git a/indra/newview/app_settings/shaders/shader_hierarchy.txt b/indra/newview/app_settings/shaders/shader_hierarchy.txt index d8bbf69b38..ebccaddd55 100644 --- a/indra/newview/app_settings/shaders/shader_hierarchy.txt +++ b/indra/newview/app_settings/shaders/shader_hierarchy.txt @@ -7,7 +7,6 @@ avatar/avatarV.glsl - gAvatarProgram, gAvatarWaterProgram sumLights() - lighting/sumLightsV.glsl calcDirectionalLight() - lighting/lightFuncV.glsl calcPointLight() - lighting/lightFuncV.glsl - scaleDownLight() - windlight/atmosphericsHelpersV.glsl atmosAmbient() - windlight/atmosphericsHelpersV.glsl atmosAffectDirectionalLight() - windlight/atmosphericsHelpersV.glsl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -28,7 +27,6 @@ avatar/eyeballV.glsl - gAvatarEyeballProgram atmosAmbient() - windlight/atmosphericsHelpersV.glsl atmosAffectDirectionalLight() - windlight/atmosphericsHelpersV.glsl atmosGetDiffuseSunlightColor() - windlight/atmosphericsHelpersV.glsl - scaleDownLight() - windlight/atmosphericsHelpersV.glsl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ avatar/eyeballF.glsl - gAvatarEyeballProgram main() - avatar/eyeballF.glsl @@ -53,7 +51,6 @@ environment/terrainV.glsl - gTerrainProgram, gTerrainWaterProgram sumLights() - lighting/sumLightsV.glsl calcDirectionalLight() - lighting/lightFuncV.glsl calcPointLight() - lighting/lightFuncV.glsl - scaleDownLight() - windlight/atmosphericsHelpersV.glsl atmosAmbient() - windlight/atmosphericsHelpersV.glsl atmosAffectDirectionalLight() - windlight/atmosphericsHelpersV.glsl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -120,7 +117,6 @@ objects/shinyV.glsl - gObjectShinyProgram, gObjectShinyWaterProgram sumLights() - lighting/sumLightsV.glsl calcDirectionalLight() - lighting/lightFuncV.glsl calcPointLight() - lighting/lightFuncV.glsl - scaleDownLight() - windlight/atmosphericsHelpersV.glsl atmosAmbient() - windlight/atmosphericsHelpersV.glsl atmosAffectDirectionalLight() - windlight/atmosphericsHelpersV.glsl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -143,7 +139,6 @@ objects/simpleV.glsl - gObjectSimpleProgram, gObjectSimpleWaterProgram sumLights() - lighting/sumLightsV.glsl calcDirectionalLight() - lighting/lightFuncV.glsl calcPointLight() - lighting/lightFuncV.glsl - scaleDownLight() - windlight/atmosphericsHelpersV.glsl atmosAmbient() - windlight/atmosphericsHelpersV.glsl atmosAffectDirectionalLight() - windlight/atmosphericsHelpersV.glsl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.2.3 From 2929998982f37221a58b9fa8037748a2e905f4b1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 6 Nov 2018 19:33:04 +0000 Subject: Move to using a shared deferredUtil object for getting pos/norm from gbuffer. Eliminate 20+ callsites with copy-paste of getPosition and/or getNorm code. Make pipeline use getShadowTarget/releaseShadowTarget consistently. --- .../shaders/class1/avatar/avatarSkinV.glsl | 7 -- .../shaders/class1/avatar/objectSkinV.glsl | 7 -- .../shaders/class1/deferred/alphaF.glsl | 19 ++- .../shaders/class1/deferred/alphaV.glsl | 17 +-- .../shaders/class1/deferred/blurLightF.glsl | 24 +--- .../shaders/class1/deferred/impostorF.glsl | 4 +- .../shaders/class1/deferred/materialF.glsl | 21 +--- .../shaders/class1/deferred/multiPointLightF.glsl | 21 +--- .../shaders/class1/deferred/multiSpotLightF.glsl | 14 +-- .../shaders/class1/deferred/pointLightF.glsl | 14 +-- .../shaders/class1/deferred/pointLightV.glsl | 2 +- .../shaders/class1/deferred/postgiF.glsl | 19 +-- .../shaders/class1/deferred/softenLightF.glsl | 32 ++--- .../shaders/class1/deferred/softenLightV.glsl | 1 + .../shaders/class1/deferred/spotLightF.glsl | 13 +- .../app_settings/shaders/class1/deferred/srgb.glsl | 3 - .../shaders/class1/deferred/sunLightSSAOF.glsl | 92 ++------------ .../shaders/class1/deferred/waterF.glsl | 9 -- .../shaders/class1/windlight/atmosphericsF.glsl | 15 +-- .../shaders/class1/windlight/transportF.glsl | 23 +++- .../shaders/class2/deferred/multiSpotLightF.glsl | 13 +- .../shaders/class2/deferred/softenLightF.glsl | 51 +------- .../shaders/class2/deferred/softenLightV.glsl | 2 - .../shaders/class2/deferred/spotLightF.glsl | 13 +- .../shaders/class2/deferred/sunLightF.glsl | 26 +--- .../shaders/class2/deferred/sunLightSSAOF.glsl | 86 +------------ .../shaders/class2/windlight/transportF.glsl | 26 ++-- .../shaders/class3/deferred/cloudsF.glsl | 77 ++++++++---- .../shaders/class3/deferred/cloudsV.glsl | 136 ++------------------- .../shaders/class3/deferred/multiSpotLightF.glsl | 13 +- .../app_settings/shaders/class3/deferred/skyF.glsl | 13 +- .../app_settings/shaders/class3/deferred/skyV.glsl | 8 +- .../shaders/class3/deferred/softenLightF.glsl | 107 +++++++++------- .../shaders/class3/deferred/softenLightV.glsl | 12 +- .../shaders/class3/deferred/spotLightF.glsl | 13 +- .../shaders/class3/deferred/sunLightF.glsl | 22 +--- .../shaders/class3/deferred/sunLightSSAOF.glsl | 89 ++------------ .../shaders/class3/windlight/transportF.glsl | 8 +- 38 files changed, 250 insertions(+), 822 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl b/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl index 767fad016c..c4caed4d71 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl @@ -38,12 +38,5 @@ mat4 getSkinnedTransform() ret[1] = mix(matrixPalette[i+15],matrixPalette[i+16], x); ret[2] = mix(matrixPalette[i+30],matrixPalette[i+31], x); ret[3] = vec4(0,0,0,1); - return ret; - -#ifdef IS_AMD_CARD - // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. - vec4 dummy1 = matrixPalette[0]; - vec4 dummy2 = matrixPalette[44]; -#endif } diff --git a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl index 90bf2851c9..94de2f7b53 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl @@ -61,12 +61,5 @@ mat4 getObjectSkinnedTransform() ret[3] = vec4(trans, 1.0); return ret; - -#ifdef IS_AMD_CARD - // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. - mat3x4 dummy1 = matrixPalette[0]; - mat3x4 dummy2 = matrixPalette[MAX_JOINTS_PER_MESH_OBJECT-1]; -#endif - } diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 3ec2ea12da..a325faaad7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -89,9 +89,7 @@ vec2 encode_normal (vec3 n); vec3 decode_normal (vec2 enc); vec3 scaleSoftClipFrag(vec3 l); -vec3 atmosFragAmbient(vec3 light, vec3 sunlit); 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); vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) @@ -164,6 +162,8 @@ void main() float shadow = 1.0; + vec3 norm = vary_norm; + #if HAS_SHADOW vec4 spos = pos; @@ -268,13 +268,10 @@ void main() vec4 gamma_diff = diff; diff.rgb = srgb_to_linear(diff.rgb); - vec3 norm = vary_norm; - - 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); vec2 abnormal = encode_normal(norm.xyz); @@ -290,7 +287,7 @@ void main() vec4 color = vec4(0,0,0,0); - color.rgb = atmosFragAmbient(color.rgb, amblit); + color.rgb = (color.rgb * 0.5) + amblit; color.a = final_alpha; float ambient = abs(da); @@ -299,7 +296,7 @@ void main() ambient = (1.0-ambient); color.rgb *= ambient; - color.rgb += atmosFragAffectDirectionalLight(final_da, sunlit); + color.rgb += (final_da * sunlit); color.rgb *= gamma_diff.rgb; //color.rgb = mix(diff.rgb, color.rgb, final_alpha); diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 506118d381..394ae80e53 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -73,7 +73,7 @@ void main() vec3 norm; //transform vertex -#ifdef HAS_SKIN +#if defined(HAS_SKIN) mat4 trans = getObjectSkinnedTransform(); trans = modelview_matrix * trans; @@ -83,9 +83,7 @@ void main() norm = normalize((trans * vec4(norm, 1.0)).xyz - pos.xyz); vec4 frag_pos = projection_matrix * pos; gl_Position = frag_pos; -#else - -#ifdef IS_AVATAR_SKIN +#elif defined(IS_AVATAR_SKIN) mat4 trans = getSkinnedTransform(); vec4 pos_in = vec4(position.xyz, 1.0); pos.x = dot(trans[0], pos_in); @@ -107,14 +105,11 @@ void main() gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); #endif -#endif - #ifdef USE_INDEXED_TEX passTextureIndex(); #endif vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - vary_norm = norm; vary_position = pos.xyz; @@ -122,18 +117,14 @@ void main() vertex_color = diffuse_color; #endif -#ifdef HAS_SKIN +#if defined(HAS_SKIN) vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); -#else - -#ifdef IS_AVATAR_SKIN +#elif defined(IS_AVATAR_SKIN) vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); #else pos = modelview_projection_matrix * vert; vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); #endif -#endif - } diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index b56abb66d1..7c9382d474 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -33,7 +33,6 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect depthMap; uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; @@ -45,22 +44,7 @@ uniform float kern_scale; VARYING vec2 vary_fragcoord; -uniform mat4 inv_proj; -uniform vec2 screen_res; - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - +vec4 getPosition(vec2 pos_screen); vec3 decode_normal (vec2 enc); void main() @@ -119,11 +103,5 @@ void main() col.y *= col.y; frag_color = col; - -#ifdef IS_AMD_CARD - // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. - vec3 dummy1 = kern[0]; - vec3 dummy2 = kern[3]; -#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index 6ba16b169c..def149d86d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -32,11 +32,9 @@ out vec4 frag_data[3]; #endif uniform float minimum_alpha; - - uniform sampler2D diffuseMap; -uniform sampler2D normalMap; uniform sampler2D specularMap; +uniform sampler2D normalMap; VARYING vec2 vary_texcoord0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c1c17532b8..1e566b77bf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -40,7 +40,6 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); -vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -176,19 +175,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe } -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - - #else #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -233,6 +219,8 @@ vec3 decode_normal (vec2 enc); void main() { + vec2 pos_screen = vary_texcoord0.xy; + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); diffcol.rgb *= vertex_color.rgb; @@ -390,7 +378,7 @@ void main() final_da = min(final_da, 1.0f); final_da = pow(final_da, 1.0/1.3); - col.rgb = atmosFragAmbient(col, amblit); + col.rgb = (col * 0.5) + amblit; float ambient = min(abs(da), 1.0); ambient *= 0.5; @@ -444,9 +432,6 @@ void main() glare += cur_glare; } - //col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index d1ac19270d..eb65c28645 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -59,18 +59,7 @@ uniform mat4 inv_proj; vec3 decode_normal (vec2 enc); -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { @@ -148,12 +137,4 @@ void main() frag_color.rgb = out_col; frag_color.a = 0.0; - -#ifdef IS_AMD_CARD - // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. - vec4 dummy1 = light[0]; - vec4 dummy2 = light_col[0]; - vec4 dummy3 = light[LIGHT_COUNT-1]; - vec4 dummy4 = light_col[LIGHT_COUNT-1]; -#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 1d75322b4c..3aa7a3a449 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -128,19 +128,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) return ret; } - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 13b803e03e..df48a66fab 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -57,19 +57,7 @@ uniform mat4 inv_proj; uniform vec4 viewport; vec3 decode_normal (vec2 enc); - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = (pos_screen.xy-viewport.xy)*2.0; - sc /= viewport.zw; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl index a5625fbc16..3da8531442 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl @@ -1,5 +1,5 @@ /** - * @file pointLightF.glsl + * @file pointLightV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl index e33254304b..c2963046c5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl @@ -49,18 +49,7 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).a; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { @@ -101,10 +90,4 @@ void main() col = col*col*blur_quad.x + col*blur_quad.y + blur_quad.z; frag_color.rgb = col; - -#ifdef IS_AMD_CARD - // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. - vec2 dummy1 = kern[0]; - vec2 dummy2 = kern[31]; -#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 5627275df6..cac3e75f1f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -69,33 +69,17 @@ vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); +vec3 scaleSoftClipFrag(vec3 l); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec4 getPosition(vec2 pos_screen) -{ //get position in screen space (world units) given window coordinate and depth map - float depth = texture2DRect(depthMap, pos_screen.xy).a; - return getPosition_d(pos_screen, depth); -} - +vec4 getPositionWithDepth(vec2 pos_screen, float depth); void main() { vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPosition_d(tc, depth).xyz; + vec4 pos = getPositionWithDepth(tc, depth); vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; norm.xyz = decode_normal(norm.xy); // unpack norm @@ -156,27 +140,25 @@ void main() 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); + col = mix(col.rgb, refcol, envIntensity); } if (norm.w < 0.5) { col = atmosFragLighting(col, additive, atten); + col = scaleSoftClipFrag(col); } #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); + vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); col = fogged.rgb; bloom = fogged.a; #endif col = srgb_to_linear(col); + //col = vec3(1,0,1); //col.g = envIntensity; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl index b59fcbe017..5655c6f99f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl @@ -30,6 +30,7 @@ ATTRIBUTE vec3 position; uniform vec2 screen_res; VARYING vec2 vary_fragcoord; + void main() { //transform vertex diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 2b6428963d..022bcbabca 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -132,18 +132,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) } -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl index 00ba0e8fad..bc3324f543 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl @@ -48,7 +48,6 @@ vec3 srgb_to_linear(vec3 cs) bvec3 lte = lessThanEqual(cs,vec3(0.04045)); return mix(high_range, low_range, lte); - } vec3 linear_to_srgb(vec3 cl) @@ -59,6 +58,4 @@ vec3 linear_to_srgb(vec3 cl) bvec3 lt = lessThan(cl,vec3(0.0031308)); return mix(high_range, low_range, lt); - } - diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 403df87853..006a49d9a0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -35,102 +35,26 @@ out vec4 frag_color; //class 1 -- no shadow, SSAO only -uniform sampler2DRect depthMap; uniform sampler2DRect normalMap; -uniform sampler2D noiseMap; - // Inputs -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; - VARYING vec2 vary_fragcoord; -uniform mat4 inv_proj; -uniform vec2 screen_res; - vec3 decode_normal (vec2 enc); - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec3 getNorm(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen); //calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm) -{ - float ret = 1.0; - - vec2 kern[8]; - // exponentially (^2) distant occlusion samples spread around origin - kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; - kern[1] = vec2(1.0, 0.0) * 0.250*0.250; - kern[2] = vec2(0.0, 1.0) * 0.375*0.375; - kern[3] = vec2(0.0, -1.0) * 0.500*0.500; - kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; - kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; - kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; - kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; - - vec2 pos_screen = vary_fragcoord.xy; - vec3 pos_world = pos.xyz; - vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; - - float angle_hidden = 0.0; - int points = 0; - - float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); - - // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations unrolling?) - for (int i = 0; i < 8; i++) - { - vec2 samppos_screen = pos_screen + scale * reflect(kern[i], noise_reflect); - vec3 samppos_world = getPosition(samppos_screen).xyz; - - vec3 diff = pos_world - samppos_world; - float dist2 = dot(diff, diff); - - // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area - // --> solid angle shrinking by the square of distance - //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 - //(k should vary inversely with # of samples, but this is taken care of later) - - angle_hidden = angle_hidden + float(dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) * min(1.0/dist2, ssao_factor_inv); - - // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" - points = points + int(diff.z > -1.0); - } - - angle_hidden = min(ssao_factor*angle_hidden/float(points), 1.0); - - ret = (1.0 - (float(points != 0) * angle_hidden)); - - return min(ret, 1.0); -} +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); void main() { - vec2 pos_screen = vary_fragcoord.xy; - - //try doing an unproject here - - vec4 pos = getPosition(pos_screen); - - vec3 norm = texture2DRect(normalMap, pos_screen).xyz; - norm = decode_normal(norm.xy); - + vec2 pos_screen = vary_fragcoord.xy; + vec4 pos = getPosition(pos_screen); + vec3 norm = getNorm(pos_screen); + frag_color[0] = 1.0; - frag_color[1] = calcAmbientOcclusion(pos, norm); + frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); frag_color[2] = 1.0; frag_color[3] = 1.0; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 73f6d9fec3..69543b93ea 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -41,15 +41,6 @@ uniform sampler2D bumpMap2; uniform float blend_factor; uniform sampler2D screenTex; uniform sampler2D refTex; -uniform sampler2DRectShadow shadowMap0; -uniform sampler2DRectShadow shadowMap1; -uniform sampler2DRectShadow shadowMap2; -uniform sampler2DRectShadow shadowMap3; -uniform sampler2D noiseMap; - -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; - uniform float sunAngle; uniform float sunAngle2; uniform vec3 lightDir; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl index c1cc3679a7..2b8cf9d8df 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl @@ -23,21 +23,10 @@ * $/LicenseInfo$ */ -vec3 atmosFragAmbient(vec3 light, vec3 sunlit) -{ - /* stub function for fallback compatibility on class1 hardware */ - return light; -} - vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { - /* stub function for fallback compatibility on class1 hardware */ - return light; -} - -vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit) -{ - return light * sunlit; + /* stub function for fallback compatibility on class1 hardware */ + return light; } vec3 atmosLighting(vec3 light) diff --git a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl index ebce9ea91d..e2b391cb7a 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl @@ -1,5 +1,5 @@ /** - * @file transportF.glsl + * @file class1/windlight/transportF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -25,6 +25,24 @@ uniform int no_atmo; +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + +vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 atten, vec3 additive) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + vec3 atmosTransport(vec3 light) { /* stub function for fallback compatibility on class1 hardware */ @@ -33,11 +51,12 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransport(vec3 light) { + /* stub function for fallback compatibility on class1 hardware */ return light; } vec3 fullbrightShinyAtmosTransport(vec3 light) { + /* stub function for fallback compatibility on class1 hardware */ return light; } - diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 864ba4859d..0848adba73 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -133,18 +133,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) } -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index c92dbda185..33f3eb46c0 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -83,51 +83,12 @@ vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 fullbrightScaleSoftClipFrag(vec3 l); vec3 scaleSoftClipFrag(vec3 l); -vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) -{ - if (no_atmo == 1) - { - return light; - } - return (light + additive) * atten.r * 2.0; -} - -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); -} - -vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); -} - -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec4 getPosition(vec2 pos_screen) -{ //get position in screen space (world units) given window coordinate and depth map - float depth = texture2DRect(depthMap, pos_screen.xy).r; - return getPosition_d(pos_screen, depth); -} +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten); +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); +vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +vec4 getPosition(vec2 pos_screen); #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); @@ -137,7 +98,7 @@ void main() { vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPosition_d(tc, depth).xyz; + vec4 pos = getPositionWithDepth(tc, depth); vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; norm.xyz = decode_normal(norm.xy); // unpack norm diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl index c840d72784..8b8b338f68 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl @@ -36,7 +36,5 @@ void main() //transform vertex vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); gl_Position = pos; - - vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index a7da140b31..80e2a9dd55 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -133,18 +133,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) } -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index aa5e99a2f7..c4018ca61a 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -67,20 +67,9 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; +vec3 getNorm(vec2 pos_screen); vec3 decode_normal (vec2 enc); - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { @@ -123,14 +112,9 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_scr void main() { - vec2 pos_screen = vary_fragcoord.xy; - - //try doing an unproject here - - vec4 pos = getPosition(pos_screen); - - vec3 norm = texture2DRect(normalMap, pos_screen).xyz; - norm = decode_normal(norm.xy); // unpack norm + vec2 pos_screen = vary_fragcoord.xy; + vec4 pos = getPosition(pos_screen); + vec3 norm = getNorm(pos_screen); /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 58f3f2f91e..bd468306ee 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -70,79 +70,10 @@ uniform float spot_shadow_offset; vec3 decode_normal (vec2 enc); -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec2 getKern(int i) -{ - vec2 kern[8]; - // exponentially (^2) distant occlusion samples spread around origin - kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; - kern[1] = vec2(1.0, 0.0) * 0.250*0.250; - kern[2] = vec2(0.0, 1.0) * 0.375*0.375; - kern[3] = vec2(0.0, -1.0) * 0.500*0.500; - kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; - kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; - kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; - kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; - - return kern[i]; -} - -//calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm) -{ - float ret = 1.0; - - vec2 pos_screen = vary_fragcoord.xy; - vec3 pos_world = pos.xyz; - vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; - - float angle_hidden = 0.0; - float points = 0; - - float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); - - // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) - for (int i = 0; i < 8; i++) - { - vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); - vec3 samppos_world = getPosition(samppos_screen).xyz; - - vec3 diff = pos_world - samppos_world; - float dist2 = dot(diff, diff); - - // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area - // --> solid angle shrinking by the square of distance - //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 - //(k should vary inversely with # of samples, but this is taken care of later) - - float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; - angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); - - // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" - float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; - points = points + diffz_val; - } - - angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); - - float points_val = (points > 0.0) ? 1.0 : 0.0; - ret = (1.0 - (points_val * angle_hidden)); +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); - ret = max(ret, 0.0); - return min(ret, 1.0); -} +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { @@ -185,13 +116,8 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_scr void main() { vec2 pos_screen = vary_fragcoord.xy; - - //try doing an unproject here - - vec4 pos = getPosition(pos_screen); - - vec3 norm = texture2DRect(normalMap, pos_screen).xyz; - norm = decode_normal(norm.xy); // unpack norm + vec4 pos = getPosition(pos_screen); + vec3 norm = getNorm(pos_screen); /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { @@ -291,7 +217,7 @@ void main() } frag_color[0] = shadow; - frag_color[1] = calcAmbientOcclusion(pos, norm); + frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index bf64605014..75d1bb0cd5 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -32,7 +32,7 @@ vec3 getAtmosAttenuation(); uniform int no_atmo; -vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { if (no_atmo == 1) { @@ -41,32 +41,36 @@ vec3 atmosFragTransport(vec3 light, vec3 atten, vec3 additive) return (light + additive) * atten * 2.0; } -vec3 fullbrightFragAtmosTransport(vec3 light, vec3 atten, vec3 additive) { +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ if (no_atmo == 1) { return light; } float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosFragTransport(light.rgb, atten, additive), light.rgb + additive.rgb, brightness * brightness); + return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); } -vec3 fullbrightFragShinyAtmosTransport(vec3 light, vec3 atten, vec3 additive) { +vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 atten, vec3 additive) { if (no_atmo == 1) { return light; } float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosFragTransport(light.rgb, atten, additive), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); + return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); } -vec3 atmosTransport(vec3 light) { - return (no_atmo == 1) ? light : atmosFragTransport(light, getAtmosAttenuation(), getAdditiveColor()); +vec3 atmosTransport(vec3 light) +{ + return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } -vec3 fullbrightAtmosTransport(vec3 light) { - return (no_atmo == 1) ? light : fullbrightFragAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +vec3 fullbrightAtmosTransport(vec3 light) +{ + return fullbrightAtmosTransportFrag(light,getAdditiveColor(), getAtmosAttenuation()); } -vec3 fullbrightShinyAtmosTransport(vec3 light) { - return (no_atmo == 1) ? light : fullbrightFragShinyAtmosTransport(light, getAtmosAttenuation(), getAdditiveColor()); +vec3 fullbrightShinyAtmosTransport(vec3 light) +{ + return fullbrightShinyAtmosTransportFrag(light,getAdditiveColor(), getAtmosAttenuation()); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl index 9f06319da3..f8373215f0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -1,5 +1,5 @@ /** - * @file WLCloudsF.glsl + * @file class3/deferred/cloudsF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -24,9 +24,9 @@ */ #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; +out vec4 frag_data[3]; #else -#define frag_color gl_FragColor +#define frag_data gl_FragData #endif ///////////////////////////////////////////////////////////////////////// @@ -36,20 +36,37 @@ out vec4 frag_color; VARYING vec4 vary_CloudColorSun; VARYING vec4 vary_CloudColorAmbient; VARYING float vary_CloudDensity; +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; +VARYING vec3 vary_pos; uniform sampler2D cloud_noise_texture; uniform sampler2D cloud_noise_texture_next; uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; -uniform vec4 gamma; +uniform vec4 sunlight_color; +uniform vec4 cloud_color; +uniform float cloud_shadow; uniform float cloud_scale; uniform float cloud_variance; - -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; +uniform vec3 ambient; +uniform vec3 camPosLocal; +uniform vec3 sun_dir; +uniform float sun_size; +uniform float far_z; + +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D single_mie_scattering_texture; +uniform sampler2D irradiance_texture; +uniform sampler2D sh_input_r; +uniform sampler2D sh_input_g; +uniform sampler2D sh_input_b; + +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); @@ -67,11 +84,9 @@ void main() // Set variables vec2 uv1 = vary_texcoord0.xy; vec2 uv2 = vary_texcoord1.xy; - - vec4 cloudColorSun = vary_CloudColorSun; - vec4 cloudColorAmbient = vary_CloudColorAmbient; - float cloudDensity = vary_CloudDensity; vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); + vec2 uv4 = vary_texcoord3.xy; vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); @@ -82,33 +97,53 @@ void main() uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0)); - // Compute alpha1, the main cloud opacity + cloudDensity *= 1.0 - (density_variance * density_variance); + // Compute alpha1, the main cloud opacity float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * (10. + disturbance.y) * cloud_pos_density1.z, 1.); + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); // And smooth alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; + if (alpha1 < 0.001f) + { + discard; + } // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * (2.5 + disturbance.x) * cloud_pos_density1.z, 1.); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); // And smooth alpha2 = 1. - alpha2; alpha2 = 1. - alpha2 * alpha2; + vec3 view_ray = vary_pos.xyz + camPosLocal; + + vec3 view_direction = normalize(view_ray); + vec3 sun_direction = normalize(sun_dir); + vec3 earth_center = vec3(0, 0, -6360.0f); + vec3 camPos = (camPosLocal / 1000.0f) - earth_center; + + vec3 transmittance; + vec3 radiance_sun = GetSkyLuminance(camPos, view_direction, 1.0 - alpha1, sun_direction, transmittance); + + vec3 sun_color = vec3(1.0) - exp(-radiance_sun * 0.0001); + // Combine vec4 color; - color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); - color *= 2.; - /// Gamma correct for WL (soft clip effect). - frag_color.rgb = scaleSoftClip(color.rgb); - frag_color.a = alpha1; + color.rgb = sun_color * cloud_color.rgb * (1. - alpha2); + color.rgb = pow(color.rgb, vec3(1.0 / 2.2)); + color.rgb += ambient; + + frag_data[0] = vec4(color.rgb, alpha1); + frag_data[1] = vec4(0); + frag_data[2] = vec4(0,1,0,1); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl index c1dd45cd67..53b6d88ef5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl @@ -24,6 +24,7 @@ */ uniform mat4 modelview_projection_matrix; +uniform mat4 modelview_matrix; ATTRIBUTE vec3 position; ATTRIBUTE vec2 texcoord0; @@ -33,158 +34,37 @@ ATTRIBUTE vec2 texcoord0; /////////////////////////////////////////////////////////////////////////////// // Output parameters -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; -VARYING float vary_CloudDensity; VARYING vec2 vary_texcoord0; VARYING vec2 vary_texcoord1; VARYING vec2 vary_texcoord2; VARYING vec2 vary_texcoord3; +VARYING vec3 vary_pos; // Inputs -uniform vec3 camPosLocal; - -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; - -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float max_y; - -uniform vec4 glow; - -uniform vec4 cloud_color; - uniform float cloud_scale; +uniform vec4 lightnorm; +uniform vec3 camPosLocal; void main() { + vary_pos = position; // World / view / projection gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - vary_texcoord0 = texcoord0; - - // Get relative position - vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); - - // Set altitude - if (P.y > 0.) - { - P *= (max_y / P.y); - } - else - { - P *= (-32000. / P.y); - } - - // Can normalize then - vec3 Pn = normalize(P); - float Plen = length(P); - - // Initialize temp variables - vec4 temp1 = vec4(0.); - vec4 temp2 = vec4(0.); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - - // Calculate relative weights - temp1 = blue_density + haze_density; - blue_weight = blue_density / temp1; - haze_weight = haze_density / temp1; - - // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Distance - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); - - - // Compute haze glow - temp2.x = dot(Pn, lightnorm.xyz); - temp2.x = 1. - temp2.x; - // temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .001); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // Add "minimum anti-solar illumination" - temp2.x += .25; - - // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; - - // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); - - // Haze color below cloud - vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) - ); - - // CLOUDS - - sunlight = sunlight_color; - temp2.y = max(0., lightnorm.y * 2.); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Cloud color out - vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; - vary_CloudColorAmbient = tmpAmbient * cloud_color; - - // Attenuate cloud color by atmosphere - temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds - vary_CloudColorSun *= temp1; - vary_CloudColorAmbient *= temp1; - vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); - - // Make a nice cloud density based on the cloud_shadow value that was passed in. - vary_CloudDensity = 2. * (cloud_shadow - 0.25); - - // Texture coords vary_texcoord0 = texcoord0; vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; - vary_texcoord0.xy += 0.5; + vary_texcoord0.xy /= cloud_scale; + vary_texcoord0.xy += 0.5; vary_texcoord1 = vary_texcoord0; vary_texcoord1.x += lightnorm.x * 0.0125; - vary_texcoord1.y += lightnorm.z * 0.0125; + vary_texcoord1.y += lightnorm.z * 0.0125; vary_texcoord2 = vary_texcoord0 * 16.; vary_texcoord3 = vary_texcoord1 * 16.; - // Combine these to minimize register use - vary_CloudColorAmbient += oHazeColorBelowCloud; - - // needs this to compile on mac - //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); - // END CLOUDS } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 864ba4859d..0848adba73 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -133,18 +133,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) } -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index 2073fc066f..d0514f7d23 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -1,5 +1,5 @@ /** - * @file class3/skyF.glsl + * @file class3/deferred/skyF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -44,6 +44,7 @@ uniform sampler3D single_mie_scattering_texture; uniform sampler2D irradiance_texture; uniform sampler2D rainbow_map; uniform sampler2D halo_map; +uniform vec4 gamma; uniform float moisture_level; uniform float droplet_radius; @@ -53,6 +54,7 @@ vec3 GetSolarLuminance(); vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); +vec3 ColorFromRadiance(vec3 radiance); vec3 rainbow(float d) { float rad = (droplet_radius - 5.0f) / 1024.0f; @@ -93,18 +95,15 @@ void main() } s = smoothstep(0.9, 1.0, s) * 16.0f; - vec3 color = vec3(1.0) - exp(-radiance_sun * 0.0001); + vec3 color = ColorFromRadiance(radiance_sun); float optic_d = dot(view_direction, sun_direction); - vec3 halo_22 = halo22(optic_d); - if (optic_d <= 0) - color.rgb += rainbow(optic_d); - + color.rgb += rainbow(optic_d) * optic_d; color.rgb += halo_22; - color = pow(color, vec3(1.0 / 2.2)); + color = pow(color, vec3(1.0/2.2)); frag_data[0] = vec4(color, 1.0 + s); frag_data[1] = vec4(0.0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl index a5cc49ca30..2eb222ada4 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl @@ -1,5 +1,5 @@ /** - * @file advancedAtmoV.glsl + * @file class3/deferred/skyV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -23,12 +23,6 @@ * $/LicenseInfo$ */ -uniform vec3 cameraPosLocal; -uniform mat4 modelview_projection_matrix; -uniform mat4 modelview_matrix; -uniform mat4 inv_proj; -uniform mat4 inv_modelview; - ATTRIBUTE vec3 position; ATTRIBUTE vec2 texcoord0; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 2615400e52..ecf6858136 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -38,30 +38,21 @@ uniform sampler2DRect specularRect; uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; +uniform sampler2D lightFunc; uniform float blur_size; +uniform samplerCube environmentMap; + uniform float blur_fidelity; // Inputs uniform vec4 morphFactor; uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; uniform vec4 gamma; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 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 vec4 glow; uniform float global_gamma; -uniform float scene_light_strength; uniform mat3 env_mat; uniform vec4 shadow_clip; uniform mat3 ssao_effect_mat; @@ -74,28 +65,29 @@ uniform mat4 inv_modelview; uniform vec2 screen_res; +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D single_mie_scattering_texture; +uniform sampler2D irradiance_texture; + +uniform sampler2D sh_input_r; +uniform sampler2D sh_input_g; +uniform sampler2D sh_input_b; + +vec3 GetSunAndSkyIrradiance(vec3 camPos, vec3 norm, vec3 dir, out vec3 sky_irradiance); +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); +vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); + +vec3 scaleSoftClipFrag(vec3 c); +vec3 fullbrightScaleSoftClipFrag(vec3 c); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec4 getPosition(vec2 pos_screen) -{ //get position in screen space (world units) given window coordinate and depth map - float depth = texture2DRect(depthMap, pos_screen.xy).r; - return getPosition_d(pos_screen, depth); -} - +vec3 ColorFromRadiance(vec3 radiance); +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); @@ -105,24 +97,22 @@ void main() { vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPosition_d(tc, depth).xyz; + vec3 pos = getPositionWithDepth(tc, depth).xyz; vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; - norm.xyz = decode_normal(norm.xy); // unpack norm - + norm.xyz = decode_normal(norm.xy); + float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); float light_gamma = 1.0/1.3; - da = pow(da, light_gamma); - vec4 diffuse = texture2DRect(diffuseRect, tc); + vec4 diffuse = texture2DRect(diffuseRect, tc); // linear - //convert to gamma space - diffuse.rgb = linear_to_srgb(diffuse.rgb); - vec3 col; float bloom = 0.0; { + vec3 camPos = (camPosLocal / 1000.0f) + vec3(0, 0, 6360.0f); + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; @@ -132,17 +122,37 @@ void main() float ambocc = scol_ambocc.g; - col *= diffuse.rgb; - + vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); + vec4 l1r = texture2D(sh_input_r, vec2(0,0)); + vec4 l1g = texture2D(sh_input_g, vec2(0,0)); + vec4 l1b = texture2D(sh_input_b, vec2(0,0)); + + vec3 indirect = vec3(dot(l1r, l1tap * vec4(1, norm.xyz)), + dot(l1g, l1tap * vec4(1, norm.xyz)), + dot(l1b, l1tap * vec4(1, norm.xyz))); + + indirect = clamp(indirect, vec3(0), vec3(1.0)); + + vec3 transmittance; + vec3 sky_irradiance; + vec3 sun_irradiance = GetSunAndSkyIrradiance(camPos, norm.xyz, sun_dir, sky_irradiance); + vec3 inscatter = GetSkyLuminanceToPoint(camPos, (pos / 1000.f) + vec3(0, 0, 6360.0f), scol, sun_dir, transmittance); + + vec3 radiance = scol * (sun_irradiance + sky_irradiance) + inscatter; + vec3 atmo_color = ColorFromRadiance(radiance); + + col = atmo_color + indirect; + col *= transmittance; + col *= diffuse.rgb; + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection { // the old infinite-sky shiny reflection // - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); + vec3 dumbshiny = scol * texture2D(lightFunc, vec2(sa, spec.a)).r * atmo_color; // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; @@ -155,17 +165,24 @@ void main() 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 sun_direction = (inv_modelview * vec4(sun_dir, 1.0)).xyz; + vec3 radiance_sun = GetSkyLuminance(camPos, env_vec, 0.0f, sun_direction, transmittance); + vec3 refcol = ColorFromRadiance(radiance_sun); + col = mix(col.rgb, refcol, envIntensity); } + /*if (norm.w < 0.5) + { + col = scaleSoftClipFrag(col); + }*/ + #ifdef WATER_FOG vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); col = fogged.rgb; bloom = fogged.a; #endif - col = srgb_to_linear(col); + col = pow(col, vec3(light_gamma)); } frag_color.rgb = col; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl index c840d72784..9d872b8df8 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl @@ -1,5 +1,5 @@ /** - * @file softenLightF.glsl + * @file class3/deferred/softenLightV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -22,21 +22,17 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - -uniform mat4 modelview_projection_matrix; - ATTRIBUTE vec3 position; -uniform vec2 screen_res; - VARYING vec2 vary_fragcoord; +uniform mat4 modelview_projection_matrix; +uniform vec2 screen_res; + void main() { //transform vertex vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); gl_Position = pos; - - vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index a7da140b31..80e2a9dd55 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -133,18 +133,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) } -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl index aa5e99a2f7..894534b105 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl @@ -68,19 +68,8 @@ uniform float spot_shadow_bias; uniform float spot_shadow_offset; vec3 decode_normal (vec2 enc); - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { @@ -124,13 +113,8 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_scr void main() { vec2 pos_screen = vary_fragcoord.xy; - - //try doing an unproject here - vec4 pos = getPosition(pos_screen); - - vec3 norm = texture2DRect(normalMap, pos_screen).xyz; - norm = decode_normal(norm.xy); // unpack norm + vec3 norm = getNorm(pos_screen); /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl index 58f3f2f91e..0870a80a32 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl @@ -68,81 +68,11 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -vec3 decode_normal (vec2 enc); - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec2 getKern(int i) -{ - vec2 kern[8]; - // exponentially (^2) distant occlusion samples spread around origin - kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; - kern[1] = vec2(1.0, 0.0) * 0.250*0.250; - kern[2] = vec2(0.0, 1.0) * 0.375*0.375; - kern[3] = vec2(0.0, -1.0) * 0.500*0.500; - kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; - kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; - kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; - kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; - - return kern[i]; -} +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); //calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm) -{ - float ret = 1.0; - - vec2 pos_screen = vary_fragcoord.xy; - vec3 pos_world = pos.xyz; - vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; - - float angle_hidden = 0.0; - float points = 0; - - float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); - - // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) - for (int i = 0; i < 8; i++) - { - vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); - vec3 samppos_world = getPosition(samppos_screen).xyz; - - vec3 diff = pos_world - samppos_world; - float dist2 = dot(diff, diff); - - // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area - // --> solid angle shrinking by the square of distance - //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 - //(k should vary inversely with # of samples, but this is taken care of later) - - float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; - angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); - - // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" - float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; - points = points + diffz_val; - } - - angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); - - float points_val = (points > 0.0) ? 1.0 : 0.0; - ret = (1.0 - (points_val * angle_hidden)); - - ret = max(ret, 0.0); - return min(ret, 1.0); -} +float calcAmbientOcclusion(vec4 pos, vec3 norm, pos_screen); float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { @@ -184,14 +114,9 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_scr void main() { - vec2 pos_screen = vary_fragcoord.xy; - - //try doing an unproject here - - vec4 pos = getPosition(pos_screen); - - vec3 norm = texture2DRect(normalMap, pos_screen).xyz; - norm = decode_normal(norm.xy); // unpack norm + vec2 pos_screen = vary_fragcoord.xy; + vec4 pos = getPosition(pos_screen); + vec3 norm = getNorm(pos_screen); /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { @@ -291,7 +216,7 @@ void main() } frag_color[0] = shadow; - frag_color[1] = calcAmbientOcclusion(pos, norm); + frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index 8195801be6..9c050256dc 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -41,16 +41,18 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) return (light + additive) * atten * 2.0; } -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ if (no_atmo == 1) { return light; } float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive,a tten), light.rgb + additive.rgb, brightness * brightness); + return mix(atmosTransportFrag(light.rgb, additive,atten), light.rgb + additive.rgb, brightness * brightness); } -vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 atten, vec3 additive) { +vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ if (no_atmo == 1) { return light; -- cgit v1.2.3 From db270df7cc00c1e2519749831e7e98c2c10e3ee6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 9 Nov 2018 18:31:29 +0000 Subject: Back out changes causing broken shadows and other render shenanigans. --- .../shaders/class1/avatar/avatarSkinV.glsl | 7 ++ .../shaders/class1/avatar/objectSkinV.glsl | 7 ++ .../shaders/class1/deferred/alphaF.glsl | 19 +-- .../shaders/class1/deferred/alphaV.glsl | 17 ++- .../shaders/class1/deferred/blurLightF.glsl | 24 +++- .../shaders/class1/deferred/impostorF.glsl | 4 +- .../shaders/class1/deferred/materialF.glsl | 21 +++- .../shaders/class1/deferred/multiPointLightF.glsl | 21 +++- .../shaders/class1/deferred/multiSpotLightF.glsl | 14 ++- .../shaders/class1/deferred/pointLightF.glsl | 14 ++- .../shaders/class1/deferred/pointLightV.glsl | 2 +- .../shaders/class1/deferred/postgiF.glsl | 19 ++- .../shaders/class1/deferred/softenLightF.glsl | 32 +++-- .../shaders/class1/deferred/softenLightV.glsl | 1 - .../shaders/class1/deferred/spotLightF.glsl | 13 +- .../app_settings/shaders/class1/deferred/srgb.glsl | 3 + .../shaders/class1/deferred/sunLightSSAOF.glsl | 92 ++++++++++++-- .../shaders/class1/deferred/waterF.glsl | 9 ++ .../shaders/class1/windlight/atmosphericsF.glsl | 15 ++- .../shaders/class2/deferred/multiSpotLightF.glsl | 13 +- .../shaders/class2/deferred/softenLightF.glsl | 51 +++++++- .../shaders/class2/deferred/softenLightV.glsl | 2 + .../shaders/class2/deferred/spotLightF.glsl | 13 +- .../shaders/class2/deferred/sunLightF.glsl | 26 +++- .../shaders/class2/deferred/sunLightSSAOF.glsl | 86 ++++++++++++- .../shaders/class3/deferred/cloudsF.glsl | 77 ++++-------- .../shaders/class3/deferred/cloudsV.glsl | 136 +++++++++++++++++++-- .../shaders/class3/deferred/multiSpotLightF.glsl | 13 +- .../app_settings/shaders/class3/deferred/skyF.glsl | 13 +- .../app_settings/shaders/class3/deferred/skyV.glsl | 8 +- .../shaders/class3/deferred/softenLightF.glsl | 107 +++++++--------- .../shaders/class3/deferred/softenLightV.glsl | 12 +- .../shaders/class3/deferred/spotLightF.glsl | 13 +- .../shaders/class3/deferred/sunLightF.glsl | 22 +++- .../shaders/class3/deferred/sunLightSSAOF.glsl | 89 ++++++++++++-- 35 files changed, 806 insertions(+), 209 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl b/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl index c4caed4d71..767fad016c 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl @@ -38,5 +38,12 @@ mat4 getSkinnedTransform() ret[1] = mix(matrixPalette[i+15],matrixPalette[i+16], x); ret[2] = mix(matrixPalette[i+30],matrixPalette[i+31], x); ret[3] = vec4(0,0,0,1); + return ret; + +#ifdef IS_AMD_CARD + // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. + vec4 dummy1 = matrixPalette[0]; + vec4 dummy2 = matrixPalette[44]; +#endif } diff --git a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl index 94de2f7b53..90bf2851c9 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl @@ -61,5 +61,12 @@ mat4 getObjectSkinnedTransform() ret[3] = vec4(trans, 1.0); return ret; + +#ifdef IS_AMD_CARD + // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. + mat3x4 dummy1 = matrixPalette[0]; + mat3x4 dummy2 = matrixPalette[MAX_JOINTS_PER_MESH_OBJECT-1]; +#endif + } diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index a325faaad7..3ec2ea12da 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -89,7 +89,9 @@ vec2 encode_normal (vec3 n); vec3 decode_normal (vec2 enc); vec3 scaleSoftClipFrag(vec3 l); +vec3 atmosFragAmbient(vec3 light, vec3 sunlit); 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); vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) @@ -162,8 +164,6 @@ void main() float shadow = 1.0; - vec3 norm = vary_norm; - #if HAS_SHADOW vec4 spos = pos; @@ -268,10 +268,13 @@ void main() vec4 gamma_diff = diff; diff.rgb = srgb_to_linear(diff.rgb); - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; + vec3 norm = vary_norm; + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); vec2 abnormal = encode_normal(norm.xyz); @@ -287,7 +290,7 @@ void main() vec4 color = vec4(0,0,0,0); - color.rgb = (color.rgb * 0.5) + amblit; + color.rgb = atmosFragAmbient(color.rgb, amblit); color.a = final_alpha; float ambient = abs(da); @@ -296,7 +299,7 @@ void main() ambient = (1.0-ambient); color.rgb *= ambient; - color.rgb += (final_da * sunlit); + color.rgb += atmosFragAffectDirectionalLight(final_da, sunlit); color.rgb *= gamma_diff.rgb; //color.rgb = mix(diff.rgb, color.rgb, final_alpha); diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 394ae80e53..506118d381 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -73,7 +73,7 @@ void main() vec3 norm; //transform vertex -#if defined(HAS_SKIN) +#ifdef HAS_SKIN mat4 trans = getObjectSkinnedTransform(); trans = modelview_matrix * trans; @@ -83,7 +83,9 @@ void main() norm = normalize((trans * vec4(norm, 1.0)).xyz - pos.xyz); vec4 frag_pos = projection_matrix * pos; gl_Position = frag_pos; -#elif defined(IS_AVATAR_SKIN) +#else + +#ifdef IS_AVATAR_SKIN mat4 trans = getSkinnedTransform(); vec4 pos_in = vec4(position.xyz, 1.0); pos.x = dot(trans[0], pos_in); @@ -105,11 +107,14 @@ void main() gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); #endif +#endif + #ifdef USE_INDEXED_TEX passTextureIndex(); #endif vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + vary_norm = norm; vary_position = pos.xyz; @@ -117,14 +122,18 @@ void main() vertex_color = diffuse_color; #endif -#if defined(HAS_SKIN) +#ifdef HAS_SKIN vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); -#elif defined(IS_AVATAR_SKIN) +#else + +#ifdef IS_AVATAR_SKIN vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); #else pos = modelview_projection_matrix * vert; vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); #endif +#endif + } diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index 7c9382d474..b56abb66d1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -33,6 +33,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif +uniform sampler2DRect depthMap; uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; @@ -44,7 +45,22 @@ uniform float kern_scale; VARYING vec2 vary_fragcoord; -vec4 getPosition(vec2 pos_screen); +uniform mat4 inv_proj; +uniform vec2 screen_res; + +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + vec3 decode_normal (vec2 enc); void main() @@ -103,5 +119,11 @@ void main() col.y *= col.y; frag_color = col; + +#ifdef IS_AMD_CARD + // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. + vec3 dummy1 = kern[0]; + vec3 dummy2 = kern[3]; +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index def149d86d..6ba16b169c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -32,9 +32,11 @@ out vec4 frag_data[3]; #endif uniform float minimum_alpha; + + uniform sampler2D diffuseMap; -uniform sampler2D specularMap; uniform sampler2D normalMap; +uniform sampler2D specularMap; VARYING vec2 vary_texcoord0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 1e566b77bf..c1c17532b8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -40,6 +40,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); +vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -175,6 +176,19 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe } +vec4 getPosition_d(vec2 pos_screen, float depth) +{ + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + + #else #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -219,8 +233,6 @@ vec3 decode_normal (vec2 enc); void main() { - vec2 pos_screen = vary_texcoord0.xy; - vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); diffcol.rgb *= vertex_color.rgb; @@ -378,7 +390,7 @@ void main() final_da = min(final_da, 1.0f); final_da = pow(final_da, 1.0/1.3); - col.rgb = (col * 0.5) + amblit; + col.rgb = atmosFragAmbient(col, amblit); float ambient = min(abs(da), 1.0); ambient *= 0.5; @@ -432,6 +444,9 @@ void main() glare += cur_glare; } + //col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); + //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index eb65c28645..d1ac19270d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -59,7 +59,18 @@ uniform mat4 inv_proj; vec3 decode_normal (vec2 enc); -vec4 getPosition(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} void main() { @@ -137,4 +148,12 @@ void main() frag_color.rgb = out_col; frag_color.a = 0.0; + +#ifdef IS_AMD_CARD + // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. + vec4 dummy1 = light[0]; + vec4 dummy2 = light_col[0]; + vec4 dummy3 = light[LIGHT_COUNT-1]; + vec4 dummy4 = light_col[LIGHT_COUNT-1]; +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 3aa7a3a449..1d75322b4c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -128,7 +128,19 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) return ret; } -vec4 getPosition(vec2 pos_screen); + +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index df48a66fab..13b803e03e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -57,7 +57,19 @@ uniform mat4 inv_proj; uniform vec4 viewport; vec3 decode_normal (vec2 enc); -vec4 getPosition(vec2 pos_screen); + +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = (pos_screen.xy-viewport.xy)*2.0; + sc /= viewport.zw; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl index 3da8531442..a5625fbc16 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl @@ -1,5 +1,5 @@ /** - * @file pointLightV.glsl + * @file pointLightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl index c2963046c5..e33254304b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl @@ -49,7 +49,18 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -vec4 getPosition(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).a; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} void main() { @@ -90,4 +101,10 @@ void main() col = col*col*blur_quad.x + col*blur_quad.y + blur_quad.z; frag_color.rgb = col; + +#ifdef IS_AMD_CARD + // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. + vec2 dummy1 = kern[0]; + vec2 dummy2 = kern[31]; +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index cac3e75f1f..5627275df6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -69,17 +69,33 @@ vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); -vec3 scaleSoftClipFrag(vec3 l); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); -vec4 getPositionWithDepth(vec2 pos_screen, float depth); +vec4 getPosition_d(vec2 pos_screen, float depth) +{ + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec4 getPosition(vec2 pos_screen) +{ //get position in screen space (world units) given window coordinate and depth map + float depth = texture2DRect(depthMap, pos_screen.xy).a; + return getPosition_d(pos_screen, depth); +} + void main() { vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; - vec4 pos = getPositionWithDepth(tc, depth); + vec3 pos = getPosition_d(tc, depth).xyz; vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; norm.xyz = decode_normal(norm.xy); // unpack norm @@ -140,25 +156,27 @@ void main() 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); + + col = mix(col.rgb, refcol, + envIntensity); } if (norm.w < 0.5) { col = atmosFragLighting(col, additive, atten); - col = scaleSoftClipFrag(col); } #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); + vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); col = fogged.rgb; bloom = fogged.a; #endif col = srgb_to_linear(col); - //col = vec3(1,0,1); //col.g = envIntensity; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl index 5655c6f99f..b59fcbe017 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl @@ -30,7 +30,6 @@ ATTRIBUTE vec3 position; uniform vec2 screen_res; VARYING vec2 vary_fragcoord; - void main() { //transform vertex diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 022bcbabca..2b6428963d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -132,7 +132,18 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) } -vec4 getPosition(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl index bc3324f543..00ba0e8fad 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl @@ -48,6 +48,7 @@ vec3 srgb_to_linear(vec3 cs) bvec3 lte = lessThanEqual(cs,vec3(0.04045)); return mix(high_range, low_range, lte); + } vec3 linear_to_srgb(vec3 cl) @@ -58,4 +59,6 @@ vec3 linear_to_srgb(vec3 cl) bvec3 lt = lessThan(cl,vec3(0.0031308)); return mix(high_range, low_range, lt); + } + diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 006a49d9a0..403df87853 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -35,26 +35,102 @@ out vec4 frag_color; //class 1 -- no shadow, SSAO only +uniform sampler2DRect depthMap; uniform sampler2DRect normalMap; +uniform sampler2D noiseMap; + // Inputs +uniform float ssao_radius; +uniform float ssao_max_radius; +uniform float ssao_factor; +uniform float ssao_factor_inv; + VARYING vec2 vary_fragcoord; +uniform mat4 inv_proj; +uniform vec2 screen_res; + vec3 decode_normal (vec2 enc); -vec3 getNorm(vec2 pos_screen); -vec4 getPosition(vec2 pos_screen); + +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} //calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); +float calcAmbientOcclusion(vec4 pos, vec3 norm) +{ + float ret = 1.0; + + vec2 kern[8]; + // exponentially (^2) distant occlusion samples spread around origin + kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; + kern[1] = vec2(1.0, 0.0) * 0.250*0.250; + kern[2] = vec2(0.0, 1.0) * 0.375*0.375; + kern[3] = vec2(0.0, -1.0) * 0.500*0.500; + kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; + kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; + kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; + kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; + + vec2 pos_screen = vary_fragcoord.xy; + vec3 pos_world = pos.xyz; + vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; + + float angle_hidden = 0.0; + int points = 0; + + float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); + + // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations unrolling?) + for (int i = 0; i < 8; i++) + { + vec2 samppos_screen = pos_screen + scale * reflect(kern[i], noise_reflect); + vec3 samppos_world = getPosition(samppos_screen).xyz; + + vec3 diff = pos_world - samppos_world; + float dist2 = dot(diff, diff); + + // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area + // --> solid angle shrinking by the square of distance + //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 + //(k should vary inversely with # of samples, but this is taken care of later) + + angle_hidden = angle_hidden + float(dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) * min(1.0/dist2, ssao_factor_inv); + + // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" + points = points + int(diff.z > -1.0); + } + + angle_hidden = min(ssao_factor*angle_hidden/float(points), 1.0); + + ret = (1.0 - (float(points != 0) * angle_hidden)); + + return min(ret, 1.0); +} void main() { - vec2 pos_screen = vary_fragcoord.xy; - vec4 pos = getPosition(pos_screen); - vec3 norm = getNorm(pos_screen); - + vec2 pos_screen = vary_fragcoord.xy; + + //try doing an unproject here + + vec4 pos = getPosition(pos_screen); + + vec3 norm = texture2DRect(normalMap, pos_screen).xyz; + norm = decode_normal(norm.xy); + frag_color[0] = 1.0; - frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); + frag_color[1] = calcAmbientOcclusion(pos, norm); frag_color[2] = 1.0; frag_color[3] = 1.0; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 69543b93ea..73f6d9fec3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -41,6 +41,15 @@ uniform sampler2D bumpMap2; uniform float blend_factor; uniform sampler2D screenTex; uniform sampler2D refTex; +uniform sampler2DRectShadow shadowMap0; +uniform sampler2DRectShadow shadowMap1; +uniform sampler2DRectShadow shadowMap2; +uniform sampler2DRectShadow shadowMap3; +uniform sampler2D noiseMap; + +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; + uniform float sunAngle; uniform float sunAngle2; uniform vec3 lightDir; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl index 2b8cf9d8df..c1cc3679a7 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl @@ -23,10 +23,21 @@ * $/LicenseInfo$ */ +vec3 atmosFragAmbient(vec3 light, vec3 sunlit) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { - /* stub function for fallback compatibility on class1 hardware */ - return light; + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + +vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit) +{ + return light * sunlit; } vec3 atmosLighting(vec3 light) diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 0848adba73..864ba4859d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -133,7 +133,18 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) } -vec4 getPosition(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} void main() { diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 33f3eb46c0..c92dbda185 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -83,12 +83,51 @@ vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 fullbrightScaleSoftClipFrag(vec3 l); vec3 scaleSoftClipFrag(vec3 l); -vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ + if (no_atmo == 1) + { + return light; + } + return (light + additive) * atten.r * 2.0; +} + +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { + if (no_atmo == 1) + { + return light; + } + float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); +} + +vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { + if (no_atmo == 1) + { + return light; + } + float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); +} + +vec4 getPosition_d(vec2 pos_screen, float depth) +{ + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec4 getPosition(vec2 pos_screen) +{ //get position in screen space (world units) given window coordinate and depth map + float depth = texture2DRect(depthMap, pos_screen.xy).r; + return getPosition_d(pos_screen, depth); +} -vec4 getPositionWithDepth(vec2 pos_screen, float depth); -vec4 getPosition(vec2 pos_screen); #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); @@ -98,7 +137,7 @@ void main() { vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; - vec4 pos = getPositionWithDepth(tc, depth); + vec3 pos = getPosition_d(tc, depth).xyz; vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; norm.xyz = decode_normal(norm.xy); // unpack norm diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl index 8b8b338f68..c840d72784 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl @@ -36,5 +36,7 @@ void main() //transform vertex vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); gl_Position = pos; + + vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 80e2a9dd55..a7da140b31 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -133,7 +133,18 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) } -vec4 getPosition(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} void main() { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index c4018ca61a..aa5e99a2f7 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -67,9 +67,20 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -vec3 getNorm(vec2 pos_screen); vec3 decode_normal (vec2 enc); -vec4 getPosition(vec2 pos_screen); + +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { @@ -112,9 +123,14 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_scr void main() { - vec2 pos_screen = vary_fragcoord.xy; - vec4 pos = getPosition(pos_screen); - vec3 norm = getNorm(pos_screen); + vec2 pos_screen = vary_fragcoord.xy; + + //try doing an unproject here + + vec4 pos = getPosition(pos_screen); + + vec3 norm = texture2DRect(normalMap, pos_screen).xyz; + norm = decode_normal(norm.xy); // unpack norm /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index bd468306ee..58f3f2f91e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -70,10 +70,79 @@ uniform float spot_shadow_offset; vec3 decode_normal (vec2 enc); -vec4 getPosition(vec2 pos_screen); -vec3 getNorm(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec2 getKern(int i) +{ + vec2 kern[8]; + // exponentially (^2) distant occlusion samples spread around origin + kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; + kern[1] = vec2(1.0, 0.0) * 0.250*0.250; + kern[2] = vec2(0.0, 1.0) * 0.375*0.375; + kern[3] = vec2(0.0, -1.0) * 0.500*0.500; + kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; + kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; + kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; + kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; + + return kern[i]; +} + +//calculate decreases in ambient lighting when crowded out (SSAO) +float calcAmbientOcclusion(vec4 pos, vec3 norm) +{ + float ret = 1.0; + + vec2 pos_screen = vary_fragcoord.xy; + vec3 pos_world = pos.xyz; + vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; + + float angle_hidden = 0.0; + float points = 0; + + float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); + + // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) + for (int i = 0; i < 8; i++) + { + vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); + vec3 samppos_world = getPosition(samppos_screen).xyz; + + vec3 diff = pos_world - samppos_world; + float dist2 = dot(diff, diff); + + // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area + // --> solid angle shrinking by the square of distance + //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 + //(k should vary inversely with # of samples, but this is taken care of later) + + float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; + angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); + + // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" + float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; + points = points + diffz_val; + } + + angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); + + float points_val = (points > 0.0) ? 1.0 : 0.0; + ret = (1.0 - (points_val * angle_hidden)); -float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); + ret = max(ret, 0.0); + return min(ret, 1.0); +} float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { @@ -116,8 +185,13 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_scr void main() { vec2 pos_screen = vary_fragcoord.xy; - vec4 pos = getPosition(pos_screen); - vec3 norm = getNorm(pos_screen); + + //try doing an unproject here + + vec4 pos = getPosition(pos_screen); + + vec3 norm = texture2DRect(normalMap, pos_screen).xyz; + norm = decode_normal(norm.xy); // unpack norm /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { @@ -217,7 +291,7 @@ void main() } frag_color[0] = shadow; - frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); + frag_color[1] = calcAmbientOcclusion(pos, norm); spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl index f8373215f0..9f06319da3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -1,5 +1,5 @@ /** - * @file class3/deferred/cloudsF.glsl + * @file WLCloudsF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -24,9 +24,9 @@ */ #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; +out vec4 frag_color; #else -#define frag_data gl_FragData +#define frag_color gl_FragColor #endif ///////////////////////////////////////////////////////////////////////// @@ -36,37 +36,20 @@ out vec4 frag_data[3]; VARYING vec4 vary_CloudColorSun; VARYING vec4 vary_CloudColorAmbient; VARYING float vary_CloudDensity; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; -VARYING vec3 vary_pos; uniform sampler2D cloud_noise_texture; uniform sampler2D cloud_noise_texture_next; uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; -uniform vec4 sunlight_color; -uniform vec4 cloud_color; -uniform float cloud_shadow; +uniform vec4 gamma; uniform float cloud_scale; uniform float cloud_variance; -uniform vec3 ambient; -uniform vec3 camPosLocal; -uniform vec3 sun_dir; -uniform float sun_size; -uniform float far_z; - -uniform sampler2D transmittance_texture; -uniform sampler3D scattering_texture; -uniform sampler3D single_mie_scattering_texture; -uniform sampler2D irradiance_texture; -uniform sampler2D sh_input_r; -uniform sampler2D sh_input_g; -uniform sampler2D sh_input_b; - -vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); + +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); @@ -84,9 +67,11 @@ void main() // Set variables vec2 uv1 = vary_texcoord0.xy; vec2 uv2 = vary_texcoord1.xy; - vec2 uv3 = vary_texcoord2.xy; - float cloudDensity = 2.0 * (cloud_shadow - 0.25); + vec4 cloudColorSun = vary_CloudColorSun; + vec4 cloudColorAmbient = vary_CloudColorAmbient; + float cloudDensity = vary_CloudDensity; + vec2 uv3 = vary_texcoord2.xy; vec2 uv4 = vary_texcoord3.xy; vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); @@ -97,53 +82,33 @@ void main() uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0)); - - cloudDensity *= 1.0 - (density_variance * density_variance); // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + alpha1 = min(max(alpha1 + cloudDensity, 0.) * (10. + disturbance.y) * cloud_pos_density1.z, 1.); // And smooth alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; - if (alpha1 < 0.001f) - { - discard; - } // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * (2.5 + disturbance.x) * cloud_pos_density1.z, 1.); // And smooth alpha2 = 1. - alpha2; alpha2 = 1. - alpha2 * alpha2; - vec3 view_ray = vary_pos.xyz + camPosLocal; - - vec3 view_direction = normalize(view_ray); - vec3 sun_direction = normalize(sun_dir); - vec3 earth_center = vec3(0, 0, -6360.0f); - vec3 camPos = (camPosLocal / 1000.0f) - earth_center; - - vec3 transmittance; - vec3 radiance_sun = GetSkyLuminance(camPos, view_direction, 1.0 - alpha1, sun_direction, transmittance); - - vec3 sun_color = vec3(1.0) - exp(-radiance_sun * 0.0001); - // Combine vec4 color; + color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); + color *= 2.; - color.rgb = sun_color * cloud_color.rgb * (1. - alpha2); - color.rgb = pow(color.rgb, vec3(1.0 / 2.2)); - color.rgb += ambient; - - frag_data[0] = vec4(color.rgb, alpha1); - frag_data[1] = vec4(0); - frag_data[2] = vec4(0,1,0,1); + /// Gamma correct for WL (soft clip effect). + frag_color.rgb = scaleSoftClip(color.rgb); + frag_color.a = alpha1; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl index 53b6d88ef5..c1dd45cd67 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl @@ -24,7 +24,6 @@ */ uniform mat4 modelview_projection_matrix; -uniform mat4 modelview_matrix; ATTRIBUTE vec3 position; ATTRIBUTE vec2 texcoord0; @@ -34,37 +33,158 @@ ATTRIBUTE vec2 texcoord0; /////////////////////////////////////////////////////////////////////////////// // Output parameters +VARYING vec4 vary_CloudColorSun; +VARYING vec4 vary_CloudColorAmbient; +VARYING float vary_CloudDensity; VARYING vec2 vary_texcoord0; VARYING vec2 vary_texcoord1; VARYING vec2 vary_texcoord2; VARYING vec2 vary_texcoord3; -VARYING vec3 vary_pos; // Inputs +uniform vec3 camPosLocal; + +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; + +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float max_y; + +uniform vec4 glow; + +uniform vec4 cloud_color; + uniform float cloud_scale; -uniform vec4 lightnorm; -uniform vec3 camPosLocal; void main() { - vary_pos = position; // World / view / projection gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vary_texcoord0 = texcoord0; + + // Get relative position + vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); + + // Set altitude + if (P.y > 0.) + { + P *= (max_y / P.y); + } + else + { + P *= (-32000. / P.y); + } + + // Can normalize then + vec3 Pn = normalize(P); + float Plen = length(P); + + // Initialize temp variables + vec4 temp1 = vec4(0.); + vec4 temp2 = vec4(0.); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + + // Calculate relative weights + temp1 = blue_density + haze_density; + blue_weight = blue_density / temp1; + haze_weight = haze_density / temp1; + + // Compute sunlight from P & lightnorm (for long rays like sky) + temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Distance + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z); + + + // Compute haze glow + temp2.x = dot(Pn, lightnorm.xyz); + temp2.x = 1. - temp2.x; + // temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .001); + // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + // Higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + // Add "minimum anti-solar illumination" + temp2.x += .25; + + // Increase ambient when there are more clouds + vec4 tmpAmbient = ambient; + tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + + // Dim sunlight by cloud shadow percentage + sunlight *= (1. - cloud_shadow); + + // Haze color below cloud + vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) + ); + + // CLOUDS + + sunlight = sunlight_color; + temp2.y = max(0., lightnorm.y * 2.); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Cloud color out + vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; + vary_CloudColorAmbient = tmpAmbient * cloud_color; + + // Attenuate cloud color by atmosphere + temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds + vary_CloudColorSun *= temp1; + vary_CloudColorAmbient *= temp1; + vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); + + // Make a nice cloud density based on the cloud_shadow value that was passed in. + vary_CloudDensity = 2. * (cloud_shadow - 0.25); + + // Texture coords vary_texcoord0 = texcoord0; vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; - vary_texcoord0.xy += 0.5; + vary_texcoord0.xy /= cloud_scale; + vary_texcoord0.xy += 0.5; vary_texcoord1 = vary_texcoord0; vary_texcoord1.x += lightnorm.x * 0.0125; - vary_texcoord1.y += lightnorm.z * 0.0125; + vary_texcoord1.y += lightnorm.z * 0.0125; vary_texcoord2 = vary_texcoord0 * 16.; vary_texcoord3 = vary_texcoord1 * 16.; + // Combine these to minimize register use + vary_CloudColorAmbient += oHazeColorBelowCloud; + + // needs this to compile on mac + //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); + // END CLOUDS } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 0848adba73..864ba4859d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -133,7 +133,18 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) } -vec4 getPosition(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} void main() { diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index d0514f7d23..2073fc066f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -1,5 +1,5 @@ /** - * @file class3/deferred/skyF.glsl + * @file class3/skyF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -44,7 +44,6 @@ uniform sampler3D single_mie_scattering_texture; uniform sampler2D irradiance_texture; uniform sampler2D rainbow_map; uniform sampler2D halo_map; -uniform vec4 gamma; uniform float moisture_level; uniform float droplet_radius; @@ -54,7 +53,6 @@ vec3 GetSolarLuminance(); vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); -vec3 ColorFromRadiance(vec3 radiance); vec3 rainbow(float d) { float rad = (droplet_radius - 5.0f) / 1024.0f; @@ -95,15 +93,18 @@ void main() } s = smoothstep(0.9, 1.0, s) * 16.0f; - vec3 color = ColorFromRadiance(radiance_sun); + vec3 color = vec3(1.0) - exp(-radiance_sun * 0.0001); float optic_d = dot(view_direction, sun_direction); + vec3 halo_22 = halo22(optic_d); - color.rgb += rainbow(optic_d) * optic_d; + if (optic_d <= 0) + color.rgb += rainbow(optic_d); + color.rgb += halo_22; - color = pow(color, vec3(1.0/2.2)); + color = pow(color, vec3(1.0 / 2.2)); frag_data[0] = vec4(color, 1.0 + s); frag_data[1] = vec4(0.0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl index 2eb222ada4..a5cc49ca30 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl @@ -1,5 +1,5 @@ /** - * @file class3/deferred/skyV.glsl + * @file advancedAtmoV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -23,6 +23,12 @@ * $/LicenseInfo$ */ +uniform vec3 cameraPosLocal; +uniform mat4 modelview_projection_matrix; +uniform mat4 modelview_matrix; +uniform mat4 inv_proj; +uniform mat4 inv_modelview; + ATTRIBUTE vec3 position; ATTRIBUTE vec2 texcoord0; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index ecf6858136..2615400e52 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -38,21 +38,30 @@ uniform sampler2DRect specularRect; uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; -uniform sampler2D lightFunc; - -uniform float blur_size; uniform samplerCube environmentMap; +uniform sampler2D lightFunc; +uniform float blur_size; uniform float blur_fidelity; // Inputs uniform vec4 morphFactor; uniform vec3 camPosLocal; +//uniform vec4 camPosWorld; uniform vec4 gamma; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 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 vec4 glow; uniform float global_gamma; +uniform float scene_light_strength; uniform mat3 env_mat; uniform vec4 shadow_clip; uniform mat3 ssao_effect_mat; @@ -65,29 +74,28 @@ uniform mat4 inv_modelview; uniform vec2 screen_res; -uniform sampler2D transmittance_texture; -uniform sampler3D scattering_texture; -uniform sampler3D single_mie_scattering_texture; -uniform sampler2D irradiance_texture; - -uniform sampler2D sh_input_r; -uniform sampler2D sh_input_g; -uniform sampler2D sh_input_b; - -vec3 GetSunAndSkyIrradiance(vec3 camPos, vec3 norm, vec3 dir, out vec3 sky_irradiance); -vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); -vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); - -vec3 scaleSoftClipFrag(vec3 c); -vec3 fullbrightScaleSoftClipFrag(vec3 c); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); -vec3 ColorFromRadiance(vec3 radiance); -vec4 getPositionWithDepth(vec2 pos_screen, float depth); -vec4 getPosition(vec2 pos_screen); -vec3 getNorm(vec2 pos_screen); +vec4 getPosition_d(vec2 pos_screen, float depth) +{ + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec4 getPosition(vec2 pos_screen) +{ //get position in screen space (world units) given window coordinate and depth map + float depth = texture2DRect(depthMap, pos_screen.xy).r; + return getPosition_d(pos_screen, depth); +} + #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); @@ -97,22 +105,24 @@ void main() { vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPositionWithDepth(tc, depth).xyz; + vec3 pos = getPosition_d(tc, depth).xyz; vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; - norm.xyz = decode_normal(norm.xy); - + norm.xyz = decode_normal(norm.xy); // unpack norm + float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); float light_gamma = 1.0/1.3; + da = pow(da, light_gamma); - vec4 diffuse = texture2DRect(diffuseRect, tc); // linear + vec4 diffuse = texture2DRect(diffuseRect, tc); + //convert to gamma space + diffuse.rgb = linear_to_srgb(diffuse.rgb); + vec3 col; float bloom = 0.0; { - vec3 camPos = (camPosLocal / 1000.0f) + vec3(0, 0, 6360.0f); - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; @@ -122,37 +132,17 @@ void main() float ambocc = scol_ambocc.g; - vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); - vec4 l1r = texture2D(sh_input_r, vec2(0,0)); - vec4 l1g = texture2D(sh_input_g, vec2(0,0)); - vec4 l1b = texture2D(sh_input_b, vec2(0,0)); - - vec3 indirect = vec3(dot(l1r, l1tap * vec4(1, norm.xyz)), - dot(l1g, l1tap * vec4(1, norm.xyz)), - dot(l1b, l1tap * vec4(1, norm.xyz))); - - indirect = clamp(indirect, vec3(0), vec3(1.0)); - - vec3 transmittance; - vec3 sky_irradiance; - vec3 sun_irradiance = GetSunAndSkyIrradiance(camPos, norm.xyz, sun_dir, sky_irradiance); - vec3 inscatter = GetSkyLuminanceToPoint(camPos, (pos / 1000.f) + vec3(0, 0, 6360.0f), scol, sun_dir, transmittance); - - vec3 radiance = scol * (sun_irradiance + sky_irradiance) + inscatter; - vec3 atmo_color = ColorFromRadiance(radiance); - - col = atmo_color + indirect; - col *= transmittance; - col *= diffuse.rgb; - + col *= diffuse.rgb; + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection { // the old infinite-sky shiny reflection // + float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = scol * texture2D(lightFunc, vec2(sa, spec.a)).r * atmo_color; + vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; @@ -165,24 +155,17 @@ void main() if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; - vec3 sun_direction = (inv_modelview * vec4(sun_dir, 1.0)).xyz; - vec3 radiance_sun = GetSkyLuminance(camPos, env_vec, 0.0f, sun_direction, transmittance); - vec3 refcol = ColorFromRadiance(radiance_sun); - col = mix(col.rgb, refcol, envIntensity); + vec3 refcol = textureCube(environmentMap, env_vec).rgb; + col = mix(col.rgb, refcol, envintensity); } - /*if (norm.w < 0.5) - { - col = scaleSoftClipFrag(col); - }*/ - #ifdef WATER_FOG vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); col = fogged.rgb; bloom = fogged.a; #endif - col = pow(col, vec3(light_gamma)); + col = srgb_to_linear(col); } frag_color.rgb = col; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl index 9d872b8df8..c840d72784 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl @@ -1,5 +1,5 @@ /** - * @file class3/deferred/softenLightV.glsl + * @file softenLightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -22,17 +22,21 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -ATTRIBUTE vec3 position; - -VARYING vec2 vary_fragcoord; uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + uniform vec2 screen_res; +VARYING vec2 vary_fragcoord; + void main() { //transform vertex vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); gl_Position = pos; + + vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 80e2a9dd55..a7da140b31 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -133,7 +133,18 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) } -vec4 getPosition(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} void main() { diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl index 894534b105..aa5e99a2f7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl @@ -68,8 +68,19 @@ uniform float spot_shadow_bias; uniform float spot_shadow_offset; vec3 decode_normal (vec2 enc); -vec4 getPosition(vec2 pos_screen); -vec3 getNorm(vec2 pos_screen); + +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { @@ -113,8 +124,13 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_scr void main() { vec2 pos_screen = vary_fragcoord.xy; + + //try doing an unproject here + vec4 pos = getPosition(pos_screen); - vec3 norm = getNorm(pos_screen); + + vec3 norm = texture2DRect(normalMap, pos_screen).xyz; + norm = decode_normal(norm.xy); // unpack norm /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl index 0870a80a32..58f3f2f91e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl @@ -68,11 +68,81 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -vec4 getPosition(vec2 pos_screen); -vec3 getNorm(vec2 pos_screen); +vec3 decode_normal (vec2 enc); + +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).r; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec2 getKern(int i) +{ + vec2 kern[8]; + // exponentially (^2) distant occlusion samples spread around origin + kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; + kern[1] = vec2(1.0, 0.0) * 0.250*0.250; + kern[2] = vec2(0.0, 1.0) * 0.375*0.375; + kern[3] = vec2(0.0, -1.0) * 0.500*0.500; + kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; + kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; + kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; + kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; + + return kern[i]; +} //calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm, pos_screen); +float calcAmbientOcclusion(vec4 pos, vec3 norm) +{ + float ret = 1.0; + + vec2 pos_screen = vary_fragcoord.xy; + vec3 pos_world = pos.xyz; + vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; + + float angle_hidden = 0.0; + float points = 0; + + float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); + + // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) + for (int i = 0; i < 8; i++) + { + vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); + vec3 samppos_world = getPosition(samppos_screen).xyz; + + vec3 diff = pos_world - samppos_world; + float dist2 = dot(diff, diff); + + // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area + // --> solid angle shrinking by the square of distance + //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 + //(k should vary inversely with # of samples, but this is taken care of later) + + float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; + angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); + + // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" + float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; + points = points + diffz_val; + } + + angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); + + float points_val = (points > 0.0) ? 1.0 : 0.0; + ret = (1.0 - (points_val * angle_hidden)); + + ret = max(ret, 0.0); + return min(ret, 1.0); +} float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { @@ -114,9 +184,14 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_scr void main() { - vec2 pos_screen = vary_fragcoord.xy; - vec4 pos = getPosition(pos_screen); - vec3 norm = getNorm(pos_screen); + vec2 pos_screen = vary_fragcoord.xy; + + //try doing an unproject here + + vec4 pos = getPosition(pos_screen); + + vec3 norm = texture2DRect(normalMap, pos_screen).xyz; + norm = decode_normal(norm.xy); // unpack norm /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { @@ -216,7 +291,7 @@ void main() } frag_color[0] = shadow; - frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); + frag_color[1] = calcAmbientOcclusion(pos, norm); spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); -- cgit v1.2.3 From d614bf11357d9ff1fef59c7ff11eff73b211dcac Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 9 Nov 2018 21:11:37 +0000 Subject: Yes, Maurice, baby steps. --- .../shaders/class1/avatar/avatarSkinV.glsl | 7 -- .../shaders/class1/avatar/objectSkinV.glsl | 7 -- .../shaders/class1/deferred/pointLightV.glsl | 2 +- .../shaders/class3/deferred/cloudsF.glsl | 77 ++++++++---- .../shaders/class3/deferred/cloudsV.glsl | 136 ++------------------- .../shaders/class3/deferred/multiSpotLightF.glsl | 13 +- .../app_settings/shaders/class3/deferred/skyF.glsl | 13 +- .../app_settings/shaders/class3/deferred/skyV.glsl | 8 +- .../shaders/class3/deferred/softenLightF.glsl | 107 +++++++++------- .../shaders/class3/deferred/softenLightV.glsl | 12 +- .../shaders/class3/deferred/spotLightF.glsl | 13 +- .../shaders/class3/deferred/sunLightF.glsl | 22 +--- .../shaders/class3/deferred/sunLightSSAOF.glsl | 89 ++------------ 13 files changed, 150 insertions(+), 356 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl b/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl index 767fad016c..c4caed4d71 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl @@ -38,12 +38,5 @@ mat4 getSkinnedTransform() ret[1] = mix(matrixPalette[i+15],matrixPalette[i+16], x); ret[2] = mix(matrixPalette[i+30],matrixPalette[i+31], x); ret[3] = vec4(0,0,0,1); - return ret; - -#ifdef IS_AMD_CARD - // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. - vec4 dummy1 = matrixPalette[0]; - vec4 dummy2 = matrixPalette[44]; -#endif } diff --git a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl index 90bf2851c9..94de2f7b53 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl @@ -61,12 +61,5 @@ mat4 getObjectSkinnedTransform() ret[3] = vec4(trans, 1.0); return ret; - -#ifdef IS_AMD_CARD - // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. - mat3x4 dummy1 = matrixPalette[0]; - mat3x4 dummy2 = matrixPalette[MAX_JOINTS_PER_MESH_OBJECT-1]; -#endif - } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl index a5625fbc16..3da8531442 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl @@ -1,5 +1,5 @@ /** - * @file pointLightF.glsl + * @file pointLightV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl index 9f06319da3..f8373215f0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -1,5 +1,5 @@ /** - * @file WLCloudsF.glsl + * @file class3/deferred/cloudsF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -24,9 +24,9 @@ */ #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; +out vec4 frag_data[3]; #else -#define frag_color gl_FragColor +#define frag_data gl_FragData #endif ///////////////////////////////////////////////////////////////////////// @@ -36,20 +36,37 @@ out vec4 frag_color; VARYING vec4 vary_CloudColorSun; VARYING vec4 vary_CloudColorAmbient; VARYING float vary_CloudDensity; +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; +VARYING vec3 vary_pos; uniform sampler2D cloud_noise_texture; uniform sampler2D cloud_noise_texture_next; uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; -uniform vec4 gamma; +uniform vec4 sunlight_color; +uniform vec4 cloud_color; +uniform float cloud_shadow; uniform float cloud_scale; uniform float cloud_variance; - -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; +uniform vec3 ambient; +uniform vec3 camPosLocal; +uniform vec3 sun_dir; +uniform float sun_size; +uniform float far_z; + +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D single_mie_scattering_texture; +uniform sampler2D irradiance_texture; +uniform sampler2D sh_input_r; +uniform sampler2D sh_input_g; +uniform sampler2D sh_input_b; + +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); @@ -67,11 +84,9 @@ void main() // Set variables vec2 uv1 = vary_texcoord0.xy; vec2 uv2 = vary_texcoord1.xy; - - vec4 cloudColorSun = vary_CloudColorSun; - vec4 cloudColorAmbient = vary_CloudColorAmbient; - float cloudDensity = vary_CloudDensity; vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); + vec2 uv4 = vary_texcoord3.xy; vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); @@ -82,33 +97,53 @@ void main() uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0)); - // Compute alpha1, the main cloud opacity + cloudDensity *= 1.0 - (density_variance * density_variance); + // Compute alpha1, the main cloud opacity float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * (10. + disturbance.y) * cloud_pos_density1.z, 1.); + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); // And smooth alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; + if (alpha1 < 0.001f) + { + discard; + } // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * (2.5 + disturbance.x) * cloud_pos_density1.z, 1.); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); // And smooth alpha2 = 1. - alpha2; alpha2 = 1. - alpha2 * alpha2; + vec3 view_ray = vary_pos.xyz + camPosLocal; + + vec3 view_direction = normalize(view_ray); + vec3 sun_direction = normalize(sun_dir); + vec3 earth_center = vec3(0, 0, -6360.0f); + vec3 camPos = (camPosLocal / 1000.0f) - earth_center; + + vec3 transmittance; + vec3 radiance_sun = GetSkyLuminance(camPos, view_direction, 1.0 - alpha1, sun_direction, transmittance); + + vec3 sun_color = vec3(1.0) - exp(-radiance_sun * 0.0001); + // Combine vec4 color; - color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); - color *= 2.; - /// Gamma correct for WL (soft clip effect). - frag_color.rgb = scaleSoftClip(color.rgb); - frag_color.a = alpha1; + color.rgb = sun_color * cloud_color.rgb * (1. - alpha2); + color.rgb = pow(color.rgb, vec3(1.0 / 2.2)); + color.rgb += ambient; + + frag_data[0] = vec4(color.rgb, alpha1); + frag_data[1] = vec4(0); + frag_data[2] = vec4(0,1,0,1); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl index c1dd45cd67..53b6d88ef5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl @@ -24,6 +24,7 @@ */ uniform mat4 modelview_projection_matrix; +uniform mat4 modelview_matrix; ATTRIBUTE vec3 position; ATTRIBUTE vec2 texcoord0; @@ -33,158 +34,37 @@ ATTRIBUTE vec2 texcoord0; /////////////////////////////////////////////////////////////////////////////// // Output parameters -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; -VARYING float vary_CloudDensity; VARYING vec2 vary_texcoord0; VARYING vec2 vary_texcoord1; VARYING vec2 vary_texcoord2; VARYING vec2 vary_texcoord3; +VARYING vec3 vary_pos; // Inputs -uniform vec3 camPosLocal; - -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; - -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float max_y; - -uniform vec4 glow; - -uniform vec4 cloud_color; - uniform float cloud_scale; +uniform vec4 lightnorm; +uniform vec3 camPosLocal; void main() { + vary_pos = position; // World / view / projection gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - vary_texcoord0 = texcoord0; - - // Get relative position - vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); - - // Set altitude - if (P.y > 0.) - { - P *= (max_y / P.y); - } - else - { - P *= (-32000. / P.y); - } - - // Can normalize then - vec3 Pn = normalize(P); - float Plen = length(P); - - // Initialize temp variables - vec4 temp1 = vec4(0.); - vec4 temp2 = vec4(0.); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - - // Calculate relative weights - temp1 = blue_density + haze_density; - blue_weight = blue_density / temp1; - haze_weight = haze_density / temp1; - - // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Distance - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); - - - // Compute haze glow - temp2.x = dot(Pn, lightnorm.xyz); - temp2.x = 1. - temp2.x; - // temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .001); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // Add "minimum anti-solar illumination" - temp2.x += .25; - - // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; - - // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); - - // Haze color below cloud - vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) - ); - - // CLOUDS - - sunlight = sunlight_color; - temp2.y = max(0., lightnorm.y * 2.); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Cloud color out - vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; - vary_CloudColorAmbient = tmpAmbient * cloud_color; - - // Attenuate cloud color by atmosphere - temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds - vary_CloudColorSun *= temp1; - vary_CloudColorAmbient *= temp1; - vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); - - // Make a nice cloud density based on the cloud_shadow value that was passed in. - vary_CloudDensity = 2. * (cloud_shadow - 0.25); - - // Texture coords vary_texcoord0 = texcoord0; vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; - vary_texcoord0.xy += 0.5; + vary_texcoord0.xy /= cloud_scale; + vary_texcoord0.xy += 0.5; vary_texcoord1 = vary_texcoord0; vary_texcoord1.x += lightnorm.x * 0.0125; - vary_texcoord1.y += lightnorm.z * 0.0125; + vary_texcoord1.y += lightnorm.z * 0.0125; vary_texcoord2 = vary_texcoord0 * 16.; vary_texcoord3 = vary_texcoord1 * 16.; - // Combine these to minimize register use - vary_CloudColorAmbient += oHazeColorBelowCloud; - - // needs this to compile on mac - //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); - // END CLOUDS } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 864ba4859d..0848adba73 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -133,18 +133,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) } -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index 2073fc066f..d0514f7d23 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -1,5 +1,5 @@ /** - * @file class3/skyF.glsl + * @file class3/deferred/skyF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -44,6 +44,7 @@ uniform sampler3D single_mie_scattering_texture; uniform sampler2D irradiance_texture; uniform sampler2D rainbow_map; uniform sampler2D halo_map; +uniform vec4 gamma; uniform float moisture_level; uniform float droplet_radius; @@ -53,6 +54,7 @@ vec3 GetSolarLuminance(); vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); +vec3 ColorFromRadiance(vec3 radiance); vec3 rainbow(float d) { float rad = (droplet_radius - 5.0f) / 1024.0f; @@ -93,18 +95,15 @@ void main() } s = smoothstep(0.9, 1.0, s) * 16.0f; - vec3 color = vec3(1.0) - exp(-radiance_sun * 0.0001); + vec3 color = ColorFromRadiance(radiance_sun); float optic_d = dot(view_direction, sun_direction); - vec3 halo_22 = halo22(optic_d); - if (optic_d <= 0) - color.rgb += rainbow(optic_d); - + color.rgb += rainbow(optic_d) * optic_d; color.rgb += halo_22; - color = pow(color, vec3(1.0 / 2.2)); + color = pow(color, vec3(1.0/2.2)); frag_data[0] = vec4(color, 1.0 + s); frag_data[1] = vec4(0.0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl index a5cc49ca30..2eb222ada4 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl @@ -1,5 +1,5 @@ /** - * @file advancedAtmoV.glsl + * @file class3/deferred/skyV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -23,12 +23,6 @@ * $/LicenseInfo$ */ -uniform vec3 cameraPosLocal; -uniform mat4 modelview_projection_matrix; -uniform mat4 modelview_matrix; -uniform mat4 inv_proj; -uniform mat4 inv_modelview; - ATTRIBUTE vec3 position; ATTRIBUTE vec2 texcoord0; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 2615400e52..ecf6858136 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -38,30 +38,21 @@ uniform sampler2DRect specularRect; uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; +uniform sampler2D lightFunc; uniform float blur_size; +uniform samplerCube environmentMap; + uniform float blur_fidelity; // Inputs uniform vec4 morphFactor; uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; uniform vec4 gamma; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 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 vec4 glow; uniform float global_gamma; -uniform float scene_light_strength; uniform mat3 env_mat; uniform vec4 shadow_clip; uniform mat3 ssao_effect_mat; @@ -74,28 +65,29 @@ uniform mat4 inv_modelview; uniform vec2 screen_res; +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D single_mie_scattering_texture; +uniform sampler2D irradiance_texture; + +uniform sampler2D sh_input_r; +uniform sampler2D sh_input_g; +uniform sampler2D sh_input_b; + +vec3 GetSunAndSkyIrradiance(vec3 camPos, vec3 norm, vec3 dir, out vec3 sky_irradiance); +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); +vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); + +vec3 scaleSoftClipFrag(vec3 c); +vec3 fullbrightScaleSoftClipFrag(vec3 c); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec4 getPosition(vec2 pos_screen) -{ //get position in screen space (world units) given window coordinate and depth map - float depth = texture2DRect(depthMap, pos_screen.xy).r; - return getPosition_d(pos_screen, depth); -} - +vec3 ColorFromRadiance(vec3 radiance); +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); @@ -105,24 +97,22 @@ void main() { vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPosition_d(tc, depth).xyz; + vec3 pos = getPositionWithDepth(tc, depth).xyz; vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; - norm.xyz = decode_normal(norm.xy); // unpack norm - + norm.xyz = decode_normal(norm.xy); + float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); float light_gamma = 1.0/1.3; - da = pow(da, light_gamma); - vec4 diffuse = texture2DRect(diffuseRect, tc); + vec4 diffuse = texture2DRect(diffuseRect, tc); // linear - //convert to gamma space - diffuse.rgb = linear_to_srgb(diffuse.rgb); - vec3 col; float bloom = 0.0; { + vec3 camPos = (camPosLocal / 1000.0f) + vec3(0, 0, 6360.0f); + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; @@ -132,17 +122,37 @@ void main() float ambocc = scol_ambocc.g; - col *= diffuse.rgb; - + vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); + vec4 l1r = texture2D(sh_input_r, vec2(0,0)); + vec4 l1g = texture2D(sh_input_g, vec2(0,0)); + vec4 l1b = texture2D(sh_input_b, vec2(0,0)); + + vec3 indirect = vec3(dot(l1r, l1tap * vec4(1, norm.xyz)), + dot(l1g, l1tap * vec4(1, norm.xyz)), + dot(l1b, l1tap * vec4(1, norm.xyz))); + + indirect = clamp(indirect, vec3(0), vec3(1.0)); + + vec3 transmittance; + vec3 sky_irradiance; + vec3 sun_irradiance = GetSunAndSkyIrradiance(camPos, norm.xyz, sun_dir, sky_irradiance); + vec3 inscatter = GetSkyLuminanceToPoint(camPos, (pos / 1000.f) + vec3(0, 0, 6360.0f), scol, sun_dir, transmittance); + + vec3 radiance = scol * (sun_irradiance + sky_irradiance) + inscatter; + vec3 atmo_color = ColorFromRadiance(radiance); + + col = atmo_color + indirect; + col *= transmittance; + col *= diffuse.rgb; + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection { // the old infinite-sky shiny reflection // - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); + vec3 dumbshiny = scol * texture2D(lightFunc, vec2(sa, spec.a)).r * atmo_color; // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; @@ -155,17 +165,24 @@ void main() 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 sun_direction = (inv_modelview * vec4(sun_dir, 1.0)).xyz; + vec3 radiance_sun = GetSkyLuminance(camPos, env_vec, 0.0f, sun_direction, transmittance); + vec3 refcol = ColorFromRadiance(radiance_sun); + col = mix(col.rgb, refcol, envIntensity); } + /*if (norm.w < 0.5) + { + col = scaleSoftClipFrag(col); + }*/ + #ifdef WATER_FOG vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); col = fogged.rgb; bloom = fogged.a; #endif - col = srgb_to_linear(col); + col = pow(col, vec3(light_gamma)); } frag_color.rgb = col; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl index c840d72784..9d872b8df8 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl @@ -1,5 +1,5 @@ /** - * @file softenLightF.glsl + * @file class3/deferred/softenLightV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -22,21 +22,17 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - -uniform mat4 modelview_projection_matrix; - ATTRIBUTE vec3 position; -uniform vec2 screen_res; - VARYING vec2 vary_fragcoord; +uniform mat4 modelview_projection_matrix; +uniform vec2 screen_res; + void main() { //transform vertex vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); gl_Position = pos; - - vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index a7da140b31..80e2a9dd55 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -133,18 +133,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) } -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl index aa5e99a2f7..894534b105 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl @@ -68,19 +68,8 @@ uniform float spot_shadow_bias; uniform float spot_shadow_offset; vec3 decode_normal (vec2 enc); - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { @@ -124,13 +113,8 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_scr void main() { vec2 pos_screen = vary_fragcoord.xy; - - //try doing an unproject here - vec4 pos = getPosition(pos_screen); - - vec3 norm = texture2DRect(normalMap, pos_screen).xyz; - norm = decode_normal(norm.xy); // unpack norm + vec3 norm = getNorm(pos_screen); /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl index 58f3f2f91e..0870a80a32 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl @@ -68,81 +68,11 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -vec3 decode_normal (vec2 enc); - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec2 getKern(int i) -{ - vec2 kern[8]; - // exponentially (^2) distant occlusion samples spread around origin - kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; - kern[1] = vec2(1.0, 0.0) * 0.250*0.250; - kern[2] = vec2(0.0, 1.0) * 0.375*0.375; - kern[3] = vec2(0.0, -1.0) * 0.500*0.500; - kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; - kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; - kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; - kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; - - return kern[i]; -} +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); //calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm) -{ - float ret = 1.0; - - vec2 pos_screen = vary_fragcoord.xy; - vec3 pos_world = pos.xyz; - vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; - - float angle_hidden = 0.0; - float points = 0; - - float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); - - // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) - for (int i = 0; i < 8; i++) - { - vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); - vec3 samppos_world = getPosition(samppos_screen).xyz; - - vec3 diff = pos_world - samppos_world; - float dist2 = dot(diff, diff); - - // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area - // --> solid angle shrinking by the square of distance - //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 - //(k should vary inversely with # of samples, but this is taken care of later) - - float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; - angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); - - // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" - float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; - points = points + diffz_val; - } - - angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); - - float points_val = (points > 0.0) ? 1.0 : 0.0; - ret = (1.0 - (points_val * angle_hidden)); - - ret = max(ret, 0.0); - return min(ret, 1.0); -} +float calcAmbientOcclusion(vec4 pos, vec3 norm, pos_screen); float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { @@ -184,14 +114,9 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_scr void main() { - vec2 pos_screen = vary_fragcoord.xy; - - //try doing an unproject here - - vec4 pos = getPosition(pos_screen); - - vec3 norm = texture2DRect(normalMap, pos_screen).xyz; - norm = decode_normal(norm.xy); // unpack norm + vec2 pos_screen = vary_fragcoord.xy; + vec4 pos = getPosition(pos_screen); + vec3 norm = getNorm(pos_screen); /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { @@ -291,7 +216,7 @@ void main() } frag_color[0] = shadow; - frag_color[1] = calcAmbientOcclusion(pos, norm); + frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); -- cgit v1.2.3 From a8c2bc25dd8daeebbcd1c0727a33df904dc42f76 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 9 Nov 2018 21:21:03 +0000 Subject: More incremental revive of 39561 contents to determine cuplrit. --- indra/newview/app_settings/shaders/class1/deferred/srgb.glsl | 3 --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 9 --------- 2 files changed, 12 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl index 00ba0e8fad..bc3324f543 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl @@ -48,7 +48,6 @@ vec3 srgb_to_linear(vec3 cs) bvec3 lte = lessThanEqual(cs,vec3(0.04045)); return mix(high_range, low_range, lte); - } vec3 linear_to_srgb(vec3 cl) @@ -59,6 +58,4 @@ vec3 linear_to_srgb(vec3 cl) bvec3 lt = lessThan(cl,vec3(0.0031308)); return mix(high_range, low_range, lt); - } - diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 73f6d9fec3..69543b93ea 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -41,15 +41,6 @@ uniform sampler2D bumpMap2; uniform float blend_factor; uniform sampler2D screenTex; uniform sampler2D refTex; -uniform sampler2DRectShadow shadowMap0; -uniform sampler2DRectShadow shadowMap1; -uniform sampler2DRectShadow shadowMap2; -uniform sampler2DRectShadow shadowMap3; -uniform sampler2D noiseMap; - -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; - uniform float sunAngle; uniform float sunAngle2; uniform vec3 lightDir; -- cgit v1.2.3 From bdf4442e216273bb32eeb607857efdad2336ee81 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 9 Nov 2018 22:55:41 +0000 Subject: Add missing new shader files. --- .../shaders/class1/deferred/deferredUtil.glsl | 287 +++++++++++++++++++++ .../shaders/class1/deferred/indirect.glsl | 30 +++ .../shaders/class2/deferred/indirect.glsl | 32 +++ .../shaders/class3/windlight/gammaF.glsl | 54 ++++ 4 files changed, 403 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl create mode 100644 indra/newview/app_settings/shaders/class1/deferred/indirect.glsl create mode 100644 indra/newview/app_settings/shaders/class2/deferred/indirect.glsl create mode 100644 indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl new file mode 100644 index 0000000000..b810bb4fd1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -0,0 +1,287 @@ +/** + * @file shadowUtil.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 sampler2DRect normalMap; +uniform sampler2DRect depthMap; +uniform sampler2D noiseMap; +uniform sampler2DShadow shadowMap0; +uniform sampler2DShadow shadowMap1; +uniform sampler2DShadow shadowMap2; +uniform sampler2DShadow shadowMap3; +uniform sampler2DShadow shadowMap4; +uniform sampler2DShadow shadowMap5; + +uniform float ssao_radius; +uniform float ssao_max_radius; +uniform float ssao_factor; +uniform float ssao_factor_inv; + +uniform vec3 sun_dir; +uniform vec2 shadow_res; +uniform vec2 proj_shadow_res; +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform float shadow_bias; + +uniform float spot_shadow_bias; +uniform float spot_shadow_offset; + +uniform mat4 inv_proj; +uniform vec2 screen_res; + +vec3 decode_normal(vec2 enc); + +vec2 getScreenCoordinate(vec2 screenpos) +{ + vec2 sc = screenpos.xy * 2.0; + if (screen_res.x > 0 && screen_res.y > 0) + { + sc /= screen_res; + } + return sc - vec2(1.0, 1.0); +} + +vec3 getNorm(vec2 screenpos) +{ + vec2 enc_norm = texture2DRect(normalMap, screenpos.xy).xy; + return decode_normal(enc_norm); +} + +float getDepth(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen).r; + return depth; +} + +vec4 getPosition(vec2 pos_screen) +{ + float depth = getDepth(pos_screen); + vec2 sc = getScreenCoordinate(pos_screen); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec4 getPositionWithDepth(vec2 pos_screen, float depth) +{ + vec2 sc = getScreenCoordinate(pos_screen); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) +{ + stc.xyz /= stc.w; + stc.z += shadow_bias * bias_scale; + + stc.x = floor(stc.x*pos_screen.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + return shadow*0.2; +} + +float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) +{ + stc.xyz /= stc.w; + stc.z += spot_shadow_bias * bias_scale; + stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + + vec2 off = 1.0/proj_shadow_res; + off.y *= 1.5; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; + return shadow*0.2; +} + +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) +{ + float dp_directional_light = max(0.0, dot(sun_dir.xyz, norm)); + vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); + vec3 shadow_pos = pos.xyz + (offset * shadow_bias); + + float shadow = 0.0f; + vec4 spos = vec4(shadow_pos,1.0); + if (spos.z > -shadow_clip.w) + { + vec4 lpos; + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + if (spos.z < near_split.z) + { + lpos = shadow_matrix[3]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos, 0.5, pos_screen)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + if (spos.z < near_split.y && spos.z > far_split.z) + { + lpos = shadow_matrix[2]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; + w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap2, lpos, 0.75, pos_screen)*w; + weight += w; + } + + if (spos.z < near_split.x && spos.z > far_split.y) + { + lpos = shadow_matrix[1]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; + w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + shadow += pcfShadow(shadowMap1, lpos, 0.88, pos_screen)*w; + weight += w; + } + + if (spos.z > far_split.x) + { + lpos = shadow_matrix[0]*spos; + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; + weight += w; + } + + shadow /= weight; + } + return shadow; +} + +float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) +{ + float shadow = 0.0f; + pos += norm * spot_shadow_offset; + + vec4 spos = vec4(pos,1.0); + if (spos.z > -shadow_clip.w) + { + vec4 lpos; + + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + { + lpos = shadow_matrix[4 + index]*spos; + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + + shadow += pcfSpotShadow((index == 0) ? shadowMap4 : shadowMap5, lpos, 0.8, spos.xy)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + shadow /= weight; + } + return shadow; +} + +vec2 getKern(int i) +{ + vec2 kern[8]; + // exponentially (^2) distant occlusion samples spread around origin + kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; + kern[1] = vec2(1.0, 0.0) * 0.250*0.250; + kern[2] = vec2(0.0, 1.0) * 0.375*0.375; + kern[3] = vec2(0.0, -1.0) * 0.500*0.500; + kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; + kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; + kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; + kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; + + return kern[i]; +} + +//calculate decreases in ambient lighting when crowded out (SSAO) +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen) +{ + float ret = 1.0; + vec3 pos_world = pos.xyz; + vec2 noise_reflect = texture2D(noiseMap, pos_screen.xy/128.0).xy; + + float angle_hidden = 0.0; + float points = 0; + + float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); + + // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) + for (int i = 0; i < 8; i++) + { + vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); + vec3 samppos_world = getPosition(samppos_screen).xyz; + + vec3 diff = pos_world - samppos_world; + float dist2 = dot(diff, diff); + + // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area + // --> solid angle shrinking by the square of distance + //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 + //(k should vary inversely with # of samples, but this is taken care of later) + + float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; + angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); + + // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" + float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; + points = points + diffz_val; + } + + angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); + + float points_val = (points > 0.0) ? 1.0 : 0.0; + ret = (1.0 - (points_val * angle_hidden)); + + ret = max(ret, 0.0); + return min(ret, 1.0); +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/indirect.glsl b/indra/newview/app_settings/shaders/class1/deferred/indirect.glsl new file mode 100644 index 0000000000..49bfa660f8 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/indirect.glsl @@ -0,0 +1,30 @@ +/** + * @file class1/deferred/indirect.glsl + * + * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +vec3 getIndirect(vec3 ambient, vec3 norm, vec3 pos, vec2 pos_screen) +{ + return ambient; +} + diff --git a/indra/newview/app_settings/shaders/class2/deferred/indirect.glsl b/indra/newview/app_settings/shaders/class2/deferred/indirect.glsl new file mode 100644 index 0000000000..67b98e0fb1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/deferred/indirect.glsl @@ -0,0 +1,32 @@ +/** + * @file class2/deferred/indirect.glsl + * + * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); + +vec3 getIndirect(vec3 ambient, vec3 norm, vec4 pos, vec2 pos_screen) +{ + return ambient * calcAmbientOcclusion(pos, norm, pos_screen); +} + diff --git a/indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl new file mode 100644 index 0000000000..709d9cbc0a --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl @@ -0,0 +1,54 @@ +/** + * @file gammaF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 vec4 gamma; +uniform int no_atmo; + +vec3 scaleSoftClipFrag(vec3 light) { + if (no_atmo == 1) + { + return light; + } + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, gamma.xxx); + return light; +} + +/// Soft clips the light with a gamma correction +vec3 scaleSoftClip(vec3 light) { + return scaleSoftClipFrag(light); +} + +vec3 fullbrightScaleSoftClipFrag(vec3 light) +{ + return scaleSoftClipFrag(light.rgb); +} + +vec3 fullbrightScaleSoftClip(vec3 light) { + return fullbrightScaleSoftClipFrag(light.rgb); +} + -- cgit v1.2.3 From a49e2b604e6b505e083e24b10e39053196d917c1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 12 Nov 2018 15:54:53 -0800 Subject: SL-10044 SL-10045 Fix class 1 and 2 transport/gamma funcs and made usage consistent across all shaders. Fix class1\environment\waterV reverting to old d1/d2 names for wave directions. --- .../shaders/class1/deferred/alphaF.glsl | 4 +-- .../shaders/class1/deferred/softenLightF.glsl | 13 ++++++--- .../shaders/class1/environment/waterV.glsl | 10 +++---- .../class1/lighting/sumLightsSpecularV.glsl | 2 ++ .../shaders/class1/lighting/sumLightsV.glsl | 2 ++ .../class1/windlight/atmosphericsHelpersF.glsl | 6 ++++ .../class1/windlight/atmosphericsHelpersV.glsl | 12 ++++++++ .../shaders/class1/windlight/gammaF.glsl | 2 +- .../shaders/class2/deferred/softenLightF.glsl | 32 ++++------------------ .../class2/lighting/sumLightsSpecularV.glsl | 2 ++ .../shaders/class2/lighting/sumLightsV.glsl | 3 ++ .../shaders/class2/windlight/atmosphericsF.glsl | 4 +-- .../class2/windlight/atmosphericsHelpersF.glsl | 5 ++++ .../class2/windlight/atmosphericsHelpersV.glsl | 10 +++++++ .../shaders/class2/windlight/gammaF.glsl | 15 +++++----- .../shaders/class2/windlight/transportF.glsl | 4 ++- .../class3/lighting/sumLightsSpecularV.glsl | 2 ++ 17 files changed, 78 insertions(+), 50 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 3ec2ea12da..f79fc012d1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -88,7 +88,7 @@ vec3 linear_to_srgb(vec3 cl); vec2 encode_normal (vec3 n); vec3 decode_normal (vec2 enc); -vec3 scaleSoftClipFrag(vec3 l); +vec3 scaleSoftClip(vec3 l); vec3 atmosFragAmbient(vec3 light, vec3 sunlit); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit); @@ -305,7 +305,7 @@ void main() //color.rgb = mix(diff.rgb, color.rgb, final_alpha); color.rgb = atmosFragLighting(color.rgb, additive, atten); - color.rgb = scaleSoftClipFrag(color.rgb); + color.rgb = scaleSoftClip(color.rgb); vec4 light = vec4(0,0,0,0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 5627275df6..18259ed9ed 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -70,8 +70,12 @@ vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 fullbrightAtmosTransportFrag(vec3 l, vec3 additive, vec3 atten); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +vec3 scaleSoftClip(vec3 l); +vec3 fullbrightScaleSoftClip(vec3 l); + vec4 getPosition_d(vec2 pos_screen, float depth) { vec2 sc = pos_screen.xy*2.0; @@ -129,8 +133,8 @@ void main() ambient = (1.0 - ambient); col = amblit; - col += (final_da * sunlit); col *= ambient; + col += (final_da * sunlit); col *= diffuse.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -141,7 +145,6 @@ void main() // float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together @@ -166,17 +169,19 @@ void main() if (norm.w < 0.5) { - col = atmosFragLighting(col, additive, atten); + col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); } #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); + vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); col = fogged.rgb; bloom = fogged.a; #endif col = srgb_to_linear(col); + //col = vec3(1,0,1); //col.g = envIntensity; } diff --git a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl index 352cea7aaa..1fe98a9575 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl @@ -31,8 +31,8 @@ ATTRIBUTE vec3 position; void calcAtmospherics(vec3 inPositionEye); -uniform vec2 d1; -uniform vec2 d2; +uniform vec2 waveDir1; +uniform vec2 waveDir2; uniform float time; uniform vec3 eyeVec; uniform float waterHeight; @@ -86,10 +86,10 @@ void main() //pass wave parameters to pixel shader - vec2 bigWave = (v.xy) * vec2(0.04,0.04) + d1 * time * 0.055; + vec2 bigWave = (v.xy) * vec2(0.04,0.04) + waveDir1 * time * 0.055; //get two normal map (detail map) texture coordinates - littleWave.xy = (v.xy) * vec2(0.45, 0.9) + d2 * time * 0.13; - littleWave.zw = (v.xy) * vec2(0.1, 0.2) + d1 * time * 0.1; + littleWave.xy = (v.xy) * vec2(0.45, 0.9) + waveDir2 * time * 0.13; + littleWave.zw = (v.xy) * vec2(0.1, 0.2) + waveDir1 * time * 0.1; view.w = bigWave.y; refCoord.w = bigWave.x; diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl index 10958025ac..7059ff31ae 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl @@ -29,6 +29,7 @@ float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 atmosGetDiffuseSunlightColor(); +vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_diffuse[8]; @@ -43,6 +44,7 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor vec4 specularSum = vec4(0.0); col.rgb += light_diffuse[1].rgb * calcDirectionalLightSpecular(specularColor, view, norm, light_position[1].xyz,light_diffuse[1].rgb, 1.0); + col.rgb = scaleDownLight(col.rgb); col.rgb += atmosAmbient(baseCol.rgb); col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz,atmosGetDiffuseSunlightColor()*baseCol.a, 1.0)); diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl index 569b629ef8..41288c21c1 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl @@ -30,6 +30,7 @@ float calcDirectionalLight(vec3 n, vec3 l); vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); +vec3 scaleDownLight(vec3 light); vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) { @@ -37,6 +38,7 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) col.a = color.a; col.rgb = light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); + col.rgb = scaleDownLight(col.rgb); col.rgb += atmosAmbient(baseLight.rgb); col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl index 9e5893d32a..c16e3d50a2 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl @@ -41,3 +41,9 @@ vec3 atmosGetDiffuseSunlightColor() return sunlight_color.rgb; } +vec3 scaleDownLight(vec3 light) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl index 01f19087ff..89b6a52909 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl @@ -41,3 +41,15 @@ vec3 atmosGetDiffuseSunlightColor() return sunlight_color.rgb; } +vec3 scaleDownLight(vec3 light) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + +vec3 scaleUpLight(vec3 light) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + diff --git a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl index 768d93f005..667301443a 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl @@ -39,7 +39,7 @@ vec3 scaleSoftClip(vec3 light) return light; } -vec3 fullbrightScaleSoftClipFrag(vec3 light) +vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 additive, vec3 atten) { // For compatibility with lower cards. Do nothing return light; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index c92dbda185..308a85d2d9 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -49,6 +49,7 @@ uniform vec4 morphFactor; uniform vec3 camPosLocal; //uniform vec4 camPosWorld; uniform vec4 gamma; +uniform vec4 lightnorm; uniform vec4 sunlight_color; uniform vec4 ambient; uniform vec4 blue_horizon; @@ -83,32 +84,9 @@ vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 fullbrightScaleSoftClipFrag(vec3 l); vec3 scaleSoftClipFrag(vec3 l); -vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) -{ - if (no_atmo == 1) - { - return light; - } - return (light + additive) * atten.r * 2.0; -} - -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); -} - -vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); -} +vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten); +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); +vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec4 getPosition_d(vec2 pos_screen, float depth) { @@ -175,7 +153,7 @@ void main() ambient *= ambient; ambient = (1.0-ambient); - col.rgb = ambient * amblit; + col.rgb = ambient * ((col * 0.5) + amblit); col += sunlit * max(min(da, scol), 0.0); diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl index eef259349f..3acf9fe883 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl @@ -31,6 +31,7 @@ vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 atmosGetDiffuseSunlightColor(); +vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_attenuation[8]; @@ -49,6 +50,7 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor col.rgb += light_diffuse[1].rgb * calcDirectionalLightSpecular(specularColor, view, norm, light_position[1].xyz,light_diffuse[1].rgb, 1.0); col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[2].xyz, light_attenuation[2].x, light_attenuation[2].y, light_diffuse[2].rgb); col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[3].xyz, light_attenuation[3].x, light_attenuation[3].y, light_diffuse[3].rgb); + col.rgb = scaleDownLight(col.rgb); // Add windlight lights col.rgb += atmosAmbient(baseCol.rgb); diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl index b42506dd40..c9987ef3b9 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl @@ -28,6 +28,7 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); +vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_direction[8]; @@ -44,6 +45,8 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); + col.rgb = scaleDownLight(col.rgb); + // Add windlight lights col.rgb += atmosAmbient(baseLight.rgb); col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 229f8073b0..9653e0809e 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -52,13 +52,13 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) return light; } light *= atten.r; - light += additive; + light += additive * 2.0; return light; } vec3 atmosLighting(vec3 light) { - return (no_atmo == 1) ? light : atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); + return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); } void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl index 8648c38501..63c683c99e 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl @@ -37,3 +37,8 @@ vec3 atmosFragAffectDirectionalLight(float lightIntensity, vec3 sunlit) return sunlit * lightIntensity; } +vec3 scaleDownLightFrag(vec3 light) +{ + return (light / scene_light_strength ); +} + diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl index a83aa95f95..62a034ce05 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl @@ -49,3 +49,13 @@ vec3 atmosGetDiffuseSunlightColor() return getSunlitColor(); } +vec3 scaleDownLight(vec3 light) +{ + return (light / scene_light_strength ); +} + +vec3 scaleUpLight(vec3 light) +{ + return (light * scene_light_strength); +} + diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index 187876acf7..6401845af2 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -36,10 +36,10 @@ vec3 scaleSoftClipFrag(vec3 light) { return light; } - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - return light; + //soft clip effect: + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, gamma.xxx); + return light; } vec3 scaleSoftClip(vec3 light) @@ -47,13 +47,12 @@ vec3 scaleSoftClip(vec3 light) return scaleSoftClipFrag(light); } -vec3 fullbrightScaleSoftClipFrag(vec3 light) -{ - return scaleSoftClipFrag(light.rgb); +vec3 fullbrightScaleSoftClipFrag(vec3 light) { + return mix(scaleSoftClip(light.rgb), light.rgb, getAtmosAttenuation()); } vec3 fullbrightScaleSoftClip(vec3 light) { - return fullbrightScaleSoftClipFrag(light.rgb); + return fullbrightScaleSoftClipFrag(light); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 75d1bb0cd5..359fea3073 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -38,7 +38,9 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { return light; } - return (light + additive) * atten * 2.0; + light *= atten.r; + light += additive * 2.0; + return light; } vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl index 7870d0516f..e043ac873e 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl @@ -29,6 +29,7 @@ vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 atmosGetDiffuseSunlightColor(); +vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_attenuation[8]; @@ -51,6 +52,7 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[5].xyz, light_attenuation[5].x, light_attenuation[5].y, light_diffuse[5].rgb); col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[6].xyz, light_attenuation[6].x, light_attenuation[6].y, light_diffuse[6].rgb); col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[7].xyz, light_attenuation[7].x, light_attenuation[7].y, light_diffuse[7].rgb); + col.rgb = scaleDownLight(col.rgb); // Add windlight lights col.rgb += atmosAmbient(baseCol.rgb); -- cgit v1.2.3 From c4630a4b15c6297ae669a2030b8fbc4a1490cee4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 14 Nov 2018 19:23:16 -0800 Subject: Work around broken deps on atmospheric vars in the frag-based deferred lighting pipe. --- .../shaders/class1/deferred/deferredUtil.glsl | 4 + .../shaders/class1/deferred/softenLightF.glsl | 184 ++++++++++----------- .../shaders/class1/deferred/softenLightV.glsl | 2 +- .../shaders/class2/windlight/gammaF.glsl | 4 +- 4 files changed, 95 insertions(+), 99 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index b810bb4fd1..43f0034874 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -86,6 +86,8 @@ vec4 getPosition(vec2 pos_screen) return pos; } +#if USE_DEFERRED_SHADER_API + vec4 getPositionWithDepth(vec2 pos_screen, float depth) { vec2 sc = getScreenCoordinate(pos_screen); @@ -285,3 +287,5 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen) return min(ret, 1.0); } +#endif + diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 18259ed9ed..5813dd84ee 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -41,7 +41,7 @@ uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; uniform samplerCube environmentMap; -uniform sampler2D lightFunc; +uniform sampler2D lightFunc; uniform float blur_size; uniform float blur_fidelity; @@ -78,114 +78,106 @@ vec3 fullbrightScaleSoftClip(vec3 l); vec4 getPosition_d(vec2 pos_screen, float depth) { - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; } vec4 getPosition(vec2 pos_screen) { //get position in screen space (world units) given window coordinate and depth map - float depth = texture2DRect(depthMap, pos_screen.xy).a; - return getPosition_d(pos_screen, depth); + float depth = texture2DRect(depthMap, pos_screen.xy).a; + return getPosition_d(pos_screen, depth); } void main() { - vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPosition_d(tc, depth).xyz; - vec4 norm = texture2DRect(normalMap, tc); - float envIntensity = norm.z; - norm.xyz = decode_normal(norm.xy); // unpack norm - - float da = dot(norm.xyz, sun_dir.xyz); - - float final_da = max(0.0,da); - final_da = min(final_da, 1.0f); - -// why an ad hoc gamma boost here? srgb_to_linear instead? - final_da = pow(final_da, 1.0/1.3); - - vec4 diffuse = texture2DRect(diffuseRect, tc); - - //convert to gamma space - diffuse.rgb = linear_to_srgb(diffuse.rgb); - - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - vec3 col; - float bloom = 0.0; - { + vec2 tc = vary_fragcoord.xy; + float depth = texture2DRect(depthMap, tc.xy).r; + vec3 pos = getPosition_d(tc, depth).xyz; + vec4 norm = texture2DRect(normalMap, tc); + float envIntensity = norm.z; + norm.xyz = decode_normal(norm.xy); // unpack norm + + float da = dot(norm.xyz, sun_dir.xyz); + + float final_da = clamp(da, 0.0, 1.0); + final_da = pow(final_da, 1.0/1.3); + + vec4 diffuse = texture2DRect(diffuseRect, tc); + + //convert to gamma space + diffuse.rgb = linear_to_srgb(diffuse.rgb); + + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); + vec3 col; + float bloom = 0.0; + { vec3 sunlit; vec3 amblit; vec3 additive; vec3 atten; - calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - - col = amblit; + calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); + + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); + + col = amblit; col *= ambient; - col += (final_da * sunlit); - col *= diffuse.rgb; - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - - if (spec.a > 0.0) // specular reflection - { - // the old infinite-sky shiny reflection - // - - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - col += spec_contrib; - } - - - col = mix(col.rgb, diffuse.rgb, diffuse.a); - - 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); - } - - if (norm.w < 0.5) - { - col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - } - - #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); - col = fogged.rgb; - bloom = fogged.a; - #endif - - col = srgb_to_linear(col); - - //col = vec3(1,0,1); - //col.g = envIntensity; - } - - frag_color.rgb = col.rgb; - frag_color.a = bloom; + col += (final_da * sunlit); + col *= diffuse.rgb; + + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + + if (spec.a > 0.0) // specular reflection + { + // the old infinite-sky shiny reflection + // + + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + col += spec_contrib; + } + + col = mix(col.rgb, diffuse.rgb, diffuse.a); + + 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); + } + + if (norm.w < 0.5) + { + col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + } + + #ifdef WATER_FOG + vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); + col = fogged.rgb; + bloom = fogged.a; + #endif + + col = srgb_to_linear(col); + + //col = vec3(1,0,1); + //col.g = envIntensity; + } + + frag_color.rgb = col.rgb; + frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl index b59fcbe017..e992776cb4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl @@ -1,5 +1,5 @@ /** - * @file softenLightF.glsl + * @file softenLightV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index 6401845af2..ac7c57747e 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -48,11 +48,11 @@ vec3 scaleSoftClip(vec3 light) } vec3 fullbrightScaleSoftClipFrag(vec3 light) { - return mix(scaleSoftClip(light.rgb), light.rgb, getAtmosAttenuation()); + return scaleSoftClipFrag(light.rgb); } vec3 fullbrightScaleSoftClip(vec3 light) { - return fullbrightScaleSoftClipFrag(light); + return scaleSoftClipFrag(light); } -- cgit v1.2.3 From 5a8e633ece6bcab3b5c2a01b8e31b49ba12714a8 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 15 Nov 2018 13:13:11 -0800 Subject: SL-10066 and SL-10067 Fix fullbright transport transposed args and use display gamma for post-deferred gamma correction. --- .../shaders/class1/deferred/postDeferredGammaCorrect.glsl | 2 +- .../newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 7 +++---- .../app_settings/shaders/class2/windlight/atmosphericsF.glsl | 4 ++-- .../newview/app_settings/shaders/class2/windlight/transportF.glsl | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index cbc19bbba3..8791469675 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -45,7 +45,7 @@ vec3 linear_to_srgb(vec3 cl); void main() { vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - diff.rgb = linear_to_srgb(diff.rgb); + diff.rgb = pow(diff.rgb, vec3(display_gamma)); frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 308a85d2d9..541122fb18 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -153,10 +153,9 @@ void main() ambient *= ambient; ambient = (1.0-ambient); - col.rgb = ambient * ((col * 0.5) + amblit); - - col += sunlit * max(min(da, scol), 0.0); - + col.rgb = amblit; + col.rgb *= ambient; + col += sunlit * min(da, scol); col *= diffuse.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 9653e0809e..3f33eeb8d8 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -52,8 +52,8 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) return light; } light *= atten.r; - light += additive * 2.0; - return light; + light += additive; + return light * 2.0; } vec3 atmosLighting(vec3 light) diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 359fea3073..1ef345d79b 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -53,7 +53,7 @@ vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); } -vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 atten, vec3 additive) { +vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { if (no_atmo == 1) { return light; -- cgit v1.2.3 From 30606a564db3dd3755ed6dc1c30cdacc8c35b40b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 19 Nov 2018 10:49:14 -0800 Subject: SL-10032 Plug more holes through which env ambient terms were finding their way into lighting calcs for HUDs. Fix up mismatched indenting (tabs v spaces) on several shaders. --- .../shaders/class1/windlight/atmosphericsF.glsl | 6 +- .../class1/windlight/atmosphericsHelpersF.glsl | 12 +- .../class1/windlight/atmosphericsHelpersV.glsl | 16 ++- .../shaders/class1/windlight/atmosphericsV.glsl | 4 +- .../shaders/class2/windlight/atmosphericsF.glsl | 158 ++++++++++----------- .../class2/windlight/atmosphericsHelpersF.glsl | 8 +- .../class2/windlight/atmosphericsHelpersV.glsl | 12 +- .../shaders/class2/windlight/transportF.glsl | 14 +- 8 files changed, 119 insertions(+), 111 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl index c1cc3679a7..8b7c4f2ecf 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl @@ -32,7 +32,7 @@ vec3 atmosFragAmbient(vec3 light, vec3 sunlit) vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { /* stub function for fallback compatibility on class1 hardware */ - return light; + return light; } vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit) @@ -43,11 +43,11 @@ vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit) vec3 atmosLighting(vec3 light) { /* stub function for fallback compatibility on class1 hardware */ - return light; + return light; } void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive) { - /* stub function for fallback compatibility on class1 hardware */ + /* stub function for fallback compatibility on class1 hardware */ } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl index c16e3d50a2..10407eeb02 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl @@ -25,25 +25,27 @@ uniform vec4 sunlight_color; uniform vec4 light_ambient; +uniform int no_atmo; vec3 atmosAmbient(vec3 light) { - return light + light_ambient.rgb; + if (no_atmo == 1) return light + vec3(0.66); + return light + light_ambient.rgb; } vec3 atmosAffectDirectionalLight(float lightIntensity) { - return sunlight_color.rgb * lightIntensity; + return sunlight_color.rgb * lightIntensity; } vec3 atmosGetDiffuseSunlightColor() { - return sunlight_color.rgb; + return sunlight_color.rgb; } vec3 scaleDownLight(vec3 light) { - /* stub function for fallback compatibility on class1 hardware */ - return light; + /* stub function for fallback compatibility on class1 hardware */ + return light; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl index 89b6a52909..14034bccae 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl @@ -25,31 +25,33 @@ uniform vec4 sunlight_color; uniform vec4 light_ambient; +uniform int no_atmo; vec3 atmosAmbient(vec3 light) { - return light + light_ambient.rgb; + if (no_atmo == 1) return light + vec3(0.66); + return light + light_ambient.rgb; } vec3 atmosAffectDirectionalLight(float lightIntensity) { - return sunlight_color.rgb * lightIntensity; + return sunlight_color.rgb * lightIntensity; } vec3 atmosGetDiffuseSunlightColor() { - return sunlight_color.rgb; + return sunlight_color.rgb; } vec3 scaleDownLight(vec3 light) { - /* stub function for fallback compatibility on class1 hardware */ - return light; + /* stub function for fallback compatibility on class1 hardware */ + return light; } vec3 scaleUpLight(vec3 light) { - /* stub function for fallback compatibility on class1 hardware */ - return light; + /* stub function for fallback compatibility on class1 hardware */ + return light; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl index 76d7d5059d..b749e1a7a2 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl @@ -29,7 +29,7 @@ void setPositionEye(vec3 v); void calcAtmospherics(vec3 inPositionEye) { - /* stub function for fallback compatibility on class1 hardware */ - setPositionEye(inPositionEye); + /* stub function for fallback compatibility on class1 hardware */ + setPositionEye(inPositionEye); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 3f33eeb8d8..2a629f4f42 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -51,9 +51,9 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { return light; } - light *= atten.r; - light += additive; - return light * 2.0; + light *= atten.r; + light += additive; + return light * 2.0; } vec3 atmosLighting(vec3 light) @@ -63,84 +63,84 @@ vec3 atmosLighting(vec3 light) void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { - vec3 P = inPositionEye; - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(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 - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - atten = temp1.rgb; - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color + vec3 P = inPositionEye; + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(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 + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + atten = temp1.rgb; + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color additive = - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient)); + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient)); - //brightness of surface both sunlight and ambient - sunlit = vec3(sunlight * .5); - amblit = vec3(tmpAmbient * .25); + //brightness of surface both sunlight and ambient + sunlit = vec3(sunlight * .5); + amblit = vec3(tmpAmbient * .25); additive = normalize(additive); - additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; + additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl index 63c683c99e..86743dc306 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl @@ -26,19 +26,21 @@ // Output variables uniform float scene_light_strength; +uniform int no_atmo; vec3 atmosFragAmbient(vec3 light, vec3 amblit) { - return amblit + light / 2.0; + if (no_atmo == 1) return light; + return amblit + light / 2.0; } vec3 atmosFragAffectDirectionalLight(float lightIntensity, vec3 sunlit) { - return sunlit * lightIntensity; + return sunlit * lightIntensity; } vec3 scaleDownLightFrag(vec3 light) { - return (light / scene_light_strength ); + return (light / scene_light_strength ); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl index 62a034ce05..95b4a76880 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl @@ -33,29 +33,31 @@ vec3 getAtmosAttenuation(); vec3 getPositionEye(); uniform float scene_light_strength; +uniform int no_atmo; vec3 atmosAmbient(vec3 light) { - return getAmblitColor() + light / 2.0; + if (no_atmo == 1) return light + vec3(0.66); + return getAmblitColor() + light / 2.0; } vec3 atmosAffectDirectionalLight(float lightIntensity) { - return getSunlitColor() * lightIntensity; + return getSunlitColor() * lightIntensity; } vec3 atmosGetDiffuseSunlightColor() { - return getSunlitColor(); + return getSunlitColor(); } vec3 scaleDownLight(vec3 light) { - return (light / scene_light_strength ); + return (light / scene_light_strength ); } vec3 scaleUpLight(vec3 light) { - return (light * scene_light_strength); + return (light * scene_light_strength); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 1ef345d79b..df731662e8 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -36,11 +36,11 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { if (no_atmo == 1) { - return light; + return light; } light *= atten.r; - light += additive * 2.0; - return light; + light += additive * 2.0; + return light; } vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) @@ -49,8 +49,8 @@ vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { return light; } - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); + float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); } vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { @@ -58,8 +58,8 @@ vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { { return light; } - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); + float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); } vec3 atmosTransport(vec3 light) -- cgit v1.2.3 From b6fa72d3c4d02527f6d118eadc9ba1ac48a297f5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 3 Dec 2018 15:33:15 -0800 Subject: SL-10055 Modify handling of directional light to prefer sun when it is up but use moon dir/color when it is alone in the sky. Modify handling of shader in shaders to get some shadowing of ambient and nighttime shadowing. --- .../shaders/class1/deferred/alphaF.glsl | 13 +- .../shaders/class1/deferred/deferredUtil.glsl | 332 +++++++++++---------- .../shaders/class1/deferred/materialF.glsl | 8 +- .../shaders/class1/deferred/softenLightF.glsl | 12 +- .../shaders/class2/deferred/softenLightF.glsl | 192 ++++++------ .../shaders/class2/deferred/sunLightF.glsl | 14 +- .../shaders/class2/deferred/sunLightSSAOF.glsl | 12 +- 7 files changed, 303 insertions(+), 280 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index f79fc012d1..07b0f2a98a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -43,6 +43,7 @@ uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; +uniform vec3 moon_dir; #if HAS_SHADOW uniform sampler2DShadow shadowMap0; @@ -280,20 +281,20 @@ void main() vec2 abnormal = encode_normal(norm.xyz); norm.xyz = decode_normal(abnormal.xy); - float da = dot(norm.xyz, sun_dir.xyz); + float sun_da = dot(norm.xyz, sun_dir.xyz); + float moon_da = dot(norm.xyz, moon_dir.xyz); - float final_da = da; + float final_da = max(sun_da, moon_da); final_da = min(final_da, shadow); - final_da = max(final_da, 0.0f); - final_da = min(final_da, 1.0f); - final_da = pow(final_da, 1.0/1.3); + final_da = clamp(final_da, 0.0f, 1.0f); + final_da = pow(final_da, 1.0/1.3); vec4 color = vec4(0,0,0,0); color.rgb = atmosFragAmbient(color.rgb, amblit); color.a = final_alpha; - float ambient = abs(da); + float ambient = abs(final_da); ambient *= 0.5; ambient *= ambient; ambient = (1.0-ambient); diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index 43f0034874..ec05dab57f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -1,5 +1,5 @@ /** - * @file shadowUtil.glsl + * @file class1/deferred/deferredUtil.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -39,6 +39,7 @@ uniform float ssao_factor; uniform float ssao_factor_inv; uniform vec3 sun_dir; +uniform vec3 moon_dir; uniform vec2 shadow_res; uniform vec2 proj_shadow_res; uniform mat4 shadow_matrix[6]; @@ -55,7 +56,7 @@ vec3 decode_normal(vec2 enc); vec2 getScreenCoordinate(vec2 screenpos) { - vec2 sc = screenpos.xy * 2.0; + vec2 sc = screenpos.xy * 2.0; if (screen_res.x > 0 && screen_res.y > 0) { sc /= screen_res; @@ -72,41 +73,41 @@ vec3 getNorm(vec2 screenpos) float getDepth(vec2 pos_screen) { float depth = texture2DRect(depthMap, pos_screen).r; - return depth; + return depth; } vec4 getPosition(vec2 pos_screen) { float depth = getDepth(pos_screen); - vec2 sc = getScreenCoordinate(pos_screen); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; + vec2 sc = getScreenCoordinate(pos_screen); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; } #if USE_DEFERRED_SHADER_API vec4 getPositionWithDepth(vec2 pos_screen, float depth) { - vec2 sc = getScreenCoordinate(pos_screen); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; + vec2 sc = getScreenCoordinate(pos_screen); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; } float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) { - stc.xyz /= stc.w; - stc.z += shadow_bias * bias_scale; - - stc.x = floor(stc.x*pos_screen.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; + stc.xyz /= stc.w; + stc.z += shadow_bias * bias_scale; + + stc.x = floor(stc.x*pos_screen.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; @@ -116,85 +117,90 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) { - stc.xyz /= stc.w; - stc.z += spot_shadow_bias * bias_scale; - stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - - vec2 off = 1.0/proj_shadow_res; - off.y *= 1.5; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; + stc.xyz /= stc.w; + stc.z += spot_shadow_bias * bias_scale; + stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + + vec2 off = 1.0/proj_shadow_res; + off.y *= 1.5; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; return shadow*0.2; } float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) { - float dp_directional_light = max(0.0, dot(sun_dir.xyz, norm)); - vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); - vec3 shadow_pos = pos.xyz + (offset * shadow_bias); + float dp_sun = max(0.0, dot(sun_dir.xyz, norm)); + float dp_moon = max(0.0, dot(moon_dir.xyz, norm)); + float dp_directional_light = max(dp_sun,dp_moon); + dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); + + vec3 light_dir = (dp_moon > dp_sun) ? moon_dir : sun_dir; + vec3 offset = light_dir * (1.0-dp_directional_light); + vec3 shadow_pos = pos.xyz + (offset * shadow_bias); float shadow = 0.0f; - vec4 spos = vec4(shadow_pos,1.0); - if (spos.z > -shadow_clip.w) - { - vec4 lpos; - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos, 0.5, pos_screen)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos, 0.75, pos_screen)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos, 0.88, pos_screen)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; - weight += w; - } - - shadow /= weight; - } + vec4 spos = vec4(shadow_pos,1.0); + if (spos.z > -shadow_clip.w) + { + vec4 lpos; + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + if (spos.z < near_split.z) + { + lpos = shadow_matrix[3]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos, 0.5, pos_screen)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + if (spos.z < near_split.y && spos.z > far_split.z) + { + lpos = shadow_matrix[2]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; + w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap2, lpos, 0.75, pos_screen)*w; + weight += w; + } + + if (spos.z < near_split.x && spos.z > far_split.y) + { + lpos = shadow_matrix[1]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; + w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + shadow += pcfShadow(shadowMap1, lpos, 0.88, pos_screen)*w; + weight += w; + } + + if (spos.z > far_split.x) + { + lpos = shadow_matrix[0]*spos; + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; + weight += w; + } + + shadow /= weight; + } return shadow; } @@ -203,88 +209,88 @@ float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) float shadow = 0.0f; pos += norm * spot_shadow_offset; - vec4 spos = vec4(pos,1.0); - if (spos.z > -shadow_clip.w) - { - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; + vec4 spos = vec4(pos,1.0); + if (spos.z > -shadow_clip.w) + { + vec4 lpos; + + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; { - lpos = shadow_matrix[4 + index]*spos; - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - - shadow += pcfSpotShadow((index == 0) ? shadowMap4 : shadowMap5, lpos, 0.8, spos.xy)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - shadow /= weight; - } + lpos = shadow_matrix[4 + index]*spos; + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + + shadow += pcfSpotShadow((index == 0) ? shadowMap4 : shadowMap5, lpos, 0.8, spos.xy)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + shadow /= weight; + } return shadow; } vec2 getKern(int i) { - vec2 kern[8]; - // exponentially (^2) distant occlusion samples spread around origin - kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; - kern[1] = vec2(1.0, 0.0) * 0.250*0.250; - kern[2] = vec2(0.0, 1.0) * 0.375*0.375; - kern[3] = vec2(0.0, -1.0) * 0.500*0.500; - kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; - kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; - kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; - kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; + vec2 kern[8]; + // exponentially (^2) distant occlusion samples spread around origin + kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; + kern[1] = vec2(1.0, 0.0) * 0.250*0.250; + kern[2] = vec2(0.0, 1.0) * 0.375*0.375; + kern[3] = vec2(0.0, -1.0) * 0.500*0.500; + kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; + kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; + kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; + kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; - return kern[i]; + return kern[i]; } //calculate decreases in ambient lighting when crowded out (SSAO) float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen) { - float ret = 1.0; - vec3 pos_world = pos.xyz; - vec2 noise_reflect = texture2D(noiseMap, pos_screen.xy/128.0).xy; - - float angle_hidden = 0.0; - float points = 0; - - float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); - - // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) - for (int i = 0; i < 8; i++) - { - vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); - vec3 samppos_world = getPosition(samppos_screen).xyz; - - vec3 diff = pos_world - samppos_world; - float dist2 = dot(diff, diff); - - // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area - // --> solid angle shrinking by the square of distance - //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 - //(k should vary inversely with # of samples, but this is taken care of later) - - float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; - angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); - - // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" - float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; - points = points + diffz_val; - } - - angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); - - float points_val = (points > 0.0) ? 1.0 : 0.0; - ret = (1.0 - (points_val * angle_hidden)); - - ret = max(ret, 0.0); - return min(ret, 1.0); + float ret = 1.0; + vec3 pos_world = pos.xyz; + vec2 noise_reflect = texture2D(noiseMap, pos_screen.xy/128.0).xy; + + float angle_hidden = 0.0; + float points = 0; + + float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); + + // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) + for (int i = 0; i < 8; i++) + { + vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); + vec3 samppos_world = getPosition(samppos_screen).xyz; + + vec3 diff = pos_world - samppos_world; + float dist2 = dot(diff, diff); + + // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area + // --> solid angle shrinking by the square of distance + //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 + //(k should vary inversely with # of samples, but this is taken care of later) + + float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; + angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); + + // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" + float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; + points = points + diffz_val; + } + + angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); + + float points_val = (points > 0.0) ? 1.0 : 0.0; + ret = (1.0 - (points_val * angle_hidden)); + + ret = max(ret, 0.0); + return min(ret, 1.0); } #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c1c17532b8..7d5ae7c2e7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -98,6 +98,7 @@ uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; +uniform vec3 moon_dir; VARYING vec2 vary_fragcoord; VARYING vec3 vary_position; @@ -381,9 +382,10 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float da =dot(norm.xyz, sun_dir.xyz); + float sun_da = dot(norm.xyz, sun_dir.xyz); + float moon_da = dot(norm.xyz, moon_dir.xyz); - float final_da = da; + float final_da = max(sun_da,moon_da); final_da = min(final_da, shadow); //final_da = max(final_da, diffuse.a); final_da = max(final_da, 0.0f); @@ -392,7 +394,7 @@ void main() col.rgb = atmosFragAmbient(col, amblit); - float ambient = min(abs(da), 1.0); + float ambient = min(abs(final_da), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0-ambient); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 5813dd84ee..41eb06126b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -56,6 +56,7 @@ uniform mat3 env_mat; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; +uniform vec3 moon_dir; VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; @@ -104,15 +105,17 @@ void main() float envIntensity = norm.z; norm.xyz = decode_normal(norm.xy); // unpack norm - float da = dot(norm.xyz, sun_dir.xyz); + float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); + float da_moon = dot(norm.xyz, normalize(moon_dir.xyz)); + float da = max(da_sun, da_moon); float final_da = clamp(da, 0.0, 1.0); - final_da = pow(final_da, 1.0/1.3); + final_da = pow(final_da, global_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); //convert to gamma space - diffuse.rgb = linear_to_srgb(diffuse.rgb); + //diffuse.rgb = linear_to_srgb(diffuse.rgb); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 col; @@ -171,8 +174,7 @@ void main() bloom = fogged.a; #endif - col = srgb_to_linear(col); - + //col = srgb_to_linear(col); //col = vec3(1,0,1); //col.g = envIntensity; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 541122fb18..184ac13b27 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -39,7 +39,7 @@ uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; uniform samplerCube environmentMap; -uniform sampler2D lightFunc; +uniform sampler2D lightFunc; uniform float blur_size; uniform float blur_fidelity; @@ -68,13 +68,12 @@ uniform vec4 shadow_clip; uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; +uniform vec3 moon_dir; VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -uniform int no_atmo; - vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); @@ -90,20 +89,20 @@ vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec4 getPosition_d(vec2 pos_screen, float depth) { - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; } vec4 getPosition(vec2 pos_screen) { //get position in screen space (world units) given window coordinate and depth map - float depth = texture2DRect(depthMap, pos_screen.xy).r; - return getPosition_d(pos_screen, depth); + float depth = texture2DRect(depthMap, pos_screen.xy).r; + return getPosition_d(pos_screen, depth); } @@ -113,92 +112,93 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); void main() { - vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPosition_d(tc, depth).xyz; - vec4 norm = texture2DRect(normalMap, tc); - float envIntensity = norm.z; - norm.xyz = decode_normal(norm.xy); // unpack norm - - float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - - float light_gamma = 1.0/1.3; - da = pow(da, light_gamma); - - vec4 diffuse = texture2DRect(diffuseRect, tc); - - //convert to gamma space - diffuse.rgb = linear_to_srgb(diffuse.rgb); - - vec3 col; - 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(light_gamma)); - - float scol = max(scol_ambocc.r, diffuse.a); - float ambocc = scol_ambocc.g; + vec2 tc = vary_fragcoord.xy; + float depth = texture2DRect(depthMap, tc.xy).r; + vec3 pos = getPosition_d(tc, depth).xyz; + vec4 norm = texture2DRect(normalMap, tc); + float envIntensity = norm.z; + norm.xyz = decode_normal(norm.xy); // unpack norm + + float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); + float da_moon = dot(norm.xyz, normalize(moon_dir.xyz)); + float da = max(da_sun, da_moon); + da = clamp(da, 0.0, 1.0); + + da = pow(da, global_gamma); + + vec4 diffuse = texture2DRect(diffuseRect, tc); + + //convert to gamma space + //diffuse.rgb = linear_to_srgb(diffuse.rgb); + + vec3 col; + 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)); + + float scol = max(scol_ambocc.r, diffuse.a); + float ambocc = scol_ambocc.g; vec3 sunlit; vec3 amblit; vec3 additive; vec3 atten; - - calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); - - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb = amblit; - col.rgb *= ambient; - col += sunlit * min(da, scol); - col *= diffuse.rgb; - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - - if (spec.a > 0.0) // specular reflection - { - // the old infinite-sky shiny reflection - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = sunlit*scol_ambocc.r*(texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - col += spec_contrib; - } - - col = mix(col, diffuse.rgb, diffuse.a); - - 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); - } - - if (norm.w < 0.5) - { - col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); - col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col), diffuse.a); - } - - #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); - col = fogged.rgb; - bloom = fogged.a; - #endif - - col = srgb_to_linear(col); - - //col = vec3(1,0,1); - //col.g = envIntensity; - } - - frag_color.rgb = col; - frag_color.a = bloom; + + calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); + + float ambient = dot(norm.xyz, sun_dir.xyz); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); + + col.rgb = amblit; + col.rgb *= min(ambient, max(scol, 0.5)); + + col += (sunlit * da) * scol; + + col *= diffuse.rgb; + + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + + if (spec.a > 0.0) // specular reflection + { + // the old infinite-sky shiny reflection + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = sunlit*scol_ambocc.r*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + col += spec_contrib; + } + + col = mix(col, diffuse.rgb, diffuse.a); + + 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); + } + + if (norm.w < 0.5) + { + col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); + col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col), diffuse.a); + } + + #ifdef WATER_FOG + vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); + col = fogged.rgb; + bloom = fogged.a; + #endif + + //col = srgb_to_linear(col); + + } + frag_color.rgb = col; + frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index aa5e99a2f7..f2d04c95fe 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -59,6 +59,7 @@ uniform mat4 inv_proj; uniform vec2 screen_res; uniform vec2 proj_shadow_res; uniform vec3 sun_dir; +uniform vec3 moon_dir; uniform vec2 shadow_res; uniform float shadow_bias; @@ -138,11 +139,16 @@ void main() return; }*/ - float shadow = 0.0; - float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); - + float shadow = 0.0; + float dp_sun = dot(norm, normalize(sun_dir.xyz)); + float dp_moon = dot(norm, normalize(moon_dir.xyz)); + float dp_directional_light = max(dp_sun, dp_moon); + dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); + + vec3 light_direction = (dp_moon > dp_sun) ? moon_dir : sun_dir; + vec3 shadow_pos = pos.xyz; - vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); + vec3 offset = light_direction.xyz * (1.0-dp_directional_light); vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 58f3f2f91e..fd3256e9c8 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -59,6 +59,7 @@ uniform mat4 inv_proj; uniform vec2 screen_res; uniform vec2 proj_shadow_res; uniform vec3 sun_dir; +uniform vec3 moon_dir; uniform vec2 shadow_res; @@ -200,10 +201,15 @@ void main() }*/ float shadow = 0.0; - float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); - + float dp_sun = dot(norm, normalize(sun_dir.xyz)); + float dp_moon = dot(norm, normalize(moon_dir.xyz)); + float dp_directional_light = max(dp_sun, dp_moon); + dp_directional_light = max(0.0, dp_directional_light); + + vec3 light_direction = (dp_moon > dp_sun) ? moon_dir : sun_dir; + vec3 shadow_pos = pos.xyz; - vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); + vec3 offset = light_direction.xyz * (1.0-dp_directional_light); vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); -- cgit v1.2.3 From 26c1430a04de585c1823569b60dc99abc798231b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 5 Dec 2018 13:08:06 -0800 Subject: Shader cleanup and consolidation of use of sRGB conversion funcs. --- .../shaders/class1/deferred/alphaF.glsl | 33 ++++-------- .../shaders/class1/deferred/fullbrightF.glsl | 6 --- .../shaders/class1/deferred/impostorF.glsl | 4 -- .../shaders/class1/deferred/materialF.glsl | 21 ++------ .../shaders/class1/deferred/multiSpotLightF.glsl | 5 -- .../class1/deferred/postDeferredGammaCorrect.glsl | 6 +-- .../shaders/class1/deferred/softenLightF.glsl | 34 +++++------- .../shaders/class1/deferred/spotLightF.glsl | 10 ---- .../app_settings/shaders/class1/deferred/srgb.glsl | 61 ---------------------- .../shaders/class1/deferred/underWaterF.glsl | 3 -- .../shaders/class1/deferred/waterF.glsl | 1 - .../shaders/class1/environment/srgbF.glsl | 18 +++++++ .../shaders/class1/windlight/atmosphericsF.glsl | 2 +- .../shaders/class2/deferred/multiSpotLightF.glsl | 10 ---- .../shaders/class2/deferred/softenLightF.glsl | 14 ++--- .../shaders/class2/deferred/softenLightV.glsl | 2 - .../shaders/class2/deferred/spotLightF.glsl | 10 ---- .../shaders/class3/windlight/transportF.glsl | 15 +++--- 18 files changed, 59 insertions(+), 196 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class1/deferred/srgb.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 07b0f2a98a..5e3c767460 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -84,11 +84,8 @@ uniform vec3 light_diffuse[8]; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); vec2 encode_normal (vec3 n); vec3 decode_normal (vec2 enc); - vec3 scaleSoftClip(vec3 l); vec3 atmosFragAmbient(vec3 light, vec3 sunlit); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); @@ -162,7 +159,8 @@ void main() frag *= screen_res; vec4 pos = vec4(vary_position, 1.0); - + vec3 norm = vary_norm; + float shadow = 1.0; #if HAS_SHADOW @@ -265,17 +263,10 @@ void main() float final_alpha = diff.a; #endif - - vec4 gamma_diff = diff; - diff.rgb = srgb_to_linear(diff.rgb); - - vec3 norm = vary_norm; - - 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); vec2 abnormal = encode_normal(norm.xyz); @@ -287,7 +278,7 @@ void main() float final_da = max(sun_da, moon_da); final_da = min(final_da, shadow); final_da = clamp(final_da, 0.0f, 1.0f); - final_da = pow(final_da, 1.0/1.3); + final_da = pow(final_da, display_gamma); vec4 color = vec4(0,0,0,0); @@ -300,8 +291,8 @@ void main() ambient = (1.0-ambient); color.rgb *= ambient; - color.rgb += atmosFragAffectDirectionalLight(final_da, sunlit); - color.rgb *= gamma_diff.rgb; + color.rgb += (final_da * sunlit); + color.rgb *= diff.rgb; //color.rgb = mix(diff.rgb, color.rgb, final_alpha); @@ -310,8 +301,6 @@ void main() vec4 light = vec4(0,0,0,0); - color.rgb = srgb_to_linear(color.rgb); - #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_LOOP(1) @@ -326,10 +315,6 @@ void main() // color.rgb += light.rgb; - // straight to display gamma, we're post-deferred - // - color.rgb = linear_to_srgb(color.rgb); - #ifdef WATER_FOG color = applyWaterFogView(pos.xyz, color); #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 0e21e5925d..2db737a427 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -45,9 +45,6 @@ VARYING vec2 vary_texcoord0; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); - vec3 fullbrightAtmosTransportDeferred(vec3 light) { return light; @@ -81,12 +78,9 @@ void main() #endif color.rgb *= vertex_color.rgb; - color.rgb = srgb_to_linear(color.rgb); color.rgb = fullbrightAtmosTransportDeferred(color.rgb); color.rgb = fullbrightScaleSoftClipDeferred(color.rgb); - color.rgb = linear_to_srgb(color.rgb); - #ifdef WATER_FOG vec3 pos = vary_position; vec4 fogged = applyWaterFogView(pos, vec4(color.rgb, final_alpha)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index 6ba16b169c..d29e8a9423 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -40,8 +40,6 @@ uniform sampler2D specularMap; VARYING vec2 vary_texcoord0; -vec3 linear_to_srgb(vec3 cl); - void main() { vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); @@ -54,8 +52,6 @@ void main() vec4 norm = texture2D(normalMap, vary_texcoord0.xy); vec4 spec = texture2D(specularMap, vary_texcoord0.xy); - col.rgb = linear_to_srgb(col.rgb); - frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = spec; frag_data[2] = vec4(norm.xy,0,0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 7d5ae7c2e7..211bedee59 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -37,10 +37,6 @@ uniform float display_gamma; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); - -vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -234,6 +230,8 @@ vec3 decode_normal (vec2 enc); void main() { + vec2 pos_screen = vary_texcoord0.xy; + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); diffcol.rgb *= vertex_color.rgb; @@ -246,7 +244,6 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vec3 gamma_diff = diffcol.rgb; - diffcol.rgb = srgb_to_linear(diffcol.rgb); #endif #if HAS_SPECULAR_MAP @@ -390,9 +387,9 @@ void main() //final_da = max(final_da, diffuse.a); final_da = max(final_da, 0.0f); final_da = min(final_da, 1.0f); - final_da = pow(final_da, 1.0/1.3); + final_da = pow(final_da, display_gamma); - col.rgb = atmosFragAmbient(col, amblit); + col.rgb = (col * 0.5) + amblit; float ambient = min(abs(final_da), 1.0); ambient *= 0.5; @@ -446,14 +443,7 @@ void main() glare += cur_glare; } - //col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - col = atmosFragLighting(col, additive, atten); - col = scaleSoftClipFrag(col); - - //convert to linear space before adding local lights - col = srgb_to_linear(col); vec3 npos = normalize(-pos.xyz); @@ -474,8 +464,7 @@ void main() glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; - //convert to gamma space for display on screen - col.rgb = linear_to_srgb(col.rgb); + col = scaleSoftClipFrag(col); #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 1d75322b4c..b3dcd90d98 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -73,13 +73,10 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 decode_normal (vec2 enc); -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -99,7 +96,6 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -117,7 +113,6 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = tc-vec2(0.5); diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 8791469675..0b943d2527 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -40,12 +40,10 @@ VARYING vec2 vary_fragcoord; uniform float display_gamma; -vec3 linear_to_srgb(vec3 cl); - void main() { - vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); + vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); diff.rgb = pow(diff.rgb, vec3(display_gamma)); - frag_color = diff; + frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 41eb06126b..2ba766a0c4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -66,10 +66,7 @@ uniform vec2 screen_res; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); - vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 fullbrightAtmosTransportFrag(vec3 l, vec3 additive, vec3 atten); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); @@ -114,13 +111,10 @@ void main() vec4 diffuse = texture2DRect(diffuseRect, tc); - //convert to gamma space - //diffuse.rgb = linear_to_srgb(diffuse.rgb); - - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - vec3 col; - float bloom = 0.0; - { + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); + vec3 col; + float bloom = 0.0; + { vec3 sunlit; vec3 amblit; vec3 additive; @@ -168,18 +162,14 @@ void main() col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); } - #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); - col = fogged.rgb; - bloom = fogged.a; - #endif - - //col = srgb_to_linear(col); - //col = vec3(1,0,1); - //col.g = envIntensity; - } + #ifdef WATER_FOG + vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); + col = fogged.rgb; + bloom = fogged.a; + #endif + } - frag_color.rgb = col.rgb; - frag_color.a = bloom; + frag_color.rgb = col.rgb; + frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 2b6428963d..1abdd4af33 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -71,18 +71,10 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 decode_normal (vec2 enc); -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); - -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.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -102,7 +94,6 @@ 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)); @@ -120,7 +111,6 @@ 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); diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl deleted file mode 100644 index bc3324f543..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @file srgb.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, 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$ - */ - -vec3 rgb2hsv(vec3 c) -{ - vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); - vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); - vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); - - float d = q.x - min(q.w, q.y); - float e = 1.0e-10; - return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); -} - -vec3 hsv2rgb(vec3 c) -{ - vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); - vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); - return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); -} - -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - return mix(high_range, low_range, lte); -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - - bvec3 lt = lessThan(cl,vec3(0.0031308)); - return mix(high_range, low_range, lt); -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index db1eab23fb..e95a688e1f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -58,9 +58,6 @@ VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); - vec2 encode_normal(vec3 n); vec4 applyWaterFog(vec4 color, vec3 viewVec) diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 69543b93ea..9da2548586 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -62,7 +62,6 @@ VARYING vec4 littleWave; VARYING vec4 view; VARYING vec4 vary_position; -vec3 srgb_to_linear(vec3 cs); vec2 encode_normal(vec3 n); vec3 scaleSoftClipFrag(vec3 l); diff --git a/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl index f98b3a5edf..4a8b892c3a 100644 --- a/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl @@ -64,3 +64,21 @@ vec3 ColorFromRadiance(vec3 radiance) { return vec3(1.0) - exp(-radiance * 0.0001); } + +vec3 rgb2hsv(vec3 c) +{ + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + +vec3 hsv2rgb(vec3 c) +{ + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl index 8b7c4f2ecf..4f0e2a6cb6 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericsF.glsl + * @file class1\windlight\atmosphericsF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 864ba4859d..0a8981a102 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -71,19 +71,11 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); -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.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -103,7 +95,6 @@ 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)); @@ -121,7 +112,6 @@ 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); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 184ac13b27..9de2741725 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -74,8 +74,6 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); @@ -124,13 +122,10 @@ void main() float da = max(da_sun, da_moon); da = clamp(da, 0.0, 1.0); - da = pow(da, global_gamma); - - vec4 diffuse = texture2DRect(diffuseRect, tc); - - //convert to gamma space - //diffuse.rgb = linear_to_srgb(diffuse.rgb); + da = pow(da, global_gamma); + vec4 diffuse = texture2DRect(diffuseRect, tc); + vec3 col; float bloom = 0.0; { @@ -195,9 +190,6 @@ void main() col = fogged.rgb; bloom = fogged.a; #endif - - //col = srgb_to_linear(col); - } frag_color.rgb = col; frag_color.a = bloom; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl index c840d72784..8b8b338f68 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl @@ -36,7 +36,5 @@ void main() //transform vertex vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); gl_Position = pos; - - vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index a7da140b31..d97bd936d9 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -72,18 +72,10 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 decode_normal (vec2 enc); -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); - -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.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -103,7 +95,6 @@ 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)); @@ -121,7 +112,6 @@ 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); diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index 9c050256dc..90ab5d2793 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -61,14 +61,17 @@ vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); } -vec3 atmosTransport(vec3 light) { - return (no_atmo == 1) ? light : atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); +vec3 atmosTransport(vec3 light) +{ + return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } -vec3 fullbrightAtmosTransport(vec3 light) { - return (no_atmo == 1) ? light : fullbrightAtmosTransportFrag(light, GetAdditiveColor(), getAtmosAttenuation()); +vec3 fullbrightAtmosTransport(vec3 light) +{ + return fullbrightAtmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } -vec3 fullbrightShinyAtmosTransport(vec3 light) { - return (no_atmo == 1) ? light : fullbrightShinyAtmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); +vec3 fullbrightShinyAtmosTransport(vec3 light) +{ + return fullbrightShinyAtmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } -- cgit v1.2.3 From 7e9033821a96a9d6e80b58fafb4c7da63807b9d4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 6 Dec 2018 10:59:11 -0800 Subject: De-duplicate deferred gbuffer access for getPosition/getNorm. De-duplicate ambient occlusion shader code and move to new aoUtil.glsl Split shared shadow tap funcs into shadowUtil.glsl --- .../shaders/class1/deferred/alphaF.glsl | 319 +++++++------- .../shaders/class1/deferred/aoUtil.glsl | 93 ++++ .../shaders/class1/deferred/blurLightF.glsl | 125 +++--- .../shaders/class1/deferred/deferredUtil.glsl | 222 ---------- .../shaders/class1/deferred/materialF.glsl | 487 +++++++++++---------- .../shaders/class1/deferred/multiPointLightF.glsl | 13 +- .../shaders/class1/deferred/multiSpotLightF.glsl | 14 +- .../shaders/class1/deferred/pointLightF.glsl | 13 +- .../shaders/class1/deferred/shadowUtil.glsl | 191 ++++++++ .../shaders/class1/deferred/softenLightF.glsl | 36 +- .../shaders/class1/deferred/spotLightF.glsl | 14 +- .../shaders/class1/deferred/sunLightSSAOF.glsl | 87 +--- .../shaders/class2/deferred/multiSpotLightF.glsl | 14 +- .../shaders/class2/deferred/softenLightF.glsl | 40 +- .../shaders/class2/deferred/spotLightF.glsl | 14 +- .../shaders/class2/deferred/sunLightF.glsl | 39 +- .../shaders/class2/deferred/sunLightSSAOF.glsl | 117 +---- 17 files changed, 820 insertions(+), 1018 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl create mode 100644 indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 5e3c767460..33e61f2062 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -94,46 +94,46 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) { - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float d = length(lv); - - float da = 1.0; - - vec3 col = vec3(0); - - if (d > 0.0 && la > 0.0 && fa > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //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 - - //angular attenuation - da *= max(dot(n, lv), 0.0); - - float lit = max(da * dist_atten,0.0); - - col = light_col * lit * diffuse; - - // no spec for alpha shader... - } - - return max(col, vec3(0.0,0.0,0.0)); + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float d = length(lv); + + float da = 1.0; + + vec3 col = vec3(0); + + if (d > 0.0 && la > 0.0 && fa > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //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 + + //angular attenuation + da *= max(dot(n, lv), 0.0); + + float lit = max(da * dist_atten,0.0); + + col = light_col * lit * diffuse; + + // no spec for alpha shader... + } + + return max(col, vec3(0.0,0.0,0.0)); } #if HAS_SHADOW -float pcfShadow(sampler2DShadow shadowMap, vec4 stc) +float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc) { stc.xyz /= stc.w; stc.z += shadow_bias; @@ -152,174 +152,175 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc) } #endif +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen); void main() { - vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; - frag *= screen_res; - - vec4 pos = vec4(vary_position, 1.0); - vec3 norm = vary_norm; + vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; + frag *= screen_res; + + vec4 pos = vec4(vary_position, 1.0); + vec3 norm = vary_norm; - float shadow = 1.0; + float shadow = 1.0; #if HAS_SHADOW - vec4 spos = pos; - - if (spos.z > -shadow_clip.w) - { - shadow = 0.0; - - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadow(shadowMap0, lpos)*w; - weight += w; - } - - - shadow /= weight; - } - else - { - shadow = 1.0; - } + vec4 spos = pos; + + if (spos.z > -shadow_clip.w) + { + shadow = 0.0; + + vec4 lpos; + + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + if (spos.z < near_split.z) + { + lpos = shadow_matrix[3]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadowLegacy(shadowMap3, lpos)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + if (spos.z < near_split.y && spos.z > far_split.z) + { + lpos = shadow_matrix[2]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; + w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + shadow += pcfShadowLegacy(shadowMap2, lpos)*w; + weight += w; + } + + if (spos.z < near_split.x && spos.z > far_split.y) + { + lpos = shadow_matrix[1]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; + w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + shadow += pcfShadowLegacy(shadowMap1, lpos)*w; + weight += w; + } + + if (spos.z > far_split.x) + { + lpos = shadow_matrix[0]*spos; + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadowLegacy(shadowMap0, lpos)*w; + weight += w; + } + + + shadow /= weight; + } + else + { + shadow = 1.0; + } #endif #ifdef USE_INDEXED_TEX - vec4 diff = diffuseLookup(vary_texcoord0.xy); + vec4 diff = diffuseLookup(vary_texcoord0.xy); #else - vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); + vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif #ifdef FOR_IMPOSTOR - vec4 color; - color.rgb = diff.rgb; - color.a = 1.0; + vec4 color; + color.rgb = diff.rgb; + color.a = 1.0; #ifdef USE_VERTEX_COLOR - float final_alpha = diff.a * vertex_color.a; - diff.rgb *= vertex_color.rgb; + float final_alpha = diff.a * vertex_color.a; + diff.rgb *= vertex_color.rgb; #else - float final_alpha = diff.a; + float final_alpha = diff.a; #endif - - // Insure we don't pollute depth with invis pixels in impostor rendering - // - if (final_alpha < 0.01) - { - discard; - } + + // Insure we don't pollute depth with invis pixels in impostor rendering + // + if (final_alpha < 0.01) + { + discard; + } #else - + #ifdef USE_VERTEX_COLOR - float final_alpha = diff.a * vertex_color.a; - diff.rgb *= vertex_color.rgb; + float final_alpha = diff.a * vertex_color.a; + diff.rgb *= vertex_color.rgb; #else - float final_alpha = diff.a; + float final_alpha = diff.a; #endif vec3 sunlit; vec3 amblit; vec3 additive; vec3 atten; - calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); + calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - vec2 abnormal = encode_normal(norm.xyz); - norm.xyz = decode_normal(abnormal.xy); + vec2 abnormal = encode_normal(norm.xyz); + norm.xyz = decode_normal(abnormal.xy); - float sun_da = dot(norm.xyz, sun_dir.xyz); - float moon_da = dot(norm.xyz, moon_dir.xyz); + float sun_da = dot(norm.xyz, sun_dir.xyz); + float moon_da = dot(norm.xyz, moon_dir.xyz); float final_da = max(sun_da, moon_da); final_da = min(final_da, shadow); final_da = clamp(final_da, 0.0f, 1.0f); - final_da = pow(final_da, display_gamma); + final_da = pow(final_da, display_gamma); - vec4 color = vec4(0,0,0,0); + vec4 color = vec4(0,0,0,0); - color.rgb = atmosFragAmbient(color.rgb, amblit); - color.a = final_alpha; + color.rgb = atmosFragAmbient(color.rgb, amblit); + color.a = final_alpha; - float ambient = abs(final_da); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0-ambient); + float ambient = abs(final_da); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); - color.rgb *= ambient; - color.rgb += (final_da * sunlit); - color.rgb *= diff.rgb; + color.rgb *= ambient; + color.rgb += (final_da * sunlit); + 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 = mix(diff.rgb, color.rgb, final_alpha); + + color.rgb = atmosFragLighting(color.rgb, additive, atten); + color.rgb = scaleSoftClip(color.rgb); - vec4 light = vec4(0,0,0,0); + 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_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) - // keep it linear - // - color.rgb += light.rgb; + // keep it linear + // + color.rgb += light.rgb; #ifdef WATER_FOG - color = applyWaterFogView(pos.xyz, color); + color = applyWaterFogView(pos.xyz, color); #endif #endif - frag_color = color; + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl new file mode 100644 index 0000000000..3bb59dd7f9 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl @@ -0,0 +1,93 @@ +/** + * @file class1/deferred/aoUtil.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 sampler2D noiseMap; + +uniform float ssao_radius; +uniform float ssao_max_radius; +uniform float ssao_factor; +uniform float ssao_factor_inv; + +vec4 getPosition(vec2 pos_screen); + +vec2 getKern(int i) +{ + vec2 kern[8]; + // exponentially (^2) distant occlusion samples spread around origin + kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; + kern[1] = vec2(1.0, 0.0) * 0.250*0.250; + kern[2] = vec2(0.0, 1.0) * 0.375*0.375; + kern[3] = vec2(0.0, -1.0) * 0.500*0.500; + kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; + kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; + kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; + kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; + + return kern[i]; +} + +//calculate decreases in ambient lighting when crowded out (SSAO) +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen) +{ + float ret = 1.0; + vec3 pos_world = pos.xyz; + vec2 noise_reflect = texture2D(noiseMap, pos_screen.xy/128.0).xy; + + float angle_hidden = 0.0; + float points = 0; + + float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); + + // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) + for (int i = 0; i < 8; i++) + { + vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); + vec3 samppos_world = getPosition(samppos_screen).xyz; + + vec3 diff = pos_world - samppos_world; + float dist2 = dot(diff, diff); + + // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area + // --> solid angle shrinking by the square of distance + //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 + //(k should vary inversely with # of samples, but this is taken care of later) + + float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; + angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); + + // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" + float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; + points = points + diffz_val; + } + + angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); + + float points_val = (points > 0.0) ? 1.0 : 0.0; + ret = (1.0 - (points_val * angle_hidden)); + + ret = max(ret, 0.0); + return min(ret, 1.0); +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index b56abb66d1..868eec3926 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -48,82 +48,69 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); vec3 decode_normal (vec2 enc); void main() { vec2 tc = vary_fragcoord.xy; - vec3 norm = texture2DRect(normalMap, tc).xyz; - norm = decode_normal(norm.xy); // unpack norm - - vec3 pos = getPosition(tc).xyz; - vec4 ccol = texture2DRect(lightMap, tc).rgba; - - vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy); - dlt /= max(-pos.z*dist_factor, 1.0); - - vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free' - vec4 col = defined_weight.xyxx * ccol; - - // relax tolerance according to distance to avoid speckling artifacts, as angles and distances are a lot more abrupt within a small screen area at larger distances - float pointplanedist_tolerance_pow2 = pos.z*pos.z*0.00005; - - // perturb sampling origin slightly in screen-space to hide edge-ghosting artifacts where smoothing radius is quite large - float tc_mod = 0.5*(tc.x + tc.y); // mod(tc.x+tc.y,2) - tc_mod -= floor(tc_mod); - tc_mod *= 2.0; - tc += ( (tc_mod - 0.5) * kern[1].z * dlt * 0.5 ); - - for (int i = 1; i < 4; i++) - { - vec2 samptc = tc + kern[i].z*dlt; - vec3 samppos = getPosition(samptc).xyz; - - float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane - - if (d*d <= pointplanedist_tolerance_pow2) - { - col += texture2DRect(lightMap, samptc)*kern[i].xyxx; - defined_weight += kern[i].xy; - } - } - - for (int i = 1; i < 4; i++) - { - vec2 samptc = tc - kern[i].z*dlt; - vec3 samppos = getPosition(samptc).xyz; - - float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane - - if (d*d <= pointplanedist_tolerance_pow2) - { - col += texture2DRect(lightMap, samptc)*kern[i].xyxx; - defined_weight += kern[i].xy; - } - } - - col /= defined_weight.xyxx; - col.y *= col.y; - - frag_color = col; + vec3 norm = getNorm(tc); + vec3 pos = getPosition(tc).xyz; + vec4 ccol = texture2DRect(lightMap, tc).rgba; + + vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy); + dlt /= max(-pos.z*dist_factor, 1.0); + + vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free' + vec4 col = defined_weight.xyxx * ccol; + + // relax tolerance according to distance to avoid speckling artifacts, as angles and distances are a lot more abrupt within a small screen area at larger distances + float pointplanedist_tolerance_pow2 = pos.z*pos.z*0.00005; + + // perturb sampling origin slightly in screen-space to hide edge-ghosting artifacts where smoothing radius is quite large + float tc_mod = 0.5*(tc.x + tc.y); // mod(tc.x+tc.y,2) + tc_mod -= floor(tc_mod); + tc_mod *= 2.0; + tc += ( (tc_mod - 0.5) * kern[1].z * dlt * 0.5 ); + + for (int i = 1; i < 4; i++) + { + vec2 samptc = tc + kern[i].z*dlt; + vec3 samppos = getPosition(samptc).xyz; + + float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane + + if (d*d <= pointplanedist_tolerance_pow2) + { + col += texture2DRect(lightMap, samptc)*kern[i].xyxx; + defined_weight += kern[i].xy; + } + } + + for (int i = 1; i < 4; i++) + { + vec2 samptc = tc - kern[i].z*dlt; + vec3 samppos = getPosition(samptc).xyz; + + float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane + + if (d*d <= pointplanedist_tolerance_pow2) + { + col += texture2DRect(lightMap, samptc)*kern[i].xyxx; + defined_weight += kern[i].xy; + } + } + + col /= defined_weight.xyxx; + col.y *= col.y; + + frag_color = col; #ifdef IS_AMD_CARD - // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. - vec3 dummy1 = kern[0]; - vec3 dummy2 = kern[3]; + // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. + vec3 dummy1 = kern[0]; + vec3 dummy2 = kern[3]; #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index ec05dab57f..9d7a7f6556 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -25,29 +25,6 @@ uniform sampler2DRect normalMap; uniform sampler2DRect depthMap; -uniform sampler2D noiseMap; -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; -uniform sampler2DShadow shadowMap4; -uniform sampler2DShadow shadowMap5; - -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; - -uniform vec3 sun_dir; -uniform vec3 moon_dir; -uniform vec2 shadow_res; -uniform vec2 proj_shadow_res; -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform float shadow_bias; - -uniform float spot_shadow_bias; -uniform float spot_shadow_offset; uniform mat4 inv_proj; uniform vec2 screen_res; @@ -87,8 +64,6 @@ vec4 getPosition(vec2 pos_screen) return pos; } -#if USE_DEFERRED_SHADER_API - vec4 getPositionWithDepth(vec2 pos_screen, float depth) { vec2 sc = getScreenCoordinate(pos_screen); @@ -98,200 +73,3 @@ vec4 getPositionWithDepth(vec2 pos_screen, float depth) pos.w = 1.0; return pos; } - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias * bias_scale; - - stc.x = floor(stc.x*pos_screen.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - return shadow*0.2; -} - -float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) -{ - stc.xyz /= stc.w; - stc.z += spot_shadow_bias * bias_scale; - stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - - vec2 off = 1.0/proj_shadow_res; - off.y *= 1.5; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; - return shadow*0.2; -} - -float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) -{ - float dp_sun = max(0.0, dot(sun_dir.xyz, norm)); - float dp_moon = max(0.0, dot(moon_dir.xyz, norm)); - float dp_directional_light = max(dp_sun,dp_moon); - dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); - - vec3 light_dir = (dp_moon > dp_sun) ? moon_dir : sun_dir; - vec3 offset = light_dir * (1.0-dp_directional_light); - vec3 shadow_pos = pos.xyz + (offset * shadow_bias); - - float shadow = 0.0f; - vec4 spos = vec4(shadow_pos,1.0); - if (spos.z > -shadow_clip.w) - { - vec4 lpos; - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos, 0.5, pos_screen)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos, 0.75, pos_screen)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos, 0.88, pos_screen)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; - weight += w; - } - - shadow /= weight; - } - return shadow; -} - -float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) -{ - float shadow = 0.0f; - pos += norm * spot_shadow_offset; - - vec4 spos = vec4(pos,1.0); - if (spos.z > -shadow_clip.w) - { - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - { - lpos = shadow_matrix[4 + index]*spos; - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - - shadow += pcfSpotShadow((index == 0) ? shadowMap4 : shadowMap5, lpos, 0.8, spos.xy)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - shadow /= weight; - } - return shadow; -} - -vec2 getKern(int i) -{ - vec2 kern[8]; - // exponentially (^2) distant occlusion samples spread around origin - kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; - kern[1] = vec2(1.0, 0.0) * 0.250*0.250; - kern[2] = vec2(0.0, 1.0) * 0.375*0.375; - kern[3] = vec2(0.0, -1.0) * 0.500*0.500; - kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; - kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; - kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; - kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; - - return kern[i]; -} - -//calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen) -{ - float ret = 1.0; - vec3 pos_world = pos.xyz; - vec2 noise_reflect = texture2D(noiseMap, pos_screen.xy/128.0).xy; - - float angle_hidden = 0.0; - float points = 0; - - float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); - - // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) - for (int i = 0; i < 8; i++) - { - vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); - vec3 samppos_world = getPosition(samppos_screen).xyz; - - vec3 diff = pos_world - samppos_world; - float dist2 = dot(diff, diff); - - // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area - // --> solid angle shrinking by the square of distance - //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 - //(k should vary inversely with # of samples, but this is taken care of later) - - float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; - angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); - - // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" - float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; - points = points + diffz_val; - } - - angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); - - float points_val = (points > 0.0) ? 1.0 : 0.0; - ret = (1.0 - (points_val * angle_hidden)); - - ret = max(ret, 0.0); - return min(ret, 1.0); -} - -#endif - diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 211bedee59..a0da8563a2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -25,9 +25,9 @@ /*[EXTRA_CODE_HERE]*/ -#define DIFFUSE_ALPHA_MODE_IGNORE 0 -#define DIFFUSE_ALPHA_MODE_BLEND 1 -#define DIFFUSE_ALPHA_MODE_MASK 2 +#define DIFFUSE_ALPHA_MODE_IGNORE 0 +#define DIFFUSE_ALPHA_MODE_BLEND 1 +#define DIFFUSE_ALPHA_MODE_MASK 2 #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 uniform float emissive_brightness; @@ -62,7 +62,7 @@ uniform vec4 shadow_clip; uniform vec2 shadow_res; uniform float shadow_bias; -float pcfShadow(sampler2DShadow shadowMap, vec4 stc) +float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc) { stc.xyz /= stc.w; stc.z += shadow_bias; @@ -80,10 +80,11 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc) return shadow*0.2; } +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen); #endif uniform samplerCube environmentMap; -uniform sampler2D lightFunc; +uniform sampler2D lightFunc; // Inputs uniform vec4 morphFactor; @@ -109,80 +110,80 @@ 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) { - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float d = length(lv); - - float da = 1.0; - - vec3 col = vec3(0,0,0); - - if (d > 0.0 && la > 0.0 && fa > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //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 - - //angular attenuation - da *= max(dot(n, lv), 0.0); - - float lit = max(da * dist_atten, 0.0); - - col = light_col*lit*diffuse; - - if (spec.a > 0.0) - { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = lit*scol*light_col.rgb*spec.rgb; - 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); - //col += spec.rgb; - } - } - } - - return max(col, vec3(0.0,0.0,0.0)); + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float d = length(lv); + + float da = 1.0; + + vec3 col = vec3(0,0,0); + + if (d > 0.0 && la > 0.0 && fa > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //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 + + //angular attenuation + da *= max(dot(n, lv), 0.0); + + float lit = max(da * dist_atten, 0.0); + + col = light_col*lit*diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = lit*scol*light_col.rgb*spec.rgb; + 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); + //col += spec.rgb; + } + } + } + + return max(col, vec3(0.0,0.0,0.0)); } vec4 getPosition_d(vec2 pos_screen, float depth) { - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; } @@ -232,253 +233,253 @@ void main() { vec2 pos_screen = vary_texcoord0.xy; - vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); - diffcol.rgb *= vertex_color.rgb; + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); + diffcol.rgb *= vertex_color.rgb; #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - if (diffcol.a < minimum_alpha) - { - discard; - } + if (diffcol.a < minimum_alpha) + { + discard; + } #endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 gamma_diff = diffcol.rgb; + vec3 gamma_diff = diffcol.rgb; #endif #if HAS_SPECULAR_MAP - vec4 spec = texture2D(specularMap, vary_texcoord2.xy); - spec.rgb *= specular_color.rgb; + vec4 spec = texture2D(specularMap, vary_texcoord2.xy); + spec.rgb *= specular_color.rgb; #else - vec4 spec = vec4(specular_color.rgb, 1.0); + vec4 spec = vec4(specular_color.rgb, 1.0); #endif #if HAS_NORMAL_MAP - vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); + vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); - norm.xyz = norm.xyz * 2 - 1; + norm.xyz = norm.xyz * 2 - 1; - vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2)); + vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2)); #else - vec4 norm = vec4(0,0,0,1.0); - vec3 tnorm = vary_normal; + vec4 norm = vec4(0,0,0,1.0); + vec3 tnorm = vary_normal; #endif norm.xyz = tnorm; norm.xyz = normalize(norm.xyz); - vec2 abnormal = encode_normal(norm.xyz); - norm.xyz = decode_normal(abnormal.xy); + vec2 abnormal = encode_normal(norm.xyz); + norm.xyz = decode_normal(abnormal.xy); - vec4 final_color = diffcol; - + vec4 final_color = diffcol; + #if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = emissive_brightness; + final_color.a = emissive_brightness; #else - final_color.a = max(final_color.a, emissive_brightness); + final_color.a = max(final_color.a, emissive_brightness); #endif - vec4 final_specular = spec; + vec4 final_specular = spec; #if HAS_SPECULAR_MAP - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); - final_specular.a = specular_color.a * norm.a; + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); + final_specular.a = specular_color.a * norm.a; #else - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); - final_specular.a = specular_color.a; + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); + final_specular.a = specular_color.a; #endif - + #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - //forward rendering, output just lit RGBA - vec3 pos = vary_position; + //forward rendering, output just lit RGBA + vec3 pos = vary_position; #if HAS_SUN_SHADOW - float shadow = 0.0; - - vec4 spos = vec4(pos,1.0); - - if (spos.z > -shadow_clip.w) - { - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadow(shadowMap0, lpos)*w; - weight += w; - } - - - shadow /= weight; - } - else - { - shadow = 1.0; - } + float shadow = 0.0; + + vec4 spos = vec4(pos,1.0); + + if (spos.z > -shadow_clip.w) + { + vec4 lpos; + + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + if (spos.z < near_split.z) + { + lpos = shadow_matrix[3]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadowLegacy(shadowMap3, lpos)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + if (spos.z < near_split.y && spos.z > far_split.z) + { + lpos = shadow_matrix[2]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; + w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + shadow += pcfShadowLegacy(shadowMap2, lpos)*w; + weight += w; + } + + if (spos.z < near_split.x && spos.z > far_split.y) + { + lpos = shadow_matrix[1]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; + w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + shadow += pcfShadowLegacy(shadowMap1, lpos)*w; + weight += w; + } + + if (spos.z > far_split.x) + { + lpos = shadow_matrix[0]*spos; + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadowLegacy(shadowMap0, lpos)*w; + weight += w; + } + + + shadow /= weight; + } + else + { + shadow = 1.0; + } #else - float shadow = 1.0; + float shadow = 1.0; #endif - spec = final_specular; - vec4 diffuse = final_color; - float envIntensity = final_normal.z; + spec = final_specular; + vec4 diffuse = final_color; + float envIntensity = final_normal.z; vec3 col = vec3(0.0f,0.0f,0.0f); - float bloom = 0.0; + float bloom = 0.0; 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)); + calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); + + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float sun_da = dot(norm.xyz, sun_dir.xyz); - float moon_da = dot(norm.xyz, moon_dir.xyz); + float sun_da = dot(norm.xyz, sun_dir.xyz); + float moon_da = dot(norm.xyz, moon_dir.xyz); float final_da = max(sun_da,moon_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); - final_da = pow(final_da, display_gamma); + final_da = min(final_da, 1.0f); + final_da = pow(final_da, display_gamma); - col.rgb = (col * 0.5) + amblit; - - float ambient = min(abs(final_da), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0-ambient); + col.rgb = (col * 0.5) + amblit; + + float ambient = min(abs(final_da), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); - col.rgb *= ambient; + col.rgb *= ambient; - col.rgb = col.rgb + (final_da * sunlit); + col.rgb = col.rgb + (final_da * sunlit); - col.rgb *= gamma_diff.rgb; - + col.rgb *= gamma_diff.rgb; + - float glare = 0.0; + float glare = 0.0; - if (spec.a > 0.0) // specular reflection - { - // the old infinite-sky shiny reflection - // - + if (spec.a > 0.0) // specular reflection + { + // the old infinite-sky shiny reflection + // + float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; + vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; - glare = max(spec_contrib.r, spec_contrib.g); - glare = max(glare, spec_contrib.b); + glare = max(spec_contrib.r, spec_contrib.g); + glare = max(glare, spec_contrib.b); - col += spec_contrib; - } + col += spec_contrib; + } - col = mix(col.rgb, diffcol.rgb, diffuse.a); + col = mix(col.rgb, diffcol.rgb, diffuse.a); - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - - vec3 refcol = textureCube(environmentMap, env_vec).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); + col = mix(col.rgb, refcol, + envIntensity); - float cur_glare = max(refcol.r, refcol.g); - cur_glare = max(cur_glare, refcol.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; - } + float cur_glare = max(refcol.r, refcol.g); + cur_glare = max(cur_glare, refcol.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; + } - col = atmosFragLighting(col, additive, atten); + col = atmosFragLighting(col, additive, atten); - vec3 npos = normalize(-pos.xyz); - - vec3 light = vec3(0,0,0); + 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_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) - col.rgb += light.rgb; + col.rgb += light.rgb; - glare = min(glare, 1.0); - float al = max(diffcol.a,glare)*vertex_color.a; + glare = min(glare, 1.0); + float al = max(diffcol.a,glare)*vertex_color.a; - col = scaleSoftClipFrag(col); + col = scaleSoftClipFrag(col); #ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); - col.rgb = temp.rgb; - al = temp.a; + vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); + col.rgb = temp.rgb; + al = temp.a; #endif - frag_color.rgb = col.rgb; - frag_color.a = al; + frag_color.rgb = col.rgb; + frag_color.a = al; #else - frag_data[0] = final_color; - frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. - frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. + frag_data[0] = final_color; + frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. + frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index d1ac19270d..e8eef9b94b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -59,18 +59,7 @@ uniform mat4 inv_proj; vec3 decode_normal (vec2 enc); -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index b3dcd90d98..7438fac8fc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -123,19 +123,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) return ret; } - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 13b803e03e..8e756c37bf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -58,18 +58,7 @@ uniform vec4 viewport; vec3 decode_normal (vec2 enc); -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = (pos_screen.xy-viewport.xy)*2.0; - sc /= viewport.zw; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl new file mode 100644 index 0000000000..ae5cb7cbc1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -0,0 +1,191 @@ +/** + * @file class1/deferred/shadowUtil.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 sampler2DRect normalMap; +uniform sampler2DRect depthMap; +uniform sampler2D noiseMap; +uniform sampler2DShadow shadowMap0; +uniform sampler2DShadow shadowMap1; +uniform sampler2DShadow shadowMap2; +uniform sampler2DShadow shadowMap3; +uniform sampler2DShadow shadowMap4; +uniform sampler2DShadow shadowMap5; + +uniform float ssao_radius; +uniform float ssao_max_radius; +uniform float ssao_factor; +uniform float ssao_factor_inv; + +uniform vec3 sun_dir; +uniform vec3 moon_dir; +uniform vec2 shadow_res; +uniform vec2 proj_shadow_res; +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform float shadow_bias; + +uniform float spot_shadow_bias; +uniform float spot_shadow_offset; + +uniform mat4 inv_proj; +uniform vec2 screen_res; + +vec3 decode_normal(vec2 enc); + +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) +{ + stc.xyz /= stc.w; + stc.z += shadow_bias; + + stc.x = floor(stc.x*pos_screen.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + return shadow*0.2; +} + +float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) +{ + stc.xyz /= stc.w; + stc.z += spot_shadow_bias * bias_scale; + stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + + vec2 off = 1.0/proj_shadow_res; + off.y *= 1.5; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; + return shadow*0.2; +} + +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) +{ + float dp_sun = max(0.0, dot(sun_dir.xyz, norm)); + float dp_moon = max(0.0, dot(moon_dir.xyz, norm)); + float dp_directional_light = max(dp_sun,dp_moon); + dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); + + vec3 light_dir = (dp_moon > dp_sun) ? moon_dir : sun_dir; + vec3 offset = light_dir * (1.0-dp_directional_light); + vec3 shadow_pos = pos.xyz + (offset * shadow_bias); + + float shadow = 0.0f; + vec4 spos = vec4(shadow_pos,1.0); + if (spos.z > -shadow_clip.w) + { + vec4 lpos; + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + if (spos.z < near_split.z) + { + lpos = shadow_matrix[3]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos, 0.5, pos_screen)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + if (spos.z < near_split.y && spos.z > far_split.z) + { + lpos = shadow_matrix[2]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; + w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap2, lpos, 0.75, pos_screen)*w; + weight += w; + } + + if (spos.z < near_split.x && spos.z > far_split.y) + { + lpos = shadow_matrix[1]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; + w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + shadow += pcfShadow(shadowMap1, lpos, 0.88, pos_screen)*w; + weight += w; + } + + if (spos.z > far_split.x) + { + lpos = shadow_matrix[0]*spos; + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; + weight += w; + } + + shadow /= weight; + } + return shadow; +} + +float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) +{ + float shadow = 0.0f; + pos += norm * spot_shadow_offset; + + vec4 spos = vec4(pos,1.0); + if (spos.z > -shadow_clip.w) + { + vec4 lpos; + + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + { + lpos = shadow_matrix[4 + index]*spos; + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + + shadow += pcfSpotShadow((index == 0) ? shadowMap4 : shadowMap5, lpos, 0.8, spos.xy)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + shadow /= weight; + } + return shadow; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 2ba766a0c4..0de38a3d62 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -86,18 +86,14 @@ vec4 getPosition_d(vec2 pos_screen, float depth) return pos; } -vec4 getPosition(vec2 pos_screen) -{ //get position in screen space (world units) given window coordinate and depth map - float depth = texture2DRect(depthMap, pos_screen.xy).a; - return getPosition_d(pos_screen, depth); -} - +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +vec4 getPosition(vec2 pos_screen); void main() { vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPosition_d(tc, depth).xyz; + vec3 pos = getPositionWithDepth(tc, depth).xyz; vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; norm.xyz = decode_normal(norm.xy); // unpack norm @@ -107,14 +103,14 @@ void main() float da = max(da_sun, da_moon); float final_da = clamp(da, 0.0, 1.0); - final_da = pow(final_da, global_gamma); + final_da = pow(final_da, global_gamma + 0.3); vec4 diffuse = texture2DRect(diffuseRect, tc); - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - vec3 col; - float bloom = 0.0; - { + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); + vec3 col; + float bloom = 0.0; + { vec3 sunlit; vec3 amblit; vec3 additive; @@ -162,14 +158,14 @@ void main() col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); } - #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); - col = fogged.rgb; - bloom = fogged.a; - #endif - } + #ifdef WATER_FOG + vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); + col = fogged.rgb; + bloom = fogged.a; + #endif + } - frag_color.rgb = col.rgb; - frag_color.a = bloom; + frag_color.rgb = col.rgb; + frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 1abdd4af33..22488944cd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -121,19 +121,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) return ret; } - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 403df87853..6d65ee2add 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -41,82 +41,15 @@ uniform sampler2D noiseMap; // Inputs -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; - VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; vec3 decode_normal (vec2 enc); - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -//calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm) -{ - float ret = 1.0; - - vec2 kern[8]; - // exponentially (^2) distant occlusion samples spread around origin - kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; - kern[1] = vec2(1.0, 0.0) * 0.250*0.250; - kern[2] = vec2(0.0, 1.0) * 0.375*0.375; - kern[3] = vec2(0.0, -1.0) * 0.500*0.500; - kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; - kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; - kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; - kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; - - vec2 pos_screen = vary_fragcoord.xy; - vec3 pos_world = pos.xyz; - vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; - - float angle_hidden = 0.0; - int points = 0; - - float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); - - // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations unrolling?) - for (int i = 0; i < 8; i++) - { - vec2 samppos_screen = pos_screen + scale * reflect(kern[i], noise_reflect); - vec3 samppos_world = getPosition(samppos_screen).xyz; - - vec3 diff = pos_world - samppos_world; - float dist2 = dot(diff, diff); - - // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area - // --> solid angle shrinking by the square of distance - //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 - //(k should vary inversely with # of samples, but this is taken care of later) - - angle_hidden = angle_hidden + float(dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) * min(1.0/dist2, ssao_factor_inv); - - // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" - points = points + int(diff.z > -1.0); - } - - angle_hidden = min(ssao_factor*angle_hidden/float(points), 1.0); - - ret = (1.0 - (float(points != 0) * angle_hidden)); - - return min(ret, 1.0); -} +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); void main() { @@ -124,13 +57,11 @@ void main() //try doing an unproject here - vec4 pos = getPosition(pos_screen); - - vec3 norm = texture2DRect(normalMap, pos_screen).xyz; - norm = decode_normal(norm.xy); + vec4 pos = getPosition(pos_screen); + vec3 norm = getNorm(pos_screen); - frag_color[0] = 1.0; - frag_color[1] = calcAmbientOcclusion(pos, norm); - frag_color[2] = 1.0; - frag_color[3] = 1.0; + frag_color.r = 1.0; + frag_color.g = calcAmbientOcclusion(pos, norm, pos_screen); + frag_color.b = 1.0; + frag_color.a = 1.0; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 0a8981a102..1c5d3901f5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -122,19 +122,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) return ret; } - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 9de2741725..1b0a1b5d84 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -85,24 +85,8 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec4 getPosition(vec2 pos_screen) -{ //get position in screen space (world units) given window coordinate and depth map - float depth = texture2DRect(depthMap, pos_screen.xy).r; - return getPosition_d(pos_screen, depth); -} - +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +vec4 getPosition(vec2 pos_screen); #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); @@ -110,19 +94,19 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); void main() { - vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPosition_d(tc, depth).xyz; - vec4 norm = texture2DRect(normalMap, tc); - float envIntensity = norm.z; - norm.xyz = decode_normal(norm.xy); // unpack norm - - float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); + vec2 tc = vary_fragcoord.xy; + float depth = texture2DRect(depthMap, tc.xy).r; + vec4 pos = getPositionWithDepth(tc, depth); + vec4 norm = texture2DRect(normalMap, tc); + float envIntensity = norm.z; + norm.xyz = decode_normal(norm.xy); // unpack norm + + float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); float da_moon = dot(norm.xyz, normalize(moon_dir.xyz)); float da = max(da_sun, da_moon); da = clamp(da, 0.0, 1.0); - da = pow(da, global_gamma); + da = pow(da, global_gamma + 0.3); vec4 diffuse = texture2DRect(diffuseRect, tc); @@ -132,7 +116,7 @@ void main() vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; - scol_ambocc = pow(scol_ambocc, vec2(global_gamma)); + scol_ambocc = pow(scol_ambocc, vec2(global_gamma + 0.3)); float scol = max(scol_ambocc.r, diffuse.a); float ambocc = scol_ambocc.g; diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index d97bd936d9..36854b0e66 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -122,19 +122,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) return ret; } - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index f2d04c95fe..5f8f3114a1 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -68,22 +68,13 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -vec3 decode_normal (vec2 enc); +vec3 getNorm(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen); -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen); +float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen); -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) +float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { stc.xyz /= stc.w; stc.z += shadow_bias; @@ -102,7 +93,7 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) return shadow*0.2; } -float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) +float pcfSpotShadowLegacy(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { stc.xyz /= stc.w; stc.z += spot_shadow_bias*scl; @@ -128,10 +119,8 @@ void main() //try doing an unproject here - vec4 pos = getPosition(pos_screen); - - vec3 norm = texture2DRect(normalMap, pos_screen).xyz; - norm = decode_normal(norm.xy); // unpack norm + vec4 pos = getPosition(pos_screen); + vec3 norm = getNorm(pos_screen); /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { @@ -174,7 +163,7 @@ void main() float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen)*w; + shadow += pcfShadowLegacy(shadowMap3, lpos, 0.25, pos_screen)*w; weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } @@ -186,7 +175,7 @@ void main() float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen)*w; + shadow += pcfShadowLegacy(shadowMap2, lpos, 0.5, pos_screen)*w; weight += w; } @@ -197,7 +186,7 @@ void main() float w = 1.0; w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen)*w; + shadow += pcfShadowLegacy(shadowMap1, lpos, 0.75, pos_screen)*w; weight += w; } @@ -208,7 +197,7 @@ void main() float w = 1.0; w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; + shadow += pcfShadowLegacy(shadowMap0, lpos, 1.0, pos_screen)*w; weight += w; } @@ -242,11 +231,11 @@ void main() //spotlight shadow 1 vec4 lpos = shadow_matrix[4]*spos; - frag_color[2] = pcfSpotShadow(shadowMap4, lpos, 0.8, pos_screen); + frag_color[2] = pcfSpotShadowLegacy(shadowMap4, lpos, 0.8, pos_screen); //spotlight shadow 2 lpos = shadow_matrix[5]*spos; - frag_color[3] = pcfSpotShadow(shadowMap5, lpos, 0.8, pos_screen); + frag_color[3] = pcfSpotShadowLegacy(shadowMap5, lpos, 0.8, pos_screen); //frag_color.rgb = pos.xyz; //frag_color.b = shadow; diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index fd3256e9c8..10ef1785da 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -1,5 +1,5 @@ /** - * @file sunLightSSAOF.glsl + * @file class2/deferred/sunLightSSAOF.glsl * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. @@ -42,110 +42,33 @@ uniform sampler2DShadow shadowMap2; uniform sampler2DShadow shadowMap3; uniform sampler2DShadow shadowMap4; uniform sampler2DShadow shadowMap5; -uniform sampler2D noiseMap; - - -// Inputs -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; uniform vec2 proj_shadow_res; -uniform vec3 sun_dir; -uniform vec3 moon_dir; +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; uniform vec2 shadow_res; - uniform float shadow_bias; uniform float shadow_offset; - uniform float spot_shadow_bias; uniform float spot_shadow_offset; -vec3 decode_normal (vec2 enc); - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec2 getKern(int i) -{ - vec2 kern[8]; - // exponentially (^2) distant occlusion samples spread around origin - kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; - kern[1] = vec2(1.0, 0.0) * 0.250*0.250; - kern[2] = vec2(0.0, 1.0) * 0.375*0.375; - kern[3] = vec2(0.0, -1.0) * 0.500*0.500; - kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; - kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; - kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; - kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; - - return kern[i]; -} +uniform vec3 sun_dir; +uniform vec3 moon_dir; -//calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm) -{ - float ret = 1.0; +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); - vec2 pos_screen = vary_fragcoord.xy; - vec3 pos_world = pos.xyz; - vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; - - float angle_hidden = 0.0; - float points = 0; - - float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); - - // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) - for (int i = 0; i < 8; i++) - { - vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); - vec3 samppos_world = getPosition(samppos_screen).xyz; - - vec3 diff = pos_world - samppos_world; - float dist2 = dot(diff, diff); - - // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area - // --> solid angle shrinking by the square of distance - //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 - //(k should vary inversely with # of samples, but this is taken care of later) - - float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; - angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); - - // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" - float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; - points = points + diffz_val; - } - - angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); - - float points_val = (points > 0.0) ? 1.0 : 0.0; - ret = (1.0 - (points_val * angle_hidden)); +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen); +float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen); - ret = max(ret, 0.0); - return min(ret, 1.0); -} -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) +float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { stc.xyz /= stc.w; stc.z += shadow_bias; @@ -163,7 +86,7 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) return shadow*0.2; } -float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) +float pcfSpotShadowLegacy(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) { stc.xyz /= stc.w; stc.z += spot_shadow_bias*scl; @@ -189,10 +112,8 @@ void main() //try doing an unproject here - vec4 pos = getPosition(pos_screen); - - vec3 norm = texture2DRect(normalMap, pos_screen).xyz; - norm = decode_normal(norm.xy); // unpack norm + vec4 pos = getPosition(pos_screen); + vec3 norm = getNorm(pos_screen); /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { @@ -235,7 +156,7 @@ void main() float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen)*w; + shadow += pcfShadowLegacy(shadowMap3, lpos, 0.25, pos_screen)*w; weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } @@ -247,7 +168,7 @@ void main() float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen)*w; + shadow += pcfShadowLegacy(shadowMap2, lpos, 0.5, pos_screen)*w; weight += w; } @@ -258,7 +179,7 @@ void main() float w = 1.0; w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen)*w; + shadow += pcfShadowLegacy(shadowMap1, lpos, 0.75, pos_screen)*w; weight += w; } @@ -269,7 +190,7 @@ void main() float w = 1.0; w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; + shadow += pcfShadowLegacy(shadowMap0, lpos, 1.0, pos_screen)*w; weight += w; } @@ -297,7 +218,7 @@ void main() } frag_color[0] = shadow; - frag_color[1] = calcAmbientOcclusion(pos, norm); + frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); -- cgit v1.2.3 From 07bff3129adaabb90f09b71fa65c8be0c3ecef5d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 19 Dec 2018 14:59:19 -0800 Subject: Add new shaders for advanced atmo SH env lighting calcs. --- .../app_settings/shaders/class1/deferred/cofF.glsl | 9 +- .../shaders/class3/deferred/deferredUtil.glsl | 75 ++++++++ .../class3/deferred/depthToShadowVolumeG.glsl | 202 +++++++++++++++++++++ .../shaders/class3/deferred/gatherSkyShF.glsl | 70 +++++++ .../shaders/class3/deferred/gatherSkyShV.glsl | 40 ++++ .../shaders/class3/deferred/genSkyShF.glsl | 112 ++++++++++++ .../shaders/class3/deferred/genSkyShV.glsl | 37 ++++ .../shaders/class3/deferred/indirect.glsl | 44 +++++ .../shaders/class3/deferred/lightUtil.glsl | 117 ++++++++++++ .../shaders/class3/deferred/pointShadowBlurF.glsl | 37 ++++ .../shaders/class3/deferred/shVisF.glsl | 73 ++++++++ .../shaders/class3/deferred/shVisV.glsl | 33 ++++ .../shaders/class3/deferred/shadowAlphaBlendF.glsl | 58 ++++++ .../shaders/class3/deferred/shadowAlphaBlendV.glsl | 66 +++++++ .../shaders/class3/deferred/shadowAlphaMaskF.glsl | 74 ++++++++ .../shaders/class3/deferred/shadowAlphaMaskV.glsl | 67 +++++++ .../shaders/class3/deferred/shadowCubeV.glsl | 50 +++++ .../shaders/class3/deferred/shadowF.glsl | 49 +++++ .../shaders/class3/deferred/shadowUtil.glsl | 157 ++++++++++++++++ .../shaders/class3/deferred/shadowV.glsl | 62 +++++++ .../shaders/class3/deferred/softenLightF.glsl | 4 +- 21 files changed, 1425 insertions(+), 11 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/gatherSkyShF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/gatherSkyShV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/genSkyShV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/indirect.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/lightUtil.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/pointShadowBlurF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/shVisF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/shVisV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowUtil.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl index fef1c5a584..380d382020 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl @@ -50,14 +50,7 @@ uniform vec2 screen_res; VARYING vec2 vary_fragcoord; -float getDepth(vec2 pos_screen) -{ - float z = texture2DRect(depthMap, pos_screen.xy).r; - z = z*2.0-1.0; - vec4 ndc = vec4(0.0, 0.0, z, 1.0); - vec4 p = inv_proj*ndc; - return p.z/p.w; -} +float getDepth(vec2 pos_screen); float calc_cof(float depth) { diff --git a/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl new file mode 100644 index 0000000000..cccd01e0d7 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl @@ -0,0 +1,75 @@ +/** + * @file class3/deferred/deferredUtil.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 sampler2DRect normalMap; +uniform sampler2DRect depthMap; + +uniform mat4 inv_proj; +uniform vec2 screen_res; + +vec3 decode_normal(vec2 enc); + +vec2 getScreenCoordinate(vec2 screenpos) +{ + vec2 sc = screenpos.xy * 2.0; + if (screen_res.x > 0 && screen_res.y > 0) + { + sc /= screen_res; + } + return sc - vec2(1.0, 1.0); +} + +vec3 getNorm(vec2 screenpos) +{ + vec2 enc_norm = texture2DRect(normalMap, screenpos.xy).xy; + return decode_normal(enc_norm); +} + +float getDepth(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen).r; + return depth; +} + +vec4 getPosition(vec2 pos_screen) +{ + float depth = getDepth(pos_screen); + vec2 sc = getScreenCoordinate(pos_screen); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec4 getPositionWithDepth(vec2 pos_screen, float depth) +{ + vec2 sc = getScreenCoordinate(pos_screen); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl b/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl new file mode 100644 index 0000000000..5734e2abb2 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl @@ -0,0 +1,202 @@ +/** + * @file depthToShadowVolumeG.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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$ + */ +#extension GL_ARB_geometry_shader4 : enable +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +layout (triangles) in; +layout (triangle_strip, max_vertices = 128) out; + +uniform sampler2DRect depthMap; +uniform mat4 shadowMatrix[6]; +uniform vec4 lightpos; + +VARYING vec2 vary_texcoord0; + +out vec3 to_vec; + +void cross_products(out vec4 ns[3], int a, int b, int c) +{ + ns[0] = cross(gl_PositionIn[b].xyz - gl_PositionIn[a].xyz, gl_PositionIn[c].xyz - gl_PositionIn[a].xyz); + ns[1] = cross(gl_PositionIn[c].xyz - gl_PositionIn[b].xyz, gl_PositionIn[a].xyz - gl_PositionIn[b].xyz); + ns[2] = cross(gl_PositionIn[a].xyz - gl_PositionIn[c].xyz, gl_PositionIn[b].xyz - gl_PositionIn[c].xyz); +} + +vec3 getLightDirection(vec4 lightpos, vec3 pos) +{ + + vec3 lightdir = lightpos.xyz - lightpos.w * pos; + return lightdir; +} + +void emitTri(vec4 v[3]) +{ + gl_Position = proj_matrix * v[0]; + EmitVertex(); + + gl_Position = proj_matrix * v[1]; + EmitVertex(); + + gl_Position = proj_matrix * v[2]; + EmitVertex(); + + EndPrimitive(); +} + +void emitQuad(vec4 v[4] +{ + // Emit a quad as a triangle strip. + gl_Position = proj_matrix*v[0]; + EmitVertex(); + + gl_Position = proj_matrix*v[1]; + EmitVertex(); + + gl_Position = proj_matrix*v[2]; + EmitVertex(); + + gl_Position = proj_matrix*v[3]; + EmitVertex(); + + EndPrimitive(); +} + +void emitPrimitives(int layer) +{ + int i = layer; + gl_Layer = i; + + vec4 depth1 = vec4(texture2DRect(depthMap, tc0).rg, texture2DRect(depthMap, tc1).rg)); + vec3 depth2 = vec4(texture2DRect(depthMap, tc2).rg, texture2DRect(depthMap, tc3).rg)); + vec3 depth3 = vec4(texture2DRect(depthMap, tc4).rg, texture2DRect(depthMap, tc5).rg)); + vec3 depth4 = vec4(texture2DRect(depthMap, tc6).rg, texture2DRect(depthMap, tc7).rg)); + + depth1 = min(depth1, depth2); + depth1 = min(depth1, depth3); + depth1 = min(depth1, depth4); + + vec2 depth = min(depth1.xy, depth1.zw); + + int side = sqrt(gl_VerticesIn); + + for (int j = 0; j < side; j++) + { + for (int k = 0; k < side; ++k) + { + vec3 pos = gl_PositionIn[(j * side) + k].xyz; + vec4 v = shadowMatrix[i] * vec4(pos, 1.0); + gl_Position = v; + to_vec = pos - light_position.xyz * depth; + EmitVertex(); + } + + EndPrimitive(); + } + + vec3 norms[3]; // Normals + vec3 lightdir3]; // Directions toward light + + vec4 v[4]; // Temporary vertices + + vec4 or_pos[3] = + { // Triangle oriented toward light source + gl_PositionIn[0], + gl_PositionIn[2], + gl_PositionIn[4] + }; + + // Compute normal at each vertex. + cross_products(n, 0, 2, 4); + + // Compute direction from vertices to light. + lightdir[0] = getLightDirection(lightpos, gl_PositionIn[0].xyz); + lightdir[1] = getLightDirection(lightpos, gl_PositionIn[2].xyz); + lightdir[2] = getLightDirection(lightpos, gl_PositionIn[4].xyz); + + // Check if the main triangle faces the light. + bool faces_light = true; + if (!(dot(ns[0],d[0]) > 0 + |dot(ns[1],d[1]) > 0 + |dot(ns[2],d[2]) > 0)) + { + // Flip vertex winding order in or_pos. + or_pos[1] = gl_PositionIn[4]; + or_pos[2] = gl_PositionIn[2]; + faces_light = false; + } + + // Near cap: simply render triangle. + emitTri(or_pos); + + // Far cap: extrude positions to infinity. + v[0] =vec4(lightpos.w * or_pos[0].xyz - lightpos.xyz,0); + v[1] =vec4(lightpos.w * or_pos[2].xyz - lightpos.xyz,0); + v[2] =vec4(lightpos.w * or_pos[1].xyz - lightpos.xyz,0); + + emitTri(v); + + // Loop over all edges and extrude if needed. + for ( int i=0; i<3; i++ ) + { + // Compute indices of neighbor triangle. + int v0 = i*2; + int nb = (i*2+1); + int v1 = (i*2+2) % 6; + cross_products(n, v0, nb, v1); + + // Compute direction to light, again as above. + d[0] =lightpos.xyz-lightpos.w*gl_PositionIn[v0].xyz; + d[1] =lightpos.xyz-lightpos.w*gl_PositionIn[nb].xyz; + d[2] =lightpos.xyz-lightpos.w*gl_PositionIn[v1].xyz; + + bool is_parallel = gl_PositionIn[nb].w < 1e-5; + + // Extrude the edge if it does not have a + // neighbor, or if it's a possible silhouette. + if (is_parallel || + ( faces_light != (dot(ns[0],d[0])>0 || + dot(ns[1],d[1])>0 || + dot(ns[2],d[2])>0) )) + { + // Make sure sides are oriented correctly. + int i0 = faces_light ? v0 : v1; + int i1 = faces_light ? v1 : v0; + + v[0] = gl_PositionIn[i0]; + v[1] = vec4(lightpos.w*gl_PositionIn[i0].xyz - lightpos.xyz, 0); + v[2] = gl_PositionIn[i1]; + v[3] = vec4(lightpos.w*gl_PositionIn[i1].xyz - lightpos.xyz, 0); + + emitQuad(v); + } + } +} + +void main() +{ + // Output + emitPrimitives(0); +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShF.glsl b/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShF.glsl new file mode 100644 index 0000000000..34d26cddea --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShF.glsl @@ -0,0 +1,70 @@ +/** + * @file class3/deferred/gatherSkyShF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif + +VARYING vec2 vary_frag; + +uniform vec2 screen_res; +uniform sampler2D sh_input_r; +uniform sampler2D sh_input_g; +uniform sampler2D sh_input_b; + +void main() +{ + vec2 offset = vec2(2.0) / screen_res; + + vec4 r = vec4(0); + vec4 g = vec4(0); + vec4 b = vec4(0); + + vec2 tc = vary_frag * 2.0; + + r += texture2D(sh_input_r, tc + vec2(0, 0)); + r += texture2D(sh_input_r, tc + vec2(offset.x, 0)); + r += texture2D(sh_input_r, tc + vec2(0, offset.y)); + r += texture2D(sh_input_r, tc + vec2(offset.x, offset.y)); + r /= 4.0f; + + g += texture2D(sh_input_g, tc + vec2(0, 0)); + g += texture2D(sh_input_g, tc + vec2(offset.x, 0)); + g += texture2D(sh_input_g, tc + vec2(0, offset.y)); + g += texture2D(sh_input_g, tc + vec2(offset.x, offset.y)); + g /= 4.0f; + + b += texture2D(sh_input_b, tc + vec2(0, 0)); + b += texture2D(sh_input_b, tc + vec2(offset.x, 0)); + b += texture2D(sh_input_b, tc + vec2(0, offset.y)); + b += texture2D(sh_input_b, tc + vec2(offset.x, offset.y)); + b /= 4.0f; + + frag_data[0] = r; + frag_data[1] = g; + frag_data[2] = b; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShV.glsl b/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShV.glsl new file mode 100644 index 0000000000..337c8a50fe --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShV.glsl @@ -0,0 +1,40 @@ +/** + * @file gatherSkyShV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +VARYING vec2 vary_frag; +uniform vec2 screen_res; + +void main() +{ + // pass through untransformed fullscreen pos + float oo_divisor = screen_res.x / 64.0; + vec3 pos = (position.xyz * oo_divisor) + vec3(oo_divisor - 1, oo_divisor - 1, 0); + gl_Position = vec4(pos.xyz, 1.0); + vary_frag = texcoord0 * oo_divisor; +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl b/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl new file mode 100644 index 0000000000..c02e6d1e57 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl @@ -0,0 +1,112 @@ +/** + * @file class3/deferred/genSkyShF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif + +VARYING vec2 vary_frag; + +uniform vec3 sun_dir; + +uniform sampler2D transmittance_texture; +uniform sampler3D scattering_texture; +uniform sampler3D single_mie_scattering_texture; +uniform sampler2D irradiance_texture; +uniform vec4 gamma; + +vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); + +vec3 calcDirection(vec2 tc) +{ + float phi = tc.y * 2.0 * 3.14159265; + float cosTheta = sqrt(1.0 - tc.x); + float sinTheta = sqrt(1.0 - cosTheta * cosTheta); + return vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta); +} + +// reverse mapping above to convert a hemisphere direction into phi/theta values +void getPhiAndThetaFromDirection(vec3 dir, out float phi, out float theta) +{ + float sin_theta; + float cos_theta; + cos_theta = dir.z; + theta = acos(cos_theta); + sin_theta = sin(theta); + phi = abs(sin_theta) > 0.0001 ? acos(dir.x / sin_theta) : 1.0; +} + +// reverse mapping above to convert a hemisphere direction into an SH texture sample pos +vec2 calcShUvFromDirection(vec3 dir) +{ + vec2 uv; + float phi; + float theta; + getPhiAndThetaFromDirection(dir, phi, theta); + uv.y = phi / 2.0 * 3.14159265; + uv.x = theta / 2.0 * 3.14159265; + return uv; +} + +void projectToL1(vec3 n, vec3 c, vec4 basis, out vec4 coeffs[3]) +{ + coeffs[0] = vec4(basis.x, n * basis.yzw * c.r); + coeffs[1] = vec4(basis.x, n * basis.yzw * c.g); + coeffs[2] = vec4(basis.x, n * basis.yzw * c.b); +} + +void main() +{ + float Y00 = sqrt(1.0 / 3.14159265) * 0.5; + float Y1x = sqrt(3.0 / 3.14159265) * 0.5; + float Y1y = Y1x; + float Y1z = Y1x; + + vec4 L1 = vec4(Y00, Y1x, Y1y, Y1z); + + vec3 view_direction = calcDirection(vary_frag); + vec3 sun_direction = normalize(sun_dir); + vec3 cam_pos = vec3(0, 0, 6360); + + vec3 transmittance; + vec3 radiance = GetSkyLuminance(cam_pos, view_direction, 0.0f, sun_direction, transmittance); + + vec3 color = vec3(1.0) - exp(-radiance * 0.0001); + + color = pow(color, vec3(1.0/2.2)); + + vec4 coeffs[3]; + coeffs[0] = vec4(0); + coeffs[1] = vec4(0); + coeffs[2] = vec4(0); + + projectToL1(view_direction, color.rgb, L1, coeffs); + + frag_data[0] = coeffs[0]; + frag_data[1] = coeffs[1]; + frag_data[2] = coeffs[2]; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/genSkyShV.glsl b/indra/newview/app_settings/shaders/class3/deferred/genSkyShV.glsl new file mode 100644 index 0000000000..b466883dc7 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/genSkyShV.glsl @@ -0,0 +1,37 @@ +/** + * @file genSkyShV.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +VARYING vec2 vary_frag; + +void main() +{ + // pass through untransformed fullscreen pos + gl_Position = vec4(position.xyz, 1.0); + vary_frag = texcoord0; +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/indirect.glsl b/indra/newview/app_settings/shaders/class3/deferred/indirect.glsl new file mode 100644 index 0000000000..33c5667cae --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/indirect.glsl @@ -0,0 +1,44 @@ +/** + * @file class3/deferred/indirect.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +uniform sampler2D sh_input_r; +uniform sampler2D sh_input_g; +uniform sampler2D sh_input_b; + +vec3 GetIndirect(vec3 norm) +{ + vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); + vec4 l1r = texture2D(sh_input_r, vec2(0,0)); + vec4 l1g = texture2D(sh_input_g, vec2(0,0)); + vec4 l1b = texture2D(sh_input_b, vec2(0,0)); + vec3 indirect = vec3(dot(l1r, l1tap * vec4(1, norm.xyz)), + dot(l1g, l1tap * vec4(1, norm.xyz)), + dot(l1b, l1tap * vec4(1, norm.xyz))); + indirect = clamp(indirect, vec3(0), vec3(1.0)); + return indirect; +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/lightUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/lightUtil.glsl new file mode 100644 index 0000000000..8bb3f07fc6 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/lightUtil.glsl @@ -0,0 +1,117 @@ +/** + * @file lightInfo.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +struct DirectionalLightInfo +{ + vec4 pos; + float depth; + vec4 normal; + vec3 normalizedLightDirection; + vec3 normalizedToLight; + float lightIntensity; + vec3 lightDiffuseColor; + float specExponent; + float shadow; +}; + +struct SpotLightInfo +{ + vec4 pos; + float depth; + vec4 normal; + vec3 normalizedLightDirection; + vec3 normalizedToLight; + float lightIntensity; + float attenuation; + float distanceToLight; + vec3 lightDiffuseColor; + float innerHalfAngleCos; + float outerHalfAngleCos; + float spotExponent; + float specExponent; + float shadow; +}; + +struct PointLightInfo +{ + vec4 pos; + float depth; + vec4 normal; + vec3 normalizedToLight; + float lightIntensity; + float attenuation; + float distanceToLight; + vec3 lightDiffuseColor; + float lightRadius; + float specExponent; + vec3 worldspaceLightDirection; + float shadow; +}; + +float attenuate(float attenuationSelection, float distanceToLight) +{ +// LLRENDER_REVIEW +// sh/could eventually consume attenuation func defined in texture + return (attenuationSelection == 0.0f) ? 1.0f : // none + (attenuationSelection < 1.0f) ? (1.0f / distanceToLight) : // linear atten + (attenuationSelection < 2.0f) ? (1.0f / (distanceToLight*distanceToLight)) // quadratic atten + : (1.0f / (distanceToLight*distanceToLight*distanceToLight)); // cubic atten +} + + +vec3 lightDirectional(struct DirectionalLightInfo dli) +{ + float lightIntensity = dli.lightIntensity; + lightIntensity *= dot(dli.normal.xyz, dli.normalizedLightDirection); + //lightIntensity *= directionalShadowSample(vec4(dli.pos.xyz, 1.0f), dli.depth, dli.directionalShadowMap, dli.directionalShadowMatrix); + return lightIntensity * dli.lightDiffuseColor; +} + + +vec3 lightSpot(struct SpotLightInfo sli) +{ + float penumbraRange = (sli.outerHalfAngleCos - sli.innerHalfAngleCos); + float coneAngleCos = max(dot(sli.normalizedLightDirection, sli.normalizedToLight), 0.0); + float coneAttenFactor = (coneAngleCos <= sli.outerHalfAngleCos) ? 1.0f : pow(smoothstep(1,0, sli.outerHalfAngleCos / penumbraRange), sli.spotExponent); + float distanceAttenuation = attenuate(sli.attenuation, sli.distanceToLight); + float lightIntensity = sli.lightIntensity; + lightIntensity *= distanceAttenuation; + lightIntensity *= max(dot(sli.normal.xyz, sli.normalizedLightDirection), 0.0); + lightIntensity *= coneAttenFactor; + lightIntensity *= sli.shadow; + return lightIntensity * sli.lightDiffuseColor; +} + +vec3 lightPoint(struct PointLightInfo pli) +{ + float padRadius = pli.lightRadius * 0.1; // distance for which to perform smoothed dropoff past light radius + float distanceAttenuation = attenuate(pli.attenuation, pli.distanceToLight); + float lightIntensity = pli.lightIntensity; + lightIntensity*= distanceAttenuation; + lightIntensity *= clamp((padRadius - pli.distanceToLight + pli.lightRadius) / padRadius, 0.0, 1.0); + lightIntensity *= pli.shadow; + lightIntensity *= max(dot(pli.normal.xyz, pli.normalizedToLight), 0.0); + return lightIntensity * pli.lightDiffuseColor; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointShadowBlurF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointShadowBlurF.glsl new file mode 100644 index 0000000000..ca9ce3a2e1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/pointShadowBlurF.glsl @@ -0,0 +1,37 @@ +/** + * @file pointShadowBlur.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 samplerCube cube_map; + +in vec3 to_vec; + +out vec4 fragColor; + +void main() +{ + vec4 vcol = texture(cube_map, to_vec); + fragColor = vec4(vcol.rgb, 1.0); +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/shVisF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shVisF.glsl new file mode 100644 index 0000000000..c8991f7a18 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shVisF.glsl @@ -0,0 +1,73 @@ +/** + * @file class3/deferred/shVisF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_color; +#else + #define frag_color gl_FragColor +#endif + +///////////////////////////////////////////////////////////////////////// +// Fragment shader for L1 SH debug rendering +///////////////////////////////////////////////////////////////////////// + +uniform sampler2D sh_input_r; +uniform sampler2D sh_input_g; +uniform sampler2D sh_input_b; + +uniform mat3 inv_modelviewprojection; + +VARYING vec4 vary_pos; + +void main(void) +{ + vec2 coord = vary_pos.xy + vec2(0.5,0.5); + + coord.x *= (1.6/0.9); + + if (dot(coord, coord) > 0.25) + { + discard; + } + + vec4 n = vec4(coord*2.0, 0.0, 1); + //n.y = -n.y; + n.z = sqrt(max(1.0-n.x*n.x-n.y*n.y, 0.0)); + //n.xyz = inv_modelviewprojection * n.xyz; + + vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); + vec4 l1r = texture2D(sh_input_r, vec2(0,0)); + vec4 l1g = texture2D(sh_input_g, vec2(0,0)); + vec4 l1b = texture2D(sh_input_b, vec2(0,0)); + vec3 indirect = vec3( + dot(l1r, l1tap * n), + dot(l1g, l1tap * n), + dot(l1b, l1tap * n)); + + //indirect = pow(indirect, vec3(0.45)); + indirect *= 3.0; + + frag_color = vec4(indirect, 1.0); +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shVisV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shVisV.glsl new file mode 100644 index 0000000000..8f32dfde79 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shVisV.glsl @@ -0,0 +1,33 @@ +/** + * @file class3/deferred/shVisV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ +ATTRIBUTE vec3 position; +VARYING vec4 vary_pos; + +void main() +{ + // Output + vary_pos = vec4(position, 1); + gl_Position = vary_pos; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl new file mode 100644 index 0000000000..01599d81c4 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl @@ -0,0 +1,58 @@ +/** + * @file shadowAlphaMaskF.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2D diffuseMap; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING float pos_w; + +VARYING float target_pos_x; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; +VARYING vec3 pos; + +vec4 computeMoments(float depth, float a); + +void main() +{ + float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; + + frag_color = computeMoments(length(pos), float a); + +#if !DEPTH_CLAMP + gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); +#endif +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl new file mode 100644 index 0000000000..3fb2bafca4 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl @@ -0,0 +1,66 @@ +/** + * @file shadowAlphaMaskV.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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 mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; +uniform float shadow_target_width; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec4 diffuse_color; +ATTRIBUTE vec2 texcoord0; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING float target_pos_x; +VARYING vec4 pos; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void passTextureIndex(); + +void main() +{ + //transform vertex + vec4 pre_pos = vec4(position.xyz, 1.0); + vec4 pos = modelview_projection_matrix * pre_pos; + target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + + pos_w = pos.w; + +#if !DEPTH_CLAMP + pos_zd2 = pos.z * 0.5; + + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif + + passTextureIndex(); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + vertex_color = diffuse_color; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl new file mode 100644 index 0000000000..d6ed5b6bb0 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl @@ -0,0 +1,74 @@ +/** + * @file class3/deferred/shadowAlphaMaskF.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2D diffuseMap; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING float pos_w; + +VARYING float target_pos_x; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +vec4 getPosition(vec2 screen_coord); +vec4 computeMoments(float depth, float a); + +void main() +{ + vec4 pos = getPosition(vary_texcoord0.xy); + + float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; + + if (alpha < 0.05) // treat as totally transparent + { + discard; + } + + if (alpha < 0.88) // treat as semi-transparent + { + if (fract(0.5*floor(target_pos_x / pos_w )) < 0.25) + { + discard; + } + } + + frag_color = computeMoments(length(pos.xyz), alpha); + +#if !DEPTH_CLAMP + gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); +#endif + +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl new file mode 100644 index 0000000000..bc7fe003f2 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl @@ -0,0 +1,67 @@ +/** + * @file class3/deferred/shadowAlphaMaskV.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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 mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; +uniform float shadow_target_width; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec4 diffuse_color; +ATTRIBUTE vec2 texcoord0; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING vec4 pos; +VARYING float target_pos_x; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void passTextureIndex(); + +void main() +{ + //transform vertex + vec4 pre_pos = vec4(position.xyz, 1.0); + + pos = modelview_projection_matrix * pre_pos; + + target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + +#if !DEPTH_CLAMP + pos_zd2 = pos.z * 0.5; + + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif + + passTextureIndex(); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + + vertex_color = diffuse_color; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl new file mode 100644 index 0000000000..923de09ada --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl @@ -0,0 +1,50 @@ +/** + * @file class3/deferred/shadowCubeV.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + +#if !DEPTH_CLAMP +VARYING vec4 post_pos; +#endif + +uniform vec3 box_center; +uniform vec3 box_size; + +void main() +{ + //transform vertex + vec3 p = position*box_size+box_center; + vec4 pos = modelview_projection_matrix*vec4(p.xyz, 1.0); + +#if !DEPTH_CLAMP + post_pos = pos; + + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl new file mode 100644 index 0000000000..5a6c8728c0 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl @@ -0,0 +1,49 @@ +/** + * @file class3/deferred/shadowF.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2D diffuseMap; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING vec4 pos; +VARYING float target_pos_x; + +vec4 computeMoments(float depth, float a); + +void main() +{ + frag_color = computeMoments(length(pos), 1.0); +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowUtil.glsl new file mode 100644 index 0000000000..2f69a353e8 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowUtil.glsl @@ -0,0 +1,157 @@ +/** + * @file class3/deferred/shadowUtil.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 sampler2D shadowMap0; +uniform sampler2D shadowMap1; +uniform sampler2D shadowMap2; +uniform sampler2D shadowMap3; +uniform sampler2D shadowMap4; +uniform sampler2D shadowMap5; + +uniform vec3 sun_dir; +uniform vec3 moon_dir; +uniform vec2 shadow_res; +uniform vec2 proj_shadow_res; +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform float shadow_bias; + +uniform float spot_shadow_bias; +uniform float spot_shadow_offset; + +float getDepth(vec2 screenpos); +vec3 getNorm(vec2 screenpos); +vec4 getPosition(vec2 pos_screen); + +float ReduceLightBleeding(float p_max, float Amount) +{ + return smoothstep(Amount, 1, p_max); +} + +float ChebyshevUpperBound(vec2 m, float t, float min_v, float Amount) +{ + float p = (t <= m.x) ? 1.0 : 0.0; + + float v = m.y - (m.x*m.x); + v = max(v, min_v); + + float d = t - m.x; + + float p_max = v / (v + d*d); + + p_max = ReduceLightBleeding(p_max, Amount); + + return max(p, p_max); +} + +vec4 computeMoments(float depth, float a) +{ + float m1 = depth; + float dx = dFdx(depth); + float dy = dFdy(depth); + float m2 = m1*m1 + 0.25 * a * (dx*dx + dy*dy); + return vec4(m1, m2, a, max(dx, dy)); +} + +float vsmDirectionalSample(vec4 stc, float depth, sampler2D shadowMap, mat4 shadowMatrix) +{ + vec4 lpos = shadowMatrix * stc; + vec4 moments = texture2D(shadowMap, lpos.xy); + return ChebyshevUpperBound(moments.rg, depth - shadow_bias * 256.0f, 0.125, 0.9); +} + +float vsmSpotSample(vec4 stc, float depth, sampler2D shadowMap, mat4 shadowMatrix) +{ + vec4 lpos = shadowMatrix * stc; + vec4 moments = texture2D(shadowMap, lpos.xy); + lpos.xyz /= lpos.w; + lpos.xy *= 0.5; + lpos.xy += 0.5; + return ChebyshevUpperBound(moments.rg, depth - spot_shadow_bias * 16.0f, 0.125, 0.9); +} + +#if VSM_POINT_SHADOWS +float vsmPointSample(float lightDistance, vec3 lightDirection, samplerCube shadow_cube_map) +{ + vec4 moments = textureCube(shadow_cube_map, light_direction); + return ChebyshevUpperBound(moments.rg, light_distance, 0.01, 0.25); +} +#endif + +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) +{ + if (pos.z < -shadow_clip.w) + { + discard; + } + + float depth = getDepth(pos_screen); + + vec4 spos = vec4(pos,1.0); + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + + float shadow = 0.0f; + float weight = 1.0; + + if (spos.z < near_split.z) + { + shadow += vsmDirectionalSample(spos, depth, shadowMap3, shadow_matrix[3]); + weight += 1.0f; + } + if (spos.z < near_split.y) + { + shadow += vsmDirectionalSample(spos, depth, shadowMap2, shadow_matrix[2]); + weight += 1.0f; + } + if (spos.z < near_split.x) + { + shadow += vsmDirectionalSample(spos, depth, shadowMap1, shadow_matrix[1]); + weight += 1.0f; + } + if (spos.z > far_split.x) + { + shadow += vsmDirectionalSample(spos, depth, shadowMap0, shadow_matrix[0]); + weight += 1.0f; + } + + shadow /= weight; + + return shadow; +} + +float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) +{ + if (pos.z < -shadow_clip.w) + { + discard; + } + + float depth = getDepth(pos_screen); + + pos += norm * spot_shadow_offset; + return vsmSpotSample(vec4(pos, 1.0), depth, (index == 0) ? shadowMap4 : shadowMap5, shadow_matrix[4 + index]); +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl new file mode 100644 index 0000000000..9a5edaf091 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl @@ -0,0 +1,62 @@ +/** + * @file class3/deferred/shadowV.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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 mat4 modelview_projection_matrix; +uniform float shadow_target_width; +uniform mat4 texture_matrix0; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING vec4 pos; +VARYING float target_pos_x; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void passTextureIndex(); + +void main() +{ + //transform vertex + vec4 pre_pos = vec4(position.xyz, 1.0); + + pos = modelview_projection_matrix * pre_pos; + + target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + +#if !DEPTH_CLAMP + pos_zd2 = pos.z * 0.5; + + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index ecf6858136..b84d3efbaa 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -40,15 +40,13 @@ uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; uniform sampler2D lightFunc; -uniform float blur_size; uniform samplerCube environmentMap; - +uniform float blur_size; uniform float blur_fidelity; // Inputs uniform vec4 morphFactor; uniform vec3 camPosLocal; -uniform vec4 gamma; uniform float cloud_shadow; uniform float max_y; uniform vec4 glow; -- cgit v1.2.3 From 01da53764bebc99fd692b3eb68f8520c6cfa2a97 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 3 Jan 2019 16:21:07 -0800 Subject: Fix per-frag fullbright soft clip convenience funcs to include additive and atten args. --- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 4 ++-- indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 - indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 1b0a1b5d84..c5d317ad37 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -78,7 +78,7 @@ vec3 decode_normal (vec2 enc); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClipFrag(vec3 l); +vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 add, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten); @@ -166,7 +166,7 @@ void main() if (norm.w < 0.5) { col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); - col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col), diffuse.a); + col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col, additive, atten), diffuse.a); } #ifdef WATER_FOG diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index ac7c57747e..143bafc9c9 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -47,7 +47,7 @@ vec3 scaleSoftClip(vec3 light) return scaleSoftClipFrag(light); } -vec3 fullbrightScaleSoftClipFrag(vec3 light) { +vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 add, vec3 atten) { return scaleSoftClipFrag(light.rgb); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index b84d3efbaa..ed06e5a6ac 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -77,7 +77,6 @@ vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); vec3 scaleSoftClipFrag(vec3 c); -vec3 fullbrightScaleSoftClipFrag(vec3 c); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); diff --git a/indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl index 709d9cbc0a..a7d76052bb 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl @@ -43,7 +43,7 @@ vec3 scaleSoftClip(vec3 light) { return scaleSoftClipFrag(light); } -vec3 fullbrightScaleSoftClipFrag(vec3 light) +vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 add, vec3 atten) { return scaleSoftClipFrag(light.rgb); } -- cgit v1.2.3 From 2312efbf3ae09013bc86a2378bed43a743f2df3e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 4 Jan 2019 10:17:09 -0800 Subject: Add new shaders for generating shadows from clouds. Add new class3 shadow shaders for VSM shadows. Add disabled shadow pass in WLSky for using above. --- .../shaders/class1/deferred/cloudShadowF.glsl | 121 +++++++++++++ .../shaders/class1/deferred/cloudShadowV.glsl | 63 +++++++ .../shaders/class1/windlight/cloudShadowF.glsl | 121 +++++++++++++ .../shaders/class1/windlight/cloudShadowV.glsl | 61 +++++++ .../shaders/class3/deferred/attachmentShadowF.glsl | 44 +++++ .../shaders/class3/deferred/attachmentShadowV.glsl | 51 ++++++ .../shaders/class3/deferred/avatarShadowF.glsl | 52 ++++++ .../shaders/class3/deferred/avatarShadowV.glsl | 68 ++++++++ .../shaders/class3/deferred/cloudShadowF.glsl | 114 ++++++++++++ .../shaders/class3/deferred/cloudShadowV.glsl | 63 +++++++ .../shaders/class3/deferred/cloudsF.glsl | 16 +- .../shaders/class3/deferred/softenLightF.glsl | 117 ++++++------- .../shaders/class3/deferred/sunLightF.glsl | 187 +------------------- .../shaders/class3/deferred/sunLightSSAOF.glsl | 192 ++------------------- .../shaders/class3/deferred/treeShadowF.glsl | 59 +++++++ .../shaders/class3/deferred/treeShadowV.glsl | 43 +++++ .../shaders/class3/deferred/underWaterF.glsl | 118 +++++++++++++ .../shaders/class3/deferred/waterF.glsl | 175 +++++++++++++++++++ .../shaders/class3/deferred/waterV.glsl | 95 ++++++++++ .../shaders/class3/windlight/gammaF.glsl | 54 ------ 20 files changed, 1335 insertions(+), 479 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl create mode 100644 indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl create mode 100644 indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl create mode 100644 indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/attachmentShadowF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/treeShadowV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/waterF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/waterV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl new file mode 100644 index 0000000000..fa6926b007 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl @@ -0,0 +1,121 @@ +/** + * @file class3/deferred/cloudsF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2D diffuseMap; + +VARYING vec4 pos; +VARYING float target_pos_x; +VARYING float vary_CloudDensity; +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; + +uniform sampler2D cloud_noise_texture; +uniform sampler2D cloud_noise_texture_next; +uniform float blend_factor; +uniform vec4 cloud_pos_density1; +uniform vec4 cloud_pos_density2; +uniform vec4 sunlight_color; +uniform vec4 cloud_color; +uniform float cloud_shadow; +uniform float cloud_scale; +uniform float cloud_variance; +uniform vec3 ambient; +uniform vec3 camPosLocal; +uniform vec3 sun_dir; +uniform float sun_size; +uniform float far_z; + +#if !DEPTH_CLAMP +VARYING vec4 post_pos; +#endif + +vec4 cloudNoise(vec2 uv) +{ + vec4 a = texture2D(cloud_noise_texture, uv); + vec4 b = texture2D(cloud_noise_texture_next, uv); + vec4 cloud_noise_sample = mix(a, b, blend_factor); + return normalize(cloud_noise_sample); +} + +void main() +{ + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); + + vec2 uv4 = vary_texcoord3.xy; + + vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow + + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + + cloudDensity *= 1.0 - (density_variance * density_variance); + + // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; + + if (alpha1 < 0.001f) + { + discard; + } + + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; + + frag_color = vec4(alpha1, alpha1, alpha1, 1); + +#if !DEPTH_CLAMP + gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); +#endif + +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl new file mode 100644 index 0000000000..cb27b2c2c5 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl @@ -0,0 +1,63 @@ +/** + * @file cloudShadowV.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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 mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; +uniform float shadow_target_width; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec4 diffuse_color; +ATTRIBUTE vec2 texcoord0; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING vec4 pos; +VARYING float target_pos_x; +VARYING vec2 vary_texcoord0; +VARYING vec4 vertex_color; + +void passTextureIndex(); + +void main() +{ + //transform vertex + vec4 pre_pos = vec4(position.xyz, 1.0); + pos = modelview_projection_matrix * pre_pos; + target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + +#if !DEPTH_CLAMP + pos_zd2 = pos.z * 0.5; + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif + + passTextureIndex(); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + vertex_color = diffuse_color; +} diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl new file mode 100644 index 0000000000..fa6926b007 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl @@ -0,0 +1,121 @@ +/** + * @file class3/deferred/cloudsF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2D diffuseMap; + +VARYING vec4 pos; +VARYING float target_pos_x; +VARYING float vary_CloudDensity; +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; + +uniform sampler2D cloud_noise_texture; +uniform sampler2D cloud_noise_texture_next; +uniform float blend_factor; +uniform vec4 cloud_pos_density1; +uniform vec4 cloud_pos_density2; +uniform vec4 sunlight_color; +uniform vec4 cloud_color; +uniform float cloud_shadow; +uniform float cloud_scale; +uniform float cloud_variance; +uniform vec3 ambient; +uniform vec3 camPosLocal; +uniform vec3 sun_dir; +uniform float sun_size; +uniform float far_z; + +#if !DEPTH_CLAMP +VARYING vec4 post_pos; +#endif + +vec4 cloudNoise(vec2 uv) +{ + vec4 a = texture2D(cloud_noise_texture, uv); + vec4 b = texture2D(cloud_noise_texture_next, uv); + vec4 cloud_noise_sample = mix(a, b, blend_factor); + return normalize(cloud_noise_sample); +} + +void main() +{ + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); + + vec2 uv4 = vary_texcoord3.xy; + + vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow + + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + + cloudDensity *= 1.0 - (density_variance * density_variance); + + // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; + + if (alpha1 < 0.001f) + { + discard; + } + + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; + + frag_color = vec4(alpha1, alpha1, alpha1, 1); + +#if !DEPTH_CLAMP + gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); +#endif + +} diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl new file mode 100644 index 0000000000..52164e7b80 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl @@ -0,0 +1,61 @@ +/** + * @file cloudShadowV.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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 mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; +uniform float shadow_target_width; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec4 diffuse_color; +ATTRIBUTE vec2 texcoord0; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING vec4 pos; +VARYING float target_pos_x; +VARYING vec2 vary_texcoord0; + +void passTextureIndex(); + +void main() +{ + //transform vertex + vec4 pre_pos = vec4(position.xyz, 1.0); + pos = modelview_projection_matrix * pre_pos; + target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + +#if !DEPTH_CLAMP + pos_zd2 = pos.z * 0.5; + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif + + passTextureIndex(); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowF.glsl new file mode 100644 index 0000000000..d973326f93 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowF.glsl @@ -0,0 +1,44 @@ +/** + * @file avatarShadowF.glsl + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2D diffuseMap; + +VARYING vec4 pos; +VARYING vec2 vary_texcoord0; + +vec4 computeMoments(float depth, float a); + +void main() +{ + frag_color = computeMoments(length(pos), 1.0); +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl new file mode 100644 index 0000000000..3be9cb3de8 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl @@ -0,0 +1,51 @@ +/** + * @file attachmentShadowV.glsl + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 mat4 projection_matrix; +uniform mat4 modelview_matrix; +uniform mat4 texture_matrix0; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +mat4 getObjectSkinnedTransform(); + +VARYING vec4 pos; + +void main() +{ + //transform vertex + mat4 mat = getObjectSkinnedTransform(); + + mat = modelview_matrix * mat; + pos = (mat*vec4(position.xyz, 1.0)); + pos = projection_matrix * vec4(pos.xyz, 1.0); + +#if !DEPTH_CLAMP + pos.z = max(pos.z, -pos.w+0.01); + gl_Position = pos; +#else + gl_Position = pos; +#endif +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl new file mode 100644 index 0000000000..f4e5a61e36 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl @@ -0,0 +1,52 @@ +/** + * @file avatarShadowF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2D diffuseMap; + +#if !DEPTH_CLAMP +VARYING vec4 post_pos; +#endif + +VARYING vec4 pos; + +vec4 computeMoments(float depth, float a); + +void main() +{ + frag_color = computeMoments(length(pos), 1.0); + +#if !DEPTH_CLAMP + gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); +#endif +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl new file mode 100644 index 0000000000..96ca2fd707 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl @@ -0,0 +1,68 @@ +/** + * @file avatarShadowV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 mat4 projection_matrix; + +mat4 getSkinnedTransform(); + +ATTRIBUTE vec3 position; +ATTRIBUTE vec3 normal; +ATTRIBUTE vec2 texcoord0; + +#if !DEPTH_CLAMP +VARYING vec4 post_pos; +#endif + +VARYING vec4 pos; + +void main() +{ + vec3 norm; + + vec4 pos_in = vec4(position.xyz, 1.0); + mat4 trans = getSkinnedTransform(); + + pos.x = dot(trans[0], pos_in); + pos.y = dot(trans[1], pos_in); + pos.z = dot(trans[2], pos_in); + pos.w = 1.0; + + norm.x = dot(trans[0].xyz, normal); + norm.y = dot(trans[1].xyz, normal); + norm.z = dot(trans[2].xyz, normal); + norm = normalize(norm); + + pos = projection_matrix * pos; + +#if !DEPTH_CLAMP + post_pos = pos; + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif + +} + + diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl new file mode 100644 index 0000000000..65af2821be --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl @@ -0,0 +1,114 @@ +/** + * @file class3/deferred/cloudsF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2D diffuseMap; + +VARYING vec4 pos; +VARYING float target_pos_x; +VARYING float vary_CloudDensity; +VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; +VARYING vec2 vary_texcoord3; + +uniform sampler2D cloud_noise_texture; +uniform sampler2D cloud_noise_texture_next; +uniform float blend_factor; +uniform vec4 cloud_pos_density1; +uniform vec4 cloud_pos_density2; +uniform vec4 sunlight_color; +uniform vec4 cloud_color; +uniform float cloud_shadow; +uniform float cloud_scale; +uniform float cloud_variance; +uniform vec3 ambient; +uniform vec3 camPosLocal; +uniform vec3 sun_dir; +uniform float sun_size; +uniform float far_z; + +vec4 cloudNoise(vec2 uv) +{ + vec4 a = texture2D(cloud_noise_texture, uv); + vec4 b = texture2D(cloud_noise_texture_next, uv); + vec4 cloud_noise_sample = mix(a, b, blend_factor); + return normalize(cloud_noise_sample); +} + +vec4 computeMoments(float depth, float alpha); + +void main() +{ + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); + + vec2 uv4 = vary_texcoord3.xy; + + vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow + + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + + cloudDensity *= 1.0 - (density_variance * density_variance); + + // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; + + if (alpha1 < 0.001f) + { + discard; + } + + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; + + frag_color = computeMoments(length(pos), alpha1); +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl new file mode 100644 index 0000000000..cb27b2c2c5 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl @@ -0,0 +1,63 @@ +/** + * @file cloudShadowV.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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 mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; +uniform float shadow_target_width; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec4 diffuse_color; +ATTRIBUTE vec2 texcoord0; + +#if !DEPTH_CLAMP +VARYING float pos_zd2; +#endif + +VARYING vec4 pos; +VARYING float target_pos_x; +VARYING vec2 vary_texcoord0; +VARYING vec4 vertex_color; + +void passTextureIndex(); + +void main() +{ + //transform vertex + vec4 pre_pos = vec4(position.xyz, 1.0); + pos = modelview_projection_matrix * pre_pos; + target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + +#if !DEPTH_CLAMP + pos_zd2 = pos.z * 0.5; + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif + + passTextureIndex(); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + vertex_color = diffuse_color; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl index f8373215f0..015caad749 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -138,9 +138,23 @@ void main() // Combine vec4 color; + vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); + + vec4 l1r = texture2D(sh_input_r, vec2(0,0)); + vec4 l1g = texture2D(sh_input_g, vec2(0,0)); + vec4 l1b = texture2D(sh_input_b, vec2(0,0)); + + vec3 sun_indir = vec3(-view_direction.xy, view_direction.z); + vec3 amb = vec3(dot(l1r, l1tap * vec4(1, sun_indir)), + dot(l1g, l1tap * vec4(1, sun_indir)), + dot(l1b, l1tap * vec4(1, sun_indir))); + + + amb = max(vec3(0), amb); + color.rgb = sun_color * cloud_color.rgb * (1. - alpha2); color.rgb = pow(color.rgb, vec3(1.0 / 2.2)); - color.rgb += ambient; + color.rgb += amb; frag_data[0] = vec4(color.rgb, alpha1); frag_data[1] = vec4(0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index ed06e5a6ac..9411e905d3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -76,11 +76,7 @@ vec3 GetSunAndSkyIrradiance(vec3 camPos, vec3 norm, vec3 dir, out vec3 sky_irrad vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); -vec3 scaleSoftClipFrag(vec3 c); -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); -vec3 decode_normal (vec2 enc); - +vec3 decode_normal(vec2 xy); vec3 ColorFromRadiance(vec3 radiance); vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPosition(vec2 pos_screen); @@ -92,32 +88,31 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); void main() { - vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPositionWithDepth(tc, depth).xyz; - vec4 norm = texture2DRect(normalMap, tc); - float envIntensity = norm.z; + vec2 tc = vary_fragcoord.xy; + float depth = texture2DRect(depthMap, tc.xy).r; + vec3 pos = getPositionWithDepth(tc, depth).xyz; + vec4 norm = texture2DRect(normalMap, tc); + float envIntensity = norm.z; norm.xyz = decode_normal(norm.xy); - float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - - float light_gamma = 1.0/1.3; + float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); + da = pow(da, global_gamma + 0.3); - vec4 diffuse = texture2DRect(diffuseRect, tc); // linear + vec4 diffuse = texture2DRect(diffuseRect, tc); // linear - vec3 col; - float bloom = 0.0; - { + vec3 col; + float bloom = 0.0; + { vec3 camPos = (camPosLocal / 1000.0f) + vec3(0, 0, 6360.0f); - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - - vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; - scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); + + vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; +// scol_ambocc = pow(scol_ambocc, vec3(global_gamma + 0.3)); - float scol = max(scol_ambocc.r, diffuse.a); + float scol = max(scol_ambocc.r, diffuse.a); - float ambocc = scol_ambocc.g; + float ambocc = scol_ambocc.g; vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); vec4 l1r = texture2D(sh_input_r, vec2(0,0)); @@ -142,46 +137,44 @@ void main() col *= transmittance; col *= diffuse.rgb; - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - - if (spec.a > 0.0) // specular reflection - { - // the old infinite-sky shiny reflection - // - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = scol * texture2D(lightFunc, vec2(sa, spec.a)).r * atmo_color; - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - col += spec_contrib; - } - - col = mix(col, diffuse.rgb, diffuse.a); - - if (envIntensity > 0.0) - { //add environmentmap - vec3 env_vec = env_mat * refnormpersp; + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + + if (spec.a > 0.0) // specular reflection + { + // the old infinite-sky shiny reflection + // + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = scol * texture2D(lightFunc, vec2(sa, spec.a)).r * atmo_color; + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + col += spec_contrib; + } + + col = mix(col, diffuse.rgb, diffuse.a); + + if (envIntensity > 0.0) + { //add environmentmap + vec3 env_vec = env_mat * refnormpersp; vec3 sun_direction = (inv_modelview * vec4(sun_dir, 1.0)).xyz; vec3 radiance_sun = GetSkyLuminance(camPos, env_vec, 0.0f, sun_direction, transmittance); vec3 refcol = ColorFromRadiance(radiance_sun); - col = mix(col.rgb, refcol, envIntensity); - } - - /*if (norm.w < 0.5) - { - col = scaleSoftClipFrag(col); - }*/ - - #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); - col = fogged.rgb; - bloom = fogged.a; - #endif - - col = pow(col, vec3(light_gamma)); - } - - frag_color.rgb = col; - frag_color.a = bloom; + col = mix(col.rgb, refcol, envIntensity); + } + + /*if (norm.w < 0.5) + { + col = scaleSoftClipFrag(col); + }*/ + + #ifdef WATER_FOG + vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); + col = fogged.rgb; + bloom = fogged.a; + #endif + } + + frag_color.rgb = col; + frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl index 894534b105..e230ebb71c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl @@ -1,5 +1,5 @@ /** - * @file sunLightF.glsl + * @file class3\deferred\sunLightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -35,197 +35,24 @@ out vec4 frag_color; //class 2, shadows, no SSAO -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; -uniform sampler2DShadow shadowMap4; -uniform sampler2DShadow shadowMap5; - - // Inputs -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; - VARYING vec2 vary_fragcoord; -uniform mat4 inv_proj; -uniform vec2 screen_res; -uniform vec2 proj_shadow_res; -uniform vec3 sun_dir; - -uniform vec2 shadow_res; -uniform float shadow_bias; -uniform float shadow_offset; - -uniform float spot_shadow_bias; -uniform float spot_shadow_offset; - vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen); vec3 getNorm(vec2 pos_screen); -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias; - - stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*0.666666666))/shadow_res.x; // add some jitter to X sample pos according to Y to disguise the snapping going on here - float cs = shadow2D(shadowMap, stc.xyz).x; - - float shadow = cs; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - - return shadow*0.2; -} - -float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) -{ - stc.xyz /= stc.w; - stc.z += spot_shadow_bias*scl; - stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - - vec2 off = 1.0/proj_shadow_res; - off.y *= 1.5; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; - - return shadow*0.2; -} +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen); void main() { vec2 pos_screen = vary_fragcoord.xy; vec4 pos = getPosition(pos_screen); vec3 norm = getNorm(pos_screen); - - /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL - { - frag_color = vec4(0.0); // doesn't matter - return; - }*/ - - float shadow = 0.0; - float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); - - vec3 shadow_pos = pos.xyz; - vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); - - vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); - - if (spos.z > -shadow_clip.w) - { - if (dp_directional_light == 0.0) - { - // if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup - shadow = 0.0; - } - else - { - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; - weight += w; - } - - - shadow /= weight; - - // take the most-shadowed value out of these two: - // * the blurred sun shadow in the light (shadow) map - // * an unblurred dot product between the sun and this norm - // the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting - shadow = min(shadow, dp_directional_light); - - //lpos.xy /= lpos.w*32.0; - //if (fract(lpos.x) < 0.1 || fract(lpos.y) < 0.1) - //{ - // shadow = 0.0; - //} - - } - } - else - { - // more distant than the shadow map covers - shadow = 1.0; - } - - frag_color[0] = shadow; - frag_color[1] = 1.0; - - spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); - - //spotlight shadow 1 - vec4 lpos = shadow_matrix[4]*spos; - frag_color[2] = pcfSpotShadow(shadowMap4, lpos, 0.8, pos_screen); - - //spotlight shadow 2 - lpos = shadow_matrix[5]*spos; - frag_color[3] = pcfSpotShadow(shadowMap5, lpos, 0.8, pos_screen); - //frag_color.rgb = pos.xyz; - //frag_color.b = shadow; + frag_color.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); + frag_color.g = 1.0f; + frag_color.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); + frag_color.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl index 0870a80a32..342a2ff3ed 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl @@ -1,5 +1,5 @@ /** - * @file sunLightSSAOF.glsl + * @file class3\deferred\sunLightSSAOF.glsl * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. @@ -34,200 +34,28 @@ out vec4 frag_color; //class 2 -- shadows and SSAO -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; -uniform sampler2DShadow shadowMap4; -uniform sampler2DShadow shadowMap5; -uniform sampler2D noiseMap; - - // Inputs -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; - VARYING vec2 vary_fragcoord; -uniform mat4 inv_proj; -uniform vec2 screen_res; -uniform vec2 proj_shadow_res; uniform vec3 sun_dir; -uniform vec2 shadow_res; - -uniform float shadow_bias; -uniform float shadow_offset; - -uniform float spot_shadow_bias; -uniform float spot_shadow_offset; - vec4 getPosition(vec2 pos_screen); vec3 getNorm(vec2 pos_screen); -//calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm, pos_screen); - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias; +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen); - stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*0.666666666))/shadow_res.x; - float cs = shadow2D(shadowMap, stc.xyz).x; - - float shadow = cs; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - return shadow*0.2; -} - -float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) -{ - stc.xyz /= stc.w; - stc.z += spot_shadow_bias*scl; - stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - - vec2 off = 1.0/proj_shadow_res; - off.y *= 1.5; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; - - return shadow*0.2; -} +//calculate decreases in ambient lighting when crowded out (SSAO) +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); void main() { - vec2 pos_screen = vary_fragcoord.xy; + vec2 pos_screen = vary_fragcoord.xy; vec4 pos = getPosition(pos_screen); vec3 norm = getNorm(pos_screen); - - /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL - { - frag_color = vec4(0.0); // doesn't matter - return; - }*/ - - float shadow = 0.0; - float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); - - vec3 shadow_pos = pos.xyz; - vec3 offset = sun_dir.xyz * (1.0-dp_directional_light); - - vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); - - if (spos.z > -shadow_clip.w) - { - if (dp_directional_light == 0.0) - { - // if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup - shadow = 0.0; - } - else - { - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; - weight += w; - } - - - shadow /= weight; - - // take the most-shadowed value out of these two: - // * the blurred sun shadow in the light (shadow) map - // * an unblurred dot product between the sun and this norm - // the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting - shadow = min(shadow, dp_directional_light); - - //lpos.xy /= lpos.w*32.0; - //if (fract(lpos.x) < 0.1 || fract(lpos.y) < 0.1) - //{ - // shadow = 0.0; - //} - - } - } - else - { - // more distant than the shadow map covers - shadow = 1.0; - } - - frag_color[0] = shadow; - frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); - - spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); - - //spotlight shadow 1 - vec4 lpos = shadow_matrix[4]*spos; - frag_color[2] = pcfSpotShadow(shadowMap4, lpos, 0.8, pos_screen); - - //spotlight shadow 2 - lpos = shadow_matrix[5]*spos; - frag_color[3] = pcfSpotShadow(shadowMap5, lpos, 0.8, pos_screen); - //frag_color.rgb = pos.xyz; - //frag_color.b = shadow; + frag_color.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); + frag_color.b = calcAmbientOcclusion(pos, norm, pos_screen); + frag_color.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); + frag_color.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl new file mode 100644 index 0000000000..693af31bf2 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl @@ -0,0 +1,59 @@ +/** + * @file treeShadowF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform float minimum_alpha; + +uniform sampler2D diffuseMap; + +VARYING vec4 pos; +VARYING vec2 vary_texcoord0; + +vec4 computeMoments(float d, float a); + +void main() +{ + float alpha = texture2D(diffuseMap, vary_texcoord0.xy).a; + + if (alpha < minimum_alpha) + { + discard; + } + + frag_color = computeMoments(length(pos), 1.0); + +#if !DEPTH_CLAMP + gl_FragDepth = max(pos.z/pos.w*0.5+0.5, 0.0); +#endif + +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/treeShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/treeShadowV.glsl new file mode 100644 index 0000000000..15e769ac10 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/treeShadowV.glsl @@ -0,0 +1,43 @@ +/** + * @file treeShadowV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +VARYING vec4 pos; +VARYING vec2 vary_texcoord0; + +void main() +{ + //transform vertex + pos = modelview_projection_matrix*vec4(position.xyz, 1.0); + + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl new file mode 100644 index 0000000000..9d18d1afd8 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl @@ -0,0 +1,118 @@ +/** + * @file underWaterF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif + +uniform sampler2D diffuseMap; +uniform sampler2D bumpMap; +uniform sampler2D screenTex; +uniform sampler2D refTex; +uniform sampler2D screenDepth; + +uniform vec4 fogCol; +uniform vec3 lightDir; +uniform vec3 specular; +uniform float lightExp; +uniform vec2 fbScale; +uniform float refScale; +uniform float znear; +uniform float zfar; +uniform float kd; +uniform vec4 waterPlane; +uniform vec3 eyeVec; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; +uniform vec2 screenRes; + +//bigWave is (refCoord.w, view.w); +VARYING vec4 refCoord; +VARYING vec4 littleWave; +VARYING vec4 view; + +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); + +vec2 encode_normal(vec3 n); + +vec4 applyWaterFog(vec4 color, vec3 viewVec) +{ + //normalize view vector + vec3 view = normalize(viewVec); + float es = -view.z; + + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + //get object depth + float depth = length(viewVec); + + //get "thickness" of water + float l = max(depth, 0.1); + + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2*l) - 1.0; + + float L = min(t1/t2*t3, 1.0); + + float D = pow(0.98, l*kd); + return color * D + kc * L; +} + +void main() +{ + vec4 color; + + //get detail normals + vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; + vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + vec3 wavef = normalize(wave1+wave2+wave3); + + //figure out distortion vector (ripply) + vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; + distort = distort+wavef.xy*refScale; + + vec4 fb = texture2D(screenTex, distort); + + frag_data[0] = vec4(fb.rgb, 1.0); // diffuse + frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec + frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, displace +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl new file mode 100644 index 0000000000..2a144ba23a --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl @@ -0,0 +1,175 @@ +/** + * @file waterF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif + +uniform sampler2D bumpMap; +uniform sampler2D bumpMap2; +uniform float blend_factor; +uniform sampler2D screenTex; +uniform sampler2D refTex; + +uniform float sunAngle; +uniform float sunAngle2; +uniform vec3 lightDir; +uniform vec3 specular; +uniform float lightExp; +uniform float refScale; +uniform float kd; +uniform vec2 screenRes; +uniform vec3 normScale; +uniform float fresnelScale; +uniform float fresnelOffset; +uniform float blurMultiplier; +uniform vec2 screen_res; +uniform mat4 norm_mat; //region space to screen space + +//bigWave is (refCoord.w, view.w); +VARYING vec4 refCoord; +VARYING vec4 littleWave; +VARYING vec4 view; +VARYING vec4 vary_position; + +vec3 scaleSoftClip(vec3 c); +vec3 srgb_to_linear(vec3 cs); +vec2 encode_normal(vec3 n); + +vec3 BlendNormal(vec3 bump1, vec3 bump2) +{ + //vec3 normal = bump1.xyz * vec3( 2.0, 2.0, 2.0) - vec3(1.0, 1.0, 0.0); + //vec3 normal2 = bump2.xyz * vec3(-2.0, -2.0, 2.0) + vec3(1.0, 1.0, -1.0); + //vec3 n = normalize(normal * dot(normal, normal2) - (normal2 * normal.z)); + vec3 n = normalize(mix(bump1, bump2, blend_factor)); + return n; +} + +void main() +{ + vec4 color; + float dist = length(view.xy); + + //normalize view vector + vec3 viewVec = normalize(view.xyz); + + //get wave normals + vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + + + vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; + + vec3 wave1 = BlendNormal(wave1_a, wave1_b); + vec3 wave2 = BlendNormal(wave2_a, wave2_b); + vec3 wave3 = BlendNormal(wave3_a, wave3_b); + + //get base fresnel components + + vec3 df = vec3( + dot(viewVec, wave1), + dot(viewVec, (wave2 + wave3) * 0.5), + dot(viewVec, wave3) + ) * fresnelScale + fresnelOffset; + df *= df; + + vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; + + float dist2 = dist; + dist = max(dist, 5.0); + + float dmod = sqrt(dist); + + vec2 dmod_scale = vec2(dmod*dmod, dmod); + + //get reflected color + vec2 refdistort1 = wave1.xy*normScale.x; + vec2 refvec1 = distort+refdistort1/dmod_scale; + vec4 refcol1 = texture2D(refTex, refvec1); + + vec2 refdistort2 = wave2.xy*normScale.y; + vec2 refvec2 = distort+refdistort2/dmod_scale; + vec4 refcol2 = texture2D(refTex, refvec2); + + vec2 refdistort3 = wave3.xy*normScale.z; + vec2 refvec3 = distort+refdistort3/dmod_scale; + vec4 refcol3 = texture2D(refTex, refvec3); + + vec4 refcol = refcol1 + refcol2 + refcol3; + float df1 = df.x + df.y + df.z; + refcol *= df1 * 0.333; + + vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; + wavef.z *= max(-viewVec.z, 0.1); + wavef = normalize(wavef); + + float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; + + vec2 refdistort4 = wavef.xy*0.125; + refdistort4.y -= abs(refdistort4.y); + vec2 refvec4 = distort+refdistort4/dmod; + float dweight = min(dist2*blurMultiplier, 1.0); + vec4 baseCol = texture2D(refTex, refvec4); + + refcol = mix(baseCol*df2, refcol, dweight); + + //get specular component + float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); + + //harden specular + spec = pow(spec, 128.0); + + //figure out distortion vector (ripply) + vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); + + vec4 fb = texture2D(screenTex, distort2); + + //mix with reflection + // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); + + color.rgb *= 2.0f; + color.rgb = scaleSoftClip(color.rgb); + + vec4 pos = vary_position; + + color.rgb += spec * specular; + color.a = spec * sunAngle2; + + vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); + + frag_data[0] = vec4(color.rgb, color); // diffuse + frag_data[1] = vec4(spec * specular, spec); // speccolor, spec + frag_data[2] = vec4(encode_normal(wavef.xyz), 0.05, 0);// normalxy, 0, 0 +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterV.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterV.glsl new file mode 100644 index 0000000000..02000d90ca --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/waterV.glsl @@ -0,0 +1,95 @@ +/** + * @file waterV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 mat4 modelview_matrix; +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + + +uniform vec2 d1; +uniform vec2 d2; +uniform float time; +uniform vec3 eyeVec; +uniform float waterHeight; + +VARYING vec4 refCoord; +VARYING vec4 littleWave; +VARYING vec4 view; + +VARYING vec4 vary_position; + +float wave(vec2 v, float t, float f, vec2 d, float s) +{ + return (dot(d, v)*f + t*s)*f; +} + +void main() +{ + //transform vertex + vec4 pos = vec4(position.xyz, 1.0); + mat4 modelViewProj = modelview_projection_matrix; + + vec4 oPosition; + + //get view vector + vec3 oEyeVec; + oEyeVec.xyz = pos.xyz-eyeVec; + + float d = length(oEyeVec.xy); + float ld = min(d, 2560.0); + + pos.xy = eyeVec.xy + oEyeVec.xy/d*ld; + view.xyz = oEyeVec; + + d = clamp(ld/1536.0-0.5, 0.0, 1.0); + d *= d; + + oPosition = vec4(position, 1.0); + oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d); + vary_position = modelview_matrix * oPosition; + oPosition = modelViewProj * oPosition; + + refCoord.xyz = oPosition.xyz + vec3(0,0,0.2); + + //get wave position parameter (create sweeping horizontal waves) + vec3 v = pos.xyz; + v.x += (cos(v.x*0.08/*+time*0.01*/)+sin(v.y*0.02))*6.0; + + //push position for further horizon effect. + pos.xyz = oEyeVec.xyz*(waterHeight/oEyeVec.z); + pos.w = 1.0; + pos = modelview_matrix*pos; + + //pass wave parameters to pixel shader + vec2 bigWave = (v.xy) * vec2(0.04,0.04) + d1 * time * 0.055; + //get two normal map (detail map) texture coordinates + littleWave.xy = (v.xy) * vec2(0.45, 0.9) + d2 * time * 0.13; + littleWave.zw = (v.xy) * vec2(0.1, 0.2) + d1 * time * 0.1; + view.w = bigWave.y; + refCoord.w = bigWave.x; + + gl_Position = oPosition; +} diff --git a/indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl deleted file mode 100644 index a7d76052bb..0000000000 --- a/indra/newview/app_settings/shaders/class3/windlight/gammaF.glsl +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @file gammaF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, 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 vec4 gamma; -uniform int no_atmo; - -vec3 scaleSoftClipFrag(vec3 light) { - if (no_atmo == 1) - { - return light; - } - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - return light; -} - -/// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light) { - return scaleSoftClipFrag(light); -} - -vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 add, vec3 atten) -{ - return scaleSoftClipFrag(light.rgb); -} - -vec3 fullbrightScaleSoftClip(vec3 light) { - return fullbrightScaleSoftClipFrag(light.rgb); -} - -- cgit v1.2.3 From c007e1197c521a1b48736cbba29e7c7dadf39c20 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 4 Jan 2019 13:26:47 -0800 Subject: Convert to using shared shadow sampling function (reduce duplicated code blocks in several shaders). --- .../shaders/class1/deferred/alphaF.glsl | 93 +--------- .../shaders/class1/deferred/blurLightF.glsl | 4 - .../shaders/class1/deferred/materialF.glsl | 115 +----------- .../shaders/class1/deferred/pointLightF.glsl | 1 - .../shaders/class1/deferred/postgiF.glsl | 13 +- .../shaders/class1/deferred/shadowUtil.glsl | 34 +++- .../shaders/class1/deferred/softenLightF.glsl | 29 +-- .../shaders/class1/deferred/sunLightSSAOF.glsl | 23 +-- .../shaders/class2/deferred/sunLightF.glsl | 203 ++------------------- .../shaders/class2/deferred/sunLightSSAOF.glsl | 201 ++------------------ 10 files changed, 72 insertions(+), 644 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 33e61f2062..9670b39fdb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -92,6 +92,8 @@ 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) { //get light vector @@ -132,28 +134,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec return max(col, vec3(0.0,0.0,0.0)); } -#if HAS_SHADOW -float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias; - - stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - return shadow*0.2; -} -#endif - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen); - void main() { vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; @@ -162,74 +142,7 @@ void main() vec4 pos = vec4(vary_position, 1.0); vec3 norm = vary_norm; - float shadow = 1.0; - -#if HAS_SHADOW - vec4 spos = pos; - - if (spos.z > -shadow_clip.w) - { - shadow = 0.0; - - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap3, lpos)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap2, lpos)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadowLegacy(shadowMap1, lpos)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadowLegacy(shadowMap0, lpos)*w; - weight += w; - } - - - shadow /= weight; - } - else - { - shadow = 1.0; - } -#endif + float shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); #ifdef USE_INDEXED_TEX vec4 diff = diffuseLookup(vary_texcoord0.xy); diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index 868eec3926..812f375f42 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -33,7 +33,6 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect depthMap; uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; @@ -45,9 +44,6 @@ uniform float kern_scale; VARYING vec2 vary_fragcoord; -uniform mat4 inv_proj; -uniform vec2 screen_res; - vec4 getPosition(vec2 pos_screen); vec3 getNorm(vec2 pos_screen); vec3 decode_normal (vec2 enc); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a0da8563a2..0f7c514e94 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -50,38 +50,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -#if HAS_SUN_SHADOW - -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; - -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform vec2 shadow_res; -uniform float shadow_bias; - -float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias; - - stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - return shadow*0.2; -} - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen); -#endif +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); uniform samplerCube environmentMap; uniform sampler2D lightFunc; @@ -174,19 +143,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe } -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - - #else #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -295,74 +251,7 @@ void main() //forward rendering, output just lit RGBA vec3 pos = vary_position; -#if HAS_SUN_SHADOW - float shadow = 0.0; - - vec4 spos = vec4(pos,1.0); - - if (spos.z > -shadow_clip.w) - { - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap3, lpos)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap2, lpos)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadowLegacy(shadowMap1, lpos)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadowLegacy(shadowMap0, lpos)*w; - weight += w; - } - - - shadow /= weight; - } - else - { - shadow = 1.0; - } -#else - float shadow = 1.0; -#endif + float shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); spec = final_specular; vec4 diffuse = final_color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 8e756c37bf..df48a66fab 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -57,7 +57,6 @@ uniform mat4 inv_proj; uniform vec4 viewport; vec3 decode_normal (vec2 enc); - vec4 getPosition(vec2 pos_screen); void main() diff --git a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl index e33254304b..cf994d3547 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl @@ -49,18 +49,7 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).a; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index ae5cb7cbc1..f626609fc2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -54,12 +54,30 @@ uniform vec2 screen_res; vec3 decode_normal(vec2 enc); +float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc) +{ + stc.xyz /= stc.w; + stc.z += shadow_bias; + + stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + + return shadow*0.2; +} + float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) { stc.xyz /= stc.w; - stc.z += shadow_bias; - - stc.x = floor(stc.x*pos_screen.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + stc.z += shadow_bias * bias_scale; + + stc.x = floor(stc.x*pos_screen.x + fract(stc.y*pos_screen.y*0.666666666))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; float shadow = cs; @@ -96,7 +114,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float dp_directional_light = max(dp_sun,dp_moon); dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); - vec3 light_dir = (dp_moon > dp_sun) ? moon_dir : sun_dir; + vec3 light_dir = (dp_moon > dp_sun) ? moon_dir : sun_dir; vec3 offset = light_dir * (1.0-dp_directional_light); vec3 shadow_pos = pos.xyz + (offset * shadow_bias); @@ -116,7 +134,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos, 0.5, pos_screen)*w; + shadow += pcfShadowLegacy(shadowMap3, lpos)*w; weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } @@ -128,7 +146,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos, 0.75, pos_screen)*w; + shadow += pcfShadowLegacy(shadowMap2, lpos)*w; weight += w; } @@ -139,7 +157,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos, 0.88, pos_screen)*w; + shadow += pcfShadowLegacy(shadowMap1, lpos)*w; weight += w; } @@ -150,7 +168,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; + shadow += pcfShadowLegacy(shadowMap0, lpos)*w; weight += w; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 0de38a3d62..f0b038cc93 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -74,31 +74,18 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, vec3 scaleSoftClip(vec3 l); vec3 fullbrightScaleSoftClip(vec3 l); -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - vec4 getPositionWithDepth(vec2 pos_screen, float depth); -vec4 getPosition(vec2 pos_screen); void main() { - vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPositionWithDepth(tc, depth).xyz; - vec4 norm = texture2DRect(normalMap, tc); - float envIntensity = norm.z; - norm.xyz = decode_normal(norm.xy); // unpack norm - - float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); + vec2 tc = vary_fragcoord.xy; + float depth = texture2DRect(depthMap, tc.xy).r; + vec4 pos = getPositionWithDepth(tc, depth); + vec4 norm = texture2DRect(normalMap, tc); + float envIntensity = norm.z; + norm.xyz = decode_normal(norm.xy); // unpack norm + + float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); float da_moon = dot(norm.xyz, normalize(moon_dir.xyz)); float da = max(da_sun, da_moon); diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 6d65ee2add..e98ab1f2eb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -35,20 +35,15 @@ out vec4 frag_color; //class 1 -- no shadow, SSAO only -uniform sampler2DRect depthMap; uniform sampler2DRect normalMap; -uniform sampler2D noiseMap; - // Inputs VARYING vec2 vary_fragcoord; -uniform mat4 inv_proj; -uniform vec2 screen_res; - vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen); -vec3 getNorm(vec2 pos_screen); + +//calculate decreases in ambient lighting when crowded out (SSAO) float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); void main() @@ -57,11 +52,11 @@ void main() //try doing an unproject here - vec4 pos = getPosition(pos_screen); - vec3 norm = getNorm(pos_screen); - - frag_color.r = 1.0; - frag_color.g = calcAmbientOcclusion(pos, norm, pos_screen); - frag_color.b = 1.0; - frag_color.a = 1.0; + vec4 pos = getPosition(pos_screen); + vec3 norm = decode_normal(texture2DRect(normalMap, pos_screen).xy); + + frag_color[0] = 1.0; + frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); + frag_color[2] = 1.0; + frag_color[3] = 1.0; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index 5f8f3114a1..fc5756beef 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -35,208 +35,27 @@ out vec4 frag_color; //class 2, shadows, no SSAO -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; -uniform sampler2DShadow shadowMap4; -uniform sampler2DShadow shadowMap5; - - // Inputs -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; - VARYING vec2 vary_fragcoord; -uniform mat4 inv_proj; -uniform vec2 screen_res; -uniform vec2 proj_shadow_res; uniform vec3 sun_dir; -uniform vec3 moon_dir; - -uniform vec2 shadow_res; uniform float shadow_bias; -uniform float shadow_offset; - -uniform float spot_shadow_bias; -uniform float spot_shadow_offset; vec3 getNorm(vec2 pos_screen); +vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen); -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen); -float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen); - -float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias; - - stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*0.666666666))/shadow_res.x; // add some jitter to X sample pos according to Y to disguise the snapping going on here - float cs = shadow2D(shadowMap, stc.xyz).x; - - float shadow = cs; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - - return shadow*0.2; -} - -float pcfSpotShadowLegacy(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) -{ - stc.xyz /= stc.w; - stc.z += spot_shadow_bias*scl; - stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - - vec2 off = 1.0/proj_shadow_res; - off.y *= 1.5; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; - - return shadow*0.2; -} +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen); void main() { - vec2 pos_screen = vary_fragcoord.xy; - - //try doing an unproject here - - vec4 pos = getPosition(pos_screen); - vec3 norm = getNorm(pos_screen); - - /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL - { - frag_color = vec4(0.0); // doesn't matter - return; - }*/ - - float shadow = 0.0; - float dp_sun = dot(norm, normalize(sun_dir.xyz)); - float dp_moon = dot(norm, normalize(moon_dir.xyz)); - float dp_directional_light = max(dp_sun, dp_moon); - dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); - - vec3 light_direction = (dp_moon > dp_sun) ? moon_dir : sun_dir; - - vec3 shadow_pos = pos.xyz; - vec3 offset = light_direction.xyz * (1.0-dp_directional_light); - - vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); - - if (spos.z > -shadow_clip.w) - { - if (dp_directional_light == 0.0) - { - // if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup - shadow = 0.0; - } - else - { - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap3, lpos, 0.25, pos_screen)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap2, lpos, 0.5, pos_screen)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadowLegacy(shadowMap1, lpos, 0.75, pos_screen)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadowLegacy(shadowMap0, lpos, 1.0, pos_screen)*w; - weight += w; - } - - - shadow /= weight; - - // take the most-shadowed value out of these two: - // * the blurred sun shadow in the light (shadow) map - // * an unblurred dot product between the sun and this norm - // the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting - shadow = min(shadow, dp_directional_light); - - //lpos.xy /= lpos.w*32.0; - //if (fract(lpos.x) < 0.1 || fract(lpos.y) < 0.1) - //{ - // shadow = 0.0; - //} - - } - } - else - { - // more distant than the shadow map covers - shadow = 1.0; - } - - frag_color[0] = shadow; - frag_color[1] = 1.0; - - spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); - - //spotlight shadow 1 - vec4 lpos = shadow_matrix[4]*spos; - frag_color[2] = pcfSpotShadowLegacy(shadowMap4, lpos, 0.8, pos_screen); - - //spotlight shadow 2 - lpos = shadow_matrix[5]*spos; - frag_color[3] = pcfSpotShadowLegacy(shadowMap5, lpos, 0.8, pos_screen); - - //frag_color.rgb = pos.xyz; - //frag_color.b = shadow; + vec2 pos_screen = vary_fragcoord.xy; + vec4 pos = getPosition(pos_screen); + vec3 norm = getNorm(pos_screen); + + frag_color.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); + frag_color.g = 1.0f; + frag_color.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); + frag_color.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 10ef1785da..390f9fc947 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -34,202 +34,25 @@ out vec4 frag_color; //class 2 -- shadows and SSAO -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; -uniform sampler2DShadow shadowMap4; -uniform sampler2DShadow shadowMap5; - +// Inputs VARYING vec2 vary_fragcoord; -uniform mat4 inv_proj; -uniform vec2 screen_res; -uniform vec2 proj_shadow_res; - -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform vec2 shadow_res; -uniform float shadow_bias; -uniform float shadow_offset; -uniform float spot_shadow_bias; -uniform float spot_shadow_offset; - -uniform vec3 sun_dir; -uniform vec3 moon_dir; - +vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen); vec3 getNorm(vec2 pos_screen); +float sampleDirectionalShadow(vec3 shadow_pos, vec3 norm, vec2 pos_screen); +float sampleSpotShadow(vec3 shadow_pos, vec3 norm, int index, vec2 pos_screen); float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen); -float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen); - - -float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias; - - stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*0.666666666))/shadow_res.x; - float cs = shadow2D(shadowMap, stc.xyz).x; - - float shadow = cs; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - return shadow*0.2; -} - -float pcfSpotShadowLegacy(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) -{ - stc.xyz /= stc.w; - stc.z += spot_shadow_bias*scl; - stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - - vec2 off = 1.0/proj_shadow_res; - off.y *= 1.5; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; - - return shadow*0.2; -} void main() { - vec2 pos_screen = vary_fragcoord.xy; - - //try doing an unproject here - - vec4 pos = getPosition(pos_screen); - vec3 norm = getNorm(pos_screen); - - /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL - { - frag_color = vec4(0.0); // doesn't matter - return; - }*/ - - float shadow = 0.0; - float dp_sun = dot(norm, normalize(sun_dir.xyz)); - float dp_moon = dot(norm, normalize(moon_dir.xyz)); - float dp_directional_light = max(dp_sun, dp_moon); - dp_directional_light = max(0.0, dp_directional_light); - - vec3 light_direction = (dp_moon > dp_sun) ? moon_dir : sun_dir; - - vec3 shadow_pos = pos.xyz; - vec3 offset = light_direction.xyz * (1.0-dp_directional_light); - - vec4 spos = vec4(shadow_pos+offset*shadow_offset, 1.0); - - if (spos.z > -shadow_clip.w) - { - if (dp_directional_light == 0.0) - { - // if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup - shadow = 0.0; - } - else - { - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap3, lpos, 0.25, pos_screen)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap2, lpos, 0.5, pos_screen)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadowLegacy(shadowMap1, lpos, 0.75, pos_screen)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadowLegacy(shadowMap0, lpos, 1.0, pos_screen)*w; - weight += w; - } - - - shadow /= weight; - - // take the most-shadowed value out of these two: - // * the blurred sun shadow in the light (shadow) map - // * an unblurred dot product between the sun and this norm - // the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting - shadow = min(shadow, dp_directional_light); - - //lpos.xy /= lpos.w*32.0; - //if (fract(lpos.x) < 0.1 || fract(lpos.y) < 0.1) - //{ - // shadow = 0.0; - //} - - } - } - else - { - // more distant than the shadow map covers - shadow = 1.0; - } - - frag_color[0] = shadow; - frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); - - spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); - - //spotlight shadow 1 - vec4 lpos = shadow_matrix[4]*spos; - frag_color[2] = pcfSpotShadow(shadowMap4, lpos, 0.8, pos_screen); - - //spotlight shadow 2 - lpos = shadow_matrix[5]*spos; - frag_color[3] = pcfSpotShadow(shadowMap5, lpos, 0.8, pos_screen); - - //frag_color.rgb = pos.xyz; - //frag_color.b = shadow; + vec2 pos_screen = vary_fragcoord.xy; + vec4 pos = getPosition(pos_screen); + vec3 norm = getNorm(pos_screen); + + frag_color.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); + frag_color.g = calcAmbientOcclusion(pos, norm, pos_screen); + frag_color.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); + frag_color.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); } -- cgit v1.2.3 From aed659c5b4cb5ac2378b4aadc91468bbaf9c4362 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 7 Jan 2019 16:47:16 -0800 Subject: SL-10304 fix handling of water normal map blending when both current and next textures are identical. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 69543b93ea..869c9e7927 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -68,10 +68,7 @@ vec3 scaleSoftClipFrag(vec3 l); vec3 BlendNormal(vec3 bump1, vec3 bump2) { - //vec3 normal = bump1.xyz * vec3( 2.0, 2.0, 2.0) - vec3(1.0, 1.0, 0.0); - //vec3 normal2 = bump2.xyz * vec3(-2.0, -2.0, 2.0) + vec3(1.0, 1.0, -1.0); - //vec3 n = normalize(normal * dot(normal, normal2) - (normal2 * normal.z)); - vec3 n = normalize(mix(bump1, bump2, blend_factor)); + vec3 n = mix(bump1, bump2, blend_factor); return n; } -- cgit v1.2.3 From e13113ab0b5e7aea11feba3947d2bbf7c5699db1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 8 Jan 2019 13:15:00 -0800 Subject: SL-10305 fix post deferred gamma correction to address ALM mismatch with non-ALM lighting. --- .../app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 8791469675..cbc19bbba3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -45,7 +45,7 @@ vec3 linear_to_srgb(vec3 cl); void main() { vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - diff.rgb = pow(diff.rgb, vec3(display_gamma)); + diff.rgb = linear_to_srgb(diff.rgb); frag_color = diff; } -- cgit v1.2.3 From b865fc88e575e39111418a329362eada368445cd Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 8 Jan 2019 17:20:56 -0800 Subject: Fix broken distortion map rendering (was culling everything). Clean up deferred\alpha shader to allow re-entrant graphics switching (link error on 2nd compile/link of deferred shaders). Clean up some uses of pragma(optimize,...). --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 9670b39fdb..132364882b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -45,20 +45,6 @@ uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; uniform vec3 moon_dir; -#if HAS_SHADOW -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; - -uniform vec2 shadow_res; - -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform float shadow_bias; - -#endif - #ifdef USE_DIFFUSE_TEX uniform sampler2D diffuseMap; #endif -- cgit v1.2.3 From c0f67e8d6a20933d35539888b229e3ac77fa22ec Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Thu, 10 Jan 2019 19:54:02 +0200 Subject: Fix for lineendings in depthToShadowVolumeG.glsl --- .../class3/deferred/depthToShadowVolumeG.glsl | 404 ++++++++++----------- 1 file changed, 202 insertions(+), 202 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl b/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl index 5734e2abb2..cdaff4b09f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl @@ -1,202 +1,202 @@ -/** - * @file depthToShadowVolumeG.glsl - * - * $LicenseInfo:firstyear=2011&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2011, 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$ - */ -#extension GL_ARB_geometry_shader4 : enable -#extension GL_ARB_texture_rectangle : enable - -/*[EXTRA_CODE_HERE]*/ - -layout (triangles) in; -layout (triangle_strip, max_vertices = 128) out; - -uniform sampler2DRect depthMap; -uniform mat4 shadowMatrix[6]; -uniform vec4 lightpos; - -VARYING vec2 vary_texcoord0; - -out vec3 to_vec; - -void cross_products(out vec4 ns[3], int a, int b, int c) -{ - ns[0] = cross(gl_PositionIn[b].xyz - gl_PositionIn[a].xyz, gl_PositionIn[c].xyz - gl_PositionIn[a].xyz); - ns[1] = cross(gl_PositionIn[c].xyz - gl_PositionIn[b].xyz, gl_PositionIn[a].xyz - gl_PositionIn[b].xyz); - ns[2] = cross(gl_PositionIn[a].xyz - gl_PositionIn[c].xyz, gl_PositionIn[b].xyz - gl_PositionIn[c].xyz); -} - -vec3 getLightDirection(vec4 lightpos, vec3 pos) -{ - - vec3 lightdir = lightpos.xyz - lightpos.w * pos; - return lightdir; -} - -void emitTri(vec4 v[3]) -{ - gl_Position = proj_matrix * v[0]; - EmitVertex(); - - gl_Position = proj_matrix * v[1]; - EmitVertex(); - - gl_Position = proj_matrix * v[2]; - EmitVertex(); - - EndPrimitive(); -} - -void emitQuad(vec4 v[4] -{ - // Emit a quad as a triangle strip. - gl_Position = proj_matrix*v[0]; - EmitVertex(); - - gl_Position = proj_matrix*v[1]; - EmitVertex(); - - gl_Position = proj_matrix*v[2]; - EmitVertex(); - - gl_Position = proj_matrix*v[3]; - EmitVertex(); - - EndPrimitive(); -} - -void emitPrimitives(int layer) -{ - int i = layer; - gl_Layer = i; - - vec4 depth1 = vec4(texture2DRect(depthMap, tc0).rg, texture2DRect(depthMap, tc1).rg)); - vec3 depth2 = vec4(texture2DRect(depthMap, tc2).rg, texture2DRect(depthMap, tc3).rg)); - vec3 depth3 = vec4(texture2DRect(depthMap, tc4).rg, texture2DRect(depthMap, tc5).rg)); - vec3 depth4 = vec4(texture2DRect(depthMap, tc6).rg, texture2DRect(depthMap, tc7).rg)); - - depth1 = min(depth1, depth2); - depth1 = min(depth1, depth3); - depth1 = min(depth1, depth4); - - vec2 depth = min(depth1.xy, depth1.zw); - - int side = sqrt(gl_VerticesIn); - - for (int j = 0; j < side; j++) - { - for (int k = 0; k < side; ++k) - { - vec3 pos = gl_PositionIn[(j * side) + k].xyz; - vec4 v = shadowMatrix[i] * vec4(pos, 1.0); - gl_Position = v; - to_vec = pos - light_position.xyz * depth; - EmitVertex(); - } - - EndPrimitive(); - } - - vec3 norms[3]; // Normals - vec3 lightdir3]; // Directions toward light - - vec4 v[4]; // Temporary vertices - - vec4 or_pos[3] = - { // Triangle oriented toward light source - gl_PositionIn[0], - gl_PositionIn[2], - gl_PositionIn[4] - }; - - // Compute normal at each vertex. - cross_products(n, 0, 2, 4); - - // Compute direction from vertices to light. - lightdir[0] = getLightDirection(lightpos, gl_PositionIn[0].xyz); - lightdir[1] = getLightDirection(lightpos, gl_PositionIn[2].xyz); - lightdir[2] = getLightDirection(lightpos, gl_PositionIn[4].xyz); - - // Check if the main triangle faces the light. - bool faces_light = true; - if (!(dot(ns[0],d[0]) > 0 - |dot(ns[1],d[1]) > 0 - |dot(ns[2],d[2]) > 0)) - { - // Flip vertex winding order in or_pos. - or_pos[1] = gl_PositionIn[4]; - or_pos[2] = gl_PositionIn[2]; - faces_light = false; - } - - // Near cap: simply render triangle. - emitTri(or_pos); - - // Far cap: extrude positions to infinity. - v[0] =vec4(lightpos.w * or_pos[0].xyz - lightpos.xyz,0); - v[1] =vec4(lightpos.w * or_pos[2].xyz - lightpos.xyz,0); - v[2] =vec4(lightpos.w * or_pos[1].xyz - lightpos.xyz,0); - - emitTri(v); - - // Loop over all edges and extrude if needed. - for ( int i=0; i<3; i++ ) - { - // Compute indices of neighbor triangle. - int v0 = i*2; - int nb = (i*2+1); - int v1 = (i*2+2) % 6; - cross_products(n, v0, nb, v1); - - // Compute direction to light, again as above. - d[0] =lightpos.xyz-lightpos.w*gl_PositionIn[v0].xyz; - d[1] =lightpos.xyz-lightpos.w*gl_PositionIn[nb].xyz; - d[2] =lightpos.xyz-lightpos.w*gl_PositionIn[v1].xyz; - - bool is_parallel = gl_PositionIn[nb].w < 1e-5; - - // Extrude the edge if it does not have a - // neighbor, or if it's a possible silhouette. - if (is_parallel || - ( faces_light != (dot(ns[0],d[0])>0 || - dot(ns[1],d[1])>0 || - dot(ns[2],d[2])>0) )) - { - // Make sure sides are oriented correctly. - int i0 = faces_light ? v0 : v1; - int i1 = faces_light ? v1 : v0; - - v[0] = gl_PositionIn[i0]; - v[1] = vec4(lightpos.w*gl_PositionIn[i0].xyz - lightpos.xyz, 0); - v[2] = gl_PositionIn[i1]; - v[3] = vec4(lightpos.w*gl_PositionIn[i1].xyz - lightpos.xyz, 0); - - emitQuad(v); - } - } -} - -void main() -{ - // Output - emitPrimitives(0); -} +/** + * @file depthToShadowVolumeG.glsl + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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$ + */ +#extension GL_ARB_geometry_shader4 : enable +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +layout (triangles) in; +layout (triangle_strip, max_vertices = 128) out; + +uniform sampler2DRect depthMap; +uniform mat4 shadowMatrix[6]; +uniform vec4 lightpos; + +VARYING vec2 vary_texcoord0; + +out vec3 to_vec; + +void cross_products(out vec4 ns[3], int a, int b, int c) +{ + ns[0] = cross(gl_PositionIn[b].xyz - gl_PositionIn[a].xyz, gl_PositionIn[c].xyz - gl_PositionIn[a].xyz); + ns[1] = cross(gl_PositionIn[c].xyz - gl_PositionIn[b].xyz, gl_PositionIn[a].xyz - gl_PositionIn[b].xyz); + ns[2] = cross(gl_PositionIn[a].xyz - gl_PositionIn[c].xyz, gl_PositionIn[b].xyz - gl_PositionIn[c].xyz); +} + +vec3 getLightDirection(vec4 lightpos, vec3 pos) +{ + + vec3 lightdir = lightpos.xyz - lightpos.w * pos; + return lightdir; +} + +void emitTri(vec4 v[3]) +{ + gl_Position = proj_matrix * v[0]; + EmitVertex(); + + gl_Position = proj_matrix * v[1]; + EmitVertex(); + + gl_Position = proj_matrix * v[2]; + EmitVertex(); + + EndPrimitive(); +} + +void emitQuad(vec4 v[4] +{ + // Emit a quad as a triangle strip. + gl_Position = proj_matrix*v[0]; + EmitVertex(); + + gl_Position = proj_matrix*v[1]; + EmitVertex(); + + gl_Position = proj_matrix*v[2]; + EmitVertex(); + + gl_Position = proj_matrix*v[3]; + EmitVertex(); + + EndPrimitive(); +} + +void emitPrimitives(int layer) +{ + int i = layer; + gl_Layer = i; + + vec4 depth1 = vec4(texture2DRect(depthMap, tc0).rg, texture2DRect(depthMap, tc1).rg)); + vec3 depth2 = vec4(texture2DRect(depthMap, tc2).rg, texture2DRect(depthMap, tc3).rg)); + vec3 depth3 = vec4(texture2DRect(depthMap, tc4).rg, texture2DRect(depthMap, tc5).rg)); + vec3 depth4 = vec4(texture2DRect(depthMap, tc6).rg, texture2DRect(depthMap, tc7).rg)); + + depth1 = min(depth1, depth2); + depth1 = min(depth1, depth3); + depth1 = min(depth1, depth4); + + vec2 depth = min(depth1.xy, depth1.zw); + + int side = sqrt(gl_VerticesIn); + + for (int j = 0; j < side; j++) + { + for (int k = 0; k < side; ++k) + { + vec3 pos = gl_PositionIn[(j * side) + k].xyz; + vec4 v = shadowMatrix[i] * vec4(pos, 1.0); + gl_Position = v; + to_vec = pos - light_position.xyz * depth; + EmitVertex(); + } + + EndPrimitive(); + } + + vec3 norms[3]; // Normals + vec3 lightdir3]; // Directions toward light + + vec4 v[4]; // Temporary vertices + + vec4 or_pos[3] = + { // Triangle oriented toward light source + gl_PositionIn[0], + gl_PositionIn[2], + gl_PositionIn[4] + }; + + // Compute normal at each vertex. + cross_products(n, 0, 2, 4); + + // Compute direction from vertices to light. + lightdir[0] = getLightDirection(lightpos, gl_PositionIn[0].xyz); + lightdir[1] = getLightDirection(lightpos, gl_PositionIn[2].xyz); + lightdir[2] = getLightDirection(lightpos, gl_PositionIn[4].xyz); + + // Check if the main triangle faces the light. + bool faces_light = true; + if (!(dot(ns[0],d[0]) > 0 + |dot(ns[1],d[1]) > 0 + |dot(ns[2],d[2]) > 0)) + { + // Flip vertex winding order in or_pos. + or_pos[1] = gl_PositionIn[4]; + or_pos[2] = gl_PositionIn[2]; + faces_light = false; + } + + // Near cap: simply render triangle. + emitTri(or_pos); + + // Far cap: extrude positions to infinity. + v[0] =vec4(lightpos.w * or_pos[0].xyz - lightpos.xyz,0); + v[1] =vec4(lightpos.w * or_pos[2].xyz - lightpos.xyz,0); + v[2] =vec4(lightpos.w * or_pos[1].xyz - lightpos.xyz,0); + + emitTri(v); + + // Loop over all edges and extrude if needed. + for ( int i=0; i<3; i++ ) + { + // Compute indices of neighbor triangle. + int v0 = i*2; + int nb = (i*2+1); + int v1 = (i*2+2) % 6; + cross_products(n, v0, nb, v1); + + // Compute direction to light, again as above. + d[0] =lightpos.xyz-lightpos.w*gl_PositionIn[v0].xyz; + d[1] =lightpos.xyz-lightpos.w*gl_PositionIn[nb].xyz; + d[2] =lightpos.xyz-lightpos.w*gl_PositionIn[v1].xyz; + + bool is_parallel = gl_PositionIn[nb].w < 1e-5; + + // Extrude the edge if it does not have a + // neighbor, or if it's a possible silhouette. + if (is_parallel || + ( faces_light != (dot(ns[0],d[0])>0 || + dot(ns[1],d[1])>0 || + dot(ns[2],d[2])>0) )) + { + // Make sure sides are oriented correctly. + int i0 = faces_light ? v0 : v1; + int i1 = faces_light ? v1 : v0; + + v[0] = gl_PositionIn[i0]; + v[1] = vec4(lightpos.w*gl_PositionIn[i0].xyz - lightpos.xyz, 0); + v[2] = gl_PositionIn[i1]; + v[3] = vec4(lightpos.w*gl_PositionIn[i1].xyz - lightpos.xyz, 0); + + emitQuad(v); + } + } +} + +void main() +{ + // Output + emitPrimitives(0); +} -- cgit v1.2.3 From adac468cc160eab148008861000b27df6380817c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 14 Jan 2019 11:20:31 -0800 Subject: SL-10355 Modify distortion vec calc in shader to account for modified range of reflection scale above/below. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 2acfe58e82..ceadb9fb67 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -149,7 +149,7 @@ void main() spec = pow(spec, 128.0); //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); + vec2 distort2 = distort+wavef.xy*refScale * 0.33/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); -- cgit v1.2.3 From 9de895aa03570935e49aeb5eb874444904de59e6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 15 Jan 2019 16:06:34 -0800 Subject: SL-10369 Fix handling of backfaces in shared shadow sampling broken during de-duplication. --- .../app_settings/shaders/class1/deferred/shadowUtil.glsl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index f626609fc2..70568bc75f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -120,6 +120,13 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float shadow = 0.0f; vec4 spos = vec4(shadow_pos,1.0); + + // if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup + if (dp_directional_light <= 0.0) + { + return 0.0; + } + if (spos.z > -shadow_clip.w) { vec4 lpos; @@ -174,7 +181,8 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) shadow /= weight; } - return shadow; + + return min(dp_directional_light, shadow); } float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) -- cgit v1.2.3 From 066eb59808d5649c745fdc6c37b62f2eb9a19b6f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 17 Jan 2019 08:32:09 -0800 Subject: SL-10368 Fix OSX shader compile bug from use of #if FOO instead of #ifdef FOO or #if defined(FOO) preventing atmospherics (and thus ALM) from working on OSX. --- .../app_settings/shaders/class1/deferred/attachmentShadowV.glsl | 2 +- .../newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl | 4 ++-- .../newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl | 4 ++-- .../newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl | 4 ++-- .../newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl | 4 ++-- .../app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl | 4 ++-- .../app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl | 4 ++-- .../app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl | 4 ++-- .../app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl | 4 ++-- .../newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl | 4 ++-- .../newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl | 4 ++-- .../app_settings/shaders/class3/deferred/attachmentShadowV.glsl | 6 ++---- .../newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl | 4 ++-- .../newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl | 4 ++-- .../newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl | 4 ++-- .../app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl | 4 ++-- .../app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl | 4 ++-- .../app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl | 4 ++-- .../app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl | 4 ++-- indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl | 4 ++-- indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl | 4 ++-- indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl | 2 +- 26 files changed, 49 insertions(+), 51 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl index 3f90600ace..0fa0edfd67 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl @@ -41,7 +41,7 @@ void main() vec4 p = projection_matrix * vec4(pos, 1.0); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) p.z = max(p.z, -p.w+0.01); gl_Position = p; #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl index 8e46425ea8..50020a50d8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING vec4 post_pos; #endif @@ -41,7 +41,7 @@ void main() { frag_color = vec4(1,1,1,1); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl index bde1ad4e9f..91b25613e0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl @@ -31,7 +31,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING vec4 post_pos; #endif @@ -53,7 +53,7 @@ void main() norm = normalize(norm); pos = projection_matrix * pos; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) post_pos = pos; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl index fa6926b007..d93baa03c6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl @@ -55,7 +55,7 @@ uniform vec3 sun_dir; uniform float sun_size; uniform float far_z; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING vec4 post_pos; #endif @@ -114,7 +114,7 @@ void main() frag_color = vec4(alpha1, alpha1, alpha1, 1); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl index cb27b2c2c5..effb070f93 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl @@ -31,7 +31,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif @@ -49,7 +49,7 @@ void main() pos = modelview_projection_matrix * pre_pos; target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) pos_zd2 = pos.z * 0.5; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl index 12bc690553..44f2a73e1f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif @@ -49,7 +49,7 @@ void main() frag_color = vec4(alpha, alpha, alpha, 1); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl index 11411a605c..f45c343066 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl @@ -31,7 +31,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif @@ -52,7 +52,7 @@ void main() pos_w = pos.w; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) pos_zd2 = pos.z * 0.5; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index ae1b19a35c..1791d3e315 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif @@ -62,7 +62,7 @@ void main() frag_color = vec4(1,1,1,1); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl index 11411a605c..f45c343066 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl @@ -31,7 +31,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif @@ -52,7 +52,7 @@ void main() pos_w = pos.w; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) pos_zd2 = pos.z * 0.5; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl index ef153dfc5b..0e74d2eb8a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl @@ -27,7 +27,7 @@ uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING vec4 post_pos; #endif @@ -40,7 +40,7 @@ void main() vec3 p = position*box_size+box_center; vec4 pos = modelview_projection_matrix*vec4(p.xyz, 1.0); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) post_pos = pos; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl index 242aef821d..22d42d38c1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl @@ -31,7 +31,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING vec4 post_pos; #endif @@ -39,7 +39,7 @@ void main() { frag_color = vec4(1,1,1,1); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl index cc77a4cea0..41a89fb8b4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl @@ -27,7 +27,7 @@ uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING vec4 post_pos; #endif @@ -36,7 +36,7 @@ void main() //transform vertex vec4 pos = modelview_projection_matrix*vec4(position.xyz, 1.0); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) post_pos = pos; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl index fa6926b007..d93baa03c6 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl @@ -55,7 +55,7 @@ uniform vec3 sun_dir; uniform float sun_size; uniform float far_z; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING vec4 post_pos; #endif @@ -114,7 +114,7 @@ void main() frag_color = vec4(alpha1, alpha1, alpha1, 1); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); #endif diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl index 52164e7b80..1c2fbaf25d 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl @@ -31,7 +31,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif @@ -48,7 +48,7 @@ void main() pos = modelview_projection_matrix * pre_pos; target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) pos_zd2 = pos.z * 0.5; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); #else diff --git a/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl index 3be9cb3de8..1a655e6467 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl @@ -42,10 +42,8 @@ void main() pos = (mat*vec4(position.xyz, 1.0)); pos = projection_matrix * vec4(pos.xyz, 1.0); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) pos.z = max(pos.z, -pos.w+0.01); - gl_Position = pos; -#else - gl_Position = pos; #endif + gl_Position = pos; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl index f4e5a61e36..48eefc7a73 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING vec4 post_pos; #endif @@ -45,7 +45,7 @@ void main() { frag_color = computeMoments(length(pos), 1.0); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); #endif } diff --git a/indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl index 96ca2fd707..164b355f20 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl @@ -31,7 +31,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING vec4 post_pos; #endif @@ -56,7 +56,7 @@ void main() pos = projection_matrix * pos; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) post_pos = pos; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); #else diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl index cb27b2c2c5..effb070f93 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl @@ -31,7 +31,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif @@ -49,7 +49,7 @@ void main() pos = modelview_projection_matrix * pre_pos; target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) pos_zd2 = pos.z * 0.5; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); #else diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl index 01599d81c4..345c07a354 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif @@ -52,7 +52,7 @@ void main() frag_color = computeMoments(length(pos), float a); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); #endif } diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl index 3fb2bafca4..af1461c297 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl @@ -31,7 +31,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif @@ -51,7 +51,7 @@ void main() pos_w = pos.w; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) pos_zd2 = pos.z * 0.5; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl index d6ed5b6bb0..50f1ffd626 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif @@ -67,7 +67,7 @@ void main() frag_color = computeMoments(length(pos.xyz), alpha); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); #endif diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl index bc7fe003f2..6a646f5e9e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl @@ -31,7 +31,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif @@ -51,7 +51,7 @@ void main() target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) pos_zd2 = pos.z * 0.5; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl index 923de09ada..db8c75fb8a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl @@ -27,7 +27,7 @@ uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING vec4 post_pos; #endif @@ -40,7 +40,7 @@ void main() vec3 p = position*box_size+box_center; vec4 pos = modelview_projection_matrix*vec4(p.xyz, 1.0); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) post_pos = pos; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl index 5a6c8728c0..3350267130 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl index 9a5edaf091..6577fe0ecf 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl @@ -30,7 +30,7 @@ uniform mat4 texture_matrix0; ATTRIBUTE vec3 position; ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) VARYING float pos_zd2; #endif @@ -50,7 +50,7 @@ void main() target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) pos_zd2 = pos.z * 0.5; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); diff --git a/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl index 693af31bf2..41673d1669 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl @@ -51,7 +51,7 @@ void main() frag_color = computeMoments(length(pos), 1.0); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP) gl_FragDepth = max(pos.z/pos.w*0.5+0.5, 0.0); #endif -- cgit v1.2.3 From ec8140016b991d2729b51dd1746a29fafaea5b61 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 24 Jan 2019 10:58:03 -0800 Subject: SL-10282 Use clamping on dot product to determine halo TCs to fix abrupt cutoff at dot == 0. Ifdef around engaging advanced atmo which is not ready for primetime yet. --- indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 3232f81cd9..520bfbeadc 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -70,6 +70,7 @@ uniform float ice_level; vec3 rainbow(float d) { + d = clamp(d, -1, 0); float rad = (droplet_radius - 5.0f) / 1024.0f; return pow(texture2D(rainbow_map, vec2(rad, d)).rgb, vec3(1.8)) * moisture_level; } @@ -182,8 +183,7 @@ void main() vec3 halo_22 = halo22(optic_d); - if (optic_d <= 0) - color.rgb += rainbow(optic_d); + color.rgb += rainbow(optic_d); color.rgb += halo_22; -- cgit v1.2.3 From a6f92d8190e8771d6a3372eb456dbb97c7ca0c8d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 24 Jan 2019 11:48:04 -0800 Subject: SL-10281 Use clamp on dot product of view and light norm to eliminate 2nd halo. --- indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 520bfbeadc..09ad6e70d6 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -70,14 +70,15 @@ uniform float ice_level; vec3 rainbow(float d) { - d = clamp(d, -1, 0); + d = clamp(d, -1.0, 0.0); float rad = (droplet_radius - 5.0f) / 1024.0f; return pow(texture2D(rainbow_map, vec2(rad, d)).rgb, vec3(1.8)) * moisture_level; } vec3 halo22(float d) { - float v = sqrt(max(0, 1 - (d*d))); + d = clamp(d, 0.1, 1.0); + float v = sqrt(clamp(1 - (d * d), 0, 1)); return texture2D(halo_map, vec2(0, v)).rgb * ice_level; } -- cgit v1.2.3 From 966dc7fc8fb1fade861e8070e9c5fbbfe4d0cb45 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 24 Jan 2019 14:54:11 -0800 Subject: SL-10276 SL-9851 Fix cloud shaders to ignore clouds when cloud_scale is 0. Fix creation of heavenly body geo to avoid degenerate vector math and not randomly flip orientation when crossing zenith. Add sun_up_factor to eliminate sun glow around moon when sun is down. --- .../shaders/class1/deferred/cloudShadowF.glsl | 91 ++++---- .../shaders/class1/deferred/cloudsF.glsl | 73 +++--- .../shaders/class1/deferred/cloudsV.glsl | 5 +- .../shaders/class1/deferred/moonF.glsl | 10 +- .../shaders/class1/deferred/moonV.glsl | 12 +- .../shaders/class1/windlight/cloudShadowF.glsl | 93 ++++---- .../app_settings/shaders/class2/deferred/skyF.glsl | 196 +++++++++-------- .../shaders/class2/deferred/softenLightF.glsl | 12 - .../shaders/class2/windlight/atmosphericsF.glsl | 3 + .../shaders/class2/windlight/atmosphericsV.glsl | 202 ++++++++--------- .../shaders/class2/windlight/cloudsF.glsl | 73 +++--- .../shaders/class2/windlight/cloudsV.glsl | 245 +++++++++++---------- .../shaders/class2/windlight/skyV.glsl | 4 +- .../shaders/class3/deferred/cloudShadowF.glsl | 91 ++++---- .../shaders/class3/deferred/cloudsF.glsl | 63 +++--- .../shaders/class3/deferred/cloudsV.glsl | 22 +- 16 files changed, 617 insertions(+), 578 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl index d93baa03c6..035e979827 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl @@ -69,53 +69,60 @@ vec4 cloudNoise(vec2 uv) void main() { - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; - vec2 uv3 = vary_texcoord2.xy; - float cloudDensity = 2.0 * (cloud_shadow - 0.25); + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); - vec2 uv4 = vary_texcoord3.xy; - - vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - - // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow - - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); - - cloudDensity *= 1.0 - (density_variance * density_variance); - - // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; - - if (alpha1 < 0.001f) + if (cloud_scale >= 0.0001) { - discard; + vec2 uv4 = vary_texcoord3.xy; + + vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow + + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + + cloudDensity *= 1.0 - (density_variance * density_variance); + + // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; + + if (alpha1 < 0.001f) + { + discard; + } + + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; + + frag_color = vec4(alpha1, alpha1, alpha1, 1); + } + else + { + frag_color = vec4(1); } - - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; - - frag_color = vec4(alpha1, alpha1, alpha1, 1); #if !defined(DEPTH_CLAMP) - gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); + gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index fe69233e68..60ccfa64db 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -65,60 +65,65 @@ vec4 cloudNoise(vec2 uv) void main() { - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; - vec4 cloudColorSun = vary_CloudColorSun; - vec4 cloudColorAmbient = vary_CloudColorAmbient; - float cloudDensity = vary_CloudDensity; - vec2 uv3 = vary_texcoord2.xy; - vec2 uv4 = vary_texcoord3.xy; + vec4 cloudColorSun = vary_CloudColorSun; + vec4 cloudColorAmbient = vary_CloudColorAmbient; + float cloudDensity = vary_CloudDensity; + vec2 uv3 = vary_texcoord2.xy; + vec2 uv4 = vary_texcoord3.xy; + + if (cloud_scale < 0.001) + { + discard; + } vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); cloudDensity *= 1.0 - (density_variance * density_variance); - // Compute alpha1, the main cloud opacity + // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; if (alpha1 < 0.001f) { discard; } - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; - // Combine - vec4 color; - color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); - color *= 2.; + // Combine + vec4 color; + color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); + color *= 2.; - /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); - frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0,0,1,0); + /// Gamma correct for WL (soft clip effect). + frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); + frag_data[2] = vec4(0,0,1,0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 17f425475c..fe336fc3a8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -58,6 +58,7 @@ uniform float density_multiplier; uniform float max_y; uniform vec4 glow; +uniform float sun_up_factor; uniform vec4 cloud_color; @@ -131,6 +132,8 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function + temp2.x *= sun_up_factor; + // Add "minimum anti-solar illumination" temp2.x += .25; @@ -170,7 +173,7 @@ void main() // Texture coords vary_texcoord0 = texcoord0; vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; + vary_texcoord0.xy /= max(0.001, cloud_scale); vary_texcoord0.xy += 0.5; vary_texcoord1 = vary_texcoord0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 8bf4551abc..7265275e36 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -45,8 +45,8 @@ VARYING vec2 vary_texcoord0; void main() { - vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); - vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); + vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(moonA, moonB, blend_factor); // mix factor which blends when sunlight is brighter @@ -58,8 +58,8 @@ void main() vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0 - 1.0; c.rgb = pow(c.rgb, exp); - frag_data[0] = vec4(c.rgb, c.a); - frag_data[1] = vec4(0.0); - frag_data[2] = vec4(0.0f); + frag_data[0] = vec4(c.rgb, c.a); + frag_data[1] = vec4(0.0); + frag_data[2] = vec4(0.0f); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl index 0325ecead9..0a68fc82f7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl @@ -36,13 +36,13 @@ void calcAtmospherics(vec3 eye_pos); void main() { - //transform vertex - vec4 vert = vec4(position.xyz, 1.0); - vec4 pos = (modelview_matrix * vert); + //transform vertex + vec4 vert = vec4(position.xyz, 1.0); + vec4 pos = (modelview_matrix * vert); - gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); calcAtmospherics(pos.xyz); - - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl index d93baa03c6..69a3c59cb3 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl @@ -69,53 +69,60 @@ vec4 cloudNoise(vec2 uv) void main() { - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; - vec2 uv3 = vary_texcoord2.xy; - float cloudDensity = 2.0 * (cloud_shadow - 0.25); - - vec2 uv4 = vary_texcoord3.xy; - - vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - - // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow - - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); - - cloudDensity *= 1.0 - (density_variance * density_variance); - - // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; - - if (alpha1 < 0.001f) + if (cloud_scale >= 0.0001) { - discard; + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); + + vec2 uv4 = vary_texcoord3.xy; + + vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow + + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + + cloudDensity *= 1.0 - (density_variance * density_variance); + + // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; + + if (alpha1 < 0.001f) + { + discard; + } + + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; + + frag_color = vec4(alpha1, alpha1, alpha1, 1); + } + else + { + frag_color = vec4(1); } - - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; - - frag_color = vec4(alpha1, alpha1, alpha1, 1); #if !defined(DEPTH_CLAMP) - gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); + gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); #endif } diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 09ad6e70d6..6ddd7e7c86 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -45,6 +45,7 @@ uniform float density_multiplier; uniform float max_y; uniform vec4 glow; +uniform float sun_up_factor; uniform vec4 cloud_color; @@ -88,98 +89,99 @@ vec3 scaleSoftClip(vec3 light); void main() { - // World / view / projection - // Get relative position - vec3 P = pos.xyz - camPosLocal.xyz + vec3(0,50,0); - - // Set altitude - if (P.y > 0.) - { - P *= (max_y / P.y); - } - else - { - P *= (-32000. / P.y); - } - - // Can normalize then - vec3 Pn = normalize(P); - float Plen = length(P); - - // Initialize temp variables - vec4 temp1 = vec4(0.); - vec4 temp2 = vec4(0.); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - - // Calculate relative weights - temp1 = blue_density + haze_density; - blue_weight = blue_density / temp1; - haze_weight = haze_density / temp1; - - // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Distance - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); - - - // Compute haze glow - temp2.x = dot(Pn, lightnorm.xyz); - temp2.x = 1. - temp2.x; - // temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .001); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // Add "minimum anti-solar illumination" - temp2.x += .25; - - - // Haze color above cloud - vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) - ); - - - // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; - - // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); - - // Haze color below cloud - vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) - ); - - // Final atmosphere additive - color *= (1. - temp1); - - // Attenuate cloud color by atmosphere - temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds - - // At horizon, blend high altitude sky color towards the darker color below the clouds - color += (additiveColorBelowCloud - color) * (1. - sqrt(temp1)); - + // World / view / projection + // Get relative position + vec3 P = pos.xyz - camPosLocal.xyz + vec3(0,50,0); + + // Set altitude + if (P.y > 0.) + { + P *= (max_y / P.y); + } + else + { + P *= (-32000. / P.y); + } + + // Can normalize then + vec3 Pn = normalize(P); + float Plen = length(P); + + // Initialize temp variables + vec4 temp1 = vec4(0.); + vec4 temp2 = vec4(0.); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + + // Calculate relative weights + temp1 = blue_density + haze_density; + blue_weight = blue_density / temp1; + haze_weight = haze_density / temp1; + + // Compute sunlight from P & lightnorm (for long rays like sky) + temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Distance + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z); + + + // Compute haze glow + temp2.x = dot(Pn, lightnorm.xyz); + temp2.x = 1. - temp2.x; + // temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .001); + // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + // Higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + // Add "minimum anti-solar illumination" + temp2.x += .25; + + temp2.x *= sun_up_factor; + + // Haze color above cloud + vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) + ); + + + // Increase ambient when there are more clouds + vec4 tmpAmbient = ambient; + tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + + // Dim sunlight by cloud shadow percentage + sunlight *= (1. - cloud_shadow); + + // Haze color below cloud + vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) + ); + + // Final atmosphere additive + color *= (1. - temp1); + + // Attenuate cloud color by atmosphere + temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds + + // At horizon, blend high altitude sky color towards the darker color below the clouds + color += (additiveColorBelowCloud - color) * (1. - sqrt(temp1)); + float optic_d = dot(Pn, lightnorm.xyz); vec3 halo_22 = halo22(optic_d); @@ -188,11 +190,11 @@ void main() color.rgb += halo_22; - color *= 2.; + color *= 2.; - /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); - frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog + /// Gamma correct for WL (soft clip effect). + frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); + frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index c5d317ad37..c80e7fce18 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -48,21 +48,9 @@ uniform float blur_fidelity; uniform vec4 morphFactor; uniform vec3 camPosLocal; //uniform vec4 camPosWorld; -uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 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 vec4 glow; uniform float global_gamma; -uniform float scene_light_strength; uniform mat3 env_mat; uniform vec4 shadow_clip; uniform mat3 ssao_effect_mat; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 2a629f4f42..5cf3cd1dd2 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -42,6 +42,7 @@ uniform vec4 glow; uniform float scene_light_strength; uniform mat3 ssao_effect_mat; uniform int no_atmo; +uniform float sun_up_factor; vec3 scaleSoftClipFrag(vec3 light); @@ -117,6 +118,8 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, //add "minimum anti-solar illumination" temp2.x += .25; + + temp2.x *= sun_up_factor; //increase ambient when there are more clouds vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index 7a6bcd53a1..8c1a7c6281 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -54,110 +54,112 @@ uniform float density_multiplier; uniform float distance_multiplier; uniform float max_y; uniform vec4 glow; +uniform float sun_up_factor; void calcAtmospherics(vec3 inPositionEye) { - vec3 P = inPositionEye; - setPositionEye(P); - - //(TERRAIN) limit altitude - if (P.y > max_y) P *= (max_y / P.y); - if (P.y < -max_y) P *= (-max_y / P.y); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(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 - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - //vary_AtmosAttenuation = distance_multiplier / 10000.; - //vary_AtmosAttenuation = density_multiplier * 100.; - //vary_AtmosAttenuation = vec4(Plen / 100000., 0., 0., 1.); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - vec3 additive = - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient)); + vec3 P = inPositionEye; + setPositionEye(P); + + //(TERRAIN) limit altitude + if (P.y > max_y) P *= (max_y / P.y); + if (P.y < -max_y) P *= (-max_y / P.y); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(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 + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + setAtmosAttenuation(temp1.rgb); + //vary_AtmosAttenuation = distance_multiplier / 10000.; + //vary_AtmosAttenuation = density_multiplier * 100.; + //vary_AtmosAttenuation = vec4(Plen / 100000., 0., 0., 1.); + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + temp2.x *= sun_up_factor; + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + vec3 additive = + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient)); additive = normalize(additive); - //haze color - //setAdditiveColor( - // vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - // + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - // + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(additive * vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5); - - // vary_SunlitColor = vec3(0); - // vary_AmblitColor = vec3(0); - // vary_AdditiveColor = vec4(Pn, 1.0); - - /* - const float cloudShadowScale = 100.; - // Get cloud uvs for shadowing - vec3 cloudPos = inPositionEye + camPosWorld - cloudShadowScale / 2.; - vary_CloudUVs.xy = cloudPos.xz / cloudShadowScale; - - // We can take uv1 and multiply it by (TerrainSpan / CloudSpan) -// cloudUVs *= (((worldMaxZ - worldMinZ) * 20) /40000.); - vary_CloudUVs *= (10000./40000.); - - // Offset by sun vector * (CloudAltitude / CloudSpan) - vary_CloudUVs.x += tmpLightnorm.x / tmpLightnorm.y * (3000./40000.); - vary_CloudUVs.y += tmpLightnorm.z / tmpLightnorm.y * (3000./40000.); - */ + //haze color + //setAdditiveColor( + // vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + // + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + // + tmpAmbient))); + + //brightness of surface both sunlight and ambient + setSunlitColor(vec3(sunlight * .5)); + setAmblitColor(vec3(tmpAmbient * .25)); + setAdditiveColor(additive * vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5); + + // vary_SunlitColor = vec3(0); + // vary_AmblitColor = vec3(0); + // vary_AdditiveColor = vec4(Pn, 1.0); + + /* + const float cloudShadowScale = 100.; + // Get cloud uvs for shadowing + vec3 cloudPos = inPositionEye + camPosWorld - cloudShadowScale / 2.; + vary_CloudUVs.xy = cloudPos.xz / cloudShadowScale; + + // We can take uv1 and multiply it by (TerrainSpan / CloudSpan) +// cloudUVs *= (((worldMaxZ - worldMinZ) * 20) /40000.); + vary_CloudUVs *= (10000./40000.); + + // Offset by sun vector * (CloudAltitude / CloudSpan) + vary_CloudUVs.x += tmpLightnorm.x / tmpLightnorm.y * (3000./40000.); + vary_CloudUVs.y += tmpLightnorm.z / tmpLightnorm.y * (3000./40000.); + */ } diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index e3fa431ddf..93024bf4e7 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -66,60 +66,65 @@ vec4 cloudNoise(vec2 uv) void main() { - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; - vec4 cloudColorSun = vary_CloudColorSun; - vec4 cloudColorAmbient = vary_CloudColorAmbient; - float cloudDensity = vary_CloudDensity; - vec2 uv3 = vary_texcoord2.xy; - vec2 uv4 = vary_texcoord3.xy; + vec4 cloudColorSun = vary_CloudColorSun; + vec4 cloudColorAmbient = vary_CloudColorAmbient; + float cloudDensity = vary_CloudDensity; + vec2 uv3 = vary_texcoord2.xy; + vec2 uv4 = vary_texcoord3.xy; + + if (cloud_scale < 0.001) + { + discard; + } vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); cloudDensity *= 1.0 - (density_variance * density_variance); - // Compute alpha1, the main cloud opacity + // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; if (alpha1 < 0.001f) { discard; } - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; - // Combine - vec4 color; - color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); - color *= 2.; + // Combine + vec4 color; + color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); + color *= 2.; - /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); - frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0,0,1,0); + /// Gamma correct for WL (soft clip effect). + frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); + frag_data[2] = vec4(0,0,1,0); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index c1dd45cd67..644cd5a35b 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -57,6 +57,7 @@ uniform float density_multiplier; uniform float max_y; uniform vec4 glow; +uniform float sun_up_factor; uniform vec4 cloud_color; @@ -65,126 +66,128 @@ uniform float cloud_scale; void main() { - // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - - vary_texcoord0 = texcoord0; - - // Get relative position - vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); - - // Set altitude - if (P.y > 0.) - { - P *= (max_y / P.y); - } - else - { - P *= (-32000. / P.y); - } - - // Can normalize then - vec3 Pn = normalize(P); - float Plen = length(P); - - // Initialize temp variables - vec4 temp1 = vec4(0.); - vec4 temp2 = vec4(0.); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - - // Calculate relative weights - temp1 = blue_density + haze_density; - blue_weight = blue_density / temp1; - haze_weight = haze_density / temp1; - - // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Distance - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); - - - // Compute haze glow - temp2.x = dot(Pn, lightnorm.xyz); - temp2.x = 1. - temp2.x; - // temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .001); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // Add "minimum anti-solar illumination" - temp2.x += .25; - - // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; - - // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); - - // Haze color below cloud - vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) - ); - - // CLOUDS - - sunlight = sunlight_color; - temp2.y = max(0., lightnorm.y * 2.); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Cloud color out - vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; - vary_CloudColorAmbient = tmpAmbient * cloud_color; - - // Attenuate cloud color by atmosphere - temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds - vary_CloudColorSun *= temp1; - vary_CloudColorAmbient *= temp1; - vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); - - // Make a nice cloud density based on the cloud_shadow value that was passed in. - vary_CloudDensity = 2. * (cloud_shadow - 0.25); - - - // Texture coords - vary_texcoord0 = texcoord0; - vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; - vary_texcoord0.xy += 0.5; - - vary_texcoord1 = vary_texcoord0; - vary_texcoord1.x += lightnorm.x * 0.0125; - vary_texcoord1.y += lightnorm.z * 0.0125; - - vary_texcoord2 = vary_texcoord0 * 16.; - vary_texcoord3 = vary_texcoord1 * 16.; - - // Combine these to minimize register use - vary_CloudColorAmbient += oHazeColorBelowCloud; - - // needs this to compile on mac - //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); - - // END CLOUDS + // World / view / projection + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + + vary_texcoord0 = texcoord0; + + // Get relative position + vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); + + // Set altitude + if (P.y > 0.) + { + P *= (max_y / P.y); + } + else + { + P *= (-32000. / P.y); + } + + // Can normalize then + vec3 Pn = normalize(P); + float Plen = length(P); + + // Initialize temp variables + vec4 temp1 = vec4(0.); + vec4 temp2 = vec4(0.); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + + // Calculate relative weights + temp1 = blue_density + haze_density; + blue_weight = blue_density / temp1; + haze_weight = haze_density / temp1; + + // Compute sunlight from P & lightnorm (for long rays like sky) + temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Distance + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z); + + + // Compute haze glow + temp2.x = dot(Pn, lightnorm.xyz); + temp2.x = 1. - temp2.x; + // temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .001); + // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + // Higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + temp2.x *= sun_up_factor; + + // Add "minimum anti-solar illumination" + temp2.x += .25; + + // Increase ambient when there are more clouds + vec4 tmpAmbient = ambient; + tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + + // Dim sunlight by cloud shadow percentage + sunlight *= (1. - cloud_shadow); + + // Haze color below cloud + vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) + ); + + // CLOUDS + + sunlight = sunlight_color; + temp2.y = max(0., lightnorm.y * 2.); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Cloud color out + vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; + vary_CloudColorAmbient = tmpAmbient * cloud_color; + + // Attenuate cloud color by atmosphere + temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds + vary_CloudColorSun *= temp1; + vary_CloudColorAmbient *= temp1; + vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); + + // Make a nice cloud density based on the cloud_shadow value that was passed in. + vary_CloudDensity = 2. * (cloud_shadow - 0.25); + + + // Texture coords + vary_texcoord0 = texcoord0; + vary_texcoord0.xy -= 0.5; + vary_texcoord0.xy /= max(0.001, cloud_scale); + vary_texcoord0.xy += 0.5; + + vary_texcoord1 = vary_texcoord0; + vary_texcoord1.x += lightnorm.x * 0.0125; + vary_texcoord1.y += lightnorm.z * 0.0125; + + vary_texcoord2 = vary_texcoord0 * 16.; + vary_texcoord3 = vary_texcoord1 * 16.; + + // Combine these to minimize register use + vary_CloudColorAmbient += oHazeColorBelowCloud; + + // needs this to compile on mac + //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); + + // END CLOUDS } diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index 3788ddaf2d..04cf4052b8 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -50,7 +50,7 @@ uniform float density_multiplier; uniform float max_y; uniform vec4 glow; - +uniform float sun_up_factor; uniform vec4 cloud_color; void main() @@ -119,6 +119,8 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function + temp2.x *= sun_up_factor; + // Add "minimum anti-solar illumination" temp2.x += .25; diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl index 65af2821be..95d5b52b45 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl @@ -67,48 +67,55 @@ vec4 computeMoments(float depth, float alpha); void main() { - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; - vec2 uv3 = vary_texcoord2.xy; - float cloudDensity = 2.0 * (cloud_shadow - 0.25); - - vec2 uv4 = vary_texcoord3.xy; - - vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - - // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow - - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); - - cloudDensity *= 1.0 - (density_variance * density_variance); - - // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; - - if (alpha1 < 0.001f) + if (cloud_scale >= 0.001) { - discard; + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); + + vec2 uv4 = vary_texcoord3.xy; + + vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow + + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + + cloudDensity *= 1.0 - (density_variance * density_variance); + + // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; + + if (alpha1 < 0.001f) + { + discard; + } + + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; + + frag_color = computeMoments(length(pos), alpha1); + } + else + { + frag_color = vec4(0); } - - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; - - frag_color = computeMoments(length(pos), alpha1); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl index 015caad749..c111456782 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -81,47 +81,52 @@ vec4 cloudNoise(vec2 uv) void main() { - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; - vec2 uv3 = vary_texcoord2.xy; - float cloudDensity = 2.0 * (cloud_shadow - 0.25); + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); - vec2 uv4 = vary_texcoord3.xy; + if (cloud_scale < 0.001) + { + discard; + } + + vec2 uv4 = vary_texcoord3.xy; vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - // Offset texture coords - uv1 += cloud_pos_density1.xy + disturbance; //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow + // Offset texture coords + uv1 += cloud_pos_density1.xy + disturbance; //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0)); cloudDensity *= 1.0 - (density_variance * density_variance); - // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; if (alpha1 < 0.001f) { discard; } - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; vec3 view_ray = vary_pos.xyz + camPosLocal; @@ -135,8 +140,8 @@ void main() vec3 sun_color = vec3(1.0) - exp(-radiance_sun * 0.0001); - // Combine - vec4 color; + // Combine + vec4 color; vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); @@ -156,8 +161,8 @@ void main() color.rgb = pow(color.rgb, vec3(1.0 / 2.2)); color.rgb += amb; - frag_data[0] = vec4(color.rgb, alpha1); - frag_data[1] = vec4(0); - frag_data[2] = vec4(0,1,0,1); + frag_data[0] = vec4(color.rgb, alpha1); + frag_data[1] = vec4(0); + frag_data[2] = vec4(0,1,0,1); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl index 53b6d88ef5..71e422ddf0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl @@ -49,22 +49,22 @@ void main() { vary_pos = position; - // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + // World / view / projection + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - // Texture coords - vary_texcoord0 = texcoord0; - vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; + // Texture coords + vary_texcoord0 = texcoord0; + vary_texcoord0.xy -= 0.5; + vary_texcoord0.xy /= max(0.001, cloud_scale); vary_texcoord0.xy += 0.5; - vary_texcoord1 = vary_texcoord0; - vary_texcoord1.x += lightnorm.x * 0.0125; + vary_texcoord1 = vary_texcoord0; + vary_texcoord1.x += lightnorm.x * 0.0125; vary_texcoord1.y += lightnorm.z * 0.0125; - vary_texcoord2 = vary_texcoord0 * 16.; - vary_texcoord3 = vary_texcoord1 * 16.; + vary_texcoord2 = vary_texcoord0 * 16.; + vary_texcoord3 = vary_texcoord1 * 16.; - // END CLOUDS + // END CLOUDS } -- cgit v1.2.3 From 88d4d85711a25772f3659850902e3a395ef2358c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 25 Jan 2019 10:34:42 -0800 Subject: SL-10303 Modify sun disc shader to better position itself within the sun glow and to fade as the sun approaches the horizon (to mask where the position difference is greatest). --- .../app_settings/shaders/class1/deferred/sunDiscF.glsl | 14 +++++++++----- .../app_settings/shaders/class1/deferred/sunDiscV.glsl | 16 ++++++++++------ .../app_settings/shaders/class1/windlight/sunDiscF.glsl | 11 +++++++---- .../app_settings/shaders/class1/windlight/sunDiscV.glsl | 14 ++++++++------ .../shaders/class2/windlight/atmosphericsV.glsl | 4 ++-- 5 files changed, 36 insertions(+), 23 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index 3557c0766e..c66f3f62b2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -40,17 +40,21 @@ uniform sampler2D diffuseMap; uniform sampler2D altDiffuseMap; uniform float blend_factor; // interp factor between sunDisc A/B VARYING vec2 vary_texcoord0; +VARYING float sun_fade; void main() { - vec4 sunDiscA = texture2D(diffuseMap, vary_texcoord0.xy); - vec4 sunDiscB = texture2D(altDiffuseMap, vary_texcoord0.xy); + vec4 sunDiscA = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 sunDiscB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(sunDiscA, sunDiscB, blend_factor); c.rgb = clamp(c.rgb, vec3(0), vec3(1)); - c.rgb = pow(c.rgb, vec3(0.7f)); - c.rgb = fullbrightAtmosTransport(c.rgb); + c.rgb = pow(c.rgb, vec3(0.7f)); + c.rgb = fullbrightAtmosTransport(c.rgb); c.rgb = fullbrightScaleSoftClip(c.rgb); - frag_data[0] = c; + + c.a *= sun_fade; + + frag_data[0] = c; frag_data[1] = vec4(0.0f); frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl index c67ed8e6d9..0d117c6bc7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl @@ -31,18 +31,22 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec2 texcoord0; VARYING vec2 vary_texcoord0; +VARYING float sun_fade; void calcAtmospherics(vec3 eye_pos); void main() { - //transform vertex - vec4 vert = vec4(position.xyz - vec3(0, 0, 50), 1.0); - vec4 pos = modelview_projection_matrix*vert; + //transform vertex + vec3 offset = vec3(0, 0, 50); + vec4 vert = vec4(position.xyz - offset, 1.0); + vec4 pos = modelview_projection_matrix*vert; - gl_Position = pos; - + sun_fade = smoothstep(0.3, 1.0, (position.z + 50) / 512.0f); + + gl_Position = pos; + calcAtmospherics(pos.xyz); - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl index 3f2375ee4d..668379164d 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl @@ -40,15 +40,18 @@ uniform sampler2D diffuseMap; uniform sampler2D altDiffuseMap; uniform float blend_factor; // interp factor between sun A/B VARYING vec2 vary_texcoord0; +VARYING float sun_fade; void main() { - vec4 sunA = texture2D(diffuseMap, vary_texcoord0.xy); - vec4 sunB = texture2D(altDiffuseMap, vary_texcoord0.xy); + vec4 sunA = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 sunB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(sunA, sunB, blend_factor); + c.a *= sun_fade; + c.rgb = pow(c.rgb, vec3(0.7f)); - c.rgb = fullbrightAtmosTransport(c.rgb); + c.rgb = fullbrightAtmosTransport(c.rgb); c.rgb = fullbrightScaleSoftClip(c.rgb); - frag_color = c; + frag_color = c; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl index dd33a4be60..1fa32c3f3b 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl @@ -31,18 +31,20 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec2 texcoord0; VARYING vec2 vary_texcoord0; +VARYING float sun_fade; void calcAtmospherics(vec3 eye_pos); void main() { - //transform vertex - vec4 vert = vec4(position.xyz - vec3(0, 0, 50), 1.0); - vec4 pos = modelview_projection_matrix*vert; + //transform vertex + vec4 vert = vec4(position.xyz, 1.0); + vec4 pos = modelview_projection_matrix*vert; - gl_Position = pos; - + sun_fade = smoothstep(0.3, 1.0, (position.z + 50) / 512.0f); + gl_Position = pos; + calcAtmospherics(pos.xyz); - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index 8c1a7c6281..5ccf786fce 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -62,8 +62,8 @@ void calcAtmospherics(vec3 inPositionEye) { setPositionEye(P); //(TERRAIN) limit altitude - if (P.y > max_y) P *= (max_y / P.y); - if (P.y < -max_y) P *= (-max_y / P.y); + //if (P.y > max_y) P *= (max_y / P.y); + //if (P.y < -max_y) P *= (-max_y / P.y); vec3 tmpLightnorm = lightnorm.xyz; -- cgit v1.2.3 From 431a26c118ec0dea154a2fb2c93ae96ae41b3d7b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 25 Jan 2019 16:29:05 -0800 Subject: SL-10303, SL-10414 Fix positioning of sun/moon discs w.r.t atmo haze glow. Disable killing glow when sun is not up. --- .../app_settings/shaders/class1/deferred/cloudsV.glsl | 2 +- .../app_settings/shaders/class1/deferred/moonV.glsl | 5 +++-- .../app_settings/shaders/class1/windlight/moonV.glsl | 17 +++++++++-------- .../app_settings/shaders/class1/windlight/sunDiscV.glsl | 3 ++- .../app_settings/shaders/class2/deferred/skyF.glsl | 2 +- .../shaders/class2/windlight/atmosphericsF.glsl | 2 +- .../app_settings/shaders/class2/windlight/cloudsV.glsl | 2 +- .../app_settings/shaders/class2/windlight/skyV.glsl | 2 +- 8 files changed, 19 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index fe336fc3a8..baf54c1fbe 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -132,7 +132,7 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function - temp2.x *= sun_up_factor; + //temp2.x *= sun_up_factor; // Add "minimum anti-solar illumination" temp2.x += .25; diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl index 0a68fc82f7..e1bac4f248 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl @@ -37,10 +37,11 @@ void calcAtmospherics(vec3 eye_pos); void main() { //transform vertex - vec4 vert = vec4(position.xyz, 1.0); + vec3 offset = vec3(0, 0, 50); + vec4 vert = vec4(position.xyz - offset, 1.0); vec4 pos = (modelview_matrix * vert); - gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + gl_Position = modelview_projection_matrix*vert; calcAtmospherics(pos.xyz); diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl index aaa6768ed7..1c43a7332e 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl @@ -36,13 +36,14 @@ VARYING vec2 vary_texcoord0; void main() { - //transform vertex - vec4 vert = vec4(position.xyz, 1.0); - vec4 pos = (modelview_matrix * vert); + //transform vertex + vec3 offset = vec3(0, 0, 50); + vec4 vert = vec4(position.xyz - offset, 1.0); + vec4 pos = (modelview_matrix * vert); - gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); - - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - - calcAtmospherics(pos.xyz); + gl_Position = modelview_projection_matrix*vert; + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + + calcAtmospherics(pos.xyz); } diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl index 1fa32c3f3b..ca116628f1 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl @@ -38,7 +38,8 @@ void calcAtmospherics(vec3 eye_pos); void main() { //transform vertex - vec4 vert = vec4(position.xyz, 1.0); + vec3 offset = vec3(0, 0, 50); + vec4 vert = vec4(position.xyz - offset, 1.0); vec4 pos = modelview_projection_matrix*vert; sun_fade = smoothstep(0.3, 1.0, (position.z + 50) / 512.0f); diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 6ddd7e7c86..792aa4e85c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -153,7 +153,7 @@ void main() // Add "minimum anti-solar illumination" temp2.x += .25; - temp2.x *= sun_up_factor; + //temp2.x *= sun_up_factor; // Haze color above cloud vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient) diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 5cf3cd1dd2..8d1e5e3281 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -119,7 +119,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, //add "minimum anti-solar illumination" temp2.x += .25; - temp2.x *= sun_up_factor; + //temp2.x *= sun_up_factor; //increase ambient when there are more clouds vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index 644cd5a35b..a250cf2c45 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -131,7 +131,7 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function - temp2.x *= sun_up_factor; + //temp2.x *= sun_up_factor; // Add "minimum anti-solar illumination" temp2.x += .25; diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index 04cf4052b8..f509f9f8d4 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -119,7 +119,7 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function - temp2.x *= sun_up_factor; + //temp2.x *= sun_up_factor; // Add "minimum anti-solar illumination" temp2.x += .25; -- cgit v1.2.3 From 8cb026377e1f790ba333870e2d613e0b55a4311c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 29 Jan 2019 09:12:58 -0800 Subject: SL-10415 Tweak application of shadow bias to balance between shadow acne and Peter-panning by using light_dir z value, per-split bias multiplier, and better jitter noise method. Also tweak impl of spot shadow sampling func to work around issues with Intel HD shader compiler which crashes with Intel HD 3000 driver 4459 due to shadow map array access with index using math (kwality). --- .../shaders/class1/deferred/shadowUtil.glsl | 63 ++++++++++------------ 1 file changed, 28 insertions(+), 35 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 70568bc75f..747f1dacdd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -48,44 +48,28 @@ uniform float shadow_bias; uniform float spot_shadow_bias; uniform float spot_shadow_offset; - +uniform float sun_up_factor; uniform mat4 inv_proj; uniform vec2 screen_res; vec3 decode_normal(vec2 enc); -float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias; - - stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - return shadow*0.2; -} - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { stc.xyz /= stc.w; - stc.z += shadow_bias * bias_scale; - - stc.x = floor(stc.x*pos_screen.x + fract(stc.y*pos_screen.y*0.666666666))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + stc.z += max(0.5, light_dir.z) * shadow_bias * 8.0 * bias_mul; + + stc.x = floor(stc.x*shadow_res.x + fract(stc.y*pos_screen.y*3.14159))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; + float shadow = cs * 4.0; + shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - return shadow*0.2; + + return shadow*0.125; } float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) @@ -111,10 +95,10 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) { float dp_sun = max(0.0, dot(sun_dir.xyz, norm)); float dp_moon = max(0.0, dot(moon_dir.xyz, norm)); - float dp_directional_light = max(dp_sun,dp_moon); + float dp_directional_light = (sun_up_factor > 0) ? dp_sun : dp_moon; dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); - vec3 light_dir = (dp_moon > dp_sun) ? moon_dir : sun_dir; + vec3 light_dir = (sun_up_factor > 0) ? sun_dir : moon_dir; vec3 offset = light_dir * (1.0-dp_directional_light); vec3 shadow_pos = pos.xyz + (offset * shadow_bias); @@ -141,7 +125,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap3, lpos)*w; + shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen, light_dir)*w; weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } @@ -153,7 +137,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap2, lpos)*w; + shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen, light_dir)*w; weight += w; } @@ -164,7 +148,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadowLegacy(shadowMap1, lpos)*w; + shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen, light_dir)*w; weight += w; } @@ -175,14 +159,15 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - shadow += pcfShadowLegacy(shadowMap0, lpos)*w; + shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } shadow /= weight; } - return min(dp_directional_light, shadow); + shadow = min(dp_directional_light, shadow); + return shadow; } float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) @@ -201,11 +186,19 @@ float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) float weight = 0.0; { - lpos = shadow_matrix[4 + index]*spos; float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - - shadow += pcfSpotShadow((index == 0) ? shadowMap4 : shadowMap5, lpos, 0.8, spos.xy)*w; + + if (index == 0) + { + lpos = shadow_matrix[4]*spos; + shadow += pcfSpotShadow(shadowMap4, lpos, 0.8, spos.xy)*w; + } + else + { + lpos = shadow_matrix[5]*spos; + shadow += pcfSpotShadow(shadowMap5, lpos, 0.8, spos.xy)*w; + } weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } -- cgit v1.2.3 From 38f69533780943b432edaac212475bea5fd013b6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 29 Jan 2019 16:18:16 -0800 Subject: Roll back fix for 10415 due to knock-on that must needs be tamped down. --- .../shaders/class1/deferred/shadowUtil.glsl | 63 ++++++++++++---------- 1 file changed, 35 insertions(+), 28 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 747f1dacdd..70568bc75f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -48,28 +48,44 @@ uniform float shadow_bias; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -uniform float sun_up_factor; + uniform mat4 inv_proj; uniform vec2 screen_res; vec3 decode_normal(vec2 enc); -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) +float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc) +{ + stc.xyz /= stc.w; + stc.z += shadow_bias; + + stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + + return shadow*0.2; +} + +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) { stc.xyz /= stc.w; - stc.z += max(0.5, light_dir.z) * shadow_bias * 8.0 * bias_mul; - - stc.x = floor(stc.x*shadow_res.x + fract(stc.y*pos_screen.y*3.14159))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + stc.z += shadow_bias * bias_scale; + + stc.x = floor(stc.x*pos_screen.x + fract(stc.y*pos_screen.y*0.666666666))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs * 4.0; - + float shadow = cs; shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - return shadow*0.125; + return shadow*0.2; } float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) @@ -95,10 +111,10 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) { float dp_sun = max(0.0, dot(sun_dir.xyz, norm)); float dp_moon = max(0.0, dot(moon_dir.xyz, norm)); - float dp_directional_light = (sun_up_factor > 0) ? dp_sun : dp_moon; + float dp_directional_light = max(dp_sun,dp_moon); dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); - vec3 light_dir = (sun_up_factor > 0) ? sun_dir : moon_dir; + vec3 light_dir = (dp_moon > dp_sun) ? moon_dir : sun_dir; vec3 offset = light_dir * (1.0-dp_directional_light); vec3 shadow_pos = pos.xyz + (offset * shadow_bias); @@ -125,7 +141,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen, light_dir)*w; + shadow += pcfShadowLegacy(shadowMap3, lpos)*w; weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } @@ -137,7 +153,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen, light_dir)*w; + shadow += pcfShadowLegacy(shadowMap2, lpos)*w; weight += w; } @@ -148,7 +164,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen, light_dir)*w; + shadow += pcfShadowLegacy(shadowMap1, lpos)*w; weight += w; } @@ -159,15 +175,14 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen, light_dir)*w; + shadow += pcfShadowLegacy(shadowMap0, lpos)*w; weight += w; } shadow /= weight; } - shadow = min(dp_directional_light, shadow); - return shadow; + return min(dp_directional_light, shadow); } float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) @@ -186,19 +201,11 @@ float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) float weight = 0.0; { + lpos = shadow_matrix[4 + index]*spos; float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - - if (index == 0) - { - lpos = shadow_matrix[4]*spos; - shadow += pcfSpotShadow(shadowMap4, lpos, 0.8, spos.xy)*w; - } - else - { - lpos = shadow_matrix[5]*spos; - shadow += pcfSpotShadow(shadowMap5, lpos, 0.8, spos.xy)*w; - } + + shadow += pcfSpotShadow((index == 0) ? shadowMap4 : shadowMap5, lpos, 0.8, spos.xy)*w; weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } -- cgit v1.2.3 From acbc7f4cddd6ad999c2bc7690c10b85a414a8102 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 30 Jan 2019 08:37:07 -0800 Subject: SL-10415, SL-10434 Further tweaking of directional shadow sampling to balance between peter-panning and shadow acne. Move stars to just this side of the sky some to reduce parallax. Remove decodeNormF and uses of decode_normal in favor of unified use of getNorm (try to help the Intel HD x000 compiler learn to link correctly). --- .../shaders/class1/deferred/alphaF.glsl | 2 - .../shaders/class1/deferred/blurLightF.glsl | 1 - .../shaders/class1/deferred/deferredUtil.glsl | 12 +- .../shaders/class1/deferred/materialF.glsl | 2 - .../shaders/class1/deferred/multiPointLightF.glsl | 9 +- .../shaders/class1/deferred/multiSpotLightF.glsl | 10 +- .../shaders/class1/deferred/pointLightF.glsl | 127 ++++++++++----------- .../shaders/class1/deferred/shadowUtil.glsl | 60 +++++----- .../shaders/class1/deferred/softenLightF.glsl | 18 +-- .../shaders/class1/deferred/spotLightF.glsl | 4 +- .../shaders/class1/deferred/sunLightSSAOF.glsl | 4 +- .../shaders/class2/deferred/multiSpotLightF.glsl | 4 +- .../shaders/class2/deferred/softenLightF.glsl | 24 ++-- .../shaders/class2/deferred/spotLightF.glsl | 4 +- .../shaders/class2/deferred/sunLightF.glsl | 1 - .../shaders/class2/deferred/sunLightSSAOF.glsl | 1 - .../shaders/class3/deferred/deferredUtil.glsl | 14 ++- .../shaders/class3/deferred/multiSpotLightF.glsl | 4 +- .../shaders/class3/deferred/softenLightF.glsl | 3 +- .../shaders/class3/deferred/spotLightF.glsl | 4 +- .../shaders/class3/deferred/sunLightF.glsl | 1 - 21 files changed, 147 insertions(+), 162 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 132364882b..f1b7a1312f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -71,7 +71,6 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); #endif vec2 encode_normal (vec3 n); -vec3 decode_normal (vec2 enc); vec3 scaleSoftClip(vec3 l); vec3 atmosFragAmbient(vec3 light, vec3 sunlit); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); @@ -170,7 +169,6 @@ void main() calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); vec2 abnormal = encode_normal(norm.xyz); - norm.xyz = decode_normal(abnormal.xy); float sun_da = dot(norm.xyz, sun_dir.xyz); float moon_da = dot(norm.xyz, moon_dir.xyz); diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index 812f375f42..596d0274af 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -46,7 +46,6 @@ VARYING vec2 vary_fragcoord; vec4 getPosition(vec2 pos_screen); vec3 getNorm(vec2 pos_screen); -vec3 decode_normal (vec2 enc); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index 9d7a7f6556..e27bbce094 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -29,8 +29,6 @@ uniform sampler2DRect depthMap; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 decode_normal(vec2 enc); - vec2 getScreenCoordinate(vec2 screenpos) { vec2 sc = screenpos.xy * 2.0; @@ -43,8 +41,14 @@ vec2 getScreenCoordinate(vec2 screenpos) vec3 getNorm(vec2 screenpos) { - vec2 enc_norm = texture2DRect(normalMap, screenpos.xy).xy; - return decode_normal(enc_norm); + vec2 enc = texture2DRect(normalMap, screenpos.xy).xy; + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; } float getDepth(vec2 pos_screen) diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 0f7c514e94..09bb6c5bb8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -183,7 +183,6 @@ VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; vec2 encode_normal(vec3 n); -vec3 decode_normal (vec2 enc); void main() { @@ -227,7 +226,6 @@ void main() norm.xyz = normalize(norm.xyz); vec2 abnormal = encode_normal(norm.xyz); - norm.xyz = decode_normal(abnormal.xy); vec4 final_color = diffcol; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index e8eef9b94b..29298d7c07 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -36,7 +36,6 @@ out vec4 frag_color; uniform sampler2DRect depthMap; uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; -uniform sampler2DRect normalMap; uniform samplerCube environmentMap; uniform sampler2D noiseMap; uniform sampler2D lightFunc; @@ -57,9 +56,8 @@ uniform float far_z; uniform mat4 inv_proj; -vec3 decode_normal (vec2 enc); - vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); void main() { @@ -70,9 +68,8 @@ void main() discard; } - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - norm = decode_normal(norm.xy); // unpack norm - norm = normalize(norm); + vec3 norm = getNorm(frag.xy); + vec4 spec = texture2DRect(specularRect, frag.xy); vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 7438fac8fc..24804c3011 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -71,8 +71,7 @@ VARYING vec4 vary_fragcoord; uniform vec2 screen_res; uniform mat4 inv_proj; - -vec3 decode_normal (vec2 enc); +vec3 getNorm(vec2 pos_screen); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { @@ -141,12 +140,9 @@ void main() discard; } - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - float envIntensity = norm.z; + float envIntensity = texture2DRect(normalMap. frag.xy).z; + vec3 norm = getNorm(frag.xy); - norm = decode_normal(norm.xy); - - norm = normalize(norm); float l_dist = -dot(lv, proj_n); vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index df48a66fab..f8264d971c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -56,76 +56,75 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; -vec3 decode_normal (vec2 enc); +vec3 getNorm(vec2 pos_screen); vec4 getPosition(vec2 pos_screen); void main() { - vec4 frag = vary_fragcoord; - frag.xyz /= frag.w; - frag.xyz = frag.xyz*0.5+0.5; - frag.xy *= screen_res; - - vec3 pos = getPosition(frag.xy).xyz; - vec3 lv = trans_center.xyz-pos; - float dist = length(lv); - dist /= size; - if (dist > 1.0) - { - discard; - } - - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - norm = decode_normal(norm.xy); // unpack norm - float da = dot(norm, lv); - if (da < 0.0) - { - discard; - } - - norm = normalize(norm); - lv = normalize(lv); - da = dot(norm, lv); - - float noise = texture2D(noiseMap, frag.xy/128.0).b; - - vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; - float fa = falloff+1.0; - 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; - - float lit = da * dist_atten * noise; + vec4 frag = vary_fragcoord; + frag.xyz /= frag.w; + frag.xyz = frag.xyz*0.5+0.5; + frag.xy *= screen_res; + + vec3 pos = getPosition(frag.xy).xyz; + vec3 lv = trans_center.xyz-pos; + float dist = length(lv); + dist /= size; + if (dist > 1.0) + { + discard; + } + + vec3 norm = getNorm(frag.xy); - col = color.rgb*lit*col; + float da = dot(norm, lv); + if (da < 0.0) + { + discard; + } + + lv = normalize(lv); + da = dot(norm, lv); + + float noise = texture2D(noiseMap, frag.xy/128.0).b; + + vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; + float fa = falloff+1.0; + 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; + + float lit = da * dist_atten * noise; - vec4 spec = texture2DRect(specularRect, frag.xy); - if (spec.a > 0.0) - { - lit = min(da*6.0, 1.0) * dist_atten; + col = color.rgb*lit*col; - vec3 npos = -normalize(pos); - vec3 h = normalize(lv+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5) * 0.4+0.5; - float gtdenom = 2 * nh; - float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh))); + vec4 spec = texture2DRect(specularRect, frag.xy); + if (spec.a > 0.0) + { + lit = min(da*6.0, 1.0) * dist_atten; - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += lit*scol*color.rgb*spec.rgb; - } - } - - if (dot(col, col) <= 0.0) - { - discard; - } - - frag_color.rgb = col; - frag_color.a = 0.0; + vec3 npos = -normalize(pos); + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5) * 0.4+0.5; + float gtdenom = 2 * nh; + float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh))); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + col += lit*scol*color.rgb*spec.rgb; + } + } + + if (dot(col, col) <= 0.0) + { + discard; + } + + frag_color.rgb = col; + frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 70568bc75f..cef9938192 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -48,44 +48,29 @@ uniform float shadow_bias; uniform float spot_shadow_bias; uniform float spot_shadow_offset; - +uniform float sun_up_factor; uniform mat4 inv_proj; uniform vec2 screen_res; vec3 decode_normal(vec2 enc); -float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias; - - stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - return shadow*0.2; -} - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { stc.xyz /= stc.w; - stc.z += shadow_bias * bias_scale; - - stc.x = floor(stc.x*pos_screen.x + fract(stc.y*pos_screen.y*0.666666666))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + float offset = max(0.75, light_dir.z); + stc.z += offset * shadow_bias * 3.33 * bias_mul; + + stc.x = floor(stc.x*shadow_res.x + fract(stc.y*pos_screen.y*3.14159))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; + float shadow = cs * 4.0; + shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - return shadow*0.2; + + return shadow*0.125; } float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) @@ -141,7 +126,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap3, lpos)*w; + shadow += pcfShadow(shadowMap3, lpos, 1.0, pos_screen, light_dir)*w; weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } @@ -153,7 +138,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadowLegacy(shadowMap2, lpos)*w; + shadow += pcfShadow(shadowMap2, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } @@ -164,7 +149,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadowLegacy(shadowMap1, lpos)*w; + shadow += pcfShadow(shadowMap1, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } @@ -175,14 +160,15 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - shadow += pcfShadowLegacy(shadowMap0, lpos)*w; + shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } shadow /= weight; } - return min(dp_directional_light, shadow); + shadow = min(dp_directional_light, shadow); + return shadow; } float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) @@ -201,11 +187,19 @@ float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) float weight = 0.0; { - lpos = shadow_matrix[4 + index]*spos; float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - - shadow += pcfSpotShadow((index == 0) ? shadowMap4 : shadowMap5, lpos, 0.8, spos.xy)*w; + + if (index == 0) + { + lpos = shadow_matrix[4]*spos; + shadow += pcfSpotShadow(shadowMap4, lpos, 0.8, spos.xy)*w; + } + else + { + lpos = shadow_matrix[5]*spos; + shadow += pcfSpotShadow(shadowMap5, lpos, 0.8, spos.xy)*w; + } weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index f0b038cc93..9e0079e0e9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -66,7 +66,7 @@ uniform vec2 screen_res; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 decode_normal (vec2 enc); +vec3 getNorm(vec2 pos_screen); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 fullbrightAtmosTransportFrag(vec3 l, vec3 additive, vec3 atten); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); @@ -78,14 +78,14 @@ vec4 getPositionWithDepth(vec2 pos_screen, float depth); void main() { - vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; - vec4 pos = getPositionWithDepth(tc, depth); - vec4 norm = texture2DRect(normalMap, tc); - float envIntensity = norm.z; - norm.xyz = decode_normal(norm.xy); // unpack norm - - float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); + vec2 tc = vary_fragcoord.xy; + float depth = texture2DRect(depthMap, tc.xy).r; + vec4 pos = getPositionWithDepth(tc, depth); + vec4 norm = texture2DRect(normalMap, tc); + float envIntensity = norm.z; + norm.xyz = getNorm(tc); + + float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); float da_moon = dot(norm.xyz, normalize(moon_dir.xyz)); float da = max(da_sun, da_moon); diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 22488944cd..d09bc25334 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -70,7 +70,7 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 decode_normal (vec2 enc); +vec3 getNorm(vec2 pos_screen); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { @@ -142,7 +142,7 @@ void main() vec3 norm = texture2DRect(normalMap, frag.xy).xyz; float envIntensity = norm.z; - norm = decode_normal(norm.xy); + norm = getNorm(frag.xy); norm = normalize(norm); float l_dist = -dot(lv, proj_n); diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index e98ab1f2eb..15f141cbe5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -40,7 +40,7 @@ uniform sampler2DRect normalMap; // Inputs VARYING vec2 vary_fragcoord; -vec3 decode_normal (vec2 enc); +vec3 getNorm(vec2 pos_screen); vec4 getPosition(vec2 pos_screen); //calculate decreases in ambient lighting when crowded out (SSAO) @@ -53,7 +53,7 @@ void main() //try doing an unproject here vec4 pos = getPosition(pos_screen); - vec3 norm = decode_normal(texture2DRect(normalMap, pos_screen).xy); + vec3 norm = getNorm(pos_screen); frag_color[0] = 1.0; frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 1c5d3901f5..142b03e095 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -71,7 +71,7 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 decode_normal (vec2 enc); +vec3 getNorm(vec2 pos_screen); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { @@ -155,7 +155,7 @@ void main() float envIntensity = norm.z; - norm = decode_normal(norm.xy); + norm = getNorm(frag.xy); norm = normalize(norm); float l_dist = -dot(lv, proj_n); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index c80e7fce18..4fd3e73336 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -62,7 +62,7 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 decode_normal (vec2 enc); +vec3 getNorm(vec2 pos_screen); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); @@ -82,22 +82,22 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); void main() { - vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; - vec4 pos = getPositionWithDepth(tc, depth); - vec4 norm = texture2DRect(normalMap, tc); - float envIntensity = norm.z; - norm.xyz = decode_normal(norm.xy); // unpack norm - - float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); + vec2 tc = vary_fragcoord.xy; + float depth = texture2DRect(depthMap, tc.xy).r; + vec4 pos = getPositionWithDepth(tc, depth); + vec4 norm = texture2DRect(normalMap, tc); + float envIntensity = norm.z; + norm.xyz = getNorm(tc); // unpack norm + + float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); float da_moon = dot(norm.xyz, normalize(moon_dir.xyz)); float da = max(da_sun, da_moon); da = clamp(da, 0.0, 1.0); - da = pow(da, global_gamma + 0.3); + da = pow(da, global_gamma + 0.3); - vec4 diffuse = texture2DRect(diffuseRect, tc); - + vec4 diffuse = texture2DRect(diffuseRect, tc); + vec3 col; float bloom = 0.0; { diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 36854b0e66..9b69d8d855 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -71,7 +71,7 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 decode_normal (vec2 enc); +vec3 getNorm(vec2 pos_screen); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { @@ -153,7 +153,7 @@ void main() vec3 norm = texture2DRect(normalMap, frag.xy).xyz; float envIntensity = norm.z; - norm = decode_normal(norm.xy); + norm = getNorm(frag.xy); norm = normalize(norm); float l_dist = -dot(lv, proj_n); diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index fc5756beef..8abdeae5ae 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -42,7 +42,6 @@ uniform vec3 sun_dir; uniform float shadow_bias; vec3 getNorm(vec2 pos_screen); -vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen); float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 390f9fc947..64d99bae2c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -37,7 +37,6 @@ out vec4 frag_color; // Inputs VARYING vec2 vary_fragcoord; -vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen); vec3 getNorm(vec2 pos_screen); diff --git a/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl index cccd01e0d7..e27bbce094 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl @@ -1,5 +1,5 @@ /** - * @file class3/deferred/deferredUtil.glsl + * @file class1/deferred/deferredUtil.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -29,8 +29,6 @@ uniform sampler2DRect depthMap; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 decode_normal(vec2 enc); - vec2 getScreenCoordinate(vec2 screenpos) { vec2 sc = screenpos.xy * 2.0; @@ -43,8 +41,14 @@ vec2 getScreenCoordinate(vec2 screenpos) vec3 getNorm(vec2 screenpos) { - vec2 enc_norm = texture2DRect(normalMap, screenpos.xy).xy; - return decode_normal(enc_norm); + vec2 enc = texture2DRect(normalMap, screenpos.xy).xy; + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; } float getDepth(vec2 pos_screen) diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 0848adba73..72bccc5627 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -73,7 +73,7 @@ uniform mat4 inv_proj; vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); -vec3 decode_normal (vec2 enc); +vec3 getNorm(vec2 pos_screen); vec4 correctWithGamma(vec4 col) { @@ -166,7 +166,7 @@ void main() float envIntensity = norm.z; - norm = decode_normal(norm.xy); + norm = getNorm(frag.xy); norm = normalize(norm); float l_dist = -dot(lv, proj_n); diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 9411e905d3..ad721a80d6 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -76,7 +76,6 @@ vec3 GetSunAndSkyIrradiance(vec3 camPos, vec3 norm, vec3 dir, out vec3 sky_irrad vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); -vec3 decode_normal(vec2 xy); vec3 ColorFromRadiance(vec3 radiance); vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPosition(vec2 pos_screen); @@ -93,7 +92,7 @@ void main() vec3 pos = getPositionWithDepth(tc, depth).xyz; vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; - norm.xyz = decode_normal(norm.xy); + norm.xyz = getNorm(tc); float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); da = pow(da, global_gamma + 0.3); diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 80e2a9dd55..3b2b0d5718 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -71,7 +71,7 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 decode_normal (vec2 enc); +vec3 getNorm(vec2 pos_screen); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); @@ -164,7 +164,7 @@ void main() vec3 norm = texture2DRect(normalMap, frag.xy).xyz; float envIntensity = norm.z; - norm = decode_normal(norm.xy); + norm = getNorm(frag.xy); norm = normalize(norm); float l_dist = -dot(lv, proj_n); diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl index e230ebb71c..112b498c90 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl @@ -38,7 +38,6 @@ out vec4 frag_color; // Inputs VARYING vec2 vary_fragcoord; -vec3 decode_normal (vec2 enc); vec4 getPosition(vec2 pos_screen); vec3 getNorm(vec2 pos_screen); -- cgit v1.2.3 From bd25688867d824a3c21ffce93d689bb30e4ba803 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 30 Jan 2019 10:38:41 -0800 Subject: SL-9996 Force frag depth in water shaders to avoid z-fighting at back edge of water edge pieces. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 5 ++++- indra/newview/app_settings/shaders/class1/environment/waterF.glsl | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index ceadb9fb67..d9ae37fbfa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -167,7 +167,10 @@ void main() color.a = spec * sunAngle2; vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - + + // force frag depth which doesn't z-fight + gl_FragDepth = 0.99999f; + frag_data[0] = vec4(color.rgb, color); // diffuse frag_data[1] = vec4(0); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index 19158f4505..c4b3684141 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -157,5 +157,7 @@ void main() color.rgb = scaleSoftClip(color.rgb); color.a = spec * sunAngle2; + // force frag depth to fix z-fighting at back edge of water edge pieces + gl_FragDepth = 0.99999; frag_color = color; } -- cgit v1.2.3 From 08440def112395487d57a9d6e719c7700d7134b5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 30 Jan 2019 12:34:20 -0800 Subject: WIP for 10374 (reduce number of shaders linking against deferredUtil). Prepare for using ifdef to conditionally engage using gl_FragDepth in water shaders (because GL requires that writing to gl_FragDepth on any path means you need to write a depth value on every path). --- .../shaders/class1/deferred/multiSpotLightF.glsl | 2 +- .../shaders/class1/deferred/waterF.glsl | 189 +++++++++++---------- .../shaders/class1/environment/waterF.glsl | 171 ++++++++++--------- 3 files changed, 184 insertions(+), 178 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 24804c3011..2569e49743 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -140,7 +140,7 @@ void main() discard; } - float envIntensity = texture2DRect(normalMap. frag.xy).z; + float envIntensity = texture2DRect(normalMap, frag.xy).z; vec3 norm = getNorm(frag.xy); float l_dist = -dot(lv, proj_n); diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index d9ae37fbfa..df7b8f3f92 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -55,6 +55,7 @@ uniform float fresnelOffset; uniform float blurMultiplier; uniform vec2 screen_res; uniform mat4 norm_mat; //region space to screen space +uniform int water_edge; //bigWave is (refCoord.w, view.w); VARYING vec4 refCoord; @@ -73,105 +74,107 @@ vec3 BlendNormal(vec3 bump1, vec3 bump2) void main() { - vec4 color; - float dist = length(view.xy); - - //normalize view vector - vec3 viewVec = normalize(view.xyz); - - //get wave normals - vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; - vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; - vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; - - - vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; - vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; - vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; + vec4 color; + float dist = length(view.xy); + + //normalize view vector + vec3 viewVec = normalize(view.xyz); + + //get wave normals + vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + + + vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; vec3 wave1 = BlendNormal(wave1_a, wave1_b); vec3 wave2 = BlendNormal(wave2_a, wave2_b); vec3 wave3 = BlendNormal(wave3_a, wave3_b); - //get base fresnel components - - vec3 df = vec3( - dot(viewVec, wave1), - dot(viewVec, (wave2 + wave3) * 0.5), - dot(viewVec, wave3) - ) * fresnelScale + fresnelOffset; - df *= df; - - vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; - - float dist2 = dist; - dist = max(dist, 5.0); - - float dmod = sqrt(dist); - - vec2 dmod_scale = vec2(dmod*dmod, dmod); - - //get reflected color - vec2 refdistort1 = wave1.xy*normScale.x; - vec2 refvec1 = distort+refdistort1/dmod_scale; - vec4 refcol1 = texture2D(refTex, refvec1); - - vec2 refdistort2 = wave2.xy*normScale.y; - vec2 refvec2 = distort+refdistort2/dmod_scale; - vec4 refcol2 = texture2D(refTex, refvec2); - - vec2 refdistort3 = wave3.xy*normScale.z; - vec2 refvec3 = distort+refdistort3/dmod_scale; - vec4 refcol3 = texture2D(refTex, refvec3); - - vec4 refcol = refcol1 + refcol2 + refcol3; - float df1 = df.x + df.y + df.z; - refcol *= df1 * 0.333; - - vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; - wavef.z *= max(-viewVec.z, 0.1); - wavef = normalize(wavef); - - float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; - - vec2 refdistort4 = wavef.xy*0.125; - refdistort4.y -= abs(refdistort4.y); - vec2 refvec4 = distort+refdistort4/dmod; - float dweight = min(dist2*blurMultiplier, 1.0); - vec4 baseCol = texture2D(refTex, refvec4); - - refcol = mix(baseCol*df2, refcol, dweight); - - //get specular component - float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); - - //harden specular - spec = pow(spec, 128.0); - - //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale * 0.33/max(dmod*df1, 1.0); - - vec4 fb = texture2D(screenTex, distort2); - - //mix with reflection - // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug + //get base fresnel components + + vec3 df = vec3( + dot(viewVec, wave1), + dot(viewVec, (wave2 + wave3) * 0.5), + dot(viewVec, wave3) + ) * fresnelScale + fresnelOffset; + df *= df; + + vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; + + float dist2 = dist; + dist = max(dist, 5.0); + + float dmod = sqrt(dist); + + vec2 dmod_scale = vec2(dmod*dmod, dmod); + + //get reflected color + vec2 refdistort1 = wave1.xy*normScale.x; + vec2 refvec1 = distort+refdistort1/dmod_scale; + vec4 refcol1 = texture2D(refTex, refvec1); + + vec2 refdistort2 = wave2.xy*normScale.y; + vec2 refvec2 = distort+refdistort2/dmod_scale; + vec4 refcol2 = texture2D(refTex, refvec2); + + vec2 refdistort3 = wave3.xy*normScale.z; + vec2 refvec3 = distort+refdistort3/dmod_scale; + vec4 refcol3 = texture2D(refTex, refvec3); + + vec4 refcol = refcol1 + refcol2 + refcol3; + float df1 = df.x + df.y + df.z; + refcol *= df1 * 0.333; + + vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; + wavef.z *= max(-viewVec.z, 0.1); + wavef = normalize(wavef); + + float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; + + vec2 refdistort4 = wavef.xy*0.125; + refdistort4.y -= abs(refdistort4.y); + vec2 refvec4 = distort+refdistort4/dmod; + float dweight = min(dist2*blurMultiplier, 1.0); + vec4 baseCol = texture2D(refTex, refvec4); + + refcol = mix(baseCol*df2, refcol, dweight); + + //get specular component + float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); + + //harden specular + spec = pow(spec, 128.0); + + //figure out distortion vector (ripply) + vec2 distort2 = distort+wavef.xy*refScale * 0.33/max(dmod*df1, 1.0); + + vec4 fb = texture2D(screenTex, distort2); + + //mix with reflection + // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug refcol.rgb = pow(refcol.rgb, vec3(0.45)); // boost the reflect color a little to get stars to show up SL-1475 - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); - - vec4 pos = vary_position; - - color.rgb += spec * specular; - - color.rgb = atmosTransport(color.rgb); - color.rgb = scaleSoftClipFrag(color.rgb); - color.a = spec * sunAngle2; - - vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); + + vec4 pos = vary_position; + + color.rgb += spec * specular; + + color.rgb = atmosTransport(color.rgb); + color.rgb = scaleSoftClipFrag(color.rgb); + color.a = spec * sunAngle2; + + vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); + +#if defined(WATER_EDGE) // force frag depth which doesn't z-fight - gl_FragDepth = 0.99999f; + gl_FragDepth = 0.99999f; +#endif - frag_data[0] = vec4(color.rgb, color); // diffuse - frag_data[1] = vec4(0); // speccolor, spec - frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 + frag_data[0] = vec4(color.rgb, color); // diffuse + frag_data[1] = vec4(0); // speccolor, spec + frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 } diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index c4b3684141..415d0b9db4 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -50,7 +50,7 @@ uniform vec3 normScale; uniform float fresnelScale; uniform float fresnelOffset; uniform float blurMultiplier; - +uniform int water_edge; //bigWave is (refCoord.w, view.w); VARYING vec4 refCoord; @@ -68,96 +68,99 @@ vec3 BlendNormal(vec3 bump1, vec3 bump2) void main() { - vec4 color; - - float dist = length(view.xy); - - //normalize view vector - vec3 viewVec = normalize(view.xyz); - - //get wave normals - vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; - vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; - vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + vec4 color; + + float dist = length(view.xy); + + //normalize view vector + vec3 viewVec = normalize(view.xyz); + + //get wave normals + vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; - vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; - vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; - vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; + vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; - vec3 wave1 = BlendNormal(wave1_a, wave1_b); - vec3 wave2 = BlendNormal(wave2_a, wave2_b); - vec3 wave3 = BlendNormal(wave3_a, wave3_b); + vec3 wave1 = BlendNormal(wave1_a, wave1_b); + vec3 wave2 = BlendNormal(wave2_a, wave2_b); + vec3 wave3 = BlendNormal(wave3_a, wave3_b); - //get base fresnel components - - vec3 df = vec3( - dot(viewVec, wave1), - dot(viewVec, (wave2 + wave3) * 0.5), - dot(viewVec, wave3) - ) * fresnelScale + fresnelOffset; - df *= df; - - vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; - - float dist2 = dist; - dist = max(dist, 5.0); - - float dmod = sqrt(dist); - - vec2 dmod_scale = vec2(dmod*dmod, dmod); - - //get reflected color - vec2 refdistort1 = wave1.xy*normScale.x; - vec2 refvec1 = distort+refdistort1/dmod_scale; - vec4 refcol1 = texture2D(refTex, refvec1); - - vec2 refdistort2 = wave2.xy*normScale.y; - vec2 refvec2 = distort+refdistort2/dmod_scale; - vec4 refcol2 = texture2D(refTex, refvec2); - - vec2 refdistort3 = wave3.xy*normScale.z; - vec2 refvec3 = distort+refdistort3/dmod_scale; - vec4 refcol3 = texture2D(refTex, refvec3); + //get base fresnel components + + vec3 df = vec3( + dot(viewVec, wave1), + dot(viewVec, (wave2 + wave3) * 0.5), + dot(viewVec, wave3) + ) * fresnelScale + fresnelOffset; + df *= df; + + vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; + + float dist2 = dist; + dist = max(dist, 5.0); + + float dmod = sqrt(dist); + + vec2 dmod_scale = vec2(dmod*dmod, dmod); + + //get reflected color + vec2 refdistort1 = wave1.xy*normScale.x; + vec2 refvec1 = distort+refdistort1/dmod_scale; + vec4 refcol1 = texture2D(refTex, refvec1); + + vec2 refdistort2 = wave2.xy*normScale.y; + vec2 refvec2 = distort+refdistort2/dmod_scale; + vec4 refcol2 = texture2D(refTex, refvec2); + + vec2 refdistort3 = wave3.xy*normScale.z; + vec2 refvec3 = distort+refdistort3/dmod_scale; + vec4 refcol3 = texture2D(refTex, refvec3); - vec4 refcol = refcol1 + refcol2 + refcol3; - float df1 = df.x + df.y + df.z; - refcol *= df1 * 0.333; - - vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; - - wavef.z *= max(-viewVec.z, 0.1); - wavef = normalize(wavef); - - float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; - - vec2 refdistort4 = wavef.xy*0.125; - refdistort4.y -= abs(refdistort4.y); - vec2 refvec4 = distort+refdistort4/dmod; - float dweight = min(dist2*blurMultiplier, 1.0); - vec4 baseCol = texture2D(refTex, refvec4); - refcol = mix(baseCol*df2, refcol, dweight); + vec4 refcol = refcol1 + refcol2 + refcol3; + float df1 = df.x + df.y + df.z; + refcol *= df1 * 0.333; + + vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; + + wavef.z *= max(-viewVec.z, 0.1); + wavef = normalize(wavef); + + float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; + + vec2 refdistort4 = wavef.xy*0.125; + refdistort4.y -= abs(refdistort4.y); + vec2 refvec4 = distort+refdistort4/dmod; + float dweight = min(dist2*blurMultiplier, 1.0); + vec4 baseCol = texture2D(refTex, refvec4); + refcol = mix(baseCol*df2, refcol, dweight); - //get specular component - float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); - - //harden specular - spec = pow(spec, 128.0); + //get specular component + float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); + + //harden specular + spec = pow(spec, 128.0); - //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); - - vec4 fb = texture2D(screenTex, distort2); - - //mix with reflection - // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); - color.rgb += spec * specular; - - color.rgb = atmosTransport(color.rgb); - color.rgb = scaleSoftClip(color.rgb); - color.a = spec * sunAngle2; + //figure out distortion vector (ripply) + vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); + + vec4 fb = texture2D(screenTex, distort2); + + //mix with reflection + // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); + color.rgb += spec * specular; + + color.rgb = atmosTransport(color.rgb); + color.rgb = scaleSoftClip(color.rgb); + color.a = spec * sunAngle2; +#if defined(WATER_EDGE) // force frag depth to fix z-fighting at back edge of water edge pieces gl_FragDepth = 0.99999; - frag_color = color; +#endif + + frag_color = color; } -- cgit v1.2.3 From deb6110098569fb90ca7e5073c2e98fabbb23a82 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 30 Jan 2019 13:26:35 -0800 Subject: Eliminate helper GLSL modules depending on further GLSL modules to give Intel HD x000 compiler a fighting chance. More WIP for edge-specific water shader for 9996. --- .../shaders/class1/deferred/aoUtil.glsl | 34 ++++++++++++++++++++-- .../shaders/class1/deferred/shadowUtil.glsl | 8 ----- 2 files changed, 32 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl index 3bb59dd7f9..23adbded5e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl @@ -24,13 +24,43 @@ */ uniform sampler2D noiseMap; +uniform sampler2DRect normalMap; +uniform sampler2DRect depthMap; uniform float ssao_radius; uniform float ssao_max_radius; uniform float ssao_factor; uniform float ssao_factor_inv; -vec4 getPosition(vec2 pos_screen); +uniform mat4 inv_proj; +uniform vec2 screen_res; + +vec2 getScreenCoordinateAo(vec2 screenpos) +{ + vec2 sc = screenpos.xy * 2.0; + if (screen_res.x > 0 && screen_res.y > 0) + { + sc /= screen_res; + } + return sc - vec2(1.0, 1.0); +} + +float getDepthAo(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen).r; + return depth; +} + +vec4 getPositionAo(vec2 pos_screen) +{ + float depth = getDepthAo(pos_screen); + vec2 sc = getScreenCoordinateAo(pos_screen); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} vec2 getKern(int i) { @@ -64,7 +94,7 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen) for (int i = 0; i < 8; i++) { vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); - vec3 samppos_world = getPosition(samppos_screen).xyz; + vec3 samppos_world = getPositionAo(samppos_screen).xyz; vec3 diff = pos_world - samppos_world; float dist2 = dot(diff, diff); diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index cef9938192..843901ea6a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -25,7 +25,6 @@ uniform sampler2DRect normalMap; uniform sampler2DRect depthMap; -uniform sampler2D noiseMap; uniform sampler2DShadow shadowMap0; uniform sampler2DShadow shadowMap1; uniform sampler2DShadow shadowMap2; @@ -33,11 +32,6 @@ uniform sampler2DShadow shadowMap3; uniform sampler2DShadow shadowMap4; uniform sampler2DShadow shadowMap5; -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; - uniform vec3 sun_dir; uniform vec3 moon_dir; uniform vec2 shadow_res; @@ -52,8 +46,6 @@ uniform float sun_up_factor; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 decode_normal(vec2 enc); - float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { stc.xyz /= stc.w; -- cgit v1.2.3 From 767fb53aeb1ac92a141586b1c0b5d1e5d327b281 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 31 Jan 2019 09:56:37 -0800 Subject: 9996 partial fix (works for non-ALM rendering only) Use a new edge water shader to allow forcing frag depth to avoid z-fighting at back edge of water edge pieces. This will not work for ALM because forcing the depth breaks the use of the depth to backproject gbuffer position which breaks lighting calcs. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 5 ----- indra/newview/app_settings/shaders/class1/environment/waterF.glsl | 5 ++--- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index df7b8f3f92..40d4c24d34 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -169,11 +169,6 @@ void main() vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); -#if defined(WATER_EDGE) - // force frag depth which doesn't z-fight - gl_FragDepth = 0.99999f; -#endif - frag_data[0] = vec4(color.rgb, color); // diffuse frag_data[1] = vec4(0); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index 415d0b9db4..f228deb938 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -157,9 +157,8 @@ void main() color.rgb = scaleSoftClip(color.rgb); color.a = spec * sunAngle2; -#if defined(WATER_EDGE) - // force frag depth to fix z-fighting at back edge of water edge pieces - gl_FragDepth = 0.99999; +#if WATER_EDGE + gl_FragDepth = 0.9999847f; #endif frag_color = color; -- cgit v1.2.3 From abaa64067fc81f6124d6d7603508129502f95147 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 31 Jan 2019 11:01:13 -0800 Subject: Remove (now) unused decodeNormF GLSL shader. --- .../shaders/class1/environment/decodeNormF.glsl | 36 ---------------------- 1 file changed, 36 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl b/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl deleted file mode 100644 index becc6d89c1..0000000000 --- a/indra/newview/app_settings/shaders/class1/environment/decodeNormF.glsl +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file decodeNormF.glsl - * - * $LicenseInfo:firstyear=2018&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2018, 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$ - */ - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} - -- cgit v1.2.3 From 50b383e5aa333d453e906ae2beb28fe1da549bef Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 1 Feb 2019 09:45:07 -0800 Subject: Fix issue with OSX shader compiler not implementing #if correctly (nice job, Timmy). --- .../shaders/class1/deferred/moonF.glsl | 2 ++ .../app_settings/shaders/class1/deferred/skyF.glsl | 28 ++++++++++++---------- .../shaders/class1/deferred/waterF.glsl | 4 ++-- .../shaders/class1/environment/waterF.glsl | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 7265275e36..379fdf8535 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -61,5 +61,7 @@ void main() frag_data[0] = vec4(c.rgb, c.a); frag_data[1] = vec4(0.0); frag_data[2] = vec4(0.0f); + + gl_FragDepth = 0.9998f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 0613111632..f8172cae17 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -44,18 +44,20 @@ vec3 scaleSoftClip(vec3 light); void main() { - // Potential Fill-rate optimization. Add cloud calculation - // back in and output alpha of 0 (so that alpha culling kills - // the fragment) if the sky wouldn't show up because the clouds - // are fully opaque. - - vec4 color; - color = vary_HazeColor; - color *= 2.; - - /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); - frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog + // Potential Fill-rate optimization. Add cloud calculation + // back in and output alpha of 0 (so that alpha culling kills + // the fragment) if the sky wouldn't show up because the clouds + // are fully opaque. + + vec4 color; + color = vary_HazeColor; + color *= 2.; + + /// Gamma correct for WL (soft clip effect). + frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); + frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog + + gl_FragDepth = 0.999f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 40d4c24d34..531425b588 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -165,11 +165,11 @@ void main() color.rgb = atmosTransport(color.rgb); color.rgb = scaleSoftClipFrag(color.rgb); - color.a = spec * sunAngle2; + color.a = (water_edge > 0) ? 1.0 : (spec * sunAngle2); vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - frag_data[0] = vec4(color.rgb, color); // diffuse + frag_data[0] = vec4(color.rgb, 1); // diffuse frag_data[1] = vec4(0); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 } diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index f228deb938..a4e3f94816 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -157,7 +157,7 @@ void main() color.rgb = scaleSoftClip(color.rgb); color.a = spec * sunAngle2; -#if WATER_EDGE +#if defined(WATER_EDGE) gl_FragDepth = 0.9999847f; #endif -- cgit v1.2.3 From db97bb51489dc610fd748b73c321a08e7388d668 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 1 Feb 2019 09:49:55 -0800 Subject: Roll back attempted fix for 9996 on ALM which has unacceptable knock-on effects. --- .../shaders/class1/deferred/moonF.glsl | 2 -- .../app_settings/shaders/class1/deferred/skyF.glsl | 28 ++++++++++------------ .../shaders/class1/deferred/waterF.glsl | 4 ++-- 3 files changed, 15 insertions(+), 19 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 379fdf8535..7265275e36 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -61,7 +61,5 @@ void main() frag_data[0] = vec4(c.rgb, c.a); frag_data[1] = vec4(0.0); frag_data[2] = vec4(0.0f); - - gl_FragDepth = 0.9998f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index f8172cae17..0613111632 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -44,20 +44,18 @@ vec3 scaleSoftClip(vec3 light); void main() { - // Potential Fill-rate optimization. Add cloud calculation - // back in and output alpha of 0 (so that alpha culling kills - // the fragment) if the sky wouldn't show up because the clouds - // are fully opaque. - - vec4 color; - color = vary_HazeColor; - color *= 2.; - - /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); - frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog - - gl_FragDepth = 0.999f; + // Potential Fill-rate optimization. Add cloud calculation + // back in and output alpha of 0 (so that alpha culling kills + // the fragment) if the sky wouldn't show up because the clouds + // are fully opaque. + + vec4 color; + color = vary_HazeColor; + color *= 2.; + + /// Gamma correct for WL (soft clip effect). + frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); + frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 531425b588..40d4c24d34 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -165,11 +165,11 @@ void main() color.rgb = atmosTransport(color.rgb); color.rgb = scaleSoftClipFrag(color.rgb); - color.a = (water_edge > 0) ? 1.0 : (spec * sunAngle2); + color.a = spec * sunAngle2; vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - frag_data[0] = vec4(color.rgb, 1); // diffuse + frag_data[0] = vec4(color.rgb, color); // diffuse frag_data[1] = vec4(0); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 } -- cgit v1.2.3 From 5a8610ccb7e1f5a0e4d54170ac922e6820ce3acb Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 1 Feb 2019 13:41:31 -0800 Subject: SL-9996, SL-1130, SL-5546 Fix bug with setting texture matrix for rigged mesh. Fix z-fighting between sea and sky in ALM by cheating sky, stars, and moon using gl_FragDepth. Fix handling of atmospheric haze glow w.r.t independent sun/moon positioning (we can no longer depend on them being mutex to each other). --- .../shaders/class1/deferred/cloudsV.glsl | 4 ++-- .../shaders/class1/deferred/moonF.glsl | 2 ++ .../shaders/class1/deferred/shadowUtil.glsl | 1 - .../app_settings/shaders/class1/deferred/skyF.glsl | 28 ++++++++++++---------- .../shaders/class1/deferred/starsF.glsl | 8 ++++--- .../shaders/class1/deferred/waterF.glsl | 3 +-- .../app_settings/shaders/class2/deferred/skyF.glsl | 4 ++-- .../shaders/class2/deferred/softenLightF.glsl | 2 +- .../shaders/class2/windlight/atmosphericsF.glsl | 4 ++-- .../shaders/class2/windlight/atmosphericsV.glsl | 4 ++-- .../shaders/class2/windlight/cloudsV.glsl | 4 ++-- .../shaders/class2/windlight/skyV.glsl | 4 ++-- 12 files changed, 36 insertions(+), 32 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index baf54c1fbe..53391da9aa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -58,7 +58,7 @@ uniform float density_multiplier; uniform float max_y; uniform vec4 glow; -uniform float sun_up_factor; +uniform float sun_moon_glow_factor; uniform vec4 cloud_color; @@ -132,7 +132,7 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function - //temp2.x *= sun_up_factor; + temp2.x *= sun_moon_glow_factor; // Add "minimum anti-solar illumination" temp2.x += .25; diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 7265275e36..c6c12f80f8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -61,5 +61,7 @@ void main() frag_data[0] = vec4(c.rgb, c.a); frag_data[1] = vec4(0.0); frag_data[2] = vec4(0.0f); + + gl_FragDepth = 0.9996f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 843901ea6a..6c509b7616 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -42,7 +42,6 @@ uniform float shadow_bias; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -uniform float sun_up_factor; uniform mat4 inv_proj; uniform vec2 screen_res; diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 0613111632..f8172cae17 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -44,18 +44,20 @@ vec3 scaleSoftClip(vec3 light); void main() { - // Potential Fill-rate optimization. Add cloud calculation - // back in and output alpha of 0 (so that alpha culling kills - // the fragment) if the sky wouldn't show up because the clouds - // are fully opaque. - - vec4 color; - color = vary_HazeColor; - color *= 2.; - - /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); - frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog + // Potential Fill-rate optimization. Add cloud calculation + // back in and output alpha of 0 (so that alpha culling kills + // the fragment) if the sky wouldn't show up because the clouds + // are fully opaque. + + vec4 color; + color = vary_HazeColor; + color *= 2.; + + /// Gamma correct for WL (soft clip effect). + frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); + frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog + + gl_FragDepth = 0.999f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 4ae3f7b76f..67e7604e22 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -49,8 +49,8 @@ float twinkle(){ void main() { - vec4 col_a = texture2D(diffuseMap, vary_texcoord0.xy); - vec4 col_b = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 col_a = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 col_b = texture2D(diffuseMap, vary_texcoord0.xy); vec4 col = mix(col_b, col_a, blend_factor); col.rgb *= vertex_color.rgb; @@ -59,8 +59,10 @@ void main() col.a = (col.a * factor) * 32.0f; col.a *= twinkle(); - frag_data[0] = col; + frag_data[0] = col; frag_data[1] = vec4(0.0f); frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); + + gl_FragDepth = 0.9998; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 40d4c24d34..ee028d8194 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -165,11 +165,10 @@ void main() color.rgb = atmosTransport(color.rgb); color.rgb = scaleSoftClipFrag(color.rgb); - color.a = spec * sunAngle2; vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - frag_data[0] = vec4(color.rgb, color); // diffuse + frag_data[0] = vec4(color.rgb, 1); // diffuse frag_data[1] = vec4(0); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 } diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 792aa4e85c..7e2d41cf7b 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -45,7 +45,7 @@ uniform float density_multiplier; uniform float max_y; uniform vec4 glow; -uniform float sun_up_factor; +uniform float sun_moon_glow_factor; uniform vec4 cloud_color; @@ -153,7 +153,7 @@ void main() // Add "minimum anti-solar illumination" temp2.x += .25; - //temp2.x *= sun_up_factor; + temp2.x *= sun_moon_glow_factor; // Haze color above cloud vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient) diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 4fd3e73336..2c1cc3026f 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -91,7 +91,7 @@ void main() float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); float da_moon = dot(norm.xyz, normalize(moon_dir.xyz)); - float da = max(da_sun, da_moon); + float da = (da_sun > 0.0) ? da_sun : da_moon; da = clamp(da, 0.0, 1.0); da = pow(da, global_gamma + 0.3); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 8d1e5e3281..683ab794d3 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -42,7 +42,7 @@ uniform vec4 glow; uniform float scene_light_strength; uniform mat3 ssao_effect_mat; uniform int no_atmo; -uniform float sun_up_factor; +uniform float sun_moon_glow_factor; vec3 scaleSoftClipFrag(vec3 light); @@ -119,7 +119,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, //add "minimum anti-solar illumination" temp2.x += .25; - //temp2.x *= sun_up_factor; + temp2.x *= sun_moon_glow_factor; //increase ambient when there are more clouds vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index 5ccf786fce..86cdae8768 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -54,7 +54,7 @@ uniform float density_multiplier; uniform float distance_multiplier; uniform float max_y; uniform vec4 glow; -uniform float sun_up_factor; +uniform float sun_moon_glow_factor; void calcAtmospherics(vec3 inPositionEye) { @@ -118,7 +118,7 @@ void calcAtmospherics(vec3 inPositionEye) { temp2.x = pow(temp2.x, glow.z); //glow.z should be negative, so we're doing a sort of (1 / "angle") function - temp2.x *= sun_up_factor; + temp2.x *= sun_moon_glow_factor; //add "minimum anti-solar illumination" temp2.x += .25; diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index a250cf2c45..3e3bd929e1 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -57,7 +57,7 @@ uniform float density_multiplier; uniform float max_y; uniform vec4 glow; -uniform float sun_up_factor; +uniform float sun_moon_glow_factor; uniform vec4 cloud_color; @@ -131,7 +131,7 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function - //temp2.x *= sun_up_factor; + temp2.x *= sun_moon_glow_factor; // Add "minimum anti-solar illumination" temp2.x += .25; diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index f509f9f8d4..f9f1eb7355 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -50,7 +50,7 @@ uniform float density_multiplier; uniform float max_y; uniform vec4 glow; -uniform float sun_up_factor; +uniform float sun_moon_glow_factor; uniform vec4 cloud_color; void main() @@ -119,7 +119,7 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function - //temp2.x *= sun_up_factor; + temp2.x *= sun_moon_glow_factor; // Add "minimum anti-solar illumination" temp2.x += .25; -- cgit v1.2.3 From 1d1fcb451cc99b5ee2efbe1fdf38a0607233a2d8 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 4 Feb 2019 10:22:55 -0800 Subject: SL-10459 Use gl_FragDepth on deferred sun disc to fix z-fighting with sky dome and get layering of sky/stars/sun/moon/clouds correct. --- indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index c66f3f62b2..5bb2020971 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -57,5 +57,7 @@ void main() frag_data[0] = c; frag_data[1] = vec4(0.0f); frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); + + gl_FragDepth = 0.9997f; } -- cgit v1.2.3 From 9a007cceeffb1b960ba495cd0e3d592698a52a99 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 4 Feb 2019 12:56:11 -0800 Subject: SL-10461 Pass projector ambiance as the .w element of the light_attenuation uniform so that alpha shader can emulate the behavior of proper spot projectors. --- .../shaders/class1/deferred/alphaF.glsl | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index f1b7a1312f..772859576f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -63,7 +63,7 @@ uniform vec2 screen_res; uniform vec4 light_position[8]; uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; +uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; #ifdef WATER_FOG @@ -79,7 +79,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, 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) +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance) { //get light vector vec3 lv = lp.xyz-v; @@ -91,13 +91,16 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec vec3 col = vec3(0); - if (d > 0.0 && la > 0.0 && fa > 0.0) + if (d > 0.0 && fa > 0.0) { //normalize light vector lv = normalize(lv); - + vec3 norm = normalize(n); + + da = max(0.0, dot(norm, lv)); + //distance attenuation - float dist = d/la; + float dist = d; 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; @@ -106,17 +109,17 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 - //angular attenuation - da *= max(dot(n, lv), 0.0); - float lit = max(da * dist_atten,0.0); - col = light_col * lit * diffuse; + float amb_da = (da*da*0.5 + 0.5) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + col.rgb += amb_da * light_col * diffuse; // no spec for alpha shader... } - - return max(col, vec3(0.0,0.0,0.0)); + col = max(col, vec3(0)); + return col; } void main() @@ -199,7 +202,7 @@ void main() 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); + #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); LIGHT_LOOP(1) LIGHT_LOOP(2) -- cgit v1.2.3 From f8171a909cb2a18fcca47f6a0317919ece802aef Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 6 Feb 2019 10:07:24 -0800 Subject: SL-10461 Another attempt at getting approximage handling of projector ambiance in the alpha object shader. This will not be a perfect match for non-transparent objects but should be close enough. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 772859576f..9883ece648 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -86,9 +86,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec //get distance float d = length(lv); - float da = 1.0; - vec3 col = vec3(0); if (d > 0.0 && fa > 0.0) @@ -100,7 +98,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec da = max(0.0, dot(norm, lv)); //distance attenuation - float dist = d; + 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; @@ -109,9 +107,11 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec 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); + col = lit * light_col * diffuse; - float amb_da = (da*da*0.5 + 0.5) * ambiance; + float amb_da = (da*da*0.5 + 0.25) * ambiance; amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); -- cgit v1.2.3 From 8890c3238ab4ae8bbf1bc123284f9c6d4db4f9d6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 6 Feb 2019 16:42:23 -0800 Subject: SL-10478 Fix side-effects of having both sun and moon as potential directional light contributors. We pass an int to the shader indicating which to prefer instead of making per-pixel decisions and pass the moonlight color/di independently. Obsolete llsettingssky fade color which was unused elsewhere and cached for no reason. --- .../app_settings/shaders/class1/deferred/cloudsV.glsl | 4 +++- .../app_settings/shaders/class1/deferred/moonF.glsl | 2 ++ .../app_settings/shaders/class1/deferred/shadowUtil.glsl | 15 ++++++++------- .../app_settings/shaders/class1/deferred/skyV.glsl | 4 +++- .../app_settings/shaders/class1/deferred/starsF.glsl | 1 - .../app_settings/shaders/class1/windlight/moonF.glsl | 10 ++++++---- .../app_settings/shaders/class2/deferred/skyF.glsl | 4 +++- .../shaders/class2/deferred/softenLightF.glsl | 5 ++++- .../shaders/class2/windlight/atmosphericsF.glsl | 4 +++- .../shaders/class2/windlight/atmosphericsV.glsl | 4 +++- .../app_settings/shaders/class2/windlight/cloudsV.glsl | 4 +++- .../app_settings/shaders/class2/windlight/skyV.glsl | 4 +++- .../shaders/class3/deferred/cloudShadowF.glsl | 1 - .../app_settings/shaders/class3/deferred/cloudsF.glsl | 1 - .../shaders/class3/windlight/atmosphericsF.glsl | 4 +++- .../shaders/class3/windlight/atmosphericsV.glsl | 4 +++- 16 files changed, 47 insertions(+), 24 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 53391da9aa..4beb334f5a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -47,6 +47,8 @@ uniform vec3 camPosLocal; uniform vec4 lightnorm; uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; @@ -94,7 +96,7 @@ void main() vec4 temp2 = vec4(0.); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = sunlight_color; + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index c6c12f80f8..d964ce8eee 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -35,6 +35,7 @@ out vec4 frag_data[3]; uniform vec4 color; uniform vec4 sunlight_color; +uniform vec4 moonlight_color; uniform vec3 lumWeights; uniform float moon_brightness; uniform float minLuminance; @@ -57,6 +58,7 @@ void main() vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0 - 1.0; c.rgb = pow(c.rgb, exp); + //c.rgb *= moonlight_color.rgb; frag_data[0] = vec4(c.rgb, c.a); frag_data[1] = vec4(0.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 6c509b7616..39fdd9ec44 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -44,12 +44,13 @@ uniform float spot_shadow_bias; uniform float spot_shadow_offset; uniform mat4 inv_proj; uniform vec2 screen_res; +int sun_up_factor; float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { stc.xyz /= stc.w; float offset = max(0.75, light_dir.z); - stc.z += offset * shadow_bias * 3.33 * bias_mul; + stc.z += offset * shadow_bias * bias_mul; stc.x = floor(stc.x*shadow_res.x + fract(stc.y*pos_screen.y*3.14159))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here @@ -85,14 +86,14 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) { + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + float dp_sun = max(0.0, dot(sun_dir.xyz, norm)); float dp_moon = max(0.0, dot(moon_dir.xyz, norm)); float dp_directional_light = max(dp_sun,dp_moon); dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); - vec3 light_dir = (dp_moon > dp_sun) ? moon_dir : sun_dir; - vec3 offset = light_dir * (1.0-dp_directional_light); - vec3 shadow_pos = pos.xyz + (offset * shadow_bias); + vec3 shadow_pos = pos.xyz; float shadow = 0.0f; vec4 spos = vec4(shadow_pos,1.0); @@ -117,7 +118,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos, 1.0, pos_screen, light_dir)*w; + shadow += pcfShadow(shadowMap3, lpos, 0.5, pos_screen, light_dir)*w; weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } @@ -129,7 +130,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos, 1.0, pos_screen, light_dir)*w; + shadow += pcfShadow(shadowMap2, lpos, 0.75, pos_screen, light_dir)*w; weight += w; } @@ -140,7 +141,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos, 1.0, pos_screen, light_dir)*w; + shadow += pcfShadow(shadowMap1, lpos, 0.88, pos_screen, light_dir)*w; weight += w; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 7c02d31d43..83dd9da091 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -39,6 +39,8 @@ uniform vec3 camPosLocal; uniform vec4 lightnorm; uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; @@ -82,7 +84,7 @@ void main() vec4 temp2 = vec4(0.); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = sunlight_color; + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 67e7604e22..8a98d6a489 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -39,7 +39,6 @@ uniform sampler2D diffuseMap; uniform sampler2D altDiffuseMap; uniform float blend_factor; uniform float custom_alpha; -uniform vec4 sunlight_color; uniform float time; float twinkle(){ diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl index b66b56e0fb..947c301110 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -35,6 +35,7 @@ out vec4 frag_color; uniform vec4 color; uniform vec4 sunlight_color; +uniform vec4 moonlight_color; uniform vec3 lumWeights; uniform float moon_brightness; uniform float minLuminance; @@ -45,8 +46,8 @@ VARYING vec2 vary_texcoord0; void main() { - vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); - vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); + vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(moonA, moonB, blend_factor); // mix factor which blends when sunlight is brighter @@ -55,8 +56,9 @@ void main() float mix = 1.0f - dot(normalize(sunlight_color.rgb), luma_weights); vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0 - 1.0; - c.rgb = pow(c.rgb, exp); + c.rgb = pow(c.rgb, exp); + //c.rgb *= moonlight_color.rgb; - frag_color = vec4(c.rgb, c.a); + frag_color = vec4(c.rgb, c.a); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 7e2d41cf7b..26f8095dc1 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -34,6 +34,8 @@ uniform vec3 camPosLocal; uniform vec4 lightnorm; uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; @@ -112,7 +114,7 @@ void main() vec4 temp2 = vec4(0.); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = sunlight_color; + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 2c1cc3026f..9a159e57f0 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -57,6 +57,8 @@ 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; @@ -91,7 +93,8 @@ void main() float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); float da_moon = dot(norm.xyz, normalize(moon_dir.xyz)); - float da = (da_sun > 0.0) ? da_sun : da_moon; + float da = (sun_up_factor == 1) ? da_sun : da_moon; + //float da = (da_sun > 0.0) ? da_sun : da_moon; da = clamp(da, 0.0, 1.0); da = pow(da, global_gamma + 0.3); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 683ab794d3..efcf848ab1 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -29,6 +29,8 @@ vec3 getAtmosAttenuation(); uniform vec4 gamma; uniform vec4 lightnorm; uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; @@ -75,7 +77,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, vec3 temp2 = vec3(0); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = sunlight_color; + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; //sunlight attenuation effect (hue and brightness) due to atmosphere diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index 86cdae8768..a26752f741 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -44,6 +44,8 @@ uniform vec3 camPosLocal; uniform vec4 lightnorm; uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; @@ -74,7 +76,7 @@ void calcAtmospherics(vec3 inPositionEye) { vec3 temp2 = vec3(0); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = sunlight_color; + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; //sunlight attenuation effect (hue and brightness) due to atmosphere diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index 3e3bd929e1..fb978691da 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -46,6 +46,8 @@ uniform vec3 camPosLocal; uniform vec4 lightnorm; uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; @@ -93,7 +95,7 @@ void main() vec4 temp2 = vec4(0.); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = sunlight_color; + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index f9f1eb7355..a65cc09c73 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -39,6 +39,8 @@ uniform vec3 camPosLocal; uniform vec4 lightnorm; uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; @@ -82,7 +84,7 @@ void main() vec4 temp2 = vec4(0.); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = sunlight_color; + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; // Sunlight attenuation effect (hue and brightness) due to atmosphere diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl index 95d5b52b45..c0ba804a30 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl @@ -44,7 +44,6 @@ uniform sampler2D cloud_noise_texture_next; uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; -uniform vec4 sunlight_color; uniform vec4 cloud_color; uniform float cloud_shadow; uniform float cloud_scale; diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl index c111456782..cc7a86f35c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -47,7 +47,6 @@ uniform sampler2D cloud_noise_texture_next; uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; -uniform vec4 sunlight_color; uniform vec4 cloud_color; uniform float cloud_shadow; uniform float cloud_scale; diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl index a1b67fc31e..852c2478bc 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl @@ -29,6 +29,8 @@ vec3 getAtmosAttenuation(); uniform vec4 gamma; uniform vec4 lightnorm; uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; @@ -69,7 +71,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, vec3 temp2 = vec3(0); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = sunlight_color; + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; //sunlight attenuation effect (hue and brightness) due to atmosphere diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl index 3270c243a4..9bd75cf118 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl @@ -38,6 +38,8 @@ uniform vec3 camPosLocal; uniform vec4 lightnorm; uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; @@ -63,7 +65,7 @@ void calcAtmospherics(vec3 inPositionEye) { vec3 temp2 = vec3(0); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = sunlight_color; + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; //sunlight attenuation effect (hue and brightness) due to atmosphere -- cgit v1.2.3 From 9f2a0d2a082495ce878f0eb0d7348b181939d348 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 8 Feb 2019 10:17:39 -0800 Subject: SL-10415 Another pass at playing with shadow_offset/bias to balance between peter-panning and shadow acne while sun and/or moon are near the horizon. --- .../shaders/class1/deferred/shadowUtil.glsl | 38 +++++++++------------- .../shaders/class2/deferred/softenLightF.glsl | 15 +++++---- 2 files changed, 24 insertions(+), 29 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 39fdd9ec44..e762871ba1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -39,20 +39,18 @@ uniform vec2 proj_shadow_res; uniform mat4 shadow_matrix[6]; uniform vec4 shadow_clip; uniform float shadow_bias; - +uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; uniform mat4 inv_proj; uniform vec2 screen_res; -int sun_up_factor; +uniform int sun_up_factor; -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) +float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { stc.xyz /= stc.w; - float offset = max(0.75, light_dir.z); - stc.z += offset * shadow_bias * bias_mul; - - stc.x = floor(stc.x*shadow_res.x + fract(stc.y*pos_screen.y*3.14159))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + stc.z += shadow_bias * bias_mul* 2.0; + stc.x = floor(stc.x*shadow_res.x + fract(stc.y*pos_screen.y*pos_screen.x))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; float shadow = cs * 4.0; @@ -62,7 +60,7 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_mul, vec2 pos_sc shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - return shadow*0.125; + return shadow * 0.125; } float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) @@ -86,23 +84,18 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) { + float shadow = 0.0f; vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float dp_sun = max(0.0, dot(sun_dir.xyz, norm)); float dp_moon = max(0.0, dot(moon_dir.xyz, norm)); - float dp_directional_light = max(dp_sun,dp_moon); + float dp_directional_light = (sun_up_factor == 1) ? dp_sun : dp_moon; dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); vec3 shadow_pos = pos.xyz; - - float shadow = 0.0f; - vec4 spos = vec4(shadow_pos,1.0); - - // if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup - if (dp_directional_light <= 0.0) - { - return 0.0; - } + vec3 offset = abs(light_dir.xyz) * (1.0 - dp_directional_light* 0.8); + shadow_pos += offset; + vec4 spos = vec4(shadow_pos.xyz, 1.0); if (spos.z > -shadow_clip.w) { @@ -118,7 +111,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos, 0.5, pos_screen, light_dir)*w; + shadow += pcfShadow(shadowMap3, norm, lpos, 4.0, pos_screen, light_dir)*w; weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } @@ -130,7 +123,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos, 0.75, pos_screen, light_dir)*w; + shadow += pcfShadow(shadowMap2, norm, lpos, 2.0, pos_screen, light_dir)*w; weight += w; } @@ -141,7 +134,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos, 0.88, pos_screen, light_dir)*w; + shadow += pcfShadow(shadowMap1, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } @@ -152,14 +145,13 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen, light_dir)*w; + shadow += pcfShadow(shadowMap0, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } shadow /= weight; } - 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 9a159e57f0..8bc9add5cf 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -91,10 +91,9 @@ void main() float envIntensity = norm.z; norm.xyz = getNorm(tc); // unpack norm - float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); - float da_moon = dot(norm.xyz, normalize(moon_dir.xyz)); + float da_sun = dot(norm.xyz, sun_dir.xyz); + float da_moon = dot(norm.xyz, moon_dir.xyz); float da = (sun_up_factor == 1) ? da_sun : da_moon; - //float da = (da_sun > 0.0) ? da_sun : da_moon; da = clamp(da, 0.0, 1.0); da = pow(da, global_gamma + 0.3); @@ -109,7 +108,7 @@ void main() vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; scol_ambocc = pow(scol_ambocc, vec2(global_gamma + 0.3)); - float scol = max(scol_ambocc.r, diffuse.a); + float scol = max(scol_ambocc.r, diffuse.a); float ambocc = scol_ambocc.g; vec3 sunlit; @@ -119,7 +118,8 @@ void main() calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); - float ambient = dot(norm.xyz, sun_dir.xyz); + float ambient = da; + ambient *= 0.5; ambient *= ambient; ambient = (1.0-ambient); @@ -127,7 +127,7 @@ void main() col.rgb = amblit; col.rgb *= min(ambient, max(scol, 0.5)); - col += (sunlit * da) * scol; + col += sunlit * da * scol; col *= diffuse.rgb; @@ -165,6 +165,9 @@ void main() col = fogged.rgb; bloom = fogged.a; #endif + +//col.rgb = vec3(scol); +//col.rgb = vec3(da * scol); } frag_color.rgb = col; frag_color.a = bloom; -- cgit v1.2.3 From 1bbf62652c0b3cfdb2046ef5a3d632f56160bb8d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 8 Feb 2019 13:59:13 -0800 Subject: SL-10457 Make area beyond far split of directional light unshadowed again. --- indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index e762871ba1..d04ac6851a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -151,13 +151,16 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) shadow /= weight; } - + else + { + return 1.0f; // lit beyond the far split... + } return shadow; } float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) { - float shadow = 0.0f; + float shadow = 1.0f; pos += norm * spot_shadow_offset; vec4 spos = vec4(pos,1.0); -- cgit v1.2.3 From aafa561215b7b69a72d00ed709d6411f6438474d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 11 Feb 2019 09:36:01 -0800 Subject: SL-10500 Replace clamp on height in atmospherics calcs on fragment shader path. Fix colorspace conversions in material shaders in forward rendering mode. Fix deferred shaders not setting the sun_up_factor uniform and getting moonlight instead of sunlight. --- .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 9 +++++++-- .../shaders/class1/deferred/postDeferredGammaCorrect.glsl | 6 +++--- .../app_settings/shaders/class2/windlight/atmosphericsF.glsl | 8 ++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 09bb6c5bb8..c8f4d7c570 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -42,6 +42,9 @@ vec3 scaleSoftClipFrag(vec3 l); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cs); + #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #ifdef DEFINE_GL_FRAGCOLOR @@ -199,7 +202,7 @@ void main() #endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 gamma_diff = diffcol.rgb; + vec3 gamma_diff = linear_to_srgb(diffcol.rgb); #endif #if HAS_SPECULAR_MAP @@ -332,6 +335,7 @@ void main() } col = atmosFragLighting(col, additive, atten); + col = scaleSoftClipFrag(col); vec3 npos = normalize(-pos.xyz); @@ -352,7 +356,8 @@ void main() glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; - col = scaleSoftClipFrag(col); + //convert to gamma space for display on screen + col.rgb = linear_to_srgb(col.rgb); #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index cbc19bbba3..058e939ec8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -44,8 +44,8 @@ vec3 linear_to_srgb(vec3 cl); void main() { - vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - diff.rgb = linear_to_srgb(diff.rgb); - frag_color = diff; + vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); + diff.rgb = linear_to_srgb(diff.rgb); + frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index efcf848ab1..565c00ba79 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -67,7 +67,11 @@ vec3 atmosLighting(vec3 light) void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { vec3 P = inPositionEye; - + + //(TERRAIN) limit altitude + if (P.y > max_y) P *= (max_y / P.y); + if (P.y < -max_y) P *= (-max_y / P.y); + vec3 tmpLightnorm = lightnorm.xyz; vec3 Pn = normalize(P); @@ -93,7 +97,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) temp2.y = max(0.0, tmpLightnorm.y); temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); + sunlight *= exp(-light_atten * temp2.y); // main atmospheric scattering line integral temp2.z = Plen * density_multiplier; -- cgit v1.2.3 From 65927e0a76aaf8ff4dc268acdb12007265ff3a14 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 13 Feb 2019 13:09:14 -0800 Subject: SL-10181, SL-10546 Fix distortion map rendering in deferred mode not including underwater fog effects. Fix distortion map rendering not including post-deferred content at all. Fix distortion map rendering not including anything but sky when camera is underwater. Update sun_up_factor/sunmoon_glow_factor uniforms even when sun disc isn't in use. --- .../shaders/class1/deferred/alphaF.glsl | 2 +- .../shaders/class1/deferred/terrainF.glsl | 39 +++++++----- .../shaders/class1/deferred/terrainV.glsl | 52 ++++++++-------- .../shaders/class1/deferred/waterF.glsl | 1 - .../shaders/class1/environment/waterFogF.glsl | 70 +++++++++++----------- 5 files changed, 88 insertions(+), 76 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 9883ece648..1ba10fa8b7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -215,10 +215,10 @@ void main() // keep it linear // color.rgb += light.rgb; +#endif #ifdef WATER_FOG color = applyWaterFogView(pos.xyz, color); -#endif #endif frag_color = color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 0cd90b0d97..d7b2a9cc8e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -37,29 +37,38 @@ uniform sampler2D detail_2; uniform sampler2D detail_3; uniform sampler2D alpha_ramp; +VARYING vec3 pos; VARYING vec3 vary_normal; VARYING vec4 vary_texcoord0; VARYING vec4 vary_texcoord1; vec2 encode_normal(vec3 n); +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 c); +#endif + void main() { - /// Note: This should duplicate the blending functionality currently used for the terrain rendering. - - vec4 color0 = texture2D(detail_0, vary_texcoord0.xy); - vec4 color1 = texture2D(detail_1, vary_texcoord0.xy); - vec4 color2 = texture2D(detail_2, vary_texcoord0.xy); - vec4 color3 = texture2D(detail_3, vary_texcoord0.xy); + /// Note: This should duplicate the blending functionality currently used for the terrain rendering. + + vec4 color0 = texture2D(detail_0, vary_texcoord0.xy); + vec4 color1 = texture2D(detail_1, vary_texcoord0.xy); + vec4 color2 = texture2D(detail_2, vary_texcoord0.xy); + vec4 color3 = texture2D(detail_3, vary_texcoord0.xy); + + float alpha1 = texture2D(alpha_ramp, vary_texcoord0.zw).a; + float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; + float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; + vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); + +#ifdef WATER_FOG + outColor = applyWaterFogView(pos.xyz, outColor); +#endif - float alpha1 = texture2D(alpha_ramp, vary_texcoord0.zw).a; - float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; - float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; - vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); - - frag_data[0] = vec4(outColor.rgb, 0.0); - frag_data[1] = vec4(0,0,0,0); - vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); + frag_data[0] = vec4(outColor.rgb, 0.0); + frag_data[1] = vec4(0,0,0,0); + vec3 nvn = normalize(vary_normal); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl index 5effee4e4e..04fdc18b78 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl @@ -33,8 +33,8 @@ ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; ATTRIBUTE vec2 texcoord1; +VARYING vec3 pos; VARYING vec3 vary_normal; - VARYING vec4 vary_texcoord0; VARYING vec4 vary_texcoord1; @@ -43,31 +43,35 @@ uniform vec4 object_plane_t; vec4 texgen_object(vec4 vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1) { - vec4 tcoord; - - tcoord.x = dot(vpos, tp0); - tcoord.y = dot(vpos, tp1); - tcoord.z = tc.z; - tcoord.w = tc.w; - - tcoord = mat * tcoord; - - return tcoord; + vec4 tcoord; + + tcoord.x = dot(vpos, tp0); + tcoord.y = dot(vpos, tp1); + tcoord.z = tc.z; + tcoord.w = tc.w; + + tcoord = mat * tcoord; + + return tcoord; } void main() { - //transform vertex - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - - vary_normal = normalize(normal_matrix * normal); - - // Transform and pass tex coords - vary_texcoord0.xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; - - vec4 t = vec4(texcoord1,0,1); - - vary_texcoord0.zw = t.xy; - vary_texcoord1.xy = t.xy-vec2(2.0, 0.0); - vary_texcoord1.zw = t.xy-vec2(1.0, 0.0); + //transform vertex + vec4 pre_pos = vec4(position.xyz, 1.0); + vec4 t_pos = modelview_projection_matrix * pre_pos; + + gl_Position = t_pos; + pos = t_pos.xyz; + + vary_normal = normalize(normal_matrix * normal); + + // Transform and pass tex coords + vary_texcoord0.xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; + + vec4 t = vec4(texcoord1,0,1); + + vary_texcoord0.zw = t.xy; + vary_texcoord1.xy = t.xy-vec2(2.0, 0.0); + vary_texcoord1.zw = t.xy-vec2(1.0, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index ee028d8194..be5e3538a7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -156,7 +156,6 @@ void main() //mix with reflection // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug - refcol.rgb = pow(refcol.rgb, vec3(0.45)); // boost the reflect color a little to get stars to show up SL-1475 color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); vec4 pos = vary_position; diff --git a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl index 68ce2843d0..856924b1e5 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl @@ -34,46 +34,46 @@ vec3 getPositionEye(); vec4 applyWaterFogView(vec3 pos, vec4 color) { - vec3 view = normalize(pos); - //normalize view vector - float es = -(dot(view, waterPlane.xyz)); + vec3 view = normalize(pos); + //normalize view vector + float es = -(dot(view, waterPlane.xyz)); - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); + + //get object depth + float depth = length(pos - int_v); + + //get "thickness" of water + float l = max(depth, 0.1); - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2*l) - 1.0; + + float L = min(t1/t2*t3, 1.0); + + float D = pow(0.98, l*kd); + + color.rgb = color.rgb * D + kc.rgb * L; + color.a = kc.a + color.a; + + return color; } vec4 applyWaterFog(vec4 color) { - //normalize view vector - return applyWaterFogView(getPositionEye(), color); + //normalize view vector + return applyWaterFogView(getPositionEye(), color); } -- cgit v1.2.3 From e3c376d3812f8a2f3868f5baa71fffc785f35911 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 14 Feb 2019 16:33:20 -0800 Subject: SL-10552 Fix view-dependent peter-panning from incorrectly biased shadow pos offset. --- .../app_settings/shaders/class1/deferred/shadowUtil.glsl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index d04ac6851a..5cc24475e3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -81,20 +81,18 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; return shadow*0.2; } - float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) { float shadow = 0.0f; - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + vec3 light_dir = normalize((sun_up_factor == 1) ? sun_dir : moon_dir); - float dp_sun = max(0.0, dot(sun_dir.xyz, norm)); - float dp_moon = max(0.0, dot(moon_dir.xyz, norm)); - float dp_directional_light = (sun_up_factor == 1) ? dp_sun : dp_moon; + float dp_directional_light = max(0.0, dot(norm.xyz, light_dir)); dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); vec3 shadow_pos = pos.xyz; vec3 offset = abs(light_dir.xyz) * (1.0 - dp_directional_light* 0.8); - shadow_pos += offset; + shadow_pos += offset * shadow_offset; + vec4 spos = vec4(shadow_pos.xyz, 1.0); if (spos.z > -shadow_clip.w) -- cgit v1.2.3 From 4aad62006259c20bcdda1495138f7313b8f35e8d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 22 Feb 2019 14:50:03 -0800 Subject: SL-10415, SL-10612, SL-10569 Fix shadow sampling min with caster dp and offset tweaks. Fix moon direction not being transformed as the sun dir is. Fix colorspace issue causing some objects to render grayish instead of blackish. --- .../shaders/class1/deferred/materialF.glsl | 21 ++++++++----- .../shaders/class1/deferred/shadowUtil.glsl | 13 ++++---- .../shaders/class2/deferred/softenLightF.glsl | 35 +++++++++++----------- 3 files changed, 39 insertions(+), 30 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c8f4d7c570..251e60c59e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -202,7 +202,8 @@ void main() #endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 gamma_diff = linear_to_srgb(diffcol.rgb); + vec3 gamma_diff = diffcol.rgb; + diffcol.rgb = srgb_to_linear(diffcol.rgb); #endif #if HAS_SPECULAR_MAP @@ -280,20 +281,17 @@ void main() final_da = min(final_da, 1.0f); final_da = pow(final_da, display_gamma); - col.rgb = (col * 0.5) + amblit; + col.rgb = amblit; float ambient = min(abs(final_da), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0-ambient); - col.rgb *= ambient; - - col.rgb = col.rgb + (final_da * sunlit); - + col.rgb *= min(ambient, max(shadow,0.3)); + col.rgb += (final_da * sunlit); col.rgb *= gamma_diff.rgb; - float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -315,6 +313,7 @@ void main() col += spec_contrib; } +vec3 post_spec = col.rgb; col = mix(col.rgb, diffcol.rgb, diffuse.a); @@ -337,6 +336,8 @@ void main() col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); +vec3 post_atmo= col.rgb; + vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -353,18 +354,24 @@ void main() col.rgb += light.rgb; +vec3 post_lighting = col.rgb; + glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; //convert to gamma space for display on screen col.rgb = linear_to_srgb(col.rgb); +vec3 post_srgb = col.rgb; + #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); col.rgb = temp.rgb; al = temp.a; #endif +//col.rgb = post_lighting; + 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 5cc24475e3..ad96c84de8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -49,8 +49,8 @@ uniform int sun_up_factor; float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { stc.xyz /= stc.w; - stc.z += shadow_bias * bias_mul* 2.0; - stc.x = floor(stc.x*shadow_res.x + fract(stc.y*pos_screen.y*pos_screen.x))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + stc.z += shadow_bias * bias_mul * 2.0; + stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; float shadow = cs * 4.0; @@ -90,7 +90,9 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); vec3 shadow_pos = pos.xyz; - vec3 offset = abs(light_dir.xyz) * (1.0 - dp_directional_light* 0.8); + + vec3 offset = light_dir.xyz * (1.0 - dp_directional_light); + shadow_pos += offset * shadow_offset; vec4 spos = vec4(shadow_pos.xyz, 1.0); @@ -109,7 +111,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, norm, lpos, 4.0, pos_screen, light_dir)*w; + shadow += pcfShadow(shadowMap3, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } @@ -121,7 +123,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, norm, lpos, 2.0, pos_screen, light_dir)*w; + shadow += pcfShadow(shadowMap2, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } @@ -153,6 +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); 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 8bc9add5cf..7fd4d7e248 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -90,17 +90,16 @@ void main() vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; norm.xyz = getNorm(tc); // unpack norm - - float da_sun = dot(norm.xyz, sun_dir.xyz); - float da_moon = dot(norm.xyz, moon_dir.xyz); - float da = (sun_up_factor == 1) ? da_sun : da_moon; - da = clamp(da, 0.0, 1.0); - da = pow(da, global_gamma + 0.3); + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + + float da = dot(norm.xyz, light_dir.xyz); + da = clamp(da, 0.0, 1.0); vec4 diffuse = texture2DRect(diffuseRect, tc); vec3 col; + float scol = 1.0; float bloom = 0.0; { vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); @@ -108,9 +107,13 @@ void main() vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; scol_ambocc = pow(scol_ambocc, vec2(global_gamma + 0.3)); - float scol = max(scol_ambocc.r, diffuse.a); + 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; @@ -118,18 +121,17 @@ void main() calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); - float ambient = da; - + float ambient = min(da, 1.0); ambient *= 0.5; ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb = amblit; - col.rgb *= min(ambient, max(scol, 0.5)); + ambient = min(1.0 - ambient,max(scol,0.3)); - col += sunlit * da * scol; + vec3 sun_contrib = sunlit * final_da; - col *= diffuse.rgb; + col.rgb = amblit; + col.rgb *= ambient; + col.rgb += sun_contrib; + col.rgb *= diffuse.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -165,9 +167,6 @@ void main() col = fogged.rgb; bloom = fogged.a; #endif - -//col.rgb = vec3(scol); -//col.rgb = vec3(da * scol); } frag_color.rgb = col; frag_color.a = bloom; -- cgit v1.2.3 From bc86ad9523460ae883ea840d7b11c9de542a14aa Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 22 Feb 2019 17:03:11 -0800 Subject: SL-5186 Add ambiance handling to the light loop in the forward incarnation of materialF and tweak alphaF to match lighing of material alpha-blend objects and non-ALM rendering. --- .../shaders/class1/deferred/alphaF.glsl | 10 +++--- .../shaders/class1/deferred/materialF.glsl | 37 +++++++++++----------- 2 files changed, 23 insertions(+), 24 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 1ba10fa8b7..948a195b7a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -60,7 +60,7 @@ VARYING vec4 vertex_color; uniform mat4 inv_proj; uniform vec2 screen_res; - +uniform int sun_up_factor; uniform vec4 light_position[8]; uniform vec3 light_direction[8]; uniform vec4 light_attenuation[8]; @@ -173,13 +173,13 @@ void main() vec2 abnormal = encode_normal(norm.xyz); - float sun_da = dot(norm.xyz, sun_dir.xyz); - float moon_da = dot(norm.xyz, moon_dir.xyz); + vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; + float da = dot(norm.xyz, light_dir.xyz); - float final_da = max(sun_da, moon_da); + float final_da = da; final_da = min(final_da, shadow); final_da = clamp(final_da, 0.0f, 1.0f); - final_da = pow(final_da, display_gamma); + final_da = pow(final_da, 1.0/display_gamma); vec4 color = vec4(0,0,0,0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 251e60c59e..6dcfaddd44 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -32,6 +32,7 @@ uniform float emissive_brightness; uniform float display_gamma; +uniform int sun_up_factor; #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); @@ -77,10 +78,10 @@ uniform vec2 screen_res; uniform vec4 light_position[8]; uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[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) +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) { //get light vector vec3 lv = lp.xyz-v; @@ -114,6 +115,12 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe col = light_col*lit*diffuse; + float amb_da = (da*da*0.5 + 0.25) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + + col.rgb += amb_da * light_col * diffuse; + if (spec.a > 0.0) { //vec3 ref = dot(pos+lv, norm); @@ -203,7 +210,6 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vec3 gamma_diff = diffcol.rgb; - diffcol.rgb = srgb_to_linear(diffcol.rgb); #endif #if HAS_SPECULAR_MAP @@ -271,15 +277,14 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float sun_da = dot(norm.xyz, sun_dir.xyz); - float moon_da = dot(norm.xyz, moon_dir.xyz); + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + float da = dot(norm.xyz, light_dir.xyz); - float final_da = max(sun_da,moon_da); + 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); - final_da = pow(final_da, display_gamma); col.rgb = amblit; @@ -289,8 +294,9 @@ void main() ambient = (1.0-ambient); col.rgb *= min(ambient, max(shadow,0.3)); + col.rgb += (final_da * sunlit); - col.rgb *= gamma_diff.rgb; + col.rgb *= diffuse.rgb; float glare = 0.0; @@ -315,7 +321,7 @@ void main() vec3 post_spec = col.rgb; - col = mix(col.rgb, diffcol.rgb, diffuse.a); + col = mix(col.rgb, diffuse.rgb, diffuse.a); if (envIntensity > 0.0) { @@ -333,8 +339,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; @@ -342,7 +348,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); + #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); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -359,19 +365,12 @@ vec3 post_lighting = col.rgb; glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; - //convert to gamma space for display on screen - col.rgb = linear_to_srgb(col.rgb); - -vec3 post_srgb = col.rgb; - #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); col.rgb = temp.rgb; al = temp.a; #endif -//col.rgb = post_lighting; - frag_color.rgb = col.rgb; frag_color.a = al; -- cgit v1.2.3 From 8b0e2e4c82ae598f09a1f0cbf5d216804461155b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 25 Feb 2019 12:12:29 -0800 Subject: SL-9806 Remove blend effect when sun disc nears horizon (was letting the stars show through). --- indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index 5bb2020971..17494361f0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -52,7 +52,7 @@ void main() c.rgb = fullbrightAtmosTransport(c.rgb); c.rgb = fullbrightScaleSoftClip(c.rgb); - c.a *= sun_fade; + //c.a *= sun_fade; frag_data[0] = c; frag_data[1] = vec4(0.0f); diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl index 668379164d..5b6fefcad9 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl @@ -47,7 +47,9 @@ void main() vec4 sunA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 sunB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(sunA, sunB, blend_factor); - c.a *= sun_fade; + +// SL-9806 +// c.a *= sun_fade; c.rgb = pow(c.rgb, vec3(0.7f)); c.rgb = fullbrightAtmosTransport(c.rgb); -- cgit v1.2.3 From 5cd188840d968731047aa89459ff63f605709c6e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 25 Feb 2019 12:14:59 -0800 Subject: SL-9806 Remove fade effect on sun disc as it nears horizon (stars poke through). --- indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl | 3 ++- indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index 5bb2020971..1fb337498c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -52,7 +52,8 @@ void main() c.rgb = fullbrightAtmosTransport(c.rgb); c.rgb = fullbrightScaleSoftClip(c.rgb); - c.a *= sun_fade; + // SL-9806 stars poke through + //c.a *= sun_fade; frag_data[0] = c; frag_data[1] = vec4(0.0f); diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl index 668379164d..d85ce004a5 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl @@ -47,7 +47,9 @@ void main() vec4 sunA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 sunB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(sunA, sunB, blend_factor); - c.a *= sun_fade; + +// SL-9806 stars poke through +// c.a *= sun_fade; c.rgb = pow(c.rgb, vec3(0.7f)); c.rgb = fullbrightAtmosTransport(c.rgb); -- cgit v1.2.3 From f9896dc100ccd6dd2d92610cb4f71f61284f76a6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 26 Feb 2019 10:09:32 -0800 Subject: 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. --- .../shaders/class1/deferred/alphaF.glsl | 42 ++++++++------- .../shaders/class1/deferred/materialF.glsl | 59 ++++++++++++---------- .../shaders/class1/deferred/shadowUtil.glsl | 2 +- .../shaders/class2/deferred/softenLightF.glsl | 28 +++++----- 4 files changed, 71 insertions(+), 60 deletions(-) (limited to 'indra/newview/app_settings/shaders') 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; -- cgit v1.2.3 From 6f820163ce3a42eb90edba6f3907952e7d83517c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 26 Feb 2019 14:51:02 -0800 Subject: SL-10566 part the first Tie using deferred rendering in water reflection/distortion map generation to debug var again (claw back some performance lost to doing post-deferred in water map generation). Edit softenLightF for class1/class2 to make them comparable again. --- .../shaders/class1/deferred/alphaF.glsl | 17 +++++++ .../shaders/class1/deferred/materialF.glsl | 16 ++++++- .../shaders/class1/deferred/softenLightF.glsl | 56 ++++++++++++++-------- .../shaders/class2/deferred/softenLightF.glsl | 12 ++--- 4 files changed, 75 insertions(+), 26 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index df0ff4e654..f570908b45 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -76,7 +76,16 @@ vec3 linear_to_srgb(vec3 c); vec2 encode_normal (vec3 n); vec3 scaleSoftClipFrag(vec3 l); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); + +#if defined(VERT_ATMOSPHERICS) +vec3 getSunlitColor(); +vec3 getAmblitColor(); +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); +void calcAtmospherics(vec3 inPositionEye, float ambFactor); +#else void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); +#endif float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); @@ -174,7 +183,15 @@ void main() vec3 amblit; vec3 additive; vec3 atten; + +#if VERT_ATMOSPHERICS + sunlit = getSunlitColor(); + amblit = getAmblitColor(); + additive = getAdditiveColor(); + atten = getAtmosAttenuation(); +#else calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); +#endif vec2 abnormal = encode_normal(norm.xyz); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 586926dc01..a18eb7b075 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -41,7 +41,14 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); +#if defined(VERT_ATMOSPHERICS) +vec3 getSunlitColor(); +vec3 getAmblitColor(); +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); +#else void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +#endif vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -278,8 +285,15 @@ void main() vec3 additive; vec3 atten; +#if VERT_ATMOSPHERICS + sunlit = getSunlitColor(); + amblit = getAmblitColor(); + additive = getAdditiveColor(); + atten = getAtmosAttenuation(); +#else calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - +#endif + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 9e0079e0e9..bd187ed5fc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -57,6 +57,7 @@ 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; @@ -69,7 +70,16 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 getNorm(vec2 pos_screen); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 fullbrightAtmosTransportFrag(vec3 l, vec3 additive, vec3 atten); + +#if defined(VERT_ATMOSPHERICS) +vec3 getPositionEye(); +vec3 getSunlitColor(); +vec3 getAmblitColor(); +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); +#else void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +#endif vec3 scaleSoftClip(vec3 l); vec3 fullbrightScaleSoftClip(vec3 l); @@ -84,13 +94,14 @@ void main() vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; norm.xyz = getNorm(tc); - - float da_sun = dot(norm.xyz, normalize(sun_dir.xyz)); - float da_moon = dot(norm.xyz, normalize(moon_dir.xyz)); - float da = max(da_sun, da_moon); + + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + + float da = dot(normalize(norm.xyz), light_dir.xyz); + da = clamp(da, 0.0, 1.0); - float final_da = clamp(da, 0.0, 1.0); - final_da = pow(final_da, global_gamma + 0.3); + float light_gamma = 1.0/1.3; + da = pow(da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); @@ -102,25 +113,33 @@ void main() vec3 amblit; vec3 additive; vec3 atten; + +#if defined(VERT_ATMOSPHERICS) + sunlit = getSunlitColor(); + amblit = getAmblitColor(); + additive = getAdditiveColor(); + atten = getAtmosAttenuation(); +#else calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); +#endif + + float ambient = min(abs(da), 1.0); ambient *= 0.5; ambient *= ambient; - ambient = (1.0 - ambient); + ambient = 1.0 - ambient; + + vec3 sun_contrib = da * sunlit; + + col.rgb = amblit; + col.rgb *= ambient; + col.rgb += sun_contrib; + col.rgb *= diffuse.rgb; - col = amblit; - col *= ambient; - col += (final_da * sunlit); - col *= diffuse.rgb; - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection { // the old infinite-sky shiny reflection - // - float sa = dot(refnormpersp, sun_dir.xyz); vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); @@ -131,12 +150,12 @@ void main() } col = mix(col.rgb, diffuse.rgb, diffuse.a); - + 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); + col = mix(col.rgb, refcol, envIntensity); } if (norm.w < 0.5) @@ -155,4 +174,3 @@ void main() frag_color.rgb = col.rgb; frag_color.a = bloom; } - diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 57997245f8..415c894a43 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -101,17 +101,16 @@ void main() da = clamp(da, 0.0, 1.0); float light_gamma = 1.0/1.3; - da = pow(da, light_gamma); + da = pow(da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); scol = max(scol_ambocc.r, diffuse.a); + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 col; float bloom = 0.0; { - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - float ambocc = scol_ambocc.g; vec3 sunlit; @@ -147,7 +146,7 @@ void main() col += spec_contrib; } - col = mix(col, diffuse.rgb, diffuse.a); + col = mix(col.rgb, diffuse.rgb, diffuse.a); if (envIntensity > 0.0) { //add environmentmap @@ -155,7 +154,7 @@ void main() vec3 refcol = textureCube(environmentMap, env_vec).rgb; col = mix(col.rgb, refcol, envIntensity); } - + if (norm.w < 0.5) { col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); @@ -168,6 +167,7 @@ void main() bloom = fogged.a; #endif } - frag_color.rgb = col; + + frag_color.rgb = col.rgb; frag_color.a = bloom; } -- cgit v1.2.3 From 2b9943d6f2a02423f555d46e8100a68483f26244 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 26 Feb 2019 15:07:33 -0800 Subject: Fix up ifdefs to make OSX shader compiler happy. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index f570908b45..99988646c0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -184,7 +184,7 @@ void main() vec3 additive; vec3 atten; -#if VERT_ATMOSPHERICS +#if deifned(VERT_ATMOSPHERICS) sunlit = getSunlitColor(); amblit = getAmblitColor(); additive = getAdditiveColor(); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a18eb7b075..e2ebd928ef 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -285,7 +285,7 @@ void main() vec3 additive; vec3 atten; -#if VERT_ATMOSPHERICS +#if defined(VERT_ATMOSPHERICS) sunlit = getSunlitColor(); amblit = getAmblitColor(); additive = getAdditiveColor(); -- cgit v1.2.3 From 4f1e39d4a4e75326a469576c16488bc62396c618 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 26 Feb 2019 16:13:32 -0800 Subject: Fix ifdef in alphaF. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 99988646c0..6e1f0f201b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -184,7 +184,7 @@ void main() vec3 additive; vec3 atten; -#if deifned(VERT_ATMOSPHERICS) +#if defined(VERT_ATMOSPHERICS) sunlit = getSunlitColor(); amblit = getAmblitColor(); additive = getAdditiveColor(); -- cgit v1.2.3 From c1d2416826406631807f153e7de9d2b790b0caa5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 28 Feb 2019 14:06:19 -0800 Subject: EEP performance WIP Mods to improve alpha obj render performance. Removes hacky fix for HUD elements getting atmospherics. Re-orders rendering of glow to remove ~10ms/frame of shader re-re-rebinding. Fix up default classes and basic shader loading (remove unused shared modules). --- .../shaders/class1/avatar/avatarSkinV.glsl | 7 +++++++ .../shaders/class1/avatar/objectSkinV.glsl | 7 +++++++ .../class1/windlight/atmosphericsHelpersF.glsl | 2 -- .../class1/windlight/atmosphericsHelpersV.glsl | 2 -- .../shaders/class1/windlight/gammaF.glsl | 1 - .../shaders/class1/windlight/transportF.glsl | 2 -- .../shaders/class2/deferred/multiSpotLightF.glsl | 1 + .../shaders/class2/windlight/atmosphericsF.glsl | 5 ----- .../class2/windlight/atmosphericsHelpersF.glsl | 2 -- .../class2/windlight/atmosphericsHelpersV.glsl | 2 -- .../shaders/class2/windlight/atmosphericsV.glsl | 14 ++----------- .../shaders/class2/windlight/gammaF.glsl | 13 +++++------- .../shaders/class2/windlight/transportF.glsl | 21 ++++--------------- .../shaders/class3/windlight/transportF.glsl | 24 +++++----------------- 14 files changed, 31 insertions(+), 72 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl b/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl index c4caed4d71..767fad016c 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/avatarSkinV.glsl @@ -38,5 +38,12 @@ mat4 getSkinnedTransform() ret[1] = mix(matrixPalette[i+15],matrixPalette[i+16], x); ret[2] = mix(matrixPalette[i+30],matrixPalette[i+31], x); ret[3] = vec4(0,0,0,1); + return ret; + +#ifdef IS_AMD_CARD + // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. + vec4 dummy1 = matrixPalette[0]; + vec4 dummy2 = matrixPalette[44]; +#endif } diff --git a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl index 94de2f7b53..90bf2851c9 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl @@ -61,5 +61,12 @@ mat4 getObjectSkinnedTransform() ret[3] = vec4(trans, 1.0); return ret; + +#ifdef IS_AMD_CARD + // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. + mat3x4 dummy1 = matrixPalette[0]; + mat3x4 dummy2 = matrixPalette[MAX_JOINTS_PER_MESH_OBJECT-1]; +#endif + } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl index 10407eeb02..3572331d74 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl @@ -25,11 +25,9 @@ uniform vec4 sunlight_color; uniform vec4 light_ambient; -uniform int no_atmo; vec3 atmosAmbient(vec3 light) { - if (no_atmo == 1) return light + vec3(0.66); return light + light_ambient.rgb; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl index 14034bccae..7e4855b7c6 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl @@ -25,11 +25,9 @@ uniform vec4 sunlight_color; uniform vec4 light_ambient; -uniform int no_atmo; vec3 atmosAmbient(vec3 light) { - if (no_atmo == 1) return light + vec3(0.66); return light + light_ambient.rgb; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl index 667301443a..9917ba8d3b 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl @@ -23,7 +23,6 @@ * $/LicenseInfo$ */ -uniform int no_atmo; uniform vec4 gamma; vec3 scaleSoftClipFrag(vec3 light) diff --git a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl index e2b391cb7a..f61194db6d 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl @@ -23,8 +23,6 @@ * $/LicenseInfo$ */ -uniform int no_atmo; - vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { /* stub function for fallback compatibility on class1 hardware */ diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 142b03e095..0f6bf38388 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -212,6 +212,7 @@ void main() col = dlit*lit*diff_tex*shadow; amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; + amb_da = min(amb_da,shadow); } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 565c00ba79..ebb06e0f23 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -43,17 +43,12 @@ uniform float max_y; uniform vec4 glow; uniform float scene_light_strength; uniform mat3 ssao_effect_mat; -uniform int no_atmo; uniform float sun_moon_glow_factor; vec3 scaleSoftClipFrag(vec3 light); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } light *= atten.r; light += additive; return light * 2.0; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl index 86743dc306..c836ca98c5 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl @@ -26,11 +26,9 @@ // Output variables uniform float scene_light_strength; -uniform int no_atmo; vec3 atmosFragAmbient(vec3 light, vec3 amblit) { - if (no_atmo == 1) return light; return amblit + light / 2.0; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl index 95b4a76880..589c95bc96 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl @@ -33,11 +33,9 @@ vec3 getAtmosAttenuation(); vec3 getPositionEye(); uniform float scene_light_strength; -uniform int no_atmo; vec3 atmosAmbient(vec3 light) { - if (no_atmo == 1) return light + vec3(0.66); return getAmblitColor() + light / 2.0; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index a26752f741..bef7a8827a 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -64,8 +64,8 @@ void calcAtmospherics(vec3 inPositionEye) { setPositionEye(P); //(TERRAIN) limit altitude - //if (P.y > max_y) P *= (max_y / P.y); - //if (P.y < -max_y) P *= (-max_y / P.y); + if (P.y > max_y) P *= (max_y / P.y); + if (P.y < -max_y) P *= (-max_y / P.y); vec3 tmpLightnorm = lightnorm.xyz; @@ -134,21 +134,11 @@ void calcAtmospherics(vec3 inPositionEye) { + tmpAmbient)); additive = normalize(additive); - //haze color - //setAdditiveColor( - // vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - // + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - // + tmpAmbient))); - //brightness of surface both sunlight and ambient setSunlitColor(vec3(sunlight * .5)); setAmblitColor(vec3(tmpAmbient * .25)); setAdditiveColor(additive * vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5); - // vary_SunlitColor = vec3(0); - // vary_AmblitColor = vec3(0); - // vary_AdditiveColor = vec4(Pn, 1.0); - /* const float cloudShadowScale = 100.; // Get cloud uvs for shadowing diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index 143bafc9c9..e985c50c67 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -26,16 +26,12 @@ uniform vec4 gamma; -uniform int no_atmo; vec3 getAtmosAttenuation(); +vec3 getAdditiveColor(); vec3 scaleSoftClipFrag(vec3 light) { - if (no_atmo == 1) - { - return light; - } //soft clip effect: light = 1. - clamp(light, vec3(0.), vec3(1.)); light = 1. - pow(light, gamma.xxx); @@ -47,12 +43,13 @@ vec3 scaleSoftClip(vec3 light) return scaleSoftClipFrag(light); } -vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 add, vec3 atten) { - return scaleSoftClipFrag(light.rgb); +vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 add, vec3 atten) +{ + return mix(scaleSoftClipFrag(light.rgb), add, atten); } vec3 fullbrightScaleSoftClip(vec3 light) { - return scaleSoftClipFrag(light); + return fullbrightScaleSoftClipFrag(light, getAdditiveColor(), getAtmosAttenuation()); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index df731662e8..d799453712 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -30,34 +30,21 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); -uniform int no_atmo; - vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } light *= atten.r; - light += additive * 2.0; - return light; + light += additive; + return light * 2.0; } vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } float brightness = dot(light.rgb, vec3(0.33333)); return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); } -vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } +vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ float brightness = dot(light.rgb, vec3(0.33333)); return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); } diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index 90ab5d2793..7f74122665 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -30,35 +30,21 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); -uniform int no_atmo; - vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } - return (light + additive) * atten * 2.0; + return (light + additive) * atten * 2.0; } vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive,atten), light.rgb + additive.rgb, brightness * brightness); + float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosTransportFrag(light.rgb, additive,atten), light.rgb + additive.rgb, brightness * brightness); } vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); + float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); } vec3 atmosTransport(vec3 light) -- cgit v1.2.3 From d8eff424a5fb340b828802351e2b7f6b63bfa30f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sat, 2 Mar 2019 07:17:46 -0800 Subject: SL-10664 --- indra/newview/app_settings/shaders/class1/deferred/cofF.glsl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl index 380d382020..079d8458c9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl @@ -50,8 +50,6 @@ uniform vec2 screen_res; VARYING vec2 vary_fragcoord; -float getDepth(vec2 pos_screen); - float calc_cof(float depth) { float sc = (depth-focal_distance)/-depth*blur_constant; @@ -70,8 +68,12 @@ float calc_cof(float depth) void main() { vec2 tc = vary_fragcoord.xy; - - float depth = getDepth(tc); + + float z = texture2DRect(depthMap, tc).r; + z = z*2.0-1.0; + vec4 ndc = vec4(0.0, 0.0, z, 1.0); + vec4 p = inv_proj*ndc; + float depth = p.z/p.w; vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); -- cgit v1.2.3 From 4c3050a3953153aa8753fc10706ad2ef464f3e3d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sun, 3 Mar 2019 10:42:19 -0800 Subject: SL-10664, SL-10666 Fix up culling issues from perf work and fix Depth of Field rendering to get depth values properly. Baseline for performance work. --- .../shaders/class1/deferred/alphaF.glsl | 2 +- .../shaders/class1/deferred/materialF.glsl | 2 +- .../shaders/class1/deferred/waterF.glsl | 2 ++ .../class1/windlight/atmosphericsHelpersF.glsl | 2 ++ .../class1/windlight/atmosphericsHelpersV.glsl | 2 ++ .../shaders/class1/windlight/gammaF.glsl | 1 + .../shaders/class1/windlight/transportF.glsl | 2 ++ .../shaders/class2/deferred/multiSpotLightF.glsl | 6 ++++-- .../shaders/class2/deferred/softenLightF.glsl | 7 +++++-- .../shaders/class2/windlight/atmosphericsF.glsl | 5 +++++ .../class2/windlight/atmosphericsHelpersF.glsl | 2 ++ .../class2/windlight/atmosphericsHelpersV.glsl | 2 ++ .../shaders/class2/windlight/gammaF.glsl | 8 +++++++- .../shaders/class2/windlight/transportF.glsl | 21 +++++++++++++++---- .../shaders/class3/windlight/transportF.glsl | 24 +++++++++++++++++----- 15 files changed, 72 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 6e1f0f201b..9191787273 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -118,7 +118,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec da *= spot*spot; // GL_SPOT_EXPONENT=2 // to match spotLight (but not multiSpotLight) *sigh* - float lit = max(min(da, shadow) * dist_atten,0.0); + float lit = max(da * dist_atten,0.0); col = lit * light_col * diffuse; float amb_da = ambiance; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index e2ebd928ef..4db2b9ae54 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -119,7 +119,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe da *= clamp(da, 0.0, 1.0); da *= pow(da, 1.0 / 1.3); - float lit = max(min(da,shadow) * dist_atten, 0.0); + float lit = max(da * dist_atten, 0.0); col = light_col*lit*diffuse; diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index be5e3538a7..628f73da59 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -167,6 +167,8 @@ void main() vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); +color.rgb = max(fb.rgb, refcol.rgb); + frag_data[0] = vec4(color.rgb, 1); // diffuse frag_data[1] = vec4(0); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl index 3572331d74..10407eeb02 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl @@ -25,9 +25,11 @@ uniform vec4 sunlight_color; uniform vec4 light_ambient; +uniform int no_atmo; vec3 atmosAmbient(vec3 light) { + if (no_atmo == 1) return light + vec3(0.66); return light + light_ambient.rgb; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl index 7e4855b7c6..14034bccae 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl @@ -25,9 +25,11 @@ uniform vec4 sunlight_color; uniform vec4 light_ambient; +uniform int no_atmo; vec3 atmosAmbient(vec3 light) { + if (no_atmo == 1) return light + vec3(0.66); return light + light_ambient.rgb; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl index 9917ba8d3b..667301443a 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl @@ -23,6 +23,7 @@ * $/LicenseInfo$ */ +uniform int no_atmo; uniform vec4 gamma; vec3 scaleSoftClipFrag(vec3 light) diff --git a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl index f61194db6d..e2b391cb7a 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +uniform int no_atmo; + vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { /* stub function for fallback compatibility on class1 hardware */ diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 0f6bf38388..275bc829a7 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -211,8 +211,10 @@ void main() dlit = color.rgb * plcol.rgb * plcol.a; col = dlit*lit*diff_tex*shadow; - amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; - amb_da = min(amb_da,shadow); + amb_da += (da*0.5) * proj_ambiance; + amb_da += (da*da*0.5 + 0.5) * proj_ambiance; + //amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; + //amb_da = min(amb_da,shadow); } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 415c894a43..d220bda332 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -120,7 +120,7 @@ void main() calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); - float ambient = min(abs(da), 1.0); + float ambient = abs(da); ambient *= 0.5; ambient *= ambient; ambient = 1.0 - ambient * smoothstep(0.0, 0.3, scol); @@ -155,6 +155,8 @@ void main() col = mix(col.rgb, refcol, envIntensity); } + +vec3 a = col.rgb; if (norm.w < 0.5) { col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); @@ -166,8 +168,9 @@ void main() col = fogged.rgb; bloom = fogged.a; #endif - } +//col.rgb = a; + } frag_color.rgb = col.rgb; frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index ebb06e0f23..565c00ba79 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -43,12 +43,17 @@ uniform float max_y; uniform vec4 glow; uniform float scene_light_strength; uniform mat3 ssao_effect_mat; +uniform int no_atmo; uniform float sun_moon_glow_factor; vec3 scaleSoftClipFrag(vec3 light); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { + if (no_atmo == 1) + { + return light; + } light *= atten.r; light += additive; return light * 2.0; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl index c836ca98c5..86743dc306 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl @@ -26,9 +26,11 @@ // Output variables uniform float scene_light_strength; +uniform int no_atmo; vec3 atmosFragAmbient(vec3 light, vec3 amblit) { + if (no_atmo == 1) return light; return amblit + light / 2.0; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl index 589c95bc96..95b4a76880 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl @@ -33,9 +33,11 @@ vec3 getAtmosAttenuation(); vec3 getPositionEye(); uniform float scene_light_strength; +uniform int no_atmo; vec3 atmosAmbient(vec3 light) { + if (no_atmo == 1) return light + vec3(0.66); return getAmblitColor() + light / 2.0; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index e985c50c67..c0439006f7 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -26,12 +26,17 @@ uniform vec4 gamma; +uniform int no_atmo; vec3 getAtmosAttenuation(); vec3 getAdditiveColor(); vec3 scaleSoftClipFrag(vec3 light) { + if (no_atmo == 1) + { + return light; + } //soft clip effect: light = 1. - clamp(light, vec3(0.), vec3(1.)); light = 1. - pow(light, gamma.xxx); @@ -45,7 +50,8 @@ vec3 scaleSoftClip(vec3 light) vec3 fullbrightScaleSoftClipFrag(vec3 light, vec3 add, vec3 atten) { - return mix(scaleSoftClipFrag(light.rgb), add, atten); + //return mix(scaleSoftClipFrag(light.rgb), add, atten); + return scaleSoftClipFrag(light.rgb); } vec3 fullbrightScaleSoftClip(vec3 light) diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index d799453712..df731662e8 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -30,21 +30,34 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); +uniform int no_atmo; + vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { + if (no_atmo == 1) + { + return light; + } light *= atten.r; - light += additive; - return light * 2.0; + light += additive * 2.0; + return light; } vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { + if (no_atmo == 1) + { + return light; + } float brightness = dot(light.rgb, vec3(0.33333)); return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); } -vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) -{ +vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { + if (no_atmo == 1) + { + return light; + } float brightness = dot(light.rgb, vec3(0.33333)); return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); } diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index 7f74122665..90ab5d2793 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -30,21 +30,35 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); +uniform int no_atmo; + vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - return (light + additive) * atten * 2.0; + if (no_atmo == 1) + { + return light; + } + return (light + additive) * atten * 2.0; } vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive,atten), light.rgb + additive.rgb, brightness * brightness); + if (no_atmo == 1) + { + return light; + } + float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosTransportFrag(light.rgb, additive,atten), light.rgb + additive.rgb, brightness * brightness); } vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); + if (no_atmo == 1) + { + return light; + } + float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); } vec3 atmosTransport(vec3 light) -- cgit v1.2.3 From 423fa1ac297e39c9395f45490278b8751188b6db Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 7 Mar 2019 10:56:26 -0800 Subject: SL-10618, SL-10698 Fix reflection/distortion map culling planes again. Fix broken handling of shadow disables in ALM forward shaders. --- .../shaders/class1/deferred/alphaF.glsl | 23 +++++---------- .../shaders/class1/deferred/fullbrightF.glsl | 4 +-- .../shaders/class1/deferred/fullbrightShinyF.glsl | 4 +-- .../shaders/class1/deferred/materialF.glsl | 34 +++++++++------------- .../shaders/class1/deferred/materialV.glsl | 22 +++++++------- .../shaders/class1/deferred/softenLightF.glsl | 15 ---------- .../shaders/class1/deferred/waterF.glsl | 2 -- 7 files changed, 35 insertions(+), 69 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 9191787273..a5076ef609 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -77,17 +77,11 @@ vec2 encode_normal (vec3 n); vec3 scaleSoftClipFrag(vec3 l); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); -#if defined(VERT_ATMOSPHERICS) -vec3 getSunlitColor(); -vec3 getAmblitColor(); -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); -void calcAtmospherics(vec3 inPositionEye, float ambFactor); -#else void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); -#endif +#ifdef HAS_SHADOW float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +#endif 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) { @@ -142,7 +136,11 @@ void main() vec4 pos = vec4(vary_position, 1.0); vec3 norm = vary_norm; - float shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); + float shadow = 1.0f; + +#ifdef HAS_SHADOW + shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); +#endif #ifdef USE_INDEXED_TEX vec4 diff = diffuseLookup(vary_texcoord0.xy); @@ -184,14 +182,7 @@ void main() vec3 additive; vec3 atten; -#if defined(VERT_ATMOSPHERICS) - sunlit = getSunlitColor(); - amblit = getAmblitColor(); - additive = getAdditiveColor(); - atten = getAtmosAttenuation(); -#else calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); -#endif vec2 abnormal = encode_normal(norm.xyz); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 2db737a427..08ddaeceb3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -#if !HAS_DIFFUSE_LOOKUP +#if !defined(HAS_DIFFUSE_LOOKUP) uniform sampler2D diffuseMap; #endif @@ -62,7 +62,7 @@ uniform float minimum_alpha; void main() { -#if HAS_DIFFUSE_LOOKUP +#ifdef HAS_DIFFUSE_LOOKUP vec4 color = diffuseLookup(vary_texcoord0.xy); #else vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index 30e560450b..4005d5064d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -31,7 +31,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -#ifndef diffuseLookup +#ifndef HAS_DIFFUSE_LOOKUP uniform sampler2D diffuseMap; #endif @@ -46,7 +46,7 @@ vec3 fullbrightScaleSoftClip(vec3 light); void main() { -#if HAS_DIFFUSE_LOOKUP +#ifdef HAS_DIFFUSE_LOOKUP vec4 color = diffuseLookup(vary_texcoord0.xy); #else vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4db2b9ae54..dd691fb36b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -41,14 +41,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); -#if defined(VERT_ATMOSPHERICS) -vec3 getSunlitColor(); -vec3 getAmblitColor(); -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); -#else void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); -#endif vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -61,7 +54,9 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif +#ifdef HAS_SUN_SHADOW float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +#endif uniform samplerCube environmentMap; uniform sampler2D lightFunc; @@ -172,11 +167,11 @@ out vec4 frag_data[3]; uniform sampler2D diffuseMap; -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP uniform sampler2D bumpMap; #endif -#if HAS_SPECULAR_MAP +#ifdef HAS_SPECULAR_MAP uniform sampler2D specularMap; VARYING vec2 vary_texcoord2; @@ -189,7 +184,7 @@ uniform vec4 specular_color; // specular color RGB and specular exponent (gloss uniform float minimum_alpha; #endif -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP VARYING vec3 vary_mat0; VARYING vec3 vary_mat1; VARYING vec3 vary_mat2; @@ -221,14 +216,14 @@ void main() vec3 gamma_diff = diffcol.rgb; #endif -#if HAS_SPECULAR_MAP +#ifdef HAS_SPECULAR_MAP vec4 spec = texture2D(specularMap, vary_texcoord2.xy); spec.rgb *= specular_color.rgb; #else vec4 spec = vec4(specular_color.rgb, 1.0); #endif -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); norm.xyz = norm.xyz * 2 - 1; @@ -255,7 +250,7 @@ void main() #endif vec4 final_specular = spec; -#if HAS_SPECULAR_MAP +#ifdef HAS_SPECULAR_MAP vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); final_specular.a = specular_color.a * norm.a; #else @@ -268,8 +263,12 @@ void main() //forward rendering, output just lit RGBA vec3 pos = vary_position; - float shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); + float shadow = 1.0f; +#ifdef HAS_SUN_SHADOW + shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); +#endif + spec = final_specular; vec4 diffuse = final_color; @@ -285,14 +284,7 @@ void main() vec3 additive; vec3 atten; -#if defined(VERT_ATMOSPHERICS) - sunlit = getSunlitColor(); - amblit = getAmblitColor(); - additive = getAdditiveColor(); - atten = getAtmosAttenuation(); -#else calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); -#endif vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index 393d1e69da..7e29ada205 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -28,7 +28,7 @@ #define DIFFUSE_ALPHA_MODE_MASK 2 #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 -#if HAS_SKIN +#ifdef HAS_SKIN uniform mat4 modelview_matrix; uniform mat4 projection_matrix; mat4 getObjectSkinnedTransform(); @@ -39,7 +39,7 @@ uniform mat4 modelview_projection_matrix; #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) -#if !HAS_SKIN +#if !defined(HAS_SKIN) uniform mat4 modelview_matrix; #endif @@ -55,7 +55,7 @@ ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP ATTRIBUTE vec4 tangent; ATTRIBUTE vec2 texcoord1; @@ -68,7 +68,7 @@ VARYING vec2 vary_texcoord1; VARYING vec3 vary_normal; #endif -#if HAS_SPECULAR_MAP +#ifdef HAS_SPECULAR_MAP ATTRIBUTE vec2 texcoord2; VARYING vec2 vary_texcoord2; #endif @@ -78,7 +78,7 @@ VARYING vec2 vary_texcoord0; void main() { -#if HAS_SKIN +#ifdef HAS_SKIN mat4 mat = getObjectSkinnedTransform(); mat = modelview_matrix * mat; @@ -99,17 +99,17 @@ void main() vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; #endif -#if HAS_SPECULAR_MAP +#ifdef HAS_SPECULAR_MAP vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; #endif -#if HAS_SKIN +#ifdef HAS_SKIN vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP vec3 t = normalize((mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz); vec3 b = cross(n, t)*tangent.w; @@ -121,7 +121,7 @@ vary_normal = n; #endif //HAS_NORMAL_MAP #else //HAS_SKIN vec3 n = normalize(normal_matrix * normal); -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP vec3 t = normalize(normal_matrix * tangent.xyz); vec3 b = cross(n,t)*tangent.w; //vec3 t = cross(b,n) * binormal.w; @@ -137,7 +137,7 @@ vary_normal = n; vertex_color = diffuse_color; #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) -#if !HAS_SKIN +#if !defined(HAS_SKIN) vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; #endif #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index bd187ed5fc..07a24698a9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -71,15 +71,7 @@ vec3 getNorm(vec2 pos_screen); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 fullbrightAtmosTransportFrag(vec3 l, vec3 additive, vec3 atten); -#if defined(VERT_ATMOSPHERICS) -vec3 getPositionEye(); -vec3 getSunlitColor(); -vec3 getAmblitColor(); -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); -#else void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); -#endif vec3 scaleSoftClip(vec3 l); vec3 fullbrightScaleSoftClip(vec3 l); @@ -114,14 +106,7 @@ void main() vec3 additive; vec3 atten; -#if defined(VERT_ATMOSPHERICS) - sunlit = getSunlitColor(); - amblit = getAmblitColor(); - additive = getAdditiveColor(); - atten = getAtmosAttenuation(); -#else calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); -#endif float ambient = min(abs(da), 1.0); ambient *= 0.5; diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 628f73da59..be5e3538a7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -167,8 +167,6 @@ void main() vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); -color.rgb = max(fb.rgb, refcol.rgb); - frag_data[0] = vec4(color.rgb, 1); // diffuse frag_data[1] = vec4(0); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 -- cgit v1.2.3 From 53f3755a4629206754a5695de233d88062a54d3d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 7 Mar 2019 15:09:34 -0800 Subject: Fix tabs. --- .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 9 +++------ .../app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index dd691fb36b..5f4f1677d7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -301,7 +301,8 @@ void main() ambient *= ambient; ambient = 1.0 - ambient * smoothstep(0.0, 0.3, shadow); - vec3 sun_contrib = min(da, shadow) * sunlit; + float final_da = min(da, shadow); + vec3 sun_contrib = final_da * sunlit; col.rgb *= ambient; col.rgb += sun_contrib; @@ -314,7 +315,7 @@ void main() // the old infinite-sky shiny reflection // - float sa = dot(refnormpersp, sun_dir.xyz); + float sa = dot(refnormpersp, light_dir.xyz); vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); @@ -351,8 +352,6 @@ vec3 post_spec = col.rgb; col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); -vec3 post_atmo= col.rgb; - vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -369,8 +368,6 @@ vec3 post_atmo= col.rgb; col.rgb += light.rgb; -vec3 post_lighting = col.rgb; - glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 07a24698a9..a39a73f1b6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -125,7 +125,7 @@ void main() if (spec.a > 0.0) // specular reflection { // the old infinite-sky shiny reflection - float sa = dot(refnormpersp, sun_dir.xyz); + float sa = dot(refnormpersp, light_dir.xyz); vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index d220bda332..484c0cae3e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -137,8 +137,8 @@ void main() if (spec.a > 0.0) // specular reflection { // the old infinite-sky shiny reflection - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = sunlit*scol_ambocc.r*(texture2D(lightFunc, vec2(sa, spec.a)).r); + float sa = dot(refnormpersp, light_dir.xyz); + vec3 dumbshiny = sunlit*scol*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; -- cgit v1.2.3 From 4f724f63049e53b9c223c7665e7e5d2344adff0e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 12 Mar 2019 10:18:52 -0700 Subject: SL-10732 Fix accum of shadow weights and handling of clipped areas in spot shadow sampling. --- indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index c927c4bf06..6ff49c7dac 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -161,7 +161,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) { - float shadow = 1.0f; + float shadow = 0.0f; pos += norm * spot_shadow_offset; vec4 spos = vec4(pos,1.0); @@ -194,6 +194,10 @@ float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) shadow /= weight; } + else + { + shadow = 1.0f; + } return shadow; } -- cgit v1.2.3 From c10754ea6d47f88f3499f86543a7d6c7d439fda6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 13 Mar 2019 13:56:04 -0700 Subject: SL-10741 Remove shadow influence on ambient term causing inverted lighting in extreme setups. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 5 ++--- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index a5076ef609..251ec7d785 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -198,7 +198,7 @@ void main() float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = 1.0 - ambient * smoothstep(0.0, 0.3, shadow); + ambient = 1.0 - ambient; vec3 sun_contrib = min(da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 5f4f1677d7..76c1fc7cf4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -294,16 +294,15 @@ void main() da = clamp(da, 0.0, 1.0); da = pow(da, 1.0 / 1.3); - col.rgb = amblit; - float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = 1.0 - ambient * smoothstep(0.0, 0.3, shadow); + ambient = 1.0 - ambient; float final_da = min(da, shadow); vec3 sun_contrib = final_da * sunlit; + col.rgb = amblit; col.rgb *= ambient; col.rgb += sun_contrib; col.rgb *= diffuse.rgb; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 484c0cae3e..27532ce458 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -123,7 +123,7 @@ void main() float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = 1.0 - ambient * smoothstep(0.0, 0.3, scol); + ambient = 1.0 - ambient; vec3 sun_contrib = min(da,scol) * sunlit; -- cgit v1.2.3 From a10ec81e82d79bd79d5b058fda1b370073bfb480 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 15 Mar 2019 08:13:04 -0700 Subject: SL-10743, SL-10744 Don't step on SUNLIGHT_COLOR uniform w/ syncLightState competing set. Put drawpool alpha render loop lighting setup changes as they were (this will give back some performance and possibly require reopening 10566). --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 3 +-- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 1 - .../app_settings/shaders/class2/windlight/atmosphericsF.glsl | 6 +++++- .../app_settings/shaders/class2/windlight/atmosphericsV.glsl | 6 +++++- 4 files changed, 11 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 251ec7d785..fdbf5ec840 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -118,7 +118,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec 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 += (da*da*0.5 + 0.25) * ambiance; amb_da = min(amb_da, 1.0f - lit); col.rgb += amb_da * light_col * diffuse; @@ -228,7 +228,6 @@ void main() 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 76c1fc7cf4..ae2dd24b19 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -112,7 +112,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe //angular attenuation 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); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 565c00ba79..14af657e67 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -96,7 +96,11 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; + if (temp2.y > 0.001f) + { + temp2.y = 1. / temp2.y; + } + temp2.y = max(0.001f, temp2.y); sunlight *= exp(-light_atten * temp2.y); // main atmospheric scattering line integral diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index bef7a8827a..6c4098b9fb 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -91,7 +91,11 @@ void calcAtmospherics(vec3 inPositionEye) { //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; + if (temp2.y > 0.001f) + { + temp2.y = 1. / temp2.y; + } + temp2.y = max(0.001f, temp2.y); sunlight *= exp( - light_atten * temp2.y); // main atmospheric scattering line integral -- cgit v1.2.3 From 1a6f54cb5ede03f7e7d0b24f7eb45081adf0464e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 19 Mar 2019 15:02:13 -0700 Subject: SL-10764 Fix lighting issues when using shaders, but not ALM. Shader code cleanup (remove do nothing functions only in one file). Fix obsolete comment to refer to correct storage for projector ambiance. --- .../shaders/class1/deferred/fullbrightF.glsl | 13 ------------- .../shaders/class1/deferred/multiSpotLightF.glsl | 5 +++++ .../app_settings/shaders/class1/lighting/lightFuncV.glsl | 2 +- .../shaders/class2/deferred/multiSpotLightF.glsl | 16 +++++++++++----- .../app_settings/shaders/class2/deferred/spotLightF.glsl | 11 ++++++++++- .../app_settings/shaders/class3/lighting/sumLightsV.glsl | 2 +- 6 files changed, 28 insertions(+), 21 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 08ddaeceb3..d5ef010017 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -45,17 +45,6 @@ VARYING vec2 vary_texcoord0; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -vec3 fullbrightAtmosTransportDeferred(vec3 light) -{ - return light; -} - -vec3 fullbrightScaleSoftClipDeferred(vec3 light) -{ - //soft clip effect: - return light; -} - #ifdef HAS_ALPHA_MASK uniform float minimum_alpha; #endif @@ -78,8 +67,6 @@ void main() #endif color.rgb *= vertex_color.rgb; - color.rgb = fullbrightAtmosTransportDeferred(color.rgb); - color.rgb = fullbrightScaleSoftClipDeferred(color.rgb); #ifdef WATER_FOG vec3 pos = vary_position; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 2569e49743..57916eb3e5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -72,10 +72,13 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 getNorm(vec2 pos_screen); +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -95,6 +98,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -112,6 +116,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = tc-vec2(0.5); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl index a9288b3df6..dd14192ad6 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl @@ -52,7 +52,7 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation - da *= calcDirectionalLight(n, lv); + da *= calcDirectionalLight(n, -lv); return da; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 275bc829a7..4e3ecbcbf5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -71,11 +71,19 @@ uniform vec2 screen_res; uniform mat4 inv_proj; +vec3 srgb_to_linear(vec3 cs); + vec3 getNorm(vec2 pos_screen); +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)); @@ -95,6 +103,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)); @@ -211,16 +220,13 @@ void main() dlit = color.rgb * plcol.rgb * plcol.a; col = dlit*lit*diff_tex*shadow; - amb_da += (da*0.5) * proj_ambiance; - amb_da += (da*da*0.5 + 0.5) * proj_ambiance; - //amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; - //amb_da = min(amb_da,shadow); + amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - amb_da += (da*da*0.5+0.5)*proj_ambiance; + amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; amb_da *= dist_atten * noise; diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 9b69d8d855..abea8aecca 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -71,11 +71,18 @@ uniform vec2 screen_res; uniform mat4 inv_proj; +vec3 srgb_to_linear(vec3 cs); vec3 getNorm(vec2 pos_screen); +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)); @@ -95,6 +102,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 +120,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); @@ -216,7 +225,7 @@ void main() //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - amb_da += (da*da*0.5+0.5)*proj_ambiance; + amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; amb_da *= dist_atten * noise; diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index 9842d9ba93..5302b05043 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -32,7 +32,7 @@ vec3 atmosAffectDirectionalLight(float lightIntensity); uniform vec4 light_position[8]; uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; +uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) -- cgit v1.2.3 From 721df1f942ba7c5d78c7f974ed564aac431844f7 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 19 Mar 2019 15:29:31 -0700 Subject: SL-10764 Fix the light_atten decsl for specular lighting too. --- .../app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl | 2 +- .../app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl index 3acf9fe883..8ca7db1814 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl @@ -34,7 +34,7 @@ vec3 atmosGetDiffuseSunlightColor(); vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; -uniform vec3 light_attenuation[8]; +uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl index e043ac873e..ce5855646c 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl @@ -32,7 +32,7 @@ vec3 atmosGetDiffuseSunlightColor(); vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; -uniform vec3 light_attenuation[8]; +uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) -- cgit v1.2.3 From cdad939bbd6fbed4cfc863469d5c37e17bbcf698 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 20 Mar 2019 12:09:56 -0700 Subject: SL-10449 Make setting ALM from Mid through High graphics possible on OSX by fixing link error from softenLight shader. Set values to the atmos attenuation and additive color varyings to avoid warnerror from OSX GLSL compiler/linker. --- .../shaders/class1/deferred/softenLightV.glsl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl index e992776cb4..f1ada39854 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl @@ -29,12 +29,17 @@ ATTRIBUTE vec3 position; uniform vec2 screen_res; +void setAttenuation(vec3 c); +void setAdditiveColor(vec3 c); + VARYING vec2 vary_fragcoord; void main() { - //transform vertex - vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); - gl_Position = pos; - - vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; + //transform vertex + vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + gl_Position = pos; + // appease OSX GLSL compiler/linker by touching all the varyings we said we would + setAttenuation(vec3(1)); + setAdditiveColor(vec3(0)); + vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; } -- cgit v1.2.3 From edf8ba6e5ff0fc2b5ef55219c82af7b0f20437d9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 20 Mar 2019 13:07:21 -0700 Subject: SL-10449 Fix name of attenuation setter used. Fix flipped light vec. Make class3 lights use shadows on projector ambiance too. --- indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl | 2 +- .../app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 5 +---- indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl | 4 ++-- 5 files changed, 7 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl index f1ada39854..8891315e15 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl @@ -29,7 +29,7 @@ ATTRIBUTE vec3 position; uniform vec2 screen_res; -void setAttenuation(vec3 c); +void setAtmosAttenuation(vec3 c); void setAdditiveColor(vec3 c); VARYING vec2 vary_fragcoord; @@ -39,7 +39,7 @@ void main() vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); gl_Position = pos; // appease OSX GLSL compiler/linker by touching all the varyings we said we would - setAttenuation(vec3(1)); + setAtmosAttenuation(vec3(1)); setAdditiveColor(vec3(0)); vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl index dd14192ad6..a9288b3df6 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl @@ -52,7 +52,7 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation - da *= calcDirectionalLight(n, -lv); + da *= calcDirectionalLight(n, lv); return da; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 72bccc5627..0c113282b5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -228,7 +228,7 @@ void main() //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - amb_da += (da*da*0.5+0.5)*proj_ambiance; + amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; amb_da *= dist_atten * noise; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 3b2b0d5718..00b276f585 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -227,7 +227,7 @@ void main() //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - amb_da += (da*da*0.5+0.5)*proj_ambiance; + amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; amb_da *= dist_atten * noise; @@ -261,9 +261,6 @@ void main() } } - - - if (envIntensity > 0.0) { diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index 5302b05043..7cd0d505f9 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -48,10 +48,10 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].z); col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].z); col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].z); - col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz); + col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_direction[1].xyz); // Add windlight lights - col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); + col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_direction[0].xyz)); col.rgb += atmosAmbient(baseLight.rgb); col.rgb = min(col.rgb*color.rgb, 1.0); -- cgit v1.2.3 From 7423a86a1bb7b87c70b5ccc3dbfb13ebb4f28668 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 21 Mar 2019 10:39:14 -0700 Subject: SL-10751 Fix skydome VB generation to cover entire range of phi (give sky pants). Add shader code to fade out clouds to simulate old look at altitude. --- indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl | 8 ++++---- indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl | 5 ++++- indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl | 3 +++ indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl | 5 +++++ 4 files changed, 16 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 60ccfa64db..3fcb416601 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -51,6 +51,7 @@ VARYING vec2 vary_texcoord0; VARYING vec2 vary_texcoord1; VARYING vec2 vary_texcoord2; VARYING vec2 vary_texcoord3; +VARYING float altitude_blend_factor; /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); @@ -102,10 +103,8 @@ void main() alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; - if (alpha1 < 0.001f) - { - discard; - } + alpha1 *= altitude_blend_factor; + alpha1 = clamp(alpha1, 0.0, 1.0); // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight @@ -119,6 +118,7 @@ void main() // Combine vec4 color; color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); + color.rgb= max(vec3(0), color.rgb); color *= 2.; /// Gamma correct for WL (soft clip effect). diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 4beb334f5a..cfe5632ec0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -41,6 +41,7 @@ VARYING vec2 vary_texcoord0; VARYING vec2 vary_texcoord1; VARYING vec2 vary_texcoord2; VARYING vec2 vary_texcoord3; +VARYING float altitude_blend_factor; // Inputs uniform vec3 camPosLocal; @@ -77,12 +78,15 @@ void main() // Get relative position vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); + altitude_blend_factor = (P.y > -4096.0) ? 1.0 : 1.0 - clamp(abs(P.y) / max_y, 0.0, 1.0); + // Set altitude if (P.y > 0.) { P *= (max_y / P.y); } else + if (P.y <= 0.0) { P *= (-32000. / P.y); } @@ -122,7 +126,6 @@ void main() // compiler gets confused. temp1 = exp(-temp1 * temp2.z); - // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); temp2.x = 1. - temp2.x; diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index 93024bf4e7..666ae84e5c 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -52,6 +52,7 @@ VARYING vec2 vary_texcoord0; VARYING vec2 vary_texcoord1; VARYING vec2 vary_texcoord2; VARYING vec2 vary_texcoord3; +VARYING float altitude_blend_factor; /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); @@ -103,6 +104,8 @@ void main() alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; + alpha1 *= altitude_blend_factor; + if (alpha1 < 0.001f) { discard; diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index fb978691da..3cb69c33a1 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -40,6 +40,7 @@ VARYING vec2 vary_texcoord0; VARYING vec2 vary_texcoord1; VARYING vec2 vary_texcoord2; VARYING vec2 vary_texcoord3; +VARYING float altitude_blend_factor; // Inputs uniform vec3 camPosLocal; @@ -76,6 +77,9 @@ void main() // Get relative position vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); + // fade clouds beyond a certain point so the bottom of the sky dome doesn't look silly at high altitude + altitude_blend_factor = (P.y > -4096.0) ? 1.0 : 1.0 - clamp(abs(P.y) / max_y, 0.0, 1.0); + // Set altitude if (P.y > 0.) { @@ -86,6 +90,7 @@ void main() P *= (-32000. / P.y); } + // Can normalize then vec3 Pn = normalize(P); float Plen = length(P); -- cgit v1.2.3 From b757c932929ce60e035b5d69a351f495a77b9f9d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 22 Mar 2019 14:35:31 -0700 Subject: Make class3 light sum loop use light_diffuse[0] for sunlight_color instead of atmosAffectDirectionalLight with sunlight_color that isn't updated correctly. --- .../shaders/class3/lighting/sumLightsV.glsl | 47 +++++++++++++--------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index 7cd0d505f9..c410caa967 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -29,6 +29,8 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); +vec3 scaleDownLight(vec3 light); +vec3 scaleUpLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_direction[8]; @@ -37,25 +39,30 @@ uniform vec3 light_diffuse[8]; vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) { - vec4 col = vec4(0.0, 0.0, 0.0, color.a); - - // Collect normal lights (need to be divided by two, as we later multiply by 2) - - // Collect normal lights - col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); - col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); - col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].z); - col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].z); - col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].z); - col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].z); - col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_direction[1].xyz); - - // Add windlight lights - col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_direction[0].xyz)); - col.rgb += atmosAmbient(baseLight.rgb); - - col.rgb = min(col.rgb*color.rgb, 1.0); - - return col; + vec4 col = vec4(0.0, 0.0, 0.0, color.a); + + // Collect normal lights (need to be divided by two, as we later multiply by 2) + + // Collect normal lights + col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); + col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); + col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].z); + col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].z); + col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].z); + col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].z); + col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz); + + + // Add windlight lights + float l = calcDirectionalLight(norm, light_position[0].xyz); + + // using light_diffuse[0] instead of WL func as it is set to the same value for these shaders anyway + // when lights are sync'd + col.rgb += l * light_diffuse[0].rgb; + col.rgb = scaleDownLight(col.rgb); + + col.rgb += atmosAmbient(baseLight.rgb); + col.rgb = min(col.rgb*color.rgb, 1.0); + return col; } -- cgit v1.2.3 From 9c8cc0037a11861fa0561e8cda01d9ec7c996442 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 22 Mar 2019 14:54:40 -0700 Subject: Fix class1/2 light sum loops to use light_diffuse[0] for sunlight_color too. Rearrange ordering of scale down of light in class1 as well. --- indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl | 4 +--- indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl index 41288c21c1..7d699a4967 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl @@ -38,12 +38,10 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) col.a = color.a; col.rgb = light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); + col.rgb += light_diffuse[0].rgb * calcDirectionalLight(norm, light_position[0].xyz); col.rgb = scaleDownLight(col.rgb); col.rgb += atmosAmbient(baseLight.rgb); - col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); - col.rgb = min(col.rgb*color.rgb, 1.0); - return col; } diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl index c9987ef3b9..36a8a8147b 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl @@ -49,7 +49,7 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) // Add windlight lights col.rgb += atmosAmbient(baseLight.rgb); - col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); + col.rgb += light_diffuse[0].rgb * calcDirectionalLight(norm, light_position[0].xyz)); col.rgb = min(col.rgb*color.rgb, 1.0); -- cgit v1.2.3 From d99e2e119f08370b2003bad23617b7fdd435d19e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 25 Mar 2019 14:52:23 -0700 Subject: Add clamp to keep speccolor non-negative. Make spot shadowing more consistent. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 5 +++-- .../app_settings/shaders/class2/deferred/multiSpotLightF.glsl | 11 +++++------ .../app_settings/shaders/class2/deferred/spotLightF.glsl | 11 +++++------ 3 files changed, 13 insertions(+), 14 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index ae2dd24b19..9112b6afd3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -135,13 +135,14 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float sa = nh; float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - float gtdenom = 2 * nh; + float gtdenom = abs(2 * nh); float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - if (nh > 0.0) + if (gtdenom > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = lit*scol*light_col.rgb*spec.rgb; + speccol = max(speccol, vec3(0)); col += speccol; float cur_glare = max(speccol.r, speccol.g); diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 4e3ecbcbf5..c4f406aa76 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -154,10 +154,8 @@ void main() if (proj_shadow_idx >= 0) { vec4 shd = texture2DRect(lightMap, frag.xy); - float sh[2]; - sh[0] = shd.b; - sh[1] = shd.a; - shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0); + shadow = max(shd.b, shd.a) + shadow_fade; + shadow = clamp(shadow, 0.0, 1.0); } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; @@ -255,8 +253,9 @@ void main() if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += dlit*scol*spec.rgb*shadow; - //col += spec.rgb; + vec3 speccol = dlit*scol*spec.rgb*shadow; + speccol = max(speccol, vec3(0)); + col += speccol; } } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index abea8aecca..67eb503e72 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -154,10 +154,8 @@ void main() if (proj_shadow_idx >= 0) { vec4 shd = texture2DRect(lightMap, frag.xy); - float sh[2]; - sh[0] = shd.b; - sh[1] = shd.a; - shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0); + shadow = max(shd.b, shd.a) + shadow_fade; + shadow = min(shadow, 1.0); } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; @@ -254,8 +252,9 @@ void main() if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += dlit*scol*spec.rgb*shadow; - //col += spec.rgb; + vec3 speccol = dlit*scol*spec.rgb*shadow; + speccol = max(speccol, vec3(0)); + col += speccol; } } -- cgit v1.2.3 From fb7c887a5e09024731038eef0a57e5f1e8e08b2e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 26 Mar 2019 10:28:25 -0700 Subject: More consistent lighting across ALM/non-ALM/deferred/forward rendering. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 11 +++++++++-- .../shaders/class1/deferred/materialF.glsl | 19 ++++++++++++------- .../shaders/class1/lighting/lightFuncV.glsl | 2 +- .../shaders/class2/deferred/multiSpotLightF.glsl | 13 +++++-------- .../shaders/class2/deferred/spotLightF.glsl | 12 +++++------- 5 files changed, 32 insertions(+), 25 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index fdbf5ec840..dac93cee3a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -100,12 +100,14 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec vec3 norm = normalize(n); da = max(0.0, dot(norm, lv)); + //da = min(da, shadow); 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.0f; // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); @@ -113,12 +115,16 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec // to match spotLight (but not multiSpotLight) *sigh* float lit = max(da * dist_atten,0.0); + + // the shadowmap is wrong for alpha objects + // since we only have 2 maps but N spots + //col = lit * light_col * diffuse * shadow; col = lit * light_col * diffuse; float amb_da = ambiance; + amb_da += (da*0.5) * (1.0 - shadow) * ambiance; + amb_da += (da*da*0.5 + 0.5) * (1.0 - shadow) * 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; @@ -189,6 +195,7 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; float da = dot(norm.xyz, light_dir.xyz); da = clamp(da, 0.0, 1.0); + da = pow(da, 1.0 / 1.3); vec4 color = vec4(0,0,0,0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 9112b6afd3..c43b5b22bf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -104,23 +104,28 @@ 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.0f; + // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation da = dot(n, lv); + //da = min(da, shadow); da *= clamp(da, 0.0, 1.0); - + float lit = max(da * dist_atten, 0.0); + // shadowmap is wrong for alpha-blended objs + // since we created shadowmaps for 2 but render N + //col = light_col*lit*diffuse*shadow; col = light_col*lit*diffuse; - + float amb_da = ambiance; + amb_da += (da*0.5) * (1.0 - shadow) * ambiance; + amb_da += (da*da*0.5 + 0.5) * (1.0 - shadow) * 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; @@ -135,10 +140,10 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float sa = nh; float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - float gtdenom = abs(2 * nh); + float gtdenom = 2 * nh; float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - if (gtdenom > 0.0) + if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = lit*scol*light_col.rgb*spec.rgb; diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl index a9288b3df6..8defcf9f52 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl @@ -28,7 +28,7 @@ float calcDirectionalLight(vec3 n, vec3 l) { - float a = max(dot(n,l),0.0); + float a = max(dot(n,normalize(l)),0.0); return a; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index c4f406aa76..05192e1737 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -143,11 +143,11 @@ void main() vec3 pos = getPosition(frag.xy).xyz; vec3 lv = center.xyz-pos.xyz; float dist = length(lv); - dist /= size; - if (dist > 1.0) - { - discard; - } + + if ((size > 0) && ((dist / size) > 1.0)) + { + discard; + } float shadow = 1.0; @@ -225,11 +225,8 @@ void main() vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; - amb_da *= dist_atten * noise; - amb_da = min(amb_da, 1.0-lit); - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 67eb503e72..4a5f5e642b 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -143,11 +143,11 @@ void main() vec3 pos = getPosition(frag.xy).xyz; vec3 lv = trans_center.xyz-pos.xyz; float dist = length(lv); - dist /= size; - if (dist > 1.0) - { - discard; - } + + if ((size > 0) && ((dist / size) > 1.0)) + { + discard; + } float shadow = 1.0; @@ -224,9 +224,7 @@ void main() vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; - amb_da *= dist_atten * noise; - amb_da = min(amb_da, 1.0-lit); col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; -- cgit v1.2.3 From 09981714c306b9bf89a8e65c49318ccc6c30580f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 27 Mar 2019 09:38:26 -0700 Subject: Fix projector falloff and attenuation handling. --- .../shaders/class1/deferred/multiSpotLightF.glsl | 2 +- .../shaders/class1/deferred/pointLightF.glsl | 2 +- .../shaders/class1/deferred/spotLightF.glsl | 2 +- .../shaders/class2/deferred/multiSpotLightF.glsl | 382 +++++++++++---------- .../shaders/class2/deferred/spotLightF.glsl | 12 +- .../shaders/class3/deferred/multiSpotLightF.glsl | 369 ++++++++++---------- .../shaders/class3/deferred/spotLightF.glsl | 373 ++++++++++---------- 7 files changed, 572 insertions(+), 570 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 57916eb3e5..3364d5b5fc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -158,7 +158,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff+1.0; + float fa = (falloff * 0.5)+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index f8264d971c..55410c1ed7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -89,7 +89,7 @@ void main() float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; - float fa = falloff+1.0; + float fa = (falloff * 0.5)+1.0; 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; diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index d09bc25334..b546519a7d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -155,7 +155,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff+1.0; + float fa = (falloff * 0.5)+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 05192e1737..f817817f37 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -77,221 +77,223 @@ vec3 getNorm(vec2 pos_screen); vec4 correctWithGamma(vec4 col) { - return vec4(srgb_to_linear(col.rgb), col.a); + 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); - - float d = min(dist.x, dist.y); + 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); + + float d = min(dist.x, dist.y); d *= min(1, d * (proj_lod - lod)); - - float edge = 0.25*det; - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; + float edge = 0.25*det; + + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; } 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)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; + 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); + + float d = min(dist.x, dist.y); + + float edge = 0.25*det; + + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; } vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { - vec4 ret = texture2DLod(projectionMap, tc, lod); - - vec2 dist = tc-vec2(0.5); - - float d = dot(dist,dist); - - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; + vec4 ret = texture2DLod(projectionMap, tc, lod); + + vec2 dist = tc-vec2(0.5); + + float d = dot(dist,dist); + + ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); + + return ret; } vec4 getPosition(vec2 pos_screen); void main() { - vec4 frag = vary_fragcoord; - frag.xyz /= frag.w; - frag.xyz = frag.xyz*0.5+0.5; - frag.xy *= screen_res; - - vec3 pos = getPosition(frag.xy).xyz; - vec3 lv = center.xyz-pos.xyz; - float dist = length(lv); - - if ((size > 0) && ((dist / size) > 1.0)) + vec4 frag = vary_fragcoord; + frag.xyz /= frag.w; + frag.xyz = frag.xyz*0.5+0.5; + frag.xy *= screen_res; + + vec3 pos = getPosition(frag.xy).xyz; + vec3 lv = center.xyz-pos.xyz; + float dist = length(lv); + + if (dist >= size) { discard; } - - float shadow = 1.0; - - if (proj_shadow_idx >= 0) - { - vec4 shd = texture2DRect(lightMap, frag.xy); - shadow = max(shd.b, shd.a) + shadow_fade; - shadow = clamp(shadow, 0.0, 1.0); - } - - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - - float envIntensity = norm.z; - - norm = getNorm(frag.xy); - - norm = normalize(norm); - float l_dist = -dot(lv, proj_n); - - vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); - if (proj_tc.z < 0.0) - { - discard; - } - - proj_tc.xyz /= proj_tc.w; - - float fa = falloff+1.0; - float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0; - if (dist_atten <= 0.0) - { - discard; - } - - lv = proj_origin-pos.xyz; - lv = normalize(lv); - float da = dot(norm, lv); - - vec3 col = vec3(0,0,0); - - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - - vec4 spec = texture2DRect(specularRect, frag.xy); - - vec3 dlit = vec3(0, 0, 0); - - float noise = texture2D(noiseMap, frag.xy/128.0).b; - if (proj_tc.z > 0.0 && - proj_tc.x < 1.0 && - proj_tc.y < 1.0 && - proj_tc.x > 0.0 && - proj_tc.y > 0.0) - { - float amb_da = proj_ambiance; - float lit = 0.0; - - if (da > 0.0) - { - lit = da * dist_atten * noise; - - float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); - float lod = diff * proj_lod; - - vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - - dlit = color.rgb * plcol.rgb * plcol.a; - - col = dlit*lit*diff_tex*shadow; - amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; - } - - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); - vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - - amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; - amb_da *= dist_atten * noise; - amb_da = min(amb_da, 1.0-lit); - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; - } - - - if (spec.a > 0.0) - { - vec3 npos = -normalize(pos); - dlit *= min(da*6.0, 1.0) * dist_atten; - - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + dist /= size; + + float shadow = 1.0; + + if (proj_shadow_idx >= 0) + { + vec4 shd = texture2DRect(lightMap, frag.xy); + shadow = (proj_shadow_idx==0)?shd.b:shd.a; + shadow = clamp(shadow, 0.0, 1.0); + shadow += shadow_fade; + } + + vec3 norm = texture2DRect(normalMap, frag.xy).xyz; + + float envIntensity = norm.z; + + norm = getNorm(frag.xy); + + norm = normalize(norm); + float l_dist = -dot(lv, proj_n); + + vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); + if (proj_tc.z < 0.0) + { + discard; + } + + proj_tc.xyz /= proj_tc.w; + + float fa = (falloff * 0.5)+1.0; + float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0; + if (dist_atten <= 0.0) + { + discard; + } + + lv = proj_origin-pos.xyz; + lv = normalize(lv); + float da = dot(norm, lv); + + vec3 col = vec3(0,0,0); + + vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + + vec4 spec = texture2DRect(specularRect, frag.xy); + + vec3 dlit = vec3(0, 0, 0); + + float noise = texture2D(noiseMap, frag.xy/128.0).b; + if (proj_tc.z > 0.0 && + proj_tc.x < 1.0 && + proj_tc.y < 1.0 && + proj_tc.x > 0.0 && + proj_tc.y > 0.0) + { + float amb_da = proj_ambiance; + float lit = 0.0; + + if (da > 0.0) + { + lit = da * dist_atten * noise; + + float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); + float lod = diff * proj_lod; + + vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); + + dlit = color.rgb * plcol.rgb * plcol.a; + + col = dlit*lit*diff_tex*shadow; + amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; + } + + //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); + vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); + + amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; + amb_da *= dist_atten * noise; + amb_da = min(amb_da, 1.0-lit); + col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; + } + + + if (spec.a > 0.0) + { + vec3 npos = -normalize(pos); + dlit *= min(da*6.0, 1.0) * dist_atten; + + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = dlit*scol*spec.rgb*shadow; speccol = max(speccol, vec3(0)); - col += speccol; - } - } - - - - - - if (envIntensity > 0.0) - { - vec3 ref = reflect(normalize(pos), norm); - - //project from point pos in direction ref to plane proj_p, proj_n - vec3 pdelta = proj_p-pos; - float ds = dot(ref, proj_n); - - if (ds < 0.0) - { - vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; - - vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); - - if (stc.z > 0.0) - { + col += speccol; + } + } + + + + + + if (envIntensity > 0.0) + { + vec3 ref = reflect(normalize(pos), norm); + + //project from point pos in direction ref to plane proj_p, proj_n + vec3 pdelta = proj_p-pos; + float ds = dot(ref, proj_n); + + if (ds < 0.0) + { + vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; + + vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + + if (stc.z > 0.0) + { stc /= stc.w; - - if (stc.x < 1.0 && - stc.y < 1.0 && - stc.x > 0.0 && - stc.y > 0.0) - { - col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; - } - } - } - } - - //not sure why, but this line prevents MATBUG-194 - col = max(col, vec3(0.0)); - - frag_color.rgb = col; - frag_color.a = 0.0; + + if (stc.x < 1.0 && + stc.y < 1.0 && + stc.x > 0.0 && + stc.y > 0.0) + { + col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; + } + } + } + } + + //not sure why, but this line prevents MATBUG-194 + col = max(col, vec3(0.0)); + + frag_color.rgb = col; + frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 4a5f5e642b..510d1ca9fd 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -144,18 +144,20 @@ void main() vec3 lv = trans_center.xyz-pos.xyz; float dist = length(lv); - if ((size > 0) && ((dist / size) > 1.0)) + if (dist >= size) { discard; } - + dist /= size; + float shadow = 1.0; if (proj_shadow_idx >= 0) { vec4 shd = texture2DRect(lightMap, frag.xy); - shadow = max(shd.b, shd.a) + shadow_fade; - shadow = min(shadow, 1.0); + shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; + shadow = clamp(shadow, 0.0, 1.0); + shadow += shadow_fade; } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; @@ -173,7 +175,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff + 1.0; + float fa = (falloff * 0.5) + 1.0; float dist_atten = min(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 0c113282b5..dec9afcfb7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -77,59 +77,59 @@ vec3 getNorm(vec2 pos_screen); vec4 correctWithGamma(vec4 col) { - return vec4(srgb_to_linear(col.rgb), col.a); + return vec4(srgb_to_linear(col.rgb), col.a); } vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); + + float det = min(lod/(proj_lod*0.5), 1.0); + + float d = min(dist.x, dist.y); d *= min(1, d * (proj_lod - lod)); - - float edge = 0.25*det; - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; + float edge = 0.25*det; + + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; } vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); + 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); - - float d = min(dist.x, dist.y); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); + + float det = min(lod/(proj_lod*0.5), 1.0); + + float d = min(dist.x, dist.y); + + float edge = 0.25*det; + + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; } vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); - vec2 dist = tc-vec2(0.5); - - float d = dot(dist,dist); - - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; + vec2 dist = tc-vec2(0.5); + + float d = dot(dist,dist); + + ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); + + return ret; } @@ -137,167 +137,166 @@ vec4 getPosition(vec2 pos_screen); void main() { - vec4 frag = vary_fragcoord; - frag.xyz /= frag.w; - frag.xyz = frag.xyz*0.5+0.5; - frag.xy *= screen_res; - - vec3 pos = getPosition(frag.xy).xyz; - vec3 lv = center.xyz-pos.xyz; - float dist = length(lv); - dist /= size; - if (dist > 1.0) - { - discard; - } - - float shadow = 1.0; - - if (proj_shadow_idx >= 0) - { - vec4 shd = texture2DRect(lightMap, frag.xy); - float sh[2]; - sh[0] = shd.b; - sh[1] = shd.a; - shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0); - } - - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - - float envIntensity = norm.z; + vec4 frag = vary_fragcoord; + frag.xyz /= frag.w; + frag.xyz = frag.xyz*0.5+0.5; + frag.xy *= screen_res; + + vec3 pos = getPosition(frag.xy).xyz; + vec3 lv = center.xyz-pos.xyz; + float dist = length(lv); + dist /= size; + if (dist > 1.0) + { + discard; + } + + float shadow = 1.0; + + if (proj_shadow_idx >= 0) + { + vec4 shd = texture2DRect(lightMap, frag.xy); + shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; + shadow = clamp(shadow, 0.0, 1.0); + shadow += shadow_fade; + } + + vec3 norm = texture2DRect(normalMap, frag.xy).xyz; + + float envIntensity = norm.z; - norm = getNorm(frag.xy); - - norm = normalize(norm); - float l_dist = -dot(lv, proj_n); - - vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); - if (proj_tc.z < 0.0) - { - discard; - } - - proj_tc.xyz /= proj_tc.w; - - float fa = falloff+1.0; - float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0; - if (dist_atten <= 0.0) - { - discard; - } - - lv = proj_origin-pos.xyz; - lv = normalize(lv); - float da = dot(norm, lv); + norm = getNorm(frag.xy); + + norm = normalize(norm); + float l_dist = -dot(lv, proj_n); + + vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); + if (proj_tc.z < 0.0) + { + discard; + } + + proj_tc.xyz /= proj_tc.w; + + float fa = (falloff*0.5)+1.0; + float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0; + if (dist_atten <= 0.0) + { + discard; + } + + lv = proj_origin-pos.xyz; + lv = normalize(lv); + float da = dot(norm, lv); - vec3 col = vec3(0,0,0); - - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - - vec4 spec = texture2DRect(specularRect, frag.xy); + vec3 col = vec3(0,0,0); + + vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + + vec4 spec = texture2DRect(specularRect, frag.xy); - vec3 dlit = vec3(0, 0, 0); + vec3 dlit = vec3(0, 0, 0); - float noise = texture2D(noiseMap, frag.xy/128.0).b; - if (proj_tc.z > 0.0 && - proj_tc.x < 1.0 && - proj_tc.y < 1.0 && - proj_tc.x > 0.0 && - proj_tc.y > 0.0) - { - float amb_da = proj_ambiance; - float lit = 0.0; + float noise = texture2D(noiseMap, frag.xy/128.0).b; + if (proj_tc.z > 0.0 && + proj_tc.x < 1.0 && + proj_tc.y < 1.0 && + proj_tc.x > 0.0 && + proj_tc.y > 0.0) + { + float amb_da = proj_ambiance; + float lit = 0.0; - if (da > 0.0) - { - lit = da * dist_atten * noise; + if (da > 0.0) + { + lit = da * dist_atten * noise; - float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); - float lod = diff * proj_lod; - - vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - - dlit = color.rgb * plcol.rgb * plcol.a; - - col = dlit*lit*diff_tex*shadow; - amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; - } - - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); - vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - - amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; - - amb_da *= dist_atten * noise; - - amb_da = min(amb_da, 1.0-lit); - - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; - } - + float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); + float lod = diff * proj_lod; + + vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); + + dlit = color.rgb * plcol.rgb * plcol.a; + + col = dlit*lit*diff_tex*shadow; + amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; + } + + //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); + vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); + + amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; + + amb_da *= dist_atten * noise; + + amb_da = min(amb_da, 1.0-lit); + + col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; + } + - if (spec.a > 0.0) - { - vec3 npos = -normalize(pos); - dlit *= min(da*6.0, 1.0) * dist_atten; + if (spec.a > 0.0) + { + vec3 npos = -normalize(pos); + dlit *= min(da*6.0, 1.0) * dist_atten; - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += dlit*scol*spec.rgb*shadow; - //col += spec.rgb; - } - } - - - - + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + col += dlit*scol*spec.rgb*shadow; + //col += spec.rgb; + } + } + + + + - if (envIntensity > 0.0) - { - vec3 ref = reflect(normalize(pos), norm); - - //project from point pos in direction ref to plane proj_p, proj_n - vec3 pdelta = proj_p-pos; - float ds = dot(ref, proj_n); - - if (ds < 0.0) - { - vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; - - vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + if (envIntensity > 0.0) + { + vec3 ref = reflect(normalize(pos), norm); + + //project from point pos in direction ref to plane proj_p, proj_n + vec3 pdelta = proj_p-pos; + float ds = dot(ref, proj_n); + + if (ds < 0.0) + { + vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; + + vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); - if (stc.z > 0.0) - { + if (stc.z > 0.0) + { stc /= stc.w; - - if (stc.x < 1.0 && - stc.y < 1.0 && - stc.x > 0.0 && - stc.y > 0.0) - { - col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; - } - } - } - } + + if (stc.x < 1.0 && + stc.y < 1.0 && + stc.x > 0.0 && + stc.y > 0.0) + { + col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; + } + } + } + } - //not sure why, but this line prevents MATBUG-194 - col = max(col, vec3(0.0)); + //not sure why, but this line prevents MATBUG-194 + col = max(col, vec3(0.0)); - frag_color.rgb = col; - frag_color.a = 0.0; + frag_color.rgb = col; + frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 00b276f585..6a813cac15 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -77,59 +77,59 @@ vec3 linear_to_srgb(vec3 cl); vec4 correctWithGamma(vec4 col) { - return vec4(srgb_to_linear(col.rgb), col.a); + return vec4(srgb_to_linear(col.rgb), col.a); } vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); + + float det = min(lod/(proj_lod*0.5), 1.0); + + float d = min(dist.x, dist.y); d *= min(1, d * (proj_lod - lod)); - - float edge = 0.25*det; - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; + float edge = 0.25*det; + + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; } 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)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; + 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); + + float d = min(dist.x, dist.y); + + float edge = 0.25*det; + + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; } vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); - - vec2 dist = tc-vec2(0.5); - - float d = dot(dist,dist); - - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); + + vec2 dist = tc-vec2(0.5); + + float d = dot(dist,dist); + + ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); + + return ret; } @@ -137,163 +137,162 @@ vec4 getPosition(vec2 pos_screen); void main() { - vec4 frag = vary_fragcoord; - frag.xyz /= frag.w; - frag.xyz = frag.xyz*0.5+0.5; - frag.xy *= screen_res; - - vec3 pos = getPosition(frag.xy).xyz; - vec3 lv = trans_center.xyz-pos.xyz; - float dist = length(lv); - dist /= size; - if (dist > 1.0) - { - discard; - } - - float shadow = 1.0; - - if (proj_shadow_idx >= 0) - { - vec4 shd = texture2DRect(lightMap, frag.xy); - float sh[2]; - sh[0] = shd.b; - sh[1] = shd.a; - shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0); - } - - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - float envIntensity = norm.z; - norm = getNorm(frag.xy); - - norm = normalize(norm); - float l_dist = -dot(lv, proj_n); - - vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); - if (proj_tc.z < 0.0) - { - discard; - } - - proj_tc.xyz /= proj_tc.w; - - float fa = falloff + 1.0; - float dist_atten = min(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0; + vec4 frag = vary_fragcoord; + frag.xyz /= frag.w; + frag.xyz = frag.xyz*0.5+0.5; + frag.xy *= screen_res; + + vec3 pos = getPosition(frag.xy).xyz; + vec3 lv = trans_center.xyz-pos.xyz; + float dist = length(lv); + dist /= size; + if (dist > 1.0) + { + discard; + } + + float shadow = 1.0; + + if (proj_shadow_idx >= 0) + { + vec4 shd = texture2DRect(lightMap, frag.xy); + shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; + shadow = clamp(shadow, 0.0, 1.0); + shadow += shadow_fade; + } + + vec3 norm = texture2DRect(normalMap, frag.xy).xyz; + float envIntensity = norm.z; + norm = getNorm(frag.xy); + + norm = normalize(norm); + float l_dist = -dot(lv, proj_n); + + vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); + if (proj_tc.z < 0.0) + { + discard; + } + + proj_tc.xyz /= proj_tc.w; + + float fa = (falloff*0.5) + 1.0; + float dist_atten = min(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0; - if (dist_atten <= 0.0) - { - discard; - } - - lv = proj_origin-pos.xyz; - lv = normalize(lv); - float da = dot(norm, lv); - - vec3 col = vec3(0,0,0); - - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - - vec4 spec = texture2DRect(specularRect, frag.xy); + if (dist_atten <= 0.0) + { + discard; + } + + lv = proj_origin-pos.xyz; + lv = normalize(lv); + float da = dot(norm, lv); + + vec3 col = vec3(0,0,0); + + vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + + vec4 spec = texture2DRect(specularRect, frag.xy); - vec3 dlit = vec3(0, 0, 0); + vec3 dlit = vec3(0, 0, 0); - float noise = texture2D(noiseMap, frag.xy/128.0).b; - if (proj_tc.z > 0.0 && - proj_tc.x < 1.0 && - proj_tc.y < 1.0 && - proj_tc.x > 0.0 && - proj_tc.y > 0.0) - { - float amb_da = proj_ambiance; - float lit = 0.0; - - if (da > 0.0) - { - lit = da * dist_atten * noise; + float noise = texture2D(noiseMap, frag.xy/128.0).b; + if (proj_tc.z > 0.0 && + proj_tc.x < 1.0 && + proj_tc.y < 1.0 && + proj_tc.x > 0.0 && + proj_tc.y > 0.0) + { + float amb_da = proj_ambiance; + float lit = 0.0; + + if (da > 0.0) + { + lit = da * dist_atten * noise; - float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); - float lod = diff * proj_lod; - - vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - - dlit = color.rgb * plcol.rgb * plcol.a; - - col = dlit*lit*diff_tex*shadow; - amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; - } - - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); - vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - - amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; - - amb_da *= dist_atten * noise; - - amb_da = min(amb_da, 1.0-lit); - - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; - } - + float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); + float lod = diff * proj_lod; + + vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); + + dlit = color.rgb * plcol.rgb * plcol.a; + + col = dlit*lit*diff_tex*shadow; + amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; + } + + //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); + vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); + + amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; + + amb_da *= dist_atten * noise; + + amb_da = min(amb_da, 1.0-lit); + + col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; + } + - if (spec.a > 0.0) - { - dlit *= min(da*6.0, 1.0) * dist_atten; - vec3 npos = -normalize(pos); + if (spec.a > 0.0) + { + dlit *= min(da*6.0, 1.0) * dist_atten; + vec3 npos = -normalize(pos); - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += dlit*scol*spec.rgb*shadow; - //col += spec.rgb; - } - } - + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + col += dlit*scol*spec.rgb*shadow; + //col += spec.rgb; + } + } + - if (envIntensity > 0.0) - { - vec3 ref = reflect(normalize(pos), norm); - - //project from point pos in direction ref to plane proj_p, proj_n - vec3 pdelta = proj_p-pos; - float ds = dot(ref, proj_n); - - if (ds < 0.0) - { - vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; - - vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + if (envIntensity > 0.0) + { + vec3 ref = reflect(normalize(pos), norm); + + //project from point pos in direction ref to plane proj_p, proj_n + vec3 pdelta = proj_p-pos; + float ds = dot(ref, proj_n); + + if (ds < 0.0) + { + vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; + + vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); - if (stc.z > 0.0) - { - stc /= stc.w; - - if (stc.x < 1.0 && - stc.y < 1.0 && - stc.x > 0.0 && - stc.y > 0.0) - { - col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; - } - } - } - } - - //not sure why, but this line prevents MATBUG-194 - col = max(col, vec3(0.0)); + if (stc.z > 0.0) + { + stc /= stc.w; + + if (stc.x < 1.0 && + stc.y < 1.0 && + stc.x > 0.0 && + stc.y > 0.0) + { + col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; + } + } + } + } + + //not sure why, but this line prevents MATBUG-194 + col = max(col, vec3(0.0)); - frag_color.rgb = col; - frag_color.a = 0.0; + frag_color.rgb = col; + frag_color.a = 0.0; } -- cgit v1.2.3 From 03426a7ddbf1b3bb8349241d3b52962026f7504a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 28 Mar 2019 13:23:59 -0700 Subject: SL-10829, SL-10830 Replace old spot prio calc. Replace fudge factors on light radius and falloff for deferred lights. --- .../newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl | 2 +- .../newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl | 4 ++-- indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl | 4 ++-- .../newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 3364d5b5fc..57916eb3e5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -158,7 +158,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = (falloff * 0.5)+1.0; + float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 55410c1ed7..f8264d971c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -89,7 +89,7 @@ void main() float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; - float fa = (falloff * 0.5)+1.0; + float fa = falloff+1.0; 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; diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index b546519a7d..d09bc25334 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -155,7 +155,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = (falloff * 0.5)+1.0; + float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index f817817f37..9e14c03a96 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -156,8 +156,8 @@ void main() { vec4 shd = texture2DRect(lightMap, frag.xy); shadow = (proj_shadow_idx==0)?shd.b:shd.a; - shadow = clamp(shadow, 0.0, 1.0); shadow += shadow_fade; + shadow = clamp(shadow, 0.0, 1.0); } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; @@ -177,7 +177,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = (falloff * 0.5)+1.0; + float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 510d1ca9fd..93b55ab9c1 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -156,8 +156,8 @@ void main() { vec4 shd = texture2DRect(lightMap, frag.xy); shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; - shadow = clamp(shadow, 0.0, 1.0); shadow += shadow_fade; + shadow = clamp(shadow, 0.0, 1.0); } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; @@ -175,7 +175,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = (falloff * 0.5) + 1.0; + float fa = falloff + 1.0; float dist_atten = min(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index dec9afcfb7..abb6a3a5d8 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -157,8 +157,8 @@ void main() { vec4 shd = texture2DRect(lightMap, frag.xy); shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; - shadow = clamp(shadow, 0.0, 1.0); shadow += shadow_fade; + shadow = clamp(shadow, 0.0, 1.0); } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 6a813cac15..afc542b8bc 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -157,8 +157,8 @@ void main() { vec4 shd = texture2DRect(lightMap, frag.xy); shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; - shadow = clamp(shadow, 0.0, 1.0); shadow += shadow_fade; + shadow = clamp(shadow, 0.0, 1.0); } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; -- cgit v1.2.3 From 823172cab99c55b1c26b523d7dd63a99ece9f6cb Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 28 Mar 2019 14:18:59 -0700 Subject: SL-10831 Make moon brightness env setting affect moon diffuse/ambient color combo so it affects in-world lighting. Adjust how the moon brightness affects the moon disc texture rendering (washes out less). --- indra/newview/app_settings/shaders/class1/deferred/moonF.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/moonF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index d964ce8eee..e257b668c8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -52,7 +52,7 @@ void main() // mix factor which blends when sunlight is brighter // and shows true moon color at night - vec3 luma_weights = vec3(0.2, 0.3, 0.2); + vec3 luma_weights = vec3(0.3, 0.5, 0.3); float mix = 1.0 - dot(normalize(sunlight_color.rgb), luma_weights); diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl index 947c301110..c8bbdd109d 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -52,7 +52,7 @@ void main() // mix factor which blends when sunlight is brighter // and shows true moon color at night - vec3 luma_weights = vec3(0.2, 0.3, 0.2); + vec3 luma_weights = vec3(0.3, 0.5, 0.3); float mix = 1.0f - dot(normalize(sunlight_color.rgb), luma_weights); vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0 - 1.0; -- cgit v1.2.3 From cb7d07e0ca9041d76de2c99ae9bbee7f10e89856 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 29 Mar 2019 15:56:59 -0700 Subject: SL-10844, SL-10584 Add Geenz doings to the contribs list. Fix per-frag atmospherics to use sRGB conversion. Update ref to new KDU package. --- indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 14af657e67..7bfdb9f753 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -46,6 +46,7 @@ uniform mat3 ssao_effect_mat; uniform int no_atmo; uniform float sun_moon_glow_factor; +vec3 srgb_to_linear(vec3 c); vec3 scaleSoftClipFrag(vec3 light); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) @@ -151,7 +152,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, + tmpAmbient)); //brightness of surface both sunlight and ambient - sunlit = vec3(sunlight * .5); + sunlit = srgb_to_linear(sunlight.rgb); amblit = vec3(tmpAmbient * .25); additive = normalize(additive); additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; -- cgit v1.2.3 From a158c879578822a116e3f6a8c5dbbd1a14bb8c83 Mon Sep 17 00:00:00 2001 From: Geenz Date: Sat, 30 Mar 2019 17:22:54 -0700 Subject: Hide sRGB decode behind a flag, and make sure that sRGB decodes is strictly opt-in. --- .../newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 3 --- .../newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl | 2 -- 2 files changed, 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 57916eb3e5..6489508c00 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -78,7 +78,6 @@ vec3 linear_to_srgb(vec3 cl); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -98,7 +97,6 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -116,7 +114,6 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = tc-vec2(0.5); diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 9e14c03a96..ab380f70e8 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -83,7 +83,6 @@ vec4 correctWithGamma(vec4 col) 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)); @@ -103,7 +102,6 @@ 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)); -- cgit v1.2.3 From 233f3310aaf790b4cf12bcb9f42dd193467d25f3 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 1 Apr 2019 12:12:33 -0700 Subject: Whoops, forgot a shader! --- indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl | 3 --- 1 file changed, 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 93b55ab9c1..a9482ea54c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -82,7 +82,6 @@ vec4 correctWithGamma(vec4 col) 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)); @@ -102,7 +101,6 @@ 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)); @@ -120,7 +118,6 @@ 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); -- cgit v1.2.3 From 558eaef3ea09ff560c1fead65f1d1b3b75b4bdc5 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 1 Apr 2019 23:09:43 -0700 Subject: Make sure that atmospheric calcs aren't done twice. The atomospherics were being applied both in the G-buffer and during the sun light pass. This ensures that is not the case. Additionally, re-enable specular on the water plane, scale the bloom factor to something more reasonable, and also someone broke specular on emissive surfaces. That's fixed too now. --- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 4 ++-- .../newview/app_settings/shaders/class1/deferred/waterF.glsl | 11 ++++------- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 8 +++----- 3 files changed, 9 insertions(+), 14 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index a39a73f1b6..a04a24955e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -130,11 +130,11 @@ void main() // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; + bloom = dot(spec_contrib, spec_contrib) / 32; col += spec_contrib; } - col = mix(col.rgb, diffuse.rgb, diffuse.a); + col.rgb += diffuse.a * diffuse.rgb; if (envIntensity > 0.0) { //add environmentmap diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index be5e3538a7..9a8a098a19 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -153,21 +153,18 @@ void main() vec2 distort2 = distort+wavef.xy*refScale * 0.33/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); - //mix with reflection // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); vec4 pos = vary_position; - color.rgb += spec * specular; - - color.rgb = atmosTransport(color.rgb); - color.rgb = scaleSoftClipFrag(color.rgb); + //color.rgb = atmosTransport(color.rgb); + //color.rgb = scaleSoftClipFrag(color.rgb) * 0; vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); frag_data[0] = vec4(color.rgb, 1); // diffuse - frag_data[1] = vec4(0); // speccolor, spec - frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 + frag_data[1] = vec4(specular, 0.75); // speccolor, spec + frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 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 27532ce458..39776f1791 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -142,11 +142,11 @@ void main() // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; + bloom = dot(spec_contrib, spec_contrib) / 64; col += spec_contrib; } - col = mix(col.rgb, diffuse.rgb, diffuse.a); + col.rgb += diffuse.a * diffuse.rgb; if (envIntensity > 0.0) { //add environmentmap @@ -154,9 +154,7 @@ void main() vec3 refcol = textureCube(environmentMap, env_vec).rgb; col = mix(col.rgb, refcol, envIntensity); } - - -vec3 a = col.rgb; + if (norm.w < 0.5) { col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); -- cgit v1.2.3 From 6b54c48dff9a38a0a1410ed9bcd06d2667320df3 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 1 Apr 2019 23:25:48 -0700 Subject: Scale the specular contribution to account for brighter highlights. This is more or less to achieve the non-ALM bloom behavior in most circumstances. Why scale it? Normalized blinn-phong gets brighter the higher the specular exponent. As it stood, the old spec contribution was extremely bright despite looking "correct". This is largely eyeballed, but generally looks better for all light sources applied to the surface of the water. --- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 10 ++-------- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index a04a24955e..cbeab3fc72 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -130,7 +130,7 @@ void main() // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 32; + bloom = dot(spec_contrib, spec_contrib) / 6; col += spec_contrib; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 9a8a098a19..c3c8683f6b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -142,13 +142,7 @@ void main() vec4 baseCol = texture2D(refTex, refvec4); refcol = mix(baseCol*df2, refcol, dweight); - - //get specular component - float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); - - //harden specular - spec = pow(spec, 128.0); - + //figure out distortion vector (ripply) vec2 distort2 = distort+wavef.xy*refScale * 0.33/max(dmod*df1, 1.0); @@ -165,6 +159,6 @@ void main() vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); frag_data[0] = vec4(color.rgb, 1); // diffuse - frag_data[1] = vec4(specular, 0.75); // speccolor, spec + frag_data[1] = vec4(specular * 0.4, 0.75); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 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 39776f1791..47fc20e256 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -142,7 +142,7 @@ void main() // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 64; + bloom = dot(spec_contrib, spec_contrib) / 6; col += spec_contrib; } -- cgit v1.2.3 From f07a1741e91fe44423d27585e4eeb7b69542e299 Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 2 Apr 2019 01:28:57 -0700 Subject: Make sure emissive is actually handled with atmospherics consistently. --- .../newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 6 ++++-- .../newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index cbeab3fc72..2df55f6cfc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -145,8 +145,10 @@ void main() if (norm.w < 0.5) { - col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + //col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); + //col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col, additive, atten), diffuse.a); + col = atmosFragLighting(col, additive, atten); + col = scaleSoftClipFrag(col); } #ifdef WATER_FOG diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 47fc20e256..28248aaf6d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -157,8 +157,10 @@ void main() if (norm.w < 0.5) { - col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); - col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col, additive, atten), diffuse.a); + //col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); + //col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col, additive, atten), diffuse.a); + col = atmosFragLighting(col, additive, atten); + col = scaleSoftClipFrag(col); } #ifdef WATER_FOG -- cgit v1.2.3 From e4bac71ac38f04eca96f4e3c932b51bd0d7432a1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Apr 2019 14:14:19 -0700 Subject: Fix shader link fail from forward decl of wrong soft clip func in class 1. Fix trying to bind diffuse maps for shader without uniform in shadow shaders. Clean up merge fail around mShaderLevel namechange. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 2df55f6cfc..e22240727c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -73,8 +73,7 @@ vec3 fullbrightAtmosTransportFrag(vec3 l, vec3 additive, vec3 atten); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); -vec3 scaleSoftClip(vec3 l); -vec3 fullbrightScaleSoftClip(vec3 l); +vec3 scaleSoftClipFrag(vec3 l); vec4 getPositionWithDepth(vec2 pos_screen, float depth); @@ -145,8 +144,6 @@ void main() if (norm.w < 0.5) { - //col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); - //col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col, additive, atten), diffuse.a); col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); } -- cgit v1.2.3 From 4a0f3db9a4d741d3c2f9bf4c028670de587f3330 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Apr 2019 16:21:51 -0700 Subject: SL-10857 Juggle forced frag depths for moon/sun/stars/sky to get depth fighting with distant terrain...wait for it...sorted. --- indra/newview/app_settings/shaders/class1/deferred/moonF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/skyF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/starsF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index e257b668c8..7732cf986e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -64,6 +64,6 @@ void main() frag_data[1] = vec4(0.0); frag_data[2] = vec4(0.0f); - gl_FragDepth = 0.9996f; + gl_FragDepth = 0.99985f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index f8172cae17..72b7aa9036 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -58,6 +58,6 @@ void main() frag_data[1] = vec4(0.0,0.0,0.0,0.0); frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog - gl_FragDepth = 0.999f; + gl_FragDepth = 0.99999f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 8a98d6a489..bac79a9fdc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -62,6 +62,6 @@ void main() frag_data[1] = vec4(0.0f); frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); - gl_FragDepth = 0.9998; + gl_FragDepth = 0.99995f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index 1fb337498c..d06cb43129 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -59,6 +59,6 @@ void main() frag_data[1] = vec4(0.0f); frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); - gl_FragDepth = 0.9997f; + gl_FragDepth = 0.99988f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index d7b2a9cc8e..f73fc0079b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -66,8 +66,8 @@ void main() outColor = applyWaterFogView(pos.xyz, outColor); #endif - frag_data[0] = vec4(outColor.rgb, 0.0); - frag_data[1] = vec4(0,0,0,0); + frag_data[0] = vec4(outColor.rgb, 1.0); + frag_data[1] = vec4(0.66,0.86,0.66,0.05f); vec3 nvn = normalize(vary_normal); frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); } -- cgit v1.2.3 From 4170f7b1601203e8953672c42bfb320d7c715a92 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Apr 2019 17:26:16 -0700 Subject: SL-10855 Apply sRGB colorspace to deferred cloud output. --- indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 3fcb416601..9535cd6870 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -55,6 +55,7 @@ VARYING float altitude_blend_factor; /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); +vec3 linear_to_srgb(vec3 c); vec4 cloudNoise(vec2 uv) { @@ -119,7 +120,7 @@ void main() vec4 color; color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); color.rgb= max(vec3(0), color.rgb); - color *= 2.; + color.rgb = linear_to_srgb(color.rgb); /// Gamma correct for WL (soft clip effect). frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); -- cgit v1.2.3 From a5d4edaccc292daa7c06267c55914762ec0f6ab8 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 3 Apr 2019 15:20:52 -0700 Subject: SL-10856 Make terrain *not* blend all the way to diffuse color for no reason. --- indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl | 4 ++-- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index f73fc0079b..800070c01d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -66,8 +66,8 @@ void main() outColor = applyWaterFogView(pos.xyz, outColor); #endif - frag_data[0] = vec4(outColor.rgb, 1.0); - frag_data[1] = vec4(0.66,0.86,0.66,0.05f); + frag_data[0] = vec4(outColor.rgb, 0.0); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); vec3 nvn = normalize(vary_normal); frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 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 28248aaf6d..c34bac79dd 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -168,8 +168,6 @@ void main() col = fogged.rgb; bloom = fogged.a; #endif - -//col.rgb = a; } frag_color.rgb = col.rgb; frag_color.a = bloom; -- cgit v1.2.3 From 0e9193d84c0f96b890123f092f22f81ae84fe6dc Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 3 Apr 2019 15:51:20 -0700 Subject: Make sure that the SL BRDF is being applied to objects lit by the sun and moon. Fixes BUG-226620 --HG-- branch : BUG-226620 --- .../shaders/class1/deferred/softenLightF.glsl | 28 +++++++++++++++------- .../shaders/class2/deferred/softenLightF.glsl | 28 +++++++++++++++------- 2 files changed, 40 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index e22240727c..97b5e56529 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -123,14 +123,26 @@ void main() if (spec.a > 0.0) // specular reflection { - // the old infinite-sky shiny reflection - float sa = dot(refnormpersp, light_dir.xyz); - vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - col += spec_contrib; + vec3 npos = -normalize(pos.xyz); + + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(light_dir.xyz+npos); + float nh = dot(norm.xyz, h); + float nv = dot(norm.xyz, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = sun_contrib*scol*spec.rgb; + speccol = max(speccol, vec3(0)); + col += speccol; + } } col.rgb += diffuse.a * diffuse.rgb; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 28248aaf6d..42258cc729 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -136,14 +136,26 @@ void main() if (spec.a > 0.0) // specular reflection { - // the old infinite-sky shiny reflection - float sa = dot(refnormpersp, light_dir.xyz); - vec3 dumbshiny = sunlit*scol*(texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - col += spec_contrib; + vec3 npos = -normalize(pos.xyz); + + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(light_dir.xyz+npos); + float nh = dot(norm.xyz, h); + float nv = dot(norm.xyz, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = sun_contrib*scontrib*spec.rgb; + speccol = max(speccol, vec3(0)); + col += speccol; + } } col.rgb += diffuse.a * diffuse.rgb; -- cgit v1.2.3 From a615dc049ec1f57d3938a8b49a8f0502b4ce2523 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 3 Apr 2019 16:01:12 -0700 Subject: Bring back specular bloom. --HG-- branch : BUG-226620 --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 1 + indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 1 + 2 files changed, 2 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 97b5e56529..e44b441727 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -141,6 +141,7 @@ void main() float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = sun_contrib*scol*spec.rgb; speccol = max(speccol, vec3(0)); + bloom = dot (speccol, speccol) / 2; col += speccol; } } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 42258cc729..3192f056a5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -154,6 +154,7 @@ void main() float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = sun_contrib*scontrib*spec.rgb; speccol = max(speccol, vec3(0)); + bloom += dot (speccol, speccol) / 2; col += speccol; } } -- cgit v1.2.3 From c699ee9a7f102aa541dcc102e8fa1de2d6c55bde Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 4 Apr 2019 17:19:59 -0700 Subject: SL-10854 Clamp ambient contrib to get darker shadows. New PCF sampling func. --- .../shaders/class1/deferred/alphaF.glsl | 12 ++++-- .../shaders/class1/deferred/materialF.glsl | 2 +- .../shaders/class1/deferred/shadowUtil.glsl | 43 +++++++++++++++++++--- .../shaders/class2/deferred/softenLightF.glsl | 15 +++++--- 4 files changed, 55 insertions(+), 17 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index dac93cee3a..d560a49c1f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -194,8 +194,12 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; float da = dot(norm.xyz, light_dir.xyz); - da = clamp(da, 0.0, 1.0); - da = pow(da, 1.0 / 1.3); + + float final_da = da; + final_da = min(final_da, shadow); + final_da = max(final_da, 0.0f); + final_da = min(final_da, 1.0f); + final_da = pow(final_da, 1.0/1.3); vec4 color = vec4(0,0,0,0); @@ -205,9 +209,9 @@ void main() float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = 1.0 - ambient; + ambient = 1.0 - max(0.9, ambient); - vec3 sun_contrib = min(da, shadow) * sunlit; + vec3 sun_contrib = final_da * sunlit; color.rgb *= ambient; color.rgb += sun_contrib; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c43b5b22bf..d389d975fa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -302,7 +302,7 @@ void main() float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = 1.0 - ambient; + ambient = 1.0 - max(0.9, ambient); float final_da = min(da, shadow); vec3 sun_contrib = final_da * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 6ff49c7dac..2d2d00cb51 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -46,21 +46,52 @@ uniform mat4 inv_proj; uniform vec2 screen_res; uniform int sun_up_factor; +const float sample_count = 5; + +float cGoldenAngle = 2.39996323f; + float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { stc.xyz /= stc.w; + stc.z += shadow_bias * bias_mul * 4.0; + + float shadow = 0.0; + float cs = shadow2D(shadowMap, stc.xyz).x; + float initialTheta = cGoldenAngle*fract((pos_screen.y+pos_screen.x)*shadow_res.y); + float theta = initialTheta; + int i; + for (i = 0; i < sample_count; i++) + { + float r = float(i) / float(sample_count); + float weight = sqrt(1.0 - r); + r = sqrt(r); + vec2 sampleOffset; + sampleOffset.x = cos(theta); + sampleOffset.y = sin(theta); + sampleOffset *= r * 2.0; + float s = shadow2D(shadowMap, stc.xyz + vec3(sampleOffset, 0)).x; + shadow += weight * s; + theta += cGoldenAngle; + } + shadow /= float(sample_count); + shadow += cs; + shadow *= 0.5; + return shadow; +} + +float pcfShadowOld(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) +{ + stc.xyz /= stc.w; + + float cs = shadow2D(shadowMap, stc.xyz).x; stc.z += shadow_bias * bias_mul * 2.0; stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs * 4.0; - + float shadow = cs; shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - return shadow * 0.125; + return shadow * 0.2; } float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 7f1d518dd6..0c9dc5da58 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -98,15 +98,18 @@ void main() 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); + float final_da = da; + final_da = min(final_da, scol); + final_da = clamp(final_da, 0.0, 1.0); + + float light_gamma = 1.0/1.3; + final_da = pow(final_da, light_gamma); + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 col; float bloom = 0.0; @@ -123,9 +126,9 @@ void main() float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = 1.0 - ambient; + ambient = 1.0 - max(0.9, ambient); - vec3 sun_contrib = min(da,scol) * sunlit; + vec3 sun_contrib = final_da * sunlit; col.rgb = amblit; col.rgb *= ambient; -- cgit v1.2.3 From 09bb0336f15027e907fbd28130b4ffda28a830cd Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 5 Apr 2019 09:19:46 -0700 Subject: SL-10854 part 2 Clamp ambient to keep shadows dark. Apply min with shadow value after we've pow'd by light gamma consistently between forward and deferred. --- .../shaders/class1/deferred/alphaF.glsl | 9 +++-- .../shaders/class1/deferred/materialF.glsl | 12 ++++--- .../shaders/class1/deferred/shadowUtil.glsl | 40 ++-------------------- .../shaders/class2/deferred/softenLightF.glsl | 10 +++--- 4 files changed, 19 insertions(+), 52 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index d560a49c1f..1bc576a4ec 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -196,9 +196,7 @@ void main() float da = dot(norm.xyz, light_dir.xyz); float final_da = da; - final_da = min(final_da, shadow); - final_da = max(final_da, 0.0f); - final_da = min(final_da, 1.0f); + final_da = clamp(final_da, 0.0f, 1.0f); final_da = pow(final_da, 1.0/1.3); vec4 color = vec4(0,0,0,0); @@ -209,9 +207,10 @@ void main() float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = 1.0 - max(0.9, ambient); + ambient = max(0.9, ambient); // keeps shadows dark + ambient = 1.0 - ambient; - vec3 sun_contrib = final_da * sunlit; + vec3 sun_contrib = min(final_da, shadow) * sunlit; color.rgb *= ambient; color.rgb += sun_contrib; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d389d975fa..4e24e61018 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -296,16 +296,18 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float da = dot(norm.xyz, light_dir.xyz); - da = clamp(da, 0.0, 1.0); - da = pow(da, 1.0 / 1.3); + + float final_da = da; + final_da = clamp(final_da, 0.0, 1.0); + final_da = pow(final_da, 1.0 / 1.3); float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = 1.0 - max(0.9, ambient); + ambient = max(0.9, ambient); + ambient = 1.0 - ambient; - float final_da = min(da, shadow); - vec3 sun_contrib = final_da * sunlit; + vec3 sun_contrib = min(final_da, shadow) * sunlit; col.rgb = amblit; col.rgb *= ambient; diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 2d2d00cb51..642aff6c41 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -46,52 +46,18 @@ uniform mat4 inv_proj; uniform vec2 screen_res; uniform int sun_up_factor; -const float sample_count = 5; - -float cGoldenAngle = 2.39996323f; - float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { stc.xyz /= stc.w; - stc.z += shadow_bias * bias_mul * 4.0; - - float shadow = 0.0; - float cs = shadow2D(shadowMap, stc.xyz).x; - float initialTheta = cGoldenAngle*fract((pos_screen.y+pos_screen.x)*shadow_res.y); - float theta = initialTheta; - int i; - for (i = 0; i < sample_count; i++) - { - float r = float(i) / float(sample_count); - float weight = sqrt(1.0 - r); - r = sqrt(r); - vec2 sampleOffset; - sampleOffset.x = cos(theta); - sampleOffset.y = sin(theta); - sampleOffset *= r * 2.0; - float s = shadow2D(shadowMap, stc.xyz + vec3(sampleOffset, 0)).x; - shadow += weight * s; - theta += cGoldenAngle; - } - shadow /= float(sample_count); - shadow += cs; - shadow *= 0.5; - return shadow; -} - -float pcfShadowOld(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) -{ - stc.xyz /= stc.w; - - float cs = shadow2D(shadowMap, stc.xyz).x; stc.z += shadow_bias * bias_mul * 2.0; stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here - float shadow = cs; + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs * 4.0; shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - return shadow * 0.2; + return shadow * 0.125; } float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 0c9dc5da58..92888e0fd2 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -94,6 +94,7 @@ 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; @@ -102,12 +103,10 @@ void main() vec4 diffuse = texture2DRect(diffuseRect, tc); scol = max(scol_ambocc.r, diffuse.a); + //scol = pow(scol, light_gamma); float final_da = da; - final_da = min(final_da, scol); final_da = clamp(final_da, 0.0, 1.0); - - float light_gamma = 1.0/1.3; final_da = pow(final_da, light_gamma); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); @@ -126,9 +125,10 @@ void main() float ambient = abs(da); ambient *= 0.5; ambient *= ambient; - ambient = 1.0 - max(0.9, ambient); + ambient = max(0.9, ambient); + ambient = 1.0 - ambient; - vec3 sun_contrib = final_da * sunlit; + vec3 sun_contrib = min(scol, final_da) * sunlit; col.rgb = amblit; col.rgb *= ambient; -- cgit v1.2.3 From 39803f29c6b8dec710fb4b0244a81734bd95644a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 5 Apr 2019 11:39:14 -0700 Subject: Fix spec gone wild in ALM water rendering. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index c3c8683f6b..e0af521511 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -153,12 +153,9 @@ void main() vec4 pos = vary_position; - //color.rgb = atmosTransport(color.rgb); - //color.rgb = scaleSoftClipFrag(color.rgb) * 0; - vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - frag_data[0] = vec4(color.rgb, 1); // diffuse - frag_data[1] = vec4(specular * 0.4, 0.75); // speccolor, spec + frag_data[0] = vec4(color.rgb, 0.25); // diffuse + frag_data[1] = vec4(specular * 0.15, 0.5); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 0, 0 } -- cgit v1.2.3 From fff2aecf7f96de9e53620887210487a48dd45580 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 5 Apr 2019 14:35:55 -0700 Subject: SL-10821 Fix directionality of da and preserve bumps on completely shadowed areas. --- .../newview/app_settings/shaders/class1/deferred/alphaF.glsl | 7 ++++--- .../app_settings/shaders/class1/deferred/materialF.glsl | 5 +++-- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 12 +++++++----- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 5 +++-- 4 files changed, 17 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 1bc576a4ec..68a735e813 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -194,7 +194,8 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; float da = dot(norm.xyz, light_dir.xyz); - + da = clamp(da, -1.0, 1.0); + float final_da = da; final_da = clamp(final_da, 0.0f, 1.0f); final_da = pow(final_da, 1.0/1.3); @@ -204,13 +205,13 @@ void main() color.rgb = amblit; color.a = final_alpha; - float ambient = abs(da); + float ambient = da; ambient *= 0.5; ambient *= ambient; ambient = max(0.9, ambient); // keeps shadows dark ambient = 1.0 - ambient; - vec3 sun_contrib = min(final_da, shadow) * sunlit; + vec3 sun_contrib = mix(final_da, min(final_da, shadow), 0.1) * sunlit; color.rgb *= ambient; color.rgb += sun_contrib; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4e24e61018..8691e729ee 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -296,18 +296,19 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float da = dot(norm.xyz, light_dir.xyz); + da = clamp(da, -1.0, 1.0); float final_da = da; final_da = clamp(final_da, 0.0, 1.0); final_da = pow(final_da, 1.0 / 1.3); - float ambient = abs(da); + float ambient = da; ambient *= 0.5; ambient *= ambient; ambient = max(0.9, ambient); ambient = 1.0 - ambient; - vec3 sun_contrib = min(final_da, shadow) * sunlit; + vec3 sun_contrib = mix(final_da, min(final_da, shadow), 0.1) * sunlit; col.rgb = amblit; col.rgb *= ambient; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index e44b441727..361ed40eaf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -86,13 +86,15 @@ void main() float envIntensity = norm.z; norm.xyz = getNorm(tc); + float light_gamma = 1.0/1.3; vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float da = dot(normalize(norm.xyz), light_dir.xyz); - da = clamp(da, 0.0, 1.0); + da = clamp(da, -1.0, 1.0); - float light_gamma = 1.0/1.3; - da = pow(da, light_gamma); + float final_da = da; + final_da = clamp(final_da, 0.0, 1.0); + final_da = pow(final_da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); @@ -107,12 +109,12 @@ void main() calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - float ambient = min(abs(da), 1.0); + float ambient = da; ambient *= 0.5; ambient *= ambient; ambient = 1.0 - ambient; - vec3 sun_contrib = da * sunlit; + vec3 sun_contrib = final_da * sunlit; col.rgb = amblit; col.rgb *= ambient; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 92888e0fd2..688e4e1d59 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -99,6 +99,7 @@ void main() 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 diffuse = texture2DRect(diffuseRect, tc); @@ -122,13 +123,13 @@ void main() calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); - float ambient = abs(da); + float ambient = da; ambient *= 0.5; ambient *= ambient; ambient = max(0.9, ambient); ambient = 1.0 - ambient; - vec3 sun_contrib = min(scol, final_da) * sunlit; + vec3 sun_contrib = mix(final_da, min(scol, final_da), 0.1) * sunlit; col.rgb = amblit; col.rgb *= ambient; -- cgit v1.2.3 From fe589170d3faa5ca681baca7b9a664e2d851cd6e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 5 Apr 2019 15:54:21 -0700 Subject: SL-10896 Fix deferred water soften prog lightnorm getting stomped with rotated lightnorm, because it's a water shader and needs water atmo uniform values, but it's a deferred lighting shader that needs not-so-rotated lightnorms. Make sunlight_color not get auto-updated so we can get the correct value from mSunDiffuse. Remove mix to preserve bumps as it was washing out shadows. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 68a735e813..6e693bd33b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -211,7 +211,7 @@ void main() ambient = max(0.9, ambient); // keeps shadows dark ambient = 1.0 - ambient; - vec3 sun_contrib = mix(final_da, min(final_da, shadow), 0.1) * sunlit; + vec3 sun_contrib = min(final_da, shadow) * sunlit; color.rgb *= ambient; color.rgb += sun_contrib; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8691e729ee..4a47311eb7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -308,7 +308,7 @@ void main() ambient = max(0.9, ambient); ambient = 1.0 - ambient; - vec3 sun_contrib = mix(final_da, min(final_da, shadow), 0.1) * sunlit; + vec3 sun_contrib = min(final_da, shadow) * sunlit; col.rgb = amblit; col.rgb *= ambient; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 688e4e1d59..12115082a9 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -129,7 +129,7 @@ void main() ambient = max(0.9, ambient); ambient = 1.0 - ambient; - vec3 sun_contrib = mix(final_da, min(scol, final_da), 0.1) * sunlit; + vec3 sun_contrib = min(scol, final_da) * sunlit; col.rgb = amblit; col.rgb *= ambient; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 7bfdb9f753..40c521cd2c 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -152,7 +152,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, + tmpAmbient)); //brightness of surface both sunlight and ambient - sunlit = srgb_to_linear(sunlight.rgb); + sunlit = vec3(sunlight.rgb* 0.5); amblit = vec3(tmpAmbient * .25); additive = normalize(additive); additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; -- cgit v1.2.3 From 282f91aaf38cd108ee96475e351623ae203c57a6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 8 Apr 2019 10:34:59 -0700 Subject: Make ambient clamping consistent between class1/2 deferred lighting and forward rendering. Add decls for intermediate lighting values for debug. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 20 ++++++++++++++++++-- .../shaders/class1/deferred/materialF.glsl | 16 +++++++++++++++- .../shaders/class1/deferred/softenLightF.glsl | 11 +++++++++++ .../shaders/class1/lighting/sumLightsV.glsl | 2 +- .../shaders/class2/deferred/softenLightF.glsl | 10 +++++++++- .../shaders/class2/windlight/atmosphericsF.glsl | 2 +- 6 files changed, 55 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 6e693bd33b..fb24927b26 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -190,7 +190,7 @@ void main() calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - vec2 abnormal = encode_normal(norm.xyz); + vec2 abnormal = encode_normal(norm.xyz); vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; float da = dot(norm.xyz, light_dir.xyz); @@ -208,15 +208,23 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(0.9, ambient); // keeps shadows dark + ambient = max(0.66, ambient); // keeps shadows dark ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; color.rgb *= ambient; + +vec3 post_ambient = color.rgb; + color.rgb += sun_contrib; + +vec3 post_sunlight = color.rgb; + color.rgb *= diff.rgb; +vec3 post_diffuse = color.rgb; + //color.rgb = mix(diff.rgb, color.rgb, final_alpha); color.rgb = atmosFragLighting(color.rgb, additive, atten); @@ -224,6 +232,8 @@ void main() vec4 light = vec4(0,0,0,0); +vec3 prelight_linearish_maybe = color.rgb; + #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) @@ -238,13 +248,19 @@ void main() // color.rgb += light.rgb; +vec3 postlight_linear = color.rgb; + +color.rgb = prelight_linearish_maybe; + color.rgb = linear_to_srgb(color.rgb); + #endif #ifdef WATER_FOG color = applyWaterFogView(pos.xyz, color); #endif + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4a47311eb7..4bb01824bf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -305,16 +305,24 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(0.9, ambient); + ambient = max(0.66, ambient); ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; col.rgb = amblit; col.rgb *= ambient; + +vec3 post_ambient = col.rgb; + col.rgb += sun_contrib; + +vec3 post_sunlight = col.rgb; + col.rgb *= diffuse.rgb; +vec3 post_diffuse = col.rgb; + float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -363,6 +371,8 @@ vec3 post_spec = col.rgb; vec3 light = vec3(0,0,0); + vec3 prelight_linearish_maybe = col.rgb; + #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) @@ -375,6 +385,8 @@ vec3 post_spec = col.rgb; col.rgb += light.rgb; +vec3 postlight_linear = col.rgb; + glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; @@ -384,6 +396,8 @@ vec3 post_spec = col.rgb; al = temp.a; #endif +//col.rgb = prelight_linearish_maybe; + col.rgb = linear_to_srgb(col.rgb); frag_color.rgb = col.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 361ed40eaf..4b9e8290dd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -112,15 +112,24 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; + ambient = max(0.66, ambient); ambient = 1.0 - ambient; vec3 sun_contrib = final_da * sunlit; col.rgb = amblit; col.rgb *= ambient; + +vec3 post_ambient = col.rgb; + col.rgb += sun_contrib; + +vec3 post_sunlight = col.rgb; + col.rgb *= diffuse.rgb; +vec3 post_diffuse = col.rgb; + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection @@ -168,6 +177,8 @@ void main() col = fogged.rgb; bloom = fogged.a; #endif + +//col.rgb = post_diffuse; } frag_color.rgb = col.rgb; diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl index 7d699a4967..4d7cff37c6 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl @@ -34,7 +34,7 @@ vec3 scaleDownLight(vec3 light); vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) { - vec4 col; + vec4 col = vec4(0); col.a = color.a; col.rgb = light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 12115082a9..8814587fbc 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -126,16 +126,24 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(0.9, ambient); + ambient = max(0.66, ambient); ambient = 1.0 - ambient; vec3 sun_contrib = min(scol, final_da) * sunlit; col.rgb = amblit; col.rgb *= ambient; + +vec3 post_ambient = col.rgb; + col.rgb += sun_contrib; + +vec3 post_sunlight = col.rgb; + col.rgb *= diffuse.rgb; +vec3 post_diffuse = col.rgb; + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 40c521cd2c..f1398afb99 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -152,7 +152,7 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, + tmpAmbient)); //brightness of surface both sunlight and ambient - sunlit = vec3(sunlight.rgb* 0.5); + sunlit = vec3(sunlight.rgb); amblit = vec3(tmpAmbient * .25); additive = normalize(additive); additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; -- cgit v1.2.3 From 996d441ddc64996711b5a4eb3135607686992b86 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 8 Apr 2019 16:53:57 -0700 Subject: SL-5186 Make projector ambiance unshadowed in both forward and deferred for consistency. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 19 ++++++++----------- .../shaders/class1/deferred/materialF.glsl | 17 ++++++++--------- .../shaders/class2/deferred/multiSpotLightF.glsl | 12 ++++++++---- .../shaders/class2/deferred/spotLightF.glsl | 10 ++++++---- 4 files changed, 30 insertions(+), 28 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index fb24927b26..4b99592dbb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -99,8 +99,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec lv = normalize(lv); vec3 norm = normalize(n); - da = max(0.0, dot(norm, lv)); - //da = min(da, shadow); + da = dot(norm, lv); da = clamp(da, 0.0, 1.0); //distance attenuation @@ -116,18 +115,15 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec // to match spotLight (but not multiSpotLight) *sigh* float lit = max(da * dist_atten,0.0); - // the shadowmap is wrong for alpha objects - // since we only have 2 maps but N spots - //col = lit * light_col * diffuse * shadow; - col = lit * light_col * diffuse; + col = lit * light_col * diffuse * shadow; float amb_da = ambiance; - amb_da += (da*0.5) * (1.0 - shadow) * ambiance; + amb_da += (da*0.5+0.5) * (1.0 - shadow) * ambiance; amb_da += (da*da*0.5 + 0.5) * (1.0 - shadow) * ambiance; amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); - col.rgb += amb_da * light_col * diffuse; + col.rgb += amb_da * 0.5 * light_col * diffuse; // no spec for alpha shader... } col = max(col, vec3(0)); @@ -234,7 +230,7 @@ vec3 post_diffuse = color.rgb; vec3 prelight_linearish_maybe = color.rgb; - #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); + #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, 1.0); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -244,16 +240,17 @@ vec3 prelight_linearish_maybe = color.rgb; LIGHT_LOOP(6) LIGHT_LOOP(7) +vec3 light_linear = light.rgb; + // keep it linear // color.rgb += light.rgb; vec3 postlight_linear = color.rgb; -color.rgb = prelight_linearish_maybe; +//color.rgb = light_linear; 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 4bb01824bf..8c5a0ef297 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -112,23 +112,20 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe //angular attenuation da = dot(n, lv); - //da = min(da, shadow); - da *= clamp(da, 0.0, 1.0); + da = clamp(da, 0.0, 1.0); float lit = max(da * dist_atten, 0.0); // shadowmap is wrong for alpha-blended objs // since we created shadowmaps for 2 but render N - //col = light_col*lit*diffuse*shadow; - col = light_col*lit*diffuse; + col = light_col*lit*diffuse*shadow; float amb_da = ambiance; - amb_da += (da*0.5) * (1.0 - shadow) * ambiance; + amb_da += (da*0.5+0.5) * (1.0 - shadow) * ambiance; amb_da += (da*da*0.5 + 0.5) * (1.0 - shadow) * ambiance; - amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); - col.rgb += amb_da * light_col * diffuse; + col.rgb += amb_da * 0.5 * light_col * diffuse; if (spec.a > 0.0) { @@ -373,7 +370,7 @@ vec3 post_spec = col.rgb; vec3 prelight_linearish_maybe = col.rgb; - #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); + #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, 1.0); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -383,6 +380,8 @@ vec3 post_spec = col.rgb; LIGHT_LOOP(6) LIGHT_LOOP(7) +vec3 light_linear = light.rgb; + col.rgb += light.rgb; vec3 postlight_linear = col.rgb; @@ -396,7 +395,7 @@ vec3 postlight_linear = col.rgb; al = temp.a; #endif -//col.rgb = prelight_linearish_maybe; +//col.rgb = light_linear; col.rgb = linear_to_srgb(col.rgb); diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index ab380f70e8..7ccc91f73c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -218,15 +218,19 @@ void main() dlit = color.rgb * plcol.rgb * plcol.a; col = dlit*lit*diff_tex*shadow; - amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; + + // unshadowed for consistency between forward and deferred? + amb_da += (da*0.5+0.5)/* *(1.0-shadow) */ *proj_ambiance; } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - - amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; + + // unshadowed for consistency between forward and deferred? + amb_da += (da*da*0.5+0.5) /* *(1.0-shadow) */ * proj_ambiance; amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); + col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; } @@ -251,7 +255,7 @@ void main() { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = dlit*scol*spec.rgb*shadow; - speccol = max(speccol, vec3(0)); + speccol = clamp(speccol, vec3(0), vec3(1)); col += speccol; } } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index a9482ea54c..2844cc8574 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -185,7 +185,8 @@ void main() lv = proj_origin-pos.xyz; lv = normalize(lv); float da = dot(norm, lv); - + da = clamp(da, 0.0, 1.0); + vec3 col = vec3(0,0,0); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; @@ -214,9 +215,10 @@ void main() vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); dlit = color.rgb * plcol.rgb * plcol.a; - + col = dlit*lit*diff_tex*shadow; - amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; + + amb_da += (da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); @@ -250,7 +252,7 @@ void main() { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = dlit*scol*spec.rgb*shadow; - speccol = max(speccol, vec3(0)); + speccol = clamp(speccol, vec3(0), vec3(1)); col += speccol; } } -- cgit v1.2.3 From f9c0b021ea1a695c0d5d4042981045fe265e7918 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 9 Apr 2019 13:02:58 -0700 Subject: SL-5186 Fix falloff on projectors in forward rendering (different falloff calcs than deferred). --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 10 +++++----- .../app_settings/shaders/class1/deferred/materialF.glsl | 16 ++++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 4b99592dbb..4fe0d1351d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -92,8 +92,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec float d = length(lv); float da = 1.0; vec3 col = vec3(0); - - if (d > 0.0 && fa > 0.0) + if (d > 0.0) { //normalize light vector lv = normalize(lv); @@ -103,8 +102,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec 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); + float dist = (la > 0) ? d/la : 1.0f; + fa += 1.0f; + float dist_atten = (fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; dist_atten *= dist_atten; dist_atten *= 2.0f; @@ -230,7 +230,7 @@ vec3 post_diffuse = color.rgb; vec3 prelight_linearish_maybe = color.rgb; - #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, 1.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 * 0.5, 1.0); LIGHT_LOOP(1) LIGHT_LOOP(2) diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8c5a0ef297..6d7162b5a2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -95,14 +95,15 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe vec3 col = vec3(0,0,0); - if (d > 0.0 && la > 0.0 && fa > 0.0) + if (d > 0.0) { //normalize light vector lv = normalize(lv); //distance attenuation - float dist = d/la; - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + float dist = (la > 0) ? d/la : 1.0f; + fa += 1.0f; + float dist_atten = ( fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; dist_atten *= dist_atten; dist_atten *= 2.0f; @@ -121,8 +122,11 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe col = light_col*lit*diffuse*shadow; float amb_da = ambiance; - amb_da += (da*0.5+0.5) * (1.0 - shadow) * ambiance; - amb_da += (da*da*0.5 + 0.5) * (1.0 - shadow) * ambiance; + if (da > 0) + { + amb_da += (da*0.5 + 0.5) * ambiance; + } + amb_da += (da*da*0.5+0.5) * ambiance; amb_da = min(amb_da, 1.0f - lit); col.rgb += amb_da * 0.5 * light_col * diffuse; @@ -370,7 +374,7 @@ vec3 post_spec = col.rgb; vec3 prelight_linearish_maybe = col.rgb; - #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, 1.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 * 0.5, 1.0); LIGHT_LOOP(1) LIGHT_LOOP(2) -- cgit v1.2.3 From dcd8117b85f45886f78a1a2e9756cb1709d6572a Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 9 Apr 2019 22:35:40 -0700 Subject: First stab at moving atmospheric var calcs to its own utility shader. Still some work to go here. Largely related to how certain values (i.e., SSAO mix values) are supplied. But so far, so good. --HG-- branch : OPEN-340 --- .../class1/windlight/atmosphericsFuncs.glsl | 116 +++++++++++++++++++++ .../shaders/class2/deferred/softenLightF.glsl | 6 +- 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl (limited to 'indra/newview/app_settings/shaders') 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..2854fb8139 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -0,0 +1,116 @@ +uniform vec4 gamma; +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 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 vec4 glow; +uniform float scene_light_strength; +uniform mat3 ssao_effect_mat; +uniform int no_atmo; +uniform float sun_moon_glow_factor; + +vec3 nothing() { + return vec3(0, 0, 0); +} + +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { + + vec3 P = inPositionEye; + + //(TERRAIN) limit altitude + if (P.y > max_y) P *= (max_y / P.y); + if (P.y < -max_y) P *= (-max_y / P.y); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(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 + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + if (temp2.y > 0.001f) + { + temp2.y = 1. / temp2.y; + } + temp2.y = max(0.001f, temp2.y); + sunlight *= exp(-light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + atten = temp1.rgb; + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + temp2.x *= sun_moon_glow_factor; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + additive = + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient)); + + //brightness of surface both sunlight and ambient + sunlit = vec3(sunlight.rgb); + amblit = vec3(tmpAmbient * .25); + additive = normalize(additive); + additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; +} \ No newline at end of file diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 8814587fbc..4c7c50315f 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -72,6 +72,8 @@ vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 add, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); + vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); @@ -79,6 +81,8 @@ vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPosition(vec2 pos_screen); +vec3 nothing(); + #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); #endif @@ -121,7 +125,7 @@ void main() vec3 additive; vec3 atten; - calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); + calcAtmosphericVars(pos.xyz, ambocc, sunlit, amblit, additive, atten); float ambient = da; ambient *= 0.5; -- cgit v1.2.3 From 08812cbe060e62cb8b61e91bc2f878a74a0015e5 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 10 Apr 2019 02:11:07 -0700 Subject: Separate out vertex program objects from fragment program objects and use it. Given that mShaderObjects only ever expects one copy of a given shader object (leading to lots of "shaderV" and "shaderF"), it made having utility shaders a bit more difficult to incorporate. This change makes sure the two are separated. Using this over a multimap largely for readibility. Also, actually, you know, use this functionality. --HG-- branch : OPEN-340 --- .../shaders/class1/deferred/softenLightF.glsl | 6 +- .../class1/windlight/atmosphericsFuncs.glsl | 6 +- .../shaders/class2/deferred/softenLightF.glsl | 2 +- .../shaders/class2/windlight/atmosphericsV.glsl | 128 ++------------------- 4 files changed, 18 insertions(+), 124 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 4b9e8290dd..c599c14b43 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -73,6 +73,8 @@ vec3 fullbrightAtmosTransportFrag(vec3 l, vec3 additive, vec3 atten); void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); + vec3 scaleSoftClipFrag(vec3 l); vec4 getPositionWithDepth(vec2 pos_screen, float depth); @@ -107,8 +109,8 @@ void main() vec3 additive; vec3 atten; - calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - + calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten); + sunlit *= 0.5; float ambient = da; ambient *= 0.5; ambient *= ambient; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 2854fb8139..a099083883 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -77,7 +77,7 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o temp2.x = dot(Pn, tmpLightnorm.xyz); temp2.x = 1. - temp2.x; //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y + temp2.x = max(temp2.x, .001); //was glow.y //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) temp2.x *= glow.x; //higher glow.x gives dimmer glow (because next step is 1 / "angle") @@ -109,8 +109,8 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o + tmpAmbient)); //brightness of surface both sunlight and ambient - sunlit = vec3(sunlight.rgb); - amblit = vec3(tmpAmbient * .25); + sunlit = sunlight.rgb; + amblit = tmpAmbient.rgb * .25; additive = normalize(additive); additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; } \ No newline at end of file diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 4c7c50315f..2a772e6741 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -126,7 +126,7 @@ void main() vec3 atten; calcAtmosphericVars(pos.xyz, ambocc, sunlit, amblit, additive, atten); - + sunlit *= 0.5; float ambient = da; ambient *= 0.5; ambient *= ambient; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index 6c4098b9fb..ac7931209e 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -34,128 +34,20 @@ void setPositionEye(vec3 v); vec3 getAdditiveColor(); -//VARYING vec4 vary_CloudUVs; -//VARYING float vary_CloudDensity; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; - -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; -uniform int sun_up_factor; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 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 vec4 glow; -uniform float sun_moon_glow_factor; +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); void calcAtmospherics(vec3 inPositionEye) { vec3 P = inPositionEye; setPositionEye(P); - - //(TERRAIN) limit altitude - if (P.y > max_y) P *= (max_y / P.y); - if (P.y < -max_y) P *= (-max_y / P.y); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(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 - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - if (temp2.y > 0.001f) - { - temp2.y = 1. / temp2.y; - } - temp2.y = max(0.001f, temp2.y); - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - //vary_AtmosAttenuation = distance_multiplier / 10000.; - //vary_AtmosAttenuation = density_multiplier * 100.; - //vary_AtmosAttenuation = vec4(Plen / 100000., 0., 0., 1.); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - temp2.x *= sun_moon_glow_factor; - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - vec3 additive = - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient)); - additive = normalize(additive); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(additive * vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5); - - /* - const float cloudShadowScale = 100.; - // Get cloud uvs for shadowing - vec3 cloudPos = inPositionEye + camPosWorld - cloudShadowScale / 2.; - vary_CloudUVs.xy = cloudPos.xz / cloudShadowScale; - - // We can take uv1 and multiply it by (TerrainSpan / CloudSpan) -// cloudUVs *= (((worldMaxZ - worldMinZ) * 20) /40000.); - vary_CloudUVs *= (10000./40000.); - - // Offset by sun vector * (CloudAltitude / CloudSpan) - vary_CloudUVs.x += tmpLightnorm.x / tmpLightnorm.y * (3000./40000.); - vary_CloudUVs.y += tmpLightnorm.z / tmpLightnorm.y * (3000./40000.); - */ + vec3 tmpsunlit = vec3(1); + vec3 tmpamblit = vec3(1); + vec3 tmpaddlit = vec3(1); + vec3 tmpattenlit = vec3(1); + calcAtmosphericVars(inPositionEye, 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit); + setSunlitColor(tmpsunlit); + setAmblitColor(tmpamblit); + setAdditiveColor(tmpaddlit); + setAtmosAttenuation(tmpattenlit); } -- cgit v1.2.3 From d7d8a15092c91f6fa55547515b243b61a78868ff Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 10 Apr 2019 02:49:25 -0700 Subject: Fullbright + elimination of all references to calcFragAtmospherics. --HG-- branch : OPEN-340 --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 5 +++++ indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 4 +--- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 3 +-- 5 files changed, 11 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 4fe0d1351d..ca82dd9432 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -77,7 +77,7 @@ vec2 encode_normal (vec3 n); vec3 scaleSoftClipFrag(vec3 l); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); -void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); #ifdef HAS_SHADOW float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); @@ -184,7 +184,7 @@ void main() vec3 additive; vec3 atten; - calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); + calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten); vec2 abnormal = encode_normal(norm.xyz); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index d5ef010017..f98fc0d518 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -45,6 +45,9 @@ VARYING vec2 vary_texcoord0; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif +vec3 fullbrightAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light); + #ifdef HAS_ALPHA_MASK uniform float minimum_alpha; #endif @@ -74,6 +77,8 @@ void main() color.rgb = fogged.rgb; color.a = fogged.a; #else + color.rgb = fullbrightAtmosTransport(color.rgb); + color.rgb = fullbrightScaleSoftClip(color.rgb); color.a = final_alpha; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6d7162b5a2..9b07c11361 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -41,7 +41,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); -void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -290,7 +290,7 @@ void main() vec3 additive; vec3 atten; - calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); + calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten); vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index c599c14b43..b166f45bce 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -71,8 +71,6 @@ vec3 getNorm(vec2 pos_screen); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 fullbrightAtmosTransportFrag(vec3 l, vec3 additive, vec3 atten); -void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); - void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -168,7 +166,7 @@ vec3 post_diffuse = col.rgb; col = mix(col.rgb, refcol, envIntensity); } - if (norm.w < 0.5) + //if (norm.w < 0.5) { col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 2a772e6741..e1e299edee 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -67,7 +67,6 @@ uniform vec2 screen_res; vec3 getNorm(vec2 pos_screen); -void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 add, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -184,7 +183,7 @@ vec3 post_diffuse = col.rgb; col = mix(col.rgb, refcol, envIntensity); } - if (norm.w < 0.5) + //if (norm.w < 0.5) { //col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); //col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col, additive, atten), diffuse.a); -- cgit v1.2.3 From 3d0c05ba3aef00dfe8388e2081b3125bf252c1c0 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 10 Apr 2019 03:12:05 -0700 Subject: I don't think the class3 variant is used, but just in case. --HG-- branch : OPEN-340 --- .../shaders/class3/windlight/atmosphericsV.glsl | 110 +++------------------ 1 file changed, 13 insertions(+), 97 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl index 9bd75cf118..b8c0547102 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl @@ -32,104 +32,20 @@ void setPositionEye(vec3 v); vec3 getAdditiveColor(); -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; - -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; -uniform int sun_up_factor; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 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 vec4 glow; +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); void calcAtmospherics(vec3 inPositionEye) { - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(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 - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - //tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); + vec3 P = inPositionEye; + setPositionEye(P); + vec3 tmpsunlit = vec3(1); + vec3 tmpamblit = vec3(1); + vec3 tmpaddlit = vec3(1); + vec3 tmpattenlit = vec3(1); + calcAtmosphericVars(inPositionEye, 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit); + setSunlitColor(tmpsunlit); + setAmblitColor(tmpamblit); + setAdditiveColor(tmpaddlit); + setAtmosAttenuation(tmpattenlit); } + -- cgit v1.2.3 From de1a88d6bb17e767a9db8979ea2f7c0b3ba4cb41 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 10 Apr 2019 03:20:04 -0700 Subject: Revive the shading model that masks fog. --HG-- branch : OPEN-340 --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index b166f45bce..ff30004ffd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -166,7 +166,7 @@ vec3 post_diffuse = col.rgb; col = mix(col.rgb, refcol, envIntensity); } - //if (norm.w < 0.5) + if (norm.w < 1) { col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index e1e299edee..d87b2560ce 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -183,7 +183,7 @@ vec3 post_diffuse = col.rgb; col = mix(col.rgb, refcol, envIntensity); } - //if (norm.w < 0.5) + if (norm.w < 1) { //col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); //col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col, additive, atten), diffuse.a); -- cgit v1.2.3 From 2c568e7584ed4a5c000b2064a4d06f4b2347a34a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Apr 2019 10:11:50 -0700 Subject: SL-10925, SL-10926, SL-10896 New fix for 925/926 that doesn't cause 896 again. Also linearize moon disc tex color. --- indra/newview/app_settings/shaders/class1/deferred/moonF.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 7732cf986e..aae6158673 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -44,6 +44,8 @@ uniform sampler2D altDiffuseMap; uniform float blend_factor; // interp factor between moon A/B VARYING vec2 vary_texcoord0; +vec3 srgb_to_linear(vec3 c); + void main() { vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); @@ -58,6 +60,8 @@ void main() vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0 - 1.0; c.rgb = pow(c.rgb, exp); + c.rgb = srgb_to_linear(c.rgb); + //c.rgb *= moonlight_color.rgb; frag_data[0] = vec4(c.rgb, c.a); -- cgit v1.2.3 From 0b8ff3a8b22ccfdff320acba127ad631823b5644 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Apr 2019 10:55:30 -0700 Subject: Fix missing sentinel in shader file to avoid spurious complaints for hg policy hooks. --- .../class1/windlight/atmosphericsFuncs.glsl | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index a099083883..845c45cc07 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -1,3 +1,27 @@ +/** + * @file class1\windlight\atmosphericsFuncs.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2019, 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 vec4 gamma; uniform vec4 lightnorm; uniform vec4 sunlight_color; @@ -113,4 +137,4 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o amblit = tmpAmbient.rgb * .25; additive = normalize(additive); additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; -} \ No newline at end of file +} -- cgit v1.2.3 From 27184c74b4b8085e362c6e21d5d1071889476fe9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Apr 2019 13:43:58 -0700 Subject: SL-10901 Fix up shadow sampling and tweak shadow biasing. Clean up shader decls of unused funcs. Clean up whitespace diffs from release. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 17 +++++++++++------ .../app_settings/shaders/class1/deferred/materialF.glsl | 15 +++++++-------- .../shaders/class1/deferred/shadowUtil.glsl | 4 ++-- .../shaders/class1/deferred/softenLightF.glsl | 4 ++-- .../shaders/class2/deferred/softenLightF.glsl | 9 ++------- 5 files changed, 24 insertions(+), 25 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index ca82dd9432..ab7f779a39 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -83,7 +83,7 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); #endif -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) +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance) { //get light vector vec3 lv = lp.xyz-v; @@ -115,15 +115,19 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec // to match spotLight (but not multiSpotLight) *sigh* float lit = max(da * dist_atten,0.0); - col = lit * light_col * diffuse * shadow; + col = lit * light_col * diffuse; float amb_da = ambiance; - amb_da += (da*0.5+0.5) * (1.0 - shadow) * ambiance; - amb_da += (da*da*0.5 + 0.5) * (1.0 - shadow) * ambiance; + if (da > 0) + { + amb_da += (da*0.5+0.5) * ambiance; + } + amb_da += (da*da*0.5 + 0.5) * ambiance; amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); col.rgb += amb_da * 0.5 * light_col * diffuse; + // no spec for alpha shader... } col = max(col, vec3(0)); @@ -185,6 +189,7 @@ void main() vec3 atten; calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten); + sunlit *= 0.5; vec2 abnormal = encode_normal(norm.xyz); @@ -228,9 +233,9 @@ vec3 post_diffuse = color.rgb; vec4 light = vec4(0,0,0,0); -vec3 prelight_linearish_maybe = color.rgb; +vec3 prelight_linearish_maybe = srgb_to_linear(color.rgb); - #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 * 0.5, 1.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 * 0.5); LIGHT_LOOP(1) LIGHT_LOOP(2) diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 9b07c11361..d14e67fc73 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -83,7 +83,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, float shadow) +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) { //get light vector vec3 lv = lp.xyz-v; @@ -109,17 +109,16 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation da = dot(n, lv); da = clamp(da, 0.0, 1.0); + da *= spot*spot; // GL_SPOT_EXPONENT=2 + float lit = max(da * dist_atten, 0.0); - // shadowmap is wrong for alpha-blended objs - // since we created shadowmaps for 2 but render N - col = light_col*lit*diffuse*shadow; + col = light_col*lit*diffuse; float amb_da = ambiance; if (da > 0) @@ -148,7 +147,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = lit*scol*light_col.rgb*spec.rgb; - speccol = max(speccol, vec3(0)); + speccol = clamp(speccol, vec3(0), vec3(1)); col += speccol; float cur_glare = max(speccol.r, speccol.g); @@ -372,9 +371,9 @@ vec3 post_spec = col.rgb; vec3 light = vec3(0,0,0); - vec3 prelight_linearish_maybe = col.rgb; + vec3 prelight_linearish_maybe = srgb_to_linear(col.rgb); - #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 * 0.5, 1.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 * 0.5); LIGHT_LOOP(1) LIGHT_LOOP(2) diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 642aff6c41..0a714f0013 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -49,7 +49,7 @@ uniform int sun_up_factor; float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { stc.xyz /= stc.w; - stc.z += shadow_bias * bias_mul * 2.0; + stc.z += shadow_bias * bias_mul * 16.0; stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; float shadow = cs * 4.0; @@ -57,7 +57,7 @@ float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - return shadow * 0.125; + return clamp(shadow * 0.125, 0.0, 1.0); } float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index ff30004ffd..476a1216d3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -151,8 +151,8 @@ vec3 post_diffuse = col.rgb; { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = sun_contrib*scol*spec.rgb; - speccol = max(speccol, vec3(0)); - bloom = dot (speccol, speccol) / 2; + speccol = clamp(speccol, vec3(0), vec3(1)); + bloom = dot(speccol, speccol) / 2; col += speccol; } } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index d87b2560ce..6bebb79f31 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -68,7 +68,6 @@ uniform vec2 screen_res; vec3 getNorm(vec2 pos_screen); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 add, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); @@ -80,8 +79,6 @@ vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPosition(vec2 pos_screen); -vec3 nothing(); - #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); #endif @@ -132,7 +129,7 @@ void main() ambient = max(0.66, ambient); ambient = 1.0 - ambient; - vec3 sun_contrib = min(scol, final_da) * sunlit; + vec3 sun_contrib = scol * final_da * sunlit; col.rgb = amblit; col.rgb *= ambient; @@ -168,7 +165,7 @@ vec3 post_diffuse = col.rgb; { float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = sun_contrib*scontrib*spec.rgb; - speccol = max(speccol, vec3(0)); + speccol = clamp(speccol, vec3(0), vec3(1)); bloom += dot (speccol, speccol) / 2; col += speccol; } @@ -185,8 +182,6 @@ vec3 post_diffuse = col.rgb; if (norm.w < 1) { - //col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); - //col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col, additive, atten), diffuse.a); col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); } -- cgit v1.2.3 From 37a7c96f1724332ccddde36bf5095b99af95fe8f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 15 Apr 2019 09:41:12 -0700 Subject: Fix line-endings on new shader file from contribution. --- .../class1/windlight/atmosphericsFuncs.glsl | 280 ++++++++++----------- 1 file changed, 140 insertions(+), 140 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 845c45cc07..91760e05bf 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -1,140 +1,140 @@ -/** - * @file class1\windlight\atmosphericsFuncs.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2019, 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 vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; -uniform int sun_up_factor; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 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 vec4 glow; -uniform float scene_light_strength; -uniform mat3 ssao_effect_mat; -uniform int no_atmo; -uniform float sun_moon_glow_factor; - -vec3 nothing() { - return vec3(0, 0, 0); -} - -void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { - - vec3 P = inPositionEye; - - //(TERRAIN) limit altitude - if (P.y > max_y) P *= (max_y / P.y); - if (P.y < -max_y) P *= (-max_y / P.y); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(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 - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - if (temp2.y > 0.001f) - { - temp2.y = 1. / temp2.y; - } - temp2.y = max(0.001f, temp2.y); - sunlight *= exp(-light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - atten = temp1.rgb; - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .001); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - temp2.x *= sun_moon_glow_factor; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - additive = - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient)); - - //brightness of surface both sunlight and ambient - sunlit = sunlight.rgb; - amblit = tmpAmbient.rgb * .25; - additive = normalize(additive); - additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; -} +/** + * @file class1\windlight\atmosphericsFuncs.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2019, 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 vec4 gamma; +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 moonlight_color; +uniform int sun_up_factor; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 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 vec4 glow; +uniform float scene_light_strength; +uniform mat3 ssao_effect_mat; +uniform int no_atmo; +uniform float sun_moon_glow_factor; + +vec3 nothing() { + return vec3(0, 0, 0); +} + +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { + + vec3 P = inPositionEye; + + //(TERRAIN) limit altitude + if (P.y > max_y) P *= (max_y / P.y); + if (P.y < -max_y) P *= (-max_y / P.y); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(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 + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + if (temp2.y > 0.001f) + { + temp2.y = 1. / temp2.y; + } + temp2.y = max(0.001f, temp2.y); + sunlight *= exp(-light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + atten = temp1.rgb; + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .001); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + temp2.x *= sun_moon_glow_factor; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + additive = + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient)); + + //brightness of surface both sunlight and ambient + sunlit = sunlight.rgb; + amblit = tmpAmbient.rgb * .25; + additive = normalize(additive); + additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; +} -- cgit v1.2.3 From 508ca2d458b6ae23909c88615498b629da0ca76e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 15 Apr 2019 11:52:24 -0700 Subject: SL-10959 Scale down of bloom was off by a factor of 3 or so. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 476a1216d3..71fbe5df57 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -152,7 +152,7 @@ vec3 post_diffuse = col.rgb; float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = sun_contrib*scol*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); - bloom = dot(speccol, speccol) / 2; + bloom = dot(speccol, speccol) / 6; col += speccol; } } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 6bebb79f31..737fb0fef7 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -166,7 +166,7 @@ vec3 post_diffuse = col.rgb; float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = sun_contrib*scontrib*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); - bloom += dot (speccol, speccol) / 2; + bloom += dot (speccol, speccol) / 6; col += speccol; } } -- cgit v1.2.3 From 479385c97fa2d433c85598f6871274c970a6f9a7 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 15 Apr 2019 16:31:01 -0700 Subject: SL-10968 Tweak forced frag depths for sun/moon disc images to resolve depth fighting with hills etc. --- indra/newview/app_settings/shaders/class1/deferred/moonF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index aae6158673..cc1636d89d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -68,6 +68,6 @@ void main() frag_data[1] = vec4(0.0); frag_data[2] = vec4(0.0f); - gl_FragDepth = 0.99985f; + gl_FragDepth = 0.999985f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index d06cb43129..e240c130c6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -59,6 +59,6 @@ void main() frag_data[1] = vec4(0.0f); frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); - gl_FragDepth = 0.99988f; + gl_FragDepth = 0.999988f; } -- cgit v1.2.3 From a7e7d4a8185cd63c2f6f87fea992667912999426 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 16 Apr 2019 08:41:12 -0700 Subject: Make blended material objects use the same BRDF for spec as everything else. --- .../shaders/class1/deferred/materialF.glsl | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d14e67fc73..0819f1b292 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -327,21 +327,27 @@ vec3 post_diffuse = col.rgb; if (spec.a > 0.0) // specular reflection { - // the old infinite-sky shiny reflection - // - - float sa = dot(refnormpersp, light_dir.xyz); - - vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - - glare = max(spec_contrib.r, spec_contrib.g); - glare = max(glare, spec_contrib.b); - - col += spec_contrib; + vec3 npos = -normalize(pos.xyz); + + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(light_dir.xyz+npos); + float nh = dot(norm.xyz, h); + float nv = dot(norm.xyz, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = sun_contrib*scol*spec.rgb; + speccol = clamp(speccol, vec3(0), vec3(1)); + bloom = dot(speccol, speccol) / 6; + col += speccol; + } } vec3 post_spec = col.rgb; -- cgit v1.2.3 From ebf53108cb8b77eb15c8b16f97bee30d6649e020 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 18 Apr 2019 10:55:01 -0700 Subject: SL-10966 Fix use of density and distance multipliers in atmospherics to use original pre-EEP range instead of FS expanded range. Modify additive calc to restore old behavior (probably reverts fix for "lens flare" bug). --- .../shaders/class1/windlight/atmosphericsFuncs.glsl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 91760e05bf..d503de6f24 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -66,9 +66,12 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; + float dens_mul = density_multiplier * 0.5; // get back to original pre-EEP range... + float dist_mul = distance_multiplier * 0.1; // get back to original pre-EEP range... + //sunlight attenuation effect (hue and brightness) due to atmosphere //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * 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 @@ -86,12 +89,12 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o sunlight *= exp(-light_atten * temp2.y); // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; + temp2.z = Plen * dens_mul / 2.0f; // 2.0 to get range back to what it was pre-EEP... // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // ATI Bugfix -- can't store temp1*temp2.z*dist_mul in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); + temp1 = exp(-temp1 * temp2.z * dist_mul); //final atmosphere attenuation factor atten = temp1.rgb; @@ -135,6 +138,5 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o //brightness of surface both sunlight and ambient sunlit = sunlight.rgb; amblit = tmpAmbient.rgb * .25; - additive = normalize(additive); - additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; + additive *= vec3(1.0 - temp1); } -- cgit v1.2.3 From 311adf5469dde93da7813d6d89feb77d44c01804 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 18 Apr 2019 11:28:49 -0700 Subject: SL-10967 Make fullbright transport look closer to normal transport so fullbright objects reflect distance. --- indra/newview/app_settings/shaders/class2/windlight/transportF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index df731662e8..918ebcb0e3 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -50,7 +50,7 @@ vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) return light; } float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness); + return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness * 0.1); } vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { @@ -59,7 +59,7 @@ vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { return light; } float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); + return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness * 0.1); } vec3 atmosTransport(vec3 light) -- cgit v1.2.3 From 935adb60831166af49a61b4af97526819d54cb23 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 18 Apr 2019 13:07:49 -0700 Subject: SL-10966 Don't re-range density multiplier twice. --- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index d503de6f24..1d105690d1 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -89,7 +89,7 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o sunlight *= exp(-light_atten * temp2.y); // main atmospheric scattering line integral - temp2.z = Plen * dens_mul / 2.0f; // 2.0 to get range back to what it was pre-EEP... + temp2.z = Plen * dens_mul; // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z*dist_mul in a variable because the ati -- cgit v1.2.3 From 3dd5942776a8e3755fa75e01661b343972affbf9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 19 Apr 2019 07:44:18 -0700 Subject: Add directory names to sentinels in shaders so shaders with same filename can be differentiated in nSight while debugging. --- indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl | 2 +- indra/newview/app_settings/shaders/class1/environment/terrainF.glsl | 2 +- indra/newview/app_settings/shaders/class1/environment/terrainV.glsl | 2 +- indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl | 2 +- .../app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl | 2 +- indra/newview/app_settings/shaders/class1/lighting/lightF.glsl | 2 +- .../app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl | 2 +- .../newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl | 2 +- .../shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl | 2 +- .../shaders/class1/lighting/lightFullbrightNonIndexedF.glsl | 2 +- .../app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl | 2 +- .../shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl | 2 +- .../shaders/class1/lighting/lightFullbrightShinyWaterF.glsl | 2 +- .../shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl | 2 +- .../shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl | 2 +- .../app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl | 2 +- .../class1/lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl | 2 +- .../shaders/class1/lighting/lightFullbrightWaterNonIndexedF.glsl | 2 +- .../app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl | 2 +- indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl | 2 +- .../newview/app_settings/shaders/class1/lighting/lightNonIndexedF.glsl | 2 +- indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl | 2 +- .../app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl | 2 +- .../newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl | 2 +- .../shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl | 2 +- indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl | 2 +- indra/newview/app_settings/shaders/class1/lighting/lightV.glsl | 2 +- .../app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl | 2 +- .../shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl | 2 +- indra/newview/app_settings/shaders/class1/lighting/lightWaterF.glsl | 2 +- .../app_settings/shaders/class1/lighting/lightWaterNonIndexedF.glsl | 2 +- .../app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl | 2 +- indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl | 2 +- .../app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl | 2 +- .../app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl | 2 +- .../app_settings/shaders/class1/windlight/atmosphericsVarsF.glsl | 2 +- .../app_settings/shaders/class1/windlight/atmosphericsVarsV.glsl | 2 +- .../app_settings/shaders/class1/windlight/atmosphericsVarsWaterF.glsl | 2 +- .../app_settings/shaders/class1/windlight/atmosphericsVarsWaterV.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/moonF.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/moonV.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl | 2 +- indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl | 2 +- .../app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl | 2 +- indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl | 2 +- .../app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl | 2 +- .../app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl | 2 +- .../app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl | 2 +- .../app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl | 2 +- .../app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl | 2 +- .../app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/skyV.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/transportF.glsl | 2 +- .../app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl | 2 +- indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl | 2 +- indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl | 2 +- indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl | 2 +- indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl | 2 +- indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl | 2 +- indra/newview/app_settings/shaders/class3/windlight/transportF.glsl | 2 +- 70 files changed, 70 insertions(+), 70 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 800070c01d..9829842a0f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -1,5 +1,5 @@ /** - * @file terrainF.glsl + * @file class1\deferred\terrainF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl index 04fdc18b78..f42cb6ff6d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl @@ -1,5 +1,5 @@ /** - * @file terrainV.glsl + * @file class1\environment\terrainV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl index 668a710c04..6b68ed4169 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainF.glsl @@ -1,5 +1,5 @@ /** - * @file terrainF.glsl + * @file class1\environment\terrainF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl index 4d6f0c67a5..5dcdbfaa50 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl @@ -1,5 +1,5 @@ /** - * @file terrainV.glsl + * @file class1\environment\terrainV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl index cad5b9ff04..f665394b46 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl @@ -1,5 +1,5 @@ /** - * @file lightAlphaMaskF.glsl + * @file class1\lighting\lightAlphaMaskF.glsl * * $LicenseInfo:firstyear=2011&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl index 8918182853..b768d609f4 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl @@ -1,5 +1,5 @@ /** - * @file lightAlphaMaskNonIndexedF.glsl + * @file class1\lighting\lightAlphaMaskNonIndexedF.glsl * * $LicenseInfo:firstyear=2011&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightF.glsl index d6ebfcb825..9fd189358b 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightF.glsl @@ -1,5 +1,5 @@ /** - * @file lightF.glsl + * @file class1\lighting\lightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl index 5740987ab1..46390e4a0e 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl @@ -1,5 +1,5 @@ /** - * @file lightFullbrightAlphaMaskF.glsl + * @file class1\lighting\lightFullbrightAlphaMaskF.glsl * * $LicenseInfo:firstyear=2011&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl index c8771a3f1e..b967709c57 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl @@ -1,5 +1,5 @@ /** - * @file lightFullbrightF.glsl + * @file class1\lighting\lightFullbrightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl index f72f20b03d..e8e71beb44 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl @@ -1,5 +1,5 @@ /** - * @file lightFullbrightNonIndexedAlphaMaskF.glsl + * @file class1\lighting\lightFullbrightNonIndexedAlphaMaskF.glsl * * $LicenseInfo:firstyear=2011&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedF.glsl index 2738ff8947..11a0919086 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedF.glsl @@ -1,5 +1,5 @@ /** - * @file lightFullbrightF.glsl + * @file class1\lighting\lightFullbrightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl index c8282e9a51..64ecf1f392 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl @@ -1,5 +1,5 @@ /** - * @file lightFullbrightShinyF.glsl + * @file class1\lighting\lightFullbrightShinyF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl index e7dbd4bbd2..3118453342 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl @@ -1,5 +1,5 @@ /** - * @file lightFullbrightShinyF.glsl + * @file class1\lighting\lightFullbrightShinyF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterF.glsl index 5886fc65be..f78e5e0e8a 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterF.glsl @@ -1,5 +1,5 @@ /** - * @file lightFullbrightShinyWaterF.glsl + * @file class1\lighting\lightFullbrightShinyWaterF.glsl * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl index cddc7d8df8..90668bd2b6 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl @@ -1,5 +1,5 @@ /** - * @file lightFullbrightShinyWaterF.glsl + * @file class1\lighting\lightFullbrightShinyWaterF.glsl * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl index 6dd3bb937f..d04cd79f4b 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl @@ -1,5 +1,5 @@ /** - * @file lightFullbrightWaterAlphaMaskF.glsl + * @file class1\lighting\lightFullbrightWaterAlphaMaskF.glsl * * $LicenseInfo:firstyear=2011&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl index d3dacf9bc4..27880b720c 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl @@ -1,5 +1,5 @@ /** - * @file lightFullbrightWaterF.glsl + * @file class1\lighting\lightFullbrightWaterF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl index 63f92a8844..3b9c04b22b 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl @@ -1,5 +1,5 @@ /** - * @file lightFullbrightWaterNonIndexedAlphaMaskF.glsl + * @file class1\lighting\lightFullbrightWaterNonIndexedAlphaMaskF.glsl * * $LicenseInfo:firstyear=2011&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedF.glsl index 0e68091e7c..e9fd8ac820 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterNonIndexedF.glsl @@ -1,5 +1,5 @@ /** - * @file lightFullbrightWaterF.glsl + * @file class1\lighting\lightFullbrightWaterF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl index 20e44d74d5..13a6dde4aa 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncSpecularV.glsl @@ -1,5 +1,5 @@ /** - * @file lightFuncSpecularV.glsl + * @file class1/lighting\lightFuncSpecularV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl index 8defcf9f52..d5448a1d31 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl @@ -1,5 +1,5 @@ /** - * @file lightFuncV.glsl + * @file class1\lighting\lightFuncV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightNonIndexedF.glsl index 0aca768021..f9c7ad2ab3 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightNonIndexedF.glsl @@ -1,5 +1,5 @@ /** - * @file lightF.glsl + * @file class1\lighting\lightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl index 9208c148ef..5bbd71002d 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl @@ -1,5 +1,5 @@ /** - * @file lightShinyF.glsl + * @file class1\lighting\lightShinyF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl index 92628faa68..2b6f414005 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl @@ -1,5 +1,5 @@ /** - * @file lightShinyF.glsl + * @file class1\lighting\lightShinyF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl index 61841674e2..0f3371eba9 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl @@ -1,5 +1,5 @@ /** - * @file lightShinyWaterF.glsl + * @file class1\lighting\lightShinyWaterF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl index 0b6e835fd0..c607fa64cb 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl @@ -1,5 +1,5 @@ /** - * @file lightShinyWaterF.glsl + * @file class1\lighting\lightShinyWaterNonIndexedF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl index 24bf9b3cee..0b36229d4d 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl @@ -1,5 +1,5 @@ /** - * @file lightSpecularV.glsl + * @file class1\lighting\lightSpecularV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl index 8045809b82..9757070a82 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl @@ -1,5 +1,5 @@ /** - * @file lightV.glsl + * @file class1\lighting\lightV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl index 3426fea52f..0916797259 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl @@ -1,5 +1,5 @@ /** - * @file lightWaterAlphaMaskF.glsl + * @file class1\lighting\lightWaterAlphaMaskF.glsl * * $LicenseInfo:firstyear=2011&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl index d9faa9b314..f2a84f1d42 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl @@ -1,5 +1,5 @@ /** - * @file lightWaterAlphaMaskNonIndexedF.glsl + * @file class1\lighting\lightWaterAlphaMaskNonIndexedF.glsl * * $LicenseInfo:firstyear=2011&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightWaterF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightWaterF.glsl index 00609e93cd..57ed993a66 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightWaterF.glsl @@ -1,5 +1,5 @@ /** - * @file lightWaterF.glsl + * @file class1\lighting\lightWaterF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightWaterNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightWaterNonIndexedF.glsl index 13ecb7a636..af5da1411b 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightWaterNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightWaterNonIndexedF.glsl @@ -1,5 +1,5 @@ /** - * @file lightWaterF.glsl + * @file class1\lighting\lightWaterNonIndexedF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl index 7059ff31ae..9863f92e63 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl @@ -1,5 +1,5 @@ /** - * @file sumLightsSpecularV.glsl + * @file class1\lighting\sumLightsSpecularV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl index 4d7cff37c6..962233345a 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl @@ -1,5 +1,5 @@ /** - * @file sumLightsV.glsl + * @file class1\lighting\sumLightsV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl index 10407eeb02..06f13b11f2 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericsHelpersF.glsl + * @file class1\windlight\atmosphericsHelpersF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl index 14034bccae..c24df9eaeb 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericsHelpersV.glsl + * @file class1\windlight\atmosphericsHelpersV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl index b749e1a7a2..20457ad125 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsV.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericsV.glsl + * @file class1\windlight\atmosphericsV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsF.glsl index 8bdae328bd..a0699affbf 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsF.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericVarsF.glsl + * @file class1\windlight\atmosphericVarsF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsV.glsl index 8ec9ae617c..bd1d150fc8 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsV.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericVarsV.glsl + * @file class1\windlight\atmosphericVarsV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterF.glsl index 636d4af006..5dc086ab1e 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterF.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericVarsWaterF.glsl + * @file class1\windlight\atmosphericVarsWaterF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterV.glsl index 8afcc20f6d..e59eca265a 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsVarsWaterV.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericVarsWaterV.glsl + * @file class1\windlight\atmosphericVarsWaterV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl index 69a3c59cb3..537d6ebb99 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl @@ -1,5 +1,5 @@ /** - * @file class3/deferred/cloudsF.glsl + * @file class1/windlight/cloudShadowF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl index 1c2fbaf25d..09b6004481 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl @@ -1,5 +1,5 @@ /** - * @file cloudShadowV.glsl + * @file class1\windlight\cloudShadowV.glsl * * $LicenseInfo:firstyear=2011&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl index 667301443a..346634af33 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl @@ -1,5 +1,5 @@ /** - * @file gammaF.glsl + * @file class1\windlight\gammaF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl index c8bbdd109d..24f3992e32 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -1,5 +1,5 @@ /** - * @file moonF.glsl + * @file class1\wl\moonF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl index 1c43a7332e..8cd4b2ef47 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl @@ -1,5 +1,5 @@ /** - * @file moonV.glsl + * @file class1\wl\moonV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl index d85ce004a5..b9ae7a0226 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscF.glsl @@ -1,5 +1,5 @@ /** - * @file sunDiscF.glsl + * @file class1\wl\sunDiscF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl index ca116628f1..6c0e795f6b 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/sunDiscV.glsl @@ -1,5 +1,5 @@ /** - * @file sunDiscV.glsl + * @file class1\wl\sunDiscV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl index 8ca7db1814..6fcc41cd6d 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl @@ -1,5 +1,5 @@ /** - * @file sumLightsV.glsl + * @file class2\lighting\sumLightsSpecularV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl index 36a8a8147b..bc7e6dd865 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl @@ -1,5 +1,5 @@ /** - * @file sumLightsV.glsl + * @file class2\lighting\sumLightsV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index f1398afb99..7b46a2ed28 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericsF.glsl + * @file class2\wl\atmosphericsF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl index 86743dc306..5788871744 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersF.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericsHelpersV.glsl + * @file class2\wl\atmosphericsHelpersV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl index 95b4a76880..c80706d2a7 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericsHelpersV.glsl + * @file class2\wl\atmosphericsHelpersV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index ac7931209e..4ac44feee5 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericsV.glsl + * @file class2\wl\atmosphericsV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl index 765b0927c3..9953f79cf2 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericVars.glsl + * @file class2\wl\atmosphericVars.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl index 99dbee15ee..31109aed31 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsV.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericVars.glsl + * @file class2\wl\atmosphericVars.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl index 163ef26444..22e16b7e0f 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterF.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericVarsWaterF.glsl + * @file class2\wl\atmosphericVarsWaterF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl index 553f6752e6..0f2a3ee527 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsWaterV.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericVarsWaterV.glsl + * @file class2\wl\atmosphericVarsWaterV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index 666ae84e5c..e31bdf610c 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -1,5 +1,5 @@ /** - * @file WLCloudsF.glsl + * @file class2\wl\cloudsF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index 3cb69c33a1..36badc5214 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -1,5 +1,5 @@ /** - * @file WLCloudsV.glsl + * @file class2\wl\cloudsV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index c0439006f7..5c339f9663 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -1,5 +1,5 @@ /** - * @file gammaF.glsl + * @file class2\wl\gammaF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index a65cc09c73..5798493ce5 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -1,5 +1,5 @@ /** - * @file WLSkyV.glsl + * @file class2\wl\skyV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 918ebcb0e3..868f5fe601 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -1,5 +1,5 @@ /** - * @file transportF.glsl + * @file class2\wl\transportF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl index ce5855646c..6d4192ab13 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl @@ -1,5 +1,5 @@ /** - * @file sumLightsV.glsl + * @file class3\lighting\sumLightsSpecularV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index c410caa967..21e8263623 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -1,5 +1,5 @@ /** - * @file sumLightsV.glsl + * @file class3\lighing\sumLightsV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl index fed3edf7de..c6ea3ec9d4 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl @@ -1,5 +1,5 @@ /** - * @file advancedAtmoF.glsl + * @file class3\wl\advancedAtmoF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl index 52a7595379..65bb00b1f6 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl @@ -1,5 +1,5 @@ /** - * @file advancedAtmoV.glsl + * @file class3\wl\advancedAtmoV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl index 852c2478bc..bc13aa9388 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericsF.glsl + * @file class3\wl\atmosphericsF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl index b8c0547102..27fdae962e 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl @@ -1,5 +1,5 @@ /** - * @file atmosphericsV.glsl + * @file class3\wl\atmosphericsV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index 90ab5d2793..715d51f720 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -1,5 +1,5 @@ /** - * @file transportF.glsl + * @file class3\wl\transportF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code -- cgit v1.2.3 From ea9c8e4325b1f3629b57c36208c7669e1f028c10 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 19 Apr 2019 08:01:28 -0700 Subject: SL-10996, SL-10997, SL-10970 Revert fix for 10901 because knock-on is causing other issues. --- indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 0a714f0013..84032f7ff7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -49,7 +49,7 @@ uniform int sun_up_factor; float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { stc.xyz /= stc.w; - stc.z += shadow_bias * bias_mul * 16.0; + stc.z += shadow_bias * bias_mul * 2.0; stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; float shadow = cs * 4.0; @@ -78,6 +78,7 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; return shadow*0.2; } + float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) { float shadow = 0.0f; -- cgit v1.2.3 From f30a649f1cd789510b2f4e0b2b2f85043cdfd700 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 19 Apr 2019 08:26:03 -0700 Subject: SL-10967 All paths now use the same atmospheric transport calcs. --- .../shaders/class1/deferred/fullbrightF.glsl | 2 +- .../shaders/class1/deferred/softenLightF.glsl | 1 - .../shaders/class1/windlight/transportF.glsl | 12 ----------- .../shaders/class2/deferred/softenLightF.glsl | 2 -- .../shaders/class2/windlight/transportF.glsl | 23 ++------------------- .../shaders/class3/windlight/transportF.glsl | 24 ++-------------------- 6 files changed, 5 insertions(+), 59 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index f98fc0d518..f8b1ff44c8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -63,7 +63,7 @@ void main() float final_alpha = color.a * vertex_color.a; #ifdef HAS_ALPHA_MASK - if (color.a < minimum_alpha) + if (final_alpha < minimum_alpha) { discard; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 71fbe5df57..8d126859c3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -69,7 +69,6 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 getNorm(vec2 pos_screen); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 fullbrightAtmosTransportFrag(vec3 l, vec3 additive, vec3 atten); void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); diff --git a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl index e2b391cb7a..79d8d11b32 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl @@ -31,18 +31,6 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) return light; } -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) -{ - /* stub function for fallback compatibility on class1 hardware */ - return light; -} - -vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 atten, vec3 additive) -{ - /* stub function for fallback compatibility on class1 hardware */ - return light; -} - vec3 atmosTransport(vec3 light) { /* stub function for fallback compatibility on class1 hardware */ diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 737fb0fef7..a1d1287825 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -73,8 +73,6 @@ vec3 scaleSoftClipFrag(vec3 l); void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPosition(vec2 pos_screen); diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 868f5fe601..2e8946252b 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -43,25 +43,6 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) return light; } -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) -{ - if (no_atmo == 1) - { - return light; - } - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive.rgb, brightness * brightness * 0.1); -} - -vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light; - } - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness * 0.1); -} - vec3 atmosTransport(vec3 light) { return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); @@ -69,10 +50,10 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransport(vec3 light) { - return fullbrightAtmosTransportFrag(light,getAdditiveColor(), getAtmosAttenuation()); + return atmosTransportFrag(light,getAdditiveColor(), getAtmosAttenuation()); } vec3 fullbrightShinyAtmosTransport(vec3 light) { - return fullbrightShinyAtmosTransportFrag(light,getAdditiveColor(), getAtmosAttenuation()); + return atmosTransportFrag(light,getAdditiveColor(), getAtmosAttenuation()); } diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index 715d51f720..e7e56087ab 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -41,26 +41,6 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) return (light + additive) * atten * 2.0; } -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) -{ - if (no_atmo == 1) - { - return light; - } - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive,atten), light.rgb + additive.rgb, brightness * brightness); -} - -vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) -{ - if (no_atmo == 1) - { - return light; - } - float brightness = dot(light.rgb, vec3(0.33333)); - return mix(atmosTransportFrag(light.rgb, additive, atten), (light.rgb + additive.rgb) * (2.0 - brightness), brightness * brightness); -} - vec3 atmosTransport(vec3 light) { return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); @@ -68,10 +48,10 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransport(vec3 light) { - return fullbrightAtmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); + return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } vec3 fullbrightShinyAtmosTransport(vec3 light) { - return fullbrightShinyAtmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); + return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } -- cgit v1.2.3 From dd1cc2f3b1df472be405f4b95107972be1ea1a62 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 19 Apr 2019 13:13:50 -0700 Subject: Fix sky and cloud shader usage of density_multiplier (not re-ranged from FS to WL). Remove all refs to now unused calcFragAtmospherics. --- .../shaders/class1/deferred/cloudsV.glsl | 5 +- .../app_settings/shaders/class1/deferred/skyV.glsl | 5 +- .../shaders/class1/windlight/atmosphericsF.glsl | 5 -- .../class1/windlight/atmosphericsFuncs.glsl | 4 - .../app_settings/shaders/class2/deferred/skyF.glsl | 5 +- .../shaders/class2/windlight/atmosphericsF.glsl | 96 ---------------------- .../shaders/class2/windlight/cloudsV.glsl | 5 +- .../shaders/class2/windlight/skyV.glsl | 6 +- .../shaders/class3/windlight/atmosphericsF.glsl | 84 ------------------- 9 files changed, 16 insertions(+), 199 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index cfe5632ec0..6cc436c837 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -103,10 +103,11 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; + float dens_mul = density_multiplier * 0.5; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); // Calculate relative weights temp1 = blue_density + haze_density; @@ -119,7 +120,7 @@ void main() sunlight *= exp( - light_atten * temp2.y); // Distance - temp2.z = Plen * density_multiplier; + temp2.z = Plen * dens_mul; // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 83dd9da091..7d56742d6f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -87,10 +87,11 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; + float dens_mul = density_multiplier * 0.5; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); // Calculate relative weights temp1 = blue_density + haze_density; @@ -103,7 +104,7 @@ void main() sunlight *= exp( - light_atten * temp2.y); // Distance - temp2.z = Plen * density_multiplier; + temp2.z = Plen * dens_mul; // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl index 4f0e2a6cb6..4e0618e276 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl @@ -46,8 +46,3 @@ vec3 atmosLighting(vec3 light) return light; } -void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive) -{ - /* stub function for fallback compatibility on class1 hardware */ -} - diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 1d105690d1..3d05912f49 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -42,10 +42,6 @@ uniform mat3 ssao_effect_mat; uniform int no_atmo; uniform float sun_moon_glow_factor; -vec3 nothing() { - return vec3(0, 0, 0); -} - void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { vec3 P = inPositionEye; diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 26f8095dc1..ea926ab5f1 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -117,10 +117,11 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; + float dens_mul = density_multiplier * 0.5; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); // Calculate relative weights temp1 = blue_density + haze_density; @@ -133,7 +134,7 @@ void main() sunlight *= exp( - light_atten * temp2.y); // Distance - temp2.z = Plen * density_multiplier; + temp2.z = Plen * dens_mul; // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 7b46a2ed28..a93253c981 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -37,8 +37,6 @@ uniform vec4 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 vec4 glow; uniform float scene_light_strength; @@ -64,97 +62,3 @@ vec3 atmosLighting(vec3 light) { return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); } - -void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { - - vec3 P = inPositionEye; - - //(TERRAIN) limit altitude - if (P.y > max_y) P *= (max_y / P.y); - if (P.y < -max_y) P *= (-max_y / P.y); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(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 - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - if (temp2.y > 0.001f) - { - temp2.y = 1. / temp2.y; - } - temp2.y = max(0.001f, temp2.y); - sunlight *= exp(-light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - atten = temp1.rgb; - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - temp2.x *= sun_moon_glow_factor; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - additive = - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient)); - - //brightness of surface both sunlight and ambient - sunlit = vec3(sunlight.rgb); - amblit = vec3(tmpAmbient * .25); - additive = normalize(additive); - additive *= vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5; -} - diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index 36badc5214..fcfe5bbba0 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -103,10 +103,11 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; + float dens_mul = density_multiplier * 0.5; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); // Calculate relative weights temp1 = blue_density + haze_density; @@ -119,7 +120,7 @@ void main() sunlight *= exp( - light_atten * temp2.y); // Distance - temp2.z = Plen * density_multiplier; + temp2.z = Plen * dens_mul; // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index 5798493ce5..a253bb72d5 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -87,9 +87,11 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; + float dens_mul = density_multiplier * 0.5; + // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); // Calculate relative weights temp1 = blue_density + haze_density; @@ -102,7 +104,7 @@ void main() sunlight *= exp( - light_atten * temp2.y); // Distance - temp2.z = Plen * density_multiplier; + temp2.z = Plen * dens_mul; // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl index bc13aa9388..c0a0d4782d 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl @@ -37,8 +37,6 @@ uniform vec4 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 vec4 glow; uniform float scene_light_strength; @@ -58,85 +56,3 @@ vec3 atmosLighting(vec3 light) return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); } -void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { - - vec3 P = inPositionEye; - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(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 - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - atten = temp1.rgb; - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - additive = - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient)); - - //brightness of surface both sunlight and ambient - sunlit = vec3(sunlight * .5); - amblit = vec3(tmpAmbient * .25); - additive *= vec3(1.0 - temp1); -} - -- cgit v1.2.3 From 4d76ba2d23c22e9a507a0eb7687b3750091b356f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 22 Apr 2019 10:21:10 -0700 Subject: Fix mismatch between release and EEP in sunlight and ambient color from settings. --- indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/skyV.glsl | 2 +- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 6 +++--- indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/skyV.glsl | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 6cc436c837..61fd43f1ee 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -103,7 +103,7 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier * 0.5; + float dens_mul = density_multiplier; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 7d56742d6f..bee8e2dab5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -87,7 +87,7 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier * 0.5; + float dens_mul = density_multiplier; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 3d05912f49..fc49562235 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -62,8 +62,8 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier * 0.5; // get back to original pre-EEP range... - float dist_mul = distance_multiplier * 0.1; // get back to original pre-EEP range... + float dens_mul = density_multiplier; + float dist_mul = distance_multiplier * 0.1; //sunlight attenuation effect (hue and brightness) due to atmosphere //this is used later for sunlight modulation at various altitudes @@ -76,7 +76,7 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o haze_weight = vec4(haze_density) / temp1; //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = max(0.0, tmpLightnorm.z); if (temp2.y > 0.001f) { temp2.y = 1. / temp2.y; diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index ea926ab5f1..a8eb7102ed 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -117,7 +117,7 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier * 0.5; + float dens_mul = density_multiplier; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index fcfe5bbba0..64156bd3bf 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -103,7 +103,7 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier * 0.5; + float dens_mul = density_multiplier; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index a253bb72d5..6d6b3dafa7 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -87,7 +87,7 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier * 0.5; + float dens_mul = density_multiplier; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes -- cgit v1.2.3 From 9723bd8be2b710fa089f3404056c01f4dc55e6ac Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 22 Apr 2019 10:54:52 -0700 Subject: SL-10856 Restore light sum loops to fix broken ambient. --- .../shaders/class1/lighting/sumLightsV.glsl | 3 +- .../shaders/class2/lighting/sumLightsV.glsl | 4 +- .../shaders/class3/lighting/lightV.glsl | 37 +++++++++++++++++ .../shaders/class3/lighting/sumLightsV.glsl | 47 ++++++++++------------ 4 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class3/lighting/lightV.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl index 962233345a..9cc74cc219 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl @@ -38,9 +38,10 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) col.a = color.a; col.rgb = light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); - col.rgb += light_diffuse[0].rgb * calcDirectionalLight(norm, light_position[0].xyz); col.rgb = scaleDownLight(col.rgb); col.rgb += atmosAmbient(baseLight.rgb); + col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); + col.rgb = min(col.rgb*color.rgb, 1.0); return col; } diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl index bc7e6dd865..b4f4850646 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl @@ -41,15 +41,13 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) // Collect normal lights (need to be divided by two, as we later multiply by 2) col.rgb += light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); - col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); - col.rgb = scaleDownLight(col.rgb); // Add windlight lights col.rgb += atmosAmbient(baseLight.rgb); - col.rgb += light_diffuse[0].rgb * calcDirectionalLight(norm, light_position[0].xyz)); + col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); col.rgb = min(col.rgb*color.rgb, 1.0); diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl new file mode 100644 index 0000000000..b19f4e96ca --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -0,0 +1,37 @@ +/** + * @file class3\lighting\lightV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + + + +// All lights, no specular highlights + +vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight); +vec3 atmosAmbient(vec3 c); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) +{ + vec4 l = sumLights(pos, norm, color, baseLight); + return l; +} + diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index 21e8263623..097889039d 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -30,7 +30,6 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 scaleDownLight(vec3 light); -vec3 scaleUpLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_direction[8]; @@ -39,30 +38,26 @@ uniform vec3 light_diffuse[8]; vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) { - vec4 col = vec4(0.0, 0.0, 0.0, color.a); - - // Collect normal lights (need to be divided by two, as we later multiply by 2) - - // Collect normal lights - col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); - col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); - col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].z); - col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].z); - col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].z); - col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].z); - col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz); - - - // Add windlight lights - float l = calcDirectionalLight(norm, light_position[0].xyz); - - // using light_diffuse[0] instead of WL func as it is set to the same value for these shaders anyway - // when lights are sync'd - col.rgb += l * light_diffuse[0].rgb; - col.rgb = scaleDownLight(col.rgb); - - col.rgb += atmosAmbient(baseLight.rgb); - col.rgb = min(col.rgb*color.rgb, 1.0); - return col; + vec4 col = vec4(0.0, 0.0, 0.0, color.a); + + // Collect normal lights (need to be divided by two, as we later multiply by 2) + + // Collect normal lights + col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); + col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); + col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].z); + col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].z); + col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].z); + col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].z); + col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_direction[1].xyz); + col.rgb = scaleDownLight(col.grb); + + // Add windlight lights + col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_direction[0].xyz)); + col.rgb += atmosAmbient(baseLight.rgb); + + col.rgb = min(col.rgb*color.rgb, 1.0); + + return col; } -- cgit v1.2.3 From 6ee2fadaa8fd782eccff29777dc93aa508c5bf74 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Apr 2019 10:37:24 -0700 Subject: SL-1491 Modify handling of additive to make extreme range of glow focus/size safe from lens flare artifacts. --- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 4 ++-- .../newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index fc49562235..07190d081e 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -102,9 +102,9 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o //temp2.x is 0 at the sun and increases away from sun temp2.x = max(temp2.x, .001); //was glow.y //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; + temp2.x *= glow.x * 1.8; //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); + temp2.x = pow(temp2.x, glow.z * 0.2); //glow.z should be negative, so we're doing a sort of (1 / "angle") function //add "minimum anti-solar illumination" diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index a93253c981..246dd1a56d 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -54,7 +54,7 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) return light; } light *= atten.r; - light += additive; + light += additive * exp(-32.0f); return light * 2.0; } -- cgit v1.2.3 From 94d4ae298b38630e6d936efc02d7d1a701f0ac1c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Apr 2019 12:52:48 -0700 Subject: SL-10901 part 1 Fix flicker even in no shadow ALM from pow on final_da. Shadow acne at Midday still present. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 4 ++-- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 8d126859c3..6f18244875 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -93,7 +93,7 @@ void main() float final_da = da; final_da = clamp(final_da, 0.0, 1.0); - final_da = pow(final_da, light_gamma); + //final_da = pow(final_da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); @@ -177,7 +177,7 @@ vec3 post_diffuse = col.rgb; bloom = fogged.a; #endif -//col.rgb = post_diffuse; +//col.rgb = vec3(final_da); } frag_color.rgb = col.rgb; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index a1d1287825..f1c06fcc8a 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -106,7 +106,7 @@ void main() float final_da = da; final_da = clamp(final_da, 0.0, 1.0); - final_da = pow(final_da, light_gamma); + //final_da = pow(final_da, light_gamma); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 col; -- cgit v1.2.3 From a685e024a62751289ccfa41c962b039d1de748bd Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Apr 2019 13:12:16 -0700 Subject: SL-10901 Bias shadow sampling and allow control of how dark shadows are (clamped ambient). --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 4 +++- .../shaders/class1/deferred/materialF.glsl | 4 +++- .../shaders/class1/deferred/shadowUtil.glsl | 19 ++++++++++++------- .../shaders/class1/deferred/softenLightF.glsl | 3 ++- .../shaders/class1/windlight/atmosphericsFuncs.glsl | 5 +++++ .../shaders/class2/deferred/softenLightF.glsl | 4 ++-- 6 files changed, 27 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index ab7f779a39..e8400ba66d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -83,6 +83,8 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); #endif +float getAmbientClamp(); + vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance) { //get light vector @@ -209,7 +211,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(0.66, ambient); // keeps shadows dark + ambient = max(getAmbientClamp(), ambient); // keeps shadows dark ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 0819f1b292..f1dbf4af46 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -83,6 +83,8 @@ uniform vec3 light_direction[8]; uniform vec4 light_attenuation[8]; 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) { //get light vector @@ -305,7 +307,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(0.66, ambient); + ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 84032f7ff7..c2cb0eb8c3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -48,15 +48,17 @@ uniform int sun_up_factor; float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { + float offset = shadow_bias * bias_mul; stc.xyz /= stc.w; - stc.z += shadow_bias * bias_mul * 2.0; + stc.z += offset * 4.0; stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; float shadow = cs * 4.0; - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + stc.z += offset * 2.0; + shadow += shadow2D(shadowMap, stc.xyz+vec3( 1.5/shadow_res.x, 0.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3( 0.5/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.5/shadow_res.x, -0.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-0.5/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; return clamp(shadow * 0.125, 0.0, 1.0); } @@ -91,7 +93,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) vec3 offset = light_dir.xyz * (1.0 - dp_directional_light); - shadow_pos += offset * shadow_offset; + shadow_pos += offset * shadow_offset * 2.0; vec4 spos = vec4(shadow_pos.xyz, 1.0); @@ -109,6 +111,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + w = clamp(w, 0.0, 1.0); shadow += pcfShadow(shadowMap3, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); @@ -121,6 +124,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + w = clamp(w, 0.25, 1.0); shadow += pcfShadow(shadowMap2, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } @@ -132,6 +136,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + w = clamp(w, 0.5, 1.0); shadow += pcfShadow(shadowMap1, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } @@ -142,7 +147,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - + w = clamp(w, 0.75, 1.0); shadow += pcfShadow(shadowMap0, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 6f18244875..68deedd0d0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -70,6 +70,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 getNorm(vec2 pos_screen); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +float getAmbientClamp(); void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -111,7 +112,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(0.66, ambient); + ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = final_da * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 07190d081e..09fb3e4c8a 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -42,6 +42,11 @@ uniform mat3 ssao_effect_mat; uniform int no_atmo; uniform float sun_moon_glow_factor; +float getAmbientClamp() +{ + return 0.88f; +} + void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { vec3 P = inPositionEye; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index f1c06fcc8a..dd70790fc3 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -71,7 +71,7 @@ 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); vec4 getPositionWithDepth(vec2 pos_screen, float depth); @@ -124,7 +124,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(0.66, ambient); + ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = scol * final_da * sunlit; -- cgit v1.2.3 From 3c13779e67841147d2cdcb77e73db2ce9b011cc6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Apr 2019 15:12:49 -0700 Subject: SL-10946 Limit influence of refraction scale to avoid pulling in lots of background 'deep blue' pixels never written in the distortion map pass. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index e0af521511..e72b36f28a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -144,13 +144,14 @@ void main() refcol = mix(baseCol*df2, refcol, dweight); //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale * 0.33/max(dmod*df1, 1.0); + vec2 distort2 = distort+wavef.xy*(refScale * 0.01)/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); + //mix with reflection - // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); - + color.rgb = fb.rgb; + color.rgb += refcol.rgb * df1; + vec4 pos = vary_position; vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); -- cgit v1.2.3 From ca16874379bf76dd844d57b2ee59da531d642a8e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 24 Apr 2019 10:33:13 -0700 Subject: SL-11027 Fix incorrect discard on fullbrights w/ alpha mask and cutoff > 1. --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index f8b1ff44c8..f98fc0d518 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -63,7 +63,7 @@ void main() float final_alpha = color.a * vertex_color.a; #ifdef HAS_ALPHA_MASK - if (final_alpha < minimum_alpha) + if (color.a < minimum_alpha) { discard; } -- cgit v1.2.3 From 4ed05fc84fce0fbee76c583e91feed5aff2dbbfc Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 25 Apr 2019 10:59:00 -0700 Subject: Fix dark ALM and strangeness at Mid lighting (class 3 but with a darkness about it). Make a distinct class3/lighting/lightV which boosts to WL levels (* 2.0) and make lighting without WL atmo enabled use class 2 or below. Make forward shaders (alpha and materialF with alpha-blend mode on) more consistent with deferred lighting. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 1 - indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 7 ++++--- .../newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- .../newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/lighting/lightV.glsl | 5 ++--- 5 files changed, 8 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index e8400ba66d..8709053ac6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -201,7 +201,6 @@ void main() float final_da = da; final_da = clamp(final_da, 0.0f, 1.0f); - final_da = pow(final_da, 1.0/1.3); vec4 color = vec4(0,0,0,0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f1dbf4af46..5926236fd7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -302,7 +302,6 @@ void main() float final_da = da; final_da = clamp(final_da, 0.0, 1.0); - final_da = pow(final_da, 1.0 / 1.3); float ambient = da; ambient *= 0.5; @@ -372,6 +371,8 @@ vec3 post_spec = col.rgb; glare += cur_glare; } +vec3 post_env = col.rgb; + col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); @@ -379,7 +380,7 @@ vec3 post_spec = col.rgb; vec3 light = vec3(0,0,0); - vec3 prelight_linearish_maybe = srgb_to_linear(col.rgb); +vec3 post_atmo = col.rgb; #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 * 0.5); @@ -393,7 +394,7 @@ vec3 post_spec = col.rgb; vec3 light_linear = light.rgb; - col.rgb += light.rgb; + col.rgb += light_linear; vec3 postlight_linear = col.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 68deedd0d0..83006c8916 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -108,7 +108,7 @@ void main() vec3 atten; calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten); - sunlit *= 0.5; + float ambient = da; ambient *= 0.5; ambient *= ambient; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index dd70790fc3..2d5d1c1b50 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -120,7 +120,7 @@ void main() vec3 atten; calcAtmosphericVars(pos.xyz, ambocc, sunlit, amblit, additive, atten); - sunlit *= 0.5; + float ambient = da; ambient *= 0.5; ambient *= ambient; diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index b19f4e96ca..efe7f69f21 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -28,10 +28,9 @@ // All lights, no specular highlights vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight); -vec3 atmosAmbient(vec3 c); + vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) { - vec4 l = sumLights(pos, norm, color, baseLight); - return l; + return sumLights(pos, norm, color, baseLight) * 2.0f; } -- cgit v1.2.3 From 5766325290974ee2cfa30fd655060ef396d1e87a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 25 Apr 2019 13:02:24 -0700 Subject: SL-10904, SL-10998, SL-11018 Fix handling of 1/light_y when y was tiny but getting even tinier. Add similar adjustment to shader version of same calc. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 4 +--- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 8709053ac6..300900a9e5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -229,13 +229,11 @@ vec3 post_diffuse = color.rgb; //color.rgb = mix(diff.rgb, color.rgb, final_alpha); - color.rgb = atmosFragLighting(color.rgb, additive, atten); + color.rgb = atmosFragLighting(color.rgb, additive, atten) * 2.0; color.rgb = scaleSoftClipFrag(color.rgb); vec4 light = vec4(0,0,0,0); -vec3 prelight_linearish_maybe = srgb_to_linear(color.rgb); - #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 * 0.5); LIGHT_LOOP(1) diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 09fb3e4c8a..93513acabe 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -81,12 +81,12 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o haze_weight = vec4(haze_density) / temp1; //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.z); - if (temp2.y > 0.001f) + temp2.y = max(0.0, tmpLightnorm.y); + if (abs(temp2.y) > 0.000001f) { - temp2.y = 1. / temp2.y; + temp2.y = 1. / abs(temp2.y); } - temp2.y = max(0.001f, temp2.y); + temp2.y = max(0.0000001f, temp2.y); sunlight *= exp(-light_atten * temp2.y); // main atmospheric scattering line integral -- cgit v1.2.3 From dbb72176e8086b9a92e301c689e63c16dc704a98 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 25 Apr 2019 14:29:05 -0700 Subject: SL-11051 Fix alpha tests in alpha mask shadow shader to not include potentially incorrect vert color alpha in decision. --- .../app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index 1791d3e315..dd762958c4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -45,7 +45,7 @@ VARYING vec2 vary_texcoord0; void main() { - float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; + float alpha = diffuseLookup(vary_texcoord0.xy).a; if (alpha < 0.05) // treat as totally transparent { @@ -60,6 +60,8 @@ void main() } } + alpha *= vertex_color.a; + frag_color = vec4(1,1,1,1); #if !defined(DEPTH_CLAMP) -- cgit v1.2.3 From 948deb56d9aa11d61bba76a1e79040e8db0baf49 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 26 Apr 2019 07:59:20 -0700 Subject: Add projector light within da gtz test. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 3 +-- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 +-- .../newview/app_settings/shaders/class1/environment/terrainWaterF.glsl | 2 +- indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl | 2 +- indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl | 2 +- indra/newview/app_settings/shaders/class1/environment/waterV.glsl | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 300900a9e5..a63b9dec75 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -117,11 +117,10 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec // to match spotLight (but not multiSpotLight) *sigh* float lit = max(da * dist_atten,0.0); - col = lit * light_col * diffuse; - float amb_da = ambiance; if (da > 0) { + col = lit * light_col * diffuse; amb_da += (da*0.5+0.5) * ambiance; } amb_da += (da*da*0.5 + 0.5) * ambiance; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 5926236fd7..b3d9b1e9c5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -120,11 +120,10 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float lit = max(da * dist_atten, 0.0); - col = light_col*lit*diffuse; - float amb_da = ambiance; if (da > 0) { + col = light_col*lit*diffuse; amb_da += (da*0.5 + 0.5) * ambiance; } amb_da += (da*da*0.5+0.5) * ambiance; diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl index a956562396..3b0c81fc71 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl @@ -1,5 +1,5 @@ /** - * @file terrainWaterF.glsl + * @file class1\environment\terrainWaterF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl index 20280ab1c5..8c8bd6d0d5 100644 --- a/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl @@ -1,5 +1,5 @@ /** - * @file underWaterF.glsl + * @file class1\environment\underWaterF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl index 856924b1e5..df640cba05 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl @@ -1,5 +1,5 @@ /** - * @file waterFogF.glsl + * @file class1\environment\waterFogF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl index 1fe98a9575..cc41e3f740 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl @@ -1,5 +1,5 @@ /** - * @file waterV.glsl + * @file class1\environment\waterV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code -- cgit v1.2.3 From ca2f3dfd662bc70a187604b3cd638c97e0507843 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 26 Apr 2019 08:01:36 -0700 Subject: Make terrain shader decide to include atmo effects or not based on whether we're underwater or not. --- indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 9829842a0f..b49d86b2a2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -61,12 +61,14 @@ void main() float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); - + + outColor.a = 0.0; // yes, downstream atmospherics #ifdef WATER_FOG outColor = applyWaterFogView(pos.xyz, outColor); + outColor.a = 1.0; // no downstream atmo #endif - - frag_data[0] = vec4(outColor.rgb, 0.0); + + frag_data[0] = outColor; frag_data[1] = vec4(0.0,0.0,0.0,0.0); vec3 nvn = normalize(vary_normal); frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); -- cgit v1.2.3 From b5ba56c863184538bf45e99df81dd0b0aa5209b4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 26 Apr 2019 08:03:17 -0700 Subject: Make alpha projectors do projector clip test for consistency with deferred spot behavior. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index a63b9dec75..f49f274de0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -58,6 +58,7 @@ VARYING vec3 vary_norm; VARYING vec4 vertex_color; #endif +uniform mat4 proj_mat; uniform mat4 inv_proj; uniform vec2 screen_res; uniform int sun_up_factor; @@ -89,11 +90,22 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec { //get light vector vec3 lv = lp.xyz-v; - + + vec4 proj_tc = proj_mat * lp; + //get distance float d = length(lv); float da = 1.0; vec3 col = vec3(0); + if (proj_tc.z < 0 + || proj_tc.x < 0 + || proj_tc.z > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + } + if (d > 0.0) { //normalize light vector -- cgit v1.2.3 From 250c8474914290aea0bb8edb8c3754ddd4a26f3e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 26 Apr 2019 09:34:33 -0700 Subject: SL-11041 Put ambient clamp threshold back for lighter shadows but closer match to release lighting. --- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 93513acabe..cd1e2d6e32 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -44,7 +44,7 @@ uniform float sun_moon_glow_factor; float getAmbientClamp() { - return 0.88f; + return 0.66f; } void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { -- cgit v1.2.3 From 9d314074c9e3c898436321bdb90d3bf0d10c0079 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 26 Apr 2019 10:36:44 -0700 Subject: SL-11055 Remove shader change to reduce additive to combat SL1491 as it also kills additive from foggy settings. Zero out all cached hardware light colors causing uninit fun with class3 lighting. --- indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 246dd1a56d..94e776d51d 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -54,7 +54,7 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) return light; } light *= atten.r; - light += additive * exp(-32.0f); + light += additive * exp(-1.0f); return light * 2.0; } -- cgit v1.2.3 From f133be068a4aa23c02c47348f5c7d4a28e1d5c37 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 26 Apr 2019 16:02:21 -0700 Subject: Lighting WIP Consistency across class2/3/ALM lighting. --- .../app_settings/shaders/class1/avatar/avatarV.glsl | 4 ++-- .../shaders/class1/avatar/eyeballV.glsl | 4 ++-- .../shaders/class1/deferred/alphaF.glsl | 8 ++++++-- .../class1/deferred/avatarAlphaNoColorV.glsl | 5 ++--- .../shaders/class1/deferred/emissiveV.glsl | 2 +- .../shaders/class1/deferred/fullbrightV.glsl | 2 +- .../shaders/class1/deferred/materialF.glsl | 18 ++++++++++++++++-- .../shaders/class1/deferred/softenLightF.glsl | 10 ++++++---- .../shaders/class1/environment/terrainV.glsl | 5 +++-- .../shaders/class1/lighting/lightSpecularV.glsl | 6 +++--- .../shaders/class1/lighting/lightV.glsl | 10 ++++++---- .../shaders/class1/lighting/sumLightsSpecularV.glsl | 8 ++++---- .../shaders/class1/lighting/sumLightsV.glsl | 6 ++---- .../shaders/class1/objects/shinySimpleSkinnedV.glsl | 4 ++-- .../app_settings/shaders/class1/objects/shinyV.glsl | 4 ++-- .../shaders/class1/objects/simpleNoColorV.glsl | 4 ++-- .../shaders/class1/objects/simpleNonIndexedV.glsl | 4 ++-- .../shaders/class1/objects/simpleSkinnedV.glsl | 4 ++-- .../shaders/class1/objects/simpleTexGenV.glsl | 4 ++-- .../shaders/class1/objects/simpleV.glsl | 4 ++-- .../app_settings/shaders/class1/objects/treeV.glsl | 5 +++-- .../class1/windlight/atmosphericsHelpersF.glsl | 6 +++--- .../class1/windlight/atmosphericsHelpersV.glsl | 6 +++--- .../shaders/class2/avatar/eyeballV.glsl | 4 ++-- .../shaders/class2/deferred/multiSpotLightF.glsl | 21 ++++++--------------- .../shaders/class2/deferred/softenLightF.glsl | 14 ++++++++------ .../shaders/class2/deferred/spotLightF.glsl | 11 ++++------- .../shaders/class2/lighting/sumLightsSpecularV.glsl | 8 ++++---- .../shaders/class2/lighting/sumLightsV.glsl | 6 +----- .../class2/windlight/atmosphericsHelpersV.glsl | 6 +++--- .../shaders/class2/windlight/atmosphericsVarsF.glsl | 3 +++ .../shaders/class2/windlight/transportF.glsl | 4 ++-- .../app_settings/shaders/class3/avatar/avatarV.glsl | 4 ++-- .../shaders/class3/lighting/lightV.glsl | 10 ++++++---- .../shaders/class3/lighting/sumLightsSpecularV.glsl | 8 ++++---- .../shaders/class3/lighting/sumLightsV.glsl | 13 +++++-------- 36 files changed, 127 insertions(+), 118 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/avatar/avatarV.glsl b/indra/newview/app_settings/shaders/class1/avatar/avatarV.glsl index 19203ab670..0543a26642 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/avatarV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/avatarV.glsl @@ -34,7 +34,7 @@ VARYING vec2 vary_texcoord0; uniform vec4 color; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); mat4 getSkinnedTransform(); void calcAtmospherics(vec3 inPositionEye); @@ -62,7 +62,7 @@ void main() calcAtmospherics(pos.xyz); - vec4 col = calcLighting(pos.xyz, norm, color, vec4(0,0,0,0)); + vec4 col = calcLighting(pos.xyz, norm, color); vertex_color = col; } diff --git a/indra/newview/app_settings/shaders/class1/avatar/eyeballV.glsl b/indra/newview/app_settings/shaders/class1/avatar/eyeballV.glsl index 82db15c3ae..fac1599c6b 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/eyeballV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/eyeballV.glsl @@ -36,7 +36,7 @@ ATTRIBUTE vec2 texcoord0; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol); +vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor); void calcAtmospherics(vec3 inPositionEye); void main() @@ -52,7 +52,7 @@ void main() calcAtmospherics(pos.xyz); vec4 specular = vec4(1.0); - vec4 color = calcLightingSpecular(pos, norm, diffuse_color, specular, vec4(0.0)); + vec4 color = calcLightingSpecular(pos, norm, diffuse_color, specular); vertex_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index f49f274de0..d11b81d2d3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -194,6 +194,8 @@ void main() float final_alpha = diff.a; #endif + vec3 gamma_diff = diff.rgb; + diff.rgb = srgb_to_linear(diff.rgb); vec3 sunlit; @@ -239,10 +241,12 @@ vec3 post_sunlight = color.rgb; vec3 post_diffuse = color.rgb; //color.rgb = mix(diff.rgb, color.rgb, final_alpha); - - color.rgb = atmosFragLighting(color.rgb, additive, atten) * 2.0; + + color.rgb = atmosFragLighting(color.rgb, additive, atten); color.rgb = scaleSoftClipFrag(color.rgb); + //color.rgb = srgb_to_linear(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 * 0.5); diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl index e68b082d43..e4d96a0028 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl @@ -29,13 +29,12 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); mat4 getSkinnedTransform(); void calcAtmospherics(vec3 inPositionEye); float calcDirectionalLight(vec3 n, vec3 l); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient(); vec3 atmosAffectDirectionalLight(float lightIntensity); VARYING vec3 vary_position; @@ -128,7 +127,7 @@ void main() col.rgb = vec3(0,0,0); // Add windlight lights - col.rgb = atmosAmbient(vec3(0.)); + col.rgb = atmosAmbient(); vary_ambient = col.rgb*color.rgb; vary_directional = color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, light_position[0].xyz), 0.0)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl b/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl index 7fec3e03e7..5e4f08b017 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl @@ -34,7 +34,7 @@ ATTRIBUTE vec2 texcoord0; void calcAtmospherics(vec3 inPositionEye); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient(); vec3 atmosAffectDirectionalLight(float lightIntensity); VARYING vec4 vertex_color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl index 816bd0bf3e..bdf3546aa5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -35,7 +35,7 @@ ATTRIBUTE vec2 texcoord0; void calcAtmospherics(vec3 inPositionEye); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient(); vec3 atmosAffectDirectionalLight(float lightIntensity); #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 b3d9b1e9c5..f21b7644bb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -75,6 +75,7 @@ VARYING vec2 vary_fragcoord; VARYING vec3 vary_position; +uniform mat4 proj_mat; uniform mat4 inv_proj; uniform vec2 screen_res; @@ -97,6 +98,17 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe vec3 col = vec3(0,0,0); + vec4 proj_tc = proj_mat * lp; + + if (proj_tc.z < 0 + || proj_tc.x < 0 + || proj_tc.z > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + } + if (d > 0.0) { //normalize light vector @@ -381,6 +393,8 @@ vec3 post_env = col.rgb; vec3 post_atmo = col.rgb; + //col.rgb = srgb_to_linear(col.rgb); + #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 * 0.5); LIGHT_LOOP(1) @@ -393,7 +407,7 @@ vec3 post_atmo = col.rgb; vec3 light_linear = light.rgb; - col.rgb += light_linear; + col.rgb += light_linear; vec3 postlight_linear = col.rgb; @@ -406,7 +420,7 @@ vec3 postlight_linear = col.rgb; al = temp.a; #endif -//col.rgb = light_linear; +//col.rgb = post_atmo; col.rgb = linear_to_srgb(col.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 83006c8916..e0fe6cfae1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -74,6 +74,8 @@ float getAmbientClamp(); void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec3 scaleSoftClipFrag(vec3 l); +vec3 srgb_to_linear(vec3 c); +vec3 linear_to_srgb(vec3 c); vec4 getPositionWithDepth(vec2 pos_screen, float depth); @@ -96,7 +98,9 @@ void main() final_da = clamp(final_da, 0.0, 1.0); //final_da = pow(final_da, light_gamma); - vec4 diffuse = texture2DRect(diffuseRect, tc); + vec4 gamma_diff = texture2DRect(diffuseRect, tc); + vec4 diffuse = gamma_diff; + diffuse.rgb = srgb_to_linear(gamma_diff.rgb); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 col; @@ -126,7 +130,7 @@ vec3 post_ambient = col.rgb; vec3 post_sunlight = col.rgb; - col.rgb *= diffuse.rgb; + col.rgb *= gamma_diff.rgb; vec3 post_diffuse = col.rgb; @@ -177,8 +181,6 @@ vec3 post_diffuse = col.rgb; col = fogged.rgb; bloom = fogged.a; #endif - -//col.rgb = vec3(final_da); } frag_color.rgb = col.rgb; diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl index 5dcdbfaa50..ef27848d37 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl @@ -35,6 +35,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; ATTRIBUTE vec2 texcoord1; +ATTRIBUTE vec4 diffuse_color; VARYING vec4 vertex_color; VARYING vec4 vary_texcoord0; @@ -42,7 +43,7 @@ VARYING vec4 vary_texcoord1; void calcAtmospherics(vec3 inPositionEye); -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); vec4 texgen_object(vec4 vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1) { @@ -71,7 +72,7 @@ void main() /// Potentially better without it for water. pos /= pos.w; - vec4 color = calcLighting(pos.xyz, norm, vec4(1), vec4(0)); + vec4 color = calcLighting(pos.xyz, norm, /*diffuse_color*/vec4(1)); vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl index 0b36229d4d..06aed40e26 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightSpecularV.glsl @@ -27,10 +27,10 @@ // All lights, no specular highlights -vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol); +vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor); -vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) +vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor) { - return sumLightsSpecular(pos, norm, color, specularColor, baseCol); + return sumLightsSpecular(pos, norm, color, specularColor); } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl index 9757070a82..2d41776ee2 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl @@ -26,11 +26,13 @@ // All lights, no specular highlights +vec3 atmosAmbient(); +vec4 sumLights(vec3 pos, vec3 norm, vec4 color); -vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight); - -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { - return sumLights(pos, norm, color, baseLight); + vec4 c = sumLights(pos, norm, color); + c.rgb += atmosAmbient() * color.rgb; + return c; } diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl index 9863f92e63..7c3697c333 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl @@ -26,7 +26,7 @@ float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient(); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 atmosGetDiffuseSunlightColor(); vec3 scaleDownLight(vec3 light); @@ -34,7 +34,7 @@ vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; uniform vec3 light_diffuse[8]; -vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) +vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor) { vec4 col = vec4(0,0,0, color.a); @@ -45,8 +45,8 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor col.rgb += light_diffuse[1].rgb * calcDirectionalLightSpecular(specularColor, view, norm, light_position[1].xyz,light_diffuse[1].rgb, 1.0); col.rgb = scaleDownLight(col.rgb); - col.rgb += atmosAmbient(baseCol.rgb); - col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz,atmosGetDiffuseSunlightColor()*baseCol.a, 1.0)); + col.rgb += atmosAmbient(); + col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz, atmosGetDiffuseSunlightColor(), 1.0)); col.rgb = min(col.rgb * color.rgb, 1.0); specularColor.rgb = min(specularColor.rgb * specularSum.rgb, 1.0); diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl index 9cc74cc219..761ac29ee2 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl @@ -28,20 +28,18 @@ uniform vec3 light_diffuse[8]; float calcDirectionalLight(vec3 n, vec3 l); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient(); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 scaleDownLight(vec3 light); -vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) +vec4 sumLights(vec3 pos, vec3 norm, vec4 color) { vec4 col = vec4(0); col.a = color.a; col.rgb = light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); col.rgb = scaleDownLight(col.rgb); - col.rgb += atmosAmbient(baseLight.rgb); col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); - col.rgb = min(col.rgb*color.rgb, 1.0); return col; } diff --git a/indra/newview/app_settings/shaders/class1/objects/shinySimpleSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/shinySimpleSkinnedV.glsl index 591d6fc5c9..727bae19c0 100644 --- a/indra/newview/app_settings/shaders/class1/objects/shinySimpleSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/shinySimpleSkinnedV.glsl @@ -36,7 +36,7 @@ VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; VARYING vec3 vary_texcoord1; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); void calcAtmospherics(vec3 inPositionEye); mat4 getObjectSkinnedTransform(); @@ -59,7 +59,7 @@ void main() calcAtmospherics(pos.xyz); - vec4 color = calcLighting(pos.xyz, norm.xyz, diffuse_color, vec4(0.)); + vec4 color = calcLighting(pos.xyz, norm.xyz, diffuse_color); vertex_color = color; gl_Position = projection_matrix*vec4(pos, 1.0); diff --git a/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl b/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl index fdb3453cc5..4ba8194d03 100644 --- a/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl @@ -39,7 +39,7 @@ VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; VARYING vec3 vary_texcoord1; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); void calcAtmospherics(vec3 inPositionEye); @@ -61,5 +61,5 @@ void main() calcAtmospherics(pos.xyz); - vertex_color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.0)); + vertex_color = calcLighting(pos.xyz, norm, diffuse_color); } diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleNoColorV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleNoColorV.glsl index 0be52a52af..22821a2f76 100644 --- a/indra/newview/app_settings/shaders/class1/objects/simpleNoColorV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/simpleNoColorV.glsl @@ -38,7 +38,7 @@ VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); void calcAtmospherics(vec3 inPositionEye); void main() @@ -52,7 +52,7 @@ void main() calcAtmospherics(pos.xyz); - vec4 col = calcLighting(pos.xyz, norm, color, vec4(0.)); + vec4 col = calcLighting(pos.xyz, norm, color); vertex_color = col; diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleNonIndexedV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleNonIndexedV.glsl index cb80697d15..e605676819 100644 --- a/indra/newview/app_settings/shaders/class1/objects/simpleNonIndexedV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/simpleNonIndexedV.glsl @@ -37,7 +37,7 @@ VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); void calcAtmospherics(vec3 inPositionEye); void main() @@ -54,7 +54,7 @@ void main() calcAtmospherics(pos.xyz); - vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); + vec4 color = calcLighting(pos.xyz, norm, diffuse_color); vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleSkinnedV.glsl index 1c6e53b187..df31b5a79f 100644 --- a/indra/newview/app_settings/shaders/class1/objects/simpleSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/simpleSkinnedV.glsl @@ -35,7 +35,7 @@ VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); void calcAtmospherics(vec3 inPositionEye); mat4 getObjectSkinnedTransform(); @@ -56,7 +56,7 @@ void main() calcAtmospherics(pos.xyz); - vec4 color = calcLighting(pos.xyz, norm.xyz, diffuse_color, vec4(0.)); + vec4 color = calcLighting(pos.xyz, norm.xyz, diffuse_color); vertex_color = color; gl_Position = projection_matrix*vec4(pos, 1.0); diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleTexGenV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleTexGenV.glsl index d4dee78793..945f80f31e 100644 --- a/indra/newview/app_settings/shaders/class1/objects/simpleTexGenV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/simpleTexGenV.glsl @@ -37,7 +37,7 @@ uniform vec4 color; uniform vec4 object_plane_t; uniform vec4 object_plane_s; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); void calcAtmospherics(vec3 inPositionEye); VARYING vec4 vertex_color; @@ -70,7 +70,7 @@ void main() calcAtmospherics(pos.xyz); - vec4 color = calcLighting(pos.xyz, norm, color, vec4(0.)); + vec4 color = calcLighting(pos.xyz, norm, color); vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleV.glsl index 37a20383e2..a59bd9c0a6 100644 --- a/indra/newview/app_settings/shaders/class1/objects/simpleV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/simpleV.glsl @@ -34,7 +34,7 @@ ATTRIBUTE vec2 texcoord0; ATTRIBUTE vec3 normal; ATTRIBUTE vec4 diffuse_color; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); void calcAtmospherics(vec3 inPositionEye); @@ -57,7 +57,7 @@ void main() calcAtmospherics(pos.xyz); - vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); + vec4 color = calcLighting(pos.xyz, norm, diffuse_color); vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class1/objects/treeV.glsl b/indra/newview/app_settings/shaders/class1/objects/treeV.glsl index fa01a27ec0..179d3c42a4 100644 --- a/indra/newview/app_settings/shaders/class1/objects/treeV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/treeV.glsl @@ -31,8 +31,9 @@ uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; ATTRIBUTE vec2 texcoord0; ATTRIBUTE vec3 normal; +ATTRIBUTE vec4 diffuse_color; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); void calcAtmospherics(vec3 inPositionEye); VARYING vec4 vertex_color; @@ -53,7 +54,7 @@ void main() calcAtmospherics(pos.xyz); - vec4 color = calcLighting(pos.xyz, norm, vec4(1,1,1,1), vec4(0.)); + vec4 color = calcLighting(pos.xyz, norm, diffuse_color); vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl index 06f13b11f2..206a51db27 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersF.glsl @@ -27,10 +27,10 @@ uniform vec4 sunlight_color; uniform vec4 light_ambient; uniform int no_atmo; -vec3 atmosAmbient(vec3 light) +vec3 atmosAmbient() { - if (no_atmo == 1) return light + vec3(0.66); - return light + light_ambient.rgb; + if (no_atmo == 1) return vec3(0.16); + return light_ambient.rgb; } vec3 atmosAffectDirectionalLight(float lightIntensity) diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl index c24df9eaeb..c266f9732f 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsHelpersV.glsl @@ -27,10 +27,10 @@ uniform vec4 sunlight_color; uniform vec4 light_ambient; uniform int no_atmo; -vec3 atmosAmbient(vec3 light) +vec3 atmosAmbient() { - if (no_atmo == 1) return light + vec3(0.66); - return light + light_ambient.rgb; + if (no_atmo == 1) return vec3(0.66); + return light_ambient.rgb; } vec3 atmosAffectDirectionalLight(float lightIntensity) diff --git a/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl b/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl index 5af9f5c902..563c5f562b 100644 --- a/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl +++ b/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl @@ -37,7 +37,7 @@ VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol); +vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor); void calcAtmospherics(vec3 inPositionEye); void main() @@ -53,7 +53,7 @@ void main() // vec4 specular = specularColor; vec4 specular = vec4(1.0); - vec4 color = calcLightingSpecular(pos, norm, diffuse_color, specular, vec4(0.0)); + vec4 color = calcLightingSpecular(pos, norm, diffuse_color, specular); vertex_color = color; diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 7ccc91f73c..a82d738ec2 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -71,15 +71,8 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 srgb_to_linear(vec3 cs); - vec3 getNorm(vec2 pos_screen); - -vec4 correctWithGamma(vec4 col) -{ - return vec4(srgb_to_linear(col.rgb), col.a); -} - +vec3 scaleDownLight(vec3 light); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); @@ -220,14 +213,14 @@ void main() col = dlit*lit*diff_tex*shadow; // unshadowed for consistency between forward and deferred? - amb_da += (da*0.5+0.5)/* *(1.0-shadow) */ *proj_ambiance; + amb_da += (da*0.5+0.5) * (1.0-shadow) * proj_ambiance; } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - // unshadowed for consistency between forward and deferred? - amb_da += (da*da*0.5+0.5) /* *(1.0-shadow) */ * proj_ambiance; + // use unshadowed for consistency between forward and deferred? + amb_da += (da*da*0.5+0.5) * (1.0-shadow) * proj_ambiance; amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); @@ -259,10 +252,6 @@ void main() col += speccol; } } - - - - if (envIntensity > 0.0) { @@ -296,6 +285,8 @@ 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 2d5d1c1b50..06a76668ba 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -73,6 +73,8 @@ 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); @@ -99,14 +101,14 @@ void main() float da = dot(normalize(norm.xyz), light_dir.xyz); da = clamp(da, -1.0, 1.0); - vec4 diffuse = texture2DRect(diffuseRect, tc); - + vec4 gamma_diff = texture2DRect(diffuseRect, tc); + vec4 diffuse = gamma_diff; + diffuse.rgb = srgb_to_linear(diffuse.rgb); + scol = max(scol_ambocc.r, diffuse.a); - //scol = pow(scol, light_gamma); float final_da = da; final_da = clamp(final_da, 0.0, 1.0); - //final_da = pow(final_da, light_gamma); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 col; @@ -138,7 +140,7 @@ vec3 post_ambient = col.rgb; vec3 post_sunlight = col.rgb; - col.rgb *= diffuse.rgb; + col.rgb *= gamma_diff.rgb; vec3 post_diffuse = col.rgb; @@ -169,7 +171,7 @@ vec3 post_diffuse = col.rgb; } } - col.rgb += diffuse.a * diffuse.rgb; + col.rgb += diffuse.a * gamma_diff.rgb; if (envIntensity > 0.0) { //add environmentmap diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 2844cc8574..cd3b33eecc 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -71,13 +71,8 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 srgb_to_linear(vec3 cs); vec3 getNorm(vec2 pos_screen); - -vec4 correctWithGamma(vec4 col) -{ - return vec4(srgb_to_linear(col.rgb), col.a); -} +vec3 scaleDownLight(vec3 c); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { @@ -218,7 +213,7 @@ void main() col = dlit*lit*diff_tex*shadow; - amb_da += (da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; + amb_da += (da*0.5+0.5) * (1.0-shadow) * proj_ambiance; } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); @@ -293,6 +288,8 @@ 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/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl index 6fcc41cd6d..89d9d1bde3 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl @@ -28,7 +28,7 @@ float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da); vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient(); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 atmosGetDiffuseSunlightColor(); vec3 scaleDownLight(vec3 light); @@ -37,7 +37,7 @@ uniform vec4 light_position[8]; uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; -vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) +vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor) { vec4 col = vec4(0.0, 0.0, 0.0, color.a); @@ -53,8 +53,8 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor col.rgb = scaleDownLight(col.rgb); // Add windlight lights - col.rgb += atmosAmbient(baseCol.rgb); - col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz,atmosGetDiffuseSunlightColor()*baseCol.a, 1.0)); + col.rgb += atmosAmbient(); + col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz, atmosGetDiffuseSunlightColor(), 1.0)); col.rgb = min(col.rgb*color.rgb, 1.0); specularColor.rgb = min(specularColor.rgb*specularSum.rgb, 1.0); diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl index b4f4850646..57f93a8b36 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl @@ -26,7 +26,6 @@ float calcDirectionalLight(vec3 n, vec3 l); float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight); -vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 scaleDownLight(vec3 light); @@ -35,7 +34,7 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) +vec4 sumLights(vec3 pos, vec3 norm, vec4 color) { vec4 col = vec4(0.0, 0.0, 0.0, color.a); @@ -46,11 +45,8 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) col.rgb = scaleDownLight(col.rgb); // Add windlight lights - col.rgb += atmosAmbient(baseLight.rgb); col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); - col.rgb = min(col.rgb*color.rgb, 1.0); - return col; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl index c80706d2a7..9f049cb8fb 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl @@ -35,10 +35,10 @@ vec3 getPositionEye(); uniform float scene_light_strength; uniform int no_atmo; -vec3 atmosAmbient(vec3 light) +vec3 atmosAmbient() { - if (no_atmo == 1) return light + vec3(0.66); - return getAmblitColor() + light / 2.0; + if (no_atmo == 1) return vec3(0.66); + return getAmblitColor(); } vec3 atmosAffectDirectionalLight(float lightIntensity) diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl index 9953f79cf2..ea37610502 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl @@ -32,14 +32,17 @@ vec3 getSunlitColor() { return vec3(0,0,0); } + vec3 getAmblitColor() { return vec3(0,0,0); } + vec3 getAdditiveColor() { return vary_AdditiveColor; } + vec3 getAtmosAttenuation() { return vec3(vary_AtmosAttenuation); diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 2e8946252b..9cb9c723a2 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -39,8 +39,8 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) return light; } light *= atten.r; - light += additive * 2.0; - return light; + light += additive; + return light * 2.0; } vec3 atmosTransport(vec3 light) diff --git a/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl b/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl index 721054b5ad..df9704ec25 100644 --- a/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl +++ b/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl @@ -33,7 +33,7 @@ ATTRIBUTE vec4 clothing; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); mat4 getSkinnedTransform(); void calcAtmospherics(vec3 inPositionEye); @@ -127,7 +127,7 @@ void main() calcAtmospherics(pos.xyz); - vec4 col = calcLighting(pos.xyz, norm, color, vec4(0.0)); + vec4 col = calcLighting(pos.xyz, norm, color); vertex_color = col; gl_Position = projection_matrix * pos; diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index efe7f69f21..372992fab2 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -26,11 +26,13 @@ // All lights, no specular highlights +vec3 atmosAmbient(); +vec4 sumLights(vec3 pos, vec3 norm, vec4 color); -vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight); - -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { - return sumLights(pos, norm, color, baseLight) * 2.0f; + vec4 c = sumLights(pos, norm, color * 2.0); + c.rgb += atmosAmbient() * color.rgb * 0.5; + return c; } diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl index 6d4192ab13..c1aee69c30 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl @@ -26,7 +26,7 @@ float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da); vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol); -vec3 atmosAmbient(vec3 light); +vec3 atmosAmbient(); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 atmosGetDiffuseSunlightColor(); vec3 scaleDownLight(vec3 light); @@ -35,7 +35,7 @@ uniform vec4 light_position[8]; uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; -vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) +vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor) { vec4 col = vec4(0.0, 0.0, 0.0, color.a); @@ -55,8 +55,8 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor col.rgb = scaleDownLight(col.rgb); // Add windlight lights - col.rgb += atmosAmbient(baseCol.rgb); - col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz,atmosGetDiffuseSunlightColor()*baseCol.a, 1.0)); + col.rgb += atmosAmbient(); + col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz,atmosGetDiffuseSunlightColor(), 1.0)); col.rgb = min(col.rgb*color.rgb, 1.0); specularColor.rgb = min(specularColor.rgb*specularSum.rgb, 1.0); diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index 097889039d..81da6688c2 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -1,5 +1,5 @@ /** - * @file class3\lighing\sumLightsV.glsl + * @file class3\lighting\sumLightsV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -27,7 +27,6 @@ float calcDirectionalLight(vec3 n, vec3 l); float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight); -vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 scaleDownLight(vec3 light); @@ -36,7 +35,7 @@ uniform vec3 light_direction[8]; uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; -vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) +vec4 sumLights(vec3 pos, vec3 norm, vec4 color) { vec4 col = vec4(0.0, 0.0, 0.0, color.a); @@ -49,13 +48,11 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].z); col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].z); col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].z); - col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_direction[1].xyz); - col.rgb = scaleDownLight(col.grb); + col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz); + col.rgb = scaleDownLight(col.rgb); // Add windlight lights - col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_direction[0].xyz)); - col.rgb += atmosAmbient(baseLight.rgb); - + col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); col.rgb = min(col.rgb*color.rgb, 1.0); return col; -- cgit v1.2.3 From eff7acfb1caaa092a88555fca752dc9aea11625e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 29 Apr 2019 08:53:09 -0700 Subject: Remove hack mul of sunlight in alpha shader and add some taps for debugging the lighting pipe. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 7 ++++--- .../newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index d11b81d2d3..11fcb3e87a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -204,7 +204,6 @@ void main() vec3 atten; calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten); - sunlit *= 0.5; vec2 abnormal = encode_normal(norm.xyz); @@ -240,12 +239,14 @@ vec3 post_sunlight = color.rgb; vec3 post_diffuse = color.rgb; - //color.rgb = mix(diff.rgb, color.rgb, final_alpha); + color.rgb = mix(diff.rgb, color.rgb, final_alpha); + + //color.rgb = srgb_to_linear(color.rgb); color.rgb = atmosFragLighting(color.rgb, additive, atten); color.rgb = scaleSoftClipFrag(color.rgb); - //color.rgb = srgb_to_linear(color.rgb); +vec3 post_atmo = color.rgb; vec4 light = vec4(0,0,0,0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index e0fe6cfae1..afdd8cdda3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -160,7 +160,9 @@ vec3 post_diffuse = col.rgb; col += speccol; } } - + + vec3 post_spec = col.rgb; + col.rgb += diffuse.a * diffuse.rgb; if (envIntensity > 0.0) @@ -176,6 +178,8 @@ vec3 post_diffuse = col.rgb; col = scaleSoftClipFrag(col); } +vec3 post_atmo = col.rgb; + #ifdef WATER_FOG vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); col = fogged.rgb; -- cgit v1.2.3 From 0f83696585b8810c24d535432716215caf0c21e9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 29 Apr 2019 11:11:05 -0700 Subject: SL-10956, SL-10969 Don't ignore far z in culling. Fix Mid lighting being very dark. Partial fix for broken projectors with forward rendering. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 15 +++++---------- .../shaders/class1/deferred/materialF.glsl | 18 +++++++++++------- .../shaders/class2/deferred/multiSpotLightF.glsl | 3 +++ .../shaders/class2/deferred/spotLightF.glsl | 6 ++++-- .../app_settings/shaders/class3/lighting/lightV.glsl | 6 +++--- 5 files changed, 26 insertions(+), 22 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 11fcb3e87a..1acb76bdd1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -98,8 +98,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec float da = 1.0; vec3 col = vec3(0); if (proj_tc.z < 0 - || proj_tc.x < 0 || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 || proj_tc.y < 0 || proj_tc.y > 1) { @@ -139,7 +140,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); +#ifndef NO_AMBIANCE col.rgb += amb_da * 0.5 * light_col * diffuse; +#endif // no spec for alpha shader... } @@ -260,17 +263,9 @@ vec3 post_atmo = color.rgb; LIGHT_LOOP(6) LIGHT_LOOP(7) -vec3 light_linear = light.rgb; + color.rgb = linear_to_srgb(color.rgb); - // keep it linear - // color.rgb += light.rgb; - -vec3 postlight_linear = color.rgb; - -//color.rgb = light_linear; - - 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 f21b7644bb..cbb7a04631 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -101,8 +101,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe vec4 proj_tc = proj_mat * lp; if (proj_tc.z < 0 - || proj_tc.x < 0 || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 || proj_tc.y < 0 || proj_tc.y > 1) { @@ -119,7 +120,11 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe fa += 1.0f; float dist_atten = ( fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; dist_atten *= dist_atten; - dist_atten *= 2.0f; + + if (dist_atten <= 0) + { + return col; + } // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); @@ -141,7 +146,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe amb_da += (da*da*0.5+0.5) * ambiance; amb_da = min(amb_da, 1.0f - lit); +#ifndef NO_AMBIANCE col.rgb += amb_da * 0.5 * light_col * diffuse; +#endif if (spec.a > 0.0) { @@ -172,7 +179,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe } return max(col, vec3(0.0,0.0,0.0)); - } #else @@ -405,10 +411,6 @@ vec3 post_atmo = col.rgb; LIGHT_LOOP(6) LIGHT_LOOP(7) -vec3 light_linear = light.rgb; - - col.rgb += light_linear; - vec3 postlight_linear = col.rgb; glare = min(glare, 1.0); @@ -424,6 +426,8 @@ vec3 postlight_linear = col.rgb; col.rgb = linear_to_srgb(col.rgb); + col.rgb += light.rgb; + frag_color.rgb = col.rgb; frag_color.a = al; diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index a82d738ec2..9cd5592d7c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -224,7 +224,10 @@ 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 + } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index cd3b33eecc..957ce579c0 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -222,8 +222,10 @@ void main() amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); - - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; + +#ifndef NO_AMBIANCE + col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; +#endif } diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index 372992fab2..1ac0ad8948 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -31,8 +31,8 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { - vec4 c = sumLights(pos, norm, color * 2.0); - c.rgb += atmosAmbient() * color.rgb * 0.5; - return c; + vec4 c = sumLights(pos, norm, color); + c.rgb += atmosAmbient() * color.rgb; + return c * 2.0; } -- cgit v1.2.3 From bfce96d684d5d056061ce16a36daba9a2bd0aa9d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 30 Apr 2019 10:04:20 -0700 Subject: SL-10856 Remove ambient clamp to keep shadows dark. Partial fix for class 3 ambient term being wrong. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 1 - indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 1 - .../newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 1 - .../newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 1 - indra/newview/app_settings/shaders/class3/lighting/lightV.glsl | 6 +++--- 5 files changed, 3 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 1acb76bdd1..ae579d7f85 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -225,7 +225,6 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(getAmbientClamp(), ambient); // keeps shadows dark ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index cbb7a04631..f7af3647a1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -323,7 +323,6 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index afdd8cdda3..bcd93d9a2d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -116,7 +116,6 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = final_da * sunlit; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 06a76668ba..7368b8d80c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -126,7 +126,6 @@ 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; diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index 1ac0ad8948..f5428077fa 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -31,8 +31,8 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { - vec4 c = sumLights(pos, norm, color); - c.rgb += atmosAmbient() * color.rgb; - return c * 2.0; + vec4 c = sumLights(pos, norm, color) * 2.0; + c.rgb += atmosAmbient() * color.rgb * 0.5; + return c; } -- cgit v1.2.3 From 1ff876a961dc00b7f162054ea1a9fed79240bffc Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 30 Apr 2019 12:19:35 -0700 Subject: SL-11071 Make sun disc and moon shaders use sRGB hardware tex sampling. Remove sun disc shader use of fullbright transport (fogging). --- indra/newview/app_settings/shaders/class1/deferred/moonF.glsl | 3 --- indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index cc1636d89d..187b5a62dd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -44,8 +44,6 @@ uniform sampler2D altDiffuseMap; uniform float blend_factor; // interp factor between moon A/B VARYING vec2 vary_texcoord0; -vec3 srgb_to_linear(vec3 c); - void main() { vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); @@ -60,7 +58,6 @@ void main() vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0 - 1.0; c.rgb = pow(c.rgb, exp); - c.rgb = srgb_to_linear(c.rgb); //c.rgb *= moonlight_color.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index e240c130c6..571e9d9326 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -49,7 +49,8 @@ void main() vec4 c = mix(sunDiscA, sunDiscB, blend_factor); c.rgb = clamp(c.rgb, vec3(0), vec3(1)); c.rgb = pow(c.rgb, vec3(0.7f)); - c.rgb = fullbrightAtmosTransport(c.rgb); + + //c.rgb = fullbrightAtmosTransport(c.rgb); c.rgb = fullbrightScaleSoftClip(c.rgb); // SL-9806 stars poke through -- cgit v1.2.3 From c4032528aff8ef1938e897ec583bbf25a3e713e1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 2 May 2019 13:49:35 -0700 Subject: 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. --- .../shaders/class1/deferred/alphaF.glsl | 68 ++++++----- .../shaders/class1/deferred/cloudsF.glsl | 12 +- .../shaders/class1/deferred/cloudsV.glsl | 16 +-- .../shaders/class1/deferred/diffuseIndexedF.glsl | 3 +- .../shaders/class1/deferred/materialF.glsl | 128 +++++++++++---------- .../shaders/class1/deferred/moonF.glsl | 3 + .../shaders/class1/deferred/multiSpotLightF.glsl | 2 - .../shaders/class1/deferred/softenLightF.glsl | 104 +++++++++-------- .../shaders/class1/deferred/sunDiscF.glsl | 3 + .../class1/windlight/atmosphericsFuncs.glsl | 2 +- .../shaders/class2/deferred/multiSpotLightF.glsl | 20 ++-- .../shaders/class2/deferred/softenLightF.glsl | 94 ++++++++------- .../shaders/class2/deferred/spotLightF.glsl | 15 ++- .../shaders/class2/windlight/atmosphericsF.glsl | 1 - .../shaders/class2/windlight/cloudsF.glsl | 14 +-- .../shaders/class2/windlight/cloudsV.glsl | 3 +- .../shaders/class3/deferred/multiSpotLightF.glsl | 16 +-- .../shaders/class3/deferred/spotLightF.glsl | 11 -- .../shaders/class3/deferred/underWaterF.glsl | 3 - .../shaders/class3/deferred/waterF.glsl | 1 - .../shaders/class3/lighting/lightV.glsl | 6 +- 21 files changed, 282 insertions(+), 243 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index ae579d7f85..ecb1d599de 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -121,7 +121,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec fa += 1.0f; float dist_atten = (fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; dist_atten *= dist_atten; - dist_atten *= 2.0f; + dist_atten *= 2.0; // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); @@ -140,9 +140,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); -#ifndef NO_AMBIANCE col.rgb += amb_da * 0.5 * light_col * diffuse; -#endif // no spec for alpha shader... } @@ -164,22 +162,26 @@ void main() shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); #endif +#ifdef USE_DIFFUSE_TEX + vec4 diffuse_linear = texture2D(diffuseMap,vary_texcoord0.xy); +#endif + #ifdef USE_INDEXED_TEX - vec4 diff = diffuseLookup(vary_texcoord0.xy); -#else - vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); + vec4 diffuse_linear = diffuseLookup(vary_texcoord0.xy); #endif + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); + #ifdef FOR_IMPOSTOR vec4 color; - color.rgb = diff.rgb; + color.rgb = diffuse_srgb.rgb; color.a = 1.0; #ifdef USE_VERTEX_COLOR - float final_alpha = diff.a * vertex_color.a; - diff.rgb *= vertex_color.rgb; + float final_alpha = diffuse_srgb.a * vertex_color.a; + diffuse_srgb.rgb *= vertex_color.rgb; #else - float final_alpha = diff.a; + float final_alpha = diffuse_srgb.a; #endif // Insure we don't pollute depth with invis pixels in impostor rendering @@ -191,16 +193,12 @@ void main() #else #ifdef USE_VERTEX_COLOR - float final_alpha = diff.a * vertex_color.a; - diff.rgb *= vertex_color.rgb; + float final_alpha = diffuse_linear.a * vertex_color.a; + diffuse_srgb.rgb *= vertex_color.rgb; #else - float final_alpha = diff.a; + float final_alpha = diffuse_linear.a; #endif - vec3 gamma_diff = diff.rgb; - - diff.rgb = srgb_to_linear(diff.rgb); - vec3 sunlit; vec3 amblit; vec3 additive; @@ -217,7 +215,7 @@ void main() float final_da = da; final_da = clamp(final_da, 0.0f, 1.0f); - vec4 color = vec4(0,0,0,0); + vec4 color = vec4(0.0); color.rgb = amblit; color.a = final_alpha; @@ -225,6 +223,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; + ambient = max(getAmbientClamp(), ambient); // keeps shadows dark ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; @@ -237,14 +236,12 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diff.rgb; + color.rgb *= diffuse_linear.rgb; vec3 post_diffuse = color.rgb; - color.rgb = mix(diff.rgb, color.rgb, final_alpha); - - //color.rgb = srgb_to_linear(color.rgb); - + //color.rgb = mix(diffuse_srgb.rgb, color.rgb, final_alpha); + color.rgb = atmosFragLighting(color.rgb, additive, atten); color.rgb = scaleSoftClipFrag(color.rgb); @@ -252,7 +249,10 @@ vec3 post_atmo = 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 * 0.5); + // to linear! + color.rgb = srgb_to_linear(color.rgb); + + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.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 * 0.5); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -262,15 +262,29 @@ vec3 post_atmo = color.rgb; LIGHT_LOOP(6) LIGHT_LOOP(7) + // sum local light contrib in linear colorspace + color.rgb += light.rgb; + + // back to sRGB as we're going directly to the final RT post-deferred gamma correction color.rgb = linear_to_srgb(color.rgb); - color.rgb += light.rgb; -#endif + +//color.rgb = amblit; +//color.rgb = vec3(ambient); +//color.rgb = sunlit; +//color.rgb = vec3(final_da); +//color.rgb = post_ambient; +//color.rgb = post_sunlight; +//color.rgb = sun_contrib; +//color.rgb = diffuse_srgb.rgb; +//color.rgb = post_diffuse; +//color.rgb = post_atmo; #ifdef WATER_FOG color = applyWaterFogView(pos.xyz, color); -#endif +#endif // WATER_FOG +#endif frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 9535cd6870..c5eaacbd0b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -86,14 +86,14 @@ void main() vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv1 += cloud_pos_density1.xy;// + (disturbance * 0.02); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); - cloudDensity *= 1.0 - (density_variance * density_variance); + //cloudDensity *= 1.0 - (density_variance * density_variance); // Compute alpha1, the main cloud opacity @@ -104,8 +104,8 @@ void main() alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; - alpha1 *= altitude_blend_factor; - alpha1 = clamp(alpha1, 0.0, 1.0); + //alpha1 *= altitude_blend_factor; + //alpha1 = clamp(alpha1, 0.0, 1.0); // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight @@ -122,6 +122,10 @@ void main() color.rgb= max(vec3(0), color.rgb); color.rgb = linear_to_srgb(color.rgb); +//alpha1 = 1.0; +//color.rgb = cloudColorAmbient.rgb; + + /// Gamma correct for WL (soft clip effect). frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); frag_data[1] = vec4(0.0,0.0,0.0,0.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 61fd43f1ee..10425bb91f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -78,7 +78,7 @@ void main() // Get relative position vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); - altitude_blend_factor = (P.y > -4096.0) ? 1.0 : 1.0 - clamp(abs(P.y) / max_y, 0.0, 1.0); + altitude_blend_factor = (P.y > -4096.0) ? 1.0 : 1.0 - clamp(abs(P.y) / max_y, 0.0, 1.0); // Set altitude if (P.y > 0.) @@ -86,7 +86,6 @@ void main() P *= (max_y / P.y); } else - if (P.y <= 0.0) { P *= (-32000. / P.y); } @@ -100,14 +99,14 @@ void main() vec4 temp2 = vec4(0.); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + //vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + vec4 sunlight = sunlight_color; vec4 light_atten; - float dens_mul = density_multiplier; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); // Calculate relative weights temp1 = blue_density + haze_density; @@ -120,13 +119,14 @@ void main() sunlight *= exp( - light_atten * temp2.y); // Distance - temp2.z = Plen * dens_mul; + temp2.z = Plen * density_multiplier; // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. temp1 = exp(-temp1 * temp2.z); + // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); temp2.x = 1. - temp2.x; @@ -138,7 +138,7 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function - temp2.x *= sun_moon_glow_factor; + //temp2.x *= sun_moon_glow_factor; // Add "minimum anti-solar illumination" temp2.x += .25; @@ -179,7 +179,7 @@ void main() // Texture coords vary_texcoord0 = texcoord0; vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= max(0.001, cloud_scale); + vary_texcoord0.xy /= cloud_scale; vary_texcoord0.xy += 0.5; vary_texcoord1 = vary_texcoord0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 828c325c9d..ccd1df84f9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -36,11 +36,12 @@ VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; vec2 encode_normal(vec3 n); +vec3 linear_to_srgb(vec3 c); void main() { vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; - + vec3 spec; spec.rgb = vec3(vertex_color.a); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f7af3647a1..f640dba59b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -120,6 +120,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe fa += 1.0f; float dist_atten = ( fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; dist_atten *= dist_atten; + dist_atten *= 2.0; if (dist_atten <= 0) { @@ -226,19 +227,17 @@ void main() { vec2 pos_screen = vary_texcoord0.xy; - vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); - diffcol.rgb *= vertex_color.rgb; + vec4 diffuse_linear = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - if (diffcol.a < minimum_alpha) + if (diffuse_linear.a < minimum_alpha) { discard; } #endif -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 gamma_diff = diffcol.rgb; -#endif + diffuse_linear.rgb *= vertex_color.rgb; #ifdef HAS_SPECULAR_MAP vec4 spec = texture2D(specularMap, vary_texcoord2.xy); @@ -247,17 +246,19 @@ void main() vec4 spec = vec4(specular_color.rgb, 1.0); #endif -#ifdef HAS_NORMAL_MAP - vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); + vec4 norm = vec4(0,0,0,1.0); + vec3 tnorm; +#ifdef HAS_NORMAL_MAP + norm = texture2D(bumpMap, vary_texcoord1.xy); norm.xyz = norm.xyz * 2 - 1; - vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2)); + // tangent space norm + tnorm = vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2)); #else - vec4 norm = vec4(0,0,0,1.0); - vec3 tnorm = vary_normal; + tnorm = vary_normal; #endif norm.xyz = tnorm; @@ -265,7 +266,7 @@ void main() vec2 abnormal = encode_normal(norm.xyz); - vec4 final_color = diffcol; + vec4 final_color = diffuse_linear; #if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = emissive_brightness; @@ -274,14 +275,15 @@ void main() #endif vec4 final_specular = spec; + final_specular.a = specular_color.a; #ifdef HAS_SPECULAR_MAP - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); - final_specular.a = specular_color.a * norm.a; -#else + final_specular.a *= norm.a; +#endif + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); - final_specular.a = specular_color.a; +#ifdef HAS_SPECULAR_MAP + final_normal.z *= spec.a; #endif - #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) //forward rendering, output just lit RGBA @@ -294,13 +296,10 @@ void main() #endif 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); + vec3 color = vec3(0.0); float bloom = 0.0; vec3 sunlit; @@ -314,7 +313,7 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float da = dot(norm.xyz, light_dir.xyz); + float da = dot(normalize(norm.xyz), normalize(light_dir.xyz)); da = clamp(da, -1.0, 1.0); float final_da = da; @@ -323,22 +322,23 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; + ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * 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 *= diffuse.rgb; + color.rgb *= diffuse_linear.rgb; -vec3 post_diffuse = col.rgb; +vec3 post_diffuse = color.rgb; float glare = 0.0; @@ -363,44 +363,44 @@ vec3 post_diffuse = col.rgb; vec3 speccol = sun_contrib*scol*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); bloom = dot(speccol, speccol) / 6; - col += speccol; + color += speccol; } } -vec3 post_spec = col.rgb; +vec3 post_spec = color.rgb; - col = mix(col.rgb, diffuse.rgb, diffuse.a); + //color = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; - vec3 refcol = textureCube(environmentMap, env_vec).rgb; + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - col = mix(col.rgb, refcol, - envIntensity); + color = mix(color.rgb, reflected_color, envIntensity); - float cur_glare = max(refcol.r, refcol.g); - cur_glare = max(cur_glare, refcol.b); + float cur_glare = max(reflected_color.r, reflected_color.g); + cur_glare = max(cur_glare, reflected_color.b); cur_glare *= envIntensity*4.0; glare += cur_glare; } -vec3 post_env = col.rgb; +vec3 post_env = color.rgb; + + color = atmosFragLighting(color, additive, atten); + color = scaleSoftClipFrag(color); + +vec3 post_atmo = color.rgb; - col = atmosFragLighting(col, additive, atten); - col = scaleSoftClipFrag(col); + //convert to linear space before adding local lights + color = srgb_to_linear(color); vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); -vec3 post_atmo = col.rgb; - - //col.rgb = srgb_to_linear(col.rgb); - - #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 * 0.5); + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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 * 0.5); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -410,27 +410,39 @@ vec3 post_atmo = col.rgb; LIGHT_LOOP(6) LIGHT_LOOP(7) -vec3 postlight_linear = col.rgb; glare = min(glare, 1.0); - float al = max(diffcol.a,glare)*vertex_color.a; + float al = max(diffuse_linear.a,glare)*vertex_color.a; + + color.rgb += light.rgb; + + // (only) post-deferred needs inline gamma correction + color.rgb = linear_to_srgb(color.rgb); + +//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; #ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); - col.rgb = temp.rgb; + vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); + color.rgb = temp.rgb; al = temp.a; #endif -//col.rgb = post_atmo; - - col.rgb = linear_to_srgb(col.rgb); - - col.rgb += light.rgb; - - frag_color.rgb = col.rgb; + frag_color.rgb = color.rgb; frag_color.a = al; #else + // deferred path frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 187b5a62dd..8256d5f106 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -44,12 +44,15 @@ uniform sampler2D altDiffuseMap; uniform float blend_factor; // interp factor between moon A/B VARYING vec2 vary_texcoord0; +vec3 srgb_to_linear(vec3 c); void main() { vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(moonA, moonB, blend_factor); + c.rgb = srgb_to_linear(c.rgb); + // mix factor which blends when sunlight is brighter // and shows true moon color at night vec3 luma_weights = vec3(0.3, 0.5, 0.3); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 6489508c00..2569e49743 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -72,8 +72,6 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 getNorm(vec2 pos_screen); -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index bcd93d9a2d..84642b2f98 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -36,7 +36,6 @@ out vec4 frag_color; uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; -uniform sampler2DRect positionMap; uniform sampler2DRect normalMap; uniform sampler2DRect lightMap; uniform sampler2DRect depthMap; @@ -47,13 +46,7 @@ uniform float blur_size; uniform float blur_fidelity; // Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; -uniform vec4 gamma; -uniform float global_gamma; uniform mat3 env_mat; -uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; uniform vec3 moon_dir; @@ -63,21 +56,20 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -#ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); -#endif - vec3 getNorm(vec2 pos_screen); -vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec4 getPositionWithDepth(vec2 pos_screen, float depth); -float getAmbientClamp(); 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); -vec3 srgb_to_linear(vec3 c); + vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); -vec4 getPositionWithDepth(vec2 pos_screen, float depth); +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif void main() { @@ -88,50 +80,49 @@ void main() float envIntensity = norm.z; norm.xyz = getNorm(tc); - float light_gamma = 1.0/1.3; vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float da = dot(normalize(norm.xyz), light_dir.xyz); da = clamp(da, -1.0, 1.0); float final_da = da; final_da = clamp(final_da, 0.0, 1.0); - //final_da = pow(final_da, light_gamma); - vec4 gamma_diff = texture2DRect(diffuseRect, tc); - vec4 diffuse = gamma_diff; - diffuse.rgb = srgb_to_linear(gamma_diff.rgb); + vec4 diffuse_linear = texture2DRect(diffuseRect, tc); + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - vec3 col; + vec3 color = vec3(0); float bloom = 0.0; { + float ambocc = 1.0; // no AO... + vec3 sunlit; vec3 amblit; vec3 additive; vec3 atten; - - calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten); + + calcAtmosphericVars(pos.xyz, ambocc, sunlit, amblit, additive, atten); float ambient = da; ambient *= 0.5; ambient *= ambient; + ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = 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_linear.rgb; -vec3 post_diffuse = col.rgb; +vec3 post_diffuse = color.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -152,40 +143,59 @@ vec3 post_diffuse = col.rgb; if (nh > 0.0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scol*spec.rgb; + float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = sun_contrib*scontrib*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); - bloom = dot(speccol, speccol) / 6; - col += speccol; + bloom += dot (speccol, speccol) / 6; + color += speccol; } } - vec3 post_spec = col.rgb; + vec3 post_spec = color.rgb; - col.rgb += diffuse.a * diffuse.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 = col.rgb; +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/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index 571e9d9326..454af2a9bc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -33,6 +33,7 @@ out vec4 frag_data[3]; #define frag_data gl_FragData #endif +vec3 srgb_to_linear(vec3 c); vec3 fullbrightAtmosTransport(vec3 light); vec3 fullbrightScaleSoftClip(vec3 light); @@ -47,6 +48,8 @@ void main() vec4 sunDiscA = texture2D(diffuseMap, vary_texcoord0.xy); vec4 sunDiscB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(sunDiscA, sunDiscB, blend_factor); + + c.rgb = srgb_to_linear(c.rgb); c.rgb = clamp(c.rgb, vec3(0), vec3(1)); c.rgb = pow(c.rgb, vec3(0.7f)); diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index cd1e2d6e32..a3041fccdc 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -137,7 +137,7 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o + tmpAmbient)); //brightness of surface both sunlight and ambient - sunlit = sunlight.rgb; + sunlit = sunlight.rgb * 0.5; amblit = tmpAmbient.rgb * .25; additive *= vec3(1.0 - temp1); } 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; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 94e776d51d..36703ea742 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -44,7 +44,6 @@ uniform mat3 ssao_effect_mat; uniform int no_atmo; uniform float sun_moon_glow_factor; -vec3 srgb_to_linear(vec3 c); vec3 scaleSoftClipFrag(vec3 light); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index e31bdf610c..1de919bf30 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -86,14 +86,14 @@ void main() vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv1 += cloud_pos_density1.xy;// + (disturbance * 0.02); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); - cloudDensity *= 1.0 - (density_variance * density_variance); + //cloudDensity *= 1.0 - (density_variance * density_variance); // Compute alpha1, the main cloud opacity @@ -104,12 +104,12 @@ void main() alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; - alpha1 *= altitude_blend_factor; + //alpha1 *= altitude_blend_factor; - if (alpha1 < 0.001f) - { - discard; - } + //if (alpha1 < 0.001f) + //{ + // discard; + //} // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index 64156bd3bf..5c5cd0294a 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -180,7 +180,8 @@ void main() // Texture coords vary_texcoord0 = texcoord0; vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= max(0.001, cloud_scale); + vary_texcoord0.xy /= cloud_scale; + //vary_texcoord0.xy /= max(0.001, cloud_scale); vary_texcoord0.xy += 0.5; vary_texcoord1 = vary_texcoord0; diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index abb6a3a5d8..52de7ceaad 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -71,19 +71,11 @@ 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); -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.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -103,7 +95,6 @@ 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)); @@ -121,7 +112,6 @@ 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); @@ -260,10 +250,6 @@ void main() //col += spec.rgb; } } - - - - if (envIntensity > 0.0) { @@ -297,6 +283,8 @@ 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/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index afc542b8bc..bccd819a43 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -72,18 +72,10 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 getNorm(vec2 pos_screen); -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); - -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.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -103,7 +95,6 @@ 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)); @@ -121,7 +112,6 @@ 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); @@ -256,7 +246,6 @@ void main() { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); col += dlit*scol*spec.rgb*shadow; - //col += spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl index 9d18d1afd8..540226e672 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl @@ -58,9 +58,6 @@ VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); - vec2 encode_normal(vec3 n); vec4 applyWaterFog(vec4 color, vec3 viewVec) diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl index 2a144ba23a..c65cf48c67 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl @@ -61,7 +61,6 @@ VARYING vec4 view; VARYING vec4 vary_position; vec3 scaleSoftClip(vec3 c); -vec3 srgb_to_linear(vec3 cs); vec2 encode_normal(vec3 n); vec3 BlendNormal(vec3 bump1, vec3 bump2) diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index f5428077fa..69267621a3 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -31,8 +31,8 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { - vec4 c = sumLights(pos, norm, color) * 2.0; - c.rgb += atmosAmbient() * color.rgb * 0.5; - return c; + vec4 c = sumLights(pos, norm, color * 2.0); + c.rgb += atmosAmbient() * color.rgb; + return c * 2.0; } -- cgit v1.2.3 From 906b0be675e5467665f65180924e6117700b4cbb Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 3 May 2019 08:47:13 -0700 Subject: SL-11087, SL-11086, SL-11092 Fix sun/moon glow factor bustage. Make darkness an option. Fix moon fade shader logic getting confused when sun was below horizon. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 13 ++++++------- .../app_settings/shaders/class1/deferred/materialF.glsl | 15 ++++++--------- .../shaders/class1/deferred/softenLightF.glsl | 2 +- .../shaders/class2/deferred/multiSpotLightF.glsl | 4 ++-- .../app_settings/shaders/class2/deferred/spotLightF.glsl | 4 ++-- 5 files changed, 17 insertions(+), 21 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index ecb1d599de..0a189ff416 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -119,9 +119,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec //distance attenuation float dist = (la > 0) ? d/la : 1.0f; fa += 1.0f; - float dist_atten = (fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; + float dist_atten = (fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 0.0f; dist_atten *= dist_atten; - dist_atten *= 2.0; + dist_atten *= 2.2f; // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); @@ -131,15 +131,14 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec float lit = max(da * dist_atten,0.0); float amb_da = ambiance; - if (da > 0) + if (lit > 0) { col = lit * light_col * diffuse; amb_da += (da*0.5+0.5) * ambiance; + amb_da += (da*da*0.5 + 0.5) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); } - amb_da += (da*da*0.5 + 0.5) * ambiance; - amb_da *= dist_atten; - amb_da = min(amb_da, 1.0f - lit); - col.rgb += amb_da * 0.5 * light_col * diffuse; // no spec for alpha shader... diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f640dba59b..54bed38fb7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -120,7 +120,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe fa += 1.0f; float dist_atten = ( fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; dist_atten *= dist_atten; - dist_atten *= 2.0; + dist_atten *= 2.2f; if (dist_atten <= 0) { @@ -143,13 +143,10 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe { col = light_col*lit*diffuse; amb_da += (da*0.5 + 0.5) * ambiance; + amb_da += (da*da*0.5+0.5) * ambiance; + amb_da = min(amb_da, 1.0f - lit); } - amb_da += (da*da*0.5+0.5) * ambiance; - amb_da = min(amb_da, 1.0f - lit); - -#ifndef NO_AMBIANCE - col.rgb += amb_da * 0.5 * light_col * diffuse; -#endif + col.rgb += amb_da * 0.25 * light_col * diffuse; if (spec.a > 0.0) { @@ -362,7 +359,7 @@ vec3 post_diffuse = color.rgb; float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = sun_contrib*scol*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); - bloom = dot(speccol, speccol) / 6; + bloom = dot(speccol, speccol) / 6.0f; color += speccol; } } @@ -400,7 +397,7 @@ vec3 post_atmo = color.rgb; vec3 light = vec3(0,0,0); - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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 * 0.5); + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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); LIGHT_LOOP(1) LIGHT_LOOP(2) diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 84642b2f98..d13a717761 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -146,7 +146,7 @@ vec3 post_diffuse = color.rgb; float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = sun_contrib*scontrib*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); - bloom += dot (speccol, speccol) / 6; + bloom += dot(speccol, speccol) / 12.0; color += speccol; } } diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index b05d544938..54ec534d14 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -224,14 +224,14 @@ void main() col = dlit*lit*diff_tex*shadow; // unshadowed for consistency between forward and deferred? - amb_da += (da*0.5+0.5) * (1.0-shadow) * proj_ambiance; + amb_da += (da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); // use unshadowed for consistency between forward and deferred? - amb_da += (da*da*0.5+0.5) * (1.0-shadow) * proj_ambiance; + amb_da += (da*da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index a3ff754849..2ef7cffe9d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -220,13 +220,13 @@ void main() col = dlit*lit*diff_tex*shadow; - amb_da += (da*0.5+0.5) * (1.0-shadow) * proj_ambiance; + amb_da += (da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; + amb_da += (da*da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); -- cgit v1.2.3 From 9c23ede9799a3277ae8e79f9832b3ea557fc069d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 3 May 2019 09:12:53 -0700 Subject: SL-11075 Make alpha shader apply vert color everywhere. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/deferred/moonF.glsl | 3 ++- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 0a189ff416..b00e2290a9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -194,6 +194,7 @@ void main() #ifdef USE_VERTEX_COLOR float final_alpha = diffuse_linear.a * vertex_color.a; diffuse_srgb.rgb *= vertex_color.rgb; + diffuse_linear.rgb *= vertex_color.rgb; #else float final_alpha = diffuse_linear.a; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index c5eaacbd0b..595efdf6fe 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -120,11 +120,11 @@ void main() vec4 color; color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); color.rgb= max(vec3(0), color.rgb); - color.rgb = linear_to_srgb(color.rgb); + //color.rgb = linear_to_srgb(color.rgb); //alpha1 = 1.0; //color.rgb = cloudColorAmbient.rgb; - +color.rgb = vec3(1,0,1); /// Gamma correct for WL (soft clip effect). frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 8256d5f106..80f232948a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -57,7 +57,8 @@ void main() // and shows true moon color at night vec3 luma_weights = vec3(0.3, 0.5, 0.3); - float mix = 1.0 - dot(normalize(sunlight_color.rgb), luma_weights); + vec4 light_color = max(sunlight_color, moonlight_color); + float mix = 1.0 - dot(normalize(light_color.rgb), luma_weights); vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0 - 1.0; c.rgb = pow(c.rgb, exp); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index a2fbec524e..8fcd26eba9 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -153,7 +153,7 @@ vec3 post_diffuse = color.rgb; float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 speccol = sun_contrib*scontrib*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); - bloom += dot (speccol, speccol) / 6; + bloom += dot (speccol, speccol) / 12; color += speccol; } } -- cgit v1.2.3 From 1522a9902481b69b3d04bee5edd79102a796630b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 3 May 2019 10:12:56 -0700 Subject: SL-11070 Gave clouds the Bob Ross treatment. --- .../app_settings/shaders/class1/deferred/cloudsF.glsl | 16 ++++++---------- .../app_settings/shaders/class1/deferred/cloudsV.glsl | 10 +++++----- .../app_settings/shaders/class1/deferred/skyV.glsl | 2 +- .../app_settings/shaders/class2/deferred/skyF.glsl | 2 +- .../app_settings/shaders/class2/windlight/cloudsV.glsl | 2 +- .../app_settings/shaders/class2/windlight/skyV.glsl | 2 +- 6 files changed, 15 insertions(+), 19 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 595efdf6fe..6ff97fd1e9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -1,5 +1,5 @@ /** - * @file WLCloudsF.glsl + * @file class1\deferred\cloudsF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -86,14 +86,14 @@ void main() vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy;// + (disturbance * 0.02); //large texture, visible density + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); - //cloudDensity *= 1.0 - (density_variance * density_variance); + cloudDensity *= 1.0 - (density_variance * density_variance); // Compute alpha1, the main cloud opacity @@ -104,8 +104,8 @@ void main() alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; - //alpha1 *= altitude_blend_factor; - //alpha1 = clamp(alpha1, 0.0, 1.0); + alpha1 *= altitude_blend_factor; + alpha1 = clamp(alpha1, 0.0, 1.0); // Compute alpha2, for self shadowing effect // (1 - alpha2) will later be used as percentage of incoming sunlight @@ -120,11 +120,7 @@ void main() vec4 color; color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); color.rgb= max(vec3(0), color.rgb); - //color.rgb = linear_to_srgb(color.rgb); - -//alpha1 = 1.0; -//color.rgb = cloudColorAmbient.rgb; -color.rgb = vec3(1,0,1); + color.rgb *= 2.0; /// Gamma correct for WL (soft clip effect). frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 10425bb91f..f1eb1af90c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -99,14 +99,14 @@ void main() vec4 temp2 = vec4(0.); vec4 blue_weight; vec4 haze_weight; - //vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; - vec4 sunlight = sunlight_color; + vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; + float dens_mul = density_multiplier * 0.45; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); // Calculate relative weights temp1 = blue_density + haze_density; @@ -119,7 +119,7 @@ void main() sunlight *= exp( - light_atten * temp2.y); // Distance - temp2.z = Plen * density_multiplier; + temp2.z = Plen * dens_mul; // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati @@ -138,7 +138,7 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function - //temp2.x *= sun_moon_glow_factor; + temp2.x *= sun_moon_glow_factor; // Add "minimum anti-solar illumination" temp2.x += .25; diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index bee8e2dab5..4603c69f2a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -87,7 +87,7 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier; + float dens_mul = density_multiplier * 0.45; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index a8eb7102ed..bd0ca0a46e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -117,7 +117,7 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier; + float dens_mul = density_multiplier * 0.45; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index 5c5cd0294a..43500bc5e3 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -103,7 +103,7 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier; + float dens_mul = density_multiplier * 0.45; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index 6d6b3dafa7..f6bef3e6bc 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -87,7 +87,7 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier; + float dens_mul = density_multiplier * 0.45; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes -- cgit v1.2.3 From 8d32aade01b0b87bd626a81f68b210538e90095b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 3 May 2019 11:45:17 -0700 Subject: SL-11090 Tamp down bloom so we don't have to redo ten thousand gloss maps. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 4 ++-- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 4 ++-- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 54bed38fb7..541d6bd4fb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -357,9 +357,9 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scol*spec.rgb; + vec3 speccol = sun_contrib*scol*spec.rgb*0.25; speccol = clamp(speccol, vec3(0), vec3(1)); - bloom = dot(speccol, speccol) / 6.0f; + bloom = dot(speccol, speccol); color += speccol; } } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index d13a717761..9d6958381b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -144,9 +144,9 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scontrib*spec.rgb; + vec3 speccol = sun_contrib*scontrib*spec.rgb*0.25; speccol = clamp(speccol, vec3(0), vec3(1)); - bloom += dot(speccol, speccol) / 12.0; + bloom += dot(speccol, speccol); color += speccol; } } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 8fcd26eba9..430b85eee1 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -151,9 +151,9 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scontrib*spec.rgb; + vec3 speccol = sun_contrib*scontrib*spec.rgb * 0.25; speccol = clamp(speccol, vec3(0), vec3(1)); - bloom += dot (speccol, speccol) / 12; + bloom += dot (speccol, speccol); color += speccol; } } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index ad721a80d6..6400e5169e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -146,8 +146,8 @@ void main() vec3 dumbshiny = scol * texture2D(lightFunc, vec2(sa, spec.a)).r * atmo_color; // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; + vec3 spec_contrib = dumbshiny * spec.rgb * 0.25; + bloom = dot(spec_contrib, spec_contrib); col += spec_contrib; } -- cgit v1.2.3 From 89c24095c6c1b778b93a4eb7ad398627f4d5479f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 3 May 2019 12:02:59 -0700 Subject: SL-11085 Remove ambient term clamping to get less dark shadows where we want less dark shadows in ALM. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- .../newview/app_settings/shaders/class1/deferred/shadowUtil.glsl | 8 ++++---- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index b00e2290a9..c4d89f29f6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -223,7 +223,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(getAmbientClamp(), ambient); // keeps shadows dark + //ambient = max(getAmbientClamp(), ambient); // keeps shadows dark ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 541d6bd4fb..64cdacd4a2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -319,7 +319,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(getAmbientClamp(), ambient); + //ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index c2cb0eb8c3..14cd805d10 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -50,7 +50,7 @@ float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, { float offset = shadow_bias * bias_mul; stc.xyz /= stc.w; - stc.z += offset * 4.0; + stc.z += offset * 2.0; stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; float shadow = cs * 4.0; @@ -124,7 +124,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - w = clamp(w, 0.25, 1.0); + w = clamp(w, 0.0, 1.0); shadow += pcfShadow(shadowMap2, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } @@ -136,7 +136,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - w = clamp(w, 0.5, 1.0); + w = clamp(w, 0.0, 1.0); shadow += pcfShadow(shadowMap1, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } @@ -147,7 +147,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - w = clamp(w, 0.75, 1.0); + w = clamp(w, 0.0, 1.0); shadow += pcfShadow(shadowMap0, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 9d6958381b..981a50769a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -106,7 +106,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(getAmbientClamp(), ambient); + //ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = final_da * sunlit; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 430b85eee1..f6f8f56103 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -113,7 +113,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = max(getAmbientClamp(), ambient); + //ambient = max(getAmbientClamp(), ambient); ambient = 1.0 - ambient; vec3 sun_contrib = min(scol, final_da) * sunlit; -- cgit v1.2.3 From 42397056089245da248d1aae6318239e90fbf866 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sat, 4 May 2019 09:11:59 -0700 Subject: Fix broken water reflection/refraction mix. Restore 1.0 alpha to prevent atmo being applied directly to water. Fix broken shadow frust generation. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index e72b36f28a..8fea4e5d27 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -149,14 +149,14 @@ void main() vec4 fb = texture2D(screenTex, distort2); //mix with reflection - color.rgb = fb.rgb; - color.rgb += refcol.rgb * df1; + // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); vec4 pos = vary_position; vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - frag_data[0] = vec4(color.rgb, 0.25); // diffuse + frag_data[0] = vec4(color.rgb, 0); // diffuse frag_data[1] = vec4(specular * 0.15, 0.5); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 0, 0 } -- cgit v1.2.3 From a4b279444e76432ca60553aaef861d9cb1773c06 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sat, 4 May 2019 10:56:16 -0700 Subject: SL-11080 --- .../shaders/class1/deferred/shadowUtil.glsl | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 14cd805d10..5694ba1f7b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -50,11 +50,10 @@ float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, { float offset = shadow_bias * bias_mul; stc.xyz /= stc.w; - stc.z += offset * 2.0; - stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + stc.z += offset * 3.0; + stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; float shadow = cs * 4.0; - stc.z += offset * 2.0; shadow += shadow2D(shadowMap, stc.xyz+vec3( 1.5/shadow_res.x, 0.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3( 0.5/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.5/shadow_res.x, -0.5/shadow_res.y, 0.0)).x; @@ -112,8 +111,12 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; w = clamp(w, 0.0, 1.0); - shadow += pcfShadow(shadowMap3, norm, lpos, 1.0, pos_screen, light_dir)*w; - weight += w; + float contrib = pcfShadow(shadowMap3, norm, lpos, 1.0, pos_screen, light_dir)*w; + if (contrib > 0) + { + shadow += contrib; + weight += w; + } shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } @@ -125,8 +128,12 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; w = clamp(w, 0.0, 1.0); - shadow += pcfShadow(shadowMap2, norm, lpos, 1.0, pos_screen, light_dir)*w; - weight += w; + float contrib = pcfShadow(shadowMap2, norm, lpos, 1.0, pos_screen, light_dir)*w; + if (contrib > 0) + { + shadow += contrib; + weight += w; + } } if (spos.z < near_split.x && spos.z > far_split.y) @@ -137,8 +144,12 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; w = clamp(w, 0.0, 1.0); - shadow += pcfShadow(shadowMap1, norm, lpos, 1.0, pos_screen, light_dir)*w; - weight += w; + float contrib = pcfShadow(shadowMap1, norm, lpos, 1.0, pos_screen, light_dir)*w; + if (contrib > 0) + { + shadow += contrib; + weight += w; + } } if (spos.z > far_split.x) @@ -148,8 +159,12 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; w = clamp(w, 0.0, 1.0); - shadow += pcfShadow(shadowMap0, norm, lpos, 1.0, pos_screen, light_dir)*w; - weight += w; + float contrib = pcfShadow(shadowMap0, norm, lpos, 1.0, pos_screen, light_dir)*w; + if (contrib > 0) + { + shadow += contrib; + weight += w; + } } shadow /= weight; -- cgit v1.2.3 From 21c1941a4f4780c0675ae338cbbc5899aa7c0613 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 6 May 2019 10:16:31 -0700 Subject: Fix missin atten and atten only applied when da > 0 in material and alpha shaders resp. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 7 +++---- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index c4d89f29f6..2112fa8251 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -136,9 +136,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec col = lit * light_col * diffuse; amb_da += (da*0.5+0.5) * ambiance; amb_da += (da*da*0.5 + 0.5) * ambiance; - amb_da *= dist_atten; - amb_da = min(amb_da, 1.0f - lit); } + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); col.rgb += amb_da * 0.5 * light_col * diffuse; // no spec for alpha shader... @@ -240,7 +240,7 @@ vec3 post_sunlight = color.rgb; vec3 post_diffuse = color.rgb; - //color.rgb = mix(diffuse_srgb.rgb, color.rgb, final_alpha); + //color.rgb = mix(diffuse_linear.rgb, color.rgb, final_alpha); color.rgb = atmosFragLighting(color.rgb, additive, atten); color.rgb = scaleSoftClipFrag(color.rgb); @@ -268,7 +268,6 @@ vec3 post_atmo = color.rgb; // back to sRGB as we're going directly to the final RT post-deferred gamma correction color.rgb = linear_to_srgb(color.rgb); - //color.rgb = amblit; //color.rgb = vec3(ambient); //color.rgb = sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 64cdacd4a2..ba1f121bfd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -144,8 +144,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe col = light_col*lit*diffuse; amb_da += (da*0.5 + 0.5) * ambiance; amb_da += (da*da*0.5+0.5) * ambiance; - amb_da = min(amb_da, 1.0f - lit); } + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); col.rgb += amb_da * 0.25 * light_col * diffuse; if (spec.a > 0.0) -- cgit v1.2.3 From ac080210a8cd2f64c040f980708ccce2c5464874 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 6 May 2019 11:18:31 -0700 Subject: Make underwater shader output linear (refracted image was in wrong colorspace). --- indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index e95a688e1f..641c6fbd36 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -58,6 +58,7 @@ VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; +vec3 srgb_to_linear(vec3 c); vec2 encode_normal(vec3 n); vec4 applyWaterFog(vec4 color, vec3 viewVec) @@ -112,6 +113,8 @@ void main() vec4 fb = texture2D(screenTex, distort); + fb.rgb = srgb_to_linear(fb.rgb); + frag_data[0] = vec4(fb.rgb, 1.0); // diffuse frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, displace -- cgit v1.2.3 From c61f73321dbef9f0f5741830bfbaa8facd6ec060 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 6 May 2019 16:29:06 -0700 Subject: SL-11102, SL-11103 Fix diffuse boost in deferred lighting to match non-deferred. Make class2 soften not clamp shadow color to incoming alpha (make shadows appear on terrain underwater). --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 -- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 -- .../newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 -- .../newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 7 ++++--- 4 files changed, 4 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 2112fa8251..dbd7abd7e5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -240,8 +240,6 @@ vec3 post_sunlight = color.rgb; vec3 post_diffuse = color.rgb; - //color.rgb = mix(diffuse_linear.rgb, color.rgb, final_alpha); - color.rgb = atmosFragLighting(color.rgb, additive, atten); color.rgb = scaleSoftClipFrag(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index ba1f121bfd..7533762a96 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -367,8 +367,6 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; - //color = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); - if (envIntensity > 0.0) { //add environmentmap diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 981a50769a..fb9f6d7f37 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -153,8 +153,6 @@ vec3 post_diffuse = color.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; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index f6f8f56103..73b4473be5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -95,7 +95,10 @@ void main() 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); + + // clamping to alpha value kills underwater shadows... + //scol = max(scol_ambocc.r, diffuse_linear.a); + scol = scol_ambocc.r; vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 color = vec3(0); @@ -160,8 +163,6 @@ vec3 post_diffuse = color.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; -- cgit v1.2.3 From 570bbdb779f5e4be0c1804862bdffc9c5a1beb1b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 7 May 2019 15:09:30 -0700 Subject: Fix diffuse boost which we don't want underwater, but do want in other cases. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 4 ++++ indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index fb9f6d7f37..b6e3951ee3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -153,6 +153,10 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; +#ifndef WATER_FOG + color.rgb += diffuse_srgb.a * diffuse_srgb.rgb; +#endif + if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 73b4473be5..03e5143fca 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -163,6 +163,10 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; +#ifndef WATER_FOG + color.rgb += diffuse_srgb.a * diffuse_srgb.rgb; +#endif + if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; -- cgit v1.2.3 From a1e8042c1f2f1ab0ed5b6040535348974e659556 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 7 May 2019 15:36:43 -0700 Subject: SL-11055, SL-10966, SL-11087 Make haze look more like WL. Make lack of sun and moon mean black and fixed dir to prevent spooky underlighting. --- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 7 ++++--- .../app_settings/shaders/class2/windlight/atmosphericsF.glsl | 4 +++- indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl | 6 +++--- indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl | 7 ++++--- indra/newview/app_settings/shaders/class2/windlight/skyV.glsl | 3 ++- indra/newview/app_settings/shaders/class3/lighting/lightV.glsl | 4 ++-- 7 files changed, 19 insertions(+), 14 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index a3041fccdc..6788cc1f63 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -68,7 +68,7 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o vec4 light_atten; float dens_mul = density_multiplier; - float dist_mul = distance_multiplier * 0.1; + float dist_mul = distance_multiplier; //sunlight attenuation effect (hue and brightness) due to atmosphere //this is used later for sunlight modulation at various altitudes diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index bd0ca0a46e..eb95890e08 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -44,6 +44,7 @@ uniform float haze_density; uniform float cloud_shadow; uniform float density_multiplier; +uniform float distance_multiplier; uniform float max_y; uniform vec4 glow; @@ -117,7 +118,8 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier * 0.45; + float dens_mul = density_multiplier; + float dist_mul = distance_multiplier; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes @@ -139,8 +141,7 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); - + temp1 = exp(-temp1 * temp2.z * dist_mul); // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 36703ea742..9db04f4e9a 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -37,6 +37,8 @@ uniform vec4 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 vec4 glow; uniform float scene_light_strength; @@ -53,7 +55,7 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) return light; } light *= atten.r; - light += additive * exp(-1.0f); + light += additive; return light * 2.0; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index 1de919bf30..396ceacd19 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -86,14 +86,14 @@ void main() vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy;// + (disturbance * 0.02); //large texture, visible density + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); - //cloudDensity *= 1.0 - (density_variance * density_variance); + cloudDensity *= 1.0 - (density_variance * density_variance); // Compute alpha1, the main cloud opacity @@ -104,7 +104,7 @@ void main() alpha1 = 1. - alpha1 * alpha1; alpha1 = 1. - alpha1 * alpha1; - //alpha1 *= altitude_blend_factor; + alpha1 *= altitude_blend_factor; //if (alpha1 < 0.001f) //{ diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index 43500bc5e3..aaf995af3c 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -57,6 +57,7 @@ uniform float haze_density; uniform float cloud_shadow; uniform float density_multiplier; +uniform float distance_multiplier; uniform float max_y; uniform vec4 glow; @@ -103,7 +104,8 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier * 0.45; + float dens_mul = density_multiplier; + float dist_mul = distance_multiplier; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes @@ -125,8 +127,7 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); - + temp1 = exp(-temp1 * temp2.z * dist_mul); // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index f6bef3e6bc..a23a5d4076 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -49,6 +49,7 @@ uniform float haze_density; uniform float cloud_shadow; uniform float density_multiplier; +uniform float distance_multiplier; uniform float max_y; uniform vec4 glow; @@ -109,7 +110,7 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); + temp1 = exp(-temp1 * temp2.z * distance_multiplier); // Compute haze glow diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index 69267621a3..48c883d98a 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -31,8 +31,8 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { - vec4 c = sumLights(pos, norm, color * 2.0); + vec4 c = sumLights(pos, norm, color); c.rgb += atmosAmbient() * color.rgb; - return c * 2.0; + return c; } -- cgit v1.2.3 From d3cf82969a6bf63585eba58d50223fec5e32a502 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 7 May 2019 15:39:01 -0700 Subject: SL-11105 --- indra/newview/app_settings/shaders/class1/lighting/lightV.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl index 2d41776ee2..38230836eb 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl @@ -32,7 +32,7 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { vec4 c = sumLights(pos, norm, color); - c.rgb += atmosAmbient() * color.rgb; + c.rgb += atmosAmbient() * color.rgb * 0.5; return c; } -- cgit v1.2.3 From 989de25f189276d586d5c7077e505bc697fe4112 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 7 May 2019 16:32:34 -0700 Subject: SL-11086 Re-fix sun/moon glow factor and make it depend on moon brightness. Make cloud shaders use sunlight color exclusively for consistency when moon is up or down. --- indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl | 5 ++--- indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index f1eb1af90c..aed5a9b950 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -99,7 +99,8 @@ void main() vec4 temp2 = vec4(0.); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + //vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + vec4 sunlight = sunlight_color; vec4 light_atten; float dens_mul = density_multiplier * 0.45; @@ -156,8 +157,6 @@ void main() ); // CLOUDS - - sunlight = sunlight_color; temp2.y = max(0., lightnorm.y * 2.); temp2.y = 1. / temp2.y; sunlight *= exp( - light_atten * temp2.y); diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index aaf995af3c..5c29290e47 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -101,7 +101,8 @@ void main() vec4 temp2 = vec4(0.); vec4 blue_weight; vec4 haze_weight; - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + //vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + vec4 sunlight = sunlight_color; vec4 light_atten; float dens_mul = density_multiplier; -- cgit v1.2.3 From 06097302f4ad8786913e77514d5d60678da3160d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 7 May 2019 16:42:38 -0700 Subject: SL-11108 Remove tweaks to combine cascade results. --- .../app_settings/shaders/class1/deferred/shadowUtil.glsl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 5694ba1f7b..bea016300d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -110,9 +110,9 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - w = clamp(w, 0.0, 1.0); + //w = clamp(w, 0.0, 1.0); float contrib = pcfShadow(shadowMap3, norm, lpos, 1.0, pos_screen, light_dir)*w; - if (contrib > 0) + //if (contrib > 0) { shadow += contrib; weight += w; @@ -127,9 +127,9 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - w = clamp(w, 0.0, 1.0); + //w = clamp(w, 0.0, 1.0); float contrib = pcfShadow(shadowMap2, norm, lpos, 1.0, pos_screen, light_dir)*w; - if (contrib > 0) + //if (contrib > 0) { shadow += contrib; weight += w; @@ -143,9 +143,9 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - w = clamp(w, 0.0, 1.0); + //w = clamp(w, 0.0, 1.0); float contrib = pcfShadow(shadowMap1, norm, lpos, 1.0, pos_screen, light_dir)*w; - if (contrib > 0) + //if (contrib > 0) { shadow += contrib; weight += w; @@ -158,9 +158,9 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - w = clamp(w, 0.0, 1.0); + //w = clamp(w, 0.0, 1.0); float contrib = pcfShadow(shadowMap0, norm, lpos, 1.0, pos_screen, light_dir)*w; - if (contrib > 0) + //if (contrib > 0) { shadow += contrib; weight += w; -- cgit v1.2.3 From 4fe71c1da4d16513fe6aa1fb8a2bfd801f6ede7d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 9 May 2019 08:49:02 -0700 Subject: SL-11109 Fix alpha mask shadows to mult vert alpha prior to discard tests and obey min alpha settings. Make shadow/shadowAlphaMask use consistent varying and output. Also fixes bug with 0% and 1% transparency providing varying different visual results. --- .../shaders/class1/deferred/shadowAlphaMaskF.glsl | 18 +++++++----------- .../shaders/class1/deferred/shadowAlphaMaskV.glsl | 11 ++--------- .../app_settings/shaders/class1/deferred/shadowF.glsl | 2 -- .../app_settings/shaders/class1/deferred/shadowV.glsl | 5 ++--- 4 files changed, 11 insertions(+), 25 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index dd762958c4..d79d2423f1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -33,38 +33,34 @@ out vec4 frag_color; uniform sampler2D diffuseMap; -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING float pos_w; - +VARYING vec4 post_pos; VARYING float target_pos_x; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +uniform float minimum_alpha; void main() { float alpha = diffuseLookup(vary_texcoord0.xy).a; + alpha *= vertex_color.a; + if (alpha < 0.05) // treat as totally transparent { discard; } - if (alpha < 0.88) // treat as semi-transparent + if (alpha < minimum_alpha) // treat as semi-transparent { - if (fract(0.5*floor(target_pos_x / pos_w )) < 0.25) + if (fract(0.5*floor(target_pos_x / post_pos.w )) < 0.25) { discard; } } - alpha *= vertex_color.a; - frag_color = vec4(1,1,1,1); #if !defined(DEPTH_CLAMP) - gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); + gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl index f45c343066..b6a0f0b165 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl @@ -31,12 +31,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING float pos_w; - +VARYING vec4 post_pos; VARYING float target_pos_x; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; @@ -50,11 +45,9 @@ void main() vec4 pos = modelview_projection_matrix * pre_pos; target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; - pos_w = pos.w; + post_pos = pos; #if !defined(DEPTH_CLAMP) - pos_zd2 = pos.z * 0.5; - gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); #else gl_Position = pos; diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl index 22d42d38c1..1ea96918bb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl @@ -31,9 +31,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -#if !defined(DEPTH_CLAMP) VARYING vec4 post_pos; -#endif void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl index 41a89fb8b4..72bd0f0f34 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl @@ -27,20 +27,19 @@ uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; -#if !defined(DEPTH_CLAMP) VARYING vec4 post_pos; -#endif void main() { //transform vertex vec4 pos = modelview_projection_matrix*vec4(position.xyz, 1.0); -#if !defined(DEPTH_CLAMP) post_pos = pos; +#if !defined(DEPTH_CLAMP) gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); #else gl_Position = pos; #endif + } -- cgit v1.2.3 From 17655e576fc261bb3a9d42542a37eb319510e4d3 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 9 May 2019 16:43:02 -0700 Subject: SL-11149 Fix fullbright colorspace handling and atmo transport. --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 6 +++++- indra/newview/app_settings/shaders/class2/windlight/transportF.glsl | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index f98fc0d518..c104dc884f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -45,6 +45,8 @@ VARYING vec2 vary_texcoord0; vec4 applyWaterFogView(vec3 pos, vec4 color); #endif +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec3 fullbrightAtmosTransport(vec3 light); vec3 fullbrightScaleSoftClip(vec3 light); @@ -70,15 +72,17 @@ void main() #endif color.rgb *= vertex_color.rgb; - + #ifdef WATER_FOG vec3 pos = vary_position; vec4 fogged = applyWaterFogView(pos, vec4(color.rgb, final_alpha)); color.rgb = fogged.rgb; color.a = fogged.a; #else + color.rgb = srgb_to_linear(color.rgb); color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); + color.rgb = linear_to_srgb(color.rgb); color.a = final_alpha; #endif diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 9cb9c723a2..2683b06e1b 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -50,10 +50,12 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransport(vec3 light) { - return atmosTransportFrag(light,getAdditiveColor(), getAtmosAttenuation()); + float brightness = dot(light.rgb, vec3(0.33333)); + return atmosTransportFrag(light, getAdditiveColor() * (brightness * 0.5 + 0.5), getAtmosAttenuation()); } vec3 fullbrightShinyAtmosTransport(vec3 light) { - return atmosTransportFrag(light,getAdditiveColor(), getAtmosAttenuation()); + float brightness = dot(light.rgb, vec3(0.33333)); + return atmosTransportFrag(light, getAdditiveColor() * (brightness * 0.5 + 0.5), getAtmosAttenuation()); } -- cgit v1.2.3 From 27c96405a489327302ebeb7d192788447932d7f1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 13 May 2019 09:49:53 -0700 Subject: SL-10996 Restore old sun matrix gen code. Make sky use correct colorspace. Make sunlight color the CPU-generated WL color when not using atmo shaders or deferred (helps 11107). --- .../newview/app_settings/shaders/class1/deferred/shadowUtil.glsl | 2 +- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index bea016300d..4134220306 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -50,7 +50,7 @@ float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, { float offset = shadow_bias * bias_mul; stc.xyz /= stc.w; - stc.z += offset * 3.0; + stc.z += offset * 2.0; stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; float shadow = cs * 4.0; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 03e5143fca..e41b4b99a3 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -190,11 +190,10 @@ vec3 post_atmo = color.rgb; bloom = fogged.a; #endif +// srgb colorspace debuggables //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; @@ -208,6 +207,11 @@ vec3 post_atmo = color.rgb; color.rgb = srgb_to_linear(color.rgb); } +// linear debuggables +//color.rgb = vec3(final_da); +//color.rgb = vec3(ambient); +//color.rgb = vec3(scol); + frag_color.rgb = color.rgb; frag_color.a = bloom; } -- cgit v1.2.3 From 0412bfdd7248e7d5621469085b34dfea9c4589d4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 13 May 2019 12:10:05 -0700 Subject: SL-11149 More shader tweaks to fullbright transport to get correct coloring while keeping fog fixes. --- .../shaders/class2/windlight/atmosphericsV.glsl | 2 -- .../app_settings/shaders/class2/windlight/transportF.glsl | 4 ++-- .../shaders/class3/windlight/atmosphericsF.glsl | 15 +++++++++++---- .../app_settings/shaders/class3/windlight/transportF.glsl | 12 ++++++++---- 4 files changed, 21 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index 4ac44feee5..d66983a951 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -22,8 +22,6 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - - // VARYING param funcs void setSunlitColor(vec3 v); diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 2683b06e1b..2de708d94b 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -51,11 +51,11 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransport(vec3 light) { float brightness = dot(light.rgb, vec3(0.33333)); - return atmosTransportFrag(light, getAdditiveColor() * (brightness * 0.5 + 0.5), getAtmosAttenuation()); + return atmosTransportFrag(light * 0.5, getAdditiveColor() * (brightness * 0.5 + 0.5), getAtmosAttenuation()); } vec3 fullbrightShinyAtmosTransport(vec3 light) { float brightness = dot(light.rgb, vec3(0.33333)); - return atmosTransportFrag(light, getAdditiveColor() * (brightness * 0.5 + 0.5), getAtmosAttenuation()); + return atmosTransportFrag(light * 0.5, getAdditiveColor() * (brightness * brightness), getAtmosAttenuation()); } diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl index c0a0d4782d..88dfa8a907 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl @@ -37,22 +37,29 @@ uniform vec4 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 vec4 glow; uniform float scene_light_strength; uniform mat3 ssao_effect_mat; +uniform int no_atmo; +uniform float sun_moon_glow_factor; vec3 scaleSoftClipFrag(vec3 light); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { - light *= atten.r; - light += additive; - return (2.0 * light); + if (no_atmo == 1) + { + return light; + } + light *= atten.r; + light += additive; + return light * 2.0; } vec3 atmosLighting(vec3 light) { return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); } - diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index e7e56087ab..08eb119510 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -35,10 +35,12 @@ uniform int no_atmo; vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { if (no_atmo == 1) - { + { return light; } - return (light + additive) * atten * 2.0; + light *= atten.r; + light += additive; + return light * 2.0; } vec3 atmosTransport(vec3 light) @@ -48,10 +50,12 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransport(vec3 light) { - return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); + float brightness = dot(light.rgb, vec3(0.33333)); + return atmosTransportFrag(light * 0.5, getAdditiveColor() * (brightness * 0.5 + 0.5), getAtmosAttenuation()); } vec3 fullbrightShinyAtmosTransport(vec3 light) { - return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); + float brightness = dot(light.rgb, vec3(0.33333)); + return atmosTransportFrag(light * 0.5, getAdditiveColor() * (brightness * brightness), getAtmosAttenuation()); } -- cgit v1.2.3 From 61c2f390210720132c861a157b66cc77fe273d51 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 13 May 2019 13:54:55 -0700 Subject: SL-11107 --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 8fea4e5d27..180f38b1e1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -157,6 +157,6 @@ void main() vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); frag_data[0] = vec4(color.rgb, 0); // diffuse - frag_data[1] = vec4(specular * 0.15, 0.5); // speccolor, spec + frag_data[1] = vec4(specular * 0.5, 0.5); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 0, 0 } -- cgit v1.2.3 From b143aa96fcd6d16558464c98bcfd9984f7d29750 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 13 May 2019 15:33:48 -0700 Subject: SL-10856 Modify calc of sunlight to avoid clipping in gamma correct on values outside 0-1 range. Modify shaders to put back ambient clamp tuned to be close to ambient contrib in low/mid lighting. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 3 +-- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 +-- .../newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 3 +-- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 6 +++--- .../newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 3 +-- indra/newview/app_settings/shaders/class3/lighting/lightV.glsl | 2 +- 6 files changed, 8 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index dbd7abd7e5..b439fbbff6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -223,8 +223,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - //ambient = max(getAmbientClamp(), ambient); // keeps shadows dark - ambient = 1.0 - ambient; + ambient = min(getAmbientClamp(), 1.0 - ambient); vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 7533762a96..274d1818f0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -320,8 +320,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - //ambient = max(getAmbientClamp(), ambient); - ambient = 1.0 - ambient; + ambient = min(getAmbientClamp(), 1.0 - ambient); vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index b6e3951ee3..2a24915ade 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -106,8 +106,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - //ambient = max(getAmbientClamp(), ambient); - ambient = 1.0 - ambient; + ambient = min(getAmbientClamp(), 1.0 - ambient); vec3 sun_contrib = final_da * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 6788cc1f63..7f5ac00963 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -44,7 +44,7 @@ uniform float sun_moon_glow_factor; float getAmbientClamp() { - return 0.66f; + return 0.2f; } void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { @@ -137,7 +137,7 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o + tmpAmbient)); //brightness of surface both sunlight and ambient - sunlit = sunlight.rgb * 0.5; - amblit = tmpAmbient.rgb * .25; + sunlit = sunlight.rgb; + amblit = tmpAmbient.rgb; additive *= vec3(1.0 - temp1); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index e41b4b99a3..39b13b46cc 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -116,8 +116,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - //ambient = max(getAmbientClamp(), ambient); - ambient = 1.0 - ambient; + ambient = min(getAmbientClamp(), 1.0 - ambient); vec3 sun_contrib = min(scol, final_da) * sunlit; diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index 48c883d98a..2f64ab25cb 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -32,7 +32,7 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { vec4 c = sumLights(pos, norm, color); - c.rgb += atmosAmbient() * color.rgb; + c.rgb += atmosAmbient() * color.rgb * 0.25; return c; } -- cgit v1.2.3 From b9cd2ca7907e1543b77597fb7d9280944a9fa4bd Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 14 May 2019 08:24:23 -0700 Subject: SL-11085 Reduce spec bloom further. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 274d1818f0..dabdf69681 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -357,7 +357,7 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scol*spec.rgb*0.25; + vec3 speccol = sun_contrib*scol*spec.rgb / 16.0f; speccol = clamp(speccol, vec3(0), vec3(1)); bloom = dot(speccol, speccol); color += speccol; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 2a24915ade..4e8062977d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -143,7 +143,7 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scontrib*spec.rgb*0.25; + vec3 speccol = sun_contrib*scontrib*spec.rgb / 16.0f; speccol = clamp(speccol, vec3(0), vec3(1)); bloom += dot(speccol, speccol); color += speccol; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 39b13b46cc..5aaac382a5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -153,7 +153,7 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scontrib*spec.rgb * 0.25; + vec3 speccol = sun_contrib*scontrib*spec.rgb / 16.0; speccol = clamp(speccol, vec3(0), vec3(1)); bloom += dot (speccol, speccol); color += speccol; -- cgit v1.2.3 From 8d30b644f2a9620e361ead27367e49ce700d318e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 16 May 2019 08:33:09 -0700 Subject: SL-11195 Adjust ambient clamp up to get closer match to release viewer for existing content. --- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 7f5ac00963..6c22ef5636 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -44,7 +44,7 @@ uniform float sun_moon_glow_factor; float getAmbientClamp() { - return 0.2f; + return 0.45f; } void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { -- cgit v1.2.3 From cce6254aec2de6606b4940d961cef6cceb549d61 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 16 May 2019 09:23:07 -0700 Subject: SL-11085 Modify new spec response to better match old gloss response curve. Tuned at 255, 192, 160, 128, 64, and 32 glossiness. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 8 ++++---- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 8 ++++---- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index dabdf69681..0880a73b26 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -357,10 +357,10 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scol*spec.rgb / 16.0f; - speccol = clamp(speccol, vec3(0), vec3(1)); - bloom = dot(speccol, speccol); - color += speccol; + vec3 sp = sun_contrib*scol / 16.0f; + sp = clamp(sp, vec3(0), vec3(1)); + bloom = dot(sp, sp) / 6.0; + color += sp * spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 4e8062977d..4a6dbc0313 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -143,10 +143,10 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scontrib*spec.rgb / 16.0f; - speccol = clamp(speccol, vec3(0), vec3(1)); - bloom += dot(speccol, speccol); - color += speccol; + vec3 sp = sun_contrib*scontrib / 16.0; + sp = clamp(sp, vec3(0), vec3(1)); + bloom += dot(sp, sp) / 6.0; + color += sp * spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 5aaac382a5..1b2b835ad1 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -153,10 +153,10 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = sun_contrib*scontrib*spec.rgb / 16.0; - speccol = clamp(speccol, vec3(0), vec3(1)); - bloom += dot (speccol, speccol); - color += speccol; + vec3 sp = sun_contrib*scontrib / 16.0; + sp = clamp(sp, vec3(0), vec3(1)); + bloom += dot (sp, sp) / 6.0; + color += sp * spec.rgb; } } -- cgit v1.2.3 From b3c0218a31b9d7dd699cf3944bbcfc35e9adbd49 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 16 May 2019 14:14:02 -0700 Subject: Revert lighting changes for 10856 causing knock-on. --- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 4 ++-- indra/newview/app_settings/shaders/class3/lighting/lightV.glsl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 6c22ef5636..68eb671e7c 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -137,7 +137,7 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o + tmpAmbient)); //brightness of surface both sunlight and ambient - sunlit = sunlight.rgb; - amblit = tmpAmbient.rgb; + sunlit = sunlight.rgb * 0.5; + amblit = tmpAmbient.rgb * .25; additive *= vec3(1.0 - temp1); } diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index 2f64ab25cb..48c883d98a 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -32,7 +32,7 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { vec4 c = sumLights(pos, norm, color); - c.rgb += atmosAmbient() * color.rgb * 0.25; + c.rgb += atmosAmbient() * color.rgb; return c; } -- cgit v1.2.3 From c8ae0c0c3f1747faf36d27a63c66755a1bfeeb3c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 17 May 2019 14:21:52 -0700 Subject: SL-11112 Fix blend between reflected/refracted water maps (make less transparent) and fix setting of water fog color alpha on low end to better match prev behavior of setting the internal control value in that case. --- .../shaders/class1/deferred/softenLightF.glsl | 2 +- .../app_settings/shaders/class1/deferred/waterF.glsl | 19 ++++++++++++------- .../shaders/class1/environment/waterF.glsl | 7 ++++--- 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 4a6dbc0313..c81d0f97da 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -153,7 +153,7 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; #ifndef WATER_FOG - color.rgb += diffuse_srgb.a * diffuse_srgb.rgb; + color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); #endif if (envIntensity > 0.0) diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 180f38b1e1..914e17beed 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -64,7 +64,9 @@ VARYING vec4 view; VARYING vec4 vary_position; vec2 encode_normal(vec3 n); -vec3 scaleSoftClipFrag(vec3 l); +vec3 scaleSoftClip(vec3 l); +vec3 srgb_to_linear(vec3 c); +vec3 linear_to_srgb(vec3 c); vec3 BlendNormal(vec3 bump1, vec3 bump2) { @@ -75,7 +77,7 @@ vec3 BlendNormal(vec3 bump1, vec3 bump2) void main() { vec4 color; - float dist = length(view.xy); + float dist = length(view.xyz); //normalize view vector vec3 viewVec = normalize(view.xyz); @@ -127,7 +129,8 @@ void main() vec4 refcol = refcol1 + refcol2 + refcol3; float df1 = df.x + df.y + df.z; - refcol *= df1 * 0.333; + df1 *= 0.333; + refcol *= df1; vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; wavef.z *= max(-viewVec.z, 0.1); @@ -142,16 +145,18 @@ void main() vec4 baseCol = texture2D(refTex, refvec4); refcol = mix(baseCol*df2, refcol, dweight); - + //figure out distortion vector (ripply) vec2 distort2 = distort+wavef.xy*(refScale * 0.01)/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); - + //mix with reflection // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); - + color.rgb = mix(fb.rgb, refcol.rgb, df1 + 0.6); + color.rgb *= 2.0f; + color.rgb = scaleSoftClip(color.rgb); + vec4 pos = vary_position; vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index a4e3f94816..043815c824 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -121,7 +121,8 @@ void main() vec4 refcol = refcol1 + refcol2 + refcol3; float df1 = df.x + df.y + df.z; - refcol *= df1 * 0.333; + df1 *= 0.3333; + refcol *= df1; vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; @@ -144,13 +145,13 @@ void main() spec = pow(spec, 128.0); //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); + vec2 distort2 = distort+wavef.xy*(refScale*0.01)/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); //mix with reflection // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); + color.rgb = mix(fb.rgb, refcol.rgb, df1 + 0.6); color.rgb += spec * specular; color.rgb = atmosTransport(color.rgb); -- cgit v1.2.3 From 7f3f69002b7c7612fc89a3c5c571066a34e5baff Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 17 May 2019 15:39:27 -0700 Subject: SL-11220 Fix transport when no_atmo == 1 (HUD rendering) was in play. --- .../app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/transportF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl index 9f049cb8fb..9c42b84eca 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsHelpersV.glsl @@ -37,7 +37,7 @@ uniform int no_atmo; vec3 atmosAmbient() { - if (no_atmo == 1) return vec3(0.66); + if (no_atmo == 1) return vec3(0.16); return getAmblitColor(); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 2de708d94b..f9d2a36818 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -36,7 +36,7 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { if (no_atmo == 1) { - return light; + return light * 2.0; } light *= atten.r; light += additive; -- cgit v1.2.3 From e9dbee00262a437e4b3f971b37ea636e92032133 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 21 May 2019 16:00:45 -0700 Subject: SL-11238 Fix ambient light inputs to the renderer. Fix 3rd sky shader w/ mistaken density mod conversion. Make ambient clamp apply to all modes. Tune ALM ambient clamp to match non-ALM. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 4 +++- .../shaders/class1/deferred/materialF.glsl | 4 +++- .../shaders/class1/deferred/softenLightF.glsl | 13 ++++++++++--- .../app_settings/shaders/class1/lighting/lightV.glsl | 3 ++- .../shaders/class1/windlight/atmosphericsFuncs.glsl | 2 +- .../app_settings/shaders/class2/deferred/skyF.glsl | 7 +++++-- .../shaders/class2/deferred/softenLightF.glsl | 19 ++++++++++--------- .../app_settings/shaders/class2/windlight/skyV.glsl | 2 +- .../app_settings/shaders/class3/lighting/lightV.glsl | 3 ++- 9 files changed, 37 insertions(+), 20 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index b439fbbff6..e0bf58a5c2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -223,7 +223,9 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = min(getAmbientClamp(), 1.0 - ambient); + + float ambient_clamp = getAmbientClamp() + 0.2; + ambient = (1.0 - ambient) * ambient_clamp; vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 0880a73b26..b9c16bfa11 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -320,7 +320,9 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = min(getAmbientClamp(), 1.0 - ambient); + + float ambient_clamp = getAmbientClamp() + 0.2; + ambient = (1.0 - ambient) * ambient_clamp; vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index c81d0f97da..40bb705326 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -106,7 +106,10 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = min(getAmbientClamp(), 1.0 - ambient); + + ambient = (1.0 - ambient); + float ambient_clamp = getAmbientClamp() + 0.1; + ambient *= ambient_clamp; vec3 sun_contrib = final_da * sunlit; @@ -179,11 +182,10 @@ vec3 post_atmo = color.rgb; bloom = fogged.a; #endif +// srgb colorspace debuggables //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; @@ -197,6 +199,11 @@ vec3 post_atmo = color.rgb; color.rgb = srgb_to_linear(color.rgb); } +// linear debuggables +//color.rgb = vec3(final_da); +//color.rgb = vec3(ambient); +//color.rgb = vec3(scol); + frag_color.rgb = color.rgb; frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl index 38230836eb..cf635ffa3f 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl @@ -28,11 +28,12 @@ // All lights, no specular highlights vec3 atmosAmbient(); vec4 sumLights(vec3 pos, vec3 norm, vec4 color); +float getAmbientClamp(); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { vec4 c = sumLights(pos, norm, color); - c.rgb += atmosAmbient() * color.rgb * 0.5; + c.rgb += atmosAmbient() * color.rgb * 0.5 * getAmbientClamp(); return c; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 68eb671e7c..55ffbdcc46 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -44,7 +44,7 @@ uniform float sun_moon_glow_factor; float getAmbientClamp() { - return 0.45f; + return 0.9; } void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index eb95890e08..dca2862b5a 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -88,6 +88,7 @@ vec3 halo22(float d) /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); +vec3 srgb_to_linear(vec3 c); void main() { @@ -194,10 +195,12 @@ void main() color.rgb += halo_22; - color *= 2.; + color.rgb *= 2.; + color.rgb = scaleSoftClip(color.rgb); + color.rgb = srgb_to_linear(color.rgb); /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); + frag_data[0] = vec4(color.rgb, 1.0); frag_data[1] = vec4(0.0,0.0,0.0,0.0); frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 1b2b835ad1..94abcf08ed 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -24,6 +24,7 @@ */ #extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_shader_texture_lod : enable /*[EXTRA_CODE_HERE]*/ @@ -87,14 +88,11 @@ void main() float da = dot(normalize(norm.xyz), light_dir.xyz); da = clamp(da, -1.0, 1.0); - - 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); - + vec4 diffuse_linear = texture2DRect(diffuseRect, tc); + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); // clamping to alpha value kills underwater shadows... //scol = max(scol_ambocc.r, diffuse_linear.a); @@ -116,7 +114,10 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = min(getAmbientClamp(), 1.0 - ambient); + + float ambient_clamp = getAmbientClamp() + 0.1; + ambient = (1.0 - ambient); + ambient *= ambient_clamp; vec3 sun_contrib = min(scol, final_da) * sunlit; @@ -129,7 +130,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_srgb.rgb; + color.rgb *= diffuse_linear.rgb; vec3 post_diffuse = color.rgb; @@ -155,7 +156,7 @@ vec3 post_diffuse = color.rgb; float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 sp = sun_contrib*scontrib / 16.0; sp = clamp(sp, vec3(0), vec3(1)); - bloom += dot (sp, sp) / 6.0; + bloom += dot(sp, sp) / 6.0; color += sp * spec.rgb; } } @@ -163,7 +164,7 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; #ifndef WATER_FOG - color.rgb += diffuse_srgb.a * diffuse_srgb.rgb; + color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); #endif if (envIntensity > 0.0) diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index a23a5d4076..5b1eb55e0c 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -88,7 +88,7 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier * 0.45; + float dens_mul = density_multiplier; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index 48c883d98a..effe4c5971 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -28,11 +28,12 @@ // All lights, no specular highlights vec3 atmosAmbient(); vec4 sumLights(vec3 pos, vec3 norm, vec4 color); +float getAmbientClamp(); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { vec4 c = sumLights(pos, norm, color); - c.rgb += atmosAmbient() * color.rgb; + c.rgb += atmosAmbient() * color.rgb * getAmbientClamp(); return c; } -- cgit v1.2.3 From db091d23db70952b4ad8b610ef02942a8f13f223 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 22 May 2019 11:00:30 -0700 Subject: SL-10969 Fix linear attenuation on forward projector lighting. Revert setup of falloff to prev code. Revert deferred water spec and tweak refl/refr blend. --- .../shaders/class1/deferred/alphaF.glsl | 18 +++++--- .../shaders/class1/deferred/materialF.glsl | 23 +++++----- .../shaders/class1/deferred/multiSpotLightF.glsl | 6 ++- .../shaders/class1/deferred/pointLightF.glsl | 2 +- .../shaders/class1/deferred/softenLightF.glsl | 2 +- .../shaders/class1/deferred/spotLightF.glsl | 6 ++- .../shaders/class1/deferred/waterF.glsl | 52 +++++++++++++--------- .../shaders/class2/deferred/multiSpotLightF.glsl | 16 ++----- .../shaders/class2/deferred/spotLightF.glsl | 19 +++----- 9 files changed, 78 insertions(+), 66 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index e0bf58a5c2..1c826790fb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -107,7 +107,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec return col; } - if (d > 0.0) + if (d > 0.0 && la > 0.0 && fa > 0.0) { //normalize light vector lv = normalize(lv); @@ -115,13 +115,19 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec da = dot(norm, lv); da = clamp(da, 0.0, 1.0); + +la /= 20.0f; //distance attenuation - float dist = (la > 0) ? d/la : 1.0f; - fa += 1.0f; - float dist_atten = (fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 0.0f; + 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.2f; + + if (dist_atten < 0.0) + { + return col; + } // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); @@ -224,7 +230,7 @@ void main() ambient *= 0.5; ambient *= ambient; - float ambient_clamp = getAmbientClamp() + 0.2; + float ambient_clamp = getAmbientClamp() + 0.1; ambient = (1.0 - ambient) * ambient_clamp; vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index b9c16bfa11..373727f572 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -110,17 +110,18 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe return col; } - if (d > 0.0) - { + if (d > 0.0 && la > 0.0 && fa > 0.0) + { //normalize light vector lv = normalize(lv); - + +la /= 20.0f; + //distance attenuation - float dist = (la > 0) ? d/la : 1.0f; - fa += 1.0f; - float dist_atten = ( fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; + float dist = d/la; + + float dist_atten = (fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; dist_atten *= dist_atten; - dist_atten *= 2.2f; if (dist_atten <= 0) { @@ -139,15 +140,15 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float lit = max(da * dist_atten, 0.0); float amb_da = ambiance; - if (da > 0) - { + if (lit > 0) + { col = light_col*lit*diffuse; amb_da += (da*0.5 + 0.5) * ambiance; amb_da += (da*da*0.5+0.5) * ambiance; } amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); - col.rgb += amb_da * 0.25 * light_col * diffuse; + col.rgb += amb_da * 0.5 * light_col * diffuse; if (spec.a > 0.0) { @@ -321,7 +322,7 @@ void main() ambient *= 0.5; ambient *= ambient; - float ambient_clamp = getAmbientClamp() + 0.2; + float ambient_clamp = getAmbientClamp() + 0.1; ambient = (1.0 - ambient) * ambient_clamp; vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 2569e49743..2dd9c1f057 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -72,10 +72,12 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 getNorm(vec2 pos_screen); +vec3 srgb_to_linear(vec3 c); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -95,6 +97,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -112,6 +115,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = tc-vec2(0.5); @@ -263,7 +267,7 @@ void main() } } } - +//col.rgb = vec3(0); frag_color.rgb = col; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index f8264d971c..73bc1141b0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -124,7 +124,7 @@ void main() { discard; } - +//col.rgb = vec3(0); frag_color.rgb = col; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 40bb705326..4ab68eaf3b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -156,7 +156,7 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; #ifndef WATER_FOG - color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); + color.rgb += diffuse_srgb.rgb * diffuse_srgb.a; #endif if (envIntensity > 0.0) diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index d09bc25334..c6417fa532 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -71,10 +71,12 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 getNorm(vec2 pos_screen); +vec3 srgb_to_linear(vec3 c); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -94,6 +96,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -111,6 +114,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = tc-vec2(0.5); @@ -268,7 +272,7 @@ void main() } } } - +//col.rgb = vec3(0); frag_color.rgb = col; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 914e17beed..0459b39bd9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -129,8 +129,7 @@ void main() vec4 refcol = refcol1 + refcol2 + refcol3; float df1 = df.x + df.y + df.z; - df1 *= 0.333; - refcol *= df1; + refcol *= df1 * 0.333; vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; wavef.z *= max(-viewVec.z, 0.1); @@ -145,23 +144,34 @@ void main() vec4 baseCol = texture2D(refTex, refvec4); refcol = mix(baseCol*df2, refcol, dweight); - - //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*(refScale * 0.01)/max(dmod*df1, 1.0); - - vec4 fb = texture2D(screenTex, distort2); - - //mix with reflection - // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 + 0.6); - color.rgb *= 2.0f; - color.rgb = scaleSoftClip(color.rgb); - - vec4 pos = vary_position; - - vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - - frag_data[0] = vec4(color.rgb, 0); // diffuse - frag_data[1] = vec4(specular * 0.5, 0.5); // speccolor, spec - frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 0, 0 + refcol.rgb = srgb_to_linear(refcol.rgb); + + //get specular component + float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); + + //harden specular + spec = pow(spec, 128.0); + + //figure out distortion vector (ripply) + vec2 distort2 = distort+wavef.xy*(refScale*0.01)/max(dmod*df1, 1.0); + + vec4 fb = texture2D(screenTex, distort2); + + //mix with reflection + // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.3 + 0.7); + + vec4 pos = vary_position; + + color.rgb += spec * specular; + + color.rgb = atmosTransport(color.rgb); + color.rgb = scaleSoftClip(color.rgb); + color.a = spec * sunAngle2 * 0.88; + + vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); + + frag_data[0] = vec4(color.rgb, color); // diffuse + frag_data[1] = vec4(0); // speccolor, spec + frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 } diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 54ec534d14..bc879948e4 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -72,20 +72,12 @@ 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); - -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); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); float det = min(lod/(proj_lod*0.5), 1.0); @@ -104,7 +96,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); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -122,7 +114,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); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = tc-vec2(0.5); @@ -295,7 +287,7 @@ void main() //not sure why, but this line prevents MATBUG-194 col = max(col, vec3(0.0)); - +//col.rgb = vec3(0); frag_color.rgb = col; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 2ef7cffe9d..43f283bede 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -73,15 +73,11 @@ uniform mat4 inv_proj; vec3 getNorm(vec2 pos_screen); 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); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -101,7 +97,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); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -119,7 +115,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); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = tc-vec2(0.5); @@ -174,8 +170,8 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff + 1.0; - float dist_atten = min(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 1.0); + float fa = falloff+1.0; + float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; @@ -187,8 +183,7 @@ void main() lv = proj_origin-pos.xyz; lv = normalize(lv); float da = dot(norm, lv); - da = clamp(da, 0.0, 1.0); - + vec3 col = vec3(0,0,0); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; @@ -294,7 +289,7 @@ void main() //not sure why, but this line prevents MATBUG-194 col = max(col, vec3(0.0)); - +//col.rgb = vec3(0); frag_color.rgb = col; frag_color.a = 0.0; } -- cgit v1.2.3 From 360b3230bbfbda7988eee84a8ed04fa1696ca70a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 22 May 2019 13:16:23 -0700 Subject: SL-11260 Make terrain underwater shader not try to light said terrain. Fix colorspace of reflected color in non-ALM shading. Tweak transparency of water further. --- .../newview/app_settings/shaders/class1/deferred/waterF.glsl | 11 ++++++----- .../shaders/class1/environment/terrainWaterF.glsl | 5 ++++- .../app_settings/shaders/class1/environment/waterF.glsl | 7 +++---- indra/newview/app_settings/shaders/class2/windlight/skyF.glsl | 1 - 4 files changed, 13 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 0459b39bd9..2235ab12a4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -153,24 +153,25 @@ void main() spec = pow(spec, 128.0); //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*(refScale*0.01)/max(dmod*df1, 1.0); + vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); //mix with reflection // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.3 + 0.7); + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.4 + 0.6); vec4 pos = vary_position; color.rgb += spec * specular; - color.rgb = atmosTransport(color.rgb); + //color.rgb = atmosTransport(color.rgb); color.rgb = scaleSoftClip(color.rgb); - color.a = spec * sunAngle2 * 0.88; + color.a = spec * sunAngle2; + vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - + frag_data[0] = vec4(color.rgb, color); // diffuse frag_data[1] = vec4(0); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl index 3b0c81fc71..ddbe3ebe10 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl @@ -59,7 +59,10 @@ void main() vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); /// Add WL Components - outColor.rgb = atmosLighting(outColor.rgb * vertex_color.rgb); + outColor.rgb *= vertex_color.rgb; + + // SL-11260... + //outColor.rgb = atmosLighting(outColor.rgb); outColor = applyWaterFog(outColor); frag_color = outColor; diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index 043815c824..f033c0e7c4 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -121,7 +121,6 @@ void main() vec4 refcol = refcol1 + refcol2 + refcol3; float df1 = df.x + df.y + df.z; - df1 *= 0.3333; refcol *= df1; vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; @@ -151,11 +150,11 @@ void main() //mix with reflection // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 + 0.6); + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.4 + 0.6); color.rgb += spec * specular; - color.rgb = atmosTransport(color.rgb); - color.rgb = scaleSoftClip(color.rgb); + //color.rgb = atmosTransport(color.rgb); + color.rgb = scaleSoftClip(color.rgb * 0.5); color.a = spec * sunAngle2; #if defined(WATER_EDGE) diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl index 28d185b9af..02e10b7b50 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl @@ -50,7 +50,6 @@ void main() vec4 color; color = vary_HazeColor; color *= 2.; - /// Gamma correct for WL (soft clip effect). frag_color.rgb = scaleSoftClip(color.rgb); frag_color.a = 1.0; -- cgit v1.2.3 From d0a0eede63fdbd4ba597b86cbfbeb5b394ed2395 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 23 May 2019 09:58:33 -0700 Subject: Add render debug controls for forcing disable of ambient, sun, and local light contributions (engages AMBIENT_KILL, SUNLIGHT_KILL, and LOCAL_LIGHT_KILL defines in shaders to accomplish those tasks as required by each render mode). --- .../shaders/class1/deferred/alphaF.glsl | 81 ++++++------ .../shaders/class1/deferred/materialF.glsl | 136 ++++++++++----------- .../shaders/class1/deferred/multiPointLightF.glsl | 8 +- .../shaders/class1/deferred/multiSpotLightF.glsl | 9 +- .../shaders/class1/deferred/softenLightF.glsl | 4 + .../shaders/class1/deferred/spotLightF.glsl | 17 ++- .../shaders/class1/lighting/lightV.glsl | 4 + .../shaders/class1/lighting/sumLightsV.glsl | 8 ++ .../shaders/class2/deferred/multiSpotLightF.glsl | 11 +- .../shaders/class2/deferred/softenLightF.glsl | 4 + .../shaders/class2/deferred/spotLightF.glsl | 17 ++- .../shaders/class2/lighting/sumLightsV.glsl | 7 ++ .../shaders/class3/lighting/lightV.glsl | 4 + .../shaders/class3/lighting/sumLightsV.glsl | 7 ++ 14 files changed, 176 insertions(+), 141 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 1c826790fb..4a12659d56 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -88,64 +88,49 @@ float getAmbientClamp(); vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance) { - //get light vector - vec3 lv = lp.xyz-v; - - vec4 proj_tc = proj_mat * lp; - - //get distance - float d = length(lv); - float da = 1.0; - vec3 col = vec3(0); - if (proj_tc.z < 0 - || proj_tc.z > 1 - || proj_tc.x < 0 - || proj_tc.x > 1 - || proj_tc.y < 0 - || proj_tc.y > 1) - { - return col; - } + //get light vector + vec3 lv = lp.xyz-v; - if (d > 0.0 && la > 0.0 && fa > 0.0) - { - //normalize light vector - lv = normalize(lv); - vec3 norm = normalize(n); +la /= 20.0f; - da = dot(norm, lv); - da = clamp(da, 0.0, 1.0); + //get distance + float d = length(lv); + + float da = 1.0; -la /= 20.0f; - - //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; + vec3 col = vec3(0); - if (dist_atten < 0.0) - { - return col; - } + if (d > 0.0 && la > 0.0 && fa > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //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.0f; + + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 - // 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); - // to match spotLight (but not multiSpotLight) *sigh* - float lit = max(da * dist_atten,0.0); + float lit = max(da * dist_atten,0.0); +ambiance = 0.0f; float amb_da = ambiance; if (lit > 0) { col = lit * light_col * diffuse; amb_da += (da*0.5+0.5) * ambiance; - amb_da += (da*da*0.5 + 0.5) * ambiance; } + amb_da += (da*da*0.5 + 0.5) * ambiance; amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); - col.rgb += amb_da * 0.5 * light_col * diffuse; + col.rgb += amb_da * light_col * diffuse; // no spec for alpha shader... } @@ -223,7 +208,6 @@ void main() vec4 color = vec4(0.0); - color.rgb = amblit; color.a = final_alpha; float ambient = da; @@ -235,11 +219,16 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit; +#if !defined(AMBIENT_KILL) + color.rgb = amblit; color.rgb *= ambient; +#endif vec3 post_ambient = color.rgb; +#if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; +#endif vec3 post_sunlight = color.rgb; @@ -257,7 +246,7 @@ vec3 post_atmo = color.rgb; // to linear! color.rgb = srgb_to_linear(color.rgb); - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.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 * 0.5); + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.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); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -268,7 +257,9 @@ vec3 post_atmo = color.rgb; LIGHT_LOOP(7) // sum local light contrib in linear colorspace +#if !defined(LOCAL_LIGHT_KILL) color.rgb += light.rgb; +#endif // back to sRGB as we're going directly to the final RT post-deferred gamma correction color.rgb = linear_to_srgb(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 373727f572..1c0516923e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -88,17 +88,19 @@ 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) { - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float d = length(lv); - - float da = 1.0; + vec3 col = vec3(0); + +la /= 20.0f; - vec3 col = vec3(0,0,0); + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float d = length(lv); + + float da = 1.0; - vec4 proj_tc = proj_mat * lp; + /*vec4 proj_tc = proj_mat * lp; if (proj_tc.z < 0 || proj_tc.z > 1 @@ -108,77 +110,68 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe || proj_tc.y > 1) { return col; - } + }*/ - if (d > 0.0 && la > 0.0 && fa > 0.0) + if (d > 0.0 && la > 0.0 && fa > 0.0) { - //normalize light vector - lv = normalize(lv); - -la /= 20.0f; - - //distance attenuation - float dist = d/la; - - float dist_atten = (fa > 0) ? clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0) : 1.0f; - dist_atten *= dist_atten; - - if (dist_atten <= 0) - { - return col; - } - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - - //angular attenuation - da = dot(n, lv); - da = clamp(da, 0.0, 1.0); - - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - float lit = max(da * dist_atten, 0.0); + //normalize light vector + lv = normalize(lv); + + //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.0f; + + // 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); + + float lit = max(da * dist_atten, 0.0); float amb_da = ambiance; if (lit > 0) { col = light_col*lit*diffuse; amb_da += (da*0.5 + 0.5) * ambiance; - amb_da += (da*da*0.5+0.5) * ambiance; } + amb_da += (da*da*0.5+0.5) * ambiance; amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); - col.rgb += amb_da * 0.5 * light_col * diffuse; - - if (spec.a > 0.0) - { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = lit*scol*light_col.rgb*spec.rgb; + col.rgb += amb_da * light_col * diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = lit*scol*light_col.rgb*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); - col += speccol; + 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); - } - } - } + 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); + } + } + } - return max(col, vec3(0.0,0.0,0.0)); + return max(col, vec3(0.0,0.0,0.0)); } #else @@ -321,18 +314,22 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - + float ambient_clamp = getAmbientClamp() + 0.1; ambient = (1.0 - ambient) * ambient_clamp; vec3 sun_contrib = min(final_da, shadow) * sunlit; +#if !defined(AMBIENT_KILL) color.rgb = amblit; color.rgb *= ambient; +#endif vec3 post_ambient = color.rgb; +#if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; +#endif vec3 post_sunlight = color.rgb; @@ -398,7 +395,7 @@ vec3 post_atmo = color.rgb; vec3 light = vec3(0,0,0); - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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_linear.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 ); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -408,11 +405,12 @@ vec3 post_atmo = color.rgb; LIGHT_LOOP(6) LIGHT_LOOP(7) - glare = min(glare, 1.0); float al = max(diffuse_linear.a,glare)*vertex_color.a; +#if !defined(LOCAL_LIGHT_KILL) color.rgb += light.rgb; +#endif // (only) post-deferred needs inline gamma correction color.rgb = linear_to_srgb(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 29298d7c07..367680556a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -61,6 +61,11 @@ vec3 getNorm(vec2 pos_screen); void main() { + vec3 out_col = vec3(0,0,0); + +#if defined(LOCAL_LIGHT_KILL) + discard; +#else vec2 frag = (vary_fragcoord.xy*0.5+0.5)*screen_res; vec3 pos = getPosition(frag.xy).xyz; if (pos.z < far_z) @@ -74,7 +79,6 @@ void main() vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb; float noise = texture2D(noiseMap, frag.xy/128.0).b; - vec3 out_col = vec3(0,0,0); vec3 npos = normalize(-pos); // As of OSX 10.6.7 ATI Apple's crash when using a variable size loop @@ -130,7 +134,7 @@ void main() } } } - +#endif frag_color.rgb = out_col; frag_color.a = 0.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 2dd9c1f057..c81d633880 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -130,6 +130,11 @@ vec4 getPosition(vec2 pos_screen); void main() { + vec3 col = vec3(0,0,0); + +#if defined(LOCAL_LIGHT_KILL) + discard; +#else vec4 frag = vary_fragcoord; frag.xyz /= frag.w; frag.xyz = frag.xyz*0.5+0.5; @@ -171,7 +176,6 @@ void main() lv = normalize(lv); float da = dot(norm, lv); - vec3 col = vec3(0,0,0); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; vec3 dlit = vec3(0, 0, 0); @@ -267,7 +271,8 @@ void main() } } } -//col.rgb = vec3(0); +#endif + frag_color.rgb = col; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 4ab68eaf3b..c7426788c4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -113,12 +113,16 @@ void main() vec3 sun_contrib = final_da * sunlit; +#if !defined(AMBIENT_KILL) color.rgb = amblit; color.rgb *= ambient; +#endif vec3 post_ambient = color.rgb; +#if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; +#endif vec3 post_sunlight = color.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index c6417fa532..55c740d100 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -129,6 +129,11 @@ vec4 getPosition(vec2 pos_screen); void main() { + vec3 col = vec3(0,0,0); + +#if defined(LOCAL_LIGHT_KILL) + discard; +#else vec4 frag = vary_fragcoord; frag.xyz /= frag.w; frag.xyz = frag.xyz*0.5+0.5; @@ -142,12 +147,10 @@ void main() { discard; } - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; float envIntensity = norm.z; norm = getNorm(frag.xy); - norm = normalize(norm); float l_dist = -dot(lv, proj_n); @@ -173,14 +176,9 @@ void main() lv = normalize(lv); float da = dot(norm, lv); - vec3 col = vec3(0,0,0); - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - vec4 spec = texture2DRect(specularRect, frag.xy); - - float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 dlit = vec3(0, 0, 0); @@ -216,7 +214,6 @@ void main() amb_da = min(amb_da, 1.0-lit); col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a*diff_tex.rgb; } - if (spec.a > 0.0) { @@ -243,7 +240,6 @@ void main() } } - if (envIntensity > 0.0) { vec3 ref = reflect(normalize(pos), norm); @@ -272,7 +268,8 @@ void main() } } } -//col.rgb = vec3(0); +#endif + frag_color.rgb = col; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl index cf635ffa3f..5e39d1629d 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl @@ -33,7 +33,11 @@ float getAmbientClamp(); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { vec4 c = sumLights(pos, norm, color); + +#if !defined(AMBIENT_KILL) c.rgb += atmosAmbient() * color.rgb * 0.5 * getAmbientClamp(); +#endif + return c; } diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl index 761ac29ee2..0c3ea4231e 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl @@ -39,7 +39,15 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color) col.rgb = light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); col.rgb = scaleDownLight(col.rgb); + +#if defined(LOCAL_LIGHT_KILL) + col.rgb = vec3(0); +#endif + +#if !defined(SUNLIGHT_KILL) col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); +#endif + col.rgb = min(col.rgb*color.rgb, 1.0); return col; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index bc879948e4..bcce4c041a 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -129,6 +129,12 @@ vec4 getPosition(vec2 pos_screen); void main() { + + vec3 col = vec3(0,0,0); + +#if defined(LOCAL_LIGHT_KILL) + discard; +#else vec4 frag = vary_fragcoord; frag.xyz /= frag.w; frag.xyz = frag.xyz*0.5+0.5; @@ -183,8 +189,6 @@ void main() lv = proj_origin-pos.xyz; lv = normalize(lv); float da = dot(norm, lv); - - vec3 col = vec3(0,0,0); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; @@ -284,10 +288,11 @@ void main() } } } +#endif //not sure why, but this line prevents MATBUG-194 col = max(col, vec3(0.0)); -//col.rgb = vec3(0); + 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 94abcf08ed..7f83e168bb 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -121,12 +121,16 @@ void main() vec3 sun_contrib = min(scol, final_da) * sunlit; +#if !defined(AMBIENT_KILL) color.rgb = amblit; color.rgb *= ambient; +#endif vec3 post_ambient = color.rgb; +#if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; +#endif vec3 post_sunlight = color.rgb; diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 43f283bede..77f6e6f7ac 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -130,6 +130,11 @@ vec4 getPosition(vec2 pos_screen); void main() { + vec3 col = vec3(0,0,0); + +#if defined(LOCAL_LIGHT_KILL) + discard; +#else vec4 frag = vary_fragcoord; frag.xyz /= frag.w; frag.xyz = frag.xyz*0.5+0.5; @@ -184,12 +189,8 @@ void main() lv = normalize(lv); float da = dot(norm, lv); - vec3 col = vec3(0,0,0); - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - vec4 spec = texture2DRect(specularRect, frag.xy); - vec3 dlit = vec3(0, 0, 0); float noise = texture2D(noiseMap, frag.xy/128.0).b; @@ -227,7 +228,6 @@ void main() col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; } - if (spec.a > 0.0) { @@ -253,10 +253,6 @@ void main() col += speccol; } } - - - - if (envIntensity > 0.0) { @@ -286,10 +282,11 @@ void main() } } } +#endif //not sure why, but this line prevents MATBUG-194 col = max(col, vec3(0.0)); -//col.rgb = vec3(0); + frag_color.rgb = col; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl index 57f93a8b36..8795d69a3a 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl @@ -44,9 +44,16 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color) col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); col.rgb = scaleDownLight(col.rgb); +#if defined(LOCAL_LIGHT_KILL) + col.rgb = vec3(0); +i#endif + // Add windlight lights col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); +#if !defined(SUNLIGHT_KILL) col.rgb = min(col.rgb*color.rgb, 1.0); +#endif + return col; } diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index effe4c5971..eca8515212 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -33,7 +33,11 @@ float getAmbientClamp(); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { vec4 c = sumLights(pos, norm, color); + +#if !defined(AMBIENT_KILL) c.rgb += atmosAmbient() * color.rgb * getAmbientClamp(); +#endif + return c; } diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index 81da6688c2..38dd850296 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -51,8 +51,15 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color) col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz); col.rgb = scaleDownLight(col.rgb); +#if defined(LOCAL_LIGHT_KILL) + col.rgb = vec3(0); +#endif + // Add windlight lights +#if !defined(SUNLIGHT_KILL) col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); +#endif + col.rgb = min(col.rgb*color.rgb, 1.0); return col; -- cgit v1.2.3 From 3c37658c02a2cf4b257203a9bc68246c5ac4042a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 23 May 2019 11:16:23 -0700 Subject: Re-enable projector ambiance for forward alpha objects. Undo attenuation hacks and balance with deferred path projector lighting. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 5 +---- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 4a12659d56..cd0494dc67 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -91,8 +91,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec //get light vector vec3 lv = lp.xyz-v; -la /= 20.0f; - //get distance float d = length(lv); @@ -109,7 +107,7 @@ la /= 20.0f; 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.0f; + //dist_atten *= 2.0f; // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); @@ -120,7 +118,6 @@ la /= 20.0f; float lit = max(da * dist_atten,0.0); -ambiance = 0.0f; float amb_da = ambiance; if (lit > 0) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 1c0516923e..b599b6d2fc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -90,8 +90,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe { vec3 col = vec3(0); -la /= 20.0f; - //get light vector vec3 lv = lp.xyz-v; @@ -121,7 +119,7 @@ la /= 20.0f; 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.0f; + //dist_atten *= 2.0f; // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); -- cgit v1.2.3 From 63ecb7325e77bf3ca568788a4557045054a4520b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 23 May 2019 15:47:02 -0700 Subject: SL-11260 part deux Tamp down more view-dependent refraction map fail. --- .../app_settings/shaders/class1/environment/terrainWaterF.glsl | 8 -------- 1 file changed, 8 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl index ddbe3ebe10..937f38842f 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl @@ -39,8 +39,6 @@ uniform sampler2D detail_2; uniform sampler2D detail_3; uniform sampler2D alpha_ramp; -vec3 atmosLighting(vec3 light); - vec4 applyWaterFog(vec4 color); void main() @@ -58,12 +56,6 @@ void main() float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); - /// Add WL Components - outColor.rgb *= vertex_color.rgb; - - // SL-11260... - //outColor.rgb = atmosLighting(outColor.rgb); - outColor = applyWaterFog(outColor); frag_color = outColor; } -- cgit v1.2.3 From 3d9bd0fb8291ad3de4aaa20100149bd45680538b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 28 May 2019 14:36:00 -0700 Subject: SL-10969, SL-11073 Modify forward projector lighting to use falloff like the deferred lights. Make tex cache not evaluate evictions for size during validation passes. --- .../shaders/class1/deferred/alphaF.glsl | 57 ++++++++++++++----- .../class1/deferred/avatarAlphaNoColorV.glsl | 30 +--------- .../shaders/class1/deferred/materialF.glsl | 66 ++++++++++++++-------- .../shaders/class1/deferred/softenLightF.glsl | 6 ++ .../shaders/class1/lighting/lightFuncV.glsl | 28 +++++---- .../shaders/class1/objects/previewV.glsl | 6 +- .../shaders/class2/lighting/sumLightsV.glsl | 7 ++- .../shaders/class3/lighting/sumLightsV.glsl | 14 ++--- 8 files changed, 123 insertions(+), 91 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index cd0494dc67..2b5509400e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -88,45 +88,71 @@ float getAmbientClamp(); 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 col = vec3(0); + //get light vector vec3 lv = lp.xyz-v; //get distance - float d = length(lv); - + float dist = length(lv); float da = 1.0; - vec3 col = vec3(0); + if (dist > la) + { + return col; + } + + dist /= la; - if (d > 0.0 && la > 0.0 && fa > 0.0) + /* clip to projector bounds + vec4 proj_tc = proj_mat * lp; + + if (proj_tc.z < 0 + || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + }*/ + + fa += 1.0; + if (dist > 0.0 && la > 0.0 && fa > 0.0) { //normalize light vector lv = normalize(lv); //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.0f; + dist_atten *= 2.0f; + + if (dist_atten <= 0.0) + { + return col; + } // 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); - float lit = max(da * dist_atten,0.0); + float lit = 0.0f; float amb_da = ambiance; - if (lit > 0) + if (da > 0) { + lit = max(da * dist_atten,0.0); col = lit * light_col * diffuse; amb_da += (da*0.5+0.5) * ambiance; } amb_da += (da*da*0.5 + 0.5) * ambiance; amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); + col.rgb += amb_da * light_col * diffuse; // no spec for alpha shader... @@ -150,14 +176,14 @@ void main() #endif #ifdef USE_DIFFUSE_TEX - vec4 diffuse_linear = texture2D(diffuseMap,vary_texcoord0.xy); + vec4 diffuse_srgb = texture2D(diffuseMap,vary_texcoord0.xy); + vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); #endif #ifdef USE_INDEXED_TEX vec4 diffuse_linear = diffuseLookup(vary_texcoord0.xy); -#endif - vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); +#endif #ifdef FOR_IMPOSTOR vec4 color; @@ -229,12 +255,11 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_linear.rgb; + color.rgb *= diffuse_srgb.rgb; vec3 post_diffuse = color.rgb; color.rgb = atmosFragLighting(color.rgb, additive, atten); - color.rgb = scaleSoftClipFrag(color.rgb); vec3 post_atmo = color.rgb; @@ -243,7 +268,7 @@ vec3 post_atmo = color.rgb; // to linear! color.rgb = srgb_to_linear(color.rgb); - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.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, diffuse_srgb.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); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -258,6 +283,8 @@ vec3 post_atmo = color.rgb; color.rgb += light.rgb; #endif + color.rgb = scaleSoftClipFrag(color.rgb); + // back to sRGB as we're going directly to the final RT post-deferred gamma correction color.rgb = linear_to_srgb(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl index e4d96a0028..bbdc8fdd1c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl @@ -55,35 +55,7 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) -{ - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float d = dot(lv,lv); - - float da = 0.0; - - if (d > 0.0 && la > 0.0 && fa > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist2 = d/la; - da = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.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); - } - - return da; -} +float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index b599b6d2fc..c3ca9a6904 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -88,17 +88,19 @@ 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 col = vec3(0); + vec3 col = vec3(0); //get light vector vec3 lv = lp.xyz-v; - + //get distance - float d = length(lv); - + float dist = length(lv); float da = 1.0; - /*vec4 proj_tc = proj_mat * lp; + dist /= la; + + /* clip to projector bounds + vec4 proj_tc = proj_mat * lp; if (proj_tc.z < 0 || proj_tc.z > 1 @@ -110,35 +112,42 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe return col; }*/ - if (d > 0.0 && la > 0.0 && fa > 0.0) + fa += 1.0; + if (dist > 0.0 && la > 0.0 && fa > 0.0) { //normalize light vector lv = normalize(lv); //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.0f; + dist_atten *= 2.0f; + + if (dist_atten <= 0.0) + { + return col; + } // 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); - - float lit = max(da * dist_atten, 0.0); + da *= dot(n, lv); + + float lit = 0.0f; float amb_da = ambiance; - if (lit > 0) - { - col = light_col*lit*diffuse; - amb_da += (da*0.5 + 0.5) * ambiance; + if (da > 0) + { + lit = max(da * dist_atten,0.0); + col = lit * light_col * diffuse; + amb_da += (da*0.5+0.5) * ambiance; } - amb_da += (da*da*0.5+0.5) * ambiance; + amb_da += (da*da*0.5 + 0.5) * ambiance; amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); + col.rgb += amb_da * light_col * diffuse; if (spec.a > 0.0) @@ -217,8 +226,15 @@ void main() { vec2 pos_screen = vary_texcoord0.xy; - vec4 diffuse_linear = texture2D(diffuseMap, vary_texcoord0.xy); - vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); + vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vec4 diffuse_srgb = diffuse_tap; + vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_tap.a); +#else + vec4 diffuse_linear = diffuse_tap; + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_tap.a); +#endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffuse_linear.a < minimum_alpha) @@ -331,7 +347,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_linear.rgb; + color.rgb *= diffuse_srgb.rgb; vec3 post_diffuse = color.rgb; @@ -358,7 +374,9 @@ vec3 post_diffuse = color.rgb; vec3 sp = sun_contrib*scol / 16.0f; sp = clamp(sp, vec3(0), vec3(1)); bloom = dot(sp, sp) / 6.0; +#if !defined(SUNLIGHT_KILL) color += sp * spec.rgb; +#endif } } @@ -371,8 +389,9 @@ vec3 post_spec = color.rgb; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; +#if !defined(SUNLIGHT_KILL) color = mix(color.rgb, reflected_color, envIntensity); - +#endif float cur_glare = max(reflected_color.r, reflected_color.g); cur_glare = max(cur_glare, reflected_color.b); cur_glare *= envIntensity*4.0; @@ -382,13 +401,12 @@ vec3 post_spec = color.rgb; vec3 post_env = color.rgb; color = atmosFragLighting(color, additive, atten); - color = scaleSoftClipFrag(color); - -vec3 post_atmo = color.rgb; //convert to linear space before adding local lights color = srgb_to_linear(color); +vec3 post_atmo = color.rgb; + vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -410,6 +428,8 @@ vec3 post_atmo = color.rgb; color.rgb += light.rgb; #endif + color = scaleSoftClipFrag(color); + // (only) post-deferred needs inline gamma correction color.rgb = linear_to_srgb(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index c7426788c4..39d14314cc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -153,7 +153,9 @@ vec3 post_diffuse = color.rgb; vec3 sp = sun_contrib*scontrib / 16.0; sp = clamp(sp, vec3(0), vec3(1)); bloom += dot(sp, sp) / 6.0; +#if !defined(SUNLIGHT_KILL) color += sp * spec.rgb; +#endif } } @@ -167,15 +169,19 @@ vec3 post_diffuse = color.rgb; { //add environmentmap vec3 env_vec = env_mat * refnormpersp; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; +#if !defined(SUNLIGHT_KILL) color = mix(color.rgb, reflected_color, envIntensity); +#endif } vec3 post_env = color.rgb; if (norm.w < 1) { +#if !defined(SUNLIGHT_KILL) color = atmosFragLighting(color, additive, atten); color = scaleSoftClipFrag(color); +#endif } vec3 post_atmo = color.rgb; diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl index d5448a1d31..2762a35403 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl @@ -28,32 +28,38 @@ float calcDirectionalLight(vec3 n, vec3 l) { - float a = max(dot(n,normalize(l)),0.0); + float a = max(dot(n,l),0.0); return a; } - -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight) +float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) { //get light vector vec3 lv = lp.xyz-v; //get distance - float d = length(lv); + float dist = length(lv); + + if (dist > la) + { + return 0; + } //normalize light vector - lv *= 1.0/d; - - //distance attenuation - float da = clamp(1.0/(la * d), 0.0, 1.0); - + lv = normalize(lv); + + fa += 1.0; + float dist_atten = min(1.0 - (dist-1.0*(1.0 - fa))/fa, 1.0); + + float da = max(dot(n, lv), 0.0); + // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation - da *= calcDirectionalLight(n, lv); + da *= dist_atten; - return da; + return da; } diff --git a/indra/newview/app_settings/shaders/class1/objects/previewV.glsl b/indra/newview/app_settings/shaders/class1/objects/previewV.glsl index 7f3f84398b..88959266c8 100644 --- a/indra/newview/app_settings/shaders/class1/objects/previewV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/previewV.glsl @@ -52,7 +52,7 @@ float calcDirectionalLight(vec3 n, vec3 l) } -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight) +float calcLocalLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight) { //get light vector vec3 lv = lp.xyz-v; @@ -91,8 +91,8 @@ void main() // Collect normal lights (need to be divided by two, as we later multiply by 2) col.rgb += light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); - col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); - col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); + col.rgb += light_diffuse[2].rgb*calcLocalLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); + col.rgb += light_diffuse[3].rgb*calcLocalLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); vertex_color = col*color; } diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl index 8795d69a3a..30ca88afd2 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl @@ -24,7 +24,7 @@ */ float calcDirectionalLight(vec3 n, vec3 l); -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight); +float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 scaleDownLight(vec3 light); @@ -40,8 +40,8 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color) // Collect normal lights (need to be divided by two, as we later multiply by 2) col.rgb += light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); - col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); - col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); + col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].y, light_attenuation[2].z); + col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].y, light_attenuation[3].z); col.rgb = scaleDownLight(col.rgb); #if defined(LOCAL_LIGHT_KILL) @@ -50,6 +50,7 @@ i#endif // Add windlight lights col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); + #if !defined(SUNLIGHT_KILL) col.rgb = min(col.rgb*color.rgb, 1.0); #endif diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index 38dd850296..4b663dd5b2 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -25,7 +25,7 @@ float calcDirectionalLight(vec3 n, vec3 l); -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight); +float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 scaleDownLight(vec3 light); @@ -42,12 +42,12 @@ vec4 sumLights(vec3 pos, vec3 norm, vec4 color) // Collect normal lights (need to be divided by two, as we later multiply by 2) // Collect normal lights - col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); - col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); - col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].z); - col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].z); - col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].z); - col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].z); + col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].y, light_attenuation[2].z); + col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].y, light_attenuation[3].z); + col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].y, light_attenuation[4].z); + col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].y, light_attenuation[5].z); + col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].y, light_attenuation[6].z); + col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].y, light_attenuation[7].z); col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz); col.rgb = scaleDownLight(col.rgb); -- cgit v1.2.3 From 2f2cf6d855e1e5977ef0ed3583238636e890220a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 29 May 2019 15:57:24 -0700 Subject: SL-10969 Modify ambient handling and forward projector lighting again to stamp out alpha fires. --- .../shaders/class1/deferred/alphaF.glsl | 21 +++++++++------------ .../shaders/class1/deferred/materialF.glsl | 9 +++------ .../shaders/class1/deferred/softenLightF.glsl | 3 --- .../shaders/class1/windlight/atmosphericsFuncs.glsl | 2 +- .../shaders/class2/deferred/softenLightF.glsl | 7 ++++--- .../shaders/class3/lighting/lightV.glsl | 2 +- 6 files changed, 18 insertions(+), 26 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 2b5509400e..93359e0d4c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -102,8 +102,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec return col; } - dist /= la; - /* clip to projector bounds vec4 proj_tc = proj_mat * lp; @@ -117,16 +115,17 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec return col; }*/ - fa += 1.0; - if (dist > 0.0 && la > 0.0 && fa > 0.0) + if (dist > 0.0 && la > 0.0) { + dist /= la; + //normalize light vector lv = normalize(lv); //distance attenuation float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; - dist_atten *= 2.0f; + //dist_atten *= 2.0f; if (dist_atten <= 0.0) { @@ -177,14 +176,14 @@ void main() #ifdef USE_DIFFUSE_TEX vec4 diffuse_srgb = texture2D(diffuseMap,vary_texcoord0.xy); - vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); #endif #ifdef USE_INDEXED_TEX - vec4 diffuse_linear = diffuseLookup(vary_texcoord0.xy); - vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); + vec4 diffuse_srgb = diffuseLookup(vary_texcoord0.xy); #endif + vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); + #ifdef FOR_IMPOSTOR vec4 color; color.rgb = diffuse_srgb.rgb; @@ -236,9 +235,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - - float ambient_clamp = getAmbientClamp() + 0.1; - ambient = (1.0 - ambient) * ambient_clamp; + ambient = (1.0 - ambient); vec3 sun_contrib = min(final_da, shadow) * sunlit; @@ -268,7 +265,7 @@ vec3 post_atmo = color.rgb; // to linear! color.rgb = srgb_to_linear(color.rgb); - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_srgb.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, diffuse_linear.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); LIGHT_LOOP(1) LIGHT_LOOP(2) diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c3ca9a6904..4701157909 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -112,8 +112,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe return col; }*/ - fa += 1.0; - if (dist > 0.0 && la > 0.0 && fa > 0.0) + if (dist > 0.0 && la > 0.0) { //normalize light vector lv = normalize(lv); @@ -121,7 +120,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe //distance attenuation float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; - dist_atten *= 2.0f; + //dist_atten *= 2.0f; if (dist_atten <= 0.0) { @@ -328,9 +327,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - - float ambient_clamp = getAmbientClamp() + 0.1; - ambient = (1.0 - ambient) * ambient_clamp; + ambient = (1.0 - ambient); vec3 sun_contrib = min(final_da, shadow) * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 39d14314cc..e07b31b3c1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -106,10 +106,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - ambient = (1.0 - ambient); - float ambient_clamp = getAmbientClamp() + 0.1; - ambient *= ambient_clamp; vec3 sun_contrib = final_da * sunlit; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 55ffbdcc46..a702b8d510 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -138,6 +138,6 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o //brightness of surface both sunlight and ambient sunlit = sunlight.rgb * 0.5; - amblit = tmpAmbient.rgb * .25; + amblit = tmpAmbient.rgb * .5; additive *= vec3(1.0 - temp1); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 7f83e168bb..35018360ac 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -114,10 +114,7 @@ void main() float ambient = da; ambient *= 0.5; ambient *= ambient; - - float ambient_clamp = getAmbientClamp() + 0.1; ambient = (1.0 - ambient); - ambient *= ambient_clamp; vec3 sun_contrib = min(scol, final_da) * sunlit; @@ -161,7 +158,9 @@ vec3 post_diffuse = color.rgb; vec3 sp = sun_contrib*scontrib / 16.0; sp = clamp(sp, vec3(0), vec3(1)); bloom += dot(sp, sp) / 6.0; +#if !defined(SUNLIGHT_KILL) color += sp * spec.rgb; +#endif } } @@ -175,7 +174,9 @@ vec3 post_diffuse = color.rgb; { //add environmentmap vec3 env_vec = env_mat * refnormpersp; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; +#if !defined(SUNLIGHT_KILL) color = mix(color.rgb, reflected_color, envIntensity); +#endif } vec3 post_env = color.rgb; diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index eca8515212..6918ac3b8c 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -35,7 +35,7 @@ vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) vec4 c = sumLights(pos, norm, color); #if !defined(AMBIENT_KILL) - c.rgb += atmosAmbient() * color.rgb * getAmbientClamp(); + c.rgb += atmosAmbient() * color.rgb * 0.5 * getAmbientClamp(); #endif return c; -- cgit v1.2.3 From f7bff299f1a243e8c5bfdc2b98ea3c7b549778f1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 30 May 2019 15:58:51 -0700 Subject: SL-11330 Put back atten for non-ALM lighting that accounts for inverted lin atten setup of yore. --- .../shaders/class1/lighting/lightFuncV.glsl | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl index 2762a35403..45701002b8 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl @@ -38,27 +38,20 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa vec3 lv = lp.xyz-v; //get distance - float dist = length(lv); - - if (dist > la) - { - return 0; - } + float d = length(lv); //normalize light vector - lv = normalize(lv); - - fa += 1.0; - float dist_atten = min(1.0 - (dist-1.0*(1.0 - fa))/fa, 1.0); - - float da = max(dot(n, lv), 0.0); - + lv *= 1.0/d; + + //distance attenuation + float da = clamp(1.0/(la * d), 0.0, 1.0); + // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation - da *= dist_atten; + da *= calcDirectionalLight(n, lv); return da; } -- cgit v1.2.3 From e9b2aa384a84c2e1b5f93f81b72eb028b292ae6a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 30 May 2019 16:16:29 -0700 Subject: SL-11289 Limit banding from atmo exp falloff calc. --- indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index dca2862b5a..5cb63912be 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -127,7 +127,7 @@ void main() light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); // Calculate relative weights - temp1 = blue_density + haze_density; + temp1 = abs(blue_density) + vec4(abs(haze_density)); blue_weight = blue_density / temp1; haze_weight = haze_density / temp1; @@ -142,7 +142,8 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * dist_mul); + //temp1 = exp(-temp1 * temp2.z * dist_mul); + temp1 = exp(-temp1 * dist_mul); // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); -- cgit v1.2.3 From 485c5978e7559471f4dad66fb141408262d75363 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 31 May 2019 09:19:34 -0700 Subject: SL-11051 Make shadow alpha mask shader ignore vert alpha (if it mattered, it'd be blended anyway). Modify deferred fullbrightF to use same handling of alpha masking as shadows for consistency (esp when mask cutoff == 0). --- .../newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 7 ++++++- .../app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index c104dc884f..f7368e8652 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -65,7 +65,12 @@ void main() float final_alpha = color.a * vertex_color.a; #ifdef HAS_ALPHA_MASK - if (color.a < minimum_alpha) + if (color.a < 0.05) + { + discard; + } + + if (minimum_alpha > 0 && color.a < minimum_alpha) { discard; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index d79d2423f1..96e6f11b96 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -43,7 +43,8 @@ void main() { float alpha = diffuseLookup(vary_texcoord0.xy).a; - alpha *= vertex_color.a; + // SL-11051 + //alpha *= vertex_color.a; if (alpha < 0.05) // treat as totally transparent { -- cgit v1.2.3 From 58f7b981bdb415311f23dfffc39e7a841b3017a0 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 31 May 2019 13:47:44 -0700 Subject: SL-11337 Fix handling of ambient (was getting reset to 1,1,1,1 unintentionally). Modify shaders to balance ambient across render modes again. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 93359e0d4c..1ed25d1dba 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -240,7 +240,7 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit; + color.rgb = amblit * 0.5; color.rgb *= ambient; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4701157909..8e0b903d04 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -332,7 +332,7 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit; + color.rgb = amblit * 0.5; color.rgb *= ambient; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index e07b31b3c1..5b03fbaa50 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -111,7 +111,7 @@ void main() vec3 sun_contrib = final_da * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit; + color.rgb = amblit * 0.5; color.rgb *= ambient; #endif diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 35018360ac..9492141b49 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -119,7 +119,7 @@ void main() vec3 sun_contrib = min(scol, final_da) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit; + color.rgb = amblit * 0.5; color.rgb *= ambient; #endif -- cgit v1.2.3 From ee9ad6520ec0cad689a9dfa7ca55717a43f2e897 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 31 May 2019 15:25:54 -0700 Subject: SL-11343 Make materials apply vertex color to both linear and srgb versions of diffuse color. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8e0b903d04..1e7ca08aa1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -243,6 +243,7 @@ void main() #endif diffuse_linear.rgb *= vertex_color.rgb; + diffuse_srgb.rgb *= linear_to_srgb(vertex_color.rgb); #ifdef HAS_SPECULAR_MAP vec4 spec = texture2D(specularMap, vary_texcoord2.xy); -- cgit v1.2.3 From 9d73d103bc137a9de5ccf550b9ceaf61c419179a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 3 Jun 2019 10:22:43 -0700 Subject: SL-11238, SL-11337 Tweak application of ambient in deferred soften light for class1/2 --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 5b03fbaa50..13e0cb5169 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -111,7 +111,7 @@ void main() vec3 sun_contrib = final_da * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit * 0.5; + color.rgb = pow(amblit, vec3(1.0/1.3)); color.rgb *= ambient; #endif diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 9492141b49..343e5c8ef5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -120,6 +120,7 @@ void main() #if !defined(AMBIENT_KILL) color.rgb = amblit * 0.5; + color.rgb = pow(color.rgb, vec3(1.0/1.1)); color.rgb *= ambient; #endif -- cgit v1.2.3 From 16d3279995bcb4a4766b721d0897b3d2199971d5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 3 Jun 2019 11:30:41 -0700 Subject: SL-10966 Fix light atten and transmittance calcs breaking ambient color contrib to fog. Needs to be tested on DRTSIM-415 or better to get legacy viewer settings that match EEP. --- .../shaders/class1/deferred/cloudShadowF.glsl | 1 - .../shaders/class1/deferred/cloudsV.glsl | 4 ++-- .../app_settings/shaders/class1/deferred/skyV.glsl | 8 ++++---- .../shaders/class1/windlight/atmosphericsFuncs.glsl | 4 ++-- .../shaders/class1/windlight/cloudShadowF.glsl | 1 - .../app_settings/shaders/class2/deferred/skyF.glsl | 8 ++++---- .../shaders/class2/windlight/atmosphericsF.glsl | 21 +-------------------- .../shaders/class2/windlight/cloudsV.glsl | 4 ++-- .../app_settings/shaders/class2/windlight/skyV.glsl | 8 ++++---- .../shaders/class2/windlight/transportF.glsl | 6 +++--- .../shaders/class3/deferred/cloudShadowF.glsl | 1 - .../shaders/class3/deferred/cloudsF.glsl | 1 - .../shaders/class3/windlight/atmosphericsF.glsl | 21 +-------------------- 13 files changed, 23 insertions(+), 65 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl index 035e979827..0efde5f949 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl @@ -49,7 +49,6 @@ uniform vec4 cloud_color; uniform float cloud_shadow; uniform float cloud_scale; uniform float cloud_variance; -uniform vec3 ambient; uniform vec3 camPosLocal; uniform vec3 sun_dir; uniform float sun_size; diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index aed5a9b950..46d09c5aae 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -50,7 +50,7 @@ uniform vec4 lightnorm; uniform vec4 sunlight_color; uniform vec4 moonlight_color; uniform int sun_up_factor; -uniform vec4 ambient; +uniform vec4 ambient_color; uniform vec4 blue_horizon; uniform vec4 blue_density; uniform float haze_horizon; @@ -145,7 +145,7 @@ void main() temp2.x += .25; // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; + vec4 tmpAmbient = ambient_color; tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 4603c69f2a..de8327eff3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -41,7 +41,7 @@ uniform vec4 lightnorm; uniform vec4 sunlight_color; uniform vec4 moonlight_color; uniform int sun_up_factor; -uniform vec4 ambient; +uniform vec4 ambient_color; uniform vec4 blue_horizon; uniform vec4 blue_density; uniform float haze_horizon; @@ -128,13 +128,13 @@ void main() // Haze color above cloud - vary_HazeColor = ( blue_horizon * blue_weight * (sunlight + ambient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) + vary_HazeColor = ( blue_horizon * blue_weight * (sunlight + ambient_color) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) ); // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; + vec4 tmpAmbient = ambient_color; tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index a702b8d510..9116b86f39 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -27,7 +27,7 @@ uniform vec4 lightnorm; uniform vec4 sunlight_color; uniform vec4 moonlight_color; uniform int sun_up_factor; -uniform vec4 ambient; +uniform vec4 ambient_color; uniform vec4 blue_horizon; uniform vec4 blue_density; uniform float haze_horizon; @@ -118,7 +118,7 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o temp2.x *= sun_moon_glow_factor; //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + vec4 tmpAmbient = ambient_color + (vec4(1.) - ambient_color) * cloud_shadow * 0.5; /* decrease value and saturation (that in HSV, not HSL) for occluded areas * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl index 537d6ebb99..1d004b2b3e 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl @@ -49,7 +49,6 @@ uniform vec4 cloud_color; uniform float cloud_shadow; uniform float cloud_scale; uniform float cloud_variance; -uniform vec3 ambient; uniform vec3 camPosLocal; uniform vec3 sun_dir; uniform float sun_size; diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 5cb63912be..dcd639caff 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -36,7 +36,7 @@ uniform vec4 lightnorm; uniform vec4 sunlight_color; uniform vec4 moonlight_color; uniform int sun_up_factor; -uniform vec4 ambient; +uniform vec4 ambient_color; uniform vec4 blue_horizon; uniform vec4 blue_density; uniform float haze_horizon; @@ -162,13 +162,13 @@ void main() temp2.x *= sun_moon_glow_factor; // Haze color above cloud - vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) + vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient_color) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) ); // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; + vec4 tmpAmbient = ambient_color; tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 9db04f4e9a..ee9c990b12 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -25,28 +25,9 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); +vec3 scaleSoftClipFrag(vec3 light); -uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; -uniform int sun_up_factor; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 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 vec4 glow; -uniform float scene_light_strength; -uniform mat3 ssao_effect_mat; uniform int no_atmo; -uniform float sun_moon_glow_factor; - -vec3 scaleSoftClipFrag(vec3 light); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index 5c29290e47..97eeb302d9 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -49,7 +49,7 @@ uniform vec4 lightnorm; uniform vec4 sunlight_color; uniform vec4 moonlight_color; uniform int sun_up_factor; -uniform vec4 ambient; +uniform vec4 ambient_color; uniform vec4 blue_horizon; uniform vec4 blue_density; uniform float haze_horizon; @@ -147,7 +147,7 @@ void main() temp2.x += .25; // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; + vec4 tmpAmbient = ambient_color; tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index 5b1eb55e0c..74326f252e 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -41,7 +41,7 @@ uniform vec4 lightnorm; uniform vec4 sunlight_color; uniform vec4 moonlight_color; uniform int sun_up_factor; -uniform vec4 ambient; +uniform vec4 ambient_color; uniform vec4 blue_horizon; uniform vec4 blue_density; uniform float haze_horizon; @@ -131,13 +131,13 @@ void main() // Haze color above cloud - vary_HazeColor = ( blue_horizon * blue_weight * (sunlight + ambient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) + vary_HazeColor = ( blue_horizon * blue_weight * (sunlight + ambient_color) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) ); // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; + vec4 tmpAmbient = ambient_color; tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index f9d2a36818..d2d839ed05 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -50,12 +50,12 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - return atmosTransportFrag(light * 0.5, getAdditiveColor() * (brightness * 0.5 + 0.5), getAtmosAttenuation()); + float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; + return atmosTransportFrag(light * 0.5, getAdditiveColor() * brightness, getAtmosAttenuation()); } vec3 fullbrightShinyAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); + float brightness = dot(light.rgb * 0.5, vec3(0.33333)) + 0.1; return atmosTransportFrag(light * 0.5, getAdditiveColor() * (brightness * brightness), getAtmosAttenuation()); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl index c0ba804a30..ae521afdad 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl @@ -48,7 +48,6 @@ uniform vec4 cloud_color; uniform float cloud_shadow; uniform float cloud_scale; uniform float cloud_variance; -uniform vec3 ambient; uniform vec3 camPosLocal; uniform vec3 sun_dir; uniform float sun_size; diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl index cc7a86f35c..1abe2fab63 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -51,7 +51,6 @@ uniform vec4 cloud_color; uniform float cloud_shadow; uniform float cloud_scale; uniform float cloud_variance; -uniform vec3 ambient; uniform vec3 camPosLocal; uniform vec3 sun_dir; uniform float sun_size; diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl index 88dfa8a907..2b70ba76dc 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl @@ -25,28 +25,9 @@ vec3 getAdditiveColor(); vec3 getAtmosAttenuation(); +vec3 scaleSoftClipFrag(vec3 light); -uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; -uniform int sun_up_factor; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 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 vec4 glow; -uniform float scene_light_strength; -uniform mat3 ssao_effect_mat; uniform int no_atmo; -uniform float sun_moon_glow_factor; - -vec3 scaleSoftClipFrag(vec3 light); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) { -- cgit v1.2.3 From 42ddf24b8e206029f3fc9a4b3c1bd7138c1a849b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 5 Jun 2019 08:07:55 -0700 Subject: SL-11109, SL-11342, SL-11051 Fix handling of objects with object transparency by diffuse alpha mode none and replace discard test to allow diffuse mode alpha blend objects to not falsely cast shadows. --- .../app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index 96e6f11b96..721e682029 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -43,15 +43,15 @@ void main() { float alpha = diffuseLookup(vary_texcoord0.xy).a; - // SL-11051 - //alpha *= vertex_color.a; if (alpha < 0.05) // treat as totally transparent { discard; } - if (alpha < minimum_alpha) // treat as semi-transparent + alpha *= vertex_color.a; + + if (alpha < 0.88) // treat as semi-transparent { if (fract(0.5*floor(target_pos_x / post_pos.w )) < 0.25) { -- cgit v1.2.3 From 48401b224d778b21e4d8ae08365718591907d14b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 5 Jun 2019 08:58:28 -0700 Subject: SL-9989 Clamp fog distance multiplier to >= 0.05 and adjust min range on control as well. Make sky shaders use dist mul consistently. --- .../shaders/class1/windlight/atmosphericsFuncs.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 10 +++++----- .../newview/app_settings/shaders/class2/windlight/cloudsV.glsl | 5 +++-- indra/newview/app_settings/shaders/class2/windlight/skyV.glsl | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 9116b86f39..291e160cdc 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -68,7 +68,7 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o vec4 light_atten; float dens_mul = density_multiplier; - float dist_mul = distance_multiplier; + float dist_mul = max(0.05, distance_multiplier); //sunlight attenuation effect (hue and brightness) due to atmosphere //this is used later for sunlight modulation at various altitudes diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index dcd639caff..921f87cf14 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -120,7 +120,7 @@ void main() vec4 light_atten; float dens_mul = density_multiplier; - float dist_mul = distance_multiplier; + float dist_mul = max(0.05, distance_multiplier); // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes @@ -169,13 +169,13 @@ void main() // Increase ambient when there are more clouds vec4 tmpAmbient = ambient_color; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + tmpAmbient += max(vec4(0), (1. - ambient_color)) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); + sunlight *= max(0.0, (1. - cloud_shadow)); // Haze color below cloud - vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + vec4 additiveColorBelowCloud = (blue_horizon * blue_weight * (sunlight + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) ); @@ -192,7 +192,7 @@ void main() vec3 halo_22 = halo22(optic_d); - color.rgb += rainbow(optic_d); + color.rgb += rainbow(optic_d); color.rgb += halo_22; diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index 97eeb302d9..372c782d74 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -106,7 +106,7 @@ void main() vec4 light_atten; float dens_mul = density_multiplier; - float dist_mul = distance_multiplier; + float dist_mul = max(0.05, distance_multiplier); // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes @@ -128,7 +128,8 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * dist_mul); + //temp1 = exp(-temp1 * temp2.z * dist_mul); + temp1 = exp(-temp1 * dist_mul); // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index 74326f252e..eb5ab0f012 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -89,6 +89,7 @@ void main() vec4 light_atten; float dens_mul = density_multiplier; + float dist_mul = max(0.05, distance_multiplier); // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes @@ -110,8 +111,7 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - + temp1 = exp(-temp1 * dist_mul); // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); -- cgit v1.2.3 From a7856d4fc5b765b2e381f7606633db9431a3a80c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 6 Jun 2019 14:34:14 -0700 Subject: SL-11374 Use color channel for trees instead of shenanigans to get proper diffuse colors to shaders. Remove fudge factors on density modifier in class1 sky. --- indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/skyV.glsl | 2 +- indra/newview/app_settings/shaders/class1/objects/treeV.glsl | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 46d09c5aae..9f49432c7d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -103,7 +103,7 @@ void main() vec4 sunlight = sunlight_color; vec4 light_atten; - float dens_mul = density_multiplier * 0.45; + float dens_mul = density_multiplier; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index de8327eff3..1ab0bc4c20 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -87,7 +87,7 @@ void main() vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; vec4 light_atten; - float dens_mul = density_multiplier * 0.45; + float dens_mul = density_multiplier; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes diff --git a/indra/newview/app_settings/shaders/class1/objects/treeV.glsl b/indra/newview/app_settings/shaders/class1/objects/treeV.glsl index 179d3c42a4..0227e6e3b8 100644 --- a/indra/newview/app_settings/shaders/class1/objects/treeV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/treeV.glsl @@ -56,6 +56,4 @@ void main() vec4 color = calcLighting(pos.xyz, norm, diffuse_color); vertex_color = color; - - } -- cgit v1.2.3 From 49eae58bd0d1eceda18a3997454beb15a5e27cbd Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 6 Jun 2019 16:32:55 -0700 Subject: SL-10969 More tweaking ambient light. --- .../newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class1/lighting/lightV.glsl | 2 +- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 4 ++-- .../newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 3 +-- indra/newview/app_settings/shaders/class3/lighting/lightV.glsl | 6 +++--- 5 files changed, 8 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 13e0cb5169..7f7faffe78 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -111,7 +111,7 @@ void main() vec3 sun_contrib = final_da * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = pow(amblit, vec3(1.0/1.3)); + color.rgb = amblit * 2.0; color.rgb *= ambient; #endif diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl index 5e39d1629d..751e7da53d 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl @@ -35,7 +35,7 @@ vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) vec4 c = sumLights(pos, norm, color); #if !defined(AMBIENT_KILL) - c.rgb += atmosAmbient() * color.rgb * 0.5 * getAmbientClamp(); + c.rgb += atmosAmbient() * color.rgb * getAmbientClamp(); #endif return c; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 291e160cdc..fa20d63a4a 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -44,7 +44,7 @@ uniform float sun_moon_glow_factor; float getAmbientClamp() { - return 0.9; + return 1.0f; } void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { @@ -138,6 +138,6 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o //brightness of surface both sunlight and ambient sunlit = sunlight.rgb * 0.5; - amblit = tmpAmbient.rgb * .5; + amblit = tmpAmbient.rgb * .25; additive *= vec3(1.0 - temp1); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 343e5c8ef5..92794ddaae 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -119,8 +119,7 @@ void main() vec3 sun_contrib = min(scol, final_da) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit * 0.5; - color.rgb = pow(color.rgb, vec3(1.0/1.1)); + color.rgb = amblit * 2.0; color.rgb *= ambient; #endif diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index 6918ac3b8c..cba87a1db7 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -35,9 +35,9 @@ vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) vec4 c = sumLights(pos, norm, color); #if !defined(AMBIENT_KILL) - c.rgb += atmosAmbient() * color.rgb * 0.5 * getAmbientClamp(); + c.rgb += atmosAmbient() * color.rgb * 2.0 * getAmbientClamp(); #endif - - return c; + + return c; } -- cgit v1.2.3 From b79d0d2fdd047636598cbc9b088c3d4a10a84460 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 10 Jun 2019 09:15:35 -0700 Subject: SL-10969, SL-11051 Make fullbright alpha mask with mask cutoff == 0 not generate shadows. Adjust handling of ambient across forward and deferred again. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 7 +++---- .../app_settings/shaders/class1/deferred/materialF.glsl | 15 ++++----------- .../shaders/class1/deferred/shadowAlphaMaskF.glsl | 5 +++++ .../shaders/class1/deferred/softenLightF.glsl | 13 +++++++------ .../shaders/class1/windlight/atmosphericsFuncs.glsl | 13 +++++++++---- .../shaders/class2/deferred/softenLightF.glsl | 4 ++-- .../shaders/class2/windlight/atmosphericsV.glsl | 4 ++-- .../shaders/class3/deferred/softenLightF.glsl | 1 - .../app_settings/shaders/class3/lighting/lightV.glsl | 2 +- .../shaders/class3/windlight/atmosphericsV.glsl | 4 ++-- 10 files changed, 35 insertions(+), 33 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 1ed25d1dba..b4de492abc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -40,7 +40,6 @@ out vec4 frag_color; uniform float display_gamma; uniform vec4 gamma; uniform mat3 env_mat; -uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; uniform vec3 moon_dir; @@ -78,7 +77,7 @@ vec2 encode_normal (vec3 n); vec3 scaleSoftClipFrag(vec3 l); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); -void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive, bool use_ao); #ifdef HAS_SHADOW float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); @@ -217,7 +216,7 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten); + calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten, false); vec2 abnormal = encode_normal(norm.xyz); @@ -240,7 +239,7 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit * 0.5; + color.rgb = amblit * 2.0; color.rgb *= ambient; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 1e7ca08aa1..1f0fa97297 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -41,7 +41,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); 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); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -67,7 +67,6 @@ uniform vec3 camPosLocal; //uniform vec4 camPosWorld; uniform vec4 gamma; uniform mat3 env_mat; -uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; uniform vec3 moon_dir; @@ -226,14 +225,8 @@ void main() vec2 pos_screen = vary_texcoord0.xy; vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec4 diffuse_srgb = diffuse_tap; - vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_tap.a); -#else vec4 diffuse_linear = diffuse_tap; vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_tap.a); -#endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffuse_linear.a < minimum_alpha) @@ -313,7 +306,7 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten); + calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten, false); vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -333,7 +326,7 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit * 0.5; + color.rgb = amblit * 2.0; color.rgb *= ambient; #endif @@ -345,7 +338,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_srgb.rgb; + color.rgb *= diffuse_linear.rgb; vec3 post_diffuse = color.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index 721e682029..80b096fd97 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -43,6 +43,11 @@ void main() { float alpha = diffuseLookup(vary_texcoord0.xy).a; + // mask cutoff 0 -> no shadow SL-11051 + if (minimum_alpha == 0) + { + discard; + } if (alpha < 0.05) // treat as totally transparent { diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 7f7faffe78..8c0f74d679 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -59,7 +59,7 @@ 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); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); float getAmbientClamp(); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -87,8 +87,8 @@ void main() float final_da = da; final_da = clamp(final_da, 0.0, 1.0); - vec4 diffuse_linear = texture2DRect(diffuseRect, tc); - vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); + vec4 diffuse_srgb = texture2DRect(diffuseRect, tc); + vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 color = vec3(0); @@ -101,7 +101,7 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, ambocc, sunlit, amblit, additive, atten); + calcAtmosphericVars(pos.xyz, ambocc, sunlit, amblit, additive, atten, false); float ambient = da; ambient *= 0.5; @@ -111,7 +111,7 @@ void main() vec3 sun_contrib = final_da * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit * 2.0; + color.rgb = amblit; color.rgb *= ambient; #endif @@ -123,7 +123,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_linear.rgb; + color.rgb *= diffuse_srgb.rgb; vec3 post_diffuse = color.rgb; @@ -210,6 +210,7 @@ vec3 post_atmo = color.rgb; //color.rgb = vec3(final_da); //color.rgb = vec3(ambient); //color.rgb = vec3(scol); +//color.rgb = diffuse_linear.rgb; frag_color.rgb = color.rgb; frag_color.a = bloom; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index fa20d63a4a..deda4d8b7e 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -47,7 +47,7 @@ float getAmbientClamp() return 1.0f; } -void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao) { vec3 P = inPositionEye; @@ -116,9 +116,11 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o temp2.x += .25; temp2.x *= sun_moon_glow_factor; - + + vec4 amb_color = ambient_color; + //increase ambient when there are more clouds - vec4 tmpAmbient = ambient_color + (vec4(1.) - ambient_color) * cloud_shadow * 0.5; + vec4 tmpAmbient = amb_color + (vec4(1.) - amb_color) * cloud_shadow * 0.5; /* decrease value and saturation (that in HSV, not HSL) for occluded areas * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html @@ -128,7 +130,10 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + if (use_ao) + { + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + } //haze color additive = diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 92794ddaae..da85786317 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -59,7 +59,7 @@ 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); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); float getAmbientClamp(); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -109,7 +109,7 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, ambocc, sunlit, amblit, additive, atten); + calcAtmosphericVars(pos.xyz, ambocc, sunlit, amblit, additive, atten, true); float ambient = da; ambient *= 0.5; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index d66983a951..baba79ca96 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -32,7 +32,7 @@ void setPositionEye(vec3 v); vec3 getAdditiveColor(); -void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); void calcAtmospherics(vec3 inPositionEye) { @@ -42,7 +42,7 @@ void calcAtmospherics(vec3 inPositionEye) { vec3 tmpamblit = vec3(1); vec3 tmpaddlit = vec3(1); vec3 tmpattenlit = vec3(1); - calcAtmosphericVars(inPositionEye, 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit); + calcAtmosphericVars(inPositionEye, 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, false); setSunlitColor(tmpsunlit); setAmblitColor(tmpamblit); setAdditiveColor(tmpaddlit); diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 6400e5169e..82a899ad65 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -53,7 +53,6 @@ uniform vec4 glow; uniform float global_gamma; uniform mat3 env_mat; uniform vec4 shadow_clip; -uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; VARYING vec2 vary_fragcoord; diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index cba87a1db7..30ad493331 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -35,7 +35,7 @@ vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) vec4 c = sumLights(pos, norm, color); #if !defined(AMBIENT_KILL) - c.rgb += atmosAmbient() * color.rgb * 2.0 * getAmbientClamp(); + c.rgb += atmosAmbient() * color.rgb * getAmbientClamp(); #endif return c; diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl index 27fdae962e..7b4269ca6f 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl @@ -32,7 +32,7 @@ void setPositionEye(vec3 v); vec3 getAdditiveColor(); -void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); +void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); void calcAtmospherics(vec3 inPositionEye) { @@ -42,7 +42,7 @@ void calcAtmospherics(vec3 inPositionEye) { vec3 tmpamblit = vec3(1); vec3 tmpaddlit = vec3(1); vec3 tmpattenlit = vec3(1); - calcAtmosphericVars(inPositionEye, 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit); + calcAtmosphericVars(inPositionEye, 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, true); setSunlitColor(tmpsunlit); setAmblitColor(tmpamblit); setAdditiveColor(tmpaddlit); -- cgit v1.2.3 From c15baecbfbc9baffdeb6ec53b7e4090470514657 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 10 Jun 2019 14:54:47 -0700 Subject: SL-11370 Modify culling logic to exclude objects correctly in < Mid graphics. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 2235ab12a4..a9161b2a20 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -153,7 +153,7 @@ void main() spec = pow(spec, 128.0); //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); + vec2 distort2 = distort+wavef.xy*(refScale * 0.01)/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); -- cgit v1.2.3 From 653133b9c035e7c34563b199e991189ca3046092 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 11 Jun 2019 13:03:06 -0700 Subject: SL-11370, SL-11372, SL-11337 Fix culling on Low+ water reflection pass. Make Mid+ / High use class1 deferred sky again (no rainbows, but faster!). Fix setting of cloud color for deferred sky/cloud shaders. Put water reflections back in wrong colorspace for consistency with release. --- .../newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- .../newview/app_settings/shaders/class1/deferred/cloudsF.glsl | 8 +++++--- .../app_settings/shaders/class1/deferred/materialF.glsl | 2 +- .../shaders/class1/deferred/multiPointLightF.glsl | 2 ++ .../app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 2 ++ .../app_settings/shaders/class1/deferred/pointLightF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/skyF.glsl | 8 ++++++-- indra/newview/app_settings/shaders/class1/deferred/skyV.glsl | 6 ++++-- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 4 ++-- .../app_settings/shaders/class1/deferred/spotLightF.glsl | 2 ++ .../newview/app_settings/shaders/class1/deferred/waterF.glsl | 5 ++--- .../app_settings/shaders/class1/environment/waterF.glsl | 6 ++---- .../newview/app_settings/shaders/class1/lighting/lightV.glsl | 2 +- .../app_settings/shaders/class2/deferred/multiSpotLightF.glsl | 3 ++- indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 2 -- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 11 +++++++---- .../app_settings/shaders/class2/windlight/cloudsF.glsl | 7 ++++--- 17 files changed, 44 insertions(+), 29 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index b4de492abc..7dc2fb4cc0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -239,7 +239,7 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit * 2.0; + color.rgb = amblit; color.rgb *= ambient; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 6ff97fd1e9..d6bd0a7917 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -55,7 +55,6 @@ VARYING float altitude_blend_factor; /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); -vec3 linear_to_srgb(vec3 c); vec4 cloudNoise(vec2 uv) { @@ -121,10 +120,13 @@ void main() color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); color.rgb= max(vec3(0), color.rgb); color.rgb *= 2.0; + color.rgb = scaleSoftClip(color.rgb); /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); + frag_data[0] = vec4(color.rgb, alpha1); frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0,0,1,0); + frag_data[2] = vec4(0,0,0,1); + + gl_FragDepth = 0.99995f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 1f0fa97297..571d0dd17a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -326,7 +326,7 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit * 2.0; + color.rgb = amblit; color.rgb *= ambient; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 367680556a..3607f5a086 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -58,6 +58,7 @@ uniform mat4 inv_proj; vec4 getPosition(vec2 pos_screen); vec3 getNorm(vec2 pos_screen); +vec3 srgb_to_linear(vec3 c); void main() { @@ -77,6 +78,7 @@ void main() vec4 spec = texture2DRect(specularRect, frag.xy); vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb; + diff.rgb = srgb_to_linear(diff.rgb); float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 npos = normalize(-pos); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index c81d633880..e28506dcff 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -178,6 +178,8 @@ void main() vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + diff_tex.rgb = srgb_to_linear(diff_tex.rgb); + vec3 dlit = vec3(0, 0, 0); float noise = texture2D(noiseMap, frag.xy/128.0).b; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 73bc1141b0..b3ce1ce2e0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -89,6 +89,7 @@ void main() float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; + float fa = falloff+1.0; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 72b7aa9036..894ce8a5e9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -41,6 +41,8 @@ uniform vec4 gamma; /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); +vec3 srgb_to_linear(vec3 c); +vec3 linear_to_srgb(vec3 c); void main() { @@ -51,10 +53,12 @@ void main() vec4 color; color = vary_HazeColor; - color *= 2.; + color.rgb *= 2.0f; + //color.rgb = scaleSoftClip(color.rgb); + //color.rgb = linear_to_srgb(color.rgb); /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); + frag_data[0] = vec4(color.rgb, 1.0); frag_data[1] = vec4(0.0,0.0,0.0,0.0); frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 1ab0bc4c20..bdc2a676da 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -49,6 +49,7 @@ uniform float haze_density; uniform float cloud_shadow; uniform float density_multiplier; +uniform float distance_multiplier; uniform float max_y; uniform vec4 glow; @@ -88,6 +89,7 @@ void main() vec4 light_atten; float dens_mul = density_multiplier; + float dist_mul = distance_multiplier; // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes @@ -109,7 +111,7 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); + temp1 = exp(-temp1 * temp2.z * dist_mul); // Compute haze glow @@ -153,7 +155,7 @@ void main() // At horizon, blend high altitude sky color towards the darker color below the clouds vary_HazeColor += (additiveColorBelowCloud - vary_HazeColor) * (1. - sqrt(temp1)); - + // won't compile on mac without this being set //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 8c0f74d679..aa55b36d4a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -111,8 +111,8 @@ void main() vec3 sun_contrib = final_da * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit; - color.rgb *= ambient; + color.rgb = amblit * 2.0; + color.rgb *= ambient * 0.5; #endif vec3 post_ambient = color.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 55c740d100..5e985618f7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -177,6 +177,8 @@ void main() float da = dot(norm, lv); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + diff_tex.rgb = srgb_to_linear(diff_tex.rgb); + vec4 spec = texture2DRect(specularRect, frag.xy); float noise = texture2D(noiseMap, frag.xy/128.0).b; diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index a9161b2a20..fd5b6989eb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -144,7 +144,6 @@ void main() vec4 baseCol = texture2D(refTex, refvec4); refcol = mix(baseCol*df2, refcol, dweight); - refcol.rgb = srgb_to_linear(refcol.rgb); //get specular component float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); @@ -159,7 +158,7 @@ void main() //mix with reflection // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.4 + 0.6); + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.999999); vec4 pos = vary_position; @@ -167,7 +166,7 @@ void main() //color.rgb = atmosTransport(color.rgb); color.rgb = scaleSoftClip(color.rgb); - + color.a = spec * sunAngle2; vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index f033c0e7c4..4e550b8284 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -150,11 +150,9 @@ void main() //mix with reflection // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.4 + 0.6); + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.9999999); color.rgb += spec * specular; - - //color.rgb = atmosTransport(color.rgb); - color.rgb = scaleSoftClip(color.rgb * 0.5); + color.a = spec * sunAngle2; #if defined(WATER_EDGE) diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl index 751e7da53d..5e39d1629d 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl @@ -35,7 +35,7 @@ vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) vec4 c = sumLights(pos, norm, color); #if !defined(AMBIENT_KILL) - c.rgb += atmosAmbient() * color.rgb * getAmbientClamp(); + c.rgb += atmosAmbient() * color.rgb * 0.5 * getAmbientClamp(); #endif return c; diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index bcce4c041a..8cad21d5b4 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -191,7 +191,8 @@ void main() float da = dot(norm, lv); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - + diff_tex.rgb = srgb_to_linear(diff_tex.rgb); + vec4 spec = texture2DRect(specularRect, frag.xy); vec3 dlit = vec3(0, 0, 0); diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 921f87cf14..0f33bac3c6 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -88,7 +88,6 @@ vec3 halo22(float d) /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); -vec3 srgb_to_linear(vec3 c); void main() { @@ -198,7 +197,6 @@ void main() color.rgb *= 2.; color.rgb = scaleSoftClip(color.rgb); - color.rgb = srgb_to_linear(color.rgb); /// Gamma correct for WL (soft clip effect). frag_data[0] = vec4(color.rgb, 1.0); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index da85786317..53cdce4cb1 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -91,8 +91,8 @@ void main() float final_da = da; final_da = clamp(final_da, 0.0, 1.0); - vec4 diffuse_linear = texture2DRect(diffuseRect, tc); - vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); + vec4 diffuse_srgb = texture2DRect(diffuseRect, tc); + vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); // clamping to alpha value kills underwater shadows... //scol = max(scol_ambocc.r, diffuse_linear.a); @@ -120,7 +120,7 @@ void main() #if !defined(AMBIENT_KILL) color.rgb = amblit * 2.0; - color.rgb *= ambient; + color.rgb *= ambient * 0.5; #endif vec3 post_ambient = color.rgb; @@ -131,7 +131,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_linear.rgb; + color.rgb *= diffuse_srgb.rgb; vec3 post_diffuse = color.rgb; @@ -183,8 +183,10 @@ vec3 post_env = color.rgb; if (norm.w < 1) { +#if !defined(SUNLIGHT_KILL) color = atmosFragLighting(color, additive, atten); color = scaleSoftClipFrag(color); +#endif } vec3 post_atmo = color.rgb; @@ -216,6 +218,7 @@ vec3 post_atmo = color.rgb; //color.rgb = vec3(final_da); //color.rgb = vec3(ambient); //color.rgb = vec3(scol); +//color.rgb = diffuse_linear.rgb; frag_color.rgb = color.rgb; frag_color.a = bloom; diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index 396ceacd19..e7ae2d52e3 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -123,11 +123,12 @@ void main() // Combine vec4 color; color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); - color *= 2.; + color.rgb *= 2.; + color.rgb = scaleSoftClip(color.rgb); /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); + frag_data[0] = vec4(color.rgb, alpha1); frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0,0,1,0); + frag_data[2] = vec4(0,0,0,1); } -- cgit v1.2.3 From c68c9678a3fccf031532bfb813ecffce89f39f67 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 12 Jun 2019 14:09:47 -0700 Subject: SL-11406 Adjust atmospheric lighting in frag shader. --- .../newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index ee9c990b12..ee745b48c2 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -36,8 +36,8 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) return light; } light *= atten.r; - light += additive; - return light * 2.0; + light += additive * 2.0; + return light; } vec3 atmosLighting(vec3 light) -- cgit v1.2.3 From 9d138b1440fc68d5f4b687fbf4e8635d6d2bdfe5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Jun 2019 10:40:54 -0700 Subject: Fix sky atmospherics in class1 to match class2 and Mid. --- .../app_settings/shaders/class1/deferred/skyF.glsl | 12 +++--- .../app_settings/shaders/class1/deferred/skyV.glsl | 49 ++++++++++++---------- .../app_settings/shaders/class2/deferred/skyF.glsl | 7 ++-- .../shaders/class2/windlight/skyF.glsl | 2 +- 4 files changed, 36 insertions(+), 34 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 894ce8a5e9..7d4d9eb49f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -41,8 +41,6 @@ uniform vec4 gamma; /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); -vec3 srgb_to_linear(vec3 c); -vec3 linear_to_srgb(vec3 c); void main() { @@ -53,14 +51,14 @@ void main() vec4 color; color = vary_HazeColor; - color.rgb *= 2.0f; - //color.rgb = scaleSoftClip(color.rgb); - //color.rgb = linear_to_srgb(color.rgb); + + color.rgb *= 2.; + color.rgb = scaleSoftClip(color.rgb); /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(color.rgb, 1.0); + frag_data[0] = vec4(color.rgb, 0.0); frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog + frag_data[2] = vec4(0.0,0.0,0.0,1.0); //1.0 in norm.w masks off fog gl_FragDepth = 0.99999f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index bdc2a676da..45e79f36ea 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -53,6 +53,7 @@ uniform float distance_multiplier; uniform float max_y; uniform vec4 glow; +uniform float sun_moon_glow_factor; uniform vec4 cloud_color; @@ -60,11 +61,12 @@ void main() { // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + + gl_Position = pos; // Get relative position - vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); - //vec3 P = position.xyz + vec3(0,50,0); + vec3 P = pos.xyz - camPosLocal.xyz + vec3(0,50,0); // Set altitude if (P.y > 0.) @@ -78,6 +80,7 @@ void main() // Can normalize then vec3 Pn = normalize(P); + float Plen = length(P); // Initialize temp variables @@ -89,29 +92,30 @@ void main() vec4 light_atten; float dens_mul = density_multiplier; - float dist_mul = distance_multiplier; + float dist_mul = max(0.05, distance_multiplier); // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); // Calculate relative weights - temp1 = blue_density + haze_density; + temp1 = abs(blue_density) + vec4(abs(haze_density)); blue_weight = blue_density / temp1; haze_weight = haze_density / temp1; // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); + temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); // Distance temp2.z = Plen * dens_mul; // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * dist_mul); + // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati + // compiler gets confused. + //temp1 = exp(-temp1 * temp2.z * dist_mul); + temp1 = exp(-temp1 * dist_mul); // Compute haze glow @@ -128,35 +132,34 @@ void main() // Add "minimum anti-solar illumination" temp2.x += .25; + temp2.x *= sun_moon_glow_factor; - // Haze color above cloud - vary_HazeColor = ( blue_horizon * blue_weight * (sunlight + ambient_color) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) - ); + vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient_color) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) + ); + // Final atmosphere additive + color *= (1. - temp1); // Increase ambient when there are more clouds vec4 tmpAmbient = ambient_color; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + tmpAmbient += max(vec4(0), (1. - ambient_color)) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); + sunlight *= max(0.0, (1. - cloud_shadow)); // Haze color below cloud vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) ); - // Final atmosphere additive - vary_HazeColor *= (1. - temp1); - // Attenuate cloud color by atmosphere temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds // At horizon, blend high altitude sky color towards the darker color below the clouds - vary_HazeColor += (additiveColorBelowCloud - vary_HazeColor) * (1. - sqrt(temp1)); + color += (additiveColorBelowCloud - color) * (1. - sqrt(temp1)); - // won't compile on mac without this being set - //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); + // Haze color above cloud + vary_HazeColor = color; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 0f33bac3c6..889a989985 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -165,6 +165,8 @@ void main() + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) ); + // Final atmosphere additive + color *= (1. - temp1); // Increase ambient when there are more clouds vec4 tmpAmbient = ambient_color; @@ -178,8 +180,7 @@ void main() + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) ); - // Final atmosphere additive - color *= (1. - temp1); + // Attenuate cloud color by atmosphere temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds @@ -201,6 +202,6 @@ void main() /// Gamma correct for WL (soft clip effect). frag_data[0] = vec4(color.rgb, 1.0); frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog + frag_data[2] = vec4(0.0,0.0,0.0,1.0); //1.0 in norm.w masks off fog } diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl index 02e10b7b50..de6fb276aa 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl @@ -49,7 +49,7 @@ void main() vec4 color; color = vary_HazeColor; - color *= 2.; + color.rgb *= 2.; /// Gamma correct for WL (soft clip effect). frag_color.rgb = scaleSoftClip(color.rgb); frag_color.a = 1.0; -- cgit v1.2.3 From 032848472c1895040d5323948fc67e8f47c5fad3 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Jun 2019 11:04:04 -0700 Subject: SL-11372 Fix incorrect diffuse handling in class1 softenLight from contrib. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index aa55b36d4a..5fb3dc12e6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -159,7 +159,7 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; #ifndef WATER_FOG - color.rgb += diffuse_srgb.rgb * diffuse_srgb.a; + color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); #endif if (envIntensity > 0.0) -- cgit v1.2.3 From e7ac7d766d1c817ad43d5bf0b5bba7f07495395b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Jun 2019 11:25:55 -0700 Subject: SL-11109 Move vert alpha multiply back before discard tests to fix object transparency only object shadow casting. Very likely re-breaks SL_11051 making fullbright alpha mask objects not cast when they should (due to broken vertex alpha...). --- .../app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index 80b096fd97..b2fbd8b86c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -43,6 +43,8 @@ void main() { float alpha = diffuseLookup(vary_texcoord0.xy).a; + alpha *= vertex_color.a; + // mask cutoff 0 -> no shadow SL-11051 if (minimum_alpha == 0) { @@ -54,8 +56,6 @@ void main() discard; } - alpha *= vertex_color.a; - if (alpha < 0.88) // treat as semi-transparent { if (fract(0.5*floor(target_pos_x / post_pos.w )) < 0.25) -- cgit v1.2.3 From 4abb342e9564a7740475c3abe60cd62ae5bbc34d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Jun 2019 13:14:27 -0700 Subject: SL-10969 Remove ambiance handling from alpha and blended materials objects for now. Still too many setups where they get blown out due to attenuation mismatches with deferred. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 20 +++++++++++--------- .../shaders/class1/deferred/materialF.glsl | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 13 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 7dc2fb4cc0..241857dd92 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -96,12 +96,12 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec float dist = length(lv); float da = 1.0; - if (dist > la) + /*if (dist > la) { return col; } - /* clip to projector bounds + clip to projector bounds vec4 proj_tc = proj_mat * lp; if (proj_tc.z < 0 @@ -116,15 +116,15 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec if (dist > 0.0 && la > 0.0) { - dist /= la; + dist /= la; //normalize light vector lv = normalize(lv); //distance attenuation + fa += 1.0f; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; - //dist_atten *= 2.0f; if (dist_atten <= 0.0) { @@ -137,10 +137,11 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec //angular attenuation da *= dot(n, lv); + da = max(0.0, da); float lit = 0.0f; - float amb_da = ambiance; + float amb_da = 0.0;//ambiance; if (da > 0) { lit = max(da * dist_atten,0.0); @@ -151,7 +152,8 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); - col.rgb += amb_da * light_col * diffuse; + // SL-10969 ... need to work out why this blows out in many setups... + //col.rgb += amb_da * light_col * diffuse; // no spec for alpha shader... } @@ -174,13 +176,14 @@ void main() #endif #ifdef USE_DIFFUSE_TEX - vec4 diffuse_srgb = texture2D(diffuseMap,vary_texcoord0.xy); + vec4 diffuse_tap = texture2D(diffuseMap,vary_texcoord0.xy); #endif #ifdef USE_INDEXED_TEX - vec4 diffuse_srgb = diffuseLookup(vary_texcoord0.xy); + vec4 diffuse_tap = diffuseLookup(vary_texcoord0.xy); #endif + vec4 diffuse_srgb = diffuse_tap; vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); #ifdef FOR_IMPOSTOR @@ -205,7 +208,6 @@ void main() #ifdef USE_VERTEX_COLOR float final_alpha = diffuse_linear.a * vertex_color.a; - diffuse_srgb.rgb *= vertex_color.rgb; diffuse_linear.rgb *= vertex_color.rgb; #else float final_alpha = diffuse_linear.a; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 571d0dd17a..8ebb2f44d3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -117,6 +117,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe lv = normalize(lv); //distance attenuation + fa += 1.0f; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; //dist_atten *= 2.0f; @@ -136,7 +137,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float lit = 0.0f; float amb_da = ambiance; - if (da > 0) + if (da >= 0) { lit = max(da * dist_atten,0.0); col = lit * light_col * diffuse; @@ -146,7 +147,8 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe amb_da *= dist_atten; amb_da = min(amb_da, 1.0f - lit); - col.rgb += amb_da * light_col * diffuse; + // SL-10969 need to see why these are blown out + //col.rgb += amb_da * light_col * diffuse; if (spec.a > 0.0) { @@ -225,8 +227,14 @@ void main() vec2 pos_screen = vary_texcoord0.xy; vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vec4 diffuse_srgb = diffuse_tap; + vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); +#else vec4 diffuse_linear = diffuse_tap; - vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_tap.a); + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); +#endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffuse_linear.a < minimum_alpha) @@ -338,7 +346,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_linear.rgb; + color.rgb *= diffuse_srgb.rgb; vec3 post_diffuse = color.rgb; -- cgit v1.2.3 From 782ddfdb48e1bdf6995783c11342eed2de4a30bb Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Jun 2019 13:41:53 -0700 Subject: SL-11041 Revert fix for SL_11406 causing regression of SL-11041 --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 4 ++-- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 4 ++-- .../newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 5fb3dc12e6..0d180e5798 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -111,8 +111,8 @@ void main() vec3 sun_contrib = final_da * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit * 2.0; - color.rgb *= ambient * 0.5; + color.rgb = amblit; + color.rgb *= ambient; #endif vec3 post_ambient = color.rgb; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 53cdce4cb1..23ed3fb3d9 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -119,8 +119,8 @@ void main() vec3 sun_contrib = min(scol, final_da) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit * 2.0; - color.rgb *= ambient * 0.5; + color.rgb = amblit; + color.rgb *= ambient; #endif vec3 post_ambient = color.rgb; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index ee745b48c2..ee9c990b12 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -36,8 +36,8 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) return light; } light *= atten.r; - light += additive * 2.0; - return light; + light += additive; + return light * 2.0; } vec3 atmosLighting(vec3 light) -- cgit v1.2.3 From 5bd055fe585233b3c43e02f2082f5a95f79b825b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Jun 2019 14:33:28 -0700 Subject: SL-10829 the 2nd Made pointLightF use correct colorspace as multiPoint already was. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 +-- indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 241857dd92..20dc03d7a5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -122,9 +122,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec lv = normalize(lv); //distance attenuation - fa += 1.0f; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; + dist_atten *= 2.0f; if (dist_atten <= 0.0) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8ebb2f44d3..6e5ec7d34c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -117,10 +117,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe lv = normalize(lv); //distance attenuation - fa += 1.0f; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; - //dist_atten *= 2.0f; + dist_atten *= 2.0f; if (dist_atten <= 0.0) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index b3ce1ce2e0..d805c9ea48 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -58,6 +58,7 @@ uniform vec4 viewport; vec3 getNorm(vec2 pos_screen); vec4 getPosition(vec2 pos_screen); +vec3 srgb_to_linear(vec3 c); void main() { @@ -89,6 +90,7 @@ void main() float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; + col.rgb = srgb_to_linear(col.rgb); float fa = falloff+1.0; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); -- cgit v1.2.3 From 81c90124829c6830a3511bd6064e4ff07c94e35a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Jun 2019 14:44:10 -0700 Subject: SL-11406 Fix alpha output of fullbright deferred materials objects. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6e5ec7d34c..a82af996a1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -280,6 +280,10 @@ void main() final_color.a = max(final_color.a, emissive_brightness); #endif +#if !defined(HAS_NORMAL_MAP) + final_color.a = 0.0f; +#endif + vec4 final_specular = spec; final_specular.a = specular_color.a; #ifdef HAS_SPECULAR_MAP -- cgit v1.2.3 From 0728a31a8ff3d2f9272c2d8c47420cf46ce5ad82 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Jun 2019 15:31:22 -0700 Subject: SL-11051 Make genDrawInfo pay more attention to faces with 100% transparency that are not invisiprims. --- .../app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index b2fbd8b86c..0d028d2729 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -43,8 +43,6 @@ void main() { float alpha = diffuseLookup(vary_texcoord0.xy).a; - alpha *= vertex_color.a; - // mask cutoff 0 -> no shadow SL-11051 if (minimum_alpha == 0) { @@ -64,6 +62,8 @@ void main() } } + alpha *= vertex_color.a; + frag_color = vec4(1,1,1,1); #if !defined(DEPTH_CLAMP) -- cgit v1.2.3 From c1d1d7968325403a8033fa79567f07345c49b0a8 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 19 Jun 2019 13:01:06 -0700 Subject: Sky fixes. Make class1 sky use pre-projection pos to get proper distances for attenuation. Make all sky shaders use the dist_mul again. Revert to using old sky tessellation logic (may regress bugs addressed by new tess code). --- indra/newview/app_settings/shaders/class1/deferred/skyF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/skyV.glsl | 11 +++++------ indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 3 +-- indra/newview/app_settings/shaders/class2/windlight/skyV.glsl | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 7d4d9eb49f..65e4fdf17f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -41,6 +41,7 @@ uniform vec4 gamma; /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); +vec3 srgb_to_linear(vec3 c); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 45e79f36ea..b30651351d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -66,7 +66,7 @@ void main() gl_Position = pos; // Get relative position - vec3 P = pos.xyz - camPosLocal.xyz + vec3(0,50,0); + vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); // Set altitude if (P.y > 0.) @@ -81,7 +81,7 @@ void main() // Can normalize then vec3 Pn = normalize(P); - float Plen = length(P); + float Plen = length(P); // Initialize temp variables vec4 temp1 = vec4(0.); @@ -114,9 +114,7 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - //temp1 = exp(-temp1 * temp2.z * dist_mul); - temp1 = exp(-temp1 * dist_mul); - + temp1 = exp(-temp1 * temp2.z * dist_mul); // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); @@ -132,12 +130,13 @@ void main() // Add "minimum anti-solar illumination" temp2.x += .25; - temp2.x *= sun_moon_glow_factor; + //temp2.x *= sun_moon_glow_factor; vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient_color) + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) ); + // Final atmosphere additive color *= (1. - temp1); diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 889a989985..3bdcf28363 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -141,8 +141,7 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - //temp1 = exp(-temp1 * temp2.z * dist_mul); - temp1 = exp(-temp1 * dist_mul); + temp1 = exp(-temp1 * temp2.z * dist_mul); // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index eb5ab0f012..e6a4f3833c 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -111,7 +111,7 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * dist_mul); + temp1 = exp(-temp1 * temp2.z * dist_mul); // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); -- cgit v1.2.3 From 81659325b8978f78cc2633836404bfb0892564e9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 20 Jun 2019 08:49:09 -0700 Subject: SL-11373 Fix class2/windlight clouds. --- .../shaders/class1/deferred/cloudsV.glsl | 2 +- .../shaders/class2/windlight/cloudsV.glsl | 210 ++++++++++----------- 2 files changed, 103 insertions(+), 109 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 9f49432c7d..20ab0fb171 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -110,7 +110,7 @@ void main() light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); // Calculate relative weights - temp1 = blue_density + haze_density; + temp1 = abs(blue_density) + vec4(abs(haze_density)); blue_weight = blue_density / temp1; haze_weight = haze_density / temp1; diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index 372c782d74..18daa5a242 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -57,7 +57,6 @@ uniform float haze_density; uniform float cloud_shadow; uniform float density_multiplier; -uniform float distance_multiplier; uniform float max_y; uniform vec4 glow; @@ -70,136 +69,131 @@ uniform float cloud_scale; void main() { - // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + // World / view / projection + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - vary_texcoord0 = texcoord0; + vary_texcoord0 = texcoord0; - // Get relative position - vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); + // Get relative position + vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); // fade clouds beyond a certain point so the bottom of the sky dome doesn't look silly at high altitude altitude_blend_factor = (P.y > -4096.0) ? 1.0 : 1.0 - clamp(abs(P.y) / max_y, 0.0, 1.0); - // Set altitude - if (P.y > 0.) - { - P *= (max_y / P.y); - } - else - { - P *= (-32000. / P.y); - } - - - // Can normalize then - vec3 Pn = normalize(P); - float Plen = length(P); - - // Initialize temp variables - vec4 temp1 = vec4(0.); - vec4 temp2 = vec4(0.); - vec4 blue_weight; - vec4 haze_weight; - //vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; - vec4 sunlight = sunlight_color; - vec4 light_atten; + // Set altitude + if (P.y > 0.) + { + P *= (max_y / P.y); + } + else + { + P *= (-32000. / P.y); + } + + // Can normalize then + vec3 Pn = normalize(P); + float Plen = length(P); + + // Initialize temp variables + vec4 temp1 = vec4(0.); + vec4 temp2 = vec4(0.); + vec4 blue_weight; + vec4 haze_weight; + //vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; + vec4 sunlight = sunlight_color; + vec4 light_atten; float dens_mul = density_multiplier; - float dist_mul = max(0.05, distance_multiplier); - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); - - // Calculate relative weights - temp1 = blue_density + haze_density; - blue_weight = blue_density / temp1; - haze_weight = haze_density / temp1; - - // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Distance - temp2.z = Plen * dens_mul; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati - // compiler gets confused. - //temp1 = exp(-temp1 * temp2.z * dist_mul); - temp1 = exp(-temp1 * dist_mul); - - // Compute haze glow - temp2.x = dot(Pn, lightnorm.xyz); - temp2.x = 1. - temp2.x; - // temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .001); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - temp2.x *= sun_moon_glow_factor; + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); + + // Calculate relative weights + temp1 = abs(blue_density) + vec4(abs(haze_density)); + blue_weight = blue_density / temp1; + haze_weight = haze_density / temp1; + + // Compute sunlight from P & lightnorm (for long rays like sky) + temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Distance + temp2.z = Plen * dens_mul; - // Add "minimum anti-solar illumination" - temp2.x += .25; + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z); + + + // Compute haze glow + temp2.x = dot(Pn, lightnorm.xyz); + temp2.x = 1. - temp2.x; + // temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .001); + // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + // Higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + temp2.x *= sun_moon_glow_factor; - // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient_color; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + // Add "minimum anti-solar illumination" + temp2.x += .25; - // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); + // Increase ambient when there are more clouds + vec4 tmpAmbient = ambient_color; + tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; - // Haze color below cloud - vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) - ); + // Dim sunlight by cloud shadow percentage + sunlight *= (1. - cloud_shadow); - // CLOUDS + // Haze color below cloud + vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) + ); - sunlight = sunlight_color; - temp2.y = max(0., lightnorm.y * 2.); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); + // CLOUDS + temp2.y = max(0., lightnorm.y * 2.); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); - // Cloud color out - vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; - vary_CloudColorAmbient = tmpAmbient * cloud_color; - - // Attenuate cloud color by atmosphere - temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds - vary_CloudColorSun *= temp1; - vary_CloudColorAmbient *= temp1; - vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); + // Cloud color out + vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; + vary_CloudColorAmbient = tmpAmbient * cloud_color; + + // Attenuate cloud color by atmosphere + temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds + vary_CloudColorSun *= temp1; + vary_CloudColorAmbient *= temp1; + vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); - // Make a nice cloud density based on the cloud_shadow value that was passed in. - vary_CloudDensity = 2. * (cloud_shadow - 0.25); + // Make a nice cloud density based on the cloud_shadow value that was passed in. + vary_CloudDensity = 2. * (cloud_shadow - 0.25); - // Texture coords - vary_texcoord0 = texcoord0; - vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; - //vary_texcoord0.xy /= max(0.001, cloud_scale); - vary_texcoord0.xy += 0.5; + // Texture coords + vary_texcoord0 = texcoord0; + vary_texcoord0.xy -= 0.5; + vary_texcoord0.xy /= cloud_scale; + vary_texcoord0.xy += 0.5; - vary_texcoord1 = vary_texcoord0; - vary_texcoord1.x += lightnorm.x * 0.0125; - vary_texcoord1.y += lightnorm.z * 0.0125; + vary_texcoord1 = vary_texcoord0; + vary_texcoord1.x += lightnorm.x * 0.0125; + vary_texcoord1.y += lightnorm.z * 0.0125; - vary_texcoord2 = vary_texcoord0 * 16.; - vary_texcoord3 = vary_texcoord1 * 16.; + vary_texcoord2 = vary_texcoord0 * 16.; + vary_texcoord3 = vary_texcoord1 * 16.; - // Combine these to minimize register use - vary_CloudColorAmbient += oHazeColorBelowCloud; + // Combine these to minimize register use + vary_CloudColorAmbient += oHazeColorBelowCloud; - // needs this to compile on mac - //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); + // needs this to compile on mac + //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); - // END CLOUDS + // END CLOUDS } -- cgit v1.2.3 From 05ee6b5d9837c31660a79dea55ec877155b49009 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 20 Jun 2019 15:07:17 -0700 Subject: SL-9989 Remove use of distance multiplier from sky shaders (but leave in the atmospherics helpers). --- indra/newview/app_settings/shaders/class1/deferred/skyV.glsl | 3 +-- indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 3 +-- indra/newview/app_settings/shaders/class2/windlight/skyV.glsl | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index b30651351d..5ce246a114 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -92,7 +92,6 @@ void main() vec4 light_atten; float dens_mul = density_multiplier; - float dist_mul = max(0.05, distance_multiplier); // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes @@ -114,7 +113,7 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * dist_mul); + temp1 = exp(-temp1 * temp2.z); // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 3bdcf28363..b826cff304 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -119,7 +119,6 @@ void main() vec4 light_atten; float dens_mul = density_multiplier; - float dist_mul = max(0.05, distance_multiplier); // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes @@ -141,7 +140,7 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * dist_mul); + temp1 = exp(-temp1 * temp2.z); // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index e6a4f3833c..d81a8feb96 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -111,7 +111,7 @@ void main() // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * dist_mul); + temp1 = exp(-temp1 * temp2.z); // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); -- cgit v1.2.3 From d86464182dd69aac5368f77dbb11a3e84ce4dadb Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 25 Jun 2019 11:39:33 -0700 Subject: SL-1491 Nerf backfacing additive in ALM to prevent lens flares when facing away from sun. Use hack in spec gbuffer alpha to nerf additive only on terrain (leaves additive glare for sunsets on water). --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 3 ++- indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 0d180e5798..fd1191547b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -176,7 +176,8 @@ vec3 post_env = color.rgb; if (norm.w < 1) { #if !defined(SUNLIGHT_KILL) - color = atmosFragLighting(color, additive, atten); + float additive_angular_atten = max(0.0, dot(light_dir, normalize(pos.xyz))); + color = atmosFragLighting(color, additive * additive_angular_atten * (1.0 - spec.a), atten); color = scaleSoftClipFrag(color); #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index b49d86b2a2..5f345078b6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -69,7 +69,7 @@ void main() #endif frag_data[0] = outColor; - frag_data[1] = vec4(0.0,0.0,0.0,0.0); + frag_data[1] = vec4(0.0,0.0,0.0,1.0); vec3 nvn = normalize(vary_normal); frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 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 23ed3fb3d9..ee39fa81f5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -184,7 +184,9 @@ vec3 post_env = color.rgb; if (norm.w < 1) { #if !defined(SUNLIGHT_KILL) - color = atmosFragLighting(color, additive, atten); + vec3 p = normalize(pos.xyz); + float additive_angular_atten = max(0.0, dot(light_dir.xyz, p.xyz)); + color = atmosFragLighting(color, additive * additive_angular_atten * (1.0 - spec.a), atten); color = scaleSoftClipFrag(color); #endif } -- cgit v1.2.3 From 8ba159fed90fc221003e85c5d2d3b82ec30d81bf Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 27 Jun 2019 09:10:38 -0700 Subject: SL-11151, SL-11504 Remove update threshold logic causing hiccups and rework sky updates. Make deferred water do double transport again to match non-ALM rendering more closely. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index fd5b6989eb..8554ebef0b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -164,7 +164,7 @@ void main() color.rgb += spec * specular; - //color.rgb = atmosTransport(color.rgb); + color.rgb = atmosTransport(color.rgb); color.rgb = scaleSoftClip(color.rgb); color.a = spec * sunAngle2; -- cgit v1.2.3 From 774d91b20bcc1ac57ab29d58fc492ec369d1fc44 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 27 Jun 2019 09:46:15 -0700 Subject: SL-11503 Make underwater terrain shader mult vert lighting. --- .../app_settings/shaders/class1/environment/terrainWaterF.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl index 937f38842f..bbfec3b532 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl @@ -55,8 +55,10 @@ void main() float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); - + + outColor.rgb *= vertex_color.rgb; outColor = applyWaterFog(outColor); + frag_color = outColor; } -- cgit v1.2.3 From 4b8ec2f11f94d8fe253abd5228320c545f353b58 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 27 Jun 2019 15:15:09 -0700 Subject: SL-11503 take two Make ALM use of non-ALM water rendering for refraction map light differently than non-ALM use of same. --- .../shaders/class1/environment/terrainWaterV.glsl | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class1/environment/terrainWaterV.glsl (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainWaterV.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainWaterV.glsl new file mode 100644 index 0000000000..416d406f68 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/terrainWaterV.glsl @@ -0,0 +1,88 @@ +/** + * @file class1\environment\terrainV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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 mat3 normal_matrix; +uniform mat4 texture_matrix0; +uniform mat4 modelview_matrix; +uniform mat4 modelview_projection_matrix; + +uniform vec4 object_plane_t; +uniform vec4 object_plane_s; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec3 normal; +ATTRIBUTE vec2 texcoord0; +ATTRIBUTE vec2 texcoord1; +ATTRIBUTE vec4 diffuse_color; + +VARYING vec4 vertex_color; +VARYING vec4 vary_texcoord0; +VARYING vec4 vary_texcoord1; + +void calcAtmospherics(vec3 inPositionEye); +vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); + +vec4 texgen_object(vec4 vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1) +{ + vec4 tcoord; + + tcoord.x = dot(vpos, tp0); + tcoord.y = dot(vpos, tp1); + tcoord.z = tc.z; + tcoord.w = tc.w; + + tcoord = mat * tcoord; + + return tcoord; +} + +void main() +{ + //transform vertex + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + + vec4 pos = modelview_matrix * vec4(position.xyz, 1.0); + vec3 norm = normalize(normal_matrix * normal); + + calcAtmospherics(pos.xyz); + + vec4 color = calcLighting(pos.xyz, norm, vec4(1.0)); + +#if defined(ALM) + color.rgb *= 0.5f; +#endif + + vertex_color.rgb = color.rgb; + + // Transform and pass tex coords + vary_texcoord0.xy = texgen_object(vec4(position.xyz, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; + + vec4 t = vec4(texcoord1,0,1); + + vary_texcoord0.zw = t.xy; + vary_texcoord1.xy = t.xy-vec2(2.0, 0.0); + vary_texcoord1.zw = t.xy-vec2(1.0, 0.0); +} + -- cgit v1.2.3 From 7c651f84234813eb0ceb2c72e0c19acf2bb15f55 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 27 Jun 2019 16:07:54 -0700 Subject: SL-11512 Modify method for nerfing additive on terrain so it doesn't trip up deferred lighting and make light artifacts. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 3 ++- indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index fd1191547b..4825418fe3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -176,8 +176,9 @@ vec3 post_env = color.rgb; if (norm.w < 1) { #if !defined(SUNLIGHT_KILL) + additive *= spec.a; float additive_angular_atten = max(0.0, dot(light_dir, normalize(pos.xyz))); - color = atmosFragLighting(color, additive * additive_angular_atten * (1.0 - spec.a), atten); + color = atmosFragLighting(color, additive * additive_angular_atten, atten); color = scaleSoftClipFrag(color); #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 5f345078b6..b7bc92c460 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -69,7 +69,7 @@ void main() #endif frag_data[0] = outColor; - frag_data[1] = vec4(0.0,0.0,0.0,1.0); + frag_data[1] = vec4(0.0,0.0,0.0,-1.0); vec3 nvn = normalize(vary_normal); frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 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 ee39fa81f5..d4d69f07e8 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -185,8 +185,9 @@ vec3 post_env = color.rgb; { #if !defined(SUNLIGHT_KILL) vec3 p = normalize(pos.xyz); + additive *= spec.a; float additive_angular_atten = max(0.0, dot(light_dir.xyz, p.xyz)); - color = atmosFragLighting(color, additive * additive_angular_atten * (1.0 - spec.a), atten); + color = atmosFragLighting(color, additive * additive_angular_atten, atten); color = scaleSoftClipFrag(color); #endif } -- cgit v1.2.3 From c1697079937eade10765353039b4801d029c72fa Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 28 Jun 2019 10:58:32 -0700 Subject: SL-9928 Remove spec killing additive fix for 1491 to unbreak fog. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 4825418fe3..f9fe091124 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -176,7 +176,7 @@ vec3 post_env = color.rgb; if (norm.w < 1) { #if !defined(SUNLIGHT_KILL) - additive *= spec.a; + //additive *= spec.a; float additive_angular_atten = max(0.0, dot(light_dir, normalize(pos.xyz))); color = atmosFragLighting(color, additive * additive_angular_atten, atten); color = scaleSoftClipFrag(color); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index d4d69f07e8..d1b49d8820 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -185,7 +185,7 @@ vec3 post_env = color.rgb; { #if !defined(SUNLIGHT_KILL) vec3 p = normalize(pos.xyz); - additive *= spec.a; + //additive *= spec.a; float additive_angular_atten = max(0.0, dot(light_dir.xyz, p.xyz)); color = atmosFragLighting(color, additive * additive_angular_atten, atten); color = scaleSoftClipFrag(color); -- cgit v1.2.3 From 4e796ce8982e4e64e91a221c4acd78099c5bf58d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 28 Jun 2019 11:07:44 -0700 Subject: SL-9928 Take out angular atten on additive too. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 4 +--- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index f9fe091124..0d180e5798 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -176,9 +176,7 @@ vec3 post_env = color.rgb; if (norm.w < 1) { #if !defined(SUNLIGHT_KILL) - //additive *= spec.a; - float additive_angular_atten = max(0.0, dot(light_dir, normalize(pos.xyz))); - color = atmosFragLighting(color, additive * additive_angular_atten, atten); + color = atmosFragLighting(color, additive, atten); color = scaleSoftClipFrag(color); #endif } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index d1b49d8820..eeab6ed03d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -185,9 +185,7 @@ vec3 post_env = color.rgb; { #if !defined(SUNLIGHT_KILL) vec3 p = normalize(pos.xyz); - //additive *= spec.a; - float additive_angular_atten = max(0.0, dot(light_dir.xyz, p.xyz)); - color = atmosFragLighting(color, additive * additive_angular_atten, atten); + color = atmosFragLighting(color, additive, atten); color = scaleSoftClipFrag(color); #endif } -- cgit v1.2.3 From 83d3e565f702c5c7baefbe7800428ae80da134c5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 28 Jun 2019 14:47:24 -0700 Subject: Modify water blend between refl and refr maps to preserve sunset colors more like non-ALM. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 8554ebef0b..b24da15a07 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -155,16 +155,18 @@ void main() vec2 distort2 = distort+wavef.xy*(refScale * 0.01)/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); + fb.rgb = srgb_to_linear(fb.rgb); //mix with reflection // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.999999); + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.49999 + 0.5); vec4 pos = vary_position; color.rgb += spec * specular; - - color.rgb = atmosTransport(color.rgb); + + //color.rgb = atmosTransport(color.rgb); + color.rgb *= 2.0f; color.rgb = scaleSoftClip(color.rgb); color.a = spec * sunAngle2; -- cgit v1.2.3 From 118151750d908a8990bd611afc1dc9be7563ce6e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 28 Jun 2019 15:33:39 -0700 Subject: SL-11381 Make fullbright alpha test use correct handling when mask cutoff == 0. --- .../newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index f7368e8652..c104dc884f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -65,12 +65,7 @@ void main() float final_alpha = color.a * vertex_color.a; #ifdef HAS_ALPHA_MASK - if (color.a < 0.05) - { - discard; - } - - if (minimum_alpha > 0 && color.a < minimum_alpha) + if (color.a < minimum_alpha) { discard; } -- cgit v1.2.3 From f770e55ac6fb76f1ea5e24a4dd91f2a4b4131d6d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 1 Jul 2019 12:04:26 -0700 Subject: SL-11427 Fixed downscaling of the refscale passed in from WL in the water shader. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 2 +- indra/newview/app_settings/shaders/class1/environment/waterF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index b24da15a07..5a3a02d5d1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -152,7 +152,7 @@ void main() spec = pow(spec, 128.0); //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*(refScale * 0.01)/max(dmod*df1, 1.0); + vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); fb.rgb = srgb_to_linear(fb.rgb); diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index 4e550b8284..05fd4461c1 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -144,7 +144,7 @@ void main() spec = pow(spec, 128.0); //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*(refScale*0.01)/max(dmod*df1, 1.0); + vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); -- cgit v1.2.3 From 7e5000bb64ca8eea3fe188ebb7bccff3bdfa82e7 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Jul 2019 11:20:09 -0700 Subject: SL-11533 Make alpha shader include vertex color modulation in both srgb and linear flavors. --- .../newview/app_settings/shaders/class1/deferred/alphaF.glsl | 12 ++---------- .../newview/app_settings/shaders/class1/deferred/alphaV.glsl | 10 ---------- 2 files changed, 2 insertions(+), 20 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 20dc03d7a5..15408b3475 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -53,9 +53,7 @@ VARYING vec3 vary_position; VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; -#ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; -#endif uniform mat4 proj_mat; uniform mat4 inv_proj; @@ -191,12 +189,9 @@ void main() color.rgb = diffuse_srgb.rgb; color.a = 1.0; -#ifdef USE_VERTEX_COLOR float final_alpha = diffuse_srgb.a * vertex_color.a; diffuse_srgb.rgb *= vertex_color.rgb; -#else - float final_alpha = diffuse_srgb.a; -#endif + diffuse_linear.rgb *= vertex_color.rgb; // Insure we don't pollute depth with invis pixels in impostor rendering // @@ -206,12 +201,9 @@ void main() } #else -#ifdef USE_VERTEX_COLOR float final_alpha = diffuse_linear.a * vertex_color.a; + diffuse_srgb.rgb *= vertex_color.rgb; diffuse_linear.rgb *= vertex_color.rgb; -#else - float final_alpha = diffuse_linear.a; -#endif vec3 sunlit; vec3 amblit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 506118d381..619c4e9738 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -40,11 +40,7 @@ void passTextureIndex(); #endif ATTRIBUTE vec3 normal; - -#ifdef USE_VERTEX_COLOR ATTRIBUTE vec4 diffuse_color; -#endif - ATTRIBUTE vec2 texcoord0; #ifdef HAS_SKIN @@ -57,11 +53,7 @@ mat4 getSkinnedTransform(); VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; - -#ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; -#endif - VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; @@ -118,9 +110,7 @@ void main() vary_norm = norm; vary_position = pos.xyz; -#ifdef USE_VERTEX_COLOR vertex_color = diffuse_color; -#endif #ifdef HAS_SKIN vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); -- cgit v1.2.3 From 48f169423ba0c1da8ffe13fc8bc4cec76336d8fc Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 3 Jul 2019 10:04:05 -0700 Subject: SL-11545, SL-11543, SL-10625 Fix emissives without normal maps clobbering the alpha output in materialF. Modify glow size calc to get close to pre-EEP sun glow behavior (may require sky vert settings >= mid). Make bake ignore alpha readback for Intel until we can determine why their drivers now go boom. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 14 ++++++-------- .../newview/app_settings/shaders/class1/deferred/skyV.glsl | 2 +- .../shaders/class1/environment/terrainWaterV.glsl | 4 ---- .../shaders/class1/windlight/atmosphericsFuncs.glsl | 6 +++--- .../newview/app_settings/shaders/class2/deferred/skyF.glsl | 2 +- .../app_settings/shaders/class2/windlight/skyV.glsl | 2 +- 6 files changed, 12 insertions(+), 18 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a82af996a1..a8cac3e5a9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -273,15 +273,11 @@ void main() vec2 abnormal = encode_normal(norm.xyz); vec4 final_color = diffuse_linear; - -#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = emissive_brightness; -#else - final_color.a = max(final_color.a, emissive_brightness); -#endif -#if !defined(HAS_NORMAL_MAP) - final_color.a = 0.0f; +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) + // nop, use content of alpha emissive mask as is... +#else + final_color.a = emissive_brightness; #endif vec4 final_specular = spec; @@ -459,6 +455,8 @@ vec3 post_atmo = color.rgb; #else // deferred path + +final_color = diffuse_linear; frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 5ce246a114..c3b046552c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -121,7 +121,7 @@ void main() // temp2.x is 0 at the sun and increases away from sun temp2.x = max(temp2.x, .001); // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; + temp2.x *= glow.x * 0.33333; // Higher glow.x gives dimmer glow (because next step is 1 / "angle") temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainWaterV.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainWaterV.glsl index 416d406f68..a075cfeef2 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainWaterV.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainWaterV.glsl @@ -70,10 +70,6 @@ void main() vec4 color = calcLighting(pos.xyz, norm, vec4(1.0)); -#if defined(ALM) - color.rgb *= 0.5f; -#endif - vertex_color.rgb = color.rgb; // Transform and pass tex coords diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index deda4d8b7e..786a65df0f 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -68,7 +68,7 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o vec4 light_atten; float dens_mul = density_multiplier; - float dist_mul = max(0.05, distance_multiplier); + float dist_mul = distance_multiplier; //sunlight attenuation effect (hue and brightness) due to atmosphere //this is used later for sunlight modulation at various altitudes @@ -107,9 +107,9 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o //temp2.x is 0 at the sun and increases away from sun temp2.x = max(temp2.x, .001); //was glow.y //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x * 1.8; + temp2.x *= glow.x; //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z * 0.2); + temp2.x = pow(temp2.x, glow.z); //glow.z should be negative, so we're doing a sort of (1 / "angle") function //add "minimum anti-solar illumination" diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index b826cff304..e3e58dd046 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -148,7 +148,7 @@ void main() // temp2.x is 0 at the sun and increases away from sun temp2.x = max(temp2.x, .001); // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; + temp2.x *= glow.x * 0.33333; // Higher glow.x gives dimmer glow (because next step is 1 / "angle") temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index d81a8feb96..57ad8a92e5 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -119,7 +119,7 @@ void main() // temp2.x is 0 at the sun and increases away from sun temp2.x = max(temp2.x, .001); // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; + temp2.x *= glow.x * 0.333333; // Higher glow.x gives dimmer glow (because next step is 1 / "angle") temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function -- cgit v1.2.3 From 9f2148cc1f2469a1f45f8f3f736251a0300d1d6a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 5 Jul 2019 11:21:45 -0700 Subject: SL-11552 Fix materialF including debug force to linear color and re-add logic to stomp emissiveness when normals are not present unless explicitly requested via diffuse alpha mode. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a8cac3e5a9..72b1535332 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -25,7 +25,7 @@ /*[EXTRA_CODE_HERE]*/ -#define DIFFUSE_ALPHA_MODE_IGNORE 0 +#define DIFFUSE_ALPHA_MODE_NONE 0 #define DIFFUSE_ALPHA_MODE_BLEND 1 #define DIFFUSE_ALPHA_MODE_MASK 2 #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 @@ -274,10 +274,11 @@ void main() vec4 final_color = diffuse_linear; -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) - // nop, use content of alpha emissive mask as is... -#else - final_color.a = emissive_brightness; +#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) + final_color.a = max(final_color.a, emissive_brightness); + #if !defined(HAS_NORMAL_MAP) + final_color.a = 0.0f; + #endif #endif vec4 final_specular = spec; @@ -455,8 +456,6 @@ vec3 post_atmo = color.rgb; #else // deferred path - -final_color = diffuse_linear; frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. -- cgit v1.2.3 From c1b6d91c32ae4ab0bd9a19d92dc95110d937d940 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 8 Jul 2019 10:48:34 -0700 Subject: SL-11540 Make class1/environment and class1/deferred water match. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 6 ++---- indra/newview/app_settings/shaders/class1/environment/waterF.glsl | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 5a3a02d5d1..51b131ada7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -155,18 +155,16 @@ void main() vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); - fb.rgb = srgb_to_linear(fb.rgb); //mix with reflection // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.49999 + 0.5); + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999f); vec4 pos = vary_position; color.rgb += spec * specular; //color.rgb = atmosTransport(color.rgb); - color.rgb *= 2.0f; color.rgb = scaleSoftClip(color.rgb); color.a = spec * sunAngle2; @@ -175,5 +173,5 @@ void main() frag_data[0] = vec4(color.rgb, color); // diffuse frag_data[1] = vec4(0); // speccolor, spec - frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 + frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.0, 0);// normalxy, 0, 0 } diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index 05fd4461c1..750de7100f 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -121,6 +121,7 @@ void main() vec4 refcol = refcol1 + refcol2 + refcol3; float df1 = df.x + df.y + df.z; + df1 *= 0.666666f; refcol *= df1; vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; @@ -155,6 +156,9 @@ void main() color.a = spec * sunAngle2; + //color.rgb = atmosTransport(color.rgb); + color.rgb = scaleSoftClip(color.rgb); + #if defined(WATER_EDGE) gl_FragDepth = 0.9999847f; #endif -- cgit v1.2.3 From 5e84b7af3513851e52606a9c4610041ad1aec177 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 8 Jul 2019 13:23:43 -0700 Subject: Fix materials content being emissive when it should not. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 72b1535332..4cbef89fef 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -272,14 +272,12 @@ void main() vec2 abnormal = encode_normal(norm.xyz); - vec4 final_color = diffuse_linear; + vec4 final_color = vec4(diffuse_linear.rgb, 0.0); -#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = max(final_color.a, emissive_brightness); - #if !defined(HAS_NORMAL_MAP) - final_color.a = 0.0f; - #endif +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) + final_color.a = diffuse_linear.a; #endif + final_color.a = max(final_color.a, emissive_brightness); vec4 final_specular = spec; final_specular.a = specular_color.a; -- cgit v1.2.3 From 664722168d7016d8bf80a65626bbff542913dc24 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Jul 2019 14:50:59 -0700 Subject: SL-1491 Make sun additive contribition depend on facing the sun (without breaking fog). Put back scaling factor keeping sun contrib from blowing out with new FS param range for glow. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 7 ++++--- .../app_settings/shaders/class1/deferred/materialF.glsl | 7 ++++--- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 4 ++-- .../shaders/class1/windlight/atmosphericsFuncs.glsl | 10 ++++++++-- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 4 ++-- .../app_settings/shaders/class2/windlight/atmosphericsV.glsl | 4 ++-- .../app_settings/shaders/class3/windlight/atmosphericsV.glsl | 4 ++-- 7 files changed, 24 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 15408b3475..759c49a0fa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -75,7 +75,7 @@ vec2 encode_normal (vec3 n); vec3 scaleSoftClipFrag(vec3 l); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); -void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive, bool use_ao); +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive, bool use_ao); #ifdef HAS_SHADOW float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); @@ -201,6 +201,8 @@ void main() } #else + vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; + float final_alpha = diffuse_linear.a * vertex_color.a; diffuse_srgb.rgb *= vertex_color.rgb; diffuse_linear.rgb *= vertex_color.rgb; @@ -210,11 +212,10 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); vec2 abnormal = encode_normal(norm.xyz); - vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; float da = dot(norm.xyz, light_dir.xyz); da = clamp(da, -1.0, 1.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4cbef89fef..38792601f6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -41,7 +41,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); 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, bool use_ao); +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 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -304,6 +304,8 @@ void main() float envIntensity = final_normal.z; + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + vec3 color = vec3(0.0); float bloom = 0.0; @@ -312,11 +314,10 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float da = dot(normalize(norm.xyz), normalize(light_dir.xyz)); da = clamp(da, -1.0, 1.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 0d180e5798..269b76a19f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -59,7 +59,7 @@ 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, bool use_ao); +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); float getAmbientClamp(); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -101,7 +101,7 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, ambocc, sunlit, amblit, additive, atten, false); + calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, false); float ambient = da; ambient *= 0.5; diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 786a65df0f..3fe3b7afd3 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -47,7 +47,7 @@ float getAmbientClamp() return 1.0f; } -void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao) { +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 P = inPositionEye; @@ -103,13 +103,19 @@ void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, o //compute haze glow //(can use temp2.x as temp because we haven't used it yet) temp2.x = dot(Pn, tmpLightnorm.xyz); + + // dampen sun additive contrib when not facing it... + if (length(light_dir) > 0.01) + { + temp2.x *= max(0.0f, dot(light_dir, Pn)); + } temp2.x = 1. - temp2.x; //temp2.x is 0 at the sun and increases away from sun temp2.x = max(temp2.x, .001); //was glow.y //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) temp2.x *= glow.x; //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); + temp2.x = pow(temp2.x, glow.z * 0.2); //glow.z should be negative, so we're doing a sort of (1 / "angle") function //add "minimum anti-solar illumination" diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index eeab6ed03d..0223cef531 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -59,7 +59,7 @@ 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, bool use_ao); +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); float getAmbientClamp(); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); @@ -109,7 +109,7 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, ambocc, sunlit, amblit, additive, atten, true); + calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); float ambient = da; ambient *= 0.5; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index baba79ca96..a4bd0d566b 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -32,7 +32,7 @@ void setPositionEye(vec3 v); vec3 getAdditiveColor(); -void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); void calcAtmospherics(vec3 inPositionEye) { @@ -42,7 +42,7 @@ void calcAtmospherics(vec3 inPositionEye) { vec3 tmpamblit = vec3(1); vec3 tmpaddlit = vec3(1); vec3 tmpattenlit = vec3(1); - calcAtmosphericVars(inPositionEye, 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, false); + calcAtmosphericVars(inPositionEye, vec3(0), 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, false); setSunlitColor(tmpsunlit); setAmblitColor(tmpamblit); setAdditiveColor(tmpaddlit); diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl index 7b4269ca6f..b76192d73f 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl @@ -32,7 +32,7 @@ void setPositionEye(vec3 v); vec3 getAdditiveColor(); -void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); void calcAtmospherics(vec3 inPositionEye) { @@ -42,7 +42,7 @@ void calcAtmospherics(vec3 inPositionEye) { vec3 tmpamblit = vec3(1); vec3 tmpaddlit = vec3(1); vec3 tmpattenlit = vec3(1); - calcAtmosphericVars(inPositionEye, 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, true); + calcAtmosphericVars(inPositionEye, vec3(0), 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, true); setSunlitColor(tmpsunlit); setAmblitColor(tmpamblit); setAdditiveColor(tmpaddlit); -- cgit v1.2.3 From b8f64c55b7da9ee84f5ae570ff12cc3a57ca0d07 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 12 Jul 2019 09:34:38 -0700 Subject: SL-11545 Fix glow calcs in sky shaders (not just the not shared enough atmospherics funcs). Revert 10625 attempted fix as it breaks baggy clothes as much as skipping readbacks does. --- indra/newview/app_settings/shaders/class1/deferred/skyV.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/skyV.glsl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index c3b046552c..5ce246a114 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -121,7 +121,7 @@ void main() // temp2.x is 0 at the sun and increases away from sun temp2.x = max(temp2.x, .001); // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x * 0.33333; + temp2.x *= glow.x; // Higher glow.x gives dimmer glow (because next step is 1 / "angle") temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index e3e58dd046..b826cff304 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -148,7 +148,7 @@ void main() // temp2.x is 0 at the sun and increases away from sun temp2.x = max(temp2.x, .001); // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x * 0.33333; + temp2.x *= glow.x; // Higher glow.x gives dimmer glow (because next step is 1 / "angle") temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index 57ad8a92e5..d81a8feb96 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -119,7 +119,7 @@ void main() // temp2.x is 0 at the sun and increases away from sun temp2.x = max(temp2.x, .001); // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x * 0.333333; + temp2.x *= glow.x; // Higher glow.x gives dimmer glow (because next step is 1 / "angle") temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function -- cgit v1.2.3 From 11331604767b2dcf50c7a84f24843ce8e531a409 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 12 Jul 2019 13:26:02 -0700 Subject: SL-11109 Make shadowAlphaMask shader ignore vertex alpha before discards iff we're a fullbright object. Keep llappearance from stuffing dangling pointers into the alpha cache (crash iff you're using nSight debugging and disable readbacks). --- .../app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index 0d028d2729..9b8df0a5a4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -49,6 +49,10 @@ void main() discard; } +#if !defined(IS_FULLBRIGHT) + alpha *= vertex_color.a; +#endif + if (alpha < 0.05) // treat as totally transparent { discard; @@ -62,8 +66,6 @@ void main() } } - alpha *= vertex_color.a; - frag_color = vec4(1,1,1,1); #if !defined(DEPTH_CLAMP) -- cgit v1.2.3 From afdda55b8f6ad58c3e57185d3c352a923f4893aa Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 12 Jul 2019 14:45:15 -0700 Subject: SL-11588 Make avatar alpha shader ignore vertex color again. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 8 +++++++- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 759c49a0fa..0c4707098b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -53,7 +53,9 @@ VARYING vec3 vary_position; VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; +#ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; +#endif uniform mat4 proj_mat; uniform mat4 inv_proj; @@ -203,9 +205,13 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; - float final_alpha = diffuse_linear.a * vertex_color.a; + float final_alpha = diffuse_linear.a; + +#ifdef USE_VERTEX_COLOR + final_alpha *= vertex_color.a; diffuse_srgb.rgb *= vertex_color.rgb; diffuse_linear.rgb *= vertex_color.rgb; +#endif vec3 sunlit; vec3 amblit; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 619c4e9738..506118d381 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -40,7 +40,11 @@ void passTextureIndex(); #endif ATTRIBUTE vec3 normal; + +#ifdef USE_VERTEX_COLOR ATTRIBUTE vec4 diffuse_color; +#endif + ATTRIBUTE vec2 texcoord0; #ifdef HAS_SKIN @@ -53,7 +57,11 @@ mat4 getSkinnedTransform(); VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; + +#ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; +#endif + VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; @@ -110,7 +118,9 @@ void main() vary_norm = norm; vary_position = pos.xyz; +#ifdef USE_VERTEX_COLOR vertex_color = diffuse_color; +#endif #ifdef HAS_SKIN vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); -- cgit v1.2.3 From 2fa2da33022e0d64d02e0690f0345c5cc9dfca04 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 15 Jul 2019 15:59:45 -0700 Subject: SL-11590 Modified windlight shader to remove adjustment to glow.z --- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 3fe3b7afd3..0607ea8bc5 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -115,7 +115,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) temp2.x *= glow.x; //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z * 0.2); + temp2.x = pow(temp2.x, glow.z); //glow.z should be negative, so we're doing a sort of (1 / "angle") function //add "minimum anti-solar illumination" -- cgit v1.2.3 From aa4b24beee1d6451370983517d7ac3755429e26f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 22 Jul 2019 12:21:24 -0700 Subject: SL-11443 Make fullbright rigged objects with alpha mode none use fullbright shader instead of incorrectly using the material shader. Increase effect of variance in cloud shaders. --- .../newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl | 4 ++-- .../newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl | 4 ++-- indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl | 4 ++-- .../newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl | 4 ++-- indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl index 0efde5f949..0157d166e0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl @@ -82,12 +82,12 @@ void main() vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv1 += cloud_pos_density1.xy + (disturbance * 0.2); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); cloudDensity *= 1.0 - (density_variance * density_variance); diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index d6bd0a7917..f6694aae2a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -85,12 +85,12 @@ void main() vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv1 += cloud_pos_density1.xy + (disturbance * 0.2); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); cloudDensity *= 1.0 - (density_variance * density_variance); diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl index 1d004b2b3e..82fad4db5a 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl @@ -82,12 +82,12 @@ void main() vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv1 += cloud_pos_density1.xy + (disturbance * 0.2); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); cloudDensity *= 1.0 - (density_variance * density_variance); diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index e7ae2d52e3..3ac0fc224b 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -86,12 +86,12 @@ void main() vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv1 += cloud_pos_density1.xy + (disturbance * 0.2); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); cloudDensity *= 1.0 - (density_variance * density_variance); diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl index ae521afdad..32210f60dc 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl @@ -79,12 +79,12 @@ void main() vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv1 += cloud_pos_density1.xy + (disturbance * 0.2); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); cloudDensity *= 1.0 - (density_variance * density_variance); diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl index 1abe2fab63..e40d7e7c75 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -95,12 +95,12 @@ void main() vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); // Offset texture coords - uv1 += cloud_pos_density1.xy + disturbance; //large texture, visible density + uv1 += cloud_pos_density1.xy + (disturbance * 0.2); //large texture, visible density uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density + uv3 += cloud_pos_density2.xy; //small texture, visible density uv4 += cloud_pos_density2.xy; //small texture, self shadow - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0)); + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0) * 4.0); cloudDensity *= 1.0 - (density_variance * density_variance); -- cgit v1.2.3 From b507d63566e8896af702dd10f5643dc29068a8a9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Jul 2019 11:36:22 -0700 Subject: SL-11621 Remove all references to unused shader var global_gamma. Remove many unused decls for gamma from shaders. Make post-deferred gamma correction use display_gamma. Make setting display_gamma use the correct RenderDeferredDisplayGamma setting. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 3 --- indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl | 1 - indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 --- .../shaders/class1/deferred/postDeferredGammaCorrect.glsl | 3 +-- indra/newview/app_settings/shaders/class1/deferred/skyF.glsl | 2 -- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 1 - indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl | 1 - indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 1 - indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl | 1 - indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl | 7 ++----- indra/newview/app_settings/shaders/class2/windlight/skyF.glsl | 2 -- indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl | 1 - indra/newview/app_settings/shaders/class3/deferred/skyF.glsl | 1 - .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 3 --- 14 files changed, 3 insertions(+), 27 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 0c4707098b..546a502ee1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -37,10 +37,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform float display_gamma; -uniform vec4 gamma; uniform mat3 env_mat; - uniform vec3 sun_dir; uniform vec3 moon_dir; diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index f6694aae2a..ae1ac5de7f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -43,7 +43,6 @@ uniform sampler2D cloud_noise_texture_next; uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; -uniform vec4 gamma; uniform float cloud_scale; uniform float cloud_variance; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 38792601f6..a13c8de43e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -31,7 +31,6 @@ #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 uniform float emissive_brightness; -uniform float display_gamma; uniform int sun_up_factor; #ifdef WATER_FOG @@ -64,8 +63,6 @@ uniform sampler2D lightFunc; // Inputs uniform vec4 morphFactor; uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; -uniform vec4 gamma; uniform mat3 env_mat; uniform vec3 sun_dir; diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 058e939ec8..9f519708a2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -37,7 +37,6 @@ uniform sampler2DRect diffuseRect; uniform vec2 screen_res; VARYING vec2 vary_fragcoord; - uniform float display_gamma; vec3 linear_to_srgb(vec3 cl); @@ -45,7 +44,7 @@ vec3 linear_to_srgb(vec3 cl); void main() { vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - diff.rgb = linear_to_srgb(diff.rgb); + diff.rgb = pow(diff.rgb, vec3(display_gamma)); frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 65e4fdf17f..331249dc33 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -37,8 +37,6 @@ out vec4 frag_data[3]; VARYING vec4 vary_HazeColor; -uniform vec4 gamma; - /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); vec3 srgb_to_linear(vec3 c); diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 0607ea8bc5..4460ef905b 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -22,7 +22,6 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -uniform vec4 gamma; uniform vec4 lightnorm; uniform vec4 sunlight_color; uniform vec4 moonlight_color; diff --git a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl index 346634af33..fc51e81177 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/gammaF.glsl @@ -24,7 +24,6 @@ */ uniform int no_atmo; -uniform vec4 gamma; vec3 scaleSoftClipFrag(vec3 light) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index b826cff304..1dce85a83b 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -64,7 +64,6 @@ VARYING vec3 pos; // The fragment shader for the sky ///////////////////////////////////////////////////////////////////////// -uniform vec4 gamma; uniform sampler2D rainbow_map; uniform sampler2D halo_map; diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index 3ac0fc224b..75bf8730df 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -44,7 +44,6 @@ uniform sampler2D cloud_noise_texture_next; uniform float blend_factor; uniform vec4 cloud_pos_density1; uniform vec4 cloud_pos_density2; -uniform vec4 gamma; uniform float cloud_scale; uniform float cloud_variance; diff --git a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl index 5c339f9663..68db7fcbb1 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/gammaF.glsl @@ -22,10 +22,7 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - - - -uniform vec4 gamma; +uniform float gamma; uniform int no_atmo; vec3 getAtmosAttenuation(); @@ -39,7 +36,7 @@ vec3 scaleSoftClipFrag(vec3 light) } //soft clip effect: light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); + light = 1. - pow(light, vec3(gamma)); // s/b inverted already CPU-side return light; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl index de6fb276aa..7146349453 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl @@ -35,8 +35,6 @@ out vec4 frag_color; VARYING vec4 vary_HazeColor; -uniform vec4 gamma; - /// Soft clips the light with a gamma correction vec3 scaleSoftClip(vec3 light); diff --git a/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl b/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl index c02e6d1e57..d5d91c88f0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl @@ -37,7 +37,6 @@ uniform sampler2D transmittance_texture; uniform sampler3D scattering_texture; uniform sampler3D single_mie_scattering_texture; uniform sampler2D irradiance_texture; -uniform vec4 gamma; vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl index d0514f7d23..6de01cb667 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl @@ -44,7 +44,6 @@ uniform sampler3D single_mie_scattering_texture; uniform sampler2D irradiance_texture; uniform sampler2D rainbow_map; uniform sampler2D halo_map; -uniform vec4 gamma; uniform float moisture_level; uniform float droplet_radius; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 82a899ad65..978c25b86a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -50,7 +50,6 @@ uniform vec3 camPosLocal; uniform float cloud_shadow; uniform float max_y; uniform vec4 glow; -uniform float global_gamma; uniform mat3 env_mat; uniform vec4 shadow_clip; @@ -94,7 +93,6 @@ void main() norm.xyz = getNorm(tc); float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - da = pow(da, global_gamma + 0.3); vec4 diffuse = texture2DRect(diffuseRect, tc); // linear @@ -106,7 +104,6 @@ void main() vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; -// scol_ambocc = pow(scol_ambocc, vec3(global_gamma + 0.3)); float scol = max(scol_ambocc.r, diffuse.a); -- cgit v1.2.3 From 15f5d8caf8fc51999c4de4217ed5ac37fa911ae9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 24 Jul 2019 11:15:42 -0700 Subject: SL-10698 Reduce effect of refScale again to eliminate sampling beyond the correct area in the distortion map and getting the water fog color on the shoreline. --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 2 +- indra/newview/app_settings/shaders/class1/environment/waterF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 51b131ada7..b86867c460 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -152,7 +152,7 @@ void main() spec = pow(spec, 128.0); //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); + vec2 distort2 = distort+wavef.xy*refScale*0.16/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index 750de7100f..b3ae64bd82 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -145,7 +145,7 @@ void main() spec = pow(spec, 128.0); //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); + vec2 distort2 = distort+wavef.xy*refScale*0.16/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); -- cgit v1.2.3 From eb9a977a36742fb052b4d92c911c37816967cd6e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 24 Jul 2019 16:07:53 -0700 Subject: SL-11550 --- .../app_settings/shaders/class1/deferred/skyV.glsl | 2 - .../shaders/class2/windlight/skyV.glsl | 50 +++++++++++----------- 2 files changed, 24 insertions(+), 28 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 5ce246a114..2cd660ab79 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -129,8 +129,6 @@ void main() // Add "minimum anti-solar illumination" temp2.x += .25; - //temp2.x *= sun_moon_glow_factor; - vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient_color) + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) ); diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index d81a8feb96..0d141342ce 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -54,17 +54,19 @@ uniform float max_y; uniform vec4 glow; uniform float sun_moon_glow_factor; + uniform vec4 cloud_color; void main() { // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + gl_Position = pos; + // Get relative position vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); - //vec3 P = position.xyz + vec3(0,50,0); // Set altitude if (P.y > 0.) @@ -78,7 +80,8 @@ void main() // Can normalize then vec3 Pn = normalize(P); - float Plen = length(P); + + float Plen = length(P); // Initialize temp variables vec4 temp1 = vec4(0.); @@ -89,29 +92,28 @@ void main() vec4 light_atten; float dens_mul = density_multiplier; - float dist_mul = max(0.05, distance_multiplier); // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes light_atten = (blue_density + vec4(haze_density * 0.25)) * (dens_mul * max_y); // Calculate relative weights - temp1 = blue_density + haze_density; + temp1 = abs(blue_density) + vec4(abs(haze_density)); blue_weight = blue_density / temp1; haze_weight = haze_density / temp1; // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); + temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); // Distance temp2.z = Plen * dens_mul; // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); + // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z); // Compute haze glow temp2.x = dot(Pn, lightnorm.xyz); @@ -124,40 +126,36 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function - temp2.x *= sun_moon_glow_factor; - // Add "minimum anti-solar illumination" temp2.x += .25; + vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient_color) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) + ); - // Haze color above cloud - vary_HazeColor = ( blue_horizon * blue_weight * (sunlight + ambient_color) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient_color) - ); + // Final atmosphere additive + color *= (1. - temp1); // Increase ambient when there are more clouds vec4 tmpAmbient = ambient_color; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + tmpAmbient += max(vec4(0), (1. - ambient_color)) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); + sunlight *= max(0.0, (1. - cloud_shadow)); // Haze color below cloud vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) ); - // Final atmosphere additive - vary_HazeColor *= (1. - temp1); - // Attenuate cloud color by atmosphere temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds // At horizon, blend high altitude sky color towards the darker color below the clouds - vary_HazeColor += (additiveColorBelowCloud - vary_HazeColor) * (1. - sqrt(temp1)); - - // won't compile on mac without this being set - //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); + color += (additiveColorBelowCloud - color) * (1. - sqrt(temp1)); + + // Haze color above cloud + vary_HazeColor = color; } -- cgit v1.2.3 From 4e4011cddc4c6edf797bd3ff7950fb02d178a2e2 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 13 Aug 2019 08:14:14 -0700 Subject: SL-11589 Modify altitude blend factor in cloud shaders to fade more aggressively and fix cloud rendering artifacts when at altitude. --- indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl | 2 +- indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 20ab0fb171..8e90c1481f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -78,7 +78,7 @@ void main() // Get relative position vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); - altitude_blend_factor = (P.y > -4096.0) ? 1.0 : 1.0 - clamp(abs(P.y) / max_y, 0.0, 1.0); + altitude_blend_factor = clamp((P.y + 512.0) / max_y, 0.0, 1.0); // Set altitude if (P.y > 0.) diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index 18daa5a242..2c1475d547 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -78,7 +78,7 @@ void main() vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); // fade clouds beyond a certain point so the bottom of the sky dome doesn't look silly at high altitude - altitude_blend_factor = (P.y > -4096.0) ? 1.0 : 1.0 - clamp(abs(P.y) / max_y, 0.0, 1.0); + altitude_blend_factor = clamp((P.y + 512.0) / max_y, 0.0, 1.0); // Set altitude if (P.y > 0.) -- cgit v1.2.3 From 440a40c8f9fd35577470aee193a4b7dd128d80bb Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 22 Aug 2019 10:41:55 -0700 Subject: SL-11406 Restore code to stomp emissive in the absence of a normal map (to avoid fullbright implying full emissive). --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a13c8de43e..023172c844 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -276,6 +276,10 @@ void main() #endif final_color.a = max(final_color.a, emissive_brightness); +#if !defined(HAS_NORMAL_MAP) + final_color.a = 0.0f; +#endif + vec4 final_specular = spec; final_specular.a = specular_color.a; #ifdef HAS_SPECULAR_MAP -- cgit v1.2.3 From 2329beb3d3e3ad6501b6614578861012e4d9f4b0 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 23 Aug 2019 12:34:22 -0700 Subject: SL-11774 Fix diffuse boost when water fog is enabled and make deferred underwater shader participate in EEP/WL param updates by marking it as a water shader. --- .../shaders/class1/deferred/softenLightF.glsl | 4 ++- .../shaders/class1/deferred/underWaterF.glsl | 41 +--------------------- 2 files changed, 4 insertions(+), 41 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 269b76a19f..09b1813ebe 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -158,7 +158,9 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; -#ifndef WATER_FOG +#ifdef WATER_FOG + color.rgb += diffuse_srgb.rgb * diffuse_srgb.a * 0.25; +#else color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index 641c6fbd36..9a5debb3c1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -58,45 +58,8 @@ VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; -vec3 srgb_to_linear(vec3 c); vec2 encode_normal(vec3 n); -vec4 applyWaterFog(vec4 color, vec3 viewVec) -{ - //normalize view vector - vec3 view = normalize(viewVec); - float es = -view.z; - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - //get object depth - float depth = length(viewVec); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - //return vec4(1.0, 0.0, 1.0, 1.0); - return color * D + kc * L; - //depth /= 10.0; - //return vec4(depth,depth,depth,0.0); -} - void main() { vec4 color; @@ -113,9 +76,7 @@ void main() vec4 fb = texture2D(screenTex, distort); - fb.rgb = srgb_to_linear(fb.rgb); - frag_data[0] = vec4(fb.rgb, 1.0); // diffuse frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec - frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, displace + frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, env intens, atmo kill } -- cgit v1.2.3 From 16933b0ab9a8556467fba18790050f2d025d06a5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 3 Sep 2019 15:57:49 -0700 Subject: SL-11543, SL-11443 Fix faullbright/emissive problems. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 023172c844..fafecd57cc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -274,20 +274,16 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = diffuse_linear.a; #endif - final_color.a = max(final_color.a, emissive_brightness); -#if !defined(HAS_NORMAL_MAP) - final_color.a = 0.0f; -#endif + final_color.a = max(final_color.a, emissive_brightness); + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); vec4 final_specular = spec; + final_specular.a = specular_color.a; -#ifdef HAS_SPECULAR_MAP - final_specular.a *= norm.a; -#endif - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); -#ifdef HAS_SPECULAR_MAP +#if HAS_SPECULAR_MAP + final_specular.a *= norm.a; final_normal.z *= spec.a; #endif -- cgit v1.2.3 From 872d82529f7ca2afc3cbd3d1436c5026105da489 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 9 Sep 2019 09:08:58 -0700 Subject: SL-1144 The un-water-fogged gap area was rendering while we were still above water, but the water surface was being near culled. I've re-enabled preculling water objects (which also fixes issues with water culling vs spinning the camera) and it seems to behave correctly. --- .../app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 4460ef905b..e5f1e11180 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -121,7 +121,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou temp2.x += .25; temp2.x *= sun_moon_glow_factor; - + vec4 amb_color = ambient_color; //increase ambient when there are more clouds -- cgit v1.2.3 From 3dfdb2f6e8be4fb2a08102847520585dc1d8fd7d Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 29 Oct 2019 17:46:33 -0600 Subject: SL-10449 FIX [EEP] Fixed a (Mac-only) shader regression in changeset 41246 --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index fafecd57cc..9505f2eb74 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -277,13 +277,13 @@ void main() final_color.a = max(final_color.a, emissive_brightness); - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); + vec4 final_normal = vec4(abnormal, env_intensity, 0.0); vec4 final_specular = spec; final_specular.a = specular_color.a; -#if HAS_SPECULAR_MAP - final_specular.a *= norm.a; +#ifdef HAS_SPECULAR_MAP + final_specular.a *= norm.a; final_normal.z *= spec.a; #endif -- cgit v1.2.3 From 24920de799c8e2dd26854923c7a10fc4a551dd5d Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 19 Nov 2019 12:15:45 -0700 Subject: SL-11055 Add back pre-EEP fog burnthrough for fullbrights --- .../app_settings/shaders/class2/windlight/transportF.glsl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index d2d839ed05..a06f4f22ad 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -51,7 +51,14 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransport(vec3 light) { float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; - return atmosTransportFrag(light * 0.5, getAdditiveColor() * brightness, getAtmosAttenuation()); + vec3 attenColor = atmosTransportFrag(light * 0.5, getAdditiveColor() * brightness, getAtmosAttenuation()); + + // attenColor is an accurate fog-attenuated result for any brightness + // But, the pre-EEP shader included a brightness-indexed lerp to a non-attenuated version + // of the color - effectively a fog 'burn-through' for very bright pixels. To more closely + // match the pre-EEP behavior, we'll also lerp to the pre-EEP color, based on overall brightness + float preEepBright = dot(light.rgb, vec3(0.3333)); + retun mix(attenColor, (light.rgb + getAdditiveColor().rgb) * (2.0 - preEepBright), preEepBright * preEepBright); } vec3 fullbrightShinyAtmosTransport(vec3 light) -- cgit v1.2.3 From e1ea2c2b1eda89cf08fc31d3d1970446daea1883 Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Thu, 21 Nov 2019 05:25:18 +0000 Subject: SL-11406 Fix fullbright to better match non-EEP. Minor optimization cleanup. --- .../shaders/class1/deferred/materialF.glsl | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 9505f2eb74..e640c2d7ae 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -264,8 +264,7 @@ void main() tnorm = vary_normal; #endif - norm.xyz = tnorm; - norm.xyz = normalize(norm.xyz); + norm.xyz = normalize(tnorm.xyz); vec2 abnormal = encode_normal(norm.xyz); @@ -277,7 +276,20 @@ void main() final_color.a = max(final_color.a, emissive_brightness); - vec4 final_normal = vec4(abnormal, env_intensity, 0.0); + // SL-11406 Fullbright: Object > Texture > Shininess > Environment Intensity = 1 + // NOTE: There are two shaders that are used depending on the EI byte value: + // EI = 0 fullbright + // EI > 0 .. 255 material + // When it is passed to us it is normalized. + // We can either modify the output environment intensity + // OR + // adjust the final color via: + // final_color *= 0.666666; + // We remap the environment intensity to closely simulate what non-EEP is doing. + // At midnight the brightness is exact. + // At midday the brightness is very close. + float ei = env_intensity*0.5 + 0.5; + vec4 final_normal = vec4(abnormal, ei, 0.0); vec4 final_specular = spec; final_specular.a = specular_color.a; @@ -316,11 +328,11 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float da = dot(normalize(norm.xyz), normalize(light_dir.xyz)); - da = clamp(da, -1.0, 1.0); + float da = dot(norm.xyz, normalize(light_dir.xyz)); + // Dot product is guaranteed to be in -1 <= da <= +1 range for normalized vectors + // da = clamp(da, -1.0, 1.0); - float final_da = da; - final_da = clamp(final_da, 0.0, 1.0); + float final_da = clamp(da, 0.0, 1.0); float ambient = da; ambient *= 0.5; @@ -458,3 +470,4 @@ vec3 post_atmo = color.rgb; #endif } + -- cgit v1.2.3 From a164daad74fc0c8729aac5601df23c0f5cb3c02c Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Sat, 23 Nov 2019 00:02:30 +0000 Subject: Cleanup comments --- .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index e640c2d7ae..c23314a4b9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -276,7 +276,11 @@ void main() final_color.a = max(final_color.a, emissive_brightness); - // SL-11406 Fullbright: Object > Texture > Shininess > Environment Intensity = 1 + // Texture + // [x] Full Bright Object + // Shininess (specular) + // [X] Texture + // Environment Intensity = 1 // NOTE: There are two shaders that are used depending on the EI byte value: // EI = 0 fullbright // EI > 0 .. 255 material @@ -329,9 +333,6 @@ void main() float da = dot(norm.xyz, normalize(light_dir.xyz)); - // Dot product is guaranteed to be in -1 <= da <= +1 range for normalized vectors - // da = clamp(da, -1.0, 1.0); - float final_da = clamp(da, 0.0, 1.0); float ambient = da; -- cgit v1.2.3 From 41330f4a39e996fbcd4afa931973127a4abbcf86 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Mon, 25 Nov 2019 15:03:09 -0700 Subject: Roll back commit 41531 --- .../app_settings/shaders/class2/windlight/transportF.glsl | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index a06f4f22ad..d2d839ed05 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -51,14 +51,7 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransport(vec3 light) { float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; - vec3 attenColor = atmosTransportFrag(light * 0.5, getAdditiveColor() * brightness, getAtmosAttenuation()); - - // attenColor is an accurate fog-attenuated result for any brightness - // But, the pre-EEP shader included a brightness-indexed lerp to a non-attenuated version - // of the color - effectively a fog 'burn-through' for very bright pixels. To more closely - // match the pre-EEP behavior, we'll also lerp to the pre-EEP color, based on overall brightness - float preEepBright = dot(light.rgb, vec3(0.3333)); - retun mix(attenColor, (light.rgb + getAdditiveColor().rgb) * (2.0 - preEepBright), preEepBright * preEepBright); + return atmosTransportFrag(light * 0.5, getAdditiveColor() * brightness, getAtmosAttenuation()); } vec3 fullbrightShinyAtmosTransport(vec3 light) -- cgit v1.2.3 From 020ffe1bd3bb428abc0219d808a6a032cb6c2aeb Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 3 Dec 2019 17:49:49 -0700 Subject: SL-11055 Increase fog burn-through for fullbrights (for reals) --- indra/newview/app_settings/shaders/class2/windlight/transportF.glsl | 5 +++-- indra/newview/app_settings/shaders/class3/windlight/transportF.glsl | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index d2d839ed05..8fc5d750e3 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -38,8 +38,9 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { return light * 2.0; } - light *= atten.r; - light += additive; + // fullbright responds minimally to atmos scatter effects + light *= min(15.0 * atten.r, 1.0); + light += (0.1 * additive); return light * 2.0; } diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index 08eb119510..18705f785f 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -38,8 +38,9 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { return light; } - light *= atten.r; - light += additive; + // fullbright responds minimally to atmos scatter effects + light *= min(15.0 * atten.r, 1.0); + light += (0.1 * additive); return light * 2.0; } -- cgit v1.2.3 From 05e54ac96be519e5f60f2681ac3226dab7dcb8b2 Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Tue, 10 Dec 2019 14:41:03 -0800 Subject: SL-11406: Skip avatars being effected. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c23314a4b9..52c69b46ea 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -292,8 +292,12 @@ void main() // We remap the environment intensity to closely simulate what non-EEP is doing. // At midnight the brightness is exact. // At midday the brightness is very close. +#ifdef HAS_SKIN + vec4 final_normal = vec4(abnormal, env_intensity, 0.0); +#else float ei = env_intensity*0.5 + 0.5; vec4 final_normal = vec4(abnormal, ei, 0.0); +#endif vec4 final_specular = spec; final_specular.a = specular_color.a; -- cgit v1.2.3 From 124c5cf4a781e50f81e7266a1af5f83b36777651 Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Tue, 17 Dec 2019 23:34:54 +0000 Subject: SL-12472 to address SL-11406 --- .../app_settings/shaders/class1/deferred/materialF.glsl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 52c69b46ea..2b5fa3979b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -277,7 +277,7 @@ void main() final_color.a = max(final_color.a, emissive_brightness); // Texture - // [x] Full Bright Object + // [x] Full Bright (emissive_brightness > 0.0) // Shininess (specular) // [X] Texture // Environment Intensity = 1 @@ -292,11 +292,14 @@ void main() // We remap the environment intensity to closely simulate what non-EEP is doing. // At midnight the brightness is exact. // At midday the brightness is very close. -#ifdef HAS_SKIN vec4 final_normal = vec4(abnormal, env_intensity, 0.0); -#else - float ei = env_intensity*0.5 + 0.5; - vec4 final_normal = vec4(abnormal, ei, 0.0); + +#ifdef HAS_SPECULAR_MAP + if( emissive_brightness > 0.0) + { + float ei = env_intensity*0.5 + 0.5; + final_normal = vec4(abnormal, ei, 0.0); + } #endif vec4 final_specular = spec; -- cgit v1.2.3 From 874368d4f30b59640e843d7e30c612dd0d0baa75 Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Wed, 18 Dec 2019 01:48:44 +0000 Subject: Future-proof Full Bright --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 2b5fa3979b..1be1595a47 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -277,7 +277,7 @@ void main() final_color.a = max(final_color.a, emissive_brightness); // Texture - // [x] Full Bright (emissive_brightness > 0.0) + // [x] Full Bright (emissive_brightness >= 1.0) // Shininess (specular) // [X] Texture // Environment Intensity = 1 @@ -295,7 +295,7 @@ void main() vec4 final_normal = vec4(abnormal, env_intensity, 0.0); #ifdef HAS_SPECULAR_MAP - if( emissive_brightness > 0.0) + if( emissive_brightness >= 1.0) { float ei = env_intensity*0.5 + 0.5; final_normal = vec4(abnormal, ei, 0.0); -- cgit v1.2.3 From b3e11083cc31abfa7cebf2c3acc6aeebfc1f4205 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Thu, 19 Dec 2019 18:04:32 -0700 Subject: SL-11606 fix to match EEP light falloff vs release --- .../app_settings/shaders/class1/deferred/multiPointLightF.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 3607f5a086..dcc3750a8f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -100,7 +100,9 @@ void main() float fa = light_col[i].a+1.0; 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; + + // Tweak falloff slightly to match pre-EEP attenuation + dist_atten *= 2.2; dist_atten *= noise; -- cgit v1.2.3 From c453a0df6fe9f2d6611e7368d3f1d17ba4d5f09e Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Mon, 23 Dec 2019 23:15:03 +0000 Subject: SL-12006 pre-checkin --- .../shaders/class1/deferred/materialF.glsl | 428 +++++++++++---------- 1 file changed, 217 insertions(+), 211 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 1be1595a47..10a9e3a5b4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -47,142 +47,142 @@ vec3 linear_to_srgb(vec3 cs); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif + #ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_color; + #else + #define frag_color gl_FragColor + #endif -#ifdef HAS_SUN_SHADOW -float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); -#endif + #ifdef HAS_SUN_SHADOW + float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); + #endif -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; + uniform samplerCube environmentMap; + uniform sampler2D lightFunc; -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -uniform mat3 env_mat; + // Inputs + uniform vec4 morphFactor; + uniform vec3 camPosLocal; + uniform mat3 env_mat; -uniform vec3 sun_dir; -uniform vec3 moon_dir; -VARYING vec2 vary_fragcoord; + uniform vec3 sun_dir; + uniform vec3 moon_dir; + VARYING vec2 vary_fragcoord; -VARYING vec3 vary_position; + VARYING vec3 vary_position; -uniform mat4 proj_mat; -uniform mat4 inv_proj; -uniform vec2 screen_res; + uniform mat4 proj_mat; + uniform mat4 inv_proj; + uniform vec2 screen_res; -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec4 light_attenuation[8]; -uniform vec3 light_diffuse[8]; + uniform vec4 light_position[8]; + uniform vec3 light_direction[8]; + uniform vec4 light_attenuation[8]; + uniform vec3 light_diffuse[8]; -float getAmbientClamp(); + 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 col = vec3(0); + 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 col = vec3(0); - //get light vector - vec3 lv = lp.xyz-v; + //get light vector + vec3 lv = lp.xyz-v; - //get distance - float dist = length(lv); - float da = 1.0; + //get distance + float dist = length(lv); + float da = 1.0; - dist /= la; + dist /= la; - /* clip to projector bounds - vec4 proj_tc = proj_mat * lp; + /* clip to projector bounds + vec4 proj_tc = proj_mat * lp; - if (proj_tc.z < 0 - || proj_tc.z > 1 - || proj_tc.x < 0 - || proj_tc.x > 1 - || proj_tc.y < 0 - || proj_tc.y > 1) - { - return col; - }*/ + if (proj_tc.z < 0 + || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + }*/ - if (dist > 0.0 && la > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0f; - - if (dist_atten <= 0.0) - { - return col; - } - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - //angular attenuation - da *= dot(n, lv); - - float lit = 0.0f; - - float amb_da = ambiance; - if (da >= 0) - { - lit = max(da * dist_atten,0.0); - col = lit * light_col * diffuse; - amb_da += (da*0.5+0.5) * ambiance; - } - amb_da += (da*da*0.5 + 0.5) * ambiance; - amb_da *= dist_atten; - amb_da = min(amb_da, 1.0f - lit); - - // SL-10969 need to see why these are blown out - //col.rgb += amb_da * light_col * diffuse; - - if (spec.a > 0.0) + if (dist > 0.0 && la > 0.0) { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0f; + + if (dist_atten <= 0.0) + { + return col; + } - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 + + //angular attenuation + da *= dot(n, lv); + + float lit = 0.0f; + + float amb_da = ambiance; + if (da >= 0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - 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); + lit = max(da * dist_atten,0.0); + col = lit * light_col * diffuse; + amb_da += (da*0.5+0.5) * ambiance; + } + amb_da += (da*da*0.5 + 0.5) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + + // SL-10969 need to see why these are blown out + //col.rgb += amb_da * light_col * diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + 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); + } } } - } - return max(col, vec3(0.0,0.0,0.0)); -} + return max(col, vec3(0.0,0.0,0.0)); + } -#else -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif + #else + #ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_data[3]; + #else + #define frag_data gl_FragData + #endif #endif uniform sampler2D diffuseMap; @@ -218,7 +218,7 @@ VARYING vec2 vary_texcoord0; vec2 encode_normal(vec3 n); -void main() +void main() { vec2 pos_screen = vary_texcoord0.xy; @@ -294,6 +294,9 @@ void main() // At midday the brightness is very close. vec4 final_normal = vec4(abnormal, env_intensity, 0.0); + vec3 color = vec3(0.0); + float al = 0.0; + #ifdef HAS_SPECULAR_MAP if( emissive_brightness >= 1.0) { @@ -301,8 +304,9 @@ void main() final_normal = vec4(abnormal, ei, 0.0); } #endif + vec4 final_specular = spec; - + final_specular.a = specular_color.a; #ifdef HAS_SPECULAR_MAP @@ -310,143 +314,143 @@ void main() final_normal.z *= spec.a; #endif + #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - //forward rendering, output just lit RGBA - vec3 pos = vary_position; + { + //forward rendering, output just lit RGBA + vec3 pos = vary_position; - float shadow = 1.0f; + float shadow = 1.0f; #ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); + shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); #endif - - spec = final_specular; - float envIntensity = final_normal.z; + spec = final_specular; - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + float envIntensity = final_normal.z; - vec3 color = vec3(0.0); + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float bloom = 0.0; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; + float bloom = 0.0; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; - calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float da = dot(norm.xyz, normalize(light_dir.xyz)); - float final_da = clamp(da, 0.0, 1.0); + float da = dot(norm.xyz, normalize(light_dir.xyz)); + float final_da = clamp(da, 0.0, 1.0); - float ambient = da; - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); + float ambient = da; + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); + + vec3 sun_contrib = min(final_da, shadow) * sunlit; - vec3 sun_contrib = min(final_da, shadow) * sunlit; - #if !defined(AMBIENT_KILL) - color.rgb = amblit; - color.rgb *= ambient; + color.rgb = amblit; + color.rgb *= ambient; #endif vec3 post_ambient = color.rgb; #if !defined(SUNLIGHT_KILL) - color.rgb += sun_contrib; + color.rgb += sun_contrib; #endif vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_srgb.rgb; - + color.rgb *= diffuse_srgb.rgb; + vec3 post_diffuse = color.rgb; - float glare = 0.0; + float glare = 0.0; - if (spec.a > 0.0) // specular reflection - { - vec3 npos = -normalize(pos.xyz); - - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(light_dir.xyz+npos); - float nh = dot(norm.xyz, h); - float nv = dot(norm.xyz, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 sp = sun_contrib*scol / 16.0f; - sp = clamp(sp, vec3(0), vec3(1)); - bloom = dot(sp, sp) / 6.0; -#if !defined(SUNLIGHT_KILL) - color += sp * spec.rgb; -#endif - } - } + if (spec.a > 0.0) // specular reflection + { + vec3 npos = -normalize(pos.xyz); -vec3 post_spec = color.rgb; + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(light_dir.xyz+npos); + float nh = dot(norm.xyz, h); + float nv = dot(norm.xyz, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); -#if !defined(SUNLIGHT_KILL) - color = mix(color.rgb, reflected_color, envIntensity); -#endif - float cur_glare = max(reflected_color.r, reflected_color.g); - cur_glare = max(cur_glare, reflected_color.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; - } + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 sp = sun_contrib*scol / 16.0f; + sp = clamp(sp, vec3(0), vec3(1)); + bloom = dot(sp, sp) / 6.0; + #if !defined(SUNLIGHT_KILL) + color += sp * spec.rgb; + #endif + } + } + + vec3 post_spec = color.rgb; + + if (envIntensity > 0.0) + { + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + + #if !defined(SUNLIGHT_KILL) + color = mix(color.rgb, reflected_color, envIntensity); + #endif + float cur_glare = max(reflected_color.r, reflected_color.g); + cur_glare = max(cur_glare, reflected_color.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; + } vec3 post_env = color.rgb; - color = atmosFragLighting(color, additive, atten); + color = atmosFragLighting(color, additive, atten); - //convert to linear space before adding local lights - color = srgb_to_linear(color); + //convert to linear space before adding local lights + color = srgb_to_linear(color); vec3 post_atmo = color.rgb; - vec3 npos = normalize(-pos.xyz); - - vec3 light = vec3(0,0,0); + vec3 npos = normalize(-pos.xyz); - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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 ); + vec3 light = vec3(0,0,0); - LIGHT_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) +#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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 ); - glare = min(glare, 1.0); - float al = max(diffuse_linear.a,glare)*vertex_color.a; + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) + + glare = min(glare, 1.0); + al = max(diffuse_linear.a,glare)*vertex_color.a; #if !defined(LOCAL_LIGHT_KILL) - color.rgb += light.rgb; + color.rgb += light.rgb; #endif - color = scaleSoftClipFrag(color); + color = scaleSoftClipFrag(color); - // (only) post-deferred needs inline gamma correction - color.rgb = linear_to_srgb(color.rgb); + // (only) post-deferred needs inline gamma correction + color.rgb = linear_to_srgb(color.rgb); //color.rgb = amblit; //color.rgb = vec3(ambient); @@ -462,15 +466,17 @@ vec3 post_atmo = color.rgb; //color.rgb = post_atmo; #ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); - color.rgb = temp.rgb; - al = temp.a; + vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); + color.rgb = temp.rgb; + al = temp.a; #endif + } frag_color.rgb = color.rgb; frag_color.a = al; -#else +#else // if DIFFUSE_ALPHA_MODE_BLEND ... + // deferred path frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. -- cgit v1.2.3 From a6f7de660f942419bc0ec4632b87b77157cd058b Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Mon, 23 Dec 2019 23:48:33 +0000 Subject: Fix SL-12006: Fullbright with specular map, Alpha Mode Emissive, and wrong Diffuse for Alpha Mode Blend --- .../app_settings/shaders/class1/deferred/materialF.glsl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 10a9e3a5b4..c072d44e63 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -272,6 +272,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = diffuse_linear.a; + final_color.rgb *= 0.5; #endif final_color.a = max(final_color.a, emissive_brightness); @@ -297,13 +298,16 @@ void main() vec3 color = vec3(0.0); float al = 0.0; -#ifdef HAS_SPECULAR_MAP - if( emissive_brightness >= 1.0) + if (emissive_brightness >= 1.0) { +#ifdef HAS_SPECULAR_MAP float ei = env_intensity*0.5 + 0.5; final_normal = vec4(abnormal, ei, 0.0); - } + #endif + color.rgb = final_color.rgb; + al = vertex_color.a; + } vec4 final_specular = spec; @@ -316,6 +320,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + if (emissive_brightness < 1.0) { //forward rendering, output just lit RGBA vec3 pos = vary_position; @@ -366,7 +371,8 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_srgb.rgb; + //color.rgb *= diffuse_srgb.rgb; + color.rgb *= diffuse_linear.rgb; // SL-12006 vec3 post_diffuse = color.rgb; @@ -470,7 +476,7 @@ vec3 post_atmo = color.rgb; color.rgb = temp.rgb; al = temp.a; #endif - } + } // !fullbright frag_color.rgb = color.rgb; frag_color.a = al; -- cgit v1.2.3 From 2eb8b9af5a14ffa4a27b2c7d4f5985c2d5d00d6c Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Tue, 24 Dec 2019 00:01:25 +0000 Subject: De-tabify --- .../shaders/class1/deferred/materialF.glsl | 472 ++++++++++----------- 1 file changed, 236 insertions(+), 236 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c072d44e63..72e61095f2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -47,142 +47,142 @@ vec3 linear_to_srgb(vec3 cs); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - #ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_color; - #else - #define frag_color gl_FragColor - #endif - - #ifdef HAS_SUN_SHADOW - float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); - #endif - - uniform samplerCube environmentMap; - uniform sampler2D lightFunc; - - // Inputs - uniform vec4 morphFactor; - uniform vec3 camPosLocal; - uniform mat3 env_mat; - - uniform vec3 sun_dir; - uniform vec3 moon_dir; - VARYING vec2 vary_fragcoord; - - VARYING vec3 vary_position; - - uniform mat4 proj_mat; - uniform mat4 inv_proj; - uniform vec2 screen_res; - - uniform vec4 light_position[8]; - uniform vec3 light_direction[8]; - uniform vec4 light_attenuation[8]; - 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 col = vec3(0); - - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float dist = length(lv); - float da = 1.0; - - dist /= la; - - /* clip to projector bounds - vec4 proj_tc = proj_mat * lp; - - if (proj_tc.z < 0 - || proj_tc.z > 1 - || proj_tc.x < 0 - || proj_tc.x > 1 - || proj_tc.y < 0 - || proj_tc.y > 1) - { - return col; - }*/ - - if (dist > 0.0 && la > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0f; - - if (dist_atten <= 0.0) - { - return col; - } - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - //angular attenuation - da *= dot(n, lv); - - float lit = 0.0f; - - float amb_da = ambiance; - if (da >= 0) - { - lit = max(da * dist_atten,0.0); - col = lit * light_col * diffuse; - amb_da += (da*0.5+0.5) * ambiance; - } - amb_da += (da*da*0.5 + 0.5) * ambiance; - amb_da *= dist_atten; - amb_da = min(amb_da, 1.0f - lit); - - // SL-10969 need to see why these are blown out - //col.rgb += amb_da * light_col * diffuse; - - if (spec.a > 0.0) - { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - 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); - } - } - } - - return max(col, vec3(0.0,0.0,0.0)); - } - - #else - #ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_data[3]; - #else - #define frag_data gl_FragData - #endif + #ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_color; + #else + #define frag_color gl_FragColor + #endif + + #ifdef HAS_SUN_SHADOW + float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); + #endif + + uniform samplerCube environmentMap; + uniform sampler2D lightFunc; + + // Inputs + uniform vec4 morphFactor; + uniform vec3 camPosLocal; + uniform mat3 env_mat; + + uniform vec3 sun_dir; + uniform vec3 moon_dir; + VARYING vec2 vary_fragcoord; + + VARYING vec3 vary_position; + + uniform mat4 proj_mat; + uniform mat4 inv_proj; + uniform vec2 screen_res; + + uniform vec4 light_position[8]; + uniform vec3 light_direction[8]; + uniform vec4 light_attenuation[8]; + 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 col = vec3(0); + + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float dist = length(lv); + float da = 1.0; + + dist /= la; + + /* clip to projector bounds + vec4 proj_tc = proj_mat * lp; + + if (proj_tc.z < 0 + || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + }*/ + + if (dist > 0.0 && la > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0f; + + if (dist_atten <= 0.0) + { + return col; + } + + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 + + //angular attenuation + da *= dot(n, lv); + + float lit = 0.0f; + + float amb_da = ambiance; + if (da >= 0) + { + lit = max(da * dist_atten,0.0); + col = lit * light_col * diffuse; + amb_da += (da*0.5+0.5) * ambiance; + } + amb_da += (da*da*0.5 + 0.5) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + + // SL-10969 need to see why these are blown out + //col.rgb += amb_da * light_col * diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + 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); + } + } + } + + return max(col, vec3(0.0,0.0,0.0)); + } + + #else + #ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_data[3]; + #else + #define frag_data gl_FragData + #endif #endif uniform sampler2D diffuseMap; @@ -295,8 +295,8 @@ void main() // At midday the brightness is very close. vec4 final_normal = vec4(abnormal, env_intensity, 0.0); - vec3 color = vec3(0.0); - float al = 0.0; + vec3 color = vec3(0.0); + float al = 0.0; if (emissive_brightness >= 1.0) { @@ -305,8 +305,8 @@ void main() final_normal = vec4(abnormal, ei, 0.0); #endif - color.rgb = final_color.rgb; - al = vertex_color.a; + color.rgb = final_color.rgb; + al = vertex_color.a; } vec4 final_specular = spec; @@ -320,143 +320,143 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - if (emissive_brightness < 1.0) - { - //forward rendering, output just lit RGBA - vec3 pos = vary_position; + if (emissive_brightness < 1.0) + { + //forward rendering, output just lit RGBA + vec3 pos = vary_position; - float shadow = 1.0f; + float shadow = 1.0f; #ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); + shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); #endif - spec = final_specular; + spec = final_specular; - float envIntensity = final_normal.z; + float envIntensity = final_normal.z; - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float bloom = 0.0; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; + float bloom = 0.0; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; - calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - float da = dot(norm.xyz, normalize(light_dir.xyz)); - float final_da = clamp(da, 0.0, 1.0); + float da = dot(norm.xyz, normalize(light_dir.xyz)); + float final_da = clamp(da, 0.0, 1.0); - float ambient = da; - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); + float ambient = da; + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); - vec3 sun_contrib = min(final_da, shadow) * sunlit; + vec3 sun_contrib = min(final_da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit; - color.rgb *= ambient; + color.rgb = amblit; + color.rgb *= ambient; #endif vec3 post_ambient = color.rgb; #if !defined(SUNLIGHT_KILL) - color.rgb += sun_contrib; + color.rgb += sun_contrib; #endif vec3 post_sunlight = color.rgb; - //color.rgb *= diffuse_srgb.rgb; - color.rgb *= diffuse_linear.rgb; // SL-12006 + //color.rgb *= diffuse_srgb.rgb; + color.rgb *= diffuse_linear.rgb; // SL-12006 vec3 post_diffuse = color.rgb; - float glare = 0.0; - - if (spec.a > 0.0) // specular reflection - { - vec3 npos = -normalize(pos.xyz); - - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(light_dir.xyz+npos); - float nh = dot(norm.xyz, h); - float nv = dot(norm.xyz, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 sp = sun_contrib*scol / 16.0f; - sp = clamp(sp, vec3(0), vec3(1)); - bloom = dot(sp, sp) / 6.0; - #if !defined(SUNLIGHT_KILL) - color += sp * spec.rgb; - #endif - } - } - - vec3 post_spec = color.rgb; - - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - - #if !defined(SUNLIGHT_KILL) - color = mix(color.rgb, reflected_color, envIntensity); - #endif - float cur_glare = max(reflected_color.r, reflected_color.g); - cur_glare = max(cur_glare, reflected_color.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; - } + float glare = 0.0; + + if (spec.a > 0.0) // specular reflection + { + vec3 npos = -normalize(pos.xyz); + + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(light_dir.xyz+npos); + float nh = dot(norm.xyz, h); + float nv = dot(norm.xyz, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 sp = sun_contrib*scol / 16.0f; + sp = clamp(sp, vec3(0), vec3(1)); + bloom = dot(sp, sp) / 6.0; + #if !defined(SUNLIGHT_KILL) + color += sp * spec.rgb; + #endif + } + } + + vec3 post_spec = color.rgb; + + if (envIntensity > 0.0) + { + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + + #if !defined(SUNLIGHT_KILL) + color = mix(color.rgb, reflected_color, envIntensity); + #endif + float cur_glare = max(reflected_color.r, reflected_color.g); + cur_glare = max(cur_glare, reflected_color.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; + } vec3 post_env = color.rgb; - color = atmosFragLighting(color, additive, atten); + color = atmosFragLighting(color, additive, atten); - //convert to linear space before adding local lights - color = srgb_to_linear(color); + //convert to linear space before adding local lights + color = srgb_to_linear(color); vec3 post_atmo = color.rgb; - vec3 npos = normalize(-pos.xyz); + vec3 npos = normalize(-pos.xyz); - vec3 light = vec3(0,0,0); + vec3 light = vec3(0,0,0); #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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 ); - LIGHT_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) - glare = min(glare, 1.0); - al = max(diffuse_linear.a,glare)*vertex_color.a; + glare = min(glare, 1.0); + al = max(diffuse_linear.a,glare)*vertex_color.a; #if !defined(LOCAL_LIGHT_KILL) - color.rgb += light.rgb; + color.rgb += light.rgb; #endif - color = scaleSoftClipFrag(color); + color = scaleSoftClipFrag(color); - // (only) post-deferred needs inline gamma correction - color.rgb = linear_to_srgb(color.rgb); + // (only) post-deferred needs inline gamma correction + color.rgb = linear_to_srgb(color.rgb); //color.rgb = amblit; //color.rgb = vec3(ambient); @@ -472,11 +472,11 @@ vec3 post_atmo = color.rgb; //color.rgb = post_atmo; #ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); - color.rgb = temp.rgb; - al = temp.a; + vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); + color.rgb = temp.rgb; + al = temp.a; #endif - } // !fullbright + } // !fullbright frag_color.rgb = color.rgb; frag_color.a = al; -- cgit v1.2.3 From 090803733455a09c9763d16106ad055c2532e61d Mon Sep 17 00:00:00 2001 From: "Michael Pohoreski (Ptolemy Linden)" Date: Tue, 24 Dec 2019 01:37:40 +0000 Subject: Cleanup indentation and commented out debug color stage vectors --- .../shaders/class1/deferred/materialF.glsl | 253 +++++++++++---------- 1 file changed, 127 insertions(+), 126 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 72e61095f2..f4e041eb5c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -47,142 +47,142 @@ vec3 linear_to_srgb(vec3 cs); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - #ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_color; - #else - #define frag_color gl_FragColor - #endif +#ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_color; +#else + #define frag_color gl_FragColor +#endif - #ifdef HAS_SUN_SHADOW +#ifdef HAS_SUN_SHADOW float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); - #endif +#endif - uniform samplerCube environmentMap; - uniform sampler2D lightFunc; +uniform samplerCube environmentMap; +uniform sampler2D lightFunc; - // Inputs - uniform vec4 morphFactor; - uniform vec3 camPosLocal; - uniform mat3 env_mat; +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; +uniform mat3 env_mat; - uniform vec3 sun_dir; - uniform vec3 moon_dir; - VARYING vec2 vary_fragcoord; +uniform vec3 sun_dir; +uniform vec3 moon_dir; +VARYING vec2 vary_fragcoord; - VARYING vec3 vary_position; +VARYING vec3 vary_position; - uniform mat4 proj_mat; - uniform mat4 inv_proj; - uniform vec2 screen_res; +uniform mat4 proj_mat; +uniform mat4 inv_proj; +uniform vec2 screen_res; - uniform vec4 light_position[8]; - uniform vec3 light_direction[8]; - uniform vec4 light_attenuation[8]; - uniform vec3 light_diffuse[8]; +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec4 light_attenuation[8]; +uniform vec3 light_diffuse[8]; - float getAmbientClamp(); +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 col = vec3(0); +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 col = vec3(0); - //get light vector - vec3 lv = lp.xyz-v; + //get light vector + vec3 lv = lp.xyz-v; - //get distance - float dist = length(lv); - float da = 1.0; + //get distance + float dist = length(lv); + float da = 1.0; - dist /= la; + dist /= la; - /* clip to projector bounds - vec4 proj_tc = proj_mat * lp; + /* clip to projector bounds + vec4 proj_tc = proj_mat * lp; - if (proj_tc.z < 0 - || proj_tc.z > 1 - || proj_tc.x < 0 - || proj_tc.x > 1 - || proj_tc.y < 0 - || proj_tc.y > 1) - { - return col; - }*/ + if (proj_tc.z < 0 + || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + }*/ - if (dist > 0.0 && la > 0.0) + if (dist > 0.0 && la > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0f; + + if (dist_atten <= 0.0) { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0f; - - if (dist_atten <= 0.0) - { - return col; - } + return col; + } - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 - //angular attenuation - da *= dot(n, lv); + //angular attenuation + da *= dot(n, lv); - float lit = 0.0f; + float lit = 0.0f; - float amb_da = ambiance; - if (da >= 0) - { - lit = max(da * dist_atten,0.0); - col = lit * light_col * diffuse; - amb_da += (da*0.5+0.5) * ambiance; - } - amb_da += (da*da*0.5 + 0.5) * ambiance; - amb_da *= dist_atten; - amb_da = min(amb_da, 1.0f - lit); + float amb_da = ambiance; + if (da >= 0) + { + lit = max(da * dist_atten,0.0); + col = lit * light_col * diffuse; + amb_da += (da*0.5+0.5) * ambiance; + } + amb_da += (da*da*0.5 + 0.5) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + + // SL-10969 need to see why these are blown out + //col.rgb += amb_da * light_col * diffuse; - // SL-10969 need to see why these are blown out - //col.rgb += amb_da * light_col * diffuse; + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - if (spec.a > 0.0) + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - 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); - } + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + 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); } } - - return max(col, vec3(0.0,0.0,0.0)); } - #else - #ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_data[3]; - #else - #define frag_data gl_FragData - #endif + return max(col, vec3(0.0,0.0,0.0)); +} + +#else +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif #endif uniform sampler2D diffuseMap; @@ -358,23 +358,25 @@ void main() vec3 sun_contrib = min(final_da, shadow) * sunlit; +// vec3 debug_sun_contrib = sun_contrib; + #if !defined(AMBIENT_KILL) color.rgb = amblit; color.rgb *= ambient; #endif -vec3 post_ambient = color.rgb; +//vec3 debug_post_ambient = color.rgb; #if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; #endif -vec3 post_sunlight = color.rgb; +//vec3 debug_post_sunlight = color.rgb; //color.rgb *= diffuse_srgb.rgb; color.rgb *= diffuse_linear.rgb; // SL-12006 -vec3 post_diffuse = color.rgb; +//vec3 debug_post_diffuse = color.rgb; float glare = 0.0; @@ -399,13 +401,13 @@ vec3 post_diffuse = color.rgb; vec3 sp = sun_contrib*scol / 16.0f; sp = clamp(sp, vec3(0), vec3(1)); bloom = dot(sp, sp) / 6.0; - #if !defined(SUNLIGHT_KILL) +#if !defined(SUNLIGHT_KILL) color += sp * spec.rgb; - #endif +#endif } } - vec3 post_spec = color.rgb; +//vec3 debug_post_spec = color.rgb; if (envIntensity > 0.0) { @@ -414,23 +416,23 @@ vec3 post_diffuse = color.rgb; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - #if !defined(SUNLIGHT_KILL) +#if !defined(SUNLIGHT_KILL) color = mix(color.rgb, reflected_color, envIntensity); - #endif +#endif float cur_glare = max(reflected_color.r, reflected_color.g); cur_glare = max(cur_glare, reflected_color.b); cur_glare *= envIntensity*4.0; glare += cur_glare; } -vec3 post_env = color.rgb; +//vec3 debug_post_env = color.rgb; color = atmosFragLighting(color, additive, atten); //convert to linear space before adding local lights color = srgb_to_linear(color); -vec3 post_atmo = color.rgb; +//vec3 debug_post_atmo = color.rgb; vec3 npos = normalize(-pos.xyz); @@ -461,15 +463,15 @@ vec3 post_atmo = color.rgb; //color.rgb = amblit; //color.rgb = vec3(ambient); //color.rgb = sunlit; -//color.rgb = post_ambient; +//color.rgb = debug_post_ambient; //color.rgb = vec3(final_da); -//color.rgb = sun_contrib; -//color.rgb = post_sunlight; +//color.rgb = debug_sun_contrib; +//color.rgb = debug_post_sunlight; //color.rgb = diffuse_srgb.rgb; -//color.rgb = post_diffuse; -//color.rgb = post_spec; -//color.rgb = post_env; -//color.rgb = post_atmo; +//color.rgb = debug_post_diffuse; +//color.rgb = debug_post_spec; +//color.rgb = debug_post_env; +//color.rgb = debug_post_atmo; #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); @@ -490,4 +492,3 @@ vec3 post_atmo = color.rgb; #endif } - -- cgit v1.2.3 From a471ddd0be09a7bd6815c09a98fc7acd87feac58 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 10 Jan 2020 17:26:54 -0800 Subject: SL-12171: Fix for SL-12006 that made non-emissive portions of textures too dim. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f4e041eb5c..8ed5713e22 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -272,7 +272,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = diffuse_linear.a; - final_color.rgb *= 0.5; + final_color.rgb = mix( diffuse_linear.rgb, final_color.rgb*0.5, diffuse_tap.a ); // SL-12171: Fix emissive texture portion being twice as bright. #endif final_color.a = max(final_color.a, emissive_brightness); -- cgit v1.2.3 From 8545b81a32e1f8a7621ca7e136a5899545a5788b Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 24 Jan 2020 16:30:48 -0800 Subject: SL-11406: Fix specularity being blown out due to previous fix --- .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8ed5713e22..8a6b2b7066 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -290,9 +290,7 @@ void main() // OR // adjust the final color via: // final_color *= 0.666666; - // We remap the environment intensity to closely simulate what non-EEP is doing. - // At midnight the brightness is exact. - // At midday the brightness is very close. + // We don't remap the environment intensity but adjust the final color to closely simulate what non-EEP is doing. vec4 final_normal = vec4(abnormal, env_intensity, 0.0); vec3 color = vec3(0.0); @@ -301,9 +299,8 @@ void main() if (emissive_brightness >= 1.0) { #ifdef HAS_SPECULAR_MAP - float ei = env_intensity*0.5 + 0.5; - final_normal = vec4(abnormal, ei, 0.0); - + // Note: We actually need to adjust all 4 channels not just .rgb + final_color *= 0.666666; #endif color.rgb = final_color.rgb; al = vertex_color.a; -- cgit v1.2.3 From c1652b4c42256b2e9dd6a564a83681c87d1a3528 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Mon, 3 Feb 2020 17:41:54 -0700 Subject: SL-12005, back out SRGB changes for projector spotlights Deferred spotlights were transitioned srdb->linear in commit 653133b The lights transition between the deferred and (some other) path at fixed camera distance, causing a distinct light-level pop. Backing out this change to avoid the pop. Note to the future: pick a light space at the beginning and stick with it. --- .../newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 4 +++- indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl | 4 +++- .../newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index e28506dcff..a690cc45a8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -178,7 +178,9 @@ void main() vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - diff_tex.rgb = srgb_to_linear(diff_tex.rgb); + // SL-12005 Projector light pops as we get closer, more objectionable than being in wrong color space. + // We can't switch to linear here unless we do it everywhere + //diff_tex.rgb = srgb_to_linear(diff_tex.rgb); vec3 dlit = vec3(0, 0, 0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 5e985618f7..2216afe609 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -177,7 +177,9 @@ void main() float da = dot(norm, lv); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - diff_tex.rgb = srgb_to_linear(diff_tex.rgb); + // SL-12005 Projector light pops as we get closer, more objectionable than being in wrong color space. + // We can't switch to linear here unless we do it everywhere + //diff_tex.rgb = srgb_to_linear(diff_tex.rgb); vec4 spec = texture2DRect(specularRect, frag.xy); diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 8cad21d5b4..7cde67d11b 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -191,7 +191,9 @@ void main() float da = dot(norm, lv); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - diff_tex.rgb = srgb_to_linear(diff_tex.rgb); + // SL-12005 Projector light pops as we get closer, more objectionable than being in wrong color space. + // We can't switch to linear here unless we do it everywhere + //diff_tex.rgb = srgb_to_linear(diff_tex.rgb); vec4 spec = texture2DRect(specularRect, frag.xy); -- cgit v1.2.3 From 54bd5ed5fa6257508f9882455b49599dd84b76e8 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 4 Feb 2020 17:45:04 -0700 Subject: SL-12592, fix transparency for full-brights --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8a6b2b7066..80a2e16fb0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -317,7 +317,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - if (emissive_brightness < 1.0) + if (emissive_brightness <= 1.0) { //forward rendering, output just lit RGBA vec3 pos = vary_position; -- cgit v1.2.3 From 8e0d5f463edc24101ecdcb420c05f6d5b0e6b6c0 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Thu, 6 Feb 2020 18:43:21 -0700 Subject: SL-12682, remove negative light & clean up materialF.glsl --- .../shaders/class1/deferred/materialF.glsl | 46 +++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 80a2e16fb0..d28fc128b6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -249,24 +249,25 @@ void main() vec4 spec = vec4(specular_color.rgb, 1.0); #endif - vec4 norm = vec4(0,0,0,1.0); - vec3 tnorm; + vec3 norm = vec3(0); + float bmap_specular = 1.0; #ifdef HAS_NORMAL_MAP - norm = texture2D(bumpMap, vary_texcoord1.xy); - norm.xyz = norm.xyz * 2 - 1; - - // tangent space norm - tnorm = vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2)); + vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); + norm = (bump_sample.xyz * 2) - vec3(1); + bmap_specular = bump_sample.w; + + // convert sampled normal to tangent space normal + norm = vec3(dot(norm, vary_mat0), + dot(norm, vary_mat1), + dot(norm, vary_mat2)); #else - tnorm = vary_normal; + norm = vary_normal; #endif - norm.xyz = normalize(tnorm.xyz); + norm = normalize(norm); - vec2 abnormal = encode_normal(norm.xyz); + vec2 abnormal = encode_normal(norm); vec4 final_color = vec4(diffuse_linear.rgb, 0.0); @@ -311,7 +312,7 @@ void main() final_specular.a = specular_color.a; #ifdef HAS_SPECULAR_MAP - final_specular.a *= norm.a; + final_specular.a *= bmap_specular; final_normal.z *= spec.a; #endif @@ -325,7 +326,7 @@ void main() float shadow = 1.0f; #ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); + shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); #endif spec = final_specular; @@ -342,18 +343,17 @@ void main() calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - + vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); - float da = dot(norm.xyz, normalize(light_dir.xyz)); - float final_da = clamp(da, 0.0, 1.0); + float da = dot(norm, normalize(light_dir)); + da = clamp(da, 0.0, 1.0); // No negative light contributions float ambient = da; ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); - vec3 sun_contrib = min(final_da, shadow) * sunlit; + vec3 sun_contrib = min(da, shadow) * sunlit; // vec3 debug_sun_contrib = sun_contrib; @@ -383,8 +383,8 @@ void main() //vec3 ref = dot(pos+lv, norm); vec3 h = normalize(light_dir.xyz+npos); - float nh = dot(norm.xyz, h); - float nv = dot(norm.xyz, npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); float vh = dot(npos, h); float sa = nh; float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; @@ -435,7 +435,7 @@ void main() vec3 light = vec3(0,0,0); -#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.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_linear.rgb, final_specular, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w ); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -461,7 +461,7 @@ void main() //color.rgb = vec3(ambient); //color.rgb = sunlit; //color.rgb = debug_post_ambient; -//color.rgb = vec3(final_da); +//color.rgb = vec3(da); //color.rgb = debug_sun_contrib; //color.rgb = debug_post_sunlight; //color.rgb = diffuse_srgb.rgb; -- cgit v1.2.3 From 4be51fa5598c2ec2aa8dca2e0f00ef79a0732e1e Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 7 Feb 2020 16:17:15 -0800 Subject: DRTVWR-440: SL-12574: Tweak environment cube map to better match Windlight --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 4 ++-- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 09b1813ebe..b1dce665a1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -147,9 +147,9 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 sp = sun_contrib*scontrib / 16.0; + vec3 sp = sun_contrib*scontrib / 6.0; sp = clamp(sp, vec3(0), vec3(1)); - bloom += dot(sp, sp) / 6.0; + bloom += dot(sp, sp) / 4.0; #if !defined(SUNLIGHT_KILL) color += sp * spec.rgb; #endif diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 0223cef531..f49fad5517 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -155,9 +155,9 @@ vec3 post_diffuse = color.rgb; if (nh > 0.0) { float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 sp = sun_contrib*scontrib / 16.0; + vec3 sp = sun_contrib*scontrib / 6.0; sp = clamp(sp, vec3(0), vec3(1)); - bloom += dot(sp, sp) / 6.0; + bloom += dot(sp, sp) / 4.0; #if !defined(SUNLIGHT_KILL) color += sp * spec.rgb; #endif -- cgit v1.2.3 From 2ea507526921b68cb5f9929be1a7693203fe608e Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 25 Feb 2020 08:05:24 -0700 Subject: SL-12638, fix overly dark appearance of normal-mapped objects Adds the 'additive' component of calcAtmosphericVars into the sunlit color to reduce darkening of sun lighting component, and adds a further magic number gainto boost final result to rough parity with windlight. Removes all light calculations on fullbright objects, just passing through the unlit diffuse color. --- .../shaders/class1/deferred/fullbrightF.glsl | 3 +- .../shaders/class1/deferred/materialF.glsl | 73 ++++++---------------- 2 files changed, 20 insertions(+), 56 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index c104dc884f..39ed9a6e82 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -86,7 +86,6 @@ void main() color.a = final_alpha; #endif - frag_color.rgb = color.rgb; - frag_color.a = color.a; + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d28fc128b6..2df683a5fd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -95,19 +95,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe dist /= la; - /* clip to projector bounds - vec4 proj_tc = proj_mat * lp; - - if (proj_tc.z < 0 - || proj_tc.z > 1 - || proj_tc.x < 0 - || proj_tc.x > 1 - || proj_tc.y < 0 - || proj_tc.y > 1) - { - return col; - }*/ - if (dist > 0.0 && la > 0.0) { //normalize light vector @@ -252,7 +239,11 @@ void main() vec3 norm = vec3(0); float bmap_specular = 1.0; + // Non-physical gain, sole purpose to make EEP viewer better match windlight when normal-mapped. + float eep_bump_gain = 1.0; + #ifdef HAS_NORMAL_MAP + eep_bump_gain = 1.75; vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); norm = (bump_sample.xyz * 2) - vec3(1); bmap_specular = bump_sample.w; @@ -295,7 +286,7 @@ void main() vec4 final_normal = vec4(abnormal, env_intensity, 0.0); vec3 color = vec3(0.0); - float al = 0.0; + float al = 1.0; if (emissive_brightness >= 1.0) { @@ -318,7 +309,12 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - if (emissive_brightness <= 1.0) + if (emissive_brightness >= 1.0) + { + // fullbright = diffuse texture pass-through, no lighting + frag_color = diffuse_srgb; + } + else { //forward rendering, output just lit RGBA vec3 pos = vary_position; @@ -348,40 +344,28 @@ void main() float da = dot(norm, normalize(light_dir)); da = clamp(da, 0.0, 1.0); // No negative light contributions - float ambient = da; - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - - vec3 sun_contrib = min(da, shadow) * sunlit; + // ambient weight varies from 0.75 at max direct light to 1.0 with sun at grazing angle + float ambient = 1.0 - (0.25 * da * da); -// vec3 debug_sun_contrib = sun_contrib; + vec3 sun_contrib = additive + (min(da, shadow) * sunlit); #if !defined(AMBIENT_KILL) color.rgb = amblit; color.rgb *= ambient; #endif -//vec3 debug_post_ambient = color.rgb; - #if !defined(SUNLIGHT_KILL) - color.rgb += sun_contrib; + color.rgb += eep_bump_gain * sun_contrib; #endif -//vec3 debug_post_sunlight = color.rgb; - - //color.rgb *= diffuse_srgb.rgb; color.rgb *= diffuse_linear.rgb; // SL-12006 -//vec3 debug_post_diffuse = color.rgb; - float glare = 0.0; if (spec.a > 0.0) // specular reflection { vec3 npos = -normalize(pos.xyz); - //vec3 ref = dot(pos+lv, norm); vec3 h = normalize(light_dir.xyz+npos); float nh = dot(norm, h); float nv = dot(norm, npos); @@ -404,8 +388,6 @@ void main() } } -//vec3 debug_post_spec = color.rgb; - if (envIntensity > 0.0) { //add environmentmap @@ -422,15 +404,11 @@ void main() glare += cur_glare; } -//vec3 debug_post_env = color.rgb; - color = atmosFragLighting(color, additive, atten); //convert to linear space before adding local lights color = srgb_to_linear(color); -//vec3 debug_post_atmo = color.rgb; - vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -453,32 +431,19 @@ void main() #endif color = scaleSoftClipFrag(color); - + // (only) post-deferred needs inline gamma correction color.rgb = linear_to_srgb(color.rgb); -//color.rgb = amblit; -//color.rgb = vec3(ambient); -//color.rgb = sunlit; -//color.rgb = debug_post_ambient; -//color.rgb = vec3(da); -//color.rgb = debug_sun_contrib; -//color.rgb = debug_post_sunlight; -//color.rgb = diffuse_srgb.rgb; -//color.rgb = debug_post_diffuse; -//color.rgb = debug_post_spec; -//color.rgb = debug_post_env; -//color.rgb = debug_post_atmo; - #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); color.rgb = temp.rgb; al = temp.a; #endif - } // !fullbright - frag_color.rgb = color.rgb; - frag_color.a = al; + frag_color.rgb = color.rgb; + frag_color.a = al; + } #else // if DIFFUSE_ALPHA_MODE_BLEND ... -- cgit v1.2.3 From 22ec67975ccf7dd6da3dbddf94f503b14abee68e Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 25 Feb 2020 11:34:23 -0800 Subject: SL-12574: Simplify Direct Ambient --- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 8 ++------ .../app_settings/shaders/class2/deferred/softenLightF.glsl | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index b1dce665a1..705cc2f04e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -81,11 +81,7 @@ void main() norm.xyz = getNorm(tc); vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float da = dot(normalize(norm.xyz), light_dir.xyz); - da = clamp(da, -1.0, 1.0); - - float final_da = da; - final_da = clamp(final_da, 0.0, 1.0); + float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); vec4 diffuse_srgb = texture2DRect(diffuseRect, tc); vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); @@ -108,7 +104,7 @@ void main() ambient *= ambient; ambient = (1.0 - ambient); - vec3 sun_contrib = final_da * sunlit; + vec3 sun_contrib = da * sunlit; #if !defined(AMBIENT_KILL) color.rgb = amblit; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index f49fad5517..593706867d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -85,11 +85,7 @@ void main() 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); - - float final_da = da; - final_da = clamp(final_da, 0.0, 1.0); + float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); vec4 diffuse_srgb = texture2DRect(diffuseRect, tc); vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); @@ -116,7 +112,7 @@ void main() ambient *= ambient; ambient = (1.0 - ambient); - vec3 sun_contrib = min(scol, final_da) * sunlit; + vec3 sun_contrib = min(scol, da) * sunlit; #if !defined(AMBIENT_KILL) color.rgb = amblit; -- cgit v1.2.3 From d180e94a8633bb7d6c355b36aba9712151d90207 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 25 Feb 2020 11:37:24 -0800 Subject: SL-12574: Document shader class summary --- indra/newview/app_settings/shaders/shader_hierarchy.txt | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/shader_hierarchy.txt b/indra/newview/app_settings/shaders/shader_hierarchy.txt index ebccaddd55..8ef04d8e1f 100644 --- a/indra/newview/app_settings/shaders/shader_hierarchy.txt +++ b/indra/newview/app_settings/shaders/shader_hierarchy.txt @@ -1,3 +1,9 @@ +Class 3 is highest quality / lowest performance +Class 2 is medium quality / medium performance +Class 1 is lowest quality / highest performance + +Shaders WILL fall back to "lower" classes for functionality. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ avatar/avatarV.glsl - gAvatarProgram, gAvatarWaterProgram main() - avatar/avatarV.glsl -- cgit v1.2.3 From 823d8bce6034eaa748b65dfec3618d1283f1ec9d Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Thu, 27 Feb 2020 11:48:04 -0700 Subject: SL-12638, further tweaking of normal-map lighting, add some de-saturation --- .../app_settings/shaders/class1/deferred/materialF.glsl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 2df683a5fd..eebb0a5fe5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -164,6 +164,14 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe return max(col, vec3(0.0,0.0,0.0)); } +// Q&D approximate RGB-space de-saturation, strength from 0 (no effect) to 1.0 (complete grey-scale) +vec3 desat(vec3 color, float strength) +{ + float primary_value = max(color.r, max(color.g, color.b)); + vec3 delta = strength * (vec3(primary_value)-color); + return color + delta; +} + #else #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -355,11 +363,15 @@ void main() #endif #if !defined(SUNLIGHT_KILL) - color.rgb += eep_bump_gain * sun_contrib; + color.rgb += sun_contrib; #endif color.rgb *= diffuse_linear.rgb; // SL-12006 + // ad-hoc brighten and de-saturate (normal-mapped only), to match windlight - SL-12638 + color.rgb = desat(color.rgb, 0.33 * (eep_bump_gain - 1.0)); + color.rgb *= eep_bump_gain; + float glare = 0.0; if (spec.a > 0.0) // specular reflection -- cgit v1.2.3 From 8c2b7e0e83566e9a27a65856d5ae7fbe3558422f Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 3 Mar 2020 16:39:17 -0700 Subject: Revert 2 merges (PR#13, PR#16) related to SL-12638 This reverts commits 9d9b890 and 5f846e4. --- .../shaders/class1/deferred/fullbrightF.glsl | 3 +- .../shaders/class1/deferred/materialF.glsl | 81 ++++++++++++++-------- 2 files changed, 54 insertions(+), 30 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 39ed9a6e82..c104dc884f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -86,6 +86,7 @@ void main() color.a = final_alpha; #endif - frag_color = color; + frag_color.rgb = color.rgb; + frag_color.a = color.a; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index eebb0a5fe5..d28fc128b6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -95,6 +95,19 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe dist /= la; + /* clip to projector bounds + vec4 proj_tc = proj_mat * lp; + + if (proj_tc.z < 0 + || proj_tc.z > 1 + || proj_tc.x < 0 + || proj_tc.x > 1 + || proj_tc.y < 0 + || proj_tc.y > 1) + { + return col; + }*/ + if (dist > 0.0 && la > 0.0) { //normalize light vector @@ -164,14 +177,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe return max(col, vec3(0.0,0.0,0.0)); } -// Q&D approximate RGB-space de-saturation, strength from 0 (no effect) to 1.0 (complete grey-scale) -vec3 desat(vec3 color, float strength) -{ - float primary_value = max(color.r, max(color.g, color.b)); - vec3 delta = strength * (vec3(primary_value)-color); - return color + delta; -} - #else #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -247,11 +252,7 @@ void main() vec3 norm = vec3(0); float bmap_specular = 1.0; - // Non-physical gain, sole purpose to make EEP viewer better match windlight when normal-mapped. - float eep_bump_gain = 1.0; - #ifdef HAS_NORMAL_MAP - eep_bump_gain = 1.75; vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); norm = (bump_sample.xyz * 2) - vec3(1); bmap_specular = bump_sample.w; @@ -294,7 +295,7 @@ void main() vec4 final_normal = vec4(abnormal, env_intensity, 0.0); vec3 color = vec3(0.0); - float al = 1.0; + float al = 0.0; if (emissive_brightness >= 1.0) { @@ -317,12 +318,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - if (emissive_brightness >= 1.0) - { - // fullbright = diffuse texture pass-through, no lighting - frag_color = diffuse_srgb; - } - else + if (emissive_brightness <= 1.0) { //forward rendering, output just lit RGBA vec3 pos = vary_position; @@ -352,25 +348,32 @@ void main() float da = dot(norm, normalize(light_dir)); da = clamp(da, 0.0, 1.0); // No negative light contributions - // ambient weight varies from 0.75 at max direct light to 1.0 with sun at grazing angle - float ambient = 1.0 - (0.25 * da * da); + float ambient = da; + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); + + vec3 sun_contrib = min(da, shadow) * sunlit; - vec3 sun_contrib = additive + (min(da, shadow) * sunlit); +// vec3 debug_sun_contrib = sun_contrib; #if !defined(AMBIENT_KILL) color.rgb = amblit; color.rgb *= ambient; #endif +//vec3 debug_post_ambient = color.rgb; + #if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; #endif +//vec3 debug_post_sunlight = color.rgb; + + //color.rgb *= diffuse_srgb.rgb; color.rgb *= diffuse_linear.rgb; // SL-12006 - // ad-hoc brighten and de-saturate (normal-mapped only), to match windlight - SL-12638 - color.rgb = desat(color.rgb, 0.33 * (eep_bump_gain - 1.0)); - color.rgb *= eep_bump_gain; +//vec3 debug_post_diffuse = color.rgb; float glare = 0.0; @@ -378,6 +381,7 @@ void main() { vec3 npos = -normalize(pos.xyz); + //vec3 ref = dot(pos+lv, norm); vec3 h = normalize(light_dir.xyz+npos); float nh = dot(norm, h); float nv = dot(norm, npos); @@ -400,6 +404,8 @@ void main() } } +//vec3 debug_post_spec = color.rgb; + if (envIntensity > 0.0) { //add environmentmap @@ -416,11 +422,15 @@ void main() glare += cur_glare; } +//vec3 debug_post_env = color.rgb; + color = atmosFragLighting(color, additive, atten); //convert to linear space before adding local lights color = srgb_to_linear(color); +//vec3 debug_post_atmo = color.rgb; + vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -443,19 +453,32 @@ void main() #endif color = scaleSoftClipFrag(color); - + // (only) post-deferred needs inline gamma correction color.rgb = linear_to_srgb(color.rgb); +//color.rgb = amblit; +//color.rgb = vec3(ambient); +//color.rgb = sunlit; +//color.rgb = debug_post_ambient; +//color.rgb = vec3(da); +//color.rgb = debug_sun_contrib; +//color.rgb = debug_post_sunlight; +//color.rgb = diffuse_srgb.rgb; +//color.rgb = debug_post_diffuse; +//color.rgb = debug_post_spec; +//color.rgb = debug_post_env; +//color.rgb = debug_post_atmo; + #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); color.rgb = temp.rgb; al = temp.a; #endif + } // !fullbright - frag_color.rgb = color.rgb; - frag_color.a = al; - } + frag_color.rgb = color.rgb; + frag_color.a = al; #else // if DIFFUSE_ALPHA_MODE_BLEND ... -- cgit v1.2.3 From 1ba0df9abe26a18f2c870210be9b8fe6a1c72699 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 3 Mar 2020 17:13:46 -0700 Subject: Roll back SL-12006 commits to materialF.glsl (Dec23) --- .../shaders/class1/deferred/materialF.glsl | 69 ++++------------------ 1 file changed, 11 insertions(+), 58 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d28fc128b6..0829968dd1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -95,19 +95,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe dist /= la; - /* clip to projector bounds - vec4 proj_tc = proj_mat * lp; - - if (proj_tc.z < 0 - || proj_tc.z > 1 - || proj_tc.x < 0 - || proj_tc.x > 1 - || proj_tc.y < 0 - || proj_tc.y > 1) - { - return col; - }*/ - if (dist > 0.0 && la > 0.0) { //normalize light vector @@ -273,7 +260,6 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = diffuse_linear.a; - final_color.rgb = mix( diffuse_linear.rgb, final_color.rgb*0.5, diffuse_tap.a ); // SL-12171: Fix emissive texture portion being twice as bright. #endif final_color.a = max(final_color.a, emissive_brightness); @@ -295,17 +281,15 @@ void main() vec4 final_normal = vec4(abnormal, env_intensity, 0.0); vec3 color = vec3(0.0); - float al = 0.0; + float al = 0; +#ifdef HAS_SPECULAR_MAP if (emissive_brightness >= 1.0) { -#ifdef HAS_SPECULAR_MAP - // Note: We actually need to adjust all 4 channels not just .rgb - final_color *= 0.666666; -#endif - color.rgb = final_color.rgb; - al = vertex_color.a; + float ei = env_intensity*0.5 + 0.5; + final_normal = vec4(abnormal, ei, 0.0); } +#endif vec4 final_specular = spec; @@ -318,7 +302,6 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - if (emissive_brightness <= 1.0) { //forward rendering, output just lit RGBA vec3 pos = vary_position; @@ -348,33 +331,22 @@ void main() float da = dot(norm, normalize(light_dir)); da = clamp(da, 0.0, 1.0); // No negative light contributions - float ambient = da; - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); + // ambient weight varies from 0.75 at max direct light to 1.0 with sun at grazing angle + float ambient = 1.0 - (0.25 * da * da); vec3 sun_contrib = min(da, shadow) * sunlit; -// vec3 debug_sun_contrib = sun_contrib; - #if !defined(AMBIENT_KILL) color.rgb = amblit; color.rgb *= ambient; #endif -//vec3 debug_post_ambient = color.rgb; - #if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; #endif -//vec3 debug_post_sunlight = color.rgb; - - //color.rgb *= diffuse_srgb.rgb; - color.rgb *= diffuse_linear.rgb; // SL-12006 - -//vec3 debug_post_diffuse = color.rgb; - + color.rgb *= diffuse_srgb.rgb; + float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -404,8 +376,6 @@ void main() } } -//vec3 debug_post_spec = color.rgb; - if (envIntensity > 0.0) { //add environmentmap @@ -422,15 +392,11 @@ void main() glare += cur_glare; } -//vec3 debug_post_env = color.rgb; - color = atmosFragLighting(color, additive, atten); //convert to linear space before adding local lights color = srgb_to_linear(color); -//vec3 debug_post_atmo = color.rgb; - vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -457,30 +423,17 @@ void main() // (only) post-deferred needs inline gamma correction color.rgb = linear_to_srgb(color.rgb); -//color.rgb = amblit; -//color.rgb = vec3(ambient); -//color.rgb = sunlit; -//color.rgb = debug_post_ambient; -//color.rgb = vec3(da); -//color.rgb = debug_sun_contrib; -//color.rgb = debug_post_sunlight; -//color.rgb = diffuse_srgb.rgb; -//color.rgb = debug_post_diffuse; -//color.rgb = debug_post_spec; -//color.rgb = debug_post_env; -//color.rgb = debug_post_atmo; - #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); color.rgb = temp.rgb; al = temp.a; #endif - } // !fullbright + } frag_color.rgb = color.rgb; frag_color.a = al; -#else // if DIFFUSE_ALPHA_MODE_BLEND ... +#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer // deferred path frag_data[0] = final_color; -- cgit v1.2.3 From cc5044bce06598aab9f405bba745f0e8209fc5ce Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Wed, 4 Mar 2020 15:56:02 -0600 Subject: WIP - fix various inconsistencies in sRGB vs linear color space. Fix inconsistencies between softenLightF.glsl, materialF.glsl, and alphaF.glsl --- .../shaders/class1/deferred/alphaF.glsl | 19 +++--- .../shaders/class1/deferred/materialF.glsl | 70 +++++++++++----------- .../class1/deferred/postDeferredGammaCorrect.glsl | 3 +- .../shaders/class1/deferred/softenLightF.glsl | 10 ++-- 4 files changed, 50 insertions(+), 52 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 546a502ee1..814d5036db 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -22,7 +22,9 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + +//class1/deferred/alphaF.glsl + #extension GL_ARB_texture_rectangle : enable /*[EXTRA_CODE_HERE]*/ @@ -51,7 +53,7 @@ VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; #ifdef USE_VERTEX_COLOR -VARYING vec4 vertex_color; +VARYING vec4 vertex_color; //vertex color should be treated as sRGB #endif uniform mat4 proj_mat; @@ -190,7 +192,7 @@ void main() float final_alpha = diffuse_srgb.a * vertex_color.a; diffuse_srgb.rgb *= vertex_color.rgb; - diffuse_linear.rgb *= vertex_color.rgb; + diffuse_linear.rgb = srgb_to_linear(diffuse_srgb.rgb); // Insure we don't pollute depth with invis pixels in impostor rendering // @@ -207,7 +209,7 @@ void main() #ifdef USE_VERTEX_COLOR final_alpha *= vertex_color.a; diffuse_srgb.rgb *= vertex_color.rgb; - diffuse_linear.rgb *= vertex_color.rgb; + diffuse_linear.rgb = srgb_to_linear(diffuse_srgb.rgb); #endif vec3 sunlit; @@ -249,7 +251,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_srgb.rgb; + color.rgb *= diffuse_linear.rgb; vec3 post_diffuse = color.rgb; @@ -258,10 +260,7 @@ vec3 post_diffuse = color.rgb; vec3 post_atmo = color.rgb; vec4 light = vec4(0,0,0,0); - - // to linear! - color.rgb = srgb_to_linear(color.rgb); - + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.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); LIGHT_LOOP(1) @@ -298,7 +297,7 @@ vec3 post_atmo = color.rgb; #endif // WATER_FOG #endif - + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index eebb0a5fe5..c6ba489d52 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -25,6 +25,10 @@ /*[EXTRA_CODE_HERE]*/ +//class1/deferred/materialF.glsl + +// This shader is used for both writing opaque/masked content to the gbuffer and writing blended content to the framebuffer during the alpha pass. + #define DIFFUSE_ALPHA_MODE_NONE 0 #define DIFFUSE_ALPHA_MODE_BLEND 1 #define DIFFUSE_ALPHA_MODE_MASK 2 @@ -180,7 +184,7 @@ out vec4 frag_data[3]; #endif #endif -uniform sampler2D diffuseMap; +uniform sampler2D diffuseMap; //always in sRGB space #ifdef HAS_NORMAL_MAP uniform sampler2D bumpMap; @@ -218,14 +222,16 @@ void main() vec2 pos_screen = vary_texcoord0.xy; vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); + diffuse_tap.rgb *= vertex_color.rgb; + //diffuse_tap = vec4(1,1,1,1); -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) +//#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vec4 diffuse_srgb = diffuse_tap; vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); -#else +/*#else vec4 diffuse_linear = diffuse_tap; vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); -#endif +#endif*/ #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffuse_linear.a < minimum_alpha) @@ -234,9 +240,6 @@ void main() } #endif - diffuse_linear.rgb *= vertex_color.rgb; - diffuse_srgb.rgb *= linear_to_srgb(vertex_color.rgb); - #ifdef HAS_SPECULAR_MAP vec4 spec = texture2D(specularMap, vary_texcoord2.xy); spec.rgb *= specular_color.rgb; @@ -298,10 +301,10 @@ void main() if (emissive_brightness >= 1.0) { -#ifdef HAS_SPECULAR_MAP +/*#ifdef HAS_SPECULAR_MAP // Note: We actually need to adjust all 4 channels not just .rgb final_color *= 0.666666; -#endif +#endif*/ color.rgb = final_color.rgb; al = vertex_color.a; } @@ -320,11 +323,12 @@ void main() if (emissive_brightness >= 1.0) { // fullbright = diffuse texture pass-through, no lighting - frag_color = diffuse_srgb; + color = diffuse_linear.rgb; + al = diffuse_linear.a; } else { - //forward rendering, output just lit RGBA + //forward rendering, output just lit sRGBA vec3 pos = vary_position; float shadow = 1.0f; @@ -349,13 +353,14 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); - float da = dot(norm, normalize(light_dir)); - da = clamp(da, 0.0, 1.0); // No negative light contributions + float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); - // ambient weight varies from 0.75 at max direct light to 1.0 with sun at grazing angle - float ambient = 1.0 - (0.25 * da * da); + float ambient = da; + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); - vec3 sun_contrib = additive + (min(da, shadow) * sunlit); + vec3 sun_contrib = da * sunlit; #if !defined(AMBIENT_KILL) color.rgb = amblit; @@ -367,11 +372,7 @@ void main() #endif color.rgb *= diffuse_linear.rgb; // SL-12006 - - // ad-hoc brighten and de-saturate (normal-mapped only), to match windlight - SL-12638 - color.rgb = desat(color.rgb, 0.33 * (eep_bump_gain - 1.0)); - color.rgb *= eep_bump_gain; - + float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -391,9 +392,9 @@ void main() if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 sp = sun_contrib*scol / 16.0f; + vec3 sp = sun_contrib*scol / 6.0f; sp = clamp(sp, vec3(0), vec3(1)); - bloom = dot(sp, sp) / 6.0; + bloom = dot(sp, sp) / 4.0; #if !defined(SUNLIGHT_KILL) color += sp * spec.rgb; #endif @@ -418,9 +419,6 @@ void main() color = atmosFragLighting(color, additive, atten); - //convert to linear space before adding local lights - color = srgb_to_linear(color); - vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -444,23 +442,23 @@ void main() color = scaleSoftClipFrag(color); - // (only) post-deferred needs inline gamma correction - color.rgb = linear_to_srgb(color.rgb); - -#ifdef WATER_FOG +/*#ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); color.rgb = temp.rgb; al = temp.a; -#endif - - frag_color.rgb = color.rgb; - frag_color.a = al; +#endif*/ } -#else // if DIFFUSE_ALPHA_MODE_BLEND ... + // (only) post-deferred needs inline gamma correction + color.rgb = linear_to_srgb(color.rgb); + + frag_color = vec4(color, al); + +#else // if DIFFUSE_ALPHA_MODE_BLEND ... + // deferred path - frag_data[0] = final_color; + frag_data[0] = vec4(linear_to_srgb(final_color.rgb), final_color.a); //gbuffer is sRGB frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 9f519708a2..966c73ef24 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -44,7 +44,8 @@ vec3 linear_to_srgb(vec3 cl); void main() { vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - diff.rgb = pow(diff.rgb, vec3(display_gamma)); + //diff.rgb = pow(diff.rgb, vec3(display_gamma)); + diff.rgb = linear_to_srgb(diff.rgb); frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 705cc2f04e..da2eb47e3b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -119,7 +119,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_srgb.rgb; + color.rgb *= diffuse_linear.rgb; vec3 post_diffuse = color.rgb; @@ -157,7 +157,7 @@ vec3 post_diffuse = color.rgb; #ifdef WATER_FOG color.rgb += diffuse_srgb.rgb * diffuse_srgb.a * 0.25; #else - color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); + color.rgb = mix(color.rgb, diffuse_linear.rgb, diffuse_linear.a); #endif if (envIntensity > 0.0) @@ -201,7 +201,7 @@ vec3 post_atmo = color.rgb; // 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); + //color.rgb = srgb_to_linear(color.rgb); } // linear debuggables @@ -209,7 +209,7 @@ vec3 post_atmo = color.rgb; //color.rgb = vec3(ambient); //color.rgb = vec3(scol); //color.rgb = diffuse_linear.rgb; - + frag_color.rgb = color.rgb; - frag_color.a = bloom; + frag_color.a = 0.0; //bloom; } -- cgit v1.2.3 From 1481d78bb25a06ca99e0d75e8d6333abd6ce5590 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Wed, 4 Mar 2020 16:23:31 -0600 Subject: Changes somehow missing from last commit --- .../shaders/class1/deferred/multiPointLightF.glsl | 3 ++- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index dcc3750a8f..0d1cc81786 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -102,7 +102,8 @@ void main() dist_atten *= dist_atten; // Tweak falloff slightly to match pre-EEP attenuation - dist_atten *= 2.2; + // NOTE: this magic number also shows up in a great many other places, search for dist_atten *= to audit + dist_atten *= 2.0; dist_atten *= noise; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 593706867d..bacdb6f70f 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -127,7 +127,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_srgb.rgb; + color.rgb *= diffuse_linear.rgb; vec3 post_diffuse = color.rgb; @@ -162,8 +162,10 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; -#ifndef WATER_FOG - color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); +#ifdef WATER_FOG + color.rgb += diffuse_srgb.rgb * diffuse_srgb.a * 0.25; +#else + color.rgb = mix(color.rgb, diffuse_linear.rgb, diffuse_linear.a); #endif if (envIntensity > 0.0) @@ -206,9 +208,6 @@ vec3 post_atmo = color.rgb; //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); } // linear debuggables @@ -217,6 +216,8 @@ vec3 post_atmo = color.rgb; //color.rgb = vec3(scol); //color.rgb = diffuse_linear.rgb; + //output linear RGB as lights are summed up in linear space and then gamma corrected prior to the + //post deferred passes frag_color.rgb = color.rgb; frag_color.a = bloom; } -- cgit v1.2.3 From 265cefd2621a7d29e322ac903835bceb365f4f0a Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Wed, 4 Mar 2020 16:38:37 -0600 Subject: Merge fix --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 57e30c0ef3..ffd9dfed8c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -349,7 +349,7 @@ void main() color.rgb += sun_contrib; #endif - color.rgb *= diffuse_srgb.rgb; + color.rgb *= diffuse_linear.rgb; float glare = 0.0; -- cgit v1.2.3 From ca5cc79dfbc55a2160212f213a1a622691b7f02e Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Wed, 4 Mar 2020 16:43:18 -0600 Subject: Fix line endings? --- .../shaders/class1/deferred/materialF.glsl | 888 ++++++++++----------- 1 file changed, 444 insertions(+), 444 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index ffd9dfed8c..586ce4a9b7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -1,444 +1,444 @@ -/** - * @file materialF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, 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$ - */ - -/*[EXTRA_CODE_HERE]*/ - -//class1/deferred/materialF.glsl - -// This shader is used for both writing opaque/masked content to the gbuffer and writing blended content to the framebuffer during the alpha pass. - -#define DIFFUSE_ALPHA_MODE_NONE 0 -#define DIFFUSE_ALPHA_MODE_BLEND 1 -#define DIFFUSE_ALPHA_MODE_MASK 2 -#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 - -uniform float emissive_brightness; -uniform int sun_up_factor; - -#ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); -#endif - -vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleSoftClipFrag(vec3 l); - -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 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cs); - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - -#ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_color; -#else - #define frag_color gl_FragColor -#endif - -#ifdef HAS_SUN_SHADOW - float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); -#endif - -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -uniform mat3 env_mat; - -uniform vec3 sun_dir; -uniform vec3 moon_dir; -VARYING vec2 vary_fragcoord; - -VARYING vec3 vary_position; - -uniform mat4 proj_mat; -uniform mat4 inv_proj; -uniform vec2 screen_res; - -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec4 light_attenuation[8]; -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 col = vec3(0); - - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float dist = length(lv); - float da = 1.0; - - dist /= la; - - if (dist > 0.0 && la > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0f; - - if (dist_atten <= 0.0) - { - return col; - } - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - //angular attenuation - da *= dot(n, lv); - - float lit = 0.0f; - - float amb_da = ambiance; - if (da >= 0) - { - lit = max(da * dist_atten,0.0); - col = lit * light_col * diffuse; - amb_da += (da*0.5+0.5) * ambiance; - } - amb_da += (da*da*0.5 + 0.5) * ambiance; - amb_da *= dist_atten; - amb_da = min(amb_da, 1.0f - lit); - - // SL-10969 need to see why these are blown out - //col.rgb += amb_da * light_col * diffuse; - - if (spec.a > 0.0) - { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - 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); - } - } - } - - return max(col, vec3(0.0,0.0,0.0)); -} - -#else -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif -#endif - -uniform sampler2D diffuseMap; //always in sRGB space - -#ifdef HAS_NORMAL_MAP -uniform sampler2D bumpMap; -#endif - -#ifdef HAS_SPECULAR_MAP -uniform sampler2D specularMap; - -VARYING vec2 vary_texcoord2; -#endif - -uniform float env_intensity; -uniform vec4 specular_color; // specular color RGB and specular exponent (glossiness) in alpha - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) -uniform float minimum_alpha; -#endif - -#ifdef HAS_NORMAL_MAP -VARYING vec3 vary_mat0; -VARYING vec3 vary_mat1; -VARYING vec3 vary_mat2; -VARYING vec2 vary_texcoord1; -#else -VARYING vec3 vary_normal; -#endif - -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -vec2 encode_normal(vec3 n); - -void main() -{ - vec2 pos_screen = vary_texcoord0.xy; - - vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); - diffuse_tap.rgb *= vertex_color.rgb; - //diffuse_tap = vec4(1,1,1,1); - -//#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec4 diffuse_srgb = diffuse_tap; - vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); -/*#else - vec4 diffuse_linear = diffuse_tap; - vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); -#endif*/ - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - if (diffuse_linear.a < minimum_alpha) - { - discard; - } -#endif - -#ifdef HAS_SPECULAR_MAP - vec4 spec = texture2D(specularMap, vary_texcoord2.xy); - spec.rgb *= specular_color.rgb; -#else - vec4 spec = vec4(specular_color.rgb, 1.0); -#endif - - vec3 norm = vec3(0); - float bmap_specular = 1.0; - -#ifdef HAS_NORMAL_MAP - vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); - norm = (bump_sample.xyz * 2) - vec3(1); - bmap_specular = bump_sample.w; - - // convert sampled normal to tangent space normal - norm = vec3(dot(norm, vary_mat0), - dot(norm, vary_mat1), - dot(norm, vary_mat2)); -#else - norm = vary_normal; -#endif - - norm = normalize(norm); - - vec2 abnormal = encode_normal(norm); - - vec4 final_color = vec4(diffuse_linear.rgb, 0.0); - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = diffuse_linear.a; -#endif - - final_color.a = max(final_color.a, emissive_brightness); - - // Texture - // [x] Full Bright (emissive_brightness >= 1.0) - // Shininess (specular) - // [X] Texture - // Environment Intensity = 1 - // NOTE: There are two shaders that are used depending on the EI byte value: - // EI = 0 fullbright - // EI > 0 .. 255 material - // When it is passed to us it is normalized. - // We can either modify the output environment intensity - // OR - // adjust the final color via: - // final_color *= 0.666666; - // We don't remap the environment intensity but adjust the final color to closely simulate what non-EEP is doing. - vec4 final_normal = vec4(abnormal, env_intensity, 0.0); - - vec3 color = vec3(0.0); - float al = 0; - -#ifdef HAS_SPECULAR_MAP - if (emissive_brightness >= 1.0) - { - float ei = env_intensity*0.5 + 0.5; - final_normal = vec4(abnormal, ei, 0.0); - } -#endif - - vec4 final_specular = spec; - - final_specular.a = specular_color.a; - -#ifdef HAS_SPECULAR_MAP - final_specular.a *= bmap_specular; - final_normal.z *= spec.a; -#endif - - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - { - //forward rendering, output just lit sRGBA - vec3 pos = vary_position; - - float shadow = 1.0f; - -#ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); -#endif - - spec = final_specular; - - float envIntensity = final_normal.z; - - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - - float bloom = 0.0; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - - calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); - - float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); - - float ambient = da; - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - - vec3 sun_contrib = min(da, shadow) * sunlit; - -#if !defined(AMBIENT_KILL) - color.rgb = amblit; - color.rgb *= ambient; -#endif - -#if !defined(SUNLIGHT_KILL) - color.rgb += sun_contrib; -#endif - - color.rgb *= diffuse_linear.rgb; - - float glare = 0.0; - - if (spec.a > 0.0) // specular reflection - { - vec3 npos = -normalize(pos.xyz); - - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(light_dir.xyz+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 sp = sun_contrib*scol / 6.0f; - sp = clamp(sp, vec3(0), vec3(1)); - bloom = dot(sp, sp) / 4.0; -#if !defined(SUNLIGHT_KILL) - color += sp * spec.rgb; -#endif - } - } - - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - -#if !defined(SUNLIGHT_KILL) - color = mix(color.rgb, reflected_color, envIntensity); -#endif - float cur_glare = max(reflected_color.r, reflected_color.g); - cur_glare = max(cur_glare, reflected_color.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; - } - - color = atmosFragLighting(color, additive, atten); - - vec3 npos = normalize(-pos.xyz); - - vec3 light = vec3(0,0,0); - -#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w ); - - LIGHT_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) - - glare = min(glare, 1.0); - al = max(diffuse_linear.a,glare)*vertex_color.a; - -#if !defined(LOCAL_LIGHT_KILL) - color.rgb += light.rgb; -#endif - - color = scaleSoftClipFrag(color); - -/*#ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); - color.rgb = temp.rgb; - al = temp.a; -#endif*/ - } - - - color.rgb = linear_to_srgb(color.rgb); - - frag_color = vec4(color, al); - -#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer - - // deferred path - frag_data[0] = vec4(linear_to_srgb(final_color.rgb), final_color.a); //gbuffer is sRGB - frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. - frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. -#endif -} - +/** + * @file materialF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, 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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +//class1/deferred/materialF.glsl + +// This shader is used for both writing opaque/masked content to the gbuffer and writing blended content to the framebuffer during the alpha pass. + +#define DIFFUSE_ALPHA_MODE_NONE 0 +#define DIFFUSE_ALPHA_MODE_BLEND 1 +#define DIFFUSE_ALPHA_MODE_MASK 2 +#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 + +uniform float emissive_brightness; +uniform int sun_up_factor; + +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif + +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleSoftClipFrag(vec3 l); + +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 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cs); + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + +#ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_color; +#else + #define frag_color gl_FragColor +#endif + +#ifdef HAS_SUN_SHADOW + float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +#endif + +uniform samplerCube environmentMap; +uniform sampler2D lightFunc; + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; +uniform mat3 env_mat; + +uniform vec3 sun_dir; +uniform vec3 moon_dir; +VARYING vec2 vary_fragcoord; + +VARYING vec3 vary_position; + +uniform mat4 proj_mat; +uniform mat4 inv_proj; +uniform vec2 screen_res; + +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec4 light_attenuation[8]; +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 col = vec3(0); + + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float dist = length(lv); + float da = 1.0; + + dist /= la; + + if (dist > 0.0 && la > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0f; + + if (dist_atten <= 0.0) + { + return col; + } + + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 + + //angular attenuation + da *= dot(n, lv); + + float lit = 0.0f; + + float amb_da = ambiance; + if (da >= 0) + { + lit = max(da * dist_atten,0.0); + col = lit * light_col * diffuse; + amb_da += (da*0.5+0.5) * ambiance; + } + amb_da += (da*da*0.5 + 0.5) * ambiance; + amb_da *= dist_atten; + amb_da = min(amb_da, 1.0f - lit); + + // SL-10969 need to see why these are blown out + //col.rgb += amb_da * light_col * diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + 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); + } + } + } + + return max(col, vec3(0.0,0.0,0.0)); +} + +#else +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif +#endif + +uniform sampler2D diffuseMap; //always in sRGB space + +#ifdef HAS_NORMAL_MAP +uniform sampler2D bumpMap; +#endif + +#ifdef HAS_SPECULAR_MAP +uniform sampler2D specularMap; + +VARYING vec2 vary_texcoord2; +#endif + +uniform float env_intensity; +uniform vec4 specular_color; // specular color RGB and specular exponent (glossiness) in alpha + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) +uniform float minimum_alpha; +#endif + +#ifdef HAS_NORMAL_MAP +VARYING vec3 vary_mat0; +VARYING vec3 vary_mat1; +VARYING vec3 vary_mat2; +VARYING vec2 vary_texcoord1; +#else +VARYING vec3 vary_normal; +#endif + +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +vec2 encode_normal(vec3 n); + +void main() +{ + vec2 pos_screen = vary_texcoord0.xy; + + vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); + diffuse_tap.rgb *= vertex_color.rgb; + //diffuse_tap = vec4(1,1,1,1); + +//#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vec4 diffuse_srgb = diffuse_tap; + vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); +/*#else + vec4 diffuse_linear = diffuse_tap; + vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); +#endif*/ + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) + if (diffuse_linear.a < minimum_alpha) + { + discard; + } +#endif + +#ifdef HAS_SPECULAR_MAP + vec4 spec = texture2D(specularMap, vary_texcoord2.xy); + spec.rgb *= specular_color.rgb; +#else + vec4 spec = vec4(specular_color.rgb, 1.0); +#endif + + vec3 norm = vec3(0); + float bmap_specular = 1.0; + +#ifdef HAS_NORMAL_MAP + vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); + norm = (bump_sample.xyz * 2) - vec3(1); + bmap_specular = bump_sample.w; + + // convert sampled normal to tangent space normal + norm = vec3(dot(norm, vary_mat0), + dot(norm, vary_mat1), + dot(norm, vary_mat2)); +#else + norm = vary_normal; +#endif + + norm = normalize(norm); + + vec2 abnormal = encode_normal(norm); + + vec4 final_color = vec4(diffuse_linear.rgb, 0.0); + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) + final_color.a = diffuse_linear.a; +#endif + + final_color.a = max(final_color.a, emissive_brightness); + + // Texture + // [x] Full Bright (emissive_brightness >= 1.0) + // Shininess (specular) + // [X] Texture + // Environment Intensity = 1 + // NOTE: There are two shaders that are used depending on the EI byte value: + // EI = 0 fullbright + // EI > 0 .. 255 material + // When it is passed to us it is normalized. + // We can either modify the output environment intensity + // OR + // adjust the final color via: + // final_color *= 0.666666; + // We don't remap the environment intensity but adjust the final color to closely simulate what non-EEP is doing. + vec4 final_normal = vec4(abnormal, env_intensity, 0.0); + + vec3 color = vec3(0.0); + float al = 0; + +#ifdef HAS_SPECULAR_MAP + if (emissive_brightness >= 1.0) + { + float ei = env_intensity*0.5 + 0.5; + final_normal = vec4(abnormal, ei, 0.0); + } +#endif + + vec4 final_specular = spec; + + final_specular.a = specular_color.a; + +#ifdef HAS_SPECULAR_MAP + final_specular.a *= bmap_specular; + final_normal.z *= spec.a; +#endif + + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + { + //forward rendering, output just lit sRGBA + vec3 pos = vary_position; + + float shadow = 1.0f; + +#ifdef HAS_SUN_SHADOW + shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); +#endif + + spec = final_specular; + + float envIntensity = final_normal.z; + + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + + float bloom = 0.0; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + + vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); + + float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); + + float ambient = da; + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); + + vec3 sun_contrib = min(da, shadow) * sunlit; + +#if !defined(AMBIENT_KILL) + color.rgb = amblit; + color.rgb *= ambient; +#endif + +#if !defined(SUNLIGHT_KILL) + color.rgb += sun_contrib; +#endif + + color.rgb *= diffuse_linear.rgb; + + float glare = 0.0; + + if (spec.a > 0.0) // specular reflection + { + vec3 npos = -normalize(pos.xyz); + + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(light_dir.xyz+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 sp = sun_contrib*scol / 6.0f; + sp = clamp(sp, vec3(0), vec3(1)); + bloom = dot(sp, sp) / 4.0; +#if !defined(SUNLIGHT_KILL) + color += sp * spec.rgb; +#endif + } + } + + if (envIntensity > 0.0) + { + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + +#if !defined(SUNLIGHT_KILL) + color = mix(color.rgb, reflected_color, envIntensity); +#endif + float cur_glare = max(reflected_color.r, reflected_color.g); + cur_glare = max(cur_glare, reflected_color.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; + } + + color = atmosFragLighting(color, additive, atten); + + vec3 npos = normalize(-pos.xyz); + + vec3 light = vec3(0,0,0); + +#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w ); + + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) + + glare = min(glare, 1.0); + al = max(diffuse_linear.a,glare)*vertex_color.a; + +#if !defined(LOCAL_LIGHT_KILL) + color.rgb += light.rgb; +#endif + + color = scaleSoftClipFrag(color); + +/*#ifdef WATER_FOG + vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); + color.rgb = temp.rgb; + al = temp.a; +#endif*/ + } + + + color.rgb = linear_to_srgb(color.rgb); + + frag_color = vec4(color, al); + +#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer + + // deferred path + frag_data[0] = vec4(linear_to_srgb(final_color.rgb), final_color.a); //gbuffer is sRGB + frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. + frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. +#endif +} + -- cgit v1.2.3 From d33655828c104d1afe484b63093ad5aab1571a3c Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Thu, 5 Mar 2020 11:58:58 -0600 Subject: Reenable water fog in materialF.glsl (oops) --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 586ce4a9b7..18293f4c11 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -421,16 +421,16 @@ void main() color = scaleSoftClipFrag(color); -/*#ifdef WATER_FOG +#ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); color.rgb = temp.rgb; al = temp.a; -#endif*/ +#endif } - - color.rgb = linear_to_srgb(color.rgb); + color.rgb = linear_to_srgb(color.rgb); + frag_color = vec4(color, al); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer -- cgit v1.2.3 From 7c7d71269f5b47397d14bbe44e341e4ac1d96889 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Thu, 5 Mar 2020 16:28:06 -0600 Subject: WIP - Windlight sun lighting should happen in sRGB space, not linear space. This keeps ambient from getting overblown and better matches environment lighting with ALM on/off. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 10 ++++++---- .../shaders/class1/deferred/materialF.glsl | 18 ++++++++++-------- .../shaders/class1/deferred/multiSpotLightF.glsl | 18 ++++++++++++------ .../class1/deferred/postDeferredGammaCorrect.glsl | 1 + .../shaders/class1/deferred/softenLightF.glsl | 11 +++++------ .../shaders/class1/windlight/atmosphericsFuncs.glsl | 3 ++- .../shaders/class2/deferred/multiSpotLightF.glsl | 8 +++++--- .../shaders/class2/deferred/softenLightF.glsl | 6 +++--- .../shaders/class2/deferred/spotLightF.glsl | 3 ++- .../shaders/class3/deferred/multiSpotLightF.glsl | 3 ++- .../shaders/class3/deferred/softenLightF.glsl | 6 ++++-- .../shaders/class3/deferred/spotLightF.glsl | 2 +- 12 files changed, 53 insertions(+), 36 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 814d5036db..e38eeab370 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -251,7 +251,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_linear.rgb; + color.rgb *= diffuse_srgb.rgb; vec3 post_diffuse = color.rgb; @@ -261,6 +261,11 @@ vec3 post_atmo = color.rgb; vec4 light = vec4(0,0,0,0); + color.rgb = scaleSoftClipFrag(color.rgb); + + //convert to linear before applying local lights + color.rgb = srgb_to_linear(color.rgb); + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.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); LIGHT_LOOP(1) @@ -275,9 +280,6 @@ vec3 post_atmo = color.rgb; #if !defined(LOCAL_LIGHT_KILL) color.rgb += light.rgb; #endif - - color.rgb = scaleSoftClipFrag(color.rgb); - // back to sRGB as we're going directly to the final RT post-deferred gamma correction color.rgb = linear_to_srgb(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 18293f4c11..e4ebf0edee 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -117,7 +117,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 - + //angular attenuation da *= dot(n, lv); @@ -215,8 +215,7 @@ void main() vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); diffuse_tap.rgb *= vertex_color.rgb; - //diffuse_tap = vec4(1,1,1,1); - + //#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vec4 diffuse_srgb = diffuse_tap; vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); @@ -349,7 +348,7 @@ void main() color.rgb += sun_contrib; #endif - color.rgb *= diffuse_linear.rgb; + color.rgb *= diffuse_srgb.rgb; float glare = 0.0; @@ -397,11 +396,15 @@ void main() } color = atmosFragLighting(color, additive, atten); + color = scaleSoftClipFrag(color); vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); + //convert to linear before adding local lights + color.rgb = srgb_to_linear(color.rgb); + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w ); LIGHT_LOOP(1) @@ -419,8 +422,9 @@ void main() color.rgb += light.rgb; #endif - color = scaleSoftClipFrag(color); - +//convert to srgb as this color is being written post gamma correction + color.rgb = linear_to_srgb(color.rgb); + #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); color.rgb = temp.rgb; @@ -429,8 +433,6 @@ void main() } - color.rgb = linear_to_srgb(color.rgb); - frag_color = vec4(color, al); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index a690cc45a8..9bba45bc4e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -163,15 +163,19 @@ void main() proj_tc.xyz /= proj_tc.w; float fa = falloff+1.0; - float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); + 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; + if (dist_atten <= 0.0) { discard; } + float noise = texture2D(noiseMap, frag.xy/128.0).b; + dist_atten *= noise; + lv = proj_origin-pos.xyz; lv = normalize(lv); float da = dot(norm, lv); @@ -179,12 +183,13 @@ void main() vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; // SL-12005 Projector light pops as we get closer, more objectionable than being in wrong color space. - // We can't switch to linear here unless we do it everywhere - //diff_tex.rgb = srgb_to_linear(diff_tex.rgb); + // We can't switch to linear here unless we do it everywhere* + // *gbuffer is sRGB, convert to linear whenever sampling from it + diff_tex.rgb = srgb_to_linear(diff_tex.rgb); vec3 dlit = vec3(0, 0, 0); - float noise = texture2D(noiseMap, frag.xy/128.0).b; + if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && proj_tc.y < 1.0 && @@ -203,7 +208,7 @@ void main() dlit = color.rgb * plcol.rgb * plcol.a; - lit = da * dist_atten * noise; + lit = da * dist_atten; col = dlit*lit*diff_tex; amb_da += (da*0.5)*proj_ambiance; @@ -245,7 +250,7 @@ void main() col += dlit*scol*spec.rgb; //col += spec.rgb; } - } + } if (envIntensity > 0.0) { @@ -277,6 +282,7 @@ void main() } #endif + //output linear, sum of lights will be gamma corrected later frag_color.rgb = col; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 966c73ef24..cd37a34e0d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -43,6 +43,7 @@ vec3 linear_to_srgb(vec3 cl); void main() { + //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB) vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); //diff.rgb = pow(diff.rgb, vec3(display_gamma)); diff.rgb = linear_to_srgb(diff.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index da2eb47e3b..19e737326d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -119,7 +119,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_linear.rgb; + color.rgb *= diffuse_srgb.rgb; vec3 post_diffuse = color.rgb; @@ -199,9 +199,6 @@ vec3 post_atmo = color.rgb; //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); } // linear debuggables @@ -209,7 +206,9 @@ vec3 post_atmo = color.rgb; //color.rgb = vec3(ambient); //color.rgb = vec3(scol); //color.rgb = diffuse_linear.rgb; - - frag_color.rgb = color.rgb; + + // 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.a = 0.0; //bloom; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index e5f1e11180..dcb02bd1c1 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -46,6 +46,7 @@ float getAmbientClamp() return 1.0f; } + 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 P = inPositionEye; @@ -123,7 +124,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou temp2.x *= sun_moon_glow_factor; vec4 amb_color = ambient_color; - + //increase ambient when there are more clouds vec4 tmpAmbient = amb_color + (vec4(1.) - amb_color) * cloud_shadow * 0.5; diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 7cde67d11b..5d7a28c359 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -192,8 +192,9 @@ void main() vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; // SL-12005 Projector light pops as we get closer, more objectionable than being in wrong color space. - // We can't switch to linear here unless we do it everywhere - //diff_tex.rgb = srgb_to_linear(diff_tex.rgb); + // We can't switch to linear here unless we do it everywhere* + // *gbuffer IS sRGB, convert to linear since this shader outputs linear + diff_tex.rgb = srgb_to_linear(diff_tex.rgb); vec4 spec = texture2DRect(specularRect, frag.xy); @@ -296,6 +297,7 @@ void main() //not sure why, but this line prevents MATBUG-194 col = max(col, vec3(0.0)); - frag_color.rgb = col; + //output linear + 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 bacdb6f70f..58d573c724 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -106,7 +106,7 @@ void main() vec3 atten; calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); - + float ambient = da; ambient *= 0.5; ambient *= ambient; @@ -127,7 +127,7 @@ vec3 post_ambient = color.rgb; vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_linear.rgb; + color.rgb *= diffuse_srgb.rgb; vec3 post_diffuse = color.rgb; @@ -218,6 +218,6 @@ vec3 post_atmo = color.rgb; //output linear RGB as lights are summed up in linear space and then gamma corrected prior to the //post deferred passes - frag_color.rgb = color.rgb; + frag_color.rgb = srgb_to_linear(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 77f6e6f7ac..5ab0b5c5b4 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -189,7 +189,7 @@ void main() lv = normalize(lv); float da = dot(norm, lv); - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + vec3 diff_tex = srgb_to_linear(texture2DRect(diffuseRect, frag.xy).rgb); vec4 spec = texture2DRect(specularRect, frag.xy); vec3 dlit = vec3(0, 0, 0); @@ -287,6 +287,7 @@ void main() //not sure why, but this line prevents MATBUG-194 col = max(col, vec3(0.0)); + //output linear colors as gamma correction happens down stream frag_color.rgb = col; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 52de7ceaad..9d62b9d180 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -183,7 +183,7 @@ void main() vec3 col = vec3(0,0,0); - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + vec3 diff_tex = srgb_to_linear(texture2DRect(diffuseRect, frag.xy).rgb); vec4 spec = texture2DRect(specularRect, frag.xy); @@ -285,6 +285,7 @@ void main() col = scaleDownLight(col); + //output linear space color as gamma correction happens down stream frag_color.rgb = col; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 978c25b86a..7ed9e7b4fc 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -94,7 +94,8 @@ void main() float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - vec4 diffuse = texture2DRect(diffuseRect, tc); // linear + vec4 diffuse = texture2DRect(diffuseRect, tc); // sRGB + diffuse.rgb = srgb_to_linear(diffuse.rgb); vec3 col; float bloom = 0.0; @@ -169,7 +170,8 @@ void main() bloom = fogged.a; #endif } - + + //output linear since gamma correction happens down stream frag_color.rgb = col; frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index bccd819a43..56b0f4e5ce 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -182,7 +182,7 @@ void main() vec3 col = vec3(0,0,0); - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + vec3 diff_tex = srgb_to_linear(texture2DRect(diffuseRect, frag.xy).rgb); vec4 spec = texture2DRect(specularRect, frag.xy); -- cgit v1.2.3 From 7d0cf70e4f335056e0d81b0b48264e5dda5be668 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Fri, 6 Mar 2020 11:05:55 -0600 Subject: Fix for under water being much brighter and mismatching between alpha and deferred. Don't make terrain fullbright under water. --- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 7 ++----- indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl | 8 -------- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 4 ---- 3 files changed, 2 insertions(+), 17 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 19e737326d..54abd56625 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -154,11 +154,7 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; -#ifdef WATER_FOG - color.rgb += diffuse_srgb.rgb * diffuse_srgb.a * 0.25; -#else color.rgb = mix(color.rgb, diffuse_linear.rgb, diffuse_linear.a); -#endif if (envIntensity > 0.0) { //add environmentmap @@ -209,6 +205,7 @@ vec3 post_atmo = color.rgb; // 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.a = 0.0; //bloom; + frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index b7bc92c460..6b6eed9db8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -44,10 +44,6 @@ VARYING vec4 vary_texcoord1; vec2 encode_normal(vec3 n); -#ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 c); -#endif - void main() { /// Note: This should duplicate the blending functionality currently used for the terrain rendering. @@ -63,10 +59,6 @@ void main() vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); outColor.a = 0.0; // yes, downstream atmospherics -#ifdef WATER_FOG - outColor = applyWaterFogView(pos.xyz, outColor); - outColor.a = 1.0; // no downstream atmo -#endif frag_data[0] = outColor; frag_data[1] = vec4(0.0,0.0,0.0,-1.0); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 58d573c724..9ebacd59c7 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -162,11 +162,7 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; -#ifdef WATER_FOG - color.rgb += diffuse_srgb.rgb * diffuse_srgb.a * 0.25; -#else color.rgb = mix(color.rgb, diffuse_linear.rgb, diffuse_linear.a); -#endif if (envIntensity > 0.0) { //add environmentmap -- cgit v1.2.3 From a3759b4910b94b3a375e16e605dc1a4f096f2256 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Fri, 6 Mar 2020 13:54:27 -0600 Subject: Fix for sky in wrong color space. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 54abd56625..1acb8d08eb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -154,7 +154,7 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; - color.rgb = mix(color.rgb, diffuse_linear.rgb, diffuse_linear.a); + color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); if (envIntensity > 0.0) { //add environmentmap diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 9ebacd59c7..6f5b0981f9 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -162,7 +162,7 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; - color.rgb = mix(color.rgb, diffuse_linear.rgb, diffuse_linear.a); + color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); if (envIntensity > 0.0) { //add environmentmap -- cgit v1.2.3 From f0a9b6c01bc1e348969e3c4ac1e929aefa538ea8 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Fri, 6 Mar 2020 14:27:46 -0600 Subject: Fix for sunlight having improper gamma curve for angular attenuation. Fix for lack of angular attenuation on ambient lighting on triangles facing away from sun. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 3 ++- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 1acb8d08eb..b38f488a1f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -82,6 +82,7 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); + da = pow(da, 1.0/1.3); vec4 diffuse_srgb = texture2DRect(diffuseRect, tc); vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); @@ -99,7 +100,7 @@ void main() calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, false); - float ambient = da; + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 6f5b0981f9..da78691861 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -86,7 +86,7 @@ void main() vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); - + da = pow(da, 1.0/1.3); vec4 diffuse_srgb = texture2DRect(diffuseRect, tc); vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); @@ -107,7 +107,7 @@ void main() calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); - float ambient = da; + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); -- cgit v1.2.3 From 0390dc2fec2afdc053f373813d419178a70b299c Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Fri, 6 Mar 2020 14:33:58 -0600 Subject: Fix for mismatch on angular attenuation between sunlight on opaque and transparent objects from last commit. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 5 +++-- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index e38eeab370..dc484317e9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -223,6 +223,7 @@ void main() float da = dot(norm.xyz, light_dir.xyz); da = clamp(da, -1.0, 1.0); + da = pow(da, 1.0/1.3); float final_da = da; final_da = clamp(final_da, 0.0f, 1.0f); @@ -231,7 +232,7 @@ void main() color.a = final_alpha; - float ambient = da; + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); @@ -262,7 +263,7 @@ vec3 post_atmo = color.rgb; vec4 light = vec4(0,0,0,0); color.rgb = scaleSoftClipFrag(color.rgb); - + //convert to linear before applying local lights color.rgb = srgb_to_linear(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index e4ebf0edee..d07de529ca 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -331,8 +331,9 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); + da = pow(da, 1.0/1.3); - float ambient = da; + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); -- cgit v1.2.3 From d32821ea5bf17c4de47b9ee03b43a20ae278dfe4 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 6 Mar 2020 17:20:46 -0800 Subject: SL-12574 Fix EEP cubemap not matching non-EEP for both ALM on and off --- .../newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- .../app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl | 2 +- indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl | 2 +- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index 4005d5064d..523e7f9e04 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -56,7 +56,7 @@ void main() color.rgb *= vertex_color.rgb; vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; - color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a); + color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a*0.75); // MAGIC NUMBER SL-12574; ALM: Off, Quality > Low color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index b38f488a1f..547a159f3a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -162,7 +162,7 @@ vec3 post_diffuse = color.rgb; vec3 env_vec = env_mat * refnormpersp; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; #if !defined(SUNLIGHT_KILL) - color = mix(color.rgb, reflected_color, envIntensity); + color = mix(color.rgb, reflected_color, envIntensity*0.75); // MAGIC NUMBER SL-12574; ALM: On, Quality <= Mid+ #endif } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl index 64ecf1f392..567811cd75 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl @@ -44,7 +44,7 @@ void fullbright_shiny_lighting() color.rgb *= vertex_color.rgb; vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; - color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a); + color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a*0.75); // MAGIC NUMBER SL-12574; ALM: Off, Quality > Low color.rgb = fullbrightShinyAtmosTransport(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl index 5bbd71002d..f621a00785 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl @@ -45,7 +45,7 @@ void shiny_lighting() color.rgb *= vertex_color.rgb; vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; - color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a); + color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a*0.75); // MAGIC NUMBER SL-12574; ALM: Off, Quality > Low color.rgb = atmosLighting(color.rgb); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index da78691861..15a3bc349a 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -169,7 +169,7 @@ vec3 post_diffuse = color.rgb; vec3 env_vec = env_mat * refnormpersp; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; #if !defined(SUNLIGHT_KILL) - color = mix(color.rgb, reflected_color, envIntensity); + color = mix(color.rgb, reflected_color, envIntensity*0.75); // MAGIC NUMBER SL-12574; ALM: On, Quality >= High #endif } -- cgit v1.2.3 From f9eada575bfa46a1da5aeaf27c73537a9b86aa76 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 10 Mar 2020 00:21:52 -0600 Subject: SL-12592, avoid light modulation of fullbright and preserve diffuse alpha component --- .../shaders/class1/deferred/materialF.glsl | 191 +++++++++++---------- 1 file changed, 96 insertions(+), 95 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d07de529ca..21a462e2db 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -1,28 +1,28 @@ -/** - * @file materialF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, 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$ - */ - +/** +* @file materialF.glsl +* +* $LicenseInfo:firstyear=2007&license=viewerlgpl$ +* Second Life Viewer Source Code +* Copyright (C) 2007, 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$ +*/ + /*[EXTRA_CODE_HERE]*/ //class1/deferred/materialF.glsl @@ -34,7 +34,7 @@ #define DIFFUSE_ALPHA_MODE_MASK 2 #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 -uniform float emissive_brightness; +uniform float emissive_brightness; // fullbright flag, 1.0 == fullbright, 0.0 otherwise uniform int sun_up_factor; #ifdef WATER_FOG @@ -52,13 +52,13 @@ vec3 linear_to_srgb(vec3 cs); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_color; +out vec4 frag_color; #else - #define frag_color gl_FragColor +#define frag_color gl_FragColor #endif #ifdef HAS_SUN_SHADOW - float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); #endif uniform samplerCube environmentMap; @@ -81,7 +81,7 @@ uniform vec2 screen_res; uniform vec4 light_position[8]; uniform vec3 light_direction[8]; -uniform vec4 light_attenuation[8]; +uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; float getAmbientClamp(); @@ -91,7 +91,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe vec3 col = vec3(0); //get light vector - vec3 lv = lp.xyz-v; + vec3 lv = lp.xyz - v; //get distance float dist = length(lv); @@ -103,21 +103,21 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe { //normalize light vector lv = normalize(lv); - + //distance attenuation - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + float dist_atten = clamp(1.0 - (dist - 1.0*(1.0 - fa)) / fa, 0.0, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0f; if (dist_atten <= 0.0) { - return col; + return col; } // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 - + //angular attenuation da *= dot(n, lv); @@ -126,9 +126,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float amb_da = ambiance; if (da >= 0) { - lit = max(da * dist_atten,0.0); + lit = max(da * dist_atten, 0.0); col = lit * light_col * diffuse; - amb_da += (da*0.5+0.5) * ambiance; + amb_da += (da*0.5 + 0.5) * ambiance; } amb_da += (da*da*0.5 + 0.5) * ambiance; amb_da *= dist_atten; @@ -140,19 +140,19 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe if (spec.a > 0.0) { //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); + vec3 h = normalize(lv + npos); float nh = dot(n, h); float nv = dot(n, npos); float vh = dot(npos, h); float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5; float gtdenom = 2 * nh; float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - + if (nh > 0.0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da); vec3 speccol = lit*scol*light_col.rgb*spec.rgb; speccol = clamp(speccol, vec3(0), vec3(1)); col += speccol; @@ -165,7 +165,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe } } - return max(col, vec3(0.0,0.0,0.0)); + return max(col, vec3(0.0, 0.0, 0.0)); } #else @@ -213,16 +213,9 @@ void main() { vec2 pos_screen = vary_texcoord0.xy; - vec4 diffuse_tap = texture2D(diffuseMap, vary_texcoord0.xy); - diffuse_tap.rgb *= vertex_color.rgb; - -//#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec4 diffuse_srgb = diffuse_tap; + vec4 diffuse_srgb = texture2D(diffuseMap, vary_texcoord0.xy); + diffuse_srgb.rgb *= vertex_color.rgb; vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); -/*#else - vec4 diffuse_linear = diffuse_tap; - vec4 diffuse_srgb = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a); -#endif*/ #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffuse_linear.a < minimum_alpha) @@ -248,15 +241,15 @@ void main() // convert sampled normal to tangent space normal norm = vec3(dot(norm, vary_mat0), - dot(norm, vary_mat1), - dot(norm, vary_mat2)); + dot(norm, vary_mat1), + dot(norm, vary_mat2)); #else norm = vary_normal; #endif norm = normalize(norm); - vec2 abnormal = encode_normal(norm); + vec2 abnormal = encode_normal(norm); vec4 final_color = vec4(diffuse_linear.rgb, 0.0); @@ -286,7 +279,7 @@ void main() float al = 0; #ifdef HAS_SPECULAR_MAP - if (emissive_brightness >= 1.0) + if (emissive_brightness >= 1.0) // ie, if fullbright { float ei = env_intensity*0.5 + 0.5; final_normal = vec4(abnormal, ei, 0.0); @@ -304,34 +297,43 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - { - //forward rendering, output just lit sRGBA - vec3 pos = vary_position; - float shadow = 1.0f; + //forward rendering, output just lit sRGBA + vec3 pos = vary_position; + + float shadow = 1.0f; #ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); + shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); #endif - spec = final_specular; + spec = final_specular; - float envIntensity = final_normal.z; + float envIntensity = final_normal.z; - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float bloom = 0.0; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; + float bloom = 0.0; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; - calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + if (emissive_brightness >= 1.0) // fullbright, skip lighting calculations + { + // just do atmos attenuation (ad hoc 60% factor to match release viewer) + color = atmosFragLighting(diffuse_srgb.rgb, additive, atten*0.6); + color = scaleSoftClipFrag(color); + al = diffuse_srgb.a; + } + else // not fullbright, calculate lighting + { vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); - da = pow(da, 1.0/1.3); + da = pow(da, 1.0 / 1.3); float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; @@ -341,16 +343,15 @@ void main() vec3 sun_contrib = min(da, shadow) * sunlit; #if !defined(AMBIENT_KILL) - color.rgb = amblit; - color.rgb *= ambient; + color = amblit; + color *= ambient; #endif #if !defined(SUNLIGHT_KILL) - color.rgb += sun_contrib; + color += sun_contrib; #endif + color *= diffuse_srgb.rgb; - color.rgb *= diffuse_srgb.rgb; - float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -358,19 +359,19 @@ void main() vec3 npos = -normalize(pos.xyz); //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(light_dir.xyz+npos); + vec3 h = normalize(light_dir.xyz + npos); float nh = dot(norm, h); float nv = dot(norm, npos); float vh = dot(npos, h); float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5; float gtdenom = 2 * nh; float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); if (nh > 0.0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da); vec3 sp = sun_contrib*scol / 6.0f; sp = clamp(sp, vec3(0), vec3(1)); bloom = dot(sp, sp) / 4.0; @@ -384,11 +385,11 @@ void main() { //add environmentmap vec3 env_vec = env_mat * refnormpersp; - + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; #if !defined(SUNLIGHT_KILL) - color = mix(color.rgb, reflected_color, envIntensity); + color = mix(color, reflected_color, envIntensity); #endif float cur_glare = max(reflected_color.r, reflected_color.g); cur_glare = max(cur_glare, reflected_color.b); @@ -401,14 +402,14 @@ void main() vec3 npos = normalize(-pos.xyz); - vec3 light = vec3(0,0,0); + vec3 light = vec3(0, 0, 0); //convert to linear before adding local lights - color.rgb = srgb_to_linear(color.rgb); + color = srgb_to_linear(color); #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w ); - LIGHT_LOOP(1) + LIGHT_LOOP(1) LIGHT_LOOP(2) LIGHT_LOOP(3) LIGHT_LOOP(4) @@ -416,25 +417,25 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) - glare = min(glare, 1.0); - al = max(diffuse_linear.a,glare)*vertex_color.a; + glare = min(glare, 1.0); + al = max(diffuse_linear.a, glare)*vertex_color.a; #if !defined(LOCAL_LIGHT_KILL) - color.rgb += light.rgb; + color += light; #endif -//convert to srgb as this color is being written post gamma correction - color.rgb = linear_to_srgb(color.rgb); - + //convert to srgb as this color is being written post gamma correction + color = linear_to_srgb(color); + } + #ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color.rgb, al)); - color.rgb = temp.rgb; - al = temp.a; + vec4 temp = applyWaterFogView(pos, vec4(color, al)); + color = temp.rgb; + al = temp.a; #endif - } - - frag_color = vec4(color, al); + // Don't allow alpha to exceed input value - SL-12592 + frag_color = vec4(color, min(al, diffuse_srgb.a)); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer -- cgit v1.2.3 From b1e2615cd80f27dac6712995edcc890df021041a Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 10 Mar 2020 12:35:12 -0700 Subject: SL-12171 Fix emissive mask being too bright post sRGB/Linear cleanup --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 21a462e2db..5999063ae5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -254,7 +254,7 @@ void main() vec4 final_color = vec4(diffuse_linear.rgb, 0.0); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = diffuse_linear.a; + final_color.a = diffuse_linear.a * 0.5; // SL-12171 #endif final_color.a = max(final_color.a, emissive_brightness); -- cgit v1.2.3 From c7f2712d9576c0122726104f74690c1ee5f94ae2 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Thu, 12 Mar 2020 16:52:48 -0600 Subject: SL-12784 restore vertex color alpha contribution --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 5999063ae5..553c2f3045 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -214,7 +214,7 @@ void main() vec2 pos_screen = vary_texcoord0.xy; vec4 diffuse_srgb = texture2D(diffuseMap, vary_texcoord0.xy); - diffuse_srgb.rgb *= vertex_color.rgb; + diffuse_srgb *= vertex_color; vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) -- cgit v1.2.3 From 0a0cfcf2ef92375f099ed91f009db1ebf2d410c0 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Fri, 13 Mar 2020 12:58:47 -0500 Subject: SL-12233 Fix for disagreement between fullbright implementations with ALM on and off. --- .../app_settings/shaders/class1/deferred/emissiveF.glsl | 1 - .../shaders/class1/deferred/fullbrightF.glsl | 6 ++---- .../app_settings/shaders/class1/deferred/materialF.glsl | 16 ++++++++++++---- .../shaders/class2/windlight/transportF.glsl | 9 +++++++-- .../shaders/class3/windlight/transportF.glsl | 9 +++++++-- 5 files changed, 28 insertions(+), 13 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl index 0ffca8515c..f0522850de 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl @@ -44,7 +44,6 @@ void main() float shadow = 1.0; vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; - color.rgb = pow(color.rgb, vec3(2.2)); color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index c104dc884f..46ec20c8b0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -79,11 +79,9 @@ void main() color.rgb = fogged.rgb; color.a = fogged.a; #else - color.rgb = srgb_to_linear(color.rgb); - color.rgb = fullbrightAtmosTransport(color.rgb); + color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); - color.rgb = linear_to_srgb(color.rgb); - color.a = final_alpha; + color.a = final_alpha; #endif frag_color.rgb = color.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 5999063ae5..a69653fe4e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -44,6 +44,9 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); 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 srgb_to_linear(vec3 cs); @@ -320,21 +323,26 @@ void main() vec3 atten; calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - + if (emissive_brightness >= 1.0) // fullbright, skip lighting calculations { - // just do atmos attenuation (ad hoc 60% factor to match release viewer) - color = atmosFragLighting(diffuse_srgb.rgb, additive, atten*0.6); - color = scaleSoftClipFrag(color); + color = fullbrightAtmosTransportFrag(diffuse_srgb.rgb, additive, atten); + color = fullbrightScaleSoftClip(color); + al = diffuse_srgb.a; } else // not fullbright, calculate lighting { vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); + //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); + //darken ambient for normals perpendicular to light vector so surfaces in shadow + // and facing away from light still have some definition to them. + // do NOT gamma correct this dot product so ambient lighting stays soft float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index 8fc5d750e3..f69d36f715 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -49,10 +49,15 @@ vec3 atmosTransport(vec3 light) return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } -vec3 fullbrightAtmosTransport(vec3 light) +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; - return atmosTransportFrag(light * 0.5, getAdditiveColor() * brightness, getAtmosAttenuation()); + return atmosTransportFrag(light * 0.5, additive * brightness, atten); +} + +vec3 fullbrightAtmosTransport(vec3 light) +{ + return fullbrightAtmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } vec3 fullbrightShinyAtmosTransport(vec3 light) diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index 18705f785f..aa7dbc39ce 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -49,10 +49,15 @@ vec3 atmosTransport(vec3 light) return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } -vec3 fullbrightAtmosTransport(vec3 light) +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { float brightness = dot(light.rgb, vec3(0.33333)); - return atmosTransportFrag(light * 0.5, getAdditiveColor() * (brightness * 0.5 + 0.5), getAtmosAttenuation()); + return atmosTransportFrag(light * 0.5, additive * (brightness * 0.5 + 0.5), atten); +} + +vec3 fullbrightAtmosTransport(vec3 light) +{ + return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); } vec3 fullbrightShinyAtmosTransport(vec3 light) -- cgit v1.2.3 From 744872b43d4b538a828dad116c46eed3d6d35436 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 13 Mar 2020 11:46:13 -0700 Subject: SL-12850 --- .../newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 6 +++--- .../newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 547a159f3a..69a694a6cd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -154,8 +154,6 @@ vec3 post_diffuse = color.rgb; } vec3 post_spec = color.rgb; - - color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); if (envIntensity > 0.0) { //add environmentmap @@ -165,7 +163,9 @@ vec3 post_diffuse = color.rgb; color = mix(color.rgb, reflected_color, envIntensity*0.75); // MAGIC NUMBER SL-12574; ALM: On, Quality <= Mid+ #endif } - + else + color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); + vec3 post_env = color.rgb; if (norm.w < 1) diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 15a3bc349a..63b0f0b5c8 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -161,8 +161,6 @@ vec3 post_diffuse = color.rgb; } vec3 post_spec = color.rgb; - - color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); if (envIntensity > 0.0) { //add environmentmap @@ -170,9 +168,12 @@ vec3 post_diffuse = color.rgb; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; #if !defined(SUNLIGHT_KILL) color = mix(color.rgb, reflected_color, envIntensity*0.75); // MAGIC NUMBER SL-12574; ALM: On, Quality >= High +//color.rgb = reflected_color.rgb; #endif } - + else + color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); + vec3 post_env = color.rgb; if (norm.w < 1) -- cgit v1.2.3 From bedbbdc5c39a4ae684c0b8e569dae4bb0d7b314c Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 13 Mar 2020 12:35:12 -0700 Subject: SL-12850 remove debug --- indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 63b0f0b5c8..a1366eec01 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -168,7 +168,6 @@ vec3 post_diffuse = color.rgb; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; #if !defined(SUNLIGHT_KILL) color = mix(color.rgb, reflected_color, envIntensity*0.75); // MAGIC NUMBER SL-12574; ALM: On, Quality >= High -//color.rgb = reflected_color.rgb; #endif } else -- cgit v1.2.3 From 3792c3c7debb428d9727136afaa8b16d312abd42 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 13 Mar 2020 12:37:14 -0700 Subject: SL-12850 Adhere to coding standard --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 ++ indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 2 ++ 2 files changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 69a694a6cd..20ac78947b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -164,7 +164,9 @@ vec3 post_diffuse = color.rgb; #endif } else + { color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); + } vec3 post_env = color.rgb; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index a1366eec01..9c7a4df767 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -171,7 +171,9 @@ vec3 post_diffuse = color.rgb; #endif } else + { color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); + } vec3 post_env = color.rgb; -- cgit v1.2.3 From 09b13b3981f121f20674b874f47f96bef2ac73ce Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Fri, 13 Mar 2020 14:59:11 -0600 Subject: SL-12784 disambiguate vertex_color.a of 0 --- .../app_settings/shaders/class1/deferred/materialF.glsl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index ca11f58888..a8a5cc22db 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -217,7 +217,16 @@ void main() vec2 pos_screen = vary_texcoord0.xy; vec4 diffuse_srgb = texture2D(diffuseMap, vary_texcoord0.xy); - diffuse_srgb *= vertex_color; + diffuse_srgb.rgb *= vertex_color.rgb; + + // For some reason the Transparency slider sets vertex_color.a to 0.0 both for + // fully opaque and for fully transparent objects. This code assumes the 0 alpha + // is always from the opaque end of the scale. TODO: Remove the conditional once + // the root cause of the slider ambiguity is fixed. + if (vertex_color.a > 0.0) + { + diffuse_srgb.a *= vertex_color.a; + } vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) -- cgit v1.2.3 From 5f0303eea5a30c914b61d5de6ade3697e551f9c6 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Fri, 13 Mar 2020 16:39:58 -0500 Subject: SL-12005 Fix for projectors getting brighter when switching to single light shader. --- indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 2216afe609..694b19cdfb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -177,9 +177,8 @@ void main() float da = dot(norm, lv); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - // SL-12005 Projector light pops as we get closer, more objectionable than being in wrong color space. - // We can't switch to linear here unless we do it everywhere - //diff_tex.rgb = srgb_to_linear(diff_tex.rgb); + //light shaders output linear and are gamma corrected later in postDeferredGammaCorrectF.glsl + diff_tex.rgb = srgb_to_linear(diff_tex.rgb); vec4 spec = texture2DRect(specularRect, frag.xy); @@ -274,6 +273,7 @@ void main() } #endif + //col.r = 1.0; frag_color.rgb = col; frag_color.a = 0.0; } -- cgit v1.2.3 From 8c1b9d3e7a194c106ee79067e3136c37ea7e84e1 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Mon, 16 Mar 2020 12:10:34 -0500 Subject: Add missing fullbrightAtmosTransportFrag stub. --- indra/newview/app_settings/shaders/class1/windlight/transportF.glsl | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl index 79d8d11b32..a937d9fa99 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/transportF.glsl @@ -37,6 +37,12 @@ vec3 atmosTransport(vec3 light) return light; } +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) +{ + /* stub function for fallback compatibility on class1 hardware */ + return light; +} + vec3 fullbrightAtmosTransport(vec3 light) { /* stub function for fallback compatibility on class1 hardware */ -- cgit v1.2.3 From 6dbc72df774a99cd80c4a690e7d03017d39005e9 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 17 Mar 2020 13:46:52 -0600 Subject: SL-10449 remove soft gamma adjustment that breaks Mac GLSL compiler --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a8a5cc22db..f1b13c8825 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -336,7 +336,10 @@ void main() if (emissive_brightness >= 1.0) // fullbright, skip lighting calculations { color = fullbrightAtmosTransportFrag(diffuse_srgb.rgb, additive, atten); - color = fullbrightScaleSoftClip(color); + // 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); al = diffuse_srgb.a; } -- cgit v1.2.3 From ff683a7127d299694a8fece5772f3656d9214edc Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Wed, 18 Mar 2020 16:30:20 -0600 Subject: SL-12865, add bias to alpha mask values to avoid 8-bit acne --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f1b13c8825..4198053c99 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -230,7 +230,10 @@ void main() vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - if (diffuse_linear.a < minimum_alpha) + + // Comparing floats cast from 8-bit values, produces acne right at the 8-bit transition points + float bias = 0.001953125; // 1/512, or half an 8-bit quantization + if (diffuse_linear.a < minimum_alpha-bias) { discard; } -- cgit v1.2.3 From bb99e50b2617a67fe65a92338363c76ec400f033 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 18 Mar 2020 23:21:32 -0700 Subject: SL-12574 Add note about duplicated procedurally generated sky texture --- indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl | 4 ++++ indra/newview/app_settings/shaders/class1/deferred/skyV.glsl | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 8e90c1481f..bc51d25309 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -67,6 +67,10 @@ uniform vec4 cloud_color; uniform float cloud_scale; +// NOTE: Keep these in sync! +// indra\newview\app_settings\shaders\class1\deferred\skyV.glsl +// indra\newview\app_settings\shaders\class1\deferred\cloudsV.glsl +// indra\newview\lllegacyatmospherics.cpp void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 2cd660ab79..ead754ec76 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -57,6 +57,10 @@ uniform float sun_moon_glow_factor; uniform vec4 cloud_color; +// NOTE: Keep these in sync! +// indra\newview\app_settings\shaders\class1\deferred\skyV.glsl +// indra\newview\app_settings\shaders\class1\deferred\cloudsV.glsl +// indra\newview\lllegacyatmospherics.cpp void main() { -- cgit v1.2.3 From 4bffb6e79372c1aef5d0124943c5ae0edc790bf0 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 19 Mar 2020 00:57:18 -0700 Subject: SL-11589 Fix clouds drooping below horizon --- indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 8e90c1481f..fb405d4f1a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -87,6 +87,7 @@ void main() } else { + altitude_blend_factor = 0; // SL-11589 Fix clouds drooping below horizon P *= (-32000. / P.y); } -- cgit v1.2.3 From cbc3c51daf5b6f7ae483fac8522095dea31d582d Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 19 Mar 2020 01:09:12 -0700 Subject: SL-11589 Remove redundant setting vary_texcoord0, cleanup grouping --- .../shaders/class1/deferred/cloudsV.glsl | 24 ++++++++++------------ 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index fb405d4f1a..1ade2c0876 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -73,7 +73,18 @@ void main() // World / view / projection gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + // Texture coords vary_texcoord0 = texcoord0; + vary_texcoord0.xy -= 0.5; + vary_texcoord0.xy /= cloud_scale; + vary_texcoord0.xy += 0.5; + + vary_texcoord1 = vary_texcoord0; + vary_texcoord1.x += lightnorm.x * 0.0125; + vary_texcoord1.y += lightnorm.z * 0.0125; + + vary_texcoord2 = vary_texcoord0 * 16.; + vary_texcoord3 = vary_texcoord1 * 16.; // Get relative position vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); @@ -176,19 +187,6 @@ void main() vary_CloudDensity = 2. * (cloud_shadow - 0.25); - // Texture coords - vary_texcoord0 = texcoord0; - vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; - vary_texcoord0.xy += 0.5; - - vary_texcoord1 = vary_texcoord0; - vary_texcoord1.x += lightnorm.x * 0.0125; - vary_texcoord1.y += lightnorm.z * 0.0125; - - vary_texcoord2 = vary_texcoord0 * 16.; - vary_texcoord3 = vary_texcoord1 * 16.; - // Combine these to minimize register use vary_CloudColorAmbient += oHazeColorBelowCloud; -- cgit v1.2.3 From 3e472948db34e8efc905b5b50249f4587ba1507f Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Fri, 20 Mar 2020 16:50:37 -0500 Subject: WIP - Make EEP match production. --- .../shaders/class1/deferred/fullbrightF.glsl | 2 - .../shaders/class1/deferred/fullbrightShinyF.glsl | 4 +- .../shaders/class1/deferred/materialF.glsl | 293 +++++++++------------ .../shaders/class1/deferred/softenLightF.glsl | 83 +++--- .../shaders/class1/deferred/waterF.glsl | 9 +- .../shaders/class1/environment/terrainWaterF.glsl | 10 +- .../shaders/class1/environment/waterF.glsl | 173 ++++++------ .../shaders/class2/deferred/softenLightF.glsl | 14 +- .../shaders/class2/windlight/atmosphericsV.glsl | 128 ++++++++- .../shaders/class2/windlight/transportF.glsl | 17 +- 10 files changed, 391 insertions(+), 342 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 46ec20c8b0..57420158ca 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -79,8 +79,6 @@ void main() color.rgb = fogged.rgb; color.a = fogged.a; #else - color.rgb = fullbrightAtmosTransport(color.rgb); - color.rgb = fullbrightScaleSoftClip(color.rgb); color.a = final_alpha; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index 523e7f9e04..af903eeda8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -51,12 +51,12 @@ void main() #else vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); #endif - + color.rgb *= vertex_color.rgb; vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; - color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a*0.75); // MAGIC NUMBER SL-12574; ALM: Off, Quality > Low + color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a); color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a8a5cc22db..85d664ea1f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -216,98 +216,63 @@ void main() { vec2 pos_screen = vary_texcoord0.xy; - vec4 diffuse_srgb = texture2D(diffuseMap, vary_texcoord0.xy); - diffuse_srgb.rgb *= vertex_color.rgb; - - // For some reason the Transparency slider sets vertex_color.a to 0.0 both for - // fully opaque and for fully transparent objects. This code assumes the 0 alpha - // is always from the opaque end of the scale. TODO: Remove the conditional once - // the root cause of the slider ambiguity is fixed. - if (vertex_color.a > 0.0) - { - diffuse_srgb.a *= vertex_color.a; - } - vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); + diffcol.rgb *= vertex_color.rgb; #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - if (diffuse_linear.a < minimum_alpha) + if (diffcol.a < minimum_alpha) { discard; } #endif -#ifdef HAS_SPECULAR_MAP +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vec3 gamma_diff = diffcol.rgb; + diffcol.rgb = srgb_to_linear(diffcol.rgb); +#endif + +#if HAS_SPECULAR_MAP != 0 vec4 spec = texture2D(specularMap, vary_texcoord2.xy); spec.rgb *= specular_color.rgb; #else vec4 spec = vec4(specular_color.rgb, 1.0); #endif - vec3 norm = vec3(0); - float bmap_specular = 1.0; +#if HAS_NORMAL_MAP + vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); -#ifdef HAS_NORMAL_MAP - vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy); - norm = (bump_sample.xyz * 2) - vec3(1); - bmap_specular = bump_sample.w; - - // convert sampled normal to tangent space normal - norm = vec3(dot(norm, vary_mat0), - dot(norm, vary_mat1), - dot(norm, vary_mat2)); + norm.xyz = norm.xyz * 2 - 1; + + vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2)); #else - norm = vary_normal; + vec4 norm = vec4(0,0,0,1.0); + vec3 tnorm = vary_normal; #endif - norm = normalize(norm); - - vec2 abnormal = encode_normal(norm); + norm.xyz = normalize(tnorm.xyz); - vec4 final_color = vec4(diffuse_linear.rgb, 0.0); - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = diffuse_linear.a * 0.5; // SL-12171 -#endif + vec2 abnormal = encode_normal(norm.xyz); - final_color.a = max(final_color.a, emissive_brightness); - - // Texture - // [x] Full Bright (emissive_brightness >= 1.0) - // Shininess (specular) - // [X] Texture - // Environment Intensity = 1 - // NOTE: There are two shaders that are used depending on the EI byte value: - // EI = 0 fullbright - // EI > 0 .. 255 material - // When it is passed to us it is normalized. - // We can either modify the output environment intensity - // OR - // adjust the final color via: - // final_color *= 0.666666; - // We don't remap the environment intensity but adjust the final color to closely simulate what non-EEP is doing. - vec4 final_normal = vec4(abnormal, env_intensity, 0.0); - - vec3 color = vec3(0.0); - float al = 0; + vec4 final_color = diffcol; -#ifdef HAS_SPECULAR_MAP - if (emissive_brightness >= 1.0) // ie, if fullbright - { - float ei = env_intensity*0.5 + 0.5; - final_normal = vec4(abnormal, ei, 0.0); - } +#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) + final_color.a = emissive_brightness; +#else + final_color.a = max(final_color.a, emissive_brightness); #endif vec4 final_specular = spec; - - final_specular.a = specular_color.a; - -#ifdef HAS_SPECULAR_MAP - final_specular.a *= bmap_specular; - final_normal.z *= spec.a; + +#if HAS_SPECULAR_MAP != 0 + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); + final_specular.a = specular_color.a * norm.a; +#else + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); + final_specular.a = specular_color.a; #endif - #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) //forward rendering, output just lit sRGBA @@ -316,13 +281,15 @@ void main() float shadow = 1.0f; #ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen); + 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); + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float bloom = 0.0; @@ -333,117 +300,118 @@ void main() calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - if (emissive_brightness >= 1.0) // fullbright, skip lighting calculations - { - color = fullbrightAtmosTransportFrag(diffuse_srgb.rgb, additive, atten); - color = fullbrightScaleSoftClip(color); - al = diffuse_srgb.a; - } - else // not fullbright, calculate lighting - { - vec3 refnormpersp = normalize(reflect(pos.xyz, norm)); - - //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); - - //darken ambient for normals perpendicular to light vector so surfaces in shadow - // and facing away from light still have some definition to them. - // do NOT gamma correct this dot product so ambient lighting stays soft - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - - vec3 sun_contrib = min(da, shadow) * sunlit; - -#if !defined(AMBIENT_KILL) - color = amblit; - color *= ambient; -#endif + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); -#if !defined(SUNLIGHT_KILL) - color += sun_contrib; -#endif - color *= diffuse_srgb.rgb; + //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); - float glare = 0.0; + color = amblit; - if (spec.a > 0.0) // specular reflection - { - vec3 npos = -normalize(pos.xyz); + //darken ambient for normals perpendicular to light vector so surfaces in shadow + // and facing away from light still have some definition to them. + // do NOT gamma correct this dot product so ambient lighting stays soft + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(light_dir.xyz + npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5; + vec3 sun_contrib = min(da, shadow) * sunlit; + + color *= ambient; - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + color += sun_contrib; - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da); - vec3 sp = sun_contrib*scol / 6.0f; - sp = clamp(sp, vec3(0), vec3(1)); - bloom = dot(sp, sp) / 4.0; -#if !defined(SUNLIGHT_KILL) - color += sp * spec.rgb; -#endif - } - } + color *= gamma_diff.rgb; - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; + float glare = 0.0; - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; + if (spec.a > 0.0) // specular reflection + { +#if 1 //EEP -#if !defined(SUNLIGHT_KILL) - color = mix(color, reflected_color, envIntensity); -#endif - float cur_glare = max(reflected_color.r, reflected_color.g); - cur_glare = max(cur_glare, reflected_color.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; + vec3 npos = -normalize(pos.xyz); + + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(light_dir.xyz + npos); + float nh = dot(norm.xyz, h); + float nv = dot(norm.xyz, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da); + vec3 sp = sun_contrib*scol / 6.0f; + sp = clamp(sp, vec3(0), vec3(1)); + bloom = dot(sp, sp) / 4.0; + color += sp * spec.rgb; } +#else // PRODUCTION + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.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; +#endif + } - color = atmosFragLighting(color, additive, atten); - color = scaleSoftClipFrag(color); + color = mix(color.rgb, diffcol.rgb, diffuse.a); + + if (envIntensity > 0.0) + { + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; - vec3 npos = normalize(-pos.xyz); + vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - vec3 light = vec3(0, 0, 0); + color = mix(color, reflected_color, envIntensity); - //convert to linear before adding local lights - color = srgb_to_linear(color); + float cur_glare = max(reflected_color.r, reflected_color.g); + cur_glare = max(cur_glare, reflected_color.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; + } -#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w ); + color = atmosFragLighting(color, additive, atten); + color = scaleSoftClipFrag(color); - LIGHT_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) + //convert to linear before adding local lights + color = srgb_to_linear(color); - glare = min(glare, 1.0); - al = max(diffuse_linear.a, glare)*vertex_color.a; + vec3 npos = normalize(-pos.xyz); -#if !defined(LOCAL_LIGHT_KILL) - color += light; -#endif + 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 ); - //convert to srgb as this color is being written post gamma correction - color = linear_to_srgb(color); - } + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) + + color += light; + + glare = min(glare, 1.0); + float al = max(diffcol.a, glare)*vertex_color.a; + + //convert to srgb as this color is being written post gamma correction + color = linear_to_srgb(color); #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(color, al)); @@ -451,13 +419,12 @@ void main() al = temp.a; #endif - // Don't allow alpha to exceed input value - SL-12592 - frag_color = vec4(color, min(al, diffuse_srgb.a)); + frag_color = vec4(color, al); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer // deferred path - frag_data[0] = vec4(linear_to_srgb(final_color.rgb), final_color.a); //gbuffer is sRGB + frag_data[0] = final_color; //gbuffer is sRGB frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 20ac78947b..5b94baf7e6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -63,6 +63,8 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou float getAmbientClamp(); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); +vec3 fullbrightScaleSoftClip(vec3 light); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); @@ -81,11 +83,13 @@ void main() norm.xyz = getNorm(tc); vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); - da = pow(da, 1.0/1.3); + float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); + //da = pow(da, 1.0/1.3); + + vec4 diffuse = texture2DRect(diffuseRect, tc); - vec4 diffuse_srgb = texture2DRect(diffuseRect, tc); - vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); + //convert to gamma space + //diffuse.rgb = linear_to_srgb(diffuse.rgb); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 color = vec3(0); @@ -100,34 +104,27 @@ void main() calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, false); + color.rgb = amblit; + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); - vec3 sun_contrib = da * sunlit; - -#if !defined(AMBIENT_KILL) - color.rgb = amblit; color.rgb *= ambient; -#endif -vec3 post_ambient = color.rgb; + vec3 sun_contrib = da * sunlit; -#if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; -#endif - -vec3 post_sunlight = color.rgb; - color.rgb *= diffuse_srgb.rgb; - -vec3 post_diffuse = color.rgb; + color.rgb *= diffuse.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection { + +#if 1 //EEP vec3 npos = -normalize(pos.xyz); //vec3 ref = dot(pos+lv, norm); @@ -140,71 +137,55 @@ vec3 post_diffuse = color.rgb; float gtdenom = 2 * nh; float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - + if (nh > 0.0) { float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 sp = sun_contrib*scontrib / 6.0; sp = clamp(sp, vec3(0), vec3(1)); bloom += dot(sp, sp) / 4.0; -#if !defined(SUNLIGHT_KILL) color += sp * spec.rgb; -#endif } +#else //PRODUCTION + float sa = dot(refnormpersp, light_dir.xyz); + vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + color.rgb += spec_contrib; +#endif + } - vec3 post_spec = color.rgb; + color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; -#if !defined(SUNLIGHT_KILL) - color = mix(color.rgb, reflected_color, envIntensity*0.75); // MAGIC NUMBER SL-12574; ALM: On, Quality <= Mid+ -#endif + color = mix(color.rgb, reflected_color, envIntensity); } - else - { - color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); - } - -vec3 post_env = color.rgb; - - if (norm.w < 1) + + if (norm.w < 0.5) { -#if !defined(SUNLIGHT_KILL) - color = atmosFragLighting(color, additive, atten); - color = scaleSoftClipFrag(color); -#endif + color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a); + color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a); } -vec3 post_atmo = color.rgb; - #ifdef WATER_FOG vec4 fogged = applyWaterFogView(pos.xyz,vec4(color, bloom)); color = fogged.rgb; bloom = fogged.a; #endif -// srgb colorspace debuggables -//color.rgb = amblit; -//color.rgb = sunlit; -//color.rgb = post_ambient; -//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; - } // linear debuggables //color.rgb = vec3(final_da); //color.rgb = vec3(ambient); //color.rgb = vec3(scol); -//color.rgb = diffuse_linear.rgb; +//color.rgb = diffuse_srgb.rgb; // convert to linear as fullscreen lights need to sum in linear colorspace // and will be gamma (re)corrected downstream... diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index b86867c460..ceb4b8033d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -164,14 +164,15 @@ void main() color.rgb += spec * specular; - //color.rgb = atmosTransport(color.rgb); + color.rgb = atmosTransport(color.rgb); color.rgb = scaleSoftClip(color.rgb); color.a = spec * sunAngle2; vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - frag_data[0] = vec4(color.rgb, color); // diffuse - frag_data[1] = vec4(0); // speccolor, spec - frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.0, 0);// normalxy, 0, 0 + //frag_data[0] = color; + frag_data[0] = color; + frag_data[1] = vec4(0); // speccolor, spec + frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 0, 0 } diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl index bbfec3b532..e53bb46177 100644 --- a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl @@ -39,6 +39,8 @@ uniform sampler2D detail_2; uniform sampler2D detail_3; uniform sampler2D alpha_ramp; +vec3 atmosLighting(vec3 light); + vec4 applyWaterFog(vec4 color); void main() @@ -55,10 +57,10 @@ void main() float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); - - outColor.rgb *= vertex_color.rgb; + + /// Add WL Components + outColor.rgb = atmosLighting(outColor.rgb * vertex_color.rgb); + outColor = applyWaterFog(outColor); - frag_color = outColor; } - diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index b3ae64bd82..d1e6c7da1a 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -1,5 +1,5 @@ /** - * @file class1/environment/waterF.glsl + * @file waterF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -32,7 +32,7 @@ out vec4 frag_color; vec3 scaleSoftClip(vec3 inColor); vec3 atmosTransport(vec3 inColor); -uniform sampler2D bumpMap; +uniform sampler2D bumpMap; uniform sampler2D bumpMap2; uniform float blend_factor; uniform sampler2D screenTex; @@ -50,7 +50,7 @@ uniform vec3 normScale; uniform float fresnelScale; uniform float fresnelOffset; uniform float blurMultiplier; -uniform int water_edge; + //bigWave is (refCoord.w, view.w); VARYING vec4 refCoord; @@ -59,27 +59,27 @@ VARYING vec4 view; vec3 BlendNormal(vec3 bump1, vec3 bump2) { - //vec3 normal = bump1.xyz * vec3( 2.0, 2.0, 2.0) - vec3(1.0, 1.0, 0.0); - //vec3 normal2 = bump2.xyz * vec3(-2.0, -2.0, 2.0) + vec3(1.0, 1.0, -1.0); - //vec3 n = normalize(normal * dot(normal, normal2) - (normal2 * normal.z)); - vec3 n = normalize(mix(bump1, bump2, blend_factor)); + vec3 n = mix(bump1, bump2, blend_factor); return n; } + void main() { - vec4 color; - - float dist = length(view.xy); - - //normalize view vector - vec3 viewVec = normalize(view.xyz); - - //get wave normals + vec4 color; + + float dist = length(view.xy); + + //normalize view vector + vec3 viewVec = normalize(view.xyz); + + //get wave normals + //get wave normals vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; @@ -88,80 +88,81 @@ void main() vec3 wave2 = BlendNormal(wave2_a, wave2_b); vec3 wave3 = BlendNormal(wave3_a, wave3_b); - //get base fresnel components - - vec3 df = vec3( - dot(viewVec, wave1), - dot(viewVec, (wave2 + wave3) * 0.5), - dot(viewVec, wave3) - ) * fresnelScale + fresnelOffset; - df *= df; - - vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; - - float dist2 = dist; - dist = max(dist, 5.0); - - float dmod = sqrt(dist); - - vec2 dmod_scale = vec2(dmod*dmod, dmod); - - //get reflected color - vec2 refdistort1 = wave1.xy*normScale.x; - vec2 refvec1 = distort+refdistort1/dmod_scale; - vec4 refcol1 = texture2D(refTex, refvec1); - - vec2 refdistort2 = wave2.xy*normScale.y; - vec2 refvec2 = distort+refdistort2/dmod_scale; - vec4 refcol2 = texture2D(refTex, refvec2); - - vec2 refdistort3 = wave3.xy*normScale.z; - vec2 refvec3 = distort+refdistort3/dmod_scale; - vec4 refcol3 = texture2D(refTex, refvec3); - - vec4 refcol = refcol1 + refcol2 + refcol3; - float df1 = df.x + df.y + df.z; - df1 *= 0.666666f; - refcol *= df1; - - vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; - - wavef.z *= max(-viewVec.z, 0.1); - wavef = normalize(wavef); - - float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; - - vec2 refdistort4 = wavef.xy*0.125; - refdistort4.y -= abs(refdistort4.y); - vec2 refvec4 = distort+refdistort4/dmod; - float dweight = min(dist2*blurMultiplier, 1.0); - vec4 baseCol = texture2D(refTex, refvec4); - refcol = mix(baseCol*df2, refcol, dweight); - - //get specular component - float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); - - //harden specular - spec = pow(spec, 128.0); - - //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale*0.16/max(dmod*df1, 1.0); - - vec4 fb = texture2D(screenTex, distort2); - - //mix with reflection - // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.9999999); - color.rgb += spec * specular; - - color.a = spec * sunAngle2; - - //color.rgb = atmosTransport(color.rgb); + + //get base fresnel components + + vec3 df = vec3( + dot(viewVec, wave1), + dot(viewVec, (wave2 + wave3) * 0.5), + dot(viewVec, wave3) + ) * fresnelScale + fresnelOffset; + df *= df; + + vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; + + float dist2 = dist; + dist = max(dist, 5.0); + + float dmod = sqrt(dist); + + vec2 dmod_scale = vec2(dmod*dmod, dmod); + + //get reflected color + vec2 refdistort1 = wave1.xy*normScale.x; + vec2 refvec1 = distort+refdistort1/dmod_scale; + vec4 refcol1 = texture2D(refTex, refvec1); + + vec2 refdistort2 = wave2.xy*normScale.y; + vec2 refvec2 = distort+refdistort2/dmod_scale; + vec4 refcol2 = texture2D(refTex, refvec2); + + vec2 refdistort3 = wave3.xy*normScale.z; + vec2 refvec3 = distort+refdistort3/dmod_scale; + vec4 refcol3 = texture2D(refTex, refvec3); + + vec4 refcol = refcol1 + refcol2 + refcol3; + float df1 = df.x + df.y + df.z; + refcol *= df1 * 0.333; + + vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; + + wavef.z *= max(-viewVec.z, 0.1); + wavef = normalize(wavef); + + float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; + + vec2 refdistort4 = wavef.xy*0.125; + refdistort4.y -= abs(refdistort4.y); + vec2 refvec4 = distort+refdistort4/dmod; + float dweight = min(dist2*blurMultiplier, 1.0); + vec4 baseCol = texture2D(refTex, refvec4); + refcol = mix(baseCol*df2, refcol, dweight); + + //get specular component + float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); + + //harden specular + spec = pow(spec, 128.0); + + //figure out distortion vector (ripply) + vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); + + vec4 fb = texture2D(screenTex, distort2); + + //mix with reflection + // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug + color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); + color.rgb += spec * specular; + + color.rgb = atmosTransport(color.rgb); color.rgb = scaleSoftClip(color.rgb); + color.a = spec * sunAngle2; + + frag_color = color; #if defined(WATER_EDGE) gl_FragDepth = 0.9999847f; #endif - - frag_color = color; + } + diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 9c7a4df767..0658b3ede5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -63,6 +63,8 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou float getAmbientClamp(); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); +vec3 fullbrightScaleSoftClip(vec3 light); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); @@ -162,6 +164,8 @@ vec3 post_diffuse = color.rgb; vec3 post_spec = color.rgb; + color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); + if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; @@ -170,19 +174,15 @@ vec3 post_diffuse = color.rgb; color = mix(color.rgb, reflected_color, envIntensity*0.75); // MAGIC NUMBER SL-12574; ALM: On, Quality >= High #endif } - else - { - color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); - } vec3 post_env = color.rgb; - if (norm.w < 1) + if (norm.w < 0.5) { #if !defined(SUNLIGHT_KILL) vec3 p = normalize(pos.xyz); - color = atmosFragLighting(color, additive, atten); - color = scaleSoftClipFrag(color); + color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse_srgb.a); + color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse_srgb.a); #endif } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index a4bd0d566b..445d7c6352 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -32,20 +32,124 @@ void setPositionEye(vec3 v); vec3 getAdditiveColor(); -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +//VARYING vec4 vary_CloudUVs; +//VARYING float vary_CloudDensity; + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; +//uniform vec4 camPosWorld; + +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 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 vec4 glow; void calcAtmospherics(vec3 inPositionEye) { + + vec3 P = inPositionEye; + setPositionEye(P); + + //(TERRAIN) limit altitude + if (P.y > max_y) P *= (max_y / P.y); + if (P.y < -max_y) P *= (-max_y / P.y); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(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 + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + setAtmosAttenuation(temp1.rgb); + //vary_AtmosAttenuation = distance_multiplier / 10000.; + //vary_AtmosAttenuation = density_multiplier * 100.; + //vary_AtmosAttenuation = vec4(Plen / 100000., 0., 0., 1.); + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + //haze color + setAdditiveColor( + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient))); + + //brightness of surface both sunlight and ambient + setSunlitColor(vec3(sunlight * .5)); + setAmblitColor(vec3(tmpAmbient * .25)); + setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); + + // vary_SunlitColor = vec3(0); + // vary_AmblitColor = vec3(0); + // vary_AdditiveColor = vec4(Pn, 1.0); + + /* + const float cloudShadowScale = 100.; + // Get cloud uvs for shadowing + vec3 cloudPos = inPositionEye + camPosWorld - cloudShadowScale / 2.; + vary_CloudUVs.xy = cloudPos.xz / cloudShadowScale; + + // We can take uv1 and multiply it by (TerrainSpan / CloudSpan) +// cloudUVs *= (((worldMaxZ - worldMinZ) * 20) /40000.); + vary_CloudUVs *= (10000./40000.); - vec3 P = inPositionEye; - setPositionEye(P); - vec3 tmpsunlit = vec3(1); - vec3 tmpamblit = vec3(1); - vec3 tmpaddlit = vec3(1); - vec3 tmpattenlit = vec3(1); - calcAtmosphericVars(inPositionEye, vec3(0), 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, false); - setSunlitColor(tmpsunlit); - setAmblitColor(tmpamblit); - setAdditiveColor(tmpaddlit); - setAtmosAttenuation(tmpattenlit); + // Offset by sun vector * (CloudAltitude / CloudSpan) + vary_CloudUVs.x += tmpLightnorm.x / tmpLightnorm.y * (3000./40000.); + vary_CloudUVs.y += tmpLightnorm.z / tmpLightnorm.y * (3000./40000.); + */ } diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index f69d36f715..b0cf9b0002 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -34,14 +34,9 @@ uniform int no_atmo; vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - if (no_atmo == 1) - { - return light * 2.0; - } - // fullbright responds minimally to atmos scatter effects - light *= min(15.0 * atten.r, 1.0); - light += (0.1 * additive); - return light * 2.0; + light *= atten.r; + light += additive * 2.0; + return light; } vec3 atmosTransport(vec3 light) @@ -52,7 +47,7 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; - return atmosTransportFrag(light * 0.5, additive * brightness, atten); + return mix(atmosTransport(light.rgb), light.rgb + additive, brightness * brightness); } vec3 fullbrightAtmosTransport(vec3 light) @@ -62,6 +57,6 @@ vec3 fullbrightAtmosTransport(vec3 light) vec3 fullbrightShinyAtmosTransport(vec3 light) { - float brightness = dot(light.rgb * 0.5, vec3(0.33333)) + 0.1; - return atmosTransportFrag(light * 0.5, getAdditiveColor() * (brightness * brightness), getAtmosAttenuation()); + float brightness = dot(light.rgb, vec3(0.33333)); + return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness); } -- cgit v1.2.3 From 3d22273726ab4d40f2eb9afc5ceeac37471a9dfa Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Tue, 24 Mar 2020 11:22:01 -0500 Subject: Fix for bad fullbright shiny shininess values and inconsistency between materialF and fullbrightShinyF --- .../shaders/class1/deferred/fullbrightShinyF.glsl | 26 +++- .../shaders/class1/deferred/fullbrightShinyV.glsl | 4 +- .../shaders/class2/windlight/atmosphericsV.glsl | 137 +++------------------ 3 files changed, 42 insertions(+), 125 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index af903eeda8..bd0ad3bce8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -38,12 +38,20 @@ uniform sampler2D diffuseMap; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; VARYING vec3 vary_texcoord1; +VARYING vec4 vary_position; uniform samplerCube environmentMap; vec3 fullbrightShinyAtmosTransport(vec3 light); +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 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); + + void main() { #ifdef HAS_DIFFUSE_LOOKUP @@ -52,20 +60,28 @@ void main() vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); #endif - color.rgb *= vertex_color.rgb; + vec3 pos = vary_position.xyz/vary_position.w; + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false); vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; - color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a); + float env_intensity = vertex_color.a; + color.rgb = mix(color.rgb, envColor.rgb, env_intensity); - color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); + //color.rgb = srgb_to_linear(color.rgb); - color.rgb = fullbrightShinyAtmosTransport(color.rgb); + color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); color.rgb = fullbrightScaleSoftClip(color.rgb); color.a = 1.0; - color.rgb = pow(color.rgb, vec3(1.0/2.2)); + //color.rgb = linear_to_srgb(color.rgb); frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl index 34bd8d445a..8f6eb79668 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl @@ -45,7 +45,7 @@ ATTRIBUTE vec2 texcoord0; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; VARYING vec3 vary_texcoord1; - +VARYING vec4 vary_position; void main() { @@ -53,7 +53,7 @@ void main() vec4 vert = vec4(position.xyz,1.0); passTextureIndex(); vec4 pos = (modelview_matrix * vert); - gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + vary_position = gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); vec3 norm = normalize(normal_matrix * normal); vec3 ref = reflect(pos.xyz, -norm); diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index 445d7c6352..4c418e414f 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -24,6 +24,12 @@ */ // VARYING param funcs + + +uniform vec3 sun_dir; +uniform vec3 moon_dir; +uniform int sun_up_factor; + void setSunlitColor(vec3 v); void setAmblitColor(vec3 v); void setAdditiveColor(vec3 v); @@ -32,124 +38,19 @@ void setPositionEye(vec3 v); vec3 getAdditiveColor(); -//VARYING vec4 vary_CloudUVs; -//VARYING float vary_CloudDensity; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; - -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 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 vec4 glow; +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); void calcAtmospherics(vec3 inPositionEye) { - - vec3 P = inPositionEye; - setPositionEye(P); - - //(TERRAIN) limit altitude - if (P.y > max_y) P *= (max_y / P.y); - if (P.y < -max_y) P *= (-max_y / P.y); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(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 - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - //vary_AtmosAttenuation = distance_multiplier / 10000.; - //vary_AtmosAttenuation = density_multiplier * 100.; - //vary_AtmosAttenuation = vec4(Plen / 100000., 0., 0., 1.); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); - - // vary_SunlitColor = vec3(0); - // vary_AmblitColor = vec3(0); - // vary_AdditiveColor = vec4(Pn, 1.0); - - /* - const float cloudShadowScale = 100.; - // Get cloud uvs for shadowing - vec3 cloudPos = inPositionEye + camPosWorld - cloudShadowScale / 2.; - vary_CloudUVs.xy = cloudPos.xz / cloudShadowScale; - - // We can take uv1 and multiply it by (TerrainSpan / CloudSpan) -// cloudUVs *= (((worldMaxZ - worldMinZ) * 20) /40000.); - vary_CloudUVs *= (10000./40000.); - - // Offset by sun vector * (CloudAltitude / CloudSpan) - vary_CloudUVs.x += tmpLightnorm.x / tmpLightnorm.y * (3000./40000.); - vary_CloudUVs.y += tmpLightnorm.z / tmpLightnorm.y * (3000./40000.); - */ + vec3 P = inPositionEye; + setPositionEye(P); + vec3 tmpsunlit = vec3(1); + vec3 tmpamblit = vec3(1); + vec3 tmpaddlit = vec3(1); + vec3 tmpattenlit = vec3(1); + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + calcAtmosphericVars(inPositionEye, light_dir, 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, false); + setSunlitColor(tmpsunlit); + setAmblitColor(tmpamblit); + setAdditiveColor(tmpaddlit); + setAtmosAttenuation(tmpattenlit); } - -- cgit v1.2.3 From 20e5ad48ec1a9c6fa4902fa34b6b53f0a7fc5858 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Tue, 24 Mar 2020 13:44:40 -0500 Subject: Merge cleanup --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4644fe3f2b..2999abacef 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -223,7 +223,7 @@ void main() // Comparing floats cast from 8-bit values, produces acne right at the 8-bit transition points float bias = 0.001953125; // 1/512, or half an 8-bit quantization - if (diffuse_linear.a < minimum_alpha-bias) + if (diffcol.a < minimum_alpha-bias) { discard; } -- cgit v1.2.3 From 9e0cf3edaab99cc1c427e590c179d6dd604f4567 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Wed, 25 Mar 2020 15:29:11 -0500 Subject: Fix for class2/softenLightF.glsl not matching class1/softenLightF.glsl --- .../shaders/class1/deferred/softenLightF.glsl | 3 +- .../shaders/class2/deferred/softenLightF.glsl | 105 +++++++++------------ .../shaders/class2/windlight/transportF.glsl | 4 +- .../shaders/class3/windlight/transportF.glsl | 3 +- 4 files changed, 48 insertions(+), 67 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 5b94baf7e6..a5804220bc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -84,7 +84,8 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); - //da = pow(da, 1.0/1.3); + float light_gamma = 1.0/1.3; + da = pow(da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 0658b3ede5..b0dff0c628 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -22,7 +22,7 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable @@ -80,63 +80,55 @@ void main() vec4 pos = getPositionWithDepth(tc, depth); vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; - norm.xyz = getNorm(tc); // unpack norm - - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + norm.xyz = getNorm(tc); + + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); + float light_gamma = 1.0/1.3; + da = pow(da, light_gamma); + + vec4 diffuse = texture2DRect(diffuseRect, tc); + + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - float scol = 1.0; vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; + scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); - float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); - da = pow(da, 1.0/1.3); - vec4 diffuse_srgb = texture2DRect(diffuseRect, tc); - vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); + float scol = max(scol_ambocc.r, diffuse.a); - // clamping to alpha value kills underwater shadows... - //scol = max(scol_ambocc.r, diffuse_linear.a); - scol = scol_ambocc.r; + float ambocc = scol_ambocc.g; - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 color = vec3(0); float bloom = 0.0; { - float ambocc = scol_ambocc.g; - vec3 sunlit; vec3 amblit; vec3 additive; vec3 atten; calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); - + + color.rgb = amblit; + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); - vec3 sun_contrib = min(scol, da) * sunlit; - -#if !defined(AMBIENT_KILL) - color.rgb = amblit; color.rgb *= ambient; -#endif -vec3 post_ambient = color.rgb; + vec3 sun_contrib = min(da, scol) * sunlit; -#if !defined(SUNLIGHT_KILL) color.rgb += sun_contrib; -#endif - -vec3 post_sunlight = color.rgb; - - color.rgb *= diffuse_srgb.rgb; -vec3 post_diffuse = color.rgb; + color.rgb *= diffuse.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection { + +#if 1 //EEP vec3 npos = -normalize(pos.xyz); //vec3 ref = dot(pos+lv, norm); @@ -149,73 +141,60 @@ vec3 post_diffuse = color.rgb; float gtdenom = 2 * nh; float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - + if (nh > 0.0) { float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); vec3 sp = sun_contrib*scontrib / 6.0; sp = clamp(sp, vec3(0), vec3(1)); bloom += dot(sp, sp) / 4.0; -#if !defined(SUNLIGHT_KILL) color += sp * spec.rgb; -#endif } +#else //PRODUCTION + float sa = dot(refnormpersp, light_dir.xyz); + vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + color.rgb += spec_contrib; +#endif + } - vec3 post_spec = color.rgb; - - color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a); + color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; -#if !defined(SUNLIGHT_KILL) - color = mix(color.rgb, reflected_color, envIntensity*0.75); // MAGIC NUMBER SL-12574; ALM: On, Quality >= High -#endif + color = mix(color.rgb, reflected_color, envIntensity); } - -vec3 post_env = color.rgb; - + if (norm.w < 0.5) { -#if !defined(SUNLIGHT_KILL) - vec3 p = normalize(pos.xyz); - color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse_srgb.a); - color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse_srgb.a); -#endif + color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a); + color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a); } -vec3 post_atmo = color.rgb; - #ifdef WATER_FOG vec4 fogged = applyWaterFogView(pos.xyz,vec4(color, bloom)); color = fogged.rgb; bloom = fogged.a; #endif -// srgb colorspace debuggables -//color.rgb = amblit; -//color.rgb = sunlit; -//color.rgb = post_ambient; -//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; - } // linear debuggables //color.rgb = vec3(final_da); //color.rgb = vec3(ambient); //color.rgb = vec3(scol); -//color.rgb = diffuse_linear.rgb; +//color.rgb = diffuse_srgb.rgb; - //output linear RGB as lights are summed up in linear space and then gamma corrected prior to the - //post deferred passes + // 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.a = bloom; } + diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl index b0cf9b0002..b53a2e237f 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl @@ -46,8 +46,8 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { - float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; - return mix(atmosTransport(light.rgb), light.rgb + additive, brightness * brightness); + float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1; + return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive, brightness * brightness); } vec3 fullbrightAtmosTransport(vec3 light) diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl index aa7dbc39ce..545a32a227 100644 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl @@ -52,7 +52,8 @@ vec3 atmosTransport(vec3 light) vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) { float brightness = dot(light.rgb, vec3(0.33333)); - return atmosTransportFrag(light * 0.5, additive * (brightness * 0.5 + 0.5), atten); + return vec3(1,0,1); + //return atmosTransportFrag(light * 0.5, additive * (brightness * 0.5 + 0.5), atten); } vec3 fullbrightAtmosTransport(vec3 light) -- cgit v1.2.3 From a3f0913b4bcd23fd1fad2fa9ad6563d55abee4da Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 3 Apr 2020 07:43:14 -0700 Subject: SL-12852 Cleanup for readability --- indra/newview/app_settings/shaders/class1/environment/waterF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index d1e6c7da1a..d370997123 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -74,13 +74,13 @@ void main() vec3 viewVec = normalize(view.xyz); //get wave normals - //get wave normals - vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec2 bigwave = vec2(refCoord.w, view.w); + vec3 wave1_a = texture2D(bumpMap, bigwave ).xyz*2.0-1.0; vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; - vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave1_b = texture2D(bumpMap2, bigwave ).xyz*2.0-1.0; vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; -- cgit v1.2.3 From 1016b9de1804e445252bda297ae93aed6c2971f0 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 7 Apr 2020 14:02:48 -0700 Subject: SL-10449 Fix ALM on OSX --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 2999abacef..0afd1a9672 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -234,14 +234,14 @@ void main() diffcol.rgb = srgb_to_linear(diffcol.rgb); #endif -#if HAS_SPECULAR_MAP != 0 +#ifdef HAS_SPECULAR_MAP vec4 spec = texture2D(specularMap, vary_texcoord2.xy); spec.rgb *= specular_color.rgb; #else vec4 spec = vec4(specular_color.rgb, 1.0); #endif -#if HAS_NORMAL_MAP +#ifdef HAS_NORMAL_MAP vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); norm.xyz = norm.xyz * 2 - 1; @@ -268,7 +268,7 @@ void main() vec4 final_specular = spec; -#if HAS_SPECULAR_MAP != 0 +#ifdef HAS_SPECULAR_MAP vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); final_specular.a = specular_color.a * norm.a; #else -- cgit v1.2.3 From 9e8e623197185e340d94694e55f2ab25827cfaf0 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 7 Apr 2020 11:29:47 -0600 Subject: SL-10449, add missing linkage variable, fix OSX & Intel deferred shaders comp --- .../app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl index 79b552ee1a..1e244d9dfd 100644 --- a/indra/newview/app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl @@ -35,6 +35,7 @@ ATTRIBUTE vec2 texcoord0; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; VARYING vec3 vary_texcoord1; +VARYING vec4 vary_position; void calcAtmospherics(vec3 inPositionEye); @@ -46,6 +47,9 @@ void main() mat = modelview_matrix * mat; vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz; + + mat4 mvp = modelview_matrix * projection_matrix; + vary_position = mvp * vec4(position, 1.0); vec4 norm = vec4(position.xyz, 1.0); norm.xyz += normal.xyz; -- cgit v1.2.3 From 3c6b666ccdb00cf4c8744f11069b2394f8e76267 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Thu, 9 Apr 2020 18:30:33 -0600 Subject: SL-12975, unfix alpha and undo non-fix magic number of refracted portion of water Fresnel --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index ceb4b8033d..a157e9c017 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -152,7 +152,7 @@ void main() spec = pow(spec, 128.0); //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale*0.16/max(dmod*df1, 1.0); + vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); @@ -172,7 +172,13 @@ void main() vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); //frag_data[0] = color; - frag_data[0] = color; + + // TODO: The non-obvious assignment below is copied from the pre-EEP WL shader code + // Unfortunately, fixing it causes a mismatch for EEP, and so it remains... for now + // SL-12975 (unfix pre-EEP broken alpha) + frag_data[0] = vec4(color.rgb, color); // Effectively, color.rgbr + + frag_data[1] = vec4(0); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 0, 0 } -- cgit v1.2.3 From ff27f6c8f77cc910f240b057b58fffa49023bdc1 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Tue, 14 Apr 2020 12:20:04 -0600 Subject: SL-13019, fix broken varying linkage on MacOS --- .../app_settings/shaders/class2/deferred/softenLightV.glsl | 9 +++++++++ .../app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders') diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl index 8b8b338f68..bd11aa3f05 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl @@ -31,10 +31,19 @@ uniform vec2 screen_res; VARYING vec2 vary_fragcoord; +// forwards +void setAtmosAttenuation(vec3 c); +void setAdditiveColor(vec3 c); + void main() { //transform vertex vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); gl_Position = pos; + + // appease OSX GLSL compiler/linker by touching all the varyings we said we would + setAtmosAttenuation(vec3(1)); + setAdditiveColor(vec3(0)); + vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl index ea37610502..d758f85d71 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl @@ -24,7 +24,6 @@ */ -VARYING vec3 vary_SunlitColor; VARYING vec3 vary_AdditiveColor; VARYING vec3 vary_AtmosAttenuation; -- cgit v1.2.3