Use ShaderVisitor to skip translucent framebuffer specific stuff

pull/3044/head
AnyOldName3 4 years ago
parent 35fab97478
commit b6e92c9c6d

@ -16,6 +16,8 @@
#include <components/debug/debuglog.hpp>
#include <components/fallback/fallback.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/resource/resourcesystem.hpp>
#include <components/sceneutil/lightmanager.hpp>
#include <components/sceneutil/shadow.hpp>
@ -249,6 +251,7 @@ namespace MWRender
void CharacterPreview::setBlendMode()
{
mResourceSystem->getSceneManager()->recreateShaders(mNode, "objects", true);
SetUpBlendVisitor visitor;
mNode->accept(visitor);
}

@ -370,7 +370,6 @@ namespace MWRender
mRootNode->getOrCreateStateSet()->addUniform(new osg::Uniform("near", mNearClip));
mRootNode->getOrCreateStateSet()->addUniform(new osg::Uniform("far", mViewDistance));
mRootNode->getOrCreateStateSet()->addUniform(new osg::Uniform("simpleWater", false));
mRootNode->getOrCreateStateSet()->addUniform(new osg::Uniform("noAlpha", false));
mUniformNear = mRootNode->getOrCreateStateSet()->getUniform("near");
mUniformFar = mRootNode->getOrCreateStateSet()->getUniform("far");

@ -247,9 +247,9 @@ namespace Resource
return mForceShaders;
}
void SceneManager::recreateShaders(osg::ref_ptr<osg::Node> node, const std::string& shaderPrefix)
void SceneManager::recreateShaders(osg::ref_ptr<osg::Node> node, const std::string& shaderPrefix, bool translucentFramebuffer)
{
osg::ref_ptr<Shader::ShaderVisitor> shaderVisitor(createShaderVisitor(shaderPrefix));
osg::ref_ptr<Shader::ShaderVisitor> shaderVisitor(createShaderVisitor(shaderPrefix, translucentFramebuffer));
shaderVisitor->setAllowedToModifyStateSets(false);
node->accept(*shaderVisitor);
}
@ -749,7 +749,7 @@ namespace Resource
stats->setAttribute(frameNumber, "Node Instance", mInstanceCache->getCacheSize());
}
Shader::ShaderVisitor *SceneManager::createShaderVisitor(const std::string& shaderPrefix)
Shader::ShaderVisitor *SceneManager::createShaderVisitor(const std::string& shaderPrefix, bool translucentFramebuffer)
{
Shader::ShaderVisitor* shaderVisitor = new Shader::ShaderVisitor(*mShaderManager.get(), *mImageManager, shaderPrefix+"_vertex.glsl", shaderPrefix+"_fragment.glsl");
shaderVisitor->setForceShaders(mForceShaders);
@ -759,6 +759,7 @@ namespace Resource
shaderVisitor->setAutoUseSpecularMaps(mAutoUseSpecularMaps);
shaderVisitor->setSpecularMapPattern(mSpecularMapPattern);
shaderVisitor->setApplyLightingToEnvMaps(mApplyLightingToEnvMaps);
shaderVisitor->setTranslucentFramebuffer(translucentFramebuffer);
return shaderVisitor;
}

@ -76,7 +76,7 @@ namespace Resource
Shader::ShaderManager& getShaderManager();
/// Re-create shaders for this node, need to call this if texture stages or vertex color mode have changed.
void recreateShaders(osg::ref_ptr<osg::Node> node, const std::string& shaderPrefix = "objects");
void recreateShaders(osg::ref_ptr<osg::Node> node, const std::string& shaderPrefix = "objects", bool translucentFramebuffer = false);
/// @see ShaderVisitor::setForceShaders
void setForceShaders(bool force);
@ -173,7 +173,7 @@ namespace Resource
private:
Shader::ShaderVisitor* createShaderVisitor(const std::string& shaderPrefix = "objects");
Shader::ShaderVisitor* createShaderVisitor(const std::string& shaderPrefix = "objects", bool translucentFramebuffer = false);
std::unique_ptr<Shader::ShaderManager> mShaderManager;
bool mForceShaders;

@ -40,6 +40,7 @@ namespace Shader
, mAutoUseNormalMaps(false)
, mAutoUseSpecularMaps(false)
, mApplyLightingToEnvMaps(false)
, mTranslucentFramebuffer(false)
, mShaderManager(shaderManager)
, mImageManager(imageManager)
, mDefaultVsTemplate(defaultVsTemplate)
@ -146,7 +147,7 @@ namespace Shader
mRequirements.back().mShaderRequired = true;
}
}
else
else if (!mTranslucentFramebuffer)
Log(Debug::Error) << "ShaderVisitor encountered unknown texture " << texture;
}
}
@ -322,6 +323,8 @@ namespace Shader
writableStateSet->addUniform(new osg::Uniform("colorMode", reqs.mColorMode));
defineMap["translucentFramebuffer"] = mTranslucentFramebuffer ? "1" : "0";
osg::ref_ptr<osg::Shader> vertexShader (mShaderManager.getShader(mDefaultVsTemplate, defineMap, osg::Shader::VERTEX));
osg::ref_ptr<osg::Shader> fragmentShader (mShaderManager.getShader(mDefaultFsTemplate, defineMap, osg::Shader::FRAGMENT));
@ -474,4 +477,9 @@ namespace Shader
mApplyLightingToEnvMaps = apply;
}
void ShaderVisitor::setTranslucentFramebuffer(bool translucent)
{
mTranslucentFramebuffer = translucent;
}
}

@ -40,6 +40,8 @@ namespace Shader
void setApplyLightingToEnvMaps(bool apply);
void setTranslucentFramebuffer(bool translucent);
void apply(osg::Node& node) override;
void apply(osg::Drawable& drawable) override;
@ -63,6 +65,8 @@ namespace Shader
bool mApplyLightingToEnvMaps;
bool mTranslucentFramebuffer;
ShaderManager& mShaderManager;
Resource::ImageManager& mImageManager;

@ -209,8 +209,11 @@ void main()
#endif
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, gl_Fog.color.xyz, fogValue);
#if @translucentFramebuffer
// having testing & blending isn't enough - we need to write an opaque pixel to be opaque
if (noAlpha)
gl_FragData[0].a = 1.0;
#endif
applyShadowDebugOverlay();
}

Loading…
Cancel
Save