Wednesday, 19 January 2011
Tuesday, 18 January 2011
Only a few month ago I wrote my first script. 6 lines of Python script, that prepared an object for the horrible Shatter effect in Maya. Since then I learnt quite a bit more and I'm currently writing a mel plugin, that "erodes" or "crumbles" nParticles based on locator positions. I've figured out the math behind the expressions for those effects and I'm writing the interface. It's already a good 10 pages full of script and I'm not even half way there.
Meanwhile I could use my new scripting "skills" to write a little shading network for Craig. His project is in 3D but the look is supposed to be 2D. Mayas Toon Shader would be brilliant, but the problem is that it is kind of hard to use textures. Mayas Toon Shader is basically a ramp shader with multiple color inputs controlling the highlight/shadow, based on the brightness of the object. So I used the ramp shader as well. I used one texture that's connected to multiple color inputs of the ramp shader. The main texture is connected straight to the first color input. The shadow textures on the other hand, are the same texture but with a multiply/divide utility node inbetween. Custom made attributes on the shading node control the darkness of the shadow, cause they control the multiply node. Simple math: if you multiply an image by anything smaller than 1, the image get darker.
The script is on creative crash for free download: http://www.creativecrash.com/maya/downloads/shaders/c/ps_toonshader
And that's how it works:
First a window pops up. The Browse button will let you load a texture. The Shader and Texture Name is editable (the default is the name of the object + Shader and Texture. That would be fine, unless the name is not unique, but the script warns you for that anyway). The checkbox lets you decided whether you want to use 1 or two shadows (2 is default).
The Toon Shader button runs the action!
The ramp shader has all kinds of options to play around with (specularity, reflection, incandescence etc.) You can also play around with the position and the interpolation mode of the shadows, to get a new look. Two custom made attributes, called shadow 1 and 2, are added to the attribute editor of the ramp shader. Both control the darkness of the shadows.
Two test renders:
First: two shadows (unfortunately the shadows are quite dark, but believe me the texture under the shadows is the same as on the highlights)
Second: One shadow. The interpolation of the shadow is set to none.