Page 1 of 1

Implementing "irradiance" background

Posted: Thu Jun 04, 2020 5:18 pm
by tct
Ogre Version: 2.1
Operating System: Windows, Linux
Render System: OpenGL 3+

I'm currently studying the source code of Ogre v2 mesh viewer to get a better understanding of how to work with Ogre.
The application provides something it calls "irradiant background" which can also be seen on the screenshots (the green-white-brown background which behaves like a skybox):
Image

I'm trying to understand what is are the minimum components & configurations I need to achieve this in my own application.

The following code snipped is located in the main manager class:

Code: Select all

void OgreManager::setIrradianceBackground()
{
    Ogre::String autoGroup = Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME;
    auto& texMgr = Ogre::TextureManager::getSingleton();

    Ogre::TexturePtr irradiance = texMgr.getByName("irradiance_bg");
    if (irradiance.isNull())
    {
        Ogre::TexturePtr tex = texMgr.getByName("env.dds", autoGroup);

        Ogre::Image img;
        tex->convertToImage(img, true, tex->getNumMipmaps() - 4); // 4 looks better

        irradiance = texMgr.createManual("irradiance_bg", autoGroup,
                                         Ogre::TEX_TYPE_CUBE_MAP, 
                                         img.getWidth(), img.getHeight(), 
                                         Ogre::MIP_DEFAULT /* mipmap */, img.getFormat());
        irradiance->loadImage(img);
    }
    Ogre::MaterialPtr mtl = Ogre::MaterialManager::getSingleton().getByName("SkyPostprocess");
    Ogre::TextureUnitState* texUnit = mtl->getTechnique(0)->getPass(0)->getTextureUnitState(0);
    texUnit->setTextureName("irradiance_bg", Ogre::TEX_TYPE_CUBE_MAP);
}
My questions:
  • Do I need anything other than that and the corresponding material & shader files? I am very unsure at this point whether I also need to setup a compositor script at this stage. That's certainly what the application does (link) but I am having a hard time understanding whether I need that as well as I don't understand compositors yet.
  • I've come agross *.dds files before when looking at Ogre examples. However, I'm having a hard time understanding what those files and where they come from. Is this simply an asset format for skyboxes/cubemaps?

Re: Implementing "irradiance" background

Posted: Thu Jun 04, 2020 6:46 pm
by dark_sylinc
Note: Due to improvements in PBR made in 2.2, you probably want to use 2.2.1 once you've become accostumed to Ogre this out.
tct wrote:
Thu Jun 04, 2020 5:18 pm
Do I need anything other than that and the corresponding material & shader files? I am very unsure at this point whether I also need to setup a compositor script at this stage. That's certainly what the application does (link) but I am having a hard time understanding whether I need that as well as I don't understand compositors yet.
The links you're pointing to are 99% of what you need, but in order to use them there is probably some compositor script somewhere using a pass_quad to render a quad with the skybox texture as the background.

Regarding compositors: It may be time you start learning. I promise they don't bite!
As a brief summary all compositors do is:
  • 'Clear the texture to black'
  • 'Draw this group of objects into texture A'
  • 'Now draw this rectangle into screen with this image and this shader into texture A'
  • 'Now draw this other group of objects into texture A'
  • 'Finally switch to render window, and render this rectangle with texture A and this copy shader' (which effectively just copies the contents from A into the render window)
That's almost all there is to it. It's like applying layers on top like Photoshop does.

The only thing I didn't mention are shadow mapping nodes (which is essentially very similar, but describing how to draw shadows / what shadows to draw using which method).

Compositor passes can be chained together and they can become very complex or be kept very simple. That is up to the one writing the compos. script.
tct wrote:
Thu Jun 04, 2020 5:18 pm
Is this simply an asset format for skyboxes/cubemaps?
DDS is a container for textures. It's like PNG but supports lots of GPU formats (PNG is limited to RGB 24/48 bits, RGBA 32/64 bits, monochrome R 8/16 bits), as well as supporting many common features used by GPUs (storing mipmaps, multiple faces for cubemaps, etc).
And yes, that includes skyboxes/cubemaps which this one is.
texconv can convert from/to DDS back and forth. Recent versions of Visual Studio can open DDS files as if it were a texture editor. There are also several DDS viewers and editors, and plugins for Photoshop and GIMP.

Re: Implementing "irradiance" background

Posted: Sat Jun 27, 2020 7:44 pm
by tct
Sorry for the late reply - some other projects got pushed in-between.
Note: Due to improvements in PBR made in 2.2, you probably want to use 2.2.1 once you've become accostumed to Ogre this out.
I'm using the Ogre v2 Mesh Viewer to build the meshes I load into my application. This is working in my v2.1 based application. Is there anything that would keep me from using that tool when migrating to Ogre 2.2.1?

I'll start looking into compositors!

Re: Implementing "irradiance" background

Posted: Sat Jun 27, 2020 9:19 pm
by dark_sylinc
There were no changes in the mesh file formats between 2.1 and 2.2, thus it should work.