Page 1 of 1

GLSL shader doesn't work in RTT ?

Posted: Thu May 24, 2018 7:18 pm
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

Re: GLSL shader doesn't work in RTT ?

Posted: Thu May 24, 2018 10:04 pm
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...

Re: GLSL shader doesn't work in RTT ?

Posted: Fri May 25, 2018 1:08 am
by Rusty Rooster
Yes, setting col.a = 1.0 in the frag shader seemed to fix the problem. Thanks.