Face area to vertex color add-on, can we improve wireframe renders?

CGMatter showed in a video how to create a wireframe shader that, unlike the cycles wireframe node,  does not look at the triangulated mesh but at the original faces.

The problem

His node setup works with an uv-layer that contains a default uv mapping (one that you can get with uv unwrap -->reset and then basically calculating the distance to the edge of the uv square.
This works but it is not quite the same as the cycles wire-frame node. As some commenters pointed out, the line thickness is a fraction of the uv square so will yield thicker lines for larger faces.

The solution?

We could correct this if we had the face area available, but this is not an attribute we can access directly using nodes.
So i came up with a small add-on that stores the face area in a vertex color layer, scaled to the largest face, so the largest face will get an rgb value of (1.0, 1.0, 1.0)
If we have such a vertex color available we can simply divide the width of the original wire-frame shader by the square root of this value (because the fraction of the uv coordinate actually scales with the length of a side). The result now looks more even for large and small quads.

Limitations

For meshes with fairly regular quads this is acceptable, however, for less regular quads this calculation might give unwanted variation, especially for thicker lines (note the quads on the edges of Suzanne's ears):

For non-quads the solution doesn't work at all because some side will not align with the principal directions of the uv-map.
So I don't think this is a solution at all, but making a face area available as vertex colors might have its use in other scenarios so it is available for download.

Download

The add-on can be downloaded from my GitHub repository. After installation it will be available in the Paint menu when in vertex paint mode. Simply select it and the active vertex color layer will be filled with grey values that represent the face area.
A .blend file with a node setup is available as well.

The wireframe node group contains an extra input that if set to a value slightly larger than zero will apply an additional perspective so that lines won't shrink with distance from the camera.

No comments:

Post a comment