Clipping an mesh against an other one

Started by
5 comments, last by Austrian Coder 21 years, 2 months ago
Hi! As far as i know there are 2 ways to render a scene. 1. Order meshes and other stuff back to front and render it in this order. 2. Order mesehes and other stuff front to back and clip each mesh, which will be renderd, against the others and render it. In both methodes culling techniques are done before sorting. The advantage of 2 is that the overdraw is less then in 1. Now i have 2 little questions: 1. What kind of methode are using the professionals? Especially in first person games? 2. Who could i clip a mesh against an other? Thanks, Christian
Advertisement
Method 1 is also sometimes called the painters algorithm. It''s more popular for pure-software rendering (eg, the original Quake).

2 is the most common today, when using DX or GL to get a hardware z buffer to do the hard bit for you. Google for z-buffer for starters.
You should not worry about the depth clipping, the hardware will do that for you. It uses a zbuffer for that. Have a look at resources for the API you''re using. Z-buffering is typically explained very early in books and SDKs, as it is a fundamental concept of modern 3D graphics.

Although not needed for the visual result, you should still do a rough front to back sort of your objects. Not on face level, an approximate sort on object level is enough. It will allow newer hardware to cull invisible objects faster (early z-rejection).
Thanks for that inforamtions. It seems to be quite easy:
1. Enable depth testing
[ in the render loop]
2. Clear Depthbuffer
3. Set depthfunction to less
4. Render scene
5. Swap Buffers
[ End of the render loop]
You can (should) move the "3. Set depthfunction to less" step out of the render loop, into the initialization.

[Edit] At least on OpenGL, not sure about D3D.

[edited by - Yann L on January 23, 2003 10:48:20 AM]
Merci
Gruesse!

Another possible solution would be to write your very own sorting function! Compare the surfaces in the frustum by sorting surface-flags, z-order, ... and give it to qsort(...) as the ''comparison function''. have a look into MSDN!

good luck!

friendly regards from Graz!
- Christoph -


This topic is closed to new replies.

Advertisement