diff options
author | Graham Linden <graham@lindenlab.com> | 2018-06-08 22:22:20 +0100 |
---|---|---|
committer | Graham Linden <graham@lindenlab.com> | 2018-06-08 22:22:20 +0100 |
commit | 507c4921826e73635f6ae31087ab0e6cd1280f43 (patch) | |
tree | 1f6a5aba26ba21f43ae79b3eddd1f8d5a458c481 /indra | |
parent | 363f7f84a149c0bc4fe21df80aead821f02a7ff0 (diff) |
Add specific shader for the moon to allow different rendering at day vs night.
Add MouseMoon positioning ala MouseSun debug setting and accessors to use it.
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llrender/llshadermgr.cpp | 4 | ||||
-rw-r--r-- | indra/newview/app_settings/logcontrol.xml | 2 | ||||
-rw-r--r-- | indra/newview/app_settings/settings.xml | 11 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/windlight/moonF.glsl | 58 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/windlight/moonV.glsl | 48 | ||||
-rw-r--r-- | indra/newview/lldrawpoolwlsky.cpp | 18 | ||||
-rw-r--r-- | indra/newview/llsky.cpp | 14 | ||||
-rw-r--r-- | indra/newview/llsky.h | 2 | ||||
-rw-r--r-- | indra/newview/lltoolgun.cpp | 9 | ||||
-rw-r--r-- | indra/newview/llviewershadermgr.cpp | 25 | ||||
-rw-r--r-- | indra/newview/llviewershadermgr.h | 1 | ||||
-rw-r--r-- | indra/newview/llvosky.cpp | 36 | ||||
-rw-r--r-- | indra/newview/llvosky.h | 2 |
13 files changed, 219 insertions, 11 deletions
diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index fd187b99ee..f00d97cd47 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -552,8 +552,8 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& if (log.length() > 0) { - LL_INFOS("ShaderErrors") << "Shader loading from " << fname << ":\n" << LL_ENDL; - LL_INFOS("ShaderErrors") << log << LL_ENDL; + LL_DEBUGS() << "Shader loading from " << fname << ":\n" << LL_ENDL; + LL_DEBUGS() << log << LL_ENDL; } } diff --git a/indra/newview/app_settings/logcontrol.xml b/indra/newview/app_settings/logcontrol.xml index 951c8edcc7..670dfe2dec 100644 --- a/indra/newview/app_settings/logcontrol.xml +++ b/indra/newview/app_settings/logcontrol.xml @@ -50,8 +50,8 @@ </array> <key>tags</key> <array> + <string>ShaderErrors/string> <!-- sample entry for debugging specific items - <string>ShaderLoading</string> <string>Avatar</string> <string>Inventory</string> <string>SceneLoadTiming</string> diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 04237a6012..8649484d2f 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -6617,6 +6617,17 @@ <key>Value</key> <integer>0</integer> </map> + <key>MouseMoon</key> + <map> + <key>Comment</key> + <string /> + <key>Persist</key> + <integer>0</integer> + <key>Type</key> + <string>Boolean</string> + <key>Value</key> + <integer>0</integer> + </map> <key>MuteAmbient</key> <map> <key>Comment</key> diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl new file mode 100644 index 0000000000..14b08b1da4 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -0,0 +1,58 @@ +/** + * @file moonF.glsl + * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2005, 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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +vec3 fullbrightAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light); + +uniform vec4 color; +uniform vec4 sunlight_color; +uniform vec3 lumWeights; +uniform float minLuminance; +uniform sampler2D diffuseMap; +VARYING vec2 vary_texcoord0; + +void main() +{ + vec4 c = texture2D(diffuseMap, vary_texcoord0.xy); + c.rgb = fullbrightAtmosTransport(c.rgb); + c.rgb = fullbrightScaleSoftClip(c.rgb); + c.rgb = pow(c.rgb, vec3(0.45f)); + // mix factor which blends when sunlight is brighter + // and shows true moon color at night + float mix = dot(normalize(sunlight_color.rgb), lumWeights); + mix = smoothstep(-0.5f, 2.0f, lum); + frag_color = vec4(c.rgb, mix * c.a); +} + diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl new file mode 100644 index 0000000000..7c4dfbd999 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/windlight/moonV.glsl @@ -0,0 +1,48 @@ +/** + * @file moonV.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 texture_matrix0; +uniform mat4 modelview_matrix; +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; + +//void calcAtmospherics(vec3 inPositionEye); + +VARYING vec2 vary_texcoord0; + +void main() +{ + //transform vertex + vec4 vert = vec4(position.xyz, 1.0); + vec4 pos = (modelview_matrix * vert); + + gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + + //calcAtmospherics(pos.xyz); +} diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp index c6abba95bc..7a7739da03 100644 --- a/indra/newview/lldrawpoolwlsky.cpp +++ b/indra/newview/lldrawpoolwlsky.cpp @@ -52,7 +52,7 @@ LLPointer<LLImageRaw> LLDrawPoolWLSky::sCloudNoiseRawImage = NULL; static LLGLSLShader* cloud_shader = NULL; static LLGLSLShader* sky_shader = NULL; - +static LLGLSLShader* moon_shader = NULL; LLDrawPoolWLSky::LLDrawPoolWLSky(void) : LLDrawPool(POOL_WL_SKY) @@ -109,6 +109,11 @@ void LLDrawPoolWLSky::beginRenderPass( S32 pass ) LLPipeline::sUnderWaterRender ? &gObjectFullbrightNoColorWaterProgram : &gWLCloudProgram; + + moon_shader = + LLPipeline::sUnderWaterRender ? + &gObjectFullbrightNoColorWaterProgram : + &gWLMoonProgram; } void LLDrawPoolWLSky::endRenderPass( S32 pass ) @@ -275,6 +280,7 @@ void LLDrawPoolWLSky::renderStars(void) const void LLDrawPoolWLSky::renderSkyClouds(const LLVector3& camPosLocal, F32 camHeightLocal) const { +#if REMOVE_BEFORE_FLIGHT if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS) && sCloudNoiseTexture.notNull()) { LLGLEnable blend(GL_BLEND); @@ -289,6 +295,7 @@ void LLDrawPoolWLSky::renderSkyClouds(const LLVector3& camPosLocal, F32 camHeigh cloud_shader->unbind(); } +#endif } void LLDrawPoolWLSky::renderHeavenlyBodies() @@ -311,7 +318,7 @@ void LLDrawPoolWLSky::renderHeavenlyBodies() LLFace * face = gSky.mVOSkyp->mFace[LLVOSky::FACE_MOON]; - if (gSky.mVOSkyp->getMoon().getDraw() && face->getGeomCount()) + if (gSky.mVOSkyp->getMoon().getDraw() && face->getGeomCount() && moon_shader) { // *NOTE: even though we already bound this texture above for the // stars register combiners, we bind again here for defensive reasons, @@ -328,8 +335,9 @@ void LLDrawPoolWLSky::renderHeavenlyBodies() if (gPipeline.canUseVertexShaders()) { - gHighlightProgram.bind(); - gHighlightProgram.uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV); + moon_shader->bind(); + moon_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV); + moon_shader->uniform3fv(LLShaderMgr::GLOW_LUM_WEIGHTS, 1, LLPipeline::RenderGlowLumWeights.mV); } LLFacePool::LLOverrideFaceColor color_override(this, color); @@ -338,7 +346,7 @@ void LLDrawPoolWLSky::renderHeavenlyBodies() if (gPipeline.canUseVertexShaders()) { - gHighlightProgram.unbind(); + moon_shader->unbind(); } } } diff --git a/indra/newview/llsky.cpp b/indra/newview/llsky.cpp index 41fe206ada..bb108fa6ac 100644 --- a/indra/newview/llsky.cpp +++ b/indra/newview/llsky.cpp @@ -136,6 +136,20 @@ void LLSky::setSunAndMoonDirectionsCFR(const LLVector3 &sun_direction, const LLV } } +void LLSky::setSunDirectionCFR(const LLVector3 &sun_direction) +{ + if(mVOSkyp.notNull()) { + mVOSkyp->setSunDirectionCFR(sun_direction); + } +} + +void LLSky::setMoonDirectionCFR(const LLVector3 &moon_direction) +{ + if(mVOSkyp.notNull()) { + mVOSkyp->setMoonDirectionCFR(moon_direction); + } +} + ////////////////////////////////////////////////////////////////////// // Public Methods ////////////////////////////////////////////////////////////////////// diff --git a/indra/newview/llsky.h b/indra/newview/llsky.h index 8e86853481..4b3b06b33f 100644 --- a/indra/newview/llsky.h +++ b/indra/newview/llsky.h @@ -53,6 +53,8 @@ public: // These directions should be in CFR coord sys (+x at, +z up, +y right) void setSunAndMoonDirectionsCFR(const LLVector3 &sun_direction, const LLVector3 &moon_direction); + void setSunDirectionCFR(const LLVector3 &sun_direction); + void setMoonDirectionCFR(const LLVector3 &moon_direction); LLColor4 getSkyFogColor() const; diff --git a/indra/newview/lltoolgun.cpp b/indra/newview/lltoolgun.cpp index fb96804bfa..ee757f2566 100644 --- a/indra/newview/lltoolgun.cpp +++ b/indra/newview/lltoolgun.cpp @@ -108,7 +108,14 @@ BOOL LLToolGun::handleHover(S32 x, S32 y, MASK mask) if (gSavedSettings.getBOOL("MouseSun")) { LLVector3 sunpos = LLViewerCamera::getInstance()->getAtAxis(); - gSky.setSunAndMoonDirectionsCFR(sunpos, -sunpos); + gSky.setSunDirectionCFR(sunpos); + gSavedSettings.setVector3("SkySunDefaultPosition", LLViewerCamera::getInstance()->getAtAxis()); + } + + if (gSavedSettings.getBOOL("MouseMoon")) + { + LLVector3 moonpos = LLViewerCamera::getInstance()->getAtAxis(); + gSky.setMoonDirectionCFR(moonpos); gSavedSettings.setVector3("SkySunDefaultPosition", LLViewerCamera::getInstance()->getAtAxis()); } diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 820e18290f..48c72d8dc0 100644 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -176,7 +176,7 @@ LLGLSLShader gImpostorProgram; // WindLight shader handles LLGLSLShader gWLSkyProgram; LLGLSLShader gWLCloudProgram; - +LLGLSLShader gWLMoonProgram; // Effects Shaders LLGLSLShader gGlowProgram; @@ -250,6 +250,7 @@ LLViewerShaderMgr::LLViewerShaderMgr() : //ONLY shaders that need WL Param management should be added here mShaderList.push_back(&gWLSkyProgram); mShaderList.push_back(&gWLCloudProgram); + mShaderList.push_back(&gWLMoonProgram); mShaderList.push_back(&gAvatarProgram); mShaderList.push_back(&gObjectShinyProgram); mShaderList.push_back(&gObjectShinyNonIndexedProgram); @@ -828,6 +829,7 @@ void LLViewerShaderMgr::unloadShaders() gWLSkyProgram.unload(); gWLCloudProgram.unload(); + gWLMoonProgram.unload(); gPostColorFilterProgram.unload(); gPostNightVisionProgram.unload(); @@ -3480,6 +3482,7 @@ BOOL LLViewerShaderMgr::loadShadersWindLight() { gWLSkyProgram.unload(); gWLCloudProgram.unload(); + gWLMoonProgram.unload(); gDownsampleMinMaxDepthRectProgram.unload(); gInscatterRectProgram.unload(); return TRUE; @@ -3503,7 +3506,7 @@ BOOL LLViewerShaderMgr::loadShadersWindLight() success = gWLSkyProgram.createShader(NULL, NULL); } - if (success && (mVertexShaderLevel[SHADER_WINDLIGHT] < 3)) + if (success) { gWLCloudProgram.mName = "Windlight Cloud Program"; //gWLCloudProgram.mFeatures.hasGamma = true; @@ -3515,6 +3518,24 @@ BOOL LLViewerShaderMgr::loadShadersWindLight() success = gWLCloudProgram.createShader(NULL, NULL); } + if (success && (mVertexShaderLevel[SHADER_WINDLIGHT] < 3)) + { + gWLMoonProgram.mName = "Windlight Moon Program"; + gWLMoonProgram.mShaderFiles.clear(); + gWLMoonProgram.mFeatures.calculatesAtmospherics = true; + gWLMoonProgram.mFeatures.hasTransport = true; + gWLMoonProgram.mFeatures.hasGamma = true; + gWLMoonProgram.mFeatures.hasAtmospherics = true; + gWLMoonProgram.mFeatures.isFullbright = true; + gWLMoonProgram.mFeatures.disableTextureIndex = true; + gWLMoonProgram.mShaderGroup = LLGLSLShader::SG_SKY; + gWLMoonProgram.mShaderFiles.push_back(make_pair("windlight/moonV.glsl", GL_VERTEX_SHADER_ARB)); + gWLMoonProgram.mShaderFiles.push_back(make_pair("windlight/moonF.glsl", GL_FRAGMENT_SHADER_ARB)); + gWLMoonProgram.mShaderLevel = mVertexShaderLevel[SHADER_WINDLIGHT]; + gWLMoonProgram.mShaderGroup = LLGLSLShader::SG_SKY; + success = gWLMoonProgram.createShader(NULL, NULL); + } + return success; } diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h index 10c60187f3..d4967ca5a5 100644 --- a/indra/newview/llviewershadermgr.h +++ b/indra/newview/llviewershadermgr.h @@ -279,6 +279,7 @@ extern LLGLSLShader gImpostorProgram; // WindLight shader handles extern LLGLSLShader gWLSkyProgram; extern LLGLSLShader gWLCloudProgram; +extern LLGLSLShader gWLMoonProgram; // Post Process Shaders extern LLGLSLShader gPostColorFilterProgram; diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index fc83218b1a..6d066ecfd9 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -1354,3 +1354,39 @@ void LLVOSky::setSunAndMoonDirectionsCFR(const LLVector3 &sun_dir_cfr, const LLV LLSkyTex::stepCurrent(); } + +void LLVOSky::setSunDirectionCFR(const LLVector3 &sun_dir_cfr) +{ + mSun.setDirection(sun_dir_cfr); + + mLastLightingDirection = mSun.getDirection(); + + // Push the sun "South" as it approaches directly overhead so that we can always see bump mapping + // on the upward facing faces of cubes. + { + // Same as dot product with the up direction + clamp. + F32 sunDot = llmax(0.f, sun_dir_cfr.mV[2]); + sunDot *= sunDot; + + // Create normalized vector that has the sunDir pushed south about an hour and change. + LLVector3 adjustedDir = (sun_dir_cfr + LLVector3(0.f, -0.70711f, 0.70711f)) * 0.5f; + + // Blend between normal sun dir and adjusted sun dir based on how close we are + // to having the sun overhead. + mBumpSunDir = adjustedDir * sunDot + sun_dir_cfr * (1.0f - sunDot); + mBumpSunDir.normalize(); + } + + updateDirections(); + + LLSkyTex::stepCurrent(); +} + +void LLVOSky::setMoonDirectionCFR(const LLVector3 &moon_dir_cfr) +{ + mMoon.setDirection(moon_dir_cfr); + + updateDirections(); + + LLSkyTex::stepCurrent(); +} diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h index 4de3d12068..3d77c3f8e9 100644 --- a/indra/newview/llvosky.h +++ b/indra/newview/llvosky.h @@ -239,6 +239,8 @@ public: // directions provided should already be in CFR coord sys (+x at, +z up, +y right) void setSunAndMoonDirectionsCFR(const LLVector3 &sun_dir, const LLVector3 &moon_dir); + void setSunDirectionCFR(const LLVector3 &sun_direction); + void setMoonDirectionCFR(const LLVector3 &moon_direction); bool updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 side, LLHeavenBody& hb, const LLVector3 &up, const LLVector3 &right); void updateReflectionGeometry(LLDrawable *drawable, F32 H, const LLHeavenBody& HB); |