PDA

View Full Version : Outline with GLSL ?



artariel
06-21-2012, 03:06 PM
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.

aqnuep
06-21-2012, 03:36 PM
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.

artariel
06-21-2012, 03:56 PM
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.

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

Alfonse Reinheart
06-21-2012, 06:31 PM
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.

aqnuep
06-21-2012, 08:59 PM
Are you sure that scale would work well with concave geometry too?

artariel
06-21-2012, 10:07 PM
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 ?

artariel
06-21-2012, 10:16 PM
uh oh code above did not work with my terrains

artariel
06-26-2012, 07:27 AM
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..