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?

69 comments:

Anonymous 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.

Anonymous 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?

Anonymous 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.

Anonymous 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.

Anonymous 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

Anonymous 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.

Anonymous 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? ;-)

Anonymous said...

rXIliA Your blog is great. Articles is interesting!

Anonymous said...

CJtAXG Thanks to author.

Anonymous said...

Good job!

Anonymous said...

Hello all!

Anonymous said...

Hello all!

Anonymous said...

Hello all!

Anonymous said...

Thanks to author.

Anonymous said...

Nice Article.

Anonymous said...

Nice Article.

Anonymous said...

Hello all!

Anonymous said...

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

Anonymous said...

Magnific!

P.Svilans said...
This comment has been removed by the author.
Anonymous said...

ss cialis without prescription , cialis no prescription , generic cialis online , viagra for sale , viagra online , generic viagra online

Anonymous said...

s cialis uk , buy cialis generic , generic cialis online , purchase viagra online , cheap generic viagra , womens viagra

Anonymous said...

My cialis professional , tadalafil cialis , cialis for women , purchase viagra , cheapest viagra , how does viagra work

Anonymous said...

ss buy cialis online in usa , cialis tadalafil 5mg once a day , cialis daily 5mg , online prescription viagra , viagra pills online , order viagra online without a prescription

Anonymous said...

ge cialis daily dose , cialis pill splitting , cialis , buying viagra online , viagra , viagra canada online pharmacy

Anonymous said...

eh cheap cialis soft , cialis sale , cialis uk sales , where to buy viagra online , buy viagra online no prescription , cheap viagra online without prescription

Anonymous said...

gt cheapest viagra , buy generic viagra online , buy generic cialis online , viagra canada , female viagra , viagra for sale

Anonymous said...

s generic viagra , viagra prescription , viagra cheap , cialis prices , cialis order , cialis 10mg

Anonymous said...

gt viagra online , cheap viagra pills , online viagra , cialis generic , cialis pills , cialis prices

Anonymous said...

lafd firefighter dating sight http://loveepicentre.com/map.php meet single dating online

Anonymous said...

buy viagra cheap viagra online from us generic - buy 25 mg viagra

Anonymous said...

viagra online without prescription viagra purchase online us - buy generic viagra in us

Anonymous said...

viagra online ordering viagra online in us - order cheap viagra online us

Anonymous said...

[url=http://loveepicentre.com/success_stories.php][img]http://loveepicentre.com/uploades/photos/3.jpg[/img][/url]
single dating site [url=http://loveepicentre.com/success_stories.php]herpes dating rupert idaho[/url] dating european men
green singles dating online [url=http://loveepicentre.com/taketour.php]lawrenceburg dating[/url] hungarian dating culture
air force dating [url=http://loveepicentre.com/taketour.php]college girls dating[/url] match dating singles

Anonymous said...

cheap tramadol tramadol dosage for fibromyalgia - buy tramadol online cod overnight

Anonymous said...

buy soma online buy somatropin pills - discount soma no prescription

Anonymous said...

order soma online where to buy soma seeds - cheap generic soma

Anonymous said...

purchase soma soma rx cheap - buy generic soma no prescription

Anonymous said...

discount soma soma muscle relaxer online - picture of soma medication

Anonymous said...

soma drug discount soma bras - soma recreational drug use

Anonymous said...

discount soma will soma show up benzo drug test - buy soma online cheap

Anonymous said...

buy soma deadly soma online movie - buy soma magazine

Anonymous said...

buy cialis online cialis 800mg reviews - generic cialis price

Anonymous said...

arfe generic viagra,viagra prices , cialis ,cialispriceschu.com
http://genericviagrarbs.com http://viagrapricesapf.com http://cialisonlinesya.com http://cialispriceschu.com

Anonymous said...

arfe generic viagra,viagra prices , cialis ,cialispriceschu.com
http://genericviagrarbs.com http://viagrapricesapf.com http://cialisonlinesya.com http://cialispriceschu.com

Anonymous said...

arfe generic viagra,viagra prices , cialis ,cialispriceschu.com
http://genericviagrarbs.com http://viagrapricesapf.com http://cialisonlinesya.com http://cialispriceschu.com

Anonymous said...

order tramadol online without prescription tramadol withdrawal neurontin - tramadol hcl indications

Anonymous said...

xanax for sale without prescription xanax side effects long - generic for xanax what does it look like

Anonymous said...

xanax online xanax xl - there 4mg xanax bars

Anonymous said...

Hi Tantriс Mаssagе enthusiasts οn yоur health aid
team, you can be аssuгed а future doing things you beloved to do.

Hаy dіѕtintas tradiciοnes de toques sanadoreѕ desarrollados Massage and
whаt on the nose happеns inner a Toгonto alien Massage ρarlor?


Feel free to visit my web blog :: homepage
My page:

Anonymous said...

buy tramadol buy tramadol faq - tramadol withdrawal signs

Anonymous said...

cialis online generic cialis 5mg daily - cialis no longer works

Anonymous said...

discount xanax xanax 2mg bars street price - xanax side effects coming off

Anonymous said...

cialis online cialis price au - cialis online 4rx

Anonymous said...

learn how to buy tramdadol tramadol vs hydrocodone addiction - tramadol hcl 50 mg street price

Anonymous said...

http://www.integrativeonc.org/adminsio/buyklonopinonline/#0944 klonopin side effects brain - how many 2mg klonopin

Anonymous said...

buy tramadol online tramadol hcl mylan 50 mg - tramadol hcl 50 mg can you get high

Anonymous said...

http://buytramadolonlinecool.com/#61458 normal dosage tramadol humans - tramadol for dogs high

Anonymous said...

klonopin without prescription klonopin long term use - klonopin withdrawal support group

Anonymous said...

http://www.integrativeonc.org/adminsio/buyklonopinonline/#use klonopin dosage for recreational use - death from klonopin overdose

Anonymous said...

My viagra pills viagra,cheap viagra viagra, viagra viagra pills,cialis viagra pills
http://cheapviagrapillsesl.com#viagra pills http://cheapviagrapillsvivt.com#viagra pills http://viagraonlinegenericth.com#viagra online http://cheapcialisgenericsybf.com#cheap cialis

Anonymous said...

My viagra pills viagra,cheap viagra viagra, viagra viagra pills,cialis viagra pills
http://cheapviagrapillsesl.com#viagra pills http://cheapviagrapillsvivt.com#viagra pills http://viagraonlinegenericth.com#viagra online http://cheapcialisgenericsybf.com#cheap cialis

Anonymous said...

"In these types of operations, those committing crimes must understand that if they resist it could lead to confrontations that could lead to loss of life. They shouldn't break the law, or, they should surrender," Mejia said. generic viagra and cialis generic viagra mastercard payment,viagra 100mg generic viagra canada no prescription, cheap cialis generic viagra europe,buy cialis pills online viagra pills for men side effects
http://genericviagrapillstzj.com#viagra online http://viagraonline100mgxhy.com#viagra online http://cialispricecheapsfc.com#cialis price dubai http://cialispillscheapwr.com#cheap cialis

Anonymous said...

ge viagra cheap viagra,viagra pills viagra pills, viagra viagra,cheap cialis viagra
http://cheapviagrapillsesl.com#viagra pills http://cheapviagrapillsvivt.com#cheap viagra http://viagraonlinegenericth.com#viagra http://cheapcialisgenericsybf.com#cialis

Anonymous said...

eh cialis price cialis price,viagra online cialis price, viagra cialis price,generic viagra cialis
http://cialisonlinepricesrg.com#viagra http://viagraonlinegenerictsf.com#viagra online http://buyviagraonlinewrv.com#viagra online http://genericviagrapricevth.com#viagra

Anonymous said...

eh cialis price cialis price,viagra online cialis price, viagra cialis price,generic viagra cialis
http://cialisonlinepricesrg.com#viagra http://viagraonlinegenerictsf.com#viagra online http://buyviagraonlinewrv.com#viagra online http://genericviagrapricevth.com#viagra