Mixing parallel and perspective projection in the same frame

Hi

is it possible to render a scene using perspective projection, then switch to parallel and render a few more things over the top each frame?

Endolf

Yes, of course.

This is possible? How? I think you have to set parallel and perspective mode in View - and you can’t change it during rendering, because that’s jogl/lwjgl doing and only one call in Xith3d.

Any hints as to how? :slight_smile:

I mean, I can figure out that I do something like


view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
view.renderOnce();

view.setProjectionPolicy(View.PARALLEL_PROJECTION);

but at that point, if I call view.renderOnce() again, the scene has the 3d parts in it, and not the 2d parts. I don’t want to have to start removing objects from the scene tree and placing other ones in it, twice a frame, every frame. Also, I have a background, and if I renderOnce again I’ll lose what I rendered the first time won’t i?

Endolf

I’ve never worked with Java3D or Xith3D but…

Can’t you use the SwitchNode to switch between the 2D/3D branches then?

If this sounds like I completely missed the point, I probably did :slight_smile:

I could yes, I just want to make sure that when I draw the second part of the frame, that I don’t end up clearing the buffer at the same time, ie, I still need what I last rendered. I think xith does an equivelant of a glClear

Endolf

Whoops, sorry, I just noticed this is the Xith3D forums. ;D

So does anyone know how to tell xith to ‘draw this frame over the top of the prvious one, allowing any transparent objects to show what was drawn the frame before’?

Endolf

I think this would require a modification in the Xith code, because the screen shouldn’t be filled with the background color between the 2 renders.

This sounds like an issue relating to multi-pass. Unfortuantely Xith3D has never really implemented this feature – there are other nice things like render to texture that fall in the same bucket (I think). Yuri has raised this topic previously on a few occasions.

If you have an idea on how best to implement this, please start a dialog on the topic :slight_smile:

Will.

I looked at the CanvasPeerImpl code for jogl. There is a function called setDisableClearBuffer(boolean disable), which turns the glClear off.
So you can mix parallel and perspective, you’ll only have to remember your CanvasPeerImpl and switch setDisableClearBuffer on and off.

Arne

endolf have you tried this?

Perhaps we should make it an abstract RenderOption so LWJGL can implement it too. Potentially you could simply have two RenderOptions objects lying around and just swich them in and out each frame.

Will.

Ok so i got this kind of rendering loop. It’s working very nicely exept for one small but annoying thing (which is obious) - the hud flickers a bit.


			// run the rendering loops
			mySceneGraph.setRenderable(true);
			myHud.setRenderable(false);
			view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
			canvasPeer.setDisableClearBuffer(false);
			view.renderOnce();
			
			mySceneGraph.setRenderable(false);
			myHud.setRenderable(true);
			view.setProjectionPolicy(View.PARALLEL_PROJECTION);
			canvasPeer.setDisableClearBuffer(true);
			view.renderOnce();

How can i do in xith so that the buffers dont get swapped automatically, intsead i would swap it after im done rendering the hud.
Can this be done? Yes. ::slight_smile:
How?


Edit:

Ok I found out how to disable the automatic swapping.

canvasPeer.setForceNoSwap(true);

But now i dont know how to swap it manually… :-[

may be exposing the glFlush() instruction ?

(search for renderDone() in canvas peer impl)

Lilian

I have tried this:


canvasPeer.setForceNoSwap(true);

while(true)
{
    // run the rendering loops
    mySceneGraph.setRenderable(true);
    myHud.setRenderable(false);
    view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
    canvasPeer.setDisableClearBuffer(false);
    view.renderOnce();

    mySceneGraph.setRenderable(false);
    myHud.setRenderable(true);
    view.setProjectionPolicy(View.PARALLEL_PROJECTION);
    canvasPeer.setDisableClearBuffer(true);
    view.renderOnce();

    canvasPeer.getGl().glFlush();

… but it didnt work.

Ok, i figured out a way to do it :slight_smile:
Thanks to all that helped!!

Here is what i did in case someone finds this useful:



// render loop
while(true)
{
    // render the scene, clearing the buffer before doing it
    mySceneGraph.setRenderable(true);
    myHud.setRenderable(false);
    canvasPeer.setDisableClearBuffer(false);
    canvasPeer.setForceNoSwap(true);
    view.renderOnce();
    view.setProjectionPolicy(View.PARALLEL_PROJECTION);

    // render the hud, not clearing the buffer before
    mySceneGraph.setRenderable(false);
    myHud.setRenderable(true);
    canvasPeer.setDisableClearBuffer(true);
    canvasPeer.setForceNoSwap(false);
    view.renderOnce();
    view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);

}

So sum it up i keep the setForceNoSwap as true as long as i still want ro render more frames and finally set it to false before the final frame rendering.

Great ! and does it work really well ?
Your GUI is made of textured quads, aren’t there ? But are they simply foreground nodes ?

Now we should try and encapsulate it …

may be with a Switch node and a MultiPassView(View) (each switch beeing a pass) ?

Lilian

nice … very nice :smiley:

MultiPassView sounds nice…
maybe we could do it like this?:


class MultiPassView extends View {
  ArrayList<Switch> renderpasses;
  public void addRenderPass(Switch s) { renderpasses.add(s); }
  public void removeRenderPass(Switch s) ..
  public void render() {
    for(Switch s : renderpasses) {
      // set settings, activate switch and render
     // deactivate switch
    }
  }
}

or we could also add a class RenderPass, where we can set the combination of switches, that should be set during that render pass.

Anybody even better ideas?

Arne

Thanks. :slight_smile:

[quote="<MagicSpark.org [ BlueSky ]>,post:17,topic:24436"]
Great ! and does it work really well ?
Your GUI is made of textured quads, aren’t there ? But are they simply foreground nodes ?
[/quote]
Yes it works quite well indeed with no performance loss.
Or, hmm… I havent faced any problems yet but also havent had the time to test it extensively.

I havent really built up the gui yet (just two foreground node shapes so i can see that it renders).
Infact i still havent really decided how ill implement the gui… ::slight_smile:
Textured quads sounds like a good idea for a traditional gui.
Though, I cant get over the idea to make a really 3D ui with interactive components… :stuck_out_tongue: Something like switches and such things. It would be cool but lets see, maybe ill end up with a “simple 2D” gui.

Sounds great!
But let me ask (maybe) a stupid question:
Why need multiple Switches? Wouldnt just one do if it contains for example BranchGroups that represent the different passes?
Please correct me if i missed something… :wink: