Jump to content
  • Advertisement
Sign in to follow this  
ProgrammerDX

Why do clipping?

This topic is 2426 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

Hello,

I was just wondering.

Why do clipping? I can't find any info why clipping is useful. I mean, it doesn't reduce the data that is sent to the GPU.. and it only costs more processing time to clip a polygon against a plane..

So.. why is clipping useful?

Share this post


Link to post
Share on other sites
Advertisement
Hidden
Ah the usual misinterpretation of clipping being the same as culling. With clipping I mean a polygon which is to be 'cut' in pieces by a viewing frustum plane.

Share this post


Link to post
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

Ah the usual misinterpretation of clipping being the same as culling. With clipping I mean a polygon which is to be 'cut' in pieces by a viewing frustum plane (the polygon is intersecting the plane)

[/font]

Share this post


Link to post
Share on other sites
Because you can draw a primitive much faster when you can simply assume that all its pixels are within the bounds you are trying to draw. Clipping a primitive is really quite cheap, and it's already-low cost is further reduced by amortization across however many pixels would have been in the non-clipped primitive -- if you assume triangles averaging only 25 pixels in area, the cost to clip it is probably less than 1 instruction per pixel. The cost is more-or-less fixed (a point or line can never result in more than one point or line, but triangles can result in upwards of 4-5 new triangles after clip).

The only other alternative would be to have a conditional test on each pixel, trivial rejection costs at least one conditional, up to four for the worst case (non-clipped pixels), per pixel -- at, say, 2 instructions per conditional that's an order of magnitude more work just do test boundaries, then, you also have to interpolate at least the coordinates for all pixels, even ones that won't be drawn, so probably 2 orders of magnitude. The disparity gets worse the more of the primitive is out of bounds.

In short, it's almost always far better to choose O(1) than O(n), even when the function of O(1) seems to have a sizable fixed-cost.

It's all about avoiding computations further down the pipeline -- remember, the fastest way to do work is to avoid having to do it at all.

Share this post


Link to post
Share on other sites
Alright, thanks for your answer.

Is it normal practise to use IDirect3DDevice9::SetClipPlane everytime the view frustum changes?
Or is it possible to enable Direct3D clipping but not having to use SetClipPlane yourself everytime the projection/view changes?

Share this post


Link to post
Share on other sites
SetClipPlane is used for user-defined clipping planes, in addition to the 6 planes of the projection frustum. Clipping against the default 6 planes happens automatically and can't be enabled/disabled.

So you only need to use SetClipPlane if you've got extra, custom planes to clip against.

Share this post


Link to post
Share on other sites
I see.

Well when you do the clipping yourself, you ca clearly see in wireframe mode how the clipping is happening.

However, if I don't do clipping myself, then in wireframe I don't see DirectX doing any clipping for me..

So, I don't think DirectX is clipping for us

Share this post


Link to post
Share on other sites
Can you provide screenshots? You shouldn't be able to see the clipping that Direct3D does, since it's clipping things that are already offscreen. So if you were able to see them you'd see what's off the screen.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!