Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Weird rendering order  (Read 4523 times)
0 Members and 1 Guest are viewing this topic.
Offline darkpegasus

Senior Newbie





« Posted 2007-09-30 21:31:19 »

Since I can't answer my own question (today) this will probably sit here forever, but let's try anyway...

I've just started in Java3D and I'm noticing some odd behavior in the following. As you can see, I have a 2D grid of objects that rotates around the x axis. However, as it does so, it sometimes appears that objects that should be behind are overlapping the objects in front of them.

My best guess is that the objects in the back are being rendered after the ones in front of them. If that's the case, anyway to force the rendering order? Any help would be appreciated.

Some images of what it looks like as it rotates:
<img src="http://i65.photobucket.com/albums/h233/darkpegasus5/Ea/front-view.jpg" />

<img src="http://i65.photobucket.com/albums/h233/darkpegasus5/Ea/distorted-view.jpg" />

<img src="http://i65.photobucket.com/albums/h233/darkpegasus5/Ea/side-view.jpg" />
Offline broumbroum

Junior Member





« Reply #1 - Posted 2007-09-30 21:53:35 »

that can be sort of Z-index or field-depth, isn't it ? I've never used J3D but this is how I understand back or foreground.

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2007-09-30 22:11:12 »

Enabled depth-sorting.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline darkpegasus

Senior Newbie





« Reply #3 - Posted 2007-09-30 22:54:51 »

I kind of figured there should be a flag like that somewhere that could be set. This may be a stupid question, but where? I went through every book I have and the API and couldn't find a place to set depth sorting as either a method or a flag in SimpleUniverse, BranchGroup, Canvas3D, GraphicsConfiguration, or the ViewPort classes.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2007-09-30 22:59:25 »

Google for "Java3D Depth buffer" and check out the first hit.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline darkpegasus

Senior Newbie





« Reply #5 - Posted 2007-10-01 00:15:20 »

My first hit came up as <a href="http://www.starfireresearch.com/services/java3d/supplementalDocumentation.html">this</a> Not sure if that's where you were pointing me but I'm not seeing anything helpful.

While I know you are trying to help and can appreciate the "teach a man to fish" thing, I know this can't be more than a few lines of code setting some int or boolean somewhere. Sometimes just seeing the two lines of code sparks more than the hours of googling, thumbing through books, reading the java3d tutorial pdfs, and searching the forum archives.

I was originally told to enable depth-sorting but it wouid seem what I should really be looking at is the depth buffer instead. If so, I thought that it was already defaulted to LESS_OR_EQUAL. If it just needs to be turned on, then that's where I'm not sure how it should be done. With the Appearance object I can use RenderingAttributes so I guess I was expecting something similiar for a BranchGroup.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2007-10-01 07:17:00 »

Hm... is google personalizing the hit-results or what...

I got this link:
http://java.sun.com/products/java-media/3D/forDevelopers/J3D_1_3_API/j3dapi/javax/media/j3d/RenderingAttributes.html

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline darkpegasus

Senior Newbie





« Reply #7 - Posted 2007-10-02 01:38:21 »

That is odd. I tried googling with two different computers and got a different result than that both times (they were both the same).

Appearance app = new Appearance();
RenderingAttributes ra = new RenderingAttributes();
ra.setDepthBufferEnable(true);
app.setRenderingAttributes(ra);

Since both Appearance and RenderingAttributes are NodeComponent subclasses I would think that I could just use the following:

RenderingAttributes ra = new RenderingAttributes();
ra.setDepthBufferEnable(true);

Although this is the point where I get lost. Where do I set the ra in the scenegraph? BranchGroup is a subclass of Node and I haven't found any methods that allow me to set RenderingAttributes like I can in Appearance. I tried using this with each object  that I added to the scene, but that didn't work either.
Offline tom
« Reply #8 - Posted 2007-10-02 14:50:22 »

Are you sure the model is not transparent in some way. Depth write is disabled by default on transparent objects. You could try the following:
View.setTransparencySortingPolicy(View.TRANSPARENCY_SORT_GEOMETRY)

This will sort the objects back to front.

Offline darkpegasus

Senior Newbie





« Reply #9 - Posted 2007-10-03 01:58:03 »

That appears to have been it, thanks. I had the following method call in my constructor. So does that mean there isn't any way to currently use any type of transparency and still maintain the front to back rendering? In this instance all of the objects were set to opaque anyway.

setVisibility(IBoardConstants.VISIBLE);

   public void setVisibility(int visibility)
     {
       // let transparency value change at run time
       transAtt = new TransparencyAttributes();
       transAtt.setTransparencyMode(TransparencyAttributes.BLENDED);
       transAtt.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);

       if (visibility == IBoardConstants.VISIBLE)
       {
         visualState = visibility;
         transAtt.setTransparency(0.0f);     // opaque
       }
       if (visibility == IBoardConstants.INVISIBLE)
       {
          visualState = visibility;
          transAtt.setTransparency(1.0f);
       }
       cellApp.setTransparencyAttributes(transAtt);
     }  // end of setVisibility()
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #10 - Posted 2007-10-03 08:29:22 »

You can use View.setDepthBufferFreezeTransparent(false) to enable depth write on transparent object. Then the depth buffer attributes will work in the same way as on opaque objects. Transparency is a pain in the neck because of the depth buffer issues. Use it only when you must.

If you just want to hide your object there is two other ways to do it. One is to use a switch to switch between a an empty BranchGroup and the visible object. The other is to use RenderingAttributes.setVisible(boolean) on the objects Appearance.

Offline darkpegasus

Senior Newbie





« Reply #11 - Posted 2007-10-04 02:26:11 »

All very useful things to know. Thank you for your help Tom, I really appreciate it.
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #12 - Posted 2007-10-05 04:43:11 »


Alright guys, I am having the same problem with transparent objects.
Here is the situation.

All objects that are transparent are drawn properly before a HUD is added.
However, when I add a HUD and start removing and adding Objects to the scene graph, then I get issues listed above.

Here is the structure of my HUD.  The HUD branchgroup contains quad arrays that have an image applied to them as a texture.
1  
2  
3  
TransformGroup (Camera Location)
   -> Platform
   -> BranchGroup (HUD)


Here are some images that illistrate my problem.

Before branchgroup action


After branchgroup action


Ubuntu
Offline tom
« Reply #13 - Posted 2007-10-05 09:43:14 »

Have you tried using an OrderedGroup to render the hud after the platform. Might help.

Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #14 - Posted 2007-10-05 16:43:57 »

Do you mean to have a structure like this?

1  
2  
3  
TransformGroup (Camera Location)
    -> Platform
    -> OrderedGroup (HUD)

Ubuntu
Offline tom
« Reply #15 - Posted 2007-10-05 21:01:06 »

Sorry, I did not see that you meant ViewPlatform, meaning this is on the view branch. Then you OrderedGroup wont work.

Unfortunately it is impossible to do a decent hud in Java3D. What you want is to first draw the level, then draw the hud. In Java3D there is always a catch. Here is the alternatives:

1) use Canvas3D.postRender()
Performance is rubbish

2) Put the hud in the view side, under viewTG (cameraTG).
The hud will not move relative to the viewTG. But there is no way to force the rendereing order so one has to rely on the depth buffer. You can try to move it as close to the view as possible, but there will problem with the level geometry moving infront of the hud.

3) Use an OrderedGroup on the level side of the scene graph.
The hud has to be placed under a TransformGroup wich synced with the viewTG. The problem is how to sync the to viewTGs. WakeupOnTransformChange behior on the viewTG can not be used to update the viewTG on the level side because the transform wont be set until the next frame. So the hud will lag after the view. See the same problem with Billboards. Can be the best solution if you only set the viewTG form one place, and can update both at the same time, in a behavior.

4) Never use the TransformGroup attached to ViewPlatorm.
Instead have a TransformGroup at the root of the level geometry to move the camera. Then an OrderedGroup under to force level rendering before hud. This would probably work, but performance should suffer because all the level is constantly moved with the view.

Your using 2). In wich case you should enable depth write with View.setDepthBufferFreezeTransparent(false), move the hud as close to the fornt clipping plane as possible and hope for the best.

Btw, the screenshots are to small to see what is going on

Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #16 - Posted 2007-10-06 04:20:37 »

Alright.  Here are some more (larger) screenshots

The first 2 screens are how it looks when transparency is being rendered corectly




Here the cockpit (which is transparent) is being rendered on-top of the body of the craft




I've also tried to set the depth buffer as well as the sorting policy and am still getting the problem.

....

Alright, looks like I found the problem but i"m not sure why its a problem ... maybe some-one can shed some light on this.

So in order to take a screenshot, I created a second Canvas3D object and added this to the view.  Then when the user asks for a screenshot, the second canvas is used for rendering the screen and then an image is taken from it and eventually saved out.

When I don't include the 2nd canvas to the view, the problem goes away (this is with the depth buffer and sorting policy set).  Any ideas why this is the case?

Ubuntu
Offline micxiao

Senior Newbie





« Reply #17 - Posted 2007-11-14 09:35:09 »



hi i am having a problem with depth buffer for objects that are supposed to be intersecting. can anyhow help figure out what is the problem?

i already turned on the depthbuffer and it works fine. just the problem with intersecting objects like shown in the picture above.

help me please it's giving me a headache  Cry
Offline micxiao

Senior Newbie





« Reply #18 - Posted 2007-11-15 03:59:34 »

i think i figured out the problem. It's because i gave all my geometries a transparencyattributes.

is there any way at all to depth buffer intersecting transparent objects properly? per-geometry doesn't work because my objects are intersecting...  Sad
Offline micxiao

Senior Newbie





« Reply #19 - Posted 2007-11-15 09:44:56 »

I just thought of something to solve my own problem!!!

i just switch off transparency whenever the value of transparency is 0~

i hope it works~  Smiley

edit: ya it works now~  Grin
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (57 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!