The quad pass has support for assigning the textures via CompositorPassQuadDef::addQuadTextureSource where it is possible to specify texture unit and texture name. Together with mExposedTextures it is possible to process the information in the HLMS and setup the binding correctly and without any hard-coded relation to specific quad passes.
However in scene pass, I don't see such support. I have a scene pass A which renders to 2 textures and then next scene pass B which should bind the already rendered 2 textures and use them in a pixel shader for all the renderables. At the moment I see 2 options:
- inherit the CompositorPassSceneDef and CompositorPassScene and add the similar support for the texture sources as in quad pass and process the pass in the HLMS (general way, but more typing to implement the classes, however the HLMS implementation would be simpler)
- use custom identifiers and access them in HLMS and hard-code the binding there for each identifier separately (reusing already existing ogre classes, but the HLMS implementation is uglier)
Is there any built-in support in Ogre to do some "automatic" bindings of the rendered textures?
Just for a reference, for the quad passes, I wrote in my HLMS following code, which could be reused, if texture sources are available for scene pass as well:
Code: Select all
// Get the current compositor pass.
if (const auto* pCompositorPassQuad = dynamic_cast<const CompositorPassQuad*>(mCurrentSceneManager->getCurrentCompositorPass()); pCompositorPassQuad != nullptr)
{
// Bind the textures from the CompositorPassQuad.
const auto& sceneManagerCompositorTextures = mCurrentSceneManager->getCompositorTextures();
const auto* pCompositorPassQuadDef = static_cast<const CompositorPassQuadDef*>(pCompositorPassQuad->getDefinition());
for (const auto& textureSource : pCompositorPassQuadDef->getTextureSources())
{
// Find the compositor texture.
const auto found = std::find(sceneManagerCompositorTextures.begin(), sceneManagerCompositorTextures.end(), textureSource.textureName);
if (found == sceneManagerCompositorTextures.end())
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Invalid compositor texture!", "HlmsTech::fillBuffersFor");
// Set binding type. The compositor textures are bound always just to pixel shaders.
if (mRenderSystem->getCapabilities()->hasCapability(RSC_COMPLETE_TEXTURE_BINDING))
mRenderSystem->_setBindingType(TextureUnitState::BT_FRAGMENT);
// Set the texture to the render system.
mRenderSystem->_setTexture(textureSource.texUnitIdx, found->texture, false);
}
}
