Jump to content

  • Log In with Google      Sign In   
  • Create Account

2D geometry outline shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Ganoosh_   Members   -  Reputation: 173

Like
0Likes
Like

Posted 11 October 2012 - 05:13 PM

Hello,

I want to create a shader to outline 2D geometry. I'm using OpenGL ES2.0. I don't want to use a convolution filter, as the outline is not dependent on the texture, and it is too slow (I tried rendering the textured geometry to another texture, and then drawing that with the convolution shader). I've also tried doing 2 passes, the first being single colorded overscaled geometry to represent an oultine, and then normal drawing on top, but this results in different thicknesses or unaligned outlines. I've looking into how silhouette's in cel-shading are done but they are all calculated using normals and lights, which I don't use at all.

I'm using Box2D for physics, and have "destructable" objects with multiple fixtures. At any point an object can be broken down (fixtures deleted), and I want to the outline to follow the new outter counter.
I'm doing the drawing with a vertex buffer that matches the vertices of the fixtures, preset texture coordinates, and indices to draw triangles. When a fixture is removed, it's associated indices in the index buffer are set to 0, so no triangles are drawn there anymore.
The following image shows what this looks like for one object when it is fully intact.
The red points are the vertex positions (texturing isn't shown), the black lines are the fixtures, and the blue lines show the seperation of how the triangles are drawn. The gray outline is what I would like the outline to look like in any case.

Posted Image

This image shows the same object with a few fixtures removed.
Posted Image

Is this possible to do this in a vertex shader (or in combination with other simple methods)? Any help would be appreciated.

Thanks Posted Image

Sponsor:

#2 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 12 October 2012 - 05:16 AM

Are you drawing geometry at different depth levels? If yes, you can create extra postprocess step which would compare depth of nearby pixels, and if any of them differs from current depth, then it should be an edge.

#3 Ganoosh_   Members   -  Reputation: 173

Like
0Likes
Like

Posted 12 October 2012 - 02:40 PM

Are you drawing geometry at different depth levels? If yes, you can create extra postprocess step which would compare depth of nearby pixels, and if any of them differs from current depth, then it should be an edge.

It's all at one depth (depth buffer is disabled as well), but that's an interesting idea. I feel that may be as slow as convolution though being at the pixel level. I'm going to see if I can apply that at the vertex level somehow.

Thanks for the input :)

#4 phil_t   Crossbones+   -  Reputation: 3922

Like
0Likes
Like

Posted 12 October 2012 - 02:44 PM

Well, I think you could do this like you might do it in 3d. Add a component to your vertices and have the outside vertices of your geometry set it to a different value than the inside vertices. Then draw the outline in your pixel shader based on the interpolated value of that component.

Of course, this requires sufficient tessellation.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS