High-End Edge Detection Shader?

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?

Thanks.

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?

You answered my question by questions :smiley:

Nope I’m not rendering the edges of the mesh meaning that I’m not rendering as in wireframe.

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.

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.

even if the shader is in HLSL, this is interesting, skip to “9.5 Antialiasing” :
http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter09.html

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.

Thanks.

Well from the text, the idea is use heuristics to detect probable edges:

  • if neighbor depth is different enough : mark as edge
  • if neighbor normal is different enough : mark as edge

What is an edge anyway ? Just a very sharp thingy :slight_smile:

Can you point us to which one exactly ?

Looks like Pierre was refering to GL_AMD_shader_stencil_export