Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Z-fighting at close range

Author
Message
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 11th Sep 2005 02:20 Edited at: 11th Sep 2005 02:33
I have a number of alpha mapped plains all very close together (like 0.01 apart) - which unfortunately is too close for them to render properly, resulting in parts of planes clipping parts of other planes which should show through - all very nasty. I presume this is due to the z-buffer resolution not being high enough for alpha values that close together, and have tried numerous workarounds after posting a related thread in the bug forum, but still haven't found a solution.

The question, then, is does anyone know if the z-buffer resolution can be increased? I thought 'set camera range' might do the trick, but it doesn't stop the z-fighting.

This code demonstrates the problem - try moving the planes close together, and notice the clipping that occurs in certain places - especially when just the corners overlap:



Catalyst
21
Years of Service
User Offline
Joined: 6th Sep 2003
Location:
Posted: 11th Sep 2005 18:53
Set camera resolution would only be if they were clipping because they were too near/far from the camera. For this, try disable object zwrite. It's different from disabling the zdepth and should do the job.
The Wendigo
22
Years of Service
User Offline
Joined: 13th Sep 2002
Location: A hole near the base of a tree in the US
Posted: 11th Sep 2005 20:42
I agree with Catalyst, however, disabling object z-write may cause future problems (such as draw ordering), but it's the best thing I can think of to avoid z-fighting in some situations. Far as i know, there is no real work around. I also am not sure, but I think this is more a DX thing than a DB thing, but my general DX knowledge is limmited.


Home of DOOP, Strata Works, and Seva. djpeterson83@[email protected]
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Sep 2005 21:17
Do you really need to have such a low near range for your camera? Or such a high far range?

Either increase the near range, or reduce the far range to more reasonable levels (the default IIRC is 1,3000)

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 12th Sep 2005 02:44 Edited at: 12th Sep 2005 02:44
I tried changing the range to 1,10 and it didn't improve the resolution. And unfortunately, diabling zwrite is no good if you have some opaque planes in amongst the transluscent ones, and you don't want the transluscent ones to appear through the opaque ones.

I noticed that the z-fighting only occurs when the planes are offset in the x or y direction against other planes - in other words when just the corners of planes ovelap.

Call me crazy, but I've come up with a stab in the dark theory - not much reasoning behind it except for the fact it would explain the symptoms:-

Imagine that if you have several objects at different places on the screen, but all with equal z depths. You'd think that they were all of equal distances from the camera. I'm thinking, however, that perhaps they are not. The further from the centre of the screen the object is, the further away it is from the camera - almost as if a particular z-depth forms a curved line, which curves away from the camera at the edges of the screen. This curved line of equal z-depths may become more extreme with different camera field of views. Now imagine you have objects at slightly different z depths - say, z=1 and z=2. This picture demonstrates my hypothesis:



Object 1 is at z=1, and object 2 is at z=2; no problem, object 1 appears infrint of object 2 as it should. But now imagine moving object 1 to the position of object 3. Because of the curved z depth effect, it would now be behind object 2 even though it has a lower z depth, and hence the clipping occurs.

Or, I could be completely wrong

Attachments

Login to view attachments
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 12th Sep 2005 15:41
but because you've moved it behind - surely it'd z value would change too?

Does this problem happen if you have 0.1 distance between them rather than 0.01?

Could you provide a screenshot?

My Website:
RiiDii
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 12th Sep 2005 20:28
I think what Ric is saying is that the blue lines represent a sort of curved space flat x-axis movement because the further an object is from the center of the screen, the further it is away from the camera even though it's moving perpendicular to the camera. So, the z-buffer says "hey you moved this object further away from the camera, and now it's behind the 2nd object", even though you never moved it along the z-axis.

I can definately see Ric's theory - and it's quite sound. The z-buffer is getting "confused" because object "A" is in front of object "B" yet, some points of object "A" are further away from the camera than some points of object "B".

I'd say it's even a reasonable guess that Direct X divides the object up, similar to Ric's diagram, where plain A and plain C are both parts of the same plain.

Good work on that Ric! But unfortunately, it's starting to sound like a Direct X limitation more than any DBPro can fix. Inversely, if you turn the z-buffering off of plain A, it will also solve the problem because plain A would always be "in front of" plain B.


Open MMORPG: It's your game!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Sep 2005 00:04
I don't think there's a solution to the problem you have as you've stated it.

Can you describe your reasons for implementing a system like this in the first place?

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 13th Sep 2005 00:36 Edited at: 13th Sep 2005 02:32
@ Nic: the code snippet in my first post was used to produce this screenshot:



The three planes are all translusclent, with red closest the camera, then green, then blue farthest away. The blue shows through the green (as it should), but the green, which has a simailer z-value to the red, doesn't show through the red - I think it's because the red's z value is being pushed back as it is moved towards the edge of the screen, and tangling up with the green's z depth.

@Rii : I'm glad you see method in my madness. Makes me feel better knowing someone else appreciates the problem, even if there is no fix!

@IanM : You mean what was the reason for needing the planes so close together? I'm making a hud editor, where the various planes represent different components of the hud - and the user can move layers forwards or backwards (to change the draw order) without noticably affecting their size. But hey - looks like I'll end up using sprites instead now.

Attachments

Login to view attachments
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Sep 2005 01:23
I thought that may be it. Why not just lock the HUD objects to the screen - increase the distance between them to something larger, like 1 unit, and you should get the right effect without size changes.



Thats just a very small example - I'm sure with a bit of time spent on it, you can make much more of it

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 13th Sep 2005 02:22
I think the problem is to do with the lack of backdrop.. I cant seem to produce any wierd z-depth problems in this code (a tweaked version of rics)


I always have a cope of bliss.bmp (the windows XP backup) in my c:\ for an emergency texture

In that code, I can overlap everything fine.. Maybe I'm missing the point?

My Website:
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 13th Sep 2005 03:07 Edited at: 13th Sep 2005 03:09
@Nick: Firstly - I forgot to include the screenshot in my post above - it's there now and shows the red plane clipping the green one.

I get the same problem with your code - even with the backdrop. Note that it is only when the planes have very similar z-depths. Just to make sure it's not just my pc, I've automated a sequence to demonstrate - could you check this please?



The red plane slides left and right infrint of the green plane. OMPC, when it gets closer to the edge, it clips it. (remmed out the backdrop cube so other people can test it too even if they don't have the image)

@ Ian: The main problem with having the hud components further away from the camera, is that there is a danger of the game environment (let's say the ground, for example), actually coming through the hud. Disabling object z-depth is the usual solution to that, but then that screws up the layers in the hud when you have a mixture of transluscent and opaque elements all overlapping. I think I can solve the problem by using sprites though - major rewrite, but hey ho.

Ian T
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 13th Sep 2005 03:15
You are working in 32 bpp display mode, right ? Because a 16 bit z-buffer universaly sucks.

Some very interesting research into this you've been doing, thanks Ric

If I looking for blog
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 13th Sep 2005 03:32
Yes, I'm in 32 bit mode.

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 13th Sep 2005 12:39 Edited at: 13th Sep 2005 12:41
I'm at work right now so cant compile the code and wont be able to tonight due to being busy.. However I can try it at work on my 2.8Ghz Intel GFX machine... I just need some kind soul to compile it, zip it and attach it to a post here

EDIT: One reason I put in the background cube was not to make it look pretty, but give it some proper background to mix with the alpha-ed plains. I recall having LOTS of transparency issues when there was nothing behind the transparent object..

Also - just for reference - what graphics card you got Ric? I tried my code on a Geforce 6800GT last night.

My Website:
Morcilla
22
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 13th Sep 2005 14:03
This link may help you:

http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html

It has a z-buffer resolution calculator.

The easy workaround: put further away from the camera the hud planes, and increase as much as you can the near clip plane with SET CAMERA RANGE, that will increase the z-buffer resolution.

Not so easy one: every loop or when near the ground, check distances and adjust position of hud planes and camera range to obtain maximun z-buffer resolution dinamycally. Uh
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 13th Sep 2005 19:20
Thanks Morcilla - what is says confirms what I thought - the z-buffer resolution just isn't good enough to resolve objects to that degree of accuracy. The calculator tells me that with a 32 bit system, the smallest z-value it can resolve is about half of the near clip plane - in other words, if you have the camera's near value at 1, then objects close to there must be separated by z-values of at least 0.5 to avoid z-fighting. That sounds even worse than I thought it was in the first place!

@Nick: GF2 - can't be helping the situation I'm sure!

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 13th Sep 2005 21:48
hehe the good old Geeeeeeeforce 2.

I'm back home - but playing on my Mac while waiting for dinner to be served for me... its a hard life

My Website:
Morcilla
22
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 14th Sep 2005 13:38
Also, you could make one custom shape model with milkshape or 3dsmax, and forget about the three primitive plains, so they do not overlap anymore

Taylor it as you want and assign UV mapping. After that you'll have to make your custom bitmaps for it...

Just another idea, good luck.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 14th Sep 2005 19:14
The planes have to be able to move in all three dimensions, so that wouldn't work in this case - but not a bad idea if they were static.

mm0zct
21
Years of Service
User Offline
Joined: 18th Nov 2003
Location: scotland-uk
Posted: 15th Sep 2005 19:17 Edited at: 15th Sep 2005 19:20
with the example you posted:


i have no issues whatsoever, however this is a problem all games suffer from, even in counterstrike source i get zfighting with distant decals. but my friend doesnt get them even in exactly the same places as me, so i would suggest that it is a graphics card limitation, possibly zbuffer compression issues.

attached image of code running on my pc:

http://www.larinar.tk
AMD athlon 64 3000+, 512mb ddr400, abit kv8, 160gb hdd, gigabit lan, ati radeon 9800se 128mb.

Attachments

Login to view attachments
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 15th Sep 2005 19:49
Thanks mm0zct - that's a surprising revelation! The fact that the issue exists on only some cards makes it even harder to resolve the problem, though. Z-buffer compression does sound like a possible cause. Ok - that settles it - I'm rewriting my code using sprites!

Morcilla
22
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 15th Sep 2005 20:28
mm0zct, it would be interesting to know which card are you using.

Radeon 9700pro here and no z-buffer artifacts, but the clipping of the green plane appears too.
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 15th Sep 2005 21:35
Ric - instead of sprites, how about pasting the images?

My Website:
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 16th Sep 2005 01:23
I'll need to do things like alpha mapping and transparency, and have full control over drawing priority, and as the sprite commands are already geared up for that I guessed it would be easier - are there any advantages of pasting images instead?

MiR
21
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 16th Sep 2005 15:24
Not really. I don´t think they are much faster as long as you disable the sprite´s backsave. At least I ever noticed any slow down.

My signature has been erased by me because it's LARGE.
Thank you for the votez!1!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 16th Sep 2005 17:46
I have - in my Primtive Maze game, I used sprites for the over head map in the HUD for all 4 players. I later changed it to paste image and noticed a MASSIVE speed increase.

You can change the order images are pasted by the order you pastes them (back to front). Pasting images can also easily to transparencies, although changing them is a little hard. If you convert an image to a memblock and pass over every pixel appliying a mask like this:
memblock dword(pos) && 0xaaFFFFFF

where aa is the alpha value between 00 and FF, then convert the memblock back to an image and then paste it - you should have a semi transparent image.

Whats this all for?

My Website:
MiR
21
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 16th Sep 2005 17:58
Quote: "I have - in my Primtive Maze game, I used sprites for the over head map in the HUD for all 4 players. I later changed it to paste image and noticed a MASSIVE speed increase."

mmm. Did you disable the back save thing? Danm this means I´m going to have to do more tests. Maybe it happens when you mix sprites with 3d.

My signature has been erased by me because it's LARGE.
Thank you for the votez!1!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 16th Sep 2005 21:23
I'm pretty sure I did...

It could be that mix it doesn't like.. Also sprites have lots of "overhead" in terms of alpha percentage calculation and rotation and stuff where as paste image just dumps the image on the screen buffer!

My Website:
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 17th Sep 2005 13:55
Quote: "Whats this all for?"


My interface creator project:
http://forum.thegamecreators.com/?m=forum_view&t=50718&b=8



Login to post a reply

Server time is: 2025-06-21 05:44:36
Your offset time is: 2025-06-21 05:44:36