Outline with GLSL ?

Since I couldn’t find any way to outline models drawn with VBOs, i started to find a GLSL way. I am creating a toon shader, it successfully works with lights but there’s last thing to do : Outline everything. How can i calculate outer fragments of a model ? I searched whole internet but there’s only a nehe example, older than me.

There are multiple ways to do it, here are the two main approaches:

  1. Image space method: apply an edge detect filter as a full screen post-process pass and then perform another full screen pass to draw the outlines where there were edges. The edge detection itself can be based on depth or color incontinuities. Also you have multiple choices of filters: Sobel, Frei-Chen, Canny, etc.
  2. Geometry based method: detect edges in a geometry shader using e.g. adjacency primitives or other tricks.

[QUOTE=aqnuep;1239137]There are multiple ways to do it, here are the two main approaches:

  1. Image space method: apply an edge detect filter as a full screen post-process pass and then perform another full screen pass to draw the outlines where there were edges. The edge detection itself can be based on depth or color incontinuities. Also you have multiple choices of filters: Sobel, Frei-Chen, Canny, etc.
  2. Geometry based method: detect edges in a geometry shader using e.g. adjacency primitives or other tricks.[/QUOTE]

thanks. do you know how to apply method “draw twice, one with back culling” using VBOs ?

It doesn’t matter how you store your vertex data. You turn on backface culling. You render as normal. You reverse the backface culling. You render with a shader that will scale the vertices out a bit.

Whether you use buffer objects has nothing to do with it.

Are you sure that scale would work well with concave geometry too?

okay this is what i do and it worked :

glDrawArrays(GL_QUADS, 0, sizeof(g_cube) / sizeof(g_cube[0]));
glUseProgram(0);
glCullFace(GL_FRONT);
glColor3f(0,0,0);
glScalef(1.05,1.05,1.05);
glDrawArrays(GL_QUADS, 0, sizeof(g_cube) / sizeof(g_cube[0]));
glCullFace(GL_BACK);
glScalef(1,1,1);

but i found it a bit wrong, because i have to call useprogram(0) because it also shades the backculling so i can’t have a true-black outline. but i mustn’t call it because this isn’t the only object rendered.

by the way how can i do it push-pop attributes style ?

uh oh code above did not work with my terrains

i still couldn’t find any stable outline method. one doesn’t work with terrains, one doesn’t work with simple materials, one lags etc…