|
Toon and contour shader tutorial for Maya® (mental ray 3.4+)
David Lanier 3D hereby grants to you a royalty-free, non-exclusive license to possess and to use the
following shaders for both commercial and non-commercial purposes.
NO WARRANTY: THE SOFTWARE AND ANY OTHER MATERIALS PROVIDED BY DAVID LANIER 3D TO YOU HEREUNDER ARE PROVIDED "AS IS."
DAVID LANIER 3D DISCLAIMS ALL WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** Use them at your own risks **
Download :
shader for Maya
Image realized with our shader, courtesy of Andy Alesik : www.alesik.de

Tutorial :
In the Maya7path folder, set the mi file in the subfolder :
maya7path\mentalray\include
Add the DLL in the subfolder
maya7path\mentalray\lib
(In version of Maya 8 and later, no need to modify the .rayrc file)
Then modify the maya.rayrc file located in : maya7path\mentalray\maya.rayrc
By adding
link "{MAYABASE}/lib/dl3d_toonshader.{DSO}"
and
mi "{MAYABASE}/include/dl3d_toonshader.mi"
And finally, add the .xpm into maya7path\icons
Well, that's all.
Set mental ray® as the default render engine, suppres the "Enable default light" in the render options and add a Maya light in your scene.

First get your object (in this example a simple sphere), select its shading group in the Attribute editor and go in the mental ray® section and in the Custom shaders subsection :

Now click on Supress all Maya shaders
And choose a Material shader, choose the Dl3d_toonshader (in your version, the icon should be good :-) )
Your attribute editor displays the following :
The parameters are :
- Ka : coefficient for ambient color (multiplied by ambient color)
- Kd : coefficient for diffuse color (multiplied by diffuse color)
- Ks : coefficient for specular color (multiplied by specular color)
- roughness : coefficient to set the roughness of the surface for specular reflexions (the highest is the roughness the more centered is the specular reflexion)
- ambientcol : ambient color
- diffusecol : diffuse color
- specularcol : specular color
- fractalnoise : adds fractal noise on specular and diffuse color (more like a test for fun than a "must have" feature).
This toon shader discretize the coefficient linked to specular and diffuse reflexions. For that purpose, it uses 3 floating numbers in the range [0, 1]
- lim1 : lowest limit (all under lilm1 has a black color)
- lim2 : medium limit
- lim3 : highest limit
- mode : integer that can be 0, 1 or 2, it is used to filter the lights used for rendering. (0 = use all ights, 1 = use only lights specified in the following array, 2 = use all lights but those mentionned in the following array)
- Lights : array of lights if mode is set to 1 or 2.
Modify the background color in the menu "Toon"->Set camera background color -> Choose your camera (Persp in my case).
Now we must add the contour, come back to the shading group in the attribute editor (for example click on the object), then click on contour shader (1) and choose in the Miscellaneous mental ray® category the shader named Dl3dtoonshader_contour(2).

You now have the attribute editor displaying :
The parameters are :
- color : the color of the contour of 3D objects.
- width : width of the contour
- silhouette : if checked, we draw only the silhouette of the object (the contour lines that are interior to the object are not drawn)
Now go in the render settings in the mental ray® tab and get the contour section.
Click on enable Contour Rendering (1). Set the quality of the contour rendering (2), here it is at the maximum.
Disable all other options in (3)
Now let this window open and go in the hypershade.
In Create mental ray® nodes go in the Miscellaneous section and click on dl3d_contour_contrast_function (1).
then click on dl3d_contour_store (2)
Both shaders appear in the hypershade in (3)
The dl3d_contour_store shader has no parameters (while it is useful).
Click on dl3d_contour_contrast_function to see its parameters in the attribute editor :
This shader is used to set which pixels are going to bedrawn as contour using the color from the dl3dtoonshader_contour shader.
- deltaangle : is the angle in degrees between 2 faces, if this angle is higher than deltaangle we consider this pixel as part of the contour.
- zdelta : is the delta Z into the Z buffer to consider 2 pixels as part of the contour.
- density : floating number in the range [0,1], let you set the density of the contour drawing.
Now drag and drop with the middle mouse button the dl3d_contour_store from the hypershade to the Store shader (1) slot in the Render settings.
Same for the dl3d_contour_contrast_function from hypershade to Contrast Shader (2).
And that's all, you can now render your object.
Videos :
vidéo dl3d_toon_shader (AVI 2,3 Mo)
Image :
 |