tc_curvature v1.0
A Mental Ray shader for calculating surface curvature. by Tom Cowland - mr@tomcowland.com
http://www.tomcowland.com/mentalray
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.
UPDATE!
Now includes 64bit versions!
overview:
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! |
download:
tc_curvature.ziptc_curvature_source.zip
example scene [ render ]
useage:
Probably most usefull as the u or v input to a ramp. Assign to the 'out colour' of a surface shader for parameter tweaking...
IMPORTANT:
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:
- 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.
- Type "tcAddDerivs" into the command line.
- 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.
parameters:
Calculate from: |
- Surface Derivaives (NURBS) - Tesselation - Normal Sampling |
Method: |
- Average - Gaussian - Barycentric Interpolation (Tesselation derived curvatures only) |
Range: |
- Full (only usefull for NURBS surfaces) - Convex only (+ve) - Concave only (-ve) |
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. |
Threshold: |
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. |
Samples: |
The number of samples per point in 'Normal Sampling' mode. |
Focus: |
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'. |
examples:
NURBSwith 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 geometrythere 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 |
tesselation with barycentric interp. |
nomal sampling. |
notes / known issues:
- The output range varies considerably from surface to surface so much tweaking of the clipping values is usually needed.
- The output between different methods ( Derivs / Tesselation / Sampling ) will probably vary quite a lot for the same surface.
- It seems the way Maya processes sub-div surfaces leaves any parts of that have been modified in Poly mode without derivatives. Best use Tesselation / Sampling mode.
- If you have a NURBS surface built from many patches, you may get bad results. Try Tesselation / Sampling modes...
- If you have very fine polygon tesselation, then the effective curvature of each face is reduced. This may lead to 'black spots' where several faces actualy have low curvature, despite being on a perceptualy 'curvey' edge. Normal Samping should get around this, if you still have probs, try reducing Focus.
- There are a few black spots on occasion with the Normal Sampling method - some NaN values to hunt down...
- It just doesnt seem to work well with certain geometries/topologies. :)
- With 'smooth' turned on, you may get values above 1.0 or below 0.0 in the output. (got to fix that)
thanks:
This stared life as a simple NURBS derivatives shader, inspired by the works and research of:
Thomas Burge - affine.org
Tien-Tsin Wong, Wai-Yin Ng and Pheng-Ann Heng - Chineese University of Hong Kong
the LA Mental Ray Users Group - lamrug.org
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...