PDA

View Full Version : Z Buffer



Rong Yao
03-06-2002, 08:43 AM
Is there any way to know the values in Z Buffer? Or is there any way to know which is the front most plane if there are several planes? OpenGL will check the values in Z Buffer and hide all the overlap parts if these parts are behide the front most(closest to the viewer) object. Is there any way for the user to know that? Thank you!

zed
03-06-2002, 08:49 AM
see the red book
readpixels with GL_DEPTH_COMPONENT

Rong Yao
03-06-2002, 10:28 AM
Thank you, Zed! My question actually is: is there any way for the programmer to know which plane is in front of another one if there are two planes in the view? OpenGL knows that with Z Buffer, however, how can I know this?

Our project: we need to retrieve some information from planes in the view. We only try to get information from the front most plane. So we need to know which plane is the front most one. Is there any way to do that?

Edgar
03-06-2002, 10:46 AM
Yes, you can find that on google.

knackered
03-06-2002, 11:05 AM
I can tell you what not to do:-
- Don't rely on opengl to find out this SIMPLE information.
- Don't rely on opengl programmers to do your work for you, unless you've tried your best already.
- Don't post multiple posts on the SAME TOPIC - my 56k modem hates you for it.
- Don't post any more questions here until you've read some books/docs.

- Finally, don't take my reply too personally, please - I too have asked some stupid questions on this forum, in the past.

Rong Yao
03-06-2002, 12:01 PM
knackered:

If you do not really understand the question, you would better do not say a word. Real specialists never be so impatient. Actually I contacted some friends who have been OpenGL programers for years and they offered no good solutions for my question. If you are a real specialist and you understand my question and you give me a satisfied answer, I will shut up next time. Otherwise...

I worry about my English. Perhaps I do not explain my question clearly. If there are two planes in the same view and they could overlap with each other, can you tell which one is in the front? Do not tell me to use glEnable(GL_DEPTH_TEST).

Hope I am going to shut up next time.


Originally posted by knackered:
I can tell you what not to do:-
- Don't rely on opengl to find out this SIMPLE information.
- Don't rely on opengl programmers to do your work for you, unless you've tried your best already.
- Don't post multiple posts on the SAME TOPIC - my 56k modem hates you for it.
- Don't post any more questions here until you've read some books/docs.

- Finally, don't take my reply too personally, please - I too have asked some stupid questions on this forum, in the past.

knackered
03-06-2002, 12:59 PM
Ok, ok mr. yao. You've decided to take what I said personally - which leads me to think you're maybe a young, enthusiastic, slightly arrogant fella - I like that. It will get you far....but not far enough if you don't want to do your homework.
Your 'specialist' friends either don't consider you a friend, and have therefore fobbed you off with feigned ignorance, or they are just as ignorant as yourself.

Think about it. You have 2 planes. You obviously know how to project the planes into world space, yes? You need both your planes in world space, the same as your viewpoint. Now, you know how to perform a plane-to-plane intersection test, yes?
Then why are you asking the question?
I could understand it if your 2 objects were not planes (maybe a 2 rabbit models), but they're planes for gods sake!
I'm not a specialist - to me a specialist is the nickname of a cockney gang member, maybe someone good with safe cracking, or security systems.

zeckensack
03-06-2002, 01:18 PM
Specialist answer:
Know your viewpoint origin
Know your view normal
Know your geometry
Split your geometry into non intersecting (wrt depth) parts. Choose a representative vertex on each object in question.
Calculate ((transformed vertex - origin) dot normal) for geometry in question
Choose the minimum value. This leads to the vertex closest to the eye plane and in turn to the object closest to the eye plane.

As you can see, this has absolutely nothing to do with OpenGL. You could argue that it's related to computer graphics in general but it's simply linear math.

[This message has been edited by zeckensack (edited 03-06-2002).]

FXO
03-06-2002, 01:19 PM
I really think knackered was trying to tell you in a nice way.

Try searching the net and read books first.
Then search the forums for a similar question, chances are that your question is already answered many times.

In this case, you can find information on how to determine which plane is in front of the other on nehe.gamedev.net

HTH

FXO
03-06-2002, 01:21 PM
(This problem can be solved with OpenGL and Glut)

zeckensack
03-06-2002, 01:42 PM
Wow, asking the same question on both boards and then repeating the question on both boards two hours later is ... is ... http://www.opengl.org/discussion_boards/ubb/rolleyes.gif

SirKnight
03-06-2002, 02:06 PM
My suggestion would be to take a darn math class that covers 3-space (3D) mathematics. Many years of experience using opengl doesnt mean a thing if you dont know any 3d math. http://www.opengl.org/discussion_boards/ubb/smile.gif Now me, im taking an advanced calculus class that covers 3-space math and it has helped me a TON in graphics programming. Each day i understand some graphics concept better and/or am able to learn a new 3d technique that i wasnt able to do before. It all comes down to the math. http://www.opengl.org/discussion_boards/ubb/smile.gif

-SirKnight

Rong Yao
03-06-2002, 02:09 PM
You did make me think for a while. Actually we have up to 30 planes. These planes could be parallel with some others or intersect with others. And we know the 3D coordinates of vertex of these planes. Theoretically, you can find which plane is the most front one via the algorithm you offered if you are good at mathematics. You need to do the computation work many times because we need to compare planes pair by pair. I do not know exactly how OpenGL does this, but I guess OpenGL uses the similar algorithm and stores the information in Z Buffer. Then when OpenGL draws something, which one to draw and which one to hide is already known by referring to Z Buffer. However, is there any easy way to get the information that OpenGL already stored? Although we can do the computation to get the information I need, if the users rotate the image, we have to do all the computations again. If there is any handy way to get depth information directly, then we do not need to so much work. Besides, I am not good at mathematics(maybe you are), and I need to review my college text book to do the computation and that takes time. Any suggestion?

Humus
03-06-2002, 02:16 PM
I think it would be better if you explained why you need this information and how you plan to use it, may be easier to give you a good suggestion that way.
If it's for depth sorting I suggest you take a look at BSP trees.

zeckensack
03-06-2002, 03:12 PM
I need to review my college text book to do the computation and that takes time. Any suggestion?

And it takes time for me to answer this stuff. Let me put it clearly:
This is basic linear math. We're not talking rocket science here. You'll get nowhere in computer graphics without it.
So, take your time and review your text book. It will pay off greatly.

If you want to get the info back from OpenGL, I suggest the following horridly performaning, cheap ass solution (if you don't want to do the proper math http://www.opengl.org/discussion_boards/ubb/rolleyes.gif...)

Assign a unique 'key color' to each object.
Disable dithering, lights, textures, blending, smooth shading and whatnot. But be sure to leave depth writes and depth testing enabled.
Render your scene to the backbuffer with the key colors assigned to the objects you want to be able to recognize.
DONT SWAP THE BUFFERS!
Read the back buffer colors and the depth buffer back with glReadPixels.
Find minimum depth value.
Find associated color value.
Find object associated with this color.

Optional:
Turn fancy rendering state for audience consumption (TM) back on.
Render scene again.
Swap buffers.

Rong Yao
03-06-2002, 03:14 PM
Thank you all for joining the discussion and give me your reply. No matter what you guys said to me, I appreciate your concern on the topic. My English is not so good, so I might mislead you and I apologize for that. I want you guys note this point:

I post this question not to discuss Geometry, but an application of Geometry. Theoretically it is not so hard to find an answer from point of view of Geometry. I am not doing my homework. I am doing a geophysical project.

I am now descript my project and I hope this can help you understand my problem. In a typical geophysical survey, we survey a rectangle area and try to find something under the surface of this area. If we consider the depth, we get a cube. we cut the cube by slice from different directions to see what are there. Each slice is a plane. If there is something in a slice, that part of the slice looks different from the enviroment. We need to know the position of that part. We want our users to see the 3D position of the part he/she concerns when he/she points the mouse at that part. If there is only one slice(plane), we can know this by 2D-3D coordinate transformation. However, if there are more slices(planes) and they overloped with each other, if the user point to the overlapped part, we cannot get the position information since we do not know which slice(plane) the mouse point is located at. In this case, we assume that the mouse point is located at the front most slice(plane) and we want to show the position of the point on that slice(plane). Therefore, we need to know which slice(plane) is the front most one. In my impression, Z Buffer stores depth information, but I do not know if there is any function can help me to get the information, that is why I post this topic.
If my poor English still do not let you understand my problem, please let me know and I can further explain the topic. Please do not ignore the topic, thank you!

The reason I post this on two places is that I want more experts to see this question and give me an answer. The reason I post this twice is that I want to explain my question more clearly. I believe I did not say the question clearly the first time. OK, any suggestion?

Rob The Bloke
03-06-2002, 08:21 PM
We understand EXACTLY what you want to do. Read the posts above, or read the posts on the other forum. They all say the same thing. I fear it's you who does not understand what we are saying. In that case, it is up to YOU to read up on the subject before continuing. We cannot help you unless you do.

[This message has been edited by Rob The Bloke (edited 03-06-2002).]

wildeyedboyfromfreecloud
03-06-2002, 08:23 PM
can't believe i read all this. but i think the answer given to you just before you're final message sounds to me like what you wan't to know. the z buffer doesn't save geometry info just pixel depth i think. so you will need to assign a color to it so you can retrieve that color with your mouse point and click function. i hope i spoke simply enough that you understand. i really tried to keep my english simple as possible.

Gorg
03-06-2002, 09:32 PM
I am thinking of writing a book on picking! If all the people that need help on that would buy it, I would be rich!! http://www.opengl.org/discussion_boards/ubb/smile.gif

marcus256
03-07-2002, 03:17 AM
I do not understand why people are so afraid of stencil buffers. It's an excellent way to store "invisible" information about rendered geometry.

I made a post that hopefully solves the problem gracefully: http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/007650.html

I hope it is correct (haven't tried it).

knackered
03-07-2002, 10:31 AM
[edit] I withdraw my comment.

[This message has been edited by knackered (edited 03-07-2002).]

Rong Yao
03-07-2002, 12:40 PM
knackered,

Although you are not very polite, I still would like to thank you for reminding me that I can go back to the original point and solve the problem in a mathematic way. Before I was thinking only how to get the infromation from OpenGL functions.

You said we can find the intersection of two planes in order to solve the problem in one of your previous post, however, that requries you to know the equations of the planes and we do not have these equations at hand. I would rather use coordinate transformation to do that since our users could rotate the image frequently.

I will also take and try marcus256, Rob The Bloke, zeckensack and other people's advice because I want to learn something. knackered, do you mean it is very hard to do so in you last post?

Rong Yao
03-07-2002, 01:23 PM
Thank you, marcus256, This is a beautiful way! I learn a lot from you!


Originally posted by marcus256:
I do not understand why people are so afraid of stencil buffers. It's an excellent way to store "invisible" information about rendered geometry.

I made a post that hopefully solves the problem gracefully: http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/007650.html

I hope it is correct (haven't tried it).

Furrage
03-07-2002, 01:29 PM
This is the most hilarious thread I have ever read. How many times can you tell a man a dollar is a dollar before he understands. I know you have smiley faces http://www.opengl.org/discussion_boards/ubb/smile.gif but don't you have a belly laugh, where the icon laughs so hard it rolls around, kicks up dust, and sticks its feet in the air.

But seriously Mr. Yao. If you can't understand all these responses no one can help you.

Coconut
03-07-2002, 01:38 PM
Concerning of your opinion on cross-posting and double-posting, it is generally considered inappropiate in this forum. Don't ask me who and why set the stupid rules. Posting things multiple times only would piss certain people. It will also reduce the chance to get suggestions from these people. Since you know all real specialists are people of patience, you probably don't concern their opinions anyway.
I learned how to get the equation of a plane from three points when I was in grade 9, just like my classmates. It is just computationally cheaper to solve it geometrically.

knackered
03-08-2002, 12:00 AM
Furrage, I'm glad someone finds this funny - I was beginning to think I was going mad http://www.opengl.org/discussion_boards/ubb/smile.gif
Mr. Yao, I'm so glad you finally understand. You have a low opinion of me now, but I'm not in a popularity contest, to coin a phrase http://www.opengl.org/discussion_boards/ubb/smile.gif

Furrage
03-08-2002, 06:18 AM
I can think of some good reasons to dislike multiple posts.

1) Imagine someone entering 10 posts in the forum on the same topic. That means 9 other posts get moved to the second page where they're unlikely to be seen. Thats 9 other persons who will never get an answer because someone is inconsiderate.

2) Imagine someone puts 10 posts under 10 different topic names even though they're the same. That's 9 topics a reader has to go through unnecessarily wasting time. That time could be spent dealing with another post. Heck, even if it's the same name most people still end up wasting time wading through multiple posts.

3) People hate repeating answers. It's caught me already where I answered one post, came across a similar one, was in the process of posting to the second which included a link to the first answer, when I discovered the post was from the same person. That was a real waste of time.

4) Telephone companies and some ISPs love this time wasting. Especially when people use 56k or less modems.

5) As stated above, multiple posts tick people off, so they'll boycott your post and you won't get the full range of expert feedback you're looking for.

So please be considerate and stick to one post in one forum. If the chosen forum can't help try another, but give your first choice a chance before moving on. Also use the search facility. A lot (and I do mean a lot) of your questions have already been answered and are archived in this forum.

And if nothing else read the current posts before making your own. Yesterday, there were three or more current posts on picking from different persons asking the same question. If two persons had just taken the time to read first there would be no need for the additional posts.

Rong Yao
03-11-2002, 08:10 AM
Woo, no technical reply after a weekend's rest! :-)

Since I do not visit this forum frequently, I do not know some tacit rules such as no cross-posting and double-posting. When I first made the post, I just wanted to increase the opportunities of getting quick answers. I did not intend to waste your time. I apologize for the inconvenience I brought to you all and I promise that I will not do it next time.

I am not an unreasonable person. If someone reminds me the rules politely, I will be happy to accept their suggestions. However, someone just wants to show how smart he is by insulting others.

I admit that I was stupid because when I encountered the problem, I thought only of asking help from OpenGL, I did not even thinking about solving the problem in Geometry. I guess you understand what I mean when I say this.

There do exist some people who do not waste time in blaming people, but offer elegant solutions and get fun from helping people. I appreciate their help. I somewhat agree with angryGLfan, make beginners feel easy!