Z buffer accurate up close, but not far away.

Started by
15 comments, last by Roof Top Pew Wee 20 years, 3 months ago
I am currently writing a GUI for my sprite engine. To make things really easy, I am going to simply adjust the Z distance of windows when they are clicked on. That is, if a window is clicked on, it is moved closest to the camera and all of the others are moved back. So the user doesn''t see a difference, the changes in position are small (everything is viewed at 100 units away, and the changest are probably going to be 1/100 of a unit or less. I could draw from back to front, but for speed purposes I am first going to draw the buttons then the text. Therefore, I need the Z-buffer to do its magic. The problem is that at regular distances, this small difference in distance isn''t enough and the Z buffer isn''t working right. If I get really close to my buttons, the z buffer works just fine, but as I move further back, it seems as if the small differences aren''t large enough and some of my windows are in front when they should be in back. Is my only solution to switch textures for every button (text and the button graphics are in different textures) or is there a way to increase the sensitivity of the z buffer so that the buttons are drawn correctly at further distances. --Vic--
Advertisement
My understanding this is a hardware limitation.. ZBuffer are only 16 or 32bit buffers and you tend to mix your buffer with another type of Buffer like a Stencil buffer so it becomes a 15/1bit buffer. This means with small and mintue distance changes the precision of the ZBuffer just isn''t up to the task.

This is all quoted out of memory, so while I think the gist of what I''m saying is correct some small parts may be inaccurate..
In your perspective matrix, what is the z-value of the far plane? (If you''re using D3DXMatrixPerspectiveFovLH it would be the last param). You may want to try and make that value smaller than it currently is. Also, if it is 0 or null, you will have problems.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
The value of the near plane is far more important than the far plane. Also, using a 32-bit Zbuffer should help.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
I''m not entirely certain, but couldn''t you just load an orthographic matrix and make the differences in your z coordinates an arbitrary size? This seems to be the effect you''re trying to emulate anyway...

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
CircleSoft: I have to keep my far plane high because I am also rendering stuff that is far away. That is, my GUI will be used as a menu in all types of games; and some games have objects that are very far away.

The near plane is about as large as it ca be before I start having problems with it.

Thunder Hawk: I don''t want to use an ortho view because I take advantage of the size differences in my games. In my engine I set the view, draw all game objects then jump directly to the GUI. If I were to use a Z Buffer, that currently wouldn''t be a problem because I sort my sprites from back to front and don''t use Z for alpha reasons on them.

I have decided that I will just make two versions of my GUI. A layered version and a fast version. The layered version will draw each button in its entirety before moving on to the rest. This will be slow, but allow for windows on top of other windows. The other version will assume that there is only one layer and it is up to the programmer to make sure that buttons don''t overlap. Here I will draw buttons in components to minimize texture changes.

Hoever, thanks for your help all. Always good to learn something new.

--Vic--
Ooops, that was me up there.
After rendering your scene and before rendering your gui clear the z-buffer and set the projection matrix to whatever suits.
You realize you can use an ortho matrix for your GUI and a normal matrix for everything else, right?

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________


I remember reading in an Andre LaMothe book that Z-buffers are inaccurate at large distances, but W-buffers are not.

I''ve never used a W-buffer so I can''t tell you much beyond that.

Oh, and the book was about the DirectX8 era, so it should be relatively current.

~Sparticus

This topic is closed to new replies.

Advertisement