Z Buffering

Started by
8 comments, last by Greg K 21 years, 4 months ago
My models that I am rendering render in the reverse order. For example, if I have a building with beams on the front and on the back, the beams on the back will be rendered on top of the beams on the front. If I move around and look at the back of the model, the reverse happens. I am using the ZBuffer. Any suggestions on what I may be doing wrong? -Greg Koreman
Advertisement
I''m more of a GL guy than a D3D guy at the moment (working on changing that), but from an OpenGL perspective (should be the same in Direct3D though I can not attest to that) it sounds like you need to enable depth testing, which would test incoming pixels against a current pixel being stored in the depth buffer.

Trent Polack
Burnt Fur Entertainment
trent@codershq.com
Author of Focus on 3D Terrain Programming
It might be your culling. Try reversing the culling and see if that helps.
First off, I love this forum. Sorry, I just felt like saying that. Secondly, I have tried both of those things and neither of them worked. (Depth testing is enabled already). I think the problem lies in the fact that I am using vertex shaders...? It correctly depth tests between objects, but not inter-object. Any other suggestions? (I also tried changing the depth test but to no avail).
-Greg
quote: I think the problem lies in the fact that I am using vertex shaders...?

Vertex shaders should have nothing to do with this, as long as they''re emitting valid vertices.

Anyway, if you suspect that vShaders are the cause, switch to the FFP and try it.

Have you changed your ZCmp function? Please post some code, maybe it''ll help determine the problem.

I didn''t think that vertex shaders should be a problem either but I have tried other stuff. I played around with the z compare function. Did greater than and less than and it didn''t change anything. I even tried NEVER and it didn''t change. ZENABLE is set to D3DZB_TRUE. Culling is counter clockwise (the other way renders stuff inverse as expected). What code should I post? Also, I can''t switch to the fixed function pipeline due to my weird vertex format. Is there any way to set "unused" values in your vertex format so I can test it?
-Greg Koreman
Not some silly thing like putting the zNear plane to 0?? that causes strange effects
No, not the near plane, it is set at 1. I noticed that the depth buffer seems to be working for whole objects. If I render one object it doesn''t sort itself right but if I render multiple objects, the objects themselves still don''t render right but when they overlap they behave as expected (they block the ones underneath). I hope that helps.
-Greg Koreman
See if you can post an image of the problem - that''ll help us a lot.


[500 errors x 5 ]
All of your suggestions were good. Fortunatly, a friend of mine helped me find the problem. I forgot to create a depth buffer. As you can imagine that would mess things up a little. Thanks for all you help though.
-Greg

This topic is closed to new replies.

Advertisement