• Advertisement
Sign in to follow this  

[Resolved]Clipping rendering to a region in 3D space

This topic is 4309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Without modifying the zbuffer or stencil buffer, how can I clip rendered geometry to a specific region in world space? I'm trying to clip rendered geometry to a cube, without using the stencil buffer or zbuffer. I'm thinking of clip planes but I don't know enough about them to try. Thanks :) [Edited by - CadeF on April 7, 2006 6:26:34 PM]

Share this post


Link to post
Share on other sites
Advertisement
Yep clip planes will work, you will need 4 of them obviously. Remember to specify them in clip space instead of world space when using shaders.

Share this post


Link to post
Share on other sites
Any code on how to do this? Unless I'm mistaken, making a clip plane for each face of a cube, will require 6 planes, not 4. I'm using shaders, if that applies to the code.

Share this post


Link to post
Share on other sites
Yes, clipping to a cube will require 6 planes. When using FFP the clip planes are given in world space, when using the programmable pipeline, as in your case, they have to be given in clip space. You should have a look at the SetClipPlane() function in the DirectX SDK documentation.

Hope that helped.

Share this post


Link to post
Share on other sites
In the DirectX SDK, SetClipPlanes is sort of informative, but a code sample, preferrably using shaders, would help me. Thanks for the advice so far. :)

Share this post


Link to post
Share on other sites
Right 6, i wasn't thinking. This is how I'm transforming the world space clip plane to clip space:


void ClipPlane :: computeClipSpacePlane() {

//normalize the plane which is required for the transforms
D3DXPLANE tempPlane = worldSpacePlane;
D3DXPLANE viewSpacePlane;
D3DXPlaneNormalize(&tempPlane, &tempPlane);

//transform the plane into view space
D3DXMATRIX tempMatrix = dxAppSettings.matView;
D3DXMatrixInverse(&tempMatrix, NULL, &tempMatrix);
D3DXMatrixTranspose(&tempMatrix, &tempMatrix);
D3DXPlaneTransform(&viewSpacePlane, &tempPlane, &tempMatrix);

//transform the plane into clip space, or post projection space
tempMatrix = dxAppSettings.matProj;
D3DXMatrixInverse(&tempMatrix, NULL, &tempMatrix);
D3DXMatrixTranspose(&tempMatrix, &tempMatrix);
D3DXPlaneTransform(&clipSpacePlane, &viewSpacePlane, &tempMatrix);
}





And then in your shader code you don't have to do anything. Note that 6 is the limit on clip planes that any hardware can support, and mostly only DX9 cards support clip planes in hardware. Also 6 clip planes will have a pretty big performance hit. You can implement them yourself in the pixel shader and not use the SetClipPlane() functionality if you want, that's one dot product and compare for each plane, so 12 instructions per pixel!!!

Share this post


Link to post
Share on other sites
Well then, I will try primitive clipping, since I will only be culling a few triangles. Thanks for the help, everyone.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement