X_CLEAR_Z - what is it used it for??

Previous topic - Next topic

FutureCow

I've been reading the manual and can't work out what X_CLEAR_Z is used for. Can someone please tell me why you'd want to use it?

From the manual it "clears the depth buffer bits" - what set the depth buffer bits in the first place?
From my understanding the "depth buffer bits" are the "Z" value of your current location. If that's the case, why would you use X_CLEAR_Z and not just use X_MOVEMENT?

I've searched the forums, and looked through the 2 couple of examples that use it in the GLBasic samples folder and I can't work out why you need it.

Thanks!

Kitty Hello

When you draw a environment cube, you want to clear the Z buffer befroe drawing a racing track, because it might intersect otherwise.

FutureCow

I'm very new to 3D so forgive my ignorance =D

To draw an environment cube (I'm assuming that's a skybox!) I would expect to do the following (pseudocode)

Code (glbasic) Select
// Create a square
X_OBJSTART [number]
   X_OBJADDVERTEXT x,y,z,c
   X_OBJADDVERTEXT x,y,z,c
   X_OBJADDVERTEXT x,y,z,c
   X_OBJADDVERTEXT x,y,z,c
X_OBJEND

Repeat 6 times
   a) Move my current location to location of wall of cube (X_MOVEMENT)
   b) rotate to the correct angle (X_ROTATION)
   c) Draw box in current location (X_DRAWOBJ)

Texture new skybox
Move camera within box (X_CAMERA)


Assuming that's correct, would I have to do an X_CLEAR_Z? If so, why? And in this example, what will Z be set to before I call the X_CLEAR_Z?

Hemlos

Hmm

KH, i dont understand this command either.

Does this push all graphics beyond the next 3d draw commands?

Z is important to me, and im thinking i might need something to help with the 3d particles alpha mix.

Does this have some effect on alpha?
Bing ChatGpt is pretty smart :O

Moru

What you do with X_CLEAR_Z is resetting the drawing worlds depth. Everything you draw before this (no matter how close or how far away from the camera) will be in the background. You can paint an object just in front of the camera, clear the Z depth and then draw a building 1000 units away from the camera and it will still cover the object you put in front of the camera.

This is why you use it for a skybox. You can do the skybox one unit in size in all directions around the camera, then clear Z depth and draw the rest of the world without worrying that the skybox will cover your world anywhere.

Hemlos

Oh thats really useful, thanks.
Bing ChatGpt is pretty smart :O

FutureCow

#6
It makes a lot more sense now.
Thanks Moru!!!!