|
Replies:
5
-
Last Post:
May 21, 2008 11:59 AM
by: martinezmj
|
|
|
|
|
|
|
Transparency: I can see A through B, but not B through A. Why?
Posted:
May 15, 2008 12:28 PM
|
|
|
I have a large Java3D project for which I'm trying to work out a last few bugs. It lets users add shapes and control color and transparency of those shapes. Unfortunately, the order the shapes are added seems to affect transparency.
If for example, two spheres are added, A and B, and each is set to 50% transparency. If A is added first, you will not be able to see A through B, but if you rotate the scene you will be able to see B through A.
What might be causing this behavior? Any thoughts would be appreciated. Thanks.
Michael
|
|
|
|
|
|
|
Re: Transparency: I can see A through B, but not B through A. Why?
Posted:
May 15, 2008 1:36 PM
in response to: martinezmj
|
|
|
Hi,
RenderingAttributes ra = new RenderingAttributes(); ra.setDepthBufferEnable(true); appearance.setRenderingAttributes(ra);
should fix it
|
|
|
|
|
|
|
|
Re: Transparency: I can see A through B, but not B through A. Why?
Posted:
May 15, 2008 2:43 PM
in response to: gmrolf
|
|
|
Unfortunately, this did not fix it.
|
|
|
|
|
|
|
|
Re: Transparency: I can see A through B, but not B through A. Why?
Posted:
May 16, 2008 1:41 AM
in response to: martinezmj
|
|
|
View.setTransparencySortingPolicy(View.TRANSPARENCY_SORT_GEOMETRY) will sort the shapes back to front on the center of the shapes. This will often help. Be aware that it is often impossible to render transparent objects correctly if the objects overlap or is non convex.
Make sure View.setDepthBufferFreezeTransparent() is true. You should only turn it off if you want to transparent object to be able to write to the depth buffer.
|
|
|
|
|
|
|
|
Re: Transparency: I can see A through B, but not B through A. Why?
Posted:
May 16, 2008 1:43 AM
in response to: martinezmj
|
|
|
Hello again,
not totally sure if this is your problem (your note was a bit short), but I'll try, since I had a similiar problem a few month ago.
3D Transparency is always a tricky thing. To render transparent triangles, they have to be ordered according to their distance to the eye point (painter algorithm). Even that would be a bad solution, since it does not cover situations when two triangles intersect, but it is the best that can be done with current hardware. If your scene contains transparent and non-transparent objects, it gets even worse: the non-transparent triangles have to be rendered first (with z-buffer enabled) and the transparent triangles afterward - with zbuffer disabled. That is also the reason why it can happen that you see A throuh B but not vice versa if the tiranlges are not rendered in the correct order.
Java3d itself can sort Shape3d objects, but does not sort the triangles, so you have to take care of that by yourself. Either you can split up your objects into smaller shapes or implement a thread that does the sorting in the background. Whatever you do, it will decrease FPS, thats in the nature of transparency in 3D.
Ingo
|
|
|
|
|
|
|
|
Re: Transparency: I can see A through B, but not B through A. Why?
Posted:
May 21, 2008 11:59 AM
in response to: martinezmj
|
|
|
First, my initial description of the problem was not correct. It did not matter which shape (A or B) was added first, it was always the shape on the right side of space that was rendered on top of the other, regardless of whether it was in front or in back of it.
I eventually figured out that the problem had to do with setting the ViewingPlatform transform [i.e., universe.getViewingPlatform().getViewPlatformTransform().setTransform(viewTransform)]. That is, I was setting this transform to set the model back (in Z) so that it would all fit in the window. Otherwise the model was too close to the viewer.
Maybe this was throwing off the direction of the viewing perspective (???) which was causing the rendering order to be relative to a direction other than the viewer (???). I'm really not sure... maybe someone can give a better explanation.
So instead of setting the transform in ViewingPlatform, I set the transform in the TransformGroup that handles the MouseZoom. Now it's all working.
Michael
|
|
|
|
|