Skip to main content

Transparency Sorting inside GeometryArray

13 replies [Last post]
mulchi
Offline
Joined: 2010-06-18
Points: 0

Hello,

I am currently writing an application for plotting landscapes from bio-chemical activity data. It is a basic scientific visualization with some interactions for the researchers using it.

I stumbled across a problem, which I did not manage to solve. Whatever approach I use I solve one problem but get another instead.

I use a GeometryArray (i.g. a IndexedQuadArray) to draw the landscape. For that I calculate a regular grid and the z-values are my function values (nothing fancy). I use color alpha values with the colors4f of the array to make parts of the landscape invisible. This is essential for me, because some parts of my landscape don't have data or less data and need to be less visible.

Ok, here is my problem:
When I rotate my scene only in one half of the whole rotation the transparency for the geometry is calculated correctly (thus I can see through it and see other parts of the landscape). On the other "side" of the rotation I can't see the other parts of the landscape behind it, only other geometries that are behind my landscape.

Here is a screenshot of one of the landscapes that displays the problem: http://dl.dropbox.com/u/9477369/example.jpg

I wrote a small sample application so that you can actually see what I tried to describe. Just rotate it a bit. The problem is best seen when the landscape is turned bottom up and then rotated.

http://dl.dropbox.com/u/9477369/SimpleTestCase.java

Funny thing is, if I change
view.setDepthBufferFreezeTransparent(false);
to
view.setDepthBufferFreezeTransparent(true);

The see-through problem changes, but it even gets worse :-/

I'm working on Mac OSX, but I hope this does not make a difference here. Java3D Version is 1.5.2.

I hope you have a hint what to change, because it is really annoying if the users are limited to view the landscapes only from one direction to see it correctly.

Cheers,
Michael

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mulchi
Offline
Joined: 2010-06-18
Points: 0

Hi again,

I implemented it according to your description and it worked flawlessly :) You were such a big help, thank you very much!

Cheers
Michael

mulchi
Offline
Joined: 2010-06-18
Points: 0

I did an initial test. I just changed the order of my indices (reversing the indices array) and my expectation was that the angle where the transparency is correct would change by 180°. But it didn't change at all, everything is the same.

Shouldn't something change with the sorting effects when reversing the indices array?

Thank you for your answer
Michael

odinsbane
Offline
Joined: 2009-08-24
Points: 0

I tried this with your sample application and I took a huge performance hit. I think it is a bug though because in my own application it works find and I am creating about the same number of quad arrays as I did in your application.

http://www.pastie.org/1139881

I'm not sure if I got the winding of your quads correctly. plus getting rid of the line attributes will speed it up.

mbs

mulchi
Offline
Joined: 2010-06-18
Points: 0

Hi,

thanks for looking into my code and implementing your idea :-) Yes, it does indeed solve the problem but as you say the performance is not very good :-/

Maybe sorting the indices after rotation is more effective... I will try it out.

Thanks alot for you help!

michael

compiled the wrong version, thus after compiling the correct one I changed my post :)

Message was edited by: mulchi

lyfox
Offline
Joined: 2010-08-17
Points: 0

This is actually surprising. Normals are one the basic things in 3D-programming.

-----------------------------------
[b]PolygonAttributes Methods[/b]
[i]void setBackFaceNormalFlip(boolean backFaceNormalFlip)[/i]
where backFaceNormalFlip determines whether vertex normals of back facing polygons should be flipped (negated) prior to lighting. When this flag is set to true and back face culling is disabled, a polygon is rendered as if the polygon had two sides with opposing normals.
-----------------------------------
© Sun Microsystems, Inc.
(Getting Started with the Java 3D™ API / Chapter 2)
-----------------------------------

Good luck.

aces
Offline
Joined: 2003-07-17
Points: 0

Did you try to set cull mode as CULL_NONE ?
It is set at Appearance's PolygonAttributes.setCullFace(int mode)

mulchi
Offline
Joined: 2010-06-18
Points: 0

Thank you for answering to my question...

Yes, I always set this, because if I don't set it, I don't see the geometry when rotating. In the small sample I also set it in the appearance.

cheers
michael

odinsbane
Offline
Joined: 2009-08-24
Points: 0

Okay, I have a similar problem, and I was looking at the the View docs, and there is the method:

setTransparencySortingPolicy(int policy)

In the description TRANSPARENCY_SORT_GEOMETRY poilicy will only sort for different geometries so maybe if you made a bunch of geometries instead of 1 geometry. (Ie a bunch of quads instead of an indexed quad array.

mulchi
Offline
Joined: 2010-06-18
Points: 0

Yes, that would be a possibility, but I think it would be a huge drawback for the performance. Instead of one geometry I would need about 10.000 geometries for a 100x100 regular grid (if I create one geometry per patch).

But maybe I give it a try in my sample application just to try it out... I will post my findings :-)

Thanks for your answer

Michael

lamer77
Offline
Joined: 2006-12-22
Points: 0

You can sort your quads manually. Create an elapsed frames 0 behaviour that sorts all the quads every frame. You only need to update the indices so that the quads furthest from the view is first.

mulchi
Offline
Joined: 2010-06-18
Points: 0

Thats an interesting idea. Do you know if there is some code on which I could build on?

Or a method doing this fast? Because if I have to do this in every frame, it better be fast :-) All methods that I thought of are terrible slow :-/

Thanks
michael

lamer77
Offline
Joined: 2006-12-22
Points: 0

We use it in radiation visualisation software and the speed is good enough. Unfortunately the code is not mine to give away.

But I can give you as short description. At startup you calculate the center of each triangle in local space. For each frame transform view position into mesh localspace. Calculate distance from view to each triangle. Store distance as ints using Float.floatToIntBits(float). Use a radix sort to sort the indices in linear time. Set the sorted indices.

Btw, 15 years before HW acceleration most games did it this way instead of using a slow z-buffer.

mulchi
Offline
Joined: 2010-06-18
Points: 0

Thanks a lot for the explanation, I will give it a try :)

Cheers
Michael