Jump to content
  • Advertisement
Sign in to follow this  
Tommato

OpenGL Outline Shader

This topic is 726 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All

 

It's very simple on CPU. There is an array of facet normals and array of edges. Pseudocode

 

struct Edge {

 int v0, v1;     // vertex indices

 int f0, f1;      // indices of facets sharing this edge

};

 

bool ShouldDrawEdge( const Edge & e, const std::vector<Point3f> & faceN )

{

 if (e.f1 < 0) return true;  // unshared edge is always drawn

 bool visible0 = dot(ToCamera(faceN[e.f0]), view_direction) >= 0;

 bool visible1 = dot(ToCamera(faceN[e.f1]), view_direction) >= 0;

 return visible0 != visible1;   // draw silhouette edge

}

 

But, of course, it works slow ;-( How to use GPU for this? Or more general question: how to pass "per face" attributes to shader? Or it's impossible with modest card like OpenGL 3.3? Or impossible at all? So powerful GPU and so simple task - why it can't? ;-)

 

Note: no "pixel-based" solutions please, it's not interested

 

Thank you

Edited by Tommato

Share this post


Link to post
Share on other sites
Advertisement

There's a few ways to do this. Without using a pixel shader these techniques come to mind.

 

One way is to draw your object twice, the second time with reverse triangle culling and push you verts out along normal in vertex shader.

 

Another way is to render your object setting the stencil value to 1, then render it again using wire frame with thick lines, with the stencil test set to only render where the value is 0. See here.

Edited by Syntac_

Share this post


Link to post
Share on other sites


One way is to draw your object twice ...

...

Another way is to render your object setting the stencil value to 1, t

In both cases I can't see how to draw unshared edges too (not contour only)

 

You can do it with the geometry shader.
Never used such kind of shader yet. From API I see - yes, the current face vertices are known and I can generate some edges as lines. But based on what? I see no any way to pass data of the current face neighbors. Have I missed something?

 

Thx

Share this post


Link to post
Share on other sites

 


One way is to draw your object twice ...

...

Another way is to render your object setting the stencil value to 1, t

In both cases I can't see how to draw unshared edges too (not contour only)

 

 

By unshared edges do you mean exterior edges/silhouette?

Share this post


Link to post
Share on other sites

>> By unshared edges do you mean exterior edges/silhouette?

 

Example (attach). Left = wireframe, Right = outline. Note that some unshared edges are not in silhouette but drawn.

 

All would be simple if possible to pass some "per-face" data to shader(s). But looks like OpenGL can't do it at all :-(

 

 

Share this post


Link to post
Share on other sites

>> By unshared edges do you mean exterior edges/silhouette?

 

Example (attach). Left = wireframe, Right = outline. Note that some unshared edges are not in silhouette but drawn.

 

All would be simple if possible to pass some "per-face" data to shader(s). But looks like OpenGL can't do it at all :-(

Actually it is possible, but it's not as simple as it could be. You can use the flat qualifier ( https://www.opengl.org/wiki/Type_Qualifier_(GLSL) ) which allows for non-interpolated per face values. These values are stored on the  Provoking Vertex of each primitive, so some vertex duplication may be necessary.

Share this post


Link to post
Share on other sites

You can do it with the geometry shader.

Never used such kind of shader yet. From API I see - yes, the current face vertices are known and I can generate some edges as lines. But based on what? I see no any way to pass data of the current face neighbors. Have I missed something?

 

Try this for example.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!