GLSL shader doesn't work in RTT ?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Rusty Rooster
Posts: 11
Joined: Thu May 24, 2018 6:43 pm
Location: USA

GLSL shader doesn't work in RTT ?

Post by Rusty Rooster »

Hi,

I am having trouble with OpenGL GLSL and Render Targets. In my case, a GLSL shader which works fine when we do a normal rendering doesn't work anymore when we render the same scene to a RenderTargetTexture. To test, I added the following code to the Irrlicht Shader tutorial (using the shaders provided in the tutorial) to create a simple RTT:

In main()

Code: Select all

 
    video::ITexture* rt = 0;
    //make the render target texture to draw the view window
    rt = driver->addRenderTargetTexture(core::dimension2d<u32>(128,128), "RTT1",irr::video::ECF_A8R8G8B8);
 
    device->getGUIEnvironment()->addImage(
            rt,
            core::position2d<s32>(0,50));
 
In while(device->run())

Code: Select all

 
if (rt)
        {
            // draw scene into render target
            // set render target texture
            driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,255));
            smgr->drawAll();
 
            // set back old render target
            // The buffer might have been distorted, so clear it
            driver->setRenderTarget(0, true, true, 0);
        }
 
Then, in the "normal" screen we see both cubes correctly rendered, but in the RTT view, one of the shaders doesn't display (see through to the background).

BUT, If I run with low level shaders instead of GLSL (choosing not to run high level shaders), then both cubes render correctly in the RTT view.

Any thoughts? I'm new to shaders and I would rather try to write them in GLSL than in the shader assembly language, for obvious reasons. I'm using OpenGL and GLSL 4.4, and also Cg shaders aren't supported. I'm using RTT because the 3d view is only a portion of the GUI in my game.

Thanks
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: GLSL shader doesn't work in RTT ?

Post by CuteAlien »

It seems to have a problem with the shader returning transparent pixels for a solid material. So opengl.frag returning a gl_fragColor.a value < 1.
What you see in the transparent parts (of the solid shader) seems to be the stuff rendered into the frame buffer. Workaround - don't return transparent pixels in the solid shader.

I'll try to find some time to debug more - maybe I can figure out why it behaves different for RTT's.

edit: I did spend a little more time on it, but so far Irrlicht does what I would expect. It calls glDisable(GL_BLEND) for that material. But maybe that doesn't work for renderbuffers as there seem to exist functions like glDisableIndexedEXT and glDisablei (with OGL 3.0). So if anyone knows more about this - ideas welcome...
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
Rusty Rooster
Posts: 11
Joined: Thu May 24, 2018 6:43 pm
Location: USA

Re: GLSL shader doesn't work in RTT ?

Post by Rusty Rooster »

Yes, setting col.a = 1.0 in the frag shader seemed to fix the problem. Thanks.
Post Reply