I would like to implement a shader that is capable of detecting edges and and make them black strokes like in cel shading. The thing is that not only the silhouette should be black, but also the edges that lie in the mesh. I want to achieve something like this.
Now I tried several approaches including Frei-Chen Edge detector but it seems as if this algorithm is a bit of an overkill.
I would be very thankful if somebody could give me some help with a bit of code on how to achieve this black edges effect.
Well, as far as I know now, Frei-Chen detector is made for 2d textures but not for 3d meshes. Getting the silhouette for rounded elements shouldn’t be too hard: You grab all vertices where the normal vector is perpendicular to the view vector. This would work for a sphere for example. But this wouldn’t work for meshes like cubes. Furthermore, I have no idea how to detect the “creases” of the cube.
For the edges within an object, I can think of two solutions (maybe there are others):
Render the normals of the object into a framebuffer first and then do edge detection (with Sobel or similiar) on this framebuffer.
Choose manually which edges you want to be drawn by creating a second index array with those edges and draw it with GL_LINES.
Hope this helps.[/QUOTE]
Thanks Hermannicus for your advice. I’ll try to implement the stencil buffer solution, although I fear that it will have some negative effect on the performance.
Concerning 1. on the edges within the object: I’m not sure how I can do that with the normals. 2. is not a possibility unfortunately since I want to load arbitrary meshes.