2D geometry outline shader

Started by
2 comments, last by phil_t 11 years, 6 months ago
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.

fullmesh_zps4f4b2781.png

This image shows the same object with a few fixtures removed.
brokenmesh_zpscbd5f81a.png

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

Thanks smile.png
Advertisement
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.

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 :)
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.

This topic is closed to new replies.

Advertisement