Read Depth Texture, MRT, Attach Depth?

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
ChristophLGDV
Gnoblar
Posts: 18
Joined: Mon Jun 01, 2015 3:09 pm

Read Depth Texture, MRT, Attach Depth?

Post by ChristophLGDV »

Hello,
First off, I am completely new to this forum and Ogre in general.

Secondly, I would like to read and write depth textures. I know how to do it in GL but as I said, Ogre is new.

I have no idea how to use compositors yet and I hope I don't need that.
I have implemented the MRT sample frome somewhere around here but I don't know to create a depth texture and attach a depth attachment.

I that possible, btw?




I hope for some enlightenment.
Best Regards
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5514
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1379

Re: Read Depth Texture, MRT, Attach Depth?

Post by dark_sylinc »

I answered a similar question a few days ago.

Additionally,

In Ogre, RenderTargets (RTT) have a "depth pool ID". Depth Buffers are created to match an RTT and placed in a pool.
If an existing depth buffer is compatible with the RTT and they both belong to the same pool; the depth buffer will be reused (known as depth buffer sharing).

If you want 2 different RTTs to not share the depth buffer, you need to assign them different pool IDs.
ChristophLGDV
Gnoblar
Posts: 18
Joined: Mon Jun 01, 2015 3:09 pm

Re: Read Depth Texture, MRT, Attach Depth?

Post by ChristophLGDV »

Hi dark_sylinc,
Thank you for your answer.

As my predecessor, I will do it the simple way.

Best regards
ChristophLGDV
Gnoblar
Posts: 18
Joined: Mon Jun 01, 2015 3:09 pm

Re: Read Depth Texture, MRT, Attach Depth?

Post by ChristophLGDV »

I want to extend the question. If I should put it in a new topic, I will.


How can I define additional outputs to the material.

I have implemented http://www.ogre3d.org/tikiwiki/Multiple+Render+Targets using glsl.
My shader has 2 outputs and I have created 2 Textures (RGBA8, R32F).
However, when attaching an additional surface my program crashes:

Code: Select all

Ogre::Viewport * viewMRT[2];
...
mMRT[EYE::LEFT]->bindSurface(1, depthRenderTexLeft); 
I reckon that I have to define/create that slot/unit "1" somewhere but I don't know how.

Update: OK, I fixed that:
I simply have to add
" MRT " to my technique
and

Code: Select all

viewMRT[EYE::LEFT]->setMaterialScheme("MRT");
to my viewport.
Now that I look at the upper example, it appears exaclty what was necessary. I was confused by the two materials.

However, I cannot add a PF_FLOAT32_R texture to Attachment1.
How is that?

Update:

OK found it:
RenderSystems/GL/OgreGLFrameBufferObject.cpp

Code: Select all

if(mColour[x].buffer->getGLFormat() != 
{
 StringStream ss;
 ss << "Attachment " << x << " has incompatible format.";
 ss << "BUT I IGNORE YOU!!!";
 //OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, ss.str(), "GLFrameBufferObject::initialise");
}
Removing the exception does the trick, obviously.

Now my question:
Will Ogre 2.x do away with this?





Thank you for reading.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5514
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1379

Re: Read Depth Texture, MRT, Attach Depth?

Post by dark_sylinc »

Hi,

The exception you're seeing is because not-so-long time ago (OpenGL 2.0); many drivers enforced this silly restriction (it was moronic tbh; no actual GPU HW had it to begin with). MRTs that failed to comply with this silly rule would return "incomplete attachment".
Because OpenGL has a system where in some cases the mere presence of an extension retroactively modifies the GL behavior, removing the exception will 'just work' in any modern machine.

In Ogre 2.1; as I was working on the GL3+ RenderSystem and since GL 3.3 is already the required minimum (+ some extensions), I removed this exception as any driver that was old enough to enforce the restriction wouldn't even start anyway.

For many reasons such as this one (GL 2.0 was an absolute mess for a very long time) the D3D9 RenderSystem is far superior to the GL one in Ogre 1.x

Since the GL3+ RenderSystem and Ogre 2.1 were both heavily refactored into modern practices; our OpenGL support now is on par to D3D11 or superior as long as you stick to using the more modern v2 interfaces, both feature and performance wise.
ChristophLGDV
Gnoblar
Posts: 18
Joined: Mon Jun 01, 2015 3:09 pm

Re: Read Depth Texture, MRT, Attach Depth?

Post by ChristophLGDV »

Excellent!

Thank you for your reply.

Finally I would like to know where I can find a sample that teaches me how to attach texture depth buffer and use them later on (Ogre2.1 i guess, I read some reply that hints that way.)


Best Regards