Sign in to follow this  
TheMeatMan

DirectX, problem with clipping.

Recommended Posts

Hello. I am trying to disable the clipping of geometry in my project and purely use a frustum test. I have certain objects that I test for visibility against the frustum, and it works great. I have other objects that I want to render all of the time and do not pass them to the frustum test. However, when those objects fall outside of the far clipping plane they are not rendered although I want them to be. When I create those object's vertex buffers I am using the switch D3DUSAGE_DONOTCLIP (in addition to D3DUSAGE_WRITEONLY), and before rendering I am setting the D3DRS_CLIPPING to FALSE (D3DRS_ZENABLE is set to D3DZB_TRUE). Am I missing a call or flag? Like I said, everything displays fine, I just want certain things to remain visible at 'far' distances. Thank you.

Share this post


Link to post
Share on other sites

I'm not all the confident of this answer, so I could be wrong, but here's what I suspect:

When you create a projection transform (e.g. with D3DXMatrixPerspective()) Your projection matrix maps the depth value into a range between 0 and 1 (after perspective divide, that is), based on the near and far clipping distances that you set.

If I were to venture a guess, I would say that what's happening here is that the rasterized Z values of your object are becoming greater than one, and they are getting clamped, and they end up failing the Z-test because you've already cleared the Z-buffer to one.

If that's true, then changing the depth test to LESSEQUAL instead of LESS (or disabling Z-buffering) should cause them to be rendered.


JB

Share this post


Link to post
Share on other sites
As far as I know you cannot disable the clipping of objects all together as Direct3D needs to follow the pipeline which states that in the T&L stage (Transform and Lighting and then after that clipping/culling) a world, view and projection transformation is used to basically take your frustrum and block that to a 1 unit cube and map that to the screen which is then your screen space mapped coordinates. Now Direct3D needs to have some boundaries set either in default or by the user to know what is inside and outside of this 1 unit cube.

What you could do is tremendously increase the clipping planes in Direct3D (projection transformation matrix) but this is frowned upon as you will want to increase performance by taking advantage of clipping items out of your clipping planes.

i.e.
D3DXMatrixPerspectiveFovLH(&mat, D3DX_PI/6, 4.0f/3.0f, 1.0f, 10000.0);

I hope this helps.
Take care.

Share this post


Link to post
Share on other sites
Thanks for the quick responses. I have a question though, if Direct3D doesn't want you to disable clipping, what exactly do the D3DUSAGE_DONOTCLIP and D3DRS_CLIPPING flags actually do? Did I misread the MSDN descriptions?

Again, thank you for your responses.


--edit--
Nice tutorials by the way Pieter!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this