1. Are you one of the people who’d kill for a curvature shader for Maya? Good news, you don’t have to!

Although polygons are no match for mathematically defined NURBS surfaces when it comes to serious design surfacing, in sketch modelling and concept development they’re killing it. To get the best speed to surface quality ratio when dealing with polygons I created this curvature shader for Maya. It is an ultimate tool for highlighting lumps and imperfections in your model as well as achieving better control over surface transitions and radii.

If you found this article while searching for “Maya curvature shader”, there’s quite a big chance you already found HW shader by Byron or Mentalray shader by Tom Cowland. Originally I though I’d do just fine with Byron’s shader, but I ended up with completely new plugin when trying to improve performance and display quality.

### Computing vertex curvature

The both previously mentioned shaders are using very common method of calculating mesh curvature by measuring angle between face normal and vertex normal. The angle is then divided by perimeter of the face which results in higher curvature values in areas with increased density such as radii. Also thanks to this step the displayed curvature stays the same regardless of subdivision level of the mesh.

Since this method measures curvature per-vertex-per-face, with the same vertex the value differs for each adjacent face. This causes somewhat jagged appearance, which doesn’t improve even with increased subdivision levels. The easiest way to fix this problem is to average values of each vertex.

Here’s another problem. The angle between face normal and vertex normal ranges from 0° to 90° without any indication whether we’re dealing with a positive or a negative value. Luckily we can get this information by comparing orientation of angle plane normal and a reference plane normal.

Curvature shader based on vertex-to-face normal angle has one major weakness which shows in areas where for example a tight positive radius crosses a larger negative radius. This issue was the main reason I came up with algorithm which uses adjacent edge instead of face normal.

This method beats the previous one in several ways. The angle between vertex normal and adjacent edge falls between 0° and 180°, where value < 90° indicates negative curvature while value > 90° is a sign of positive curvature. It also handles better the previously mentioned scenario of two radii with different size and orientation since the average curvature is weighted by individual edge lengths.

### Preparation

Although MPxHwShaderNode::geometry() method provides points and vectors of the rendered mesh in function parameters, it doesn’t give us any information about connections between vertices, which is crucial for this plugin. Fortunately we can get DAG path of the rendered mesh with MPxHwShaderNode::currentPath() which we’re going to call inside MPxHwShaderNode::bind().

Before calculating the surface curvature we have to generate a smooth mesh according to its smooth display options.

### Implementation

Once we have the smooth mesh, the easiest way to calculate curvature values is using MItMeshVertex to query vertex position, normal, and connected points to define adjacent edges.

The rest is simple vector math. Using current vertex position and a connected point we construct a vector for each adjacent edge and calculate an angle to vertex normal. Since the angle is in 0-π range we need to offset it so that π/2 (zero curvature) becomes 0 (to achieve symmetric scaling for positive and negative values). After applying edge length and custom scale we calculate an average vertex curvature which needs to be offset back to get correct values from MRampAttribute.

### Rendering

With previous code we got colors, positions and normals of all mesh vertices which we can now use to draw triangulated mesh with OpenGL

### Conclusion

This article covers the most important part of making a mesh curvature shader such as quering mesh properties, calculating vertex curvature and OpenGL rendering. Since this plugin is computing values for thousands of vertices I used some additional steps to improve performance, which you can check in source files.

1. Jose

Very nice! Thank you!

2. Val

Hi!
This seems to be great but I´m not able to load this in maya 2018.
I´ve copied the file and loaded the plugin for maya2018_x64 but I must be doing something wrong:

// Error: line 1: Cannot find procedure “curvatureShader”. //

• Stepan Jirka (Author)

Hi Val,

it is even easier than that. After you load the plug-in it becomes available in the Hypershade.

Don’t forget to set your rendering engine in Preferences->Display>Viewport2.0 to OpenGL. I’ve created a new, more stable curvature shader (because this one isn’t so stable) which works with DirectX 11 but I didn’t find time to prepare it for release yet.

Best regards

Stepan

3. hao

hi i test this shader in maya2018 the mesh wil be transparent in viewpoint . is that something wrong with me install?

• Stepan Jirka (Author)

Hi Hao,

Make sure you have textures enabled and the rendering engine for VP2.0 is set to OpenGL – Legacy. (Preferences->Display->Viewport2.0)

Best regards

Štěpán

thanks so much saved alot of head scratching and will hopefully save me time exporting to another software for minimum radius checking.

5. Malom

How to install this tool?

• Stepan Jirka (Author)

Hi Malom,

to be completely honest this version is more for developers as it is not quite complete. I’m planning a release of a proper version soon. Stay tuned.

6. dario

great job