Allow to assign custom shaders to nodes

pull/3022/head
Andrei Kortunov 4 years ago
parent 08fb9073c6
commit 660df19ff7

@ -242,9 +242,9 @@ namespace Resource
return mForceShaders; return mForceShaders;
} }
void SceneManager::recreateShaders(osg::ref_ptr<osg::Node> node) void SceneManager::recreateShaders(osg::ref_ptr<osg::Node> node, const std::string& shaderPrefix)
{ {
osg::ref_ptr<Shader::ShaderVisitor> shaderVisitor(createShaderVisitor()); osg::ref_ptr<Shader::ShaderVisitor> shaderVisitor(createShaderVisitor(shaderPrefix));
shaderVisitor->setAllowedToModifyStateSets(false); shaderVisitor->setAllowedToModifyStateSets(false);
node->accept(*shaderVisitor); node->accept(*shaderVisitor);
} }
@ -761,9 +761,9 @@ namespace Resource
stats->setAttribute(frameNumber, "Node Instance", mInstanceCache->getCacheSize()); stats->setAttribute(frameNumber, "Node Instance", mInstanceCache->getCacheSize());
} }
Shader::ShaderVisitor *SceneManager::createShaderVisitor() Shader::ShaderVisitor *SceneManager::createShaderVisitor(const std::string& shaderPrefix)
{ {
Shader::ShaderVisitor* shaderVisitor = new Shader::ShaderVisitor(*mShaderManager.get(), *mImageManager, "objects_vertex.glsl", "objects_fragment.glsl"); Shader::ShaderVisitor* shaderVisitor = new Shader::ShaderVisitor(*mShaderManager.get(), *mImageManager, shaderPrefix+"_vertex.glsl", shaderPrefix+"_fragment.glsl");
shaderVisitor->setForceShaders(mForceShaders); shaderVisitor->setForceShaders(mForceShaders);
shaderVisitor->setAutoUseNormalMaps(mAutoUseNormalMaps); shaderVisitor->setAutoUseNormalMaps(mAutoUseNormalMaps);
shaderVisitor->setNormalMapPattern(mNormalMapPattern); shaderVisitor->setNormalMapPattern(mNormalMapPattern);

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

Loading…
Cancel
Save