diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class3/deferred')
6 files changed, 237 insertions, 37 deletions
| diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index 5483a4e29c..8430cca325 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -40,6 +40,8 @@ in vec3 vary_position;  uniform samplerCube environmentMap;  vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); +  void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten);  vec3 linear_to_srgb(vec3 c); @@ -83,7 +85,6 @@ void main()      color.rgb = srgb_to_linear(color.rgb);      applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); -    color.rgb = atmosFragLighting(color.rgb, additive, atten);  #endif  	color.a = 1.0; diff --git a/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl new file mode 100644 index 0000000000..0b154e82ad --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl @@ -0,0 +1,106 @@ +/** + * @file class3/deferred/hazeF.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, 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$ + */ + +out vec4 frag_color; + +uniform sampler2D normalMap; + +// Inputs +uniform vec3 sun_dir; +uniform vec3 moon_dir; +uniform int  sun_up_factor; +in vec2 vary_fragcoord; + +vec3 getNorm(vec2 pos_screen); +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); + +float getDepth(vec2 pos_screen); + +vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); + +uniform vec4 waterPlane; + +uniform int cube_snapshot; + +uniform float sky_hdr_scale; + +void main() +{ +    vec2  tc           = vary_fragcoord.xy; +    float depth        = getDepth(tc.xy); +    vec4  pos          = getPositionWithDepth(tc, depth); +    vec4  norm         = texture(normalMap, tc); +    norm.xyz           = getNorm(tc); +    vec3  light_dir   = (sun_up_factor == 1) ? sun_dir : moon_dir; + +    vec3  color = vec3(0); +    float bloom = 0.0; + +    vec3 sunlit; +    vec3 amblit; +    vec3 additive; +    vec3 atten; + +    calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten); + +    vec3 sunlit_linear = srgb_to_linear(sunlit); +     +    // mask off atmospherics below water (when camera is under water) +    bool do_atmospherics = false; +         +    if (dot(vec3(0), waterPlane.xyz) + waterPlane.w > 0.0 || +        dot(pos.xyz, waterPlane.xyz) + waterPlane.w > 0.0) +    { +        do_atmospherics = true; +    } +     +    vec3  irradiance = vec3(0); +    vec3  radiance  = vec3(0); + +    if (depth >= 1.0) +    { +        //should only be true of sky, clouds, sun/moon, and stars +        discard; +    } + +   float alpha = 0.0; + +    if (do_atmospherics) +    { +        alpha = atten.r; +        color = srgb_to_linear(additive*2.0); +        color *= sky_hdr_scale; +    } +    else +    { +        color = vec3(0,0,0); +        alpha = 1.0; +    } + +    frag_color = max(vec4(color.rgb, alpha), vec4(0)); //output linear since local lights will be added to this shader's results +     +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index db0daa9b7e..b3b1aaed56 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -37,11 +37,7 @@  uniform float emissive_brightness;  // fullbright flag, 1.0 == fullbright, 0.0 otherwise  uniform int sun_up_factor; -#ifdef WATER_FOG -vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit); -#endif - -vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); +vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color);  vec3 scaleSoftClipFragLinear(vec3 l);  void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive);  void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); @@ -404,13 +400,6 @@ void main()          glare += cur_glare;      } -    color.rgb = atmosFragLightingLinear(color.rgb, additive, atten);  - -#ifdef WATER_FOG -    vec4 temp = applyWaterFogViewLinear(pos, vec4(color, 0.0), sunlit_linear); -    color = temp.rgb; -#endif -      vec3 npos = normalize(-pos.xyz);      vec3 light = vec3(0, 0, 0); @@ -426,6 +415,8 @@ void main()      color += light; +    color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, vec4(color, 1.0)).rgb; +      glare *= 1.0-emissive;      glare = min(glare, 1.0);      float al = max(diffcol.a, glare) * vertex_color.a; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 8b7aea24ed..f5541df227 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -91,10 +91,6 @@ uniform vec4 waterPlane;  uniform int cube_snapshot; -#ifdef WATER_FOG -vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); -#endif -  uniform float sky_hdr_scale;  void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); @@ -175,18 +171,6 @@ void main()      vec3 sunlit_linear = srgb_to_linear(sunlit);      vec3 amblit_linear = amblit; -    bool do_atmospherics = false; - -#ifndef WATER_FOG -    // when above water, mask off atmospherics below water -    if (dot(pos.xyz, waterPlane.xyz) + waterPlane.w > 0.0) -    { -        do_atmospherics = true; -    } -#else -    do_atmospherics = true; -#endif -      vec3  irradiance = vec3(0);      vec3  radiance  = vec3(0); @@ -221,7 +205,6 @@ void main()          {              color = atmosFragLightingLinear(color, additive, atten);          } -              }      else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS))      { @@ -290,18 +273,13 @@ void main()          {  // add environment map              applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity);          } - -         -        if (do_atmospherics) -        { -            color = atmosFragLightingLinear(color, additive, atten); -        }     } -     +         #ifdef WATER_FOG          vec4 fogged = applyWaterFogViewLinear(pos.xyz, vec4(color, bloom));          color       = fogged.rgb;      #endif +          frag_color.rgb = max(color.rgb, vec3(0)); //output linear since local lights will be added to this shader's results      frag_color.a = 0.0;  } diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl new file mode 100644 index 0000000000..f6b8299f91 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl @@ -0,0 +1,65 @@ +/** + * @file class3/deferred/waterHazeF.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, 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$ + */ + +out vec4 frag_color; + +// Inputs +in vec4 vary_fragcoord; + +uniform sampler2D normalMap; + +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +float getDepth(vec2 pos_screen); + +vec4 getWaterFogView(vec3 pos); + +uniform int above_water; + +void main() +{ +    vec2  tc           = vary_fragcoord.xy/vary_fragcoord.w*0.5+0.5; +    float depth        = getDepth(tc.xy); + +    if (above_water > 0) +    {  +        // we want to depth test when the camera is above water, but some GPUs have a hard time +        // with depth testing against render targets that are bound for sampling in the same shader +        // so we do it manually here + +        float cur_depth = vary_fragcoord.z/vary_fragcoord.w*0.5+0.5; +        if (cur_depth > depth) +        { +            discard; +        } +    } + +    vec4  pos          = getPositionWithDepth(tc, depth); +    vec4  norm         = texture(normalMap, tc); + +    vec4 fogged = getWaterFogView(pos.xyz); + +    frag_color = max(fogged, vec4(0)); //output linear since local lights will be added to this shader's results +     +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterHazeV.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterHazeV.glsl new file mode 100644 index 0000000000..16381a5d51 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/waterHazeV.glsl @@ -0,0 +1,59 @@ +/** + * @file class3/deferred/waterHazeV.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, 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$ + */ + +in vec3 position; + +uniform vec2 screen_res; + +out vec4 vary_fragcoord; + +// forwards +void setAtmosAttenuation(vec3 c); +void setAdditiveColor(vec3 c); + +uniform vec4 waterPlane; + +uniform int above_water; + +uniform mat4 modelview_projection_matrix; + +void main() +{ +	//transform vertex +	vec4 pos = vec4(position.xyz, 1.0); + +    if (above_water > 0) +    { +        pos = modelview_projection_matrix*pos; +    } + +    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; +} | 
