From b52699091da791a1349daf66d405f27ca2568ea9 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 7 Feb 2023 11:40:56 -0600 Subject: SL-19147 Water quality pass. Remove gl_FragDepth writes from sky rendering (optimization). Incidental decruft. --- .../shaders/class1/deferred/cloudsF.glsl | 2 - .../shaders/class1/deferred/deferredUtil.glsl | 6 +- .../shaders/class1/deferred/moonF.glsl | 2 - .../shaders/class1/deferred/moonV.glsl | 6 +- .../app_settings/shaders/class1/deferred/skyF.glsl | 2 - .../shaders/class1/deferred/starsF.glsl | 2 - .../shaders/class1/deferred/starsV.glsl | 6 +- .../shaders/class1/deferred/sunDiscF.glsl | 2 - .../shaders/class1/deferred/sunDiscV.glsl | 2 + .../shaders/class1/environment/waterF.glsl | 34 ++++++ .../shaders/class1/environment/waterFogF.glsl | 17 ++- .../shaders/class3/deferred/reflectionProbeF.glsl | 2 +- .../shaders/class3/environment/underWaterF.glsl | 4 +- .../shaders/class3/environment/waterF.glsl | 134 +++++++++++---------- indra/newview/app_settings/shaders/errorF.glsl | 34 ++++++ indra/newview/app_settings/shaders/errorV.glsl | 35 ++++++ 16 files changed, 201 insertions(+), 89 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/environment/waterF.glsl create mode 100644 indra/newview/app_settings/shaders/errorF.glsl create mode 100644 indra/newview/app_settings/shaders/errorV.glsl (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 b45dfcd550..cf9ce646d1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -125,7 +125,5 @@ void main() 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,0,GBUFFER_FLAG_SKIP_ATMOS); - - gl_FragDepth = LL_SHADER_CONST_CLOUD_MOON_DEPTH; // SL-14113 Stars and Clouds need same depth } diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index c87e754eca..e71d080fc5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -531,7 +531,7 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v, float NdotV = clamp(abs(dot(norm, v)), 0.001, 1.0); - color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); + color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, 0.2); color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm, v, normalize(light_dir)) * sunlit * 2.75 * scol; color += colorEmissive*0.5; @@ -551,14 +551,14 @@ void waterClip(vec3 pos) // TODO: make this less branchy if (waterSign > 0) { - if ((dot(pos.xyz, waterPlane.xyz) + waterPlane.w) < -0.1) + if ((dot(pos.xyz, waterPlane.xyz) + waterPlane.w) < 0.0) { discard; } } else { - if ((dot(pos.xyz, waterPlane.xyz) + waterPlane.w) > -0.1) + if ((dot(pos.xyz, waterPlane.xyz) + waterPlane.w) > 0.0) { discard; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 7032c45603..41dd485fae 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -72,7 +72,5 @@ void main() frag_data[0] = vec4(c.rgb, c.a); frag_data[1] = vec4(0.0); frag_data[2] = vec4(0.0, 0.0, 0.0, GBUFFER_FLAG_HAS_ATMOS); - - gl_FragDepth = LL_SHADER_CONST_CLOUD_MOON_DEPTH; // SL-14113 } diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl index c4922afd7d..7b9aa0a4dc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl @@ -36,9 +36,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*vert; + // smash to *almost* far clip plane -- stars are still behind + pos.z = pos.w*0.999999; + gl_Position = pos; vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 0c398b263f..930338cefb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -97,7 +97,5 @@ void main() 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.0,0.0,0.0,GBUFFER_FLAG_SKIP_ATMOS); //1.0 in norm.w masks off fog - - 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 152316c117..cdafdba15c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -65,7 +65,5 @@ void main() frag_data[0] = col; frag_data[1] = vec4(0.0f); frag_data[2] = vec4(0.0, 1.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS); - - gl_FragDepth = LL_SHADER_CONST_STAR_DEPTH; // SL-14113 Moon Haze -- Stars need to depth test behind the moon } diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl index bb2a2ee72b..37d1630252 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl @@ -40,8 +40,10 @@ void main() //transform vertex 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; + + // smash to far clip plane to + // avoid rendering on top of moon (do NOT write to gl_FragDepth, it's slow) + pos.z = pos.w; gl_Position = pos; diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index 4ab8747629..e35ea83f0a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -58,7 +58,5 @@ void main() frag_data[0] = c; frag_data[1] = vec4(0.0f); frag_data[2] = vec4(0.0, 1.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS); - - gl_FragDepth = 0.999988f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl index 0d117c6bc7..d3dfa882f0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl @@ -44,6 +44,8 @@ void main() sun_fade = smoothstep(0.3, 1.0, (position.z + 50) / 512.0f); + // smash to *almost* far clip plane -- behind clouds but in front of stars + pos.z = pos.w*0.999999; gl_Position = pos; calcAtmospherics(pos.xyz); diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl new file mode 100644 index 0000000000..075397d96c --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -0,0 +1,34 @@ +/** + * @file waterF.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$ + */ + + // error fallback on compilation failure + +out vec4 frag_color; + +void main() +{ + frag_color = vec4(1,0,1,1); +} + diff --git a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl index e1cdeddcea..5765e04014 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl @@ -72,13 +72,8 @@ vec4 applyWaterFogView(vec3 pos, vec4 color) return color; } -vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit) +vec4 applyWaterFogViewLinearNoClip(vec3 pos, vec4 color, vec3 sunlit) { - if (dot(pos, waterPlane.xyz) + waterPlane.w > 0.0) - { - return color; - } - vec3 view = normalize(pos); //normalize view vector float es = -(dot(view, waterPlane.xyz)); @@ -118,6 +113,16 @@ vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit) return color; } +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit) +{ + if (dot(pos, waterPlane.xyz) + waterPlane.w > 0.0) + { + return color; + } + + return applyWaterFogViewLinearNoClip(pos, color, sunlit); +} + vec4 applyWaterFogViewLinear(vec3 pos, vec4 color) { return applyWaterFogViewLinear(pos, color, vec3(1)); diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index bb3be7260b..8b1d41776f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -643,7 +643,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, glossenv = sampleProbes(pos, normalize(refnormpersp), lod, errorCorrect); #if defined(SSR) - if (cube_snapshot != 1) + if (cube_snapshot != 1 && glossiness >= 0.9) { vec4 ssr = vec4(0); //float w = tapScreenSpaceReflection(errorCorrect ? 1 : 4, tc, pos, norm, ssr, sceneMap); diff --git a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl index a5e0adf8fa..83454631d4 100644 --- a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl @@ -55,7 +55,7 @@ VARYING vec4 littleWave; VARYING vec4 view; in vec3 vary_position; -vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); +vec4 applyWaterFogViewLinearNoClip(vec3 pos, vec4 color, vec3 sunlit); void main() { @@ -77,5 +77,5 @@ void main() vec4 fb = vec4(waterFogColorLinear, 0.0); #endif - frag_color = applyWaterFogViewLinear(vary_position, fb); + frag_color = applyWaterFogViewLinearNoClip(vary_position, fb, vec3(1)); } diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index b792feee2a..98e8d189c5 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -37,6 +37,10 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, ou vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit); // PBR interface +vec2 BRDF(float NoV, float roughness); + +void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor); + vec3 pbrIbl(vec3 diffuseColor, vec3 specularColor, vec3 radiance, // radiance map sample @@ -52,6 +56,22 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, vec3 v, // surface point to camera vec3 l); //surface point to light +vec3 pbrBaseLight(vec3 diffuseColor, + vec3 specularColor, + float metallic, + vec3 pos, + vec3 norm, + float perceptualRoughness, + vec3 light_dir, + vec3 sunlit, + float scol, + vec3 radiance, + vec3 irradiance, + vec3 colorEmissive, + float ao, + vec3 additive, + vec3 atten); + uniform sampler2D bumpMap; uniform sampler2D bumpMap2; uniform float blend_factor; @@ -112,8 +132,6 @@ vec3 getPositionWithNDC(vec3 ndc); void main() { - vec4 color; - vN = vary_normal; vT = vary_tangent; vB = cross(vN, vT); @@ -151,30 +169,28 @@ void main() vec3 waver = wavef*3; - wavef = transform_normal(wavef); + vec3 up = transform_normal(vec3(0,0,1)); + float vdu = -dot(viewVec, up)*2; + + vec3 wave_ibl = wavef; + wave_ibl.z *= 2.0; + wave_ibl = transform_normal(normalize(wave_ibl)); - //wavef.z *= max(-viewVec.z, 0.1); + vec3 norm = transform_normal(normalize(wavef)); + + vdu = clamp(vdu, 0, 1); + wavef.z *= max(vdu*vdu*vdu, 0.1); wavef = normalize(wavef); - //get base fresnel components - - vec3 df = vec3( - dot(viewVec, wave1), - dot(viewVec, (wave2 + wave3) * 0.5), - dot(viewVec, wave3) - ) * fresnelScale + fresnelOffset; - + //wavef = vec3(0, 0, 1); + wavef = transform_normal(wavef); + float dist2 = dist; dist = max(dist, 5.0); float dmod = sqrt(dist); - float df1 = df.x + df.y + df.z; - - - - //figure out distortion vector (ripply) vec2 distort2 = distort + waver.xy * refScale / max(dmod, 1.0); @@ -203,66 +219,58 @@ void main() fb = applyWaterFogViewLinear(refPos, fb, sunlit); #else - vec4 fb = vec4(waterFogColorLinear.rgb, 0.0); + vec4 fb = applyWaterFogViewLinear(viewVec*1024.0, vec4(0.5), sunlit); #endif - vec3 v = -viewVec; - float NdotV = clamp(abs(dot(wavef.xyz, v)), 0.001, 1.0); - - float metallic = fresnelOffset * 0.1; // fudge -- use fresnelOffset as metalness - float roughness = 0.1; - float gloss = 1.0 - roughness; + float metallic = 0.0; + float perceptualRoughness = 0.1; + float gloss = 1.0 - perceptualRoughness; + + vec3 irradiance = vec3(0); + vec3 radiance = vec3(0); + sampleReflectionProbes(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss); - vec3 baseColor = vec3(0.25); - vec3 f0 = vec3(0.04); - vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0); - diffuseColor *= gloss; + irradiance = vec3(0); - vec3 specularColor = mix(f0, baseColor.rgb, metallic); + vec3 diffuseColor; + vec3 specularColor; + calcDiffuseSpecular(vec3(1), metallic, diffuseColor, specularColor); - vec3 refnorm = normalize(wavef + vary_normal); - //vec3 refnorm = wavef; - - vec3 irradiance = vec3(0); - vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, distort, pos, refnorm, gloss, true); - radiance *= 0.5; - irradiance = fb.rgb; + vec3 v = -normalize(pos.xyz); - color.rgb = pbrIbl(diffuseColor, specularColor, radiance, irradiance, gloss, NdotV, 0.0); + float scol = 1.0; + vec3 colorEmissive = vec3(0); + float ao = 1.0; + vec3 light_dir = transform_normal(lightDir); - // fudge -- for punctual lighting, pretend water is metallic - diffuseColor = vec3(0); - specularColor = vec3(1); - roughness = 0.1; - float scol = 1.0; // TODO -- incorporate shadow map + perceptualRoughness = 0.0; + metallic = 1.0; - //color.rgb += pbrPunctual(diffuseColor, specularColor, roughness, metallic, wavef, v, vary_light_dir) * sunlit * 2.75 * scol; + float NdotV = clamp(abs(dot(norm, v)), 0.001, 1.0); - //get specular component - float spec = clamp(dot(vary_light_dir, (reflect(viewVec, wavef))), 0.0, 1.0); + vec3 punctual = pbrPunctual(vec3(0), specularColor, 0.1, metallic, normalize(wavef+up*max(dist, 32.0)/32.0*(1.0-vdu)), v, normalize(light_dir)); - //harden specular - spec = pow(spec, 128.0); + vec3 color = punctual * sunlit * 2.75 * scol; - color.rgb += spec * specular; + color = atmosFragLightingLinear(color, additive, atten); + color = scaleSoftClipFragLinear(color); - color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); - color.rgb = scaleSoftClipFragLinear(color.rgb); + vec3 ibl = pbrIbl(vec3(0), vec3(1), radiance, vec3(0), ao, NdotV, 0.0); - color.a = 0.f; - //color.rgb = fb.rgb; - //color.rgb = vec3(depth*depth*depth*depth); - //color.rgb = srgb_to_linear(normalize(refPos) * 0.5 + 0.5); - //color.rgb = srgb_to_linear(normalize(pos) * 0.5 + 0.5); - //color.rgb = srgb_to_linear(wavef * 0.5 + 0.5); + color += ibl; - //color.rgb = radiance; - frag_color = color; + float nv = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); + vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0); + float f = 1.0-brdf.y; //1.0 - (brdf.x+brdf.y); + f *= 0.9; + f *= f; -#if defined(WATER_EDGE) - gl_FragDepth = 0.9999847f; -#endif - + f = clamp(f, 0, 1); + //fb.rgb *= 1.; + + color = mix(color, fb.rgb, f); + float spec = min(max(max(punctual.r, punctual.g), punctual.b), 0.05); + + frag_color = vec4(color, spec); //*sunAngle2); } diff --git a/indra/newview/app_settings/shaders/errorF.glsl b/indra/newview/app_settings/shaders/errorF.glsl new file mode 100644 index 0000000000..573bb5887b --- /dev/null +++ b/indra/newview/app_settings/shaders/errorF.glsl @@ -0,0 +1,34 @@ +/** + * @file errorF.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$ + */ + + // error fallback on compilation failure + +out vec4 frag_color; + +void main() +{ + frag_color = vec4(1,0,1,1); +} + diff --git a/indra/newview/app_settings/shaders/errorV.glsl b/indra/newview/app_settings/shaders/errorV.glsl new file mode 100644 index 0000000000..e4b362c8c8 --- /dev/null +++ b/indra/newview/app_settings/shaders/errorV.glsl @@ -0,0 +1,35 @@ +/** + * @file errorV.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$ + */ + + // fallback shader for whenever there is a compilation error +uniform mat4 modelview_projection_matrix; + +in vec3 position; + +void main() +{ + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); +} + -- cgit v1.2.3