Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Outline with GLSL ?

  1. #1
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    43

    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.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941
    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.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  3. #3
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    43
    Quote Originally Posted by aqnuep View Post
    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 ?

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,714
    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.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941
    Are you sure that scale would work well with concave geometry too?
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  6. #6
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    43
    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 ?

  7. #7
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    43
    uh oh code above did not work with my terrains

  8. #8
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    43
    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..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •