Is there a way to render edges of a complex/composed model such that it shows only edges of the polygon, not the mesh. For instance, a planar polygon may consists of many triangles. It’s almost the same effect as in cel/sketch shading shading, but additional detail edges have to be shown.
A simple edge detection shader may work but it does not show edges ins some cases…lets say two boxes are rendered where one box is partially obscuring the other one:
------
| |
| |
B ------
------
| |
| |
C ------
^
viewer
Edge C is not shown in this case since polygon C and polygon B
are parallel.
Is there any sample shader that handle such cases?
Only edges of the polygon, not the mesh? What does that mean? The first two sentences seem to contradict each other. You want to render the edges of the polygon, not the mesh. Like wireframe mode does? A planar polygon has many triangles, true. You want those rendered or not?
That’s some funky ASCII art. I assume edge C is the two pipes between letters B and C?
Do you want a wireframe mode, but still want the mesh to occlude objects behind it?
I want to render the edges wherever there’s a possible edge that shows the detail of the mesh, such as silhouette, crease, feature edges…etc.
Sounds like you need a geometry shader. Basically, what you want to do is make a geometry shader that generates lines from triangles. Use one of the adjacency triangle types to decide when to generate lines based on the angles of adjacent triangles.
note that in opengl, you can use an amd extension to write the stencil value in the pixel shader in order to directly find your edges in one pass. (with the centroid sampling trick)
This is exactly the same effect I want as in the GPU gems. However I’m not sure what shader model this HLSL is because I need to translate it to GLSL first.
I’m restricted to SM 3.0, no geometry shaders or any advanced extensions.