[osg-users] Multiple render targets

J.P. Delport jpdelport at csir.co.za
Fri Sep 14 05:53:04 PDT 2007


Hi,

OK, here goes.

Attached you will find a modified RenderStage.cpp. I see that I modified 
OSG version 6386, so hopefully you can merge the changes with the latest 
SVN version. RenderStage lives in src/osgUtil.

You can either look at the diff to latest version, or search for "JP" in 
the file.

The hacky part is this: You call in your code e.g.
camera->setDrawBuffer(GL_COLOR_ATTACHMENT3_EXT);
this sets up 4 draw buffers, 0 to 3.

If you call e.g.
camera->setDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
it will set up 2 buffers.

You must also call camera->setReadBuffer(GL_COLOR_ATTACHMENT0_EXT); for 
enabling readback.

You can attach readback images as per normal (>1 possible), see the 
example I attach.

The example shows how I used MRT with 4 textures with floats, one shader 
just creates 4 textures, the other combines them again.

What needs to be done to get to a patch:

In short, I'm abusing GL_COLOR_ATTACHMENT* values to get my intention to 
use MRT into RenderStage.

We need some mechanism to store/assign more than one drawbuffer inside 
"camera" and possibly a flag to indicate we want MRT. RenderStage can 
then inherit/query these values to properly call glDrawBuffer(s).

If you have time, give it a bash.

cheers
jp


John Donovan wrote:
> Ah! That'd explain it :) Thanks JP.
> It would be handy to have a look at what you've done; perhaps we can both faff
> about with it to make it submittable.
> 
> -J
> 
> J.P. Delport wrote:
>> Hi,
>>
>> as far as I know its not supported in current version of OSG, there is 
>> no call to glDrawBuffers (as opposed to glDrawBuffer) which is needed 
>> for MRT.
>>
>> I have a version of RenderStage.cpp that I modified to allow MRT for one 
>> of our projects, but its a hack and I still need to properly organise it 
>> before I can submit a patch.
>>
>> I can post it with instructions if you want it?
>>
>> regards
>> jp
>>
>>
>> John Donovan wrote:
>>> Hi,
>>> is there anything else I need to do to render to two textures with the same
>>> fragment shader? I have the following code:
>>> 		cam->setRenderTargetImplementation(Camera::FRAME_BUFFER_OBJECT);
>>> cam->attach(Camera::COLOR_BUFFER0, _texture.get());
>>> cam->attach(Camera::COLOR_BUFFER1, _texture2.get());
>>>
>>> And the following fragment shader:
>>> void main(void)
>>> {
>>>     gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);
>>>     gl_FragData[1] = vec4(0.4, 0.4, 0.0, 1.0);
>>> }
>>>
>>> The first texture comes out red as expected, but the second one (which is
>>> identical in size and format as the first) comes out black.
>>>
>>> -J
>>>
>>>
>>> ______________________________________________________________________
>>> This email has been scanned by the MessageLabs Email Security System.
>>> For more information please visit http://www.messagelabs.com/email 
>>> ______________________________________________________________________
>>> _______________________________________________
>>> osg-users mailing list
>>> osg-users at lists.openscenegraph.org
>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>>
> 
> 
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email 
> ______________________________________________________________________
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 

-- 
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OSG_MRT.zip
Type: application/zip
Size: 12735 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20070914/b878ef35/attachment-0003.zip>


More information about the osg-users mailing list