Jump to content
  • Advertisement
Sign in to follow this  
AndyGeers

Detecting culls

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

Is there any way to detect whether a triangle has been back-face culled or not? (presumably if there was, it would be using vertex shaders, maybe?) ...or is the only way to find out actually to do the culling manually? I'm trying to implement a silhouetted outline for a cel-shading engine, and so wish to find those edges shared by front-facing and back-facing triangles. I'm just assuming it will be more efficient to carry on letting Direct3D do the culling for me, but if I can't find out the results then it's no use.

Share this post


Link to post
Share on other sites
Advertisement
In shader model 3.0 you can use vFace, but it sounds like you aren't using shaders anyway?

The problem is backface culling happens in the triangle setup part of the pipeline, and that's a very "write only" place - if data could be read back from there using the CPU, it would be catastrophic for performance. And vertex shader hardware is designed to be very parallel and in most shader models isn't at all well placed in the pipeline to be able to know about the triangle(s) a vertex is connected to.



Since you're trying to do an outline, there are methods which are more hardware friendly:

1) Cheap and nasty method: render the mesh twice; everse cull order, apply a slight scale to the object and render it in the outline colour, then render again with normal colour and scale. There are variations on this method such as moving each vertex down the normal rather than scaling it to avoid shifting artifacts.


2) More correct method: detect which vertices or even pixels are at an edge:

a. V dot N where V is the view direction and N is the vertex (or pixel) normal will get closer to 0 the more "edge on" (perpendicular) N is to the viewer.

b. solid outlines can be achieved with lookup textures or a clip/comparison.

c. in a vertex or pixel shader, the above is trivial; moving the view vector into object space will reduce unnecessary computation.

d. it is actually possible to do this with the fixed function pipeline too. Use D3DTOP_DOTPRODUCT3 to perform the dot product, encode the normal into one of the per vertex colours or an object space normal map and encode the object space view vector into a constant colour such as TFACTOR.


3) Cheap and reasonably nasty method for the fixed function pipeline: use a cube map which essentially contains black for all faces except the front face. The cube map is assumed to be in camera space, then just use the transformed object normals to look up into it. The side black faces fade towards white (e.g. no outline) towards the front of the cube.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you use VS_3 there is a new semantic/register VFACE that will have a positive value if the primitive is facing and a negitive value if it is backfacing. I have no idea how this interacts with the existing cull modes (presumably it is so you can manually do cull sorts of things in the vs) or of any other way to get information about culling state.

Have you considered using a second pass edge detection to get your outlines. It may not perform well enough for you, but it is probably worth looking into as it is fairly easy to implement with a pixel shader.

Share this post


Link to post
Share on other sites

This topic is 4749 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.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!