How do I generate a wireframe from a mesh?

(Chris Burnor) #1

I have a mesh, which for stylistic reason, I would ultimately like to render with both shading on the faces but also rendered outlines on the edges. This would give it a sort of ‘outline’ or ‘solid wireframe’ look. In the short term, I am trying to debug some of the basic geometry and really benefit from being able to see the individual polygons, even when they are on a ‘smooth’ object like a sphere or plane.

This might just be a terminology question (most of my coding experience is in building backend services for web applications), but I’ve been spelunking around the codebase and can’t figure out how to get the renderer to generate this effect. I suspect that it would be a type of ‘Pass’ but I can’t seem to find it, although I’m pretty sure I saw a wireframe from a mesh in a previous Amethyst example.

(Chris Burnor) #2

Ok, I’ve figured out how to do it technically in gfx but it doesn’t seem that the functionality is exposed right now in amethyst. I have it working right now with a patched branch of amethyst v0.10.0, but obviously that’s not a tenable solution long term.

So gfx sets this via RasterMethod::Line() which is currently hidden deep inside EffectBuilder. Exposing it there via setter would make it easy to create a wireframe: Pass and/or add it as an option to add edges on other Passs like DrawPbm. However, to do that, would require making RasterMethod publicly settable, which it almost looks like from the code was deliberately not done? Or was that just an oversight?

I think if RasterMethod could be exposed on EffectBuilder, then I could write a pretty straightforward Wireframe pass which I suspect would be pretty useful.

(Joël Lupien) #3

The new renderer is planned to be merged in the next few hours/days in the master git branch. It should allow writing custom passes to achieve what you want. If you see that something doesn’t allow you to do that (private types, bugs, etc), let us know! :slight_smile:

(Benjamin) #4

Using VK_POLYGON_MODE_LINE might not be the best option for this use case, since line segments come with a few potential issues. Particularly, if the wideLines feature isn’t supported, then the only supported width is one pixel. According to the vulkan hardware database, 88% of devices support wideLines. In addition, even if wideLines is supported, the range of supported widths can still be constrained. Here’s statistics for the max line width.

Another potential issue when trying to draw on top of the existing model is z-fighting, unless you don’t care about hiding the wireframe on non-visible parts of the mesh, in which case it’s fine.

An alternative and more flexible method for drawing wireframes is to use geometry shaders to determine the distance to the triangle edge, and then coloring differently in the fragment shader.

1 Like