Click to See Complete Forum and Search --> : IDirect3DDevice9::Clear()
MrDoomMaster
August 15th, 2005, 03:16 PM
The last two parameters of this function are very confusing to me.
The second to last parameter is a value 0.0f - 1.0f. All I know is that a value of 1.0f clears the ZBuffer appropriately, while a value of 0 causes much distortion in objects. What does this range of values represent? MSDN fails to discuss this parameter in detail.
The last parameter is a number controlling how the stencil buffer is cleared. I don't understand much about the stencil buffer in the first place, so if someone could explain the stencil buffer and also explain the last parameter in this function, I would greatly appreciate it. MSDN fails to discuss this parameter in detail.
Smasher/Devourer
August 15th, 2005, 09:17 PM
The second-to-last parameter is the value that is used to fill the z-buffer. Using a value of 1.0 is typical because that is the initial state of the z-buffer when nothing has been rendered. As you and I have talked about before, prior to rendering, geometry is transformed into the canonical view volume, which in Direct3D extends from 0.0 to 1.0 along the z-axis. Each polygon being rendered within that volume is considered one pixel at a time, and each of those pixels thus has a z-value on the interval [0.0, 1.0]. That value is what's compared against the corresponding location in the z-buffer to determine whether or not the pixel should be drawn. So if you fill the z-buffer with the value 1.0, which corresponds to the maximum z-value a pixel can have and still be visible, the effect is to "reset" the z-buffer. If you were to call Clear() with that value set to 0.5 instead of 1.0, nothing in the back half of the view volume would be rendered; all those pixels would be rejected when tested against the z-buffer.
The last parameter serves an analogous function, but for the stencil buffer rather than the depth buffer. You can find an article that discusses the nature and some uses of the stencil buffer here (http://developer.nvidia.com/object/Stencil_Buffer_Tutorial.html). It's more than five years old and it talks about OpenGL, but the first few pages should still give you a good idea for what a stencil buffer is.
MrDoomMaster
August 15th, 2005, 10:22 PM
So basically the value 0-1 represents which percentage of the area of the distance between the near and far clipping planes to render? The Canonical View Volume, on the Z axis, goes from -1 to 1, correct? So submitting 0.5 as the parameter would cause only range 0 to 1 to be rendered? Range -1 through 0 would be ignored?
I find this hard to picture in my mind, and also seems quite useless. I don't know why you wouldn't want parts of the volume being rendered. I figure you would just adjust your far clipping plane to do that.
Smasher/Devourer
August 15th, 2005, 11:29 PM
The Canonical View Volume, on the Z axis, goes from -1 to 1, correct? So submitting 0.5 as the parameter would cause only range 0 to 1 to be rendered? Range -1 through 0 would be ignored?
No, the CVV extends from 0 to 1 along the z-axis, as I mentioned in my last post. Passing a value of n for the second-to-last parameter of Clear() will prevent anything on the range [n, 1] from being rendered, while allowing geometry on [0, n]. So while you can think of that parameter as a percentage of the view volume that's being considered for rendering, it's actually a specific z-value. It only happens to come across as a percentage because the CVV is exactly one unit deep under Direct3D. You may be thinking of OpenGL, under which I'm pretty sure the CVV extends from -1 to 1 on all three axes.
As to why you would use this, I really don't know. If I were clearing the display and the depth buffer, and wanted to disallow rendering for some percentage of the back of my view volume, I'd probably just do what you suggested and alter the size of my view volume for the next frame. Perhaps there are some situations in which you'd want to clear the depth buffer to some nontrivial value without clearing the display, for some particular rendering task that's done on top of an existing image, but I haven't used Direct3D nearly enough to do any more than speculate on that. Sorry...
MrDoomMaster
August 16th, 2005, 12:56 AM
No, the CVV extends from 0 to 1 along the z-axis, as I mentioned in my last post. Passing a value of n for the second-to-last parameter of Clear() will prevent anything on the range [n, 1] from being rendered, while allowing geometry on [0, n]. So while you can think of that parameter as a percentage of the view volume that's being considered for rendering, it's actually a specific z-value. It only happens to come across as a percentage because the CVV is exactly one unit deep under Direct3D. You may be thinking of OpenGL, under which I'm pretty sure the CVV extends from -1 to 1 on all three axes.
As to why you would use this, I really don't know. If I were clearing the display and the depth buffer, and wanted to disallow rendering for some percentage of the back of my view volume, I'd probably just do what you suggested and alter the size of my view volume for the next frame. Perhaps there are some situations in which you'd want to clear the depth buffer to some nontrivial value without clearing the display, for some particular rendering task that's done on top of an existing image, but I haven't used Direct3D nearly enough to do any more than speculate on that. Sorry...
Thank you for all of your help, you've been extremely helpful, as usual!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.