SL-19147 Water quality pass. Remove gl_FragDepth writes from sky rendering (optimization). Incidental decruft.

master
Dave Parks 2023-02-07 11:40:56 -06:00
parent c8fb3ad4de
commit b52699091d
20 changed files with 256 additions and 127 deletions

View File

@ -28,6 +28,7 @@
#include "llshadermgr.h"
#include "llrender.h"
#include "llfile.h"
#include "lldir.h"
#if LL_DARWIN
#include "OpenGL/OpenGL.h"
@ -593,36 +594,57 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
S32 gpu_class;
std::string open_file_name;
//find the most relevant file
for (gpu_class = try_gpu_class; gpu_class > 0; gpu_class--)
{ //search from the current gpu class down to class 1 to find the most relevant shader
std::stringstream fname;
fname << getShaderDirPrefix();
fname << gpu_class << "/" << filename;
open_file_name = fname.str();
/*
Would be awesome, if we didn't have shaders that re-use files
with different environments to say, add skinning, etc
can't depend on cached version to have evaluate ifdefs identically...
if we can define a deterministic hash for the shader based on
all the inputs, maybe we can save some time here.
if (mShaderObjects.count(filename) > 0)
#if 0 // WIP -- try to come up with a way to fallback to an error shader without needing debug stubs all over the place in the shader tree
if (shader_level == -1)
{
// use "error" fallback
if (type == GL_VERTEX_SHADER)
{
return mShaderObjects[filename];
open_file_name = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "shaders/errorV.glsl");
}
else
{
llassert(type == GL_FRAGMENT_SHADER); // type must be vertex or fragment shader
open_file_name = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "shaders/errorF.glsl");
}
*/
file = LLFile::fopen(open_file_name, "r");
}
else
#endif
{
//find the most relevant file
for (gpu_class = try_gpu_class; gpu_class > 0; gpu_class--)
{ //search from the current gpu class down to class 1 to find the most relevant shader
std::stringstream fname;
fname << getShaderDirPrefix();
fname << gpu_class << "/" << filename;
LL_DEBUGS("ShaderLoading") << "Looking in " << open_file_name << LL_ENDL;
file = LLFile::fopen(open_file_name, "r"); /* Flawfinder: ignore */
if (file)
{
LL_DEBUGS("ShaderLoading") << "Loading file: " << open_file_name << " (Want class " << gpu_class << ")" << LL_ENDL;
break; // done
}
}
open_file_name = fname.str();
/*
Would be awesome, if we didn't have shaders that re-use files
with different environments to say, add skinning, etc
can't depend on cached version to have evaluate ifdefs identically...
if we can define a deterministic hash for the shader based on
all the inputs, maybe we can save some time here.
if (mShaderObjects.count(filename) > 0)
{
return mShaderObjects[filename];
}
*/
LL_DEBUGS("ShaderLoading") << "Looking in " << open_file_name << LL_ENDL;
file = LLFile::fopen(open_file_name, "r"); /* Flawfinder: ignore */
if (file)
{
LL_DEBUGS("ShaderLoading") << "Loading file: " << open_file_name << " (Want class " << gpu_class << ")" << LL_ENDL;
break; // done
}
}
}
if (file == NULL)
{

View File

@ -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
}

View File

@ -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;
}

View File

@ -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
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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));

View File

@ -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);

View File

@ -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));
}

View File

@ -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;
vec3 baseColor = vec3(0.25);
vec3 f0 = vec3(0.04);
vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
diffuseColor *= gloss;
vec3 specularColor = mix(f0, baseColor.rgb, metallic);
vec3 refnorm = normalize(wavef + vary_normal);
//vec3 refnorm = wavef;
float metallic = 0.0;
float perceptualRoughness = 0.1;
float gloss = 1.0 - perceptualRoughness;
vec3 irradiance = vec3(0);
vec3 radiance = vec3(0);
sampleReflectionProbes(irradiance, radiance, distort, pos, refnorm, gloss, true);
radiance *= 0.5;
irradiance = fb.rgb;
vec3 irradiance = vec3(0);
vec3 radiance = vec3(0);
sampleReflectionProbes(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss);
color.rgb = pbrIbl(diffuseColor, specularColor, radiance, irradiance, gloss, NdotV, 0.0);
irradiance = vec3(0);
vec3 diffuseColor;
vec3 specularColor;
calcDiffuseSpecular(vec3(1), metallic, diffuseColor, specularColor);
vec3 v = -normalize(pos.xyz);
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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -949,7 +949,7 @@ void LLSettingsVOWater::applySpecial(void *ptarget, bool force)
//transform water plane to eye space
glh::vec3f norm(0.f, 0.f, 1.f);
glh::vec3f p(0.f, 0.f, water_height + 0.1f);
glh::vec3f p(0.f, 0.f, water_height);
F32 modelView[16];
for (U32 i = 0; i < 16; i++)

View File

@ -819,6 +819,11 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
resY /= res_mod;
}
if (LLPipeline::sRenderTransparentWater)
{ //water reflection texture
mWaterDis.allocate(resX, resY, GL_RGBA, true);
}
if (RenderUIBuffer)
{
if (!mRT->uiScreen.allocate(resX,resY, GL_RGBA))
@ -1099,7 +1104,6 @@ void LLPipeline::releaseGLBuffers()
releaseLUTBuffers();
mWaterRef.release();
mWaterDis.release();
mBake.release();
@ -1173,12 +1177,6 @@ void LLPipeline::createGLBuffers()
stop_glerror();
assertInitialized();
if (LLPipeline::sRenderTransparentWater)
{ //water reflection texture
U32 res = (U32) llmax(gSavedSettings.getS32("RenderWaterRefResolution"), 512);
mWaterDis.allocate(res,res,GL_RGBA,true);
}
// Use FBO for bake tex
mBake.allocate(512, 512, GL_RGBA, true); // SL-12781 Build > Upload > Model; 3D Preview

View File

@ -718,9 +718,6 @@ public:
LLVector4 mSunOrthoClipPlanes;
LLVector2 mScreenScale;
//water reflection texture
LLRenderTarget mWaterRef;
//water distortion texture (refraction)
LLRenderTarget mWaterDis;