tc_curvature v1.0

A Mental Ray shader for calculating surface curvature. by Tom Cowland -


PLATFORMS: OSX (PPC + Intel) / Win / Linux / 32bit + 64bit - Mental Ray 3.2.6+

Please take a moment to have a look over the notes below. This shader usualy needs a lot of tweaking to get good results.



Now includes 64bit versions!



tc_curvature lets you calculate surface curvature for procedural shaders. usefull for creating the effects of wear and tear on sharp corners. works with nurbs, sub-divs and poly geometry. This is the first public version so please send any comments or feedback my way. Currently for OSX only, If anyone can muster up a Win/Linux compile, that would be great!

example scene [ render ]


Probably most usefull as the u or v input to a ramp. Assign to the 'out colour' of a surface shader for parameter tweaking...

In order to use this shader in 'Surface Derivatives' mode with NURBS surfaces, you need to first tell maya to save the derivatives whilst translating the scene. to do this, do the following:

  1. Select the shape node of your object. The easiest way is often to select its tab in the Attribute Editor, then click the 'Select' button at the bottom of the AE.
  2. Type "tcAddDerivs" into the command line.
  3. You should now see the 'miDerivatives' setting in the 'Extra Attributes' section. For the shader to work properly, this needs to be set to '3'.

You dont need to do this for Poly meshes or whilst using any of the tesselation based methods.


Calculate from:

- Surface Derivaives (NURBS)
Select this option when working with NURBS surfaces. Curvature is calculated from the derivatives in the state->derivs array. If you choose this method with polys and some sub-div surfaces, you'll just get black.

- Tesselation
Curvature is calculated by comparing the face normal to the vertex normals. This is suitable for any kind of geometry. This only works with 'softened' normals. Any hard normals will not show curvature. This method has the downside that the curvature value is 'per face', so with low poly geometry, you will get noticable steps in the output. (see example below)

- Normal Sampling
Curvature is calculated by arbitrarily sampling the normals around the current surface point. This has the benefit that you should get a smooth output no matter how coarsly tesselated the geometry is.


- Average
The presented curvature is the average of the principal curvatures (NURBS), the average of the vertex curvatures (Tesselation) or the average of the sampled points (Normal Sampling).

- Gaussian
This is the product of the curvatures. Generaly highlights only sharper curvatures compared to average.

- Barycentric Interpolation (Tesselation derived curvatures only)
This interpolates the vertex curvatures depending on where you are on the face. Has the effect of softening Tesselation based curvature, though sometimes it gives a 'fish scale' like effect. .


- Full (only usefull for NURBS surfaces)
Negative (concave) curvature is clipped at 'Concave Max' and scaled to the output range between 0 -> 0.5. Positive curvature (convex) is clipped at 'Convex Max' and scaled to the output range between 0.5 -> 1.0. No curvature = 0.5.

- Convex only (+ve)
Negative curvature is ignored, and the range betweeen flat (0) and 'Convex Max' is scaled to the output range 0 -> 1.0. This setting is the most usefull for poly geom.

- Concave only (-ve)
Positive curvature is ignored, and the range betweeen flat (0) and 'Concave Max' is scaled to the output range 0 -> 1.0. Only usefull with NURBS surfaces.

Convex max:

The 'upper clipping' value for positive curvature. This will usualy need quite a bit of tweaking from the default as curvature seems to vary quite a lot from surfce to surface.

Concave max:

As above, but for negative curvature.


When using the 'Convex only' or 'Concave only' range setting, this value sets a 'low clip' value, so you can trim away small curvature values from the lower end of the scale.

Smooth Result:

When enabled, applies cardinal spline interpolation of the curvature between 0 and 1.0.

Smooth gamma:

Moves the mid-point of the spline used for interpolation. Works a little bit like a gamma control. NOTE: at the moment, extreme settings can cause vaules above 1.0 and below 0.0 - got to sort that out.


The number of samples per point in 'Normal Sampling' mode.


The focus of the sample rays cast. Higher values samples over a smaller area. Use for more precise curvature calculation. Kind of a backwards 'ray spread'.




with nurbs objects the shader has the option to calculate curvature based on the surface derivatives. This is a nice method as it easlity allows us to know wether the surface is convex or concaved.

the images below are a few quick examples showing the different options:


full range output

convex only output

concave only output



Polygon geometry

there are two options for recovering curvature from poly meshes (or tesalated nurbs - see below). The first - 'tesselation' gives per-face curvature. Youll notice this has an obvious problem with big faces. An alternative is 'normal sampling' which samples the surface normals independently of tesselation, which gives smoother results. With the current inplementation, poly geometry only ever gives +ve curvature output.



tesselation with barycentric interp.

nomal sampling.

notes / known issues:


This stared life as a simple NURBS derivatives shader, inspired by the works and research of:

Thomas Burge -
Tien-Tsin Wong, Wai-Yin Ng and Pheng-Ann Heng - Chineese University of Hong Kong
the LA Mental Ray Users Group -

Many thanks and much respect to those guys.

The Normal Sampling component was helped to life by some of Daniel Rind's shader helper functions. Many thanks to him for his generosity in making his code avaiable.

Also, thanks to Shane Clodd at Alias Tech Suppoort. :-)

Big thanks to Jan Sandström and Bill Spradlin for getting the Win compile together, and spotting some silly bugs in the code...

Big thanks to Colin Strause for the LINUX compile and Hypershade icon.

Many thanks to Haggi Krey for the Win64 compile

license / etc...

This shader is free of charge for you to do whatever with. If you use it on anything fun - let me know! The source code is avaiable at the top of the page, if you change the shader, please let me know...


< Back to OSX Mental Ray Shaders