summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders
diff options
context:
space:
mode:
authorJonathan "Geenz" Goodman <geenz@lindenlab.com>2025-02-07 05:55:47 -0500
committerGitHub <noreply@github.com>2025-02-07 05:55:47 -0500
commit93a88e602545828c0298b20ff0375f191d1f6d9a (patch)
treecb098bfa5eeb4b0d784a9ed6aec3b5fe7f1a0245 /indra/newview/app_settings/shaders
parent317cd6e66e65256eda6441c06fa32e55eee99fa3 (diff)
Water Exclusion Surfaces (#3517)
* #3455 Add support for water exclusion surfaces
Diffstat (limited to 'indra/newview/app_settings/shaders')
-rw-r--r--indra/newview/app_settings/shaders/class1/objects/simpleColorF.glsl57
-rw-r--r--indra/newview/app_settings/shaders/class1/objects/simpleNoAtmosV.glsl43
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl14
-rw-r--r--indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl8
-rw-r--r--indra/newview/app_settings/shaders/class3/environment/waterF.glsl13
5 files changed, 129 insertions, 6 deletions
diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleColorF.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleColorF.glsl
new file mode 100644
index 0000000000..dea76da5a5
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class1/objects/simpleColorF.glsl
@@ -0,0 +1,57 @@
+/**
+ * @file simpleColorF.glsl
+ *
+ * $LicenseInfo:firstyear=2025&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$
+ */
+
+out vec4 frag_color;
+
+in vec4 vertex_color;
+in vec4 vertex_position;
+
+uniform vec4 waterPlane;
+uniform float waterSign;
+
+void waterClip(vec3 pos)
+{
+ // TODO: make this less branchy
+ if (waterSign > 0)
+ {
+ if ((dot(pos.xyz, waterPlane.xyz) + waterPlane.w) < 0.0)
+ {
+ discard;
+ }
+ }
+ else
+ {
+ if ((dot(pos.xyz, waterPlane.xyz) + waterPlane.w) > 0.0)
+ {
+ discard;
+ }
+ }
+}
+
+void main()
+{
+
+ frag_color = vertex_color;
+}
diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleNoAtmosV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleNoAtmosV.glsl
new file mode 100644
index 0000000000..4564e56313
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class1/objects/simpleNoAtmosV.glsl
@@ -0,0 +1,43 @@
+/**
+ * @file simpleNoAtmosV.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;
+
+uniform vec4 color;
+
+in vec3 position;
+
+out vec4 vertex_color;
+out vec4 vertex_position;
+
+void main()
+{
+ //transform vertex
+ vec4 pos = (modelview_matrix * vec4(position.xyz, 1.0));
+ vertex_position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+ gl_Position = vertex_position;
+ vertex_color = color;
+}
diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl
index ee49b4baae..091c25d15e 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl
@@ -35,13 +35,25 @@ vec4 getWaterFogView(vec3 pos);
uniform int above_water;
+uniform sampler2D exclusionTex;
+
void main()
{
vec2 tc = vary_fragcoord.xy/vary_fragcoord.w*0.5+0.5;
float depth = getDepth(tc.xy);
+ float mask = texture(exclusionTex, tc.xy).r;
if (above_water > 0)
{
+ // Just discard if we're in the exclusion mask.
+ // The previous invisiprim hack we're replacing would also crank up water fog desntiy.
+ // But doing that makes exclusion surfaces very slow as we'd need to render even more into the mask.
+ // - Geenz 2025-02-06
+ if (mask < 1)
+ {
+ discard;
+ }
+
// 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
@@ -51,12 +63,14 @@ void main()
{
discard;
}
+
}
vec4 pos = getPositionWithDepth(tc, depth);
vec4 fogged = getWaterFogView(pos.xyz);
fogged.a = max(pow(fogged.a, 1.7), 0);
+
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/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl
index 1c02dc764d..fa410e9f11 100644
--- a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl
+++ b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl
@@ -26,6 +26,7 @@
out vec4 frag_color;
uniform sampler2D bumpMap;
+uniform sampler2D exclusionTex;
#ifdef TRANSPARENT_WATER
uniform sampler2D screenTex;
@@ -59,6 +60,9 @@ void mirrorClip(vec3 position);
void main()
{
mirrorClip(vary_position);
+ vec2 screen_tc = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
+ float water_mask = texture(exclusionTex, screen_tc).r;
+
vec4 color;
//get detail normals
@@ -68,8 +72,8 @@ void main()
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;
+ vec2 distort = screen_tc;
+ distort = mix(distort, distort+wavef.xy*refScale, water_mask);
#ifdef TRANSPARENT_WATER
vec4 fb = texture(screenTex, distort);
diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl
index f8aa684433..7027e3796e 100644
--- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl
+++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl
@@ -88,7 +88,7 @@ uniform sampler2D screenTex;
uniform sampler2D depthMap;
#endif
-uniform sampler2D refTex;
+uniform sampler2D exclusionTex;
uniform float sunAngle;
uniform float sunAngle2;
@@ -252,6 +252,8 @@ void main()
float shadow = 1.0f;
+ float water_mask = texture(exclusionTex, distort).r;
+
#ifdef HAS_SUN_SHADOW
shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, distort);
#endif
@@ -266,9 +268,8 @@ void main()
vec3 refPos = getPositionWithNDC(vec3(distort*2.0-vec2(1.0), depth*2.0-1.0));
// Calculate some distance fade in the water to better assist with refraction blending and reducing the refraction texture's "disconnect".
- fade = max(0,min(1, (pos.z - refPos.z) / 10));
+ fade = max(0,min(1, (pos.z - refPos.z) / 10)) * water_mask;
distort2 = mix(distort, distort2, min(1, fade * 10));
-
depth = texture(depthMap, distort2).r;
refPos = getPositionWithNDC(vec3(distort2 * 2.0 - vec2(1.0), depth * 2.0 - 1.0));
@@ -282,6 +283,9 @@ void main()
#else
vec4 fb = applyWaterFogViewLinear(viewVec*2048.0, vec4(1.0));
+
+ if (water_mask < 1)
+ discard;
#endif
float metallic = 1.0;
@@ -333,6 +337,7 @@ void main()
color = mix(fb.rgb, color, fade);
float spec = min(max(max(punctual.r, punctual.g), punctual.b), 0.05);
- frag_color = min(vec4(1),max(vec4(color.rgb, spec), vec4(0)));
+
+ frag_color = min(vec4(1),max(vec4(color.rgb, spec * water_mask), vec4(0)));
}