PDA

View Full Version : High-End Edge Detection Shader?



glfreak
02-19-2010, 11:52 AM
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.

strattonbrazil
02-19-2010, 05:40 PM
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.


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?

glfreak
02-22-2010, 01:37 PM
You answered my question by questions :D

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.

Alfonse Reinheart
02-22-2010, 01:52 PM
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.

ZbuffeR
02-22-2010, 02:05 PM
even if the shader is in HLSL, this is interesting, skip to "9.5 Antialiasing" :
http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter09.html

Pierre Boudier
02-22-2010, 02:13 PM
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)

glfreak
02-23-2010, 10:54 AM
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.

ZbuffeR
02-23-2010, 02:18 PM
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 :)

ZbuffeR
02-23-2010, 02:19 PM
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)
Can you point us to which one exactly ?

Nicolas Lelong
03-12-2010, 07:20 PM
Can you point us to which one exactly ?
Looks like Pierre was refering to GL_AMD_shader_stencil_export (http://www.opengl.org/registry/specs/AMD/shader_stencil_export.txt)