[osg-users] RTT multipass on same geometry

2011-09-21 Thread Sebastian Messerschmidt

Hello,

I've have a question regarding RenderToTexture in a multipass setup.
I have to RTT cameras, the first one has DEPTH and 3 color attachments, 
while the second has only one color attachment.
I need to use the data from the first RTT-pass in the second camera, so 
the renderorder is set accordingly.


Basically my scene is organized like this:

root
|
RTTCamera_1
||Model
RTTCamera_2
||Model

Booth cameras use the same geometry, viewport, transform. Yet the Model 
graph is culled twice.
Is there any way to prevent the second cull traversal? I.e. reuse the 
batch collected in the first culling?


cheers
Sebastian
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] RTT multipass on same geometry

2011-09-21 Thread Paul Martz

On 9/21/2011 10:54 AM, Sebastian Messerschmidt wrote:

Hello,

I've have a question regarding RenderToTexture in a multipass setup.
I have to RTT cameras, the first one has DEPTH and 3 color attachments, while 
the second has only one color attachment.
I need to use the data from the first RTT-pass in the second camera, so the 
renderorder is set accordingly.


Basically my scene is organized like this:

root
|
RTTCamera_1
||Model
RTTCamera_2
||Model

Booth cameras use the same geometry, viewport, transform. Yet the Model graph 
is culled twice.
Is there any way to prevent the second cull traversal? I.e. reuse the batch 
collected in the first culling?


In OSG, culling (the CullVisitor) also collects state. Since you are almost 
certainly using two different shaders (one that writes to three targets, another 
which writes to one), it's unlikely that OSG's state graph can be reused in your 
situation.

   -Paul


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] RTT multipass on same geometry

2011-09-21 Thread Sebastian Messerschmidt

Thank you Paul,

It seems a little bit more obvious now.
Basically I need to write some additional value to one of the COLOR 
attachments alpha channel, which is derived from the first pass.
So my second approach (which seems to be failing) is somehow to write 
only to those texels in my color attachment of the second pass, where 
depth != far.
Right now I really feel stupid, as I thought that there must be any easy 
way to do so.
Any ideas how to render extra properties to the color buffer attachment 
at the positions that have been written in the first pass without 
re-rendering the whole scene?




On 9/21/2011 10:54 AM, Sebastian Messerschmidt wrote:

Hello,

I've have a question regarding RenderToTexture in a multipass setup.
I have to RTT cameras, the first one has DEPTH and 3 color 
attachments, while the second has only one color attachment.
I need to use the data from the first RTT-pass in the second camera, 
so the renderorder is set accordingly.


Basically my scene is organized like this:

root
|
RTTCamera_1
||Model
RTTCamera_2
||Model

Booth cameras use the same geometry, viewport, transform. Yet the 
Model graph is culled twice.
Is there any way to prevent the second cull traversal? I.e. reuse the 
batch collected in the first culling?


In OSG, culling (the CullVisitor) also collects state. Since you are 
almost certainly using two different shaders (one that writes to three 
targets, another which writes to one), it's unlikely that OSG's state 
graph can be reused in your situation.

   -Paul


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] RTT multipass on same geometry

2011-09-21 Thread Thrall, Bryan
Sebastian Messerschmidt wrote on 2011-09-21: 
> Thank you Paul,
> 
> It seems a little bit more obvious now. Basically I need to write some
> additional value to one of the COLOR attachments alpha channel, which is
> derived from the first pass. So my second approach (which seems to be
> failing) is somehow to write only to those texels in my color attachment
> of the second pass, where depth != far. Right now I really feel stupid,
> as I thought that there must be any easy way to do so. Any ideas how to
> render extra properties to the color buffer attachment at the positions
> that have been written in the first pass without re-rendering the whole
> scene?

You could write to the stencil buffer in the first pass, then render a 
full-screen quad with the stencil test enabled on the second pass to only write 
to the pixels written to in the first pass. osgPPU might be useful to you for 
doing this.

>> On 9/21/2011 10:54 AM, Sebastian Messerschmidt wrote:
>>> Hello,
>>> 
>>> I've have a question regarding RenderToTexture in a multipass setup.
>>> I have to RTT cameras, the first one has DEPTH and 3 color
>>> attachments, while the second has only one color attachment.
>>> I need to use the data from the first RTT-pass in the second camera,
>>> so the renderorder is set accordingly.
>>> 
>>> Basically my scene is organized like this:
>>> 
>>> root
>>> |
>>> RTTCamera_1
>>> ||Model
>>> RTTCamera_2
>>> ||Model
>>> Booth cameras use the same geometry, viewport, transform. Yet the
>>> Model graph is culled twice. Is there any way to prevent the second
>>> cull traversal? I.e. reuse the batch collected in the first culling?
>> 
>> In OSG, culling (the CullVisitor) also collects state. Since you are
>> almost certainly using two different shaders (one that writes to three
>> targets, another which writes to one), it's unlikely that OSG's state
>> graph can be reused in your situation.
>>-Paul


--
Bryan Thrall
Principal Software Engineer
FlightSafety International
bryan.thr...@flightsafety.com
  


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] RTT multipass on same geometry

2011-09-22 Thread Sebastian Messerschmidt

Thanks to all replies but I was able to figure it out.

My initial idea was to modify a color attachment created in the first 
pass in the second pass only where fragments were created(i.e. depth was 
written)

I came up with the following solution:

1. Pass
RTT-Cam1
- DEPTH, COLOR1, COLOR2, ...
- renders the scene
2. Pass
RTT-Cam2
- DEPTH, COLOR1 (same attachments as in the first pass
- depth test to GREATER
- depth writes off
- disable color and depth clearing (which we want to reuse)
- bind the COLOR1-texture as uniform input
- render a full screen quad with camera in ABSOLUTE_RF and same 
viewport as first pass
- in the frag shader for instance do: gl_FragData[0]= 
vec4(texture2D(firstPassTexture,gl_TexCoord[0].st).rgb, 0.0)  + 
vec4(0.0,0.0,0.0, myNewTerm);


This works, because the fullscreen quad rendered will pass depth test 
only if something was written there in the first pass. Using this sceme 
saves us a stencil test.


There is a remaining question however:
What I really wanted to do is to write the gl_FragData[0].rgb in the 
first and gl_FragData[0].a in the second pass.

This gave me a blank result (with the alpha component set to 1)
Do I have to enable blending or something? Or is it illegal to write 
uncomplete FragData?




Hello,

I've have a question regarding RenderToTexture in a multipass setup.
I have to RTT cameras, the first one has DEPTH and 3 color 
attachments, while the second has only one color attachment.
I need to use the data from the first RTT-pass in the second camera, 
so the renderorder is set accordingly.


Basically my scene is organized like this:

root
|
RTTCamera_1
||Model
RTTCamera_2
||Model

Booth cameras use the same geometry, viewport, transform. Yet the 
Model graph is culled twice.
Is there any way to prevent the second cull traversal? I.e. reuse the 
batch collected in the first culling?


cheers
Sebastian
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] RTT multipass on same geometry

2011-09-23 Thread Sergey Polischuk
Hi, Sebastian

You can setup blend func in a way that will keep old rgb values and replace 
alpha with new value.
for second pass -> BlendFunc(osg::BlendFunc::ZERO, osg::BlendFunc::ONE, 
osg::BlendFunc::ONE, osg::BlendFunc::ZERO).
However if you reading from same texture attached to camera output this is not 
gonna work, unless you use NV_texture_barrier extension (and it have 
limitations too).

Cheers

22.09.2011, 11:46, "Sebastian Messerschmidt" :
> Thanks to all replies but I was able to figure it out.
>
> My initial idea was to modify a color attachment created in the first
> pass in the second pass only where fragments were created(i.e. depth was
> written)
> I came up with the following solution:
>
> 1. Pass
> RTT-Cam1
>  - DEPTH, COLOR1, COLOR2, ...
>  - renders the scene
> 2. Pass
> RTT-Cam2
>  - DEPTH, COLOR1 (same attachments as in the first pass
>  - depth test to GREATER
>  - depth writes off
>  - disable color and depth clearing (which we want to reuse)
>  - bind the COLOR1-texture as uniform input
>  - render a full screen quad with camera in ABSOLUTE_RF and same
> viewport as first pass
>  - in the frag shader for instance do: gl_FragData[0]=
> vec4(texture2D(firstPassTexture,gl_TexCoord[0].st).rgb, 0.0)  +
> vec4(0.0,0.0,0.0, myNewTerm);
>
> This works, because the fullscreen quad rendered will pass depth test
> only if something was written there in the first pass. Using this sceme
> saves us a stencil test.
>
> There is a remaining question however:
> What I really wanted to do is to write the gl_FragData[0].rgb in the
> first and gl_FragData[0].a in the second pass.
> This gave me a blank result (with the alpha component set to 1)
> Do I have to enable blending or something? Or is it illegal to write
> uncomplete FragData?
>
>>  Hello,
>>
>>  I've have a question regarding RenderToTexture in a multipass setup.
>>  I have to RTT cameras, the first one has DEPTH and 3 color
>>  attachments, while the second has only one color attachment.
>>  I need to use the data from the first RTT-pass in the second camera,
>>  so the renderorder is set accordingly.
>>
>>  Basically my scene is organized like this:
>>
>>  root
>>  |
>>  RTTCamera_1
>>  |    |Model
>>  RTTCamera_2
>>  |    |Model
>>
>>  Booth cameras use the same geometry, viewport, transform. Yet the
>>  Model graph is culled twice.
>>  Is there any way to prevent the second cull traversal? I.e. reuse the
>>  batch collected in the first culling?
>>
>>  cheers
>>  Sebastian
>>  ___
>>  osg-users mailing list
>>  osg-users@lists.openscenegraph.org
>>  http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org