[osg-users] Repeatable rendering of subgraphs, ideas?

Paul Martz pmartz at skew-matrix.com
Thu Nov 12 10:07:05 PST 2009


I think my custom RenderStage is the only approach for what you 
describe, because the number of passes can't be known until draw time. 
In your case, you could override RenderStage::draw and iteratively call 
uniform::apply and RenderBin::draw. See my post in this thread, in which 
I include basic code for creating a custom RenderStage, for a head start.

If you want the freedom of being able to ignore OSG's state mechanism 
and make the OpenGL calls directly, this is pretty easy to implement for 
a single display (one update/cull/draw per frame).

For the multi-display case (one update, multiple cull/draw per frame), 
things get a bit trickier. Each draw traversal will have its own 
context, so you need to track the uniform IDs and other object IDs in a 
thread-safe per-context map. This is what osg::buffered_value is for.

Any time you're doing any kind of custom cull/draw code, keep in mind 
that these are read-only traversals. Do not modify the scene graph 
during cull or draw, unless you have a thread-safe way to do so.

This is fairly advanced OSG coding and requires a pretty thorough 
knowledge of how the CullVisitor works, and how RenderStages and bins 
are organized in the draw graph. One sure way to learn this stuff is to 
try to code it :-) . The OSG source is open for all to look at. None of 
its secrets are hidden.
    -Paul



Paulo Silva wrote:
> Hi,
> 
> can I add something here?
> What about a simple multipass (unknown until the draw stage), with rendering done by a glsl shader, and shader variable update in function of the pass, like:
> 
> void render() {
>     setGlslProg(prog); //which uses uniform_x
> 
>     for(i(0); i != num_of_passes; ++i) {
>         //change the same uniform in function of the pass i
>         uniform_x->set(i / num_of_passes);
>         render(node); //actually render pass i!
>     }
> }
> 
> This is somewhat similar to what is being discussed here, and also conceptually incredibly simple, but apparently very complicated to implement with osg. Apparently you cannot change the uniform in your own implementation of the cull_draw traversal, as suggested early, because in the end all passes will be rendered with the same uniform value!?
> As if the cull_draw did not actually submit the geometry to GL between passes. (still have to check it out in the code).
> 
> Ideas? 
> 
> Thank you!
> 
> Cheers,
> Paulo
> 



More information about the osg-users mailing list