# Why do clipping?

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

## 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 on other sites
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.

##### 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 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 on other sites

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 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 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 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 on other sites
Hidden
Well, can you see the polygons past your screen?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015430
×