Friday, August 25, 2006

3D Depth Sorting Issues

I am having a problem with depth sorting in a 3D environment... I have tried numerous approaches but come across problems with certain situations.

My current method involves finding the z value of an objects point furthest from the camera and sorting objects by that depth.

Consider this 3d scene:




From a side view with camera shown:



You can see that the grid is further away than the cube, the depth sorting seems to be working fine. But say if I move the camera to be below the grid problems start to occur:



The depth sorting routine still thinks the grid is further away and draws the cube on top of the grid! Has anybody got any experience with this? Can anybody give me some tips?

25 comments:

Ben Stucki said...

You might consider using quaternion math to get the result of multiplying each object's position in relation to the camera (x,y,z) by the camera's angles (ca,sa). You should be able to sort by the resulting z values (Qz) for depth from the camera.

Bob said...

As Ben said, you need to calculate your z values relative to the camera as opposed to the origin.

John said...

Ben: My engine does indeed figure out the Z value in relation to the camera. I am using Matrices rather than quarternion math though. The Z values I am using to sort are the distances from the object to the camera. I am unsure how you thought I was working out the ditance from the origin?

Ben Stucki said...

I obviously had not given it enough thought before posting. All of my 3D experiments so far have been using sprites, so I haven't come across this problem yet. I'm not sure what the right solution is, but I'm definitely interested to find out.

Spyder Murphy said...

Interesting problem you have there, it would helpful to see the math behind the diagrams. My initial though is to work out the initial points that are hit by the cameras path. They would give you a more correct z.

Andre Michelle said...

You have to split the grid in smaller objects and test them separatly. As long as you work with sprites and not with single pixels (check zBuffer), there is no other solution.

You also might take a look at:
http://recycle.andre-michelle.com/as3/beta3/as3d

Andre Michelle said...

As I mentioned in my email, you should take a deeper look onto BSP-trees. They also solve a lot of Z-Sorting issues.

Pedro Miller said...

As long as the objects are whole, there does not necessarily exist a sorting where they'd be painted correctly (think o\o, cube - slanted grid - cube) -- you'd need a z-buffering technique to paint it correctly.

As Andre mentioned, one solution would be to partition your objects so you can process each piece separately. BSPs guarantee you'll split them enough.

If you can implement a Z-Buffer, however, the problem would simply go away. I'm not sure it's appropriate for your case, though.

Cheers and good luck! :)

Anonymous said...

splitting objects up and using BSPs are good hints and in many applications will get you as far as you need to get. but pedro miller, i'm not sure if BSPs will really guarantee that all will be well. when depth sorting, there are some pathological cases that are very hard to solve. does anyone have some links to good literature? (i just found this post because i'm researching this very topic at the moment.)

oh, and it's WRONG that using a Z buffer will make the problem go away. firstly, you'll want to avoid overdraw, in which case you'll want to draw front to back with a Z buffer. secondly, you might want to handle translucent or partially transparent faces, in which case you have to draw back to front. but how do you avoid overdraw now? what would carmack do?

Anonymous said...

whoopy, i made a mistake in justifying my BSP scepticism. i just gave this a little thought and now i don't see a reason do doubt the claim that a BSP will solve the problem ... BUT the real issue here is that you can't generate a BSP in real-time, thus you have to pre-compute it, and you can only pre-compute it for static chunks of geometry, i.e. geometry in which no part will move WRT another part. so if you want to guarantee that the method works throughout your entire scene, you can't have a scene in which _anything_ moves.

now if you just want to avoid overdraw, of course the sorting doesn't have to be that perfect. it would just be a performance optimization, so blowing lots of CPU cycles on making it work would be idiotic.

but if you want translucency, it would be really nice if the sorting was perfect, so you know you'll never have ugly artifacts. suggestions anyone? ;-)

<a href="http://medonlineshops.com">OnlinePharmacy</a> said...

rXIliA Your blog is great. Articles is interesting!

<a href="http://m1.aol.com/CoryDyer55/index.html">about phentermine</a> said...

CJtAXG Thanks to author.

<a href="http://m1.aol.com/IvySalas33/31_261007.html">diet meridia pill site web</a> said...

Good job!

<a href="http://members.ospa.us/portal_memberdata/portraits/tmkeqhjef">christi corpus hotel motel</a> said...

Hello all!

name said...

Hello all!

<a href="http://anipalk.t35.com/index1.html">charity kenya tour</a> said...

Hello all!

<a href="http://hatasad.110mb.com/index5.html">4-wheeler tour</a> said...

Thanks to author.

<a href="http://www.optimising.biz/portal_memberdata/portraits/tyfyegzix">beauticians insurance</a> said...

Nice Article.

<a href="http://learning.hsc.hccs.edu/portal_memberdata/portraits/tnglpmobm">ringtones</a> said...

Nice Article.

<a href="http://www.bcrobotics.org/portal_memberdata/portraits/tunaqpwhm">Money to loan classifieds&lt;</a> said...

Hello all!

<a href="http://m1.aol.com/EloyRowe59/2-291007.html">generic cialis</a> said...

7TjRL0 actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.

<a href="http://freeringtones.99k.org/download-free-ringtones-to-cellphone-.html">download free ring</a> said...

Magnific!

air bed said...

black mold exposureblack mold symptoms of exposurewrought iron garden gatesiron garden gates find them herefine thin hair hairstylessearch hair styles for fine thin hairnight vision binocularsbuy night vision binocularslipitor reactionslipitor allergic reactionsluxury beach resort in the philippines

afordable beach resorts in the philippineshomeopathy for eczema.baby eczema.save big with great mineral makeup bargainsmineral makeup wholesalersprodam iphone Apple prodam iphone prahacect iphone manualmanual for P 168 iphonefero 52 binocularsnight vision Fero 52 binocularsThe best night vision binoculars here

night vision binoculars bargainsfree photo albums computer programsfree software to make photo albumsfree tax formsprintable tax forms for free craftmatic air bedcraftmatic air bed adjustable info hereboyd air bedboyd night air bed lowest pricefind air beds in wisconsinbest air beds in wisconsincloud air beds

best cloud inflatable air bedssealy air beds portableportables air bedsrv luggage racksaluminum made rv luggage racksair bed raisedbest form raised air bedsaircraft support equipmentsbest support equipments for aircraftsbed air informercialsbest informercials bed airmattress sized air beds

bestair bed mattress antique doorknobsantique doorknob identification tipsdvd player troubleshootingtroubleshooting with the dvd playerflat panel television lcd vs plasmaflat panel lcd television versus plasma pic the bestThe causes of economic recessionwhat are the causes of economic recessionadjustable bed air foam The best bed air foam

hoof prints antique equestrian printsantique hoof prints equestrian printsBuy air bedadjustablebuy the best adjustable air bedsair beds canadian storesCanadian stores for air beds

migraine causemigraine treatments floridaflorida headache clinicdrying dessicantair drying dessicantdessicant air dryerpediatric asthmaasthma specialistasthma children specialistcarpet cleaning dallas txcarpet cleaners dallascarpet cleaning dallas

air bed said...

black mold exposureblack mold symptoms of exposurewrought iron garden gatesiron garden gates find them herefine thin hair hairstylessearch hair styles for fine thin hairnight vision binocularsbuy night vision binocularslipitor reactionslipitor allergic reactionsluxury beach resort in the philippines

afordable beach resorts in the philippineshomeopathy for eczema.baby eczema.save big with great mineral makeup bargainsmineral makeup wholesalersprodam iphone Apple prodam iphone prahacect iphone manualmanual for P 168 iphonefero 52 binocularsnight vision Fero 52 binocularsThe best night vision binoculars here

night vision binoculars bargainsfree photo albums computer programsfree software to make photo albumsfree tax formsprintable tax forms for free craftmatic air bedcraftmatic air bed adjustable info hereboyd air bedboyd night air bed lowest pricefind air beds in wisconsinbest air beds in wisconsincloud air beds

best cloud inflatable air bedssealy air beds portableportables air bedsrv luggage racksaluminum made rv luggage racksair bed raisedbest form raised air bedsaircraft support equipmentsbest support equipments for aircraftsbed air informercialsbest informercials bed airmattress sized air beds

bestair bed mattress antique doorknobsantique doorknob identification tipsdvd player troubleshootingtroubleshooting with the dvd playerflat panel television lcd vs plasmaflat panel lcd television versus plasma pic the bestThe causes of economic recessionwhat are the causes of economic recessionadjustable bed air foam The best bed air foam

hoof prints antique equestrian printsantique hoof prints equestrian printsBuy air bedadjustablebuy the best adjustable air bedsair beds canadian storesCanadian stores for air beds

migraine causemigraine treatments floridaflorida headache clinicdrying dessicantair drying dessicantdessicant air dryerpediatric asthmaasthma specialistasthma children specialistcarpet cleaning dallas txcarpet cleaners dallascarpet cleaning dallas

Paulis said...
This post has been removed by the author.