override all materials in a compositor render_scene

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
mogumbo
Gnoblar
Posts: 14
Joined: Thu Sep 14, 2017 4:14 pm
x 1

override all materials in a compositor render_scene

Post by mogumbo »

In Ogre 1.9.1 when doing a render_scene in a compositor, is it possible to override all materials with one material? I know this must be possible on some level for things like shadow maps to be rendered, but I can't find an example of it being done in compositors. I've read a lot of things that suggest maybe material schemes are the tool for this, but I can't find a detailed explanation of how to use them in this way.
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: override all materials in a compositor render_scene

Post by loath »

yes, you need to use a material scheme.

the RTSS is implemented this way so you could look at that code for examples. in fact the RTSS documentation has a small writeup about it:
https://ogrecave.github.io/ogre/api/13/rtss.html (search for scheme)

i believe the SSAO and deferred examples also use the material scheme mechanism for other examples.
mogumbo
Gnoblar
Posts: 14
Joined: Thu Sep 14, 2017 4:14 pm
x 1

Re: override all materials in a compositor render_scene

Post by mogumbo »

Thanks Loath,
Material schemes are the way to go. Someone else also pointed me to MaterialManager::Listener. Its documentation in OgreMain/include/OgreMaterialManager.h talks about "a simple way to replace all materials with another using a scheme." You can call a scheme that is undefined in your material files and then define it in code with something like this:

Code: Select all

// Override all scene materials with custom material when a specific scheme is named
class MySchemeListener : public Ogre::MaterialManager::Listener
{
public:
  MySchemeListener() {}

  Ogre::Technique* handleSchemeNotFound(unsigned short scheme_index,
    const Ogre::String& scheme_name, Ogre::Material* original_material, unsigned short lod_index,
    const Ogre::Renderable* renderable)
  {
    Ogre::ResourcePtr res = Ogre::MaterialManager::getSingleton().load("MyOverrideMaterial",
                                                                       Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    Ogre::MaterialPtr material = res.staticCast<Ogre::Material>();

    Ogre::Technique* technique = original_material->createTechnique();
    technique->setSchemeName(scheme_name);
    Ogre::Pass* pass = technique->createPass();
    *pass = *material->getTechnique(0)->getPass(0);

    return technique;
  }
};
MySchemeListener my_scheme_listener;

MaterialManager::getSingleton().addListener(&my_scheme_listener, "MyOverrideScheme");
Post Reply