SEARCH AND PRESS ENTER
Maya API / 22 Jun 2016
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. #### Jason

03 Jan 2022 - 5:42 pm

Hi, I know this is a bunch of years later, but did this shader simply not exist before 2016?

Arnold now has an aiCurvature shader, and I’m wondering what the differences are between that and this, or if they just implemented the same principles as you have here?

• #### Stepan Jirka

10 Jan 2022 - 8:27 am

Hi Jason,

There has been some curvature shaders for Maya before before but none for real-time work in the viewport. For my job I made one in ShaderFX which is calculated in the screen space. It’s little less accurate but the performance is way better and it’s more stable than this plugin. Maybe they did something similar.

Stepan

2. #### dario

08 Mar 2020 - 7:18 am

Hi Stepan. It possible to bake the shader to vertex color? IT would be great to have an option to do this.
Thanks

• #### Stepan Jirka

08 Mar 2020 - 7:49 am

Hi Dario,

I’m sorry, this shader doesn’t have that option as the main point of it was a real-time display. It’s currently not being developed further. There are however scripts out there that do exactly what you’re looking for.

Stepan

3. #### Sergey

25 Nov 2019 - 9:12 pm

Hi! Thanks a lot for the shader! Could you make maya 2019 version? Would be very appreciated

4. #### Jose

06 Nov 2018 - 2:19 pm

Very nice! Thank you!

5. #### Val

24 Apr 2018 - 6:55 am

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

24 Apr 2018 - 7:48 am

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

6. #### hao

30 Mar 2018 - 2:55 am

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

• #### Stepan Jirka

30 Mar 2018 - 6:37 am

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

24 Aug 2017 - 1:01 pm

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

8. #### Malom

28 Feb 2017 - 11:26 pm

How to install this tool?

• #### Stepan Jirka

01 Mar 2017 - 7:24 pm

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.

9. #### dario

13 Feb 2017 - 2:22 pm

great job