Skip to main content
GameDev.net gamedev.net
🔒 Locked

Hidden face removal

Started by spiffycrony Mar 12, 2007 at 10:40 PM 3 replies 900+ views
Original Post
spiffycrony
spiffycrony
I am using Directx8(as client is using that). I have a model drawn in wire frame. I want to do the hidden face removal. Any ideas?
LostSource
LostSource
Take the surface normal (we'll call this S) of a face that your testing and take the dot product of that face normal and the look vector (we call this L) of the camera. Then if S dot L is less then 0 then the face isn't facing the camera, so don't render it.

S dot L > 0 facing the camera (acute angle)
S dot L = -1 facing opposite directions (180 angle)
S dot L < 0 not facing the camera (obtuse angle)
S dot L = 0 then the two are perpendicular to each other
Nik02
Nik02
If you want to leverage hardware acceleration in this, I recommend using the following approach:


  1. Render your model as solid faces into the z-buffer only, after disabling color writes by using D3DRS_COLORWRITEENABLE render state.
  2. Set your depth comparison function to "less or equal" (D3DRS_ZFUNC renderstate).
  3. Enable color writing and draw your wireframe. Invisible faces will be filtered out by the z-buffer filled in step one.
Niko Suni
spiffycrony
spiffycrony
LastSource - The method you described is for drawing triangles which face the user and avoiding triangles which are flipped. But what I am trying is to avoid triangles which are far away(something like using the zbuffer). Correct me if i am wrong.

Nik02 - I have been trying to use the z-buffer. For some reason it misses some valid triangles which are on the front.
Nik02
Nik02
Quote:
Original post by spiffycrony
Nik02 - I have been trying to use the z-buffer. For some reason it misses some valid triangles which are on the front.


Both the filling of the depth and the actual wireframe rendering must be done with exactly same transformations in order for the technique to work. If you mix vertex shaders and fixed function transforms now, refactor your code so that you can use the same vertex shader on both steps.

Also, do an extra check to ensure that the depth compare function is actually "less than equal". If it is "less", some (if not all) of the wireframe pixels are masked out. You could also try to apply a z-bias to the wireframe in order to bring it nearer to the screen, thus passing the z-test more easily.
Niko Suni

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.