Jump to content
  • Advertisement
Sign in to follow this  
AndyGeers

OpenGL Drawing silhouettes

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

I'm trying to implement a cel-shading system for my game, and have got to the stage of drawing the silhouetted outline. The article here provides a really simple and efficient way of doing that with very little computation (how well it works I'm not sure, but it certainly sounds logical). HOWEVER, that method is really OpenGL based and depends upon being able to change the line width so that a front-face-culled wireframe model 'sticks out' and is visible around the edges of the back-face-culled mesh. In that situation, drawing the silhouette takes about 10 lines of code and requires no extra memory. Direct3D sadly has no built in function to change the line thickness (right?) and because you have to use vertex buffers etc. it seems like manually rendering thick lines is going to require a whole lot of code and lots of extra memory to store a vertex buffer with three quads per triangle. Either that, or you use a different method altogether and do everything one triangle at a time using an Edge Buffer or similar. Am I mad, or is that true? It seems annoying that using Direct3D over OpenGL means a whole lot of extra coding/memory. Is there an easier method for thickening up my lines, perhaps using a vertex shader or something? Really, I just want to store one single representation of my mesh, and either render it normally (back-face-culled, solid) or outlined (front-face-culled, thick-lined wireframe)

Share this post


Link to post
Share on other sites
Advertisement
You are right, there are no thick lines in d3d, so this sort of approach is harder.

Another simple approach involves doing a e.n dotproduct, then mapping that to a texture that contains the edge color.

Yet another hacky way to do it is to scale up the object along its vertex normals in a vertex shader, draw just the backfaces in black, then draw the model at the normal size in the normal way.

If you are clever, you should be able to get the black lines of a known thickness by doing the extrusion based on a certain distance in view space or screenspace.

Share this post


Link to post
Share on other sites
Drawing the outline with wide lines initially sounds promising, but in practice it tends to look like ass. You tend to get edges poping into view as the model rotates (because the culling assumes flat primatives, not extruded wide lines) and you get discontinuities between line segments because of the way the lines actually get drawn (which mean you're limited to really thin lines).

Scaling the model along the normals produces *much* better results (no popping, outlines pretty much as thick as you want) and is trivial to do in a vertex shader. More tricky if you try SimmerD's method to get constant screen-space outlines though. The best solution I've found short of all the funky image-space edge detection filters.

Share this post


Link to post
Share on other sites
Yeah, I'd try the extension-along-the-normals method. There's a sample shader that does this that comes with EffectEdit, though it does it for a glow effect (Glow.fx). You might want to take a look at it.

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!