SL-14113 Fix moon haze

meow-7.2.2
Ptolemy 2021-04-12 16:58:18 -07:00
parent caabb384bd
commit 01e5caade3
13 changed files with 267 additions and 9 deletions

View File

@ -126,6 +126,6 @@ void main()
frag_data[1] = vec4(0.0,0.0,0.0,0.0);
frag_data[2] = vec4(0,0,0,1);
gl_FragDepth = 0.99995f;
gl_FragDepth = 0.999985; // SL-14113 Stars and Clouds need same depth
}

View File

@ -55,6 +55,12 @@ void main()
fade = clamp( moon_dir.z*moon_dir.z*4.0, 0.0, 1.0 );
vec4 c = texture2D(diffuseMap, vary_texcoord0.xy);
// SL-14113 Don't write to depth; prevent moon's quad from hiding stars which should be visible
// Moon texture has transparent pixels <0x55,0x55,0x55,0x00>
if (c.a <= 2./255.) // 0.00784
discard;
// c.rgb = srgb_to_linear(c.rgb);
c.rgb *= moonlight_color.rgb;
c.rgb *= moon_brightness;

View File

@ -46,8 +46,13 @@ float twinkle(){
return abs(d);
}
// See:
// ALM off: class1/environment/starsF.glsl
// ALM on : class1/deferred/starsF.glsl
void main()
{
// camera above water: class1\deferred\starsF.glsl
// camera below water: starsF.glsl
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);
@ -62,6 +67,6 @@ void main()
frag_data[1] = vec4(0.0f);
frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0);
gl_FragDepth = 0.99995f;
gl_FragDepth = 0.999995f; // SL-14113 Moon Haze -- Stars need to depth test behind the moon
}

View File

@ -0,0 +1,51 @@
/**
* @file class1/environment/moonF.glsl
*
* $LicenseInfo:firstyear=2021&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2021, 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 tex0;
VARYING vec2 vary_texcoord0;
// See:
// AS off: class1/environment/moonF.glsl
// ALM off: class1/windlight/moonF.glsl
// ALM on : class1/deferred/moonF.glsl
void main()
{
vec4 color = texture2D(tex0, vary_texcoord0.xy);
// SL-14113 Don't write to depth; prevent moon's quad from hiding stars which should be visible
// Moon texture has transparent pixels <0x55,0x55,0x55,0x00>
if (color.a <= 2./255.) // 0.00784
discard;
frag_color = color;
gl_FragDepth = 0.999985f; // SL-14113 Moon is infront of stars
}

View File

@ -0,0 +1,38 @@
/**
* @file class1\environment\moonV.glsl
*
* $LicenseInfo:firstyear=2021&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2021, 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;
VARYING vec2 vary_texcoord0;
void main()
{
gl_Position = modelview_projection_matrix * vec4(position, 1);
vary_texcoord0 = texcoord0;
}

View File

@ -0,0 +1,51 @@
/**
* @file class1/environment/starsF.glsl
*
* $LicenseInfo:firstyear=2021&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2021, 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;
uniform float custom_alpha;
VARYING vec4 vertex_color;
VARYING vec2 vary_texcoord0;
// See:
// ALM off: class1/environment/starsF.glsl
// ALM on : class1/deferred/starsF.glsl
void main()
{
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;
gl_FragDepth = 0.999995f; // SL-14113 Moon Haze -- Stars need to depth test behind the moon
}

View File

@ -0,0 +1,41 @@
/**
* @file class1/environment/starsV.glsl
*
* $LicenseInfo:firstyear=2021&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2021, 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 vec4 diffuse_color;
ATTRIBUTE vec2 texcoord0;
VARYING vec4 vertex_color;
VARYING vec2 vary_texcoord0;
void main()
{
gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
vary_texcoord0 = texcoord0;
vertex_color = diffuse_color;
}

View File

@ -52,6 +52,12 @@ void main()
fade = clamp( moon_dir.z*moon_dir.z*4.0, 0.0, 1.0 );
vec4 c = texture2D(diffuseMap, vary_texcoord0.xy);
// SL-14113 Don't write to depth; prevent moon's quad from hiding stars which should be visible
// Moon texture has transparent pixels <0x55,0x55,0x55,0x00>
if (c.a <= 2./255.) // 0.00784
discard;
// c.rgb = pow(c.rgb, vec3(0.7f)); // can't use "srgb_to_linear(color.rgb)" as that is a deferred only function
c.rgb *= moonlight_color.rgb;
c.rgb *= moon_brightness;
@ -62,5 +68,6 @@ void main()
c.rgb = scaleSoftClip(c.rgb);
frag_color = vec4(c.rgb, c.a);
gl_FragDepth = 0.999985f; // SL-14113
}

View File

@ -127,5 +127,11 @@ void main()
/// Gamma correct for WL (soft clip effect).
frag_color = vec4(color.rgb, alpha1);
// SL-14113 Moon Haze -- When the camera is underwater fix clouds clipping into moon
// camera above water: class1\defered\cloudsF.glsl
// camera below water: class2\windlight\coudsV.glsl
// See: starsV.glsl, cloudsV.glsl, moonF.glsl
gl_FragDepth = 0.999985;
}

View File

@ -130,13 +130,32 @@ void LLDrawPoolSky::renderSkyFace(U8 index)
face->renderIndexed();
}
else // Moon
if (index == LLVOSky::FACE_MOON)
{
LLGLSPipelineDepthTestSkyBox gls_skybox(true, true); // SL-14113 Write depth for moon so stars can test if behind it
LLGLEnable blend(GL_BLEND);
// if (LLGLSLShader::sNoFixedFunction) // TODO: Necessary? is this always true? We already bailed on gPipeline.canUseWindLightShaders ... above
LLViewerTexture* tex = face->getTexture(LLRender::DIFFUSE_MAP);
if (tex)
{
gMoonProgram.bind(); // SL-14113 was gOneTextureNoColorProgram
gGL.getTexUnit(0)->bind(tex, true);
face->renderIndexed();
}
}
else // heavenly body faces, no interp...
{
LLGLSPipelineDepthTestSkyBox gls_skybox(true, false); // reset to previous
LLGLEnable blend(GL_BLEND);
LLViewerTexture* tex = face->getTexture(LLRender::DIFFUSE_MAP);
if (tex)
{
gOneTextureNoColorProgram.bind();
gGL.getTexUnit(0)->bind(tex, true);
face->renderIndexed();
}

View File

@ -270,8 +270,8 @@ void LLDrawPoolWLSky::renderStars(const LLVector3& camPosLocal) const
gGL.rotatef(gFrameTimeSeconds*0.01f, 0.f, 0.f, 1.f);
if (LLGLSLShader::sNoFixedFunction)
{
gCustomAlphaProgram.bind();
gCustomAlphaProgram.uniform1f(sCustomAlpha, star_alpha.mV[3]);
gStarsProgram.bind();
gStarsProgram.uniform1f(sCustomAlpha, star_alpha.mV[3]);
}
else
{
@ -288,7 +288,7 @@ void LLDrawPoolWLSky::renderStars(const LLVector3& camPosLocal) const
if (LLGLSLShader::sNoFixedFunction)
{
gCustomAlphaProgram.unbind();
gStarsProgram.unbind(); // SL-14113 was gCustomAlphaProgram
}
else
{
@ -476,7 +476,8 @@ void LLDrawPoolWLSky::renderSkyClouds(const LLVector3& camPosLocal, F32 camHeigh
void LLDrawPoolWLSky::renderHeavenlyBodies()
{
LLGLSPipelineBlendSkyBox gls_skybox(true, false);
//LLGLSPipelineBlendSkyBox gls_skybox(true, false);
LLGLSPipelineBlendSkyBox gls_skybox(true, true); // SL-14113 we need moon to write to depth to clip stars behind
LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin();
gGL.pushMatrix();
@ -606,8 +607,8 @@ void LLDrawPoolWLSky::renderDeferred(S32 pass)
if (gPipeline.canUseWindLightShaders())
{
renderSkyHazeDeferred(origin, camHeightLocal);
renderStarsDeferred(origin);
renderHeavenlyBodies();
renderStarsDeferred(origin);
renderSkyCloudsDeferred(origin, camHeightLocal, cloud_shader);
}
gGL.setColorMask(true, true);
@ -625,8 +626,8 @@ void LLDrawPoolWLSky::render(S32 pass)
LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin();
renderSkyHaze(origin, camHeightLocal);
renderHeavenlyBodies();
renderStars(origin);
renderHeavenlyBodies();
renderSkyClouds(origin, camHeightLocal, cloud_shader);
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);

View File

@ -78,7 +78,7 @@ LLGLSLShader gTransformTangentProgram;
//utility shaders
LLGLSLShader gOcclusionProgram;
LLGLSLShader gOcclusionCubeProgram;
LLGLSLShader gCustomAlphaProgram;
LLGLSLShader gCustomAlphaProgram; // SL-14113 This used to be used for the stars with Atmospheric Shaders: OFF
LLGLSLShader gGlowCombineProgram;
LLGLSLShader gSplatTextureRectProgram;
LLGLSLShader gGlowCombineFXAAProgram;
@ -148,6 +148,8 @@ LLGLSLShader gSkinnedObjectFullbrightShinyWaterProgram;
LLGLSLShader gSkinnedObjectShinySimpleWaterProgram;
//environment shaders
LLGLSLShader gMoonProgram;
LLGLSLShader gStarsProgram;
LLGLSLShader gTerrainProgram;
LLGLSLShader gTerrainWaterProgram;
LLGLSLShader gWaterProgram;
@ -819,6 +821,9 @@ void LLViewerShaderMgr::unloadShaders()
gWaterProgram.unload();
gWaterEdgeProgram.unload();
gUnderWaterProgram.unload();
gMoonProgram.unload();
gStarsProgram.unload();
gTerrainProgram.unload();
gTerrainWaterProgram.unload();
gGlowProgram.unload();
@ -1051,6 +1056,32 @@ BOOL LLViewerShaderMgr::loadShadersEnvironment()
llassert(success);
}
if (success)
{
gStarsProgram.mName = "Environment Stars Shader";
gStarsProgram.mShaderFiles.clear();
gStarsProgram.mShaderFiles.push_back(make_pair("environment/starsV.glsl", GL_VERTEX_SHADER_ARB));
gStarsProgram.mShaderFiles.push_back(make_pair("environment/starsF.glsl", GL_FRAGMENT_SHADER_ARB));
gStarsProgram.mShaderLevel = mShaderLevel[SHADER_ENVIRONMENT];
success = gStarsProgram.createShader(NULL, NULL);
llassert(success);
}
if (success)
{
gMoonProgram.mName = "Environment Moon Shader";
gMoonProgram.mShaderFiles.clear();
gMoonProgram.mShaderFiles.push_back(make_pair("environment/moonV.glsl", GL_VERTEX_SHADER_ARB));
gMoonProgram.mShaderFiles.push_back(make_pair("environment/moonF.glsl", GL_FRAGMENT_SHADER_ARB));
gMoonProgram.mShaderLevel = mShaderLevel[SHADER_ENVIRONMENT];
success = gMoonProgram.createShader(NULL, NULL);
if (success)
{
gMoonProgram.bind();
gMoonProgram.uniform1i(sTex0, 0);
}
}
if (!success)
{
mShaderLevel[SHADER_ENVIRONMENT] = 0;

View File

@ -234,6 +234,8 @@ extern LLGLSLShader gSkinnedObjectFullbrightShinyWaterProgram;
extern LLGLSLShader gSkinnedObjectShinySimpleWaterProgram;
//environment shaders
extern LLGLSLShader gMoonProgram;
extern LLGLSLShader gStarsProgram;
extern LLGLSLShader gTerrainProgram;
extern LLGLSLShader gTerrainWaterProgram;
extern LLGLSLShader gWaterProgram;