Generating realtime cubemaps

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
poljak
Posts: 9
Joined: Mon Jul 09, 2018 5:20 pm

Generating realtime cubemaps

Post by poljak »

Hello everyone,

I'm tring to compute dynamic cubemaps (mainly for use as 3d skybox + realtime cubemaps)
I use the CRTTSkyBoxSceneNode downloaded somewhere on this forum to render my 3d skybox, then I apply its cubemap to all needed nodes

During he computation I need to convert texture to an image to feed the driver->addTextureCubemap() method (I'm using Irrlicht 1.9)
http://irrlicht.sourceforge.net/forum/v ... =9&t=22268
but the textureToImage() method is a very big resource hog, and seem pointless to me.
As I already have 6 textures, why bother creating 6 images to rebuild one cubemap texture? Maybe I missed something?

Bonus question: Is there is a way in Irrlicht to compute a dynamic cubemap in one pass? Like this:
http://cg.siomax.ru/index.php/computer- ... o-cube-map

For those who prefer to see some code, here is a method I added in CRTTSkyBoxSceneNode

Code: Select all

video::IRenderTarget* rt[6]; // Declared in CRTTSkyBoxSceneNode.h
// ...
video::ITexture* generateCubemap()
{
    irr::video::IVideoDriver* driver = SceneManager->getVideoDriver();
    irr::video::IImage* cubemapImages[6];
    video::ITexture* result;
 
    for (s32 i=0; i<6; ++i)
    {
        rt[i]->getTexture()[0]->lock();
        cubemapImages[i] = Utils::textureToImage(rt[i]->getTexture()[0]);
    }
 
    result = driver->addTextureCubemap
    (
        "cube_map",
        cubemapImages[0],
        cubemapImages[1],
        cubemapImages[2],
        cubemapImages[3],
        cubemapImages[4],
        cubemapImages[5]
    );
 
    for (s32 i=0; i<6; ++i)
    {
        cubemapImages[i]->drop();
        rt[i]->getTexture()[0]->unlock();
    }
 
    return result;
}
 
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Generating realtime cubemaps

Post by CuteAlien »

Cubemap code in Irrlicht changed recently (half a year ago). You no longer need images but can render into the cubemap texture now.
I've just not managed to finish the example yet. But the nearly finished (and working) version of what will become the example can be found here:
https://bitbucket.org/mzeilfelder/irr-p ... ubemap.cpp
You also need this subfolder for the shaders (cubemap-textures need shading code): https://bitbucket.org/mzeilfelder/irr-p ... t/cubemap/

It shows how to generate cubemaps from images as well as how to create realtime cubemaps.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply