Where did January go? I feel like it was only January 1st last week. It’s one of those rainy-snowy weeks in Toronto, which is kind of miserable if you ask me.
However this is a momentous week, as I did get to meet my blog mates Annick and Owen, you might be thinking “WHAT?!? You’re on a blog together…..” Autodesk is very global, and we are based out of different offices, and it’s not that we don’t regularly communicate, it just this is the first face to face meeting, so now I have a face for the name :)
I was digging in the crates (or rather my computer file folders), and I found some notes I made a while back on shader writing from a mental images training and I thought I would share them with you.
Writing Shaders:
This is an introduction to writing mental ray shaders; we want to try to follow these steps, to compile a shader that will run inside mental ray for Maya.
This will introduce writing a shader from scratch going through the principle ideas. The basic steps are written here, before you start you need to think about what the shader will do, what it will compute and return depending on your algorithm that you are going to implement, and which parameters it needs to control the algorithm. When you finish that you create the shader declaration that is the information that mental ray needs to know the inputs and output parameters, and some more options that tell mental ray about the type of the shader so that it can make some assumptions about the shader, and may optimize it. Then you have to write the shader writer code, you can take any language you want, the only interface to mental ray is a shared library that exports some known symbols, so that mental ray will be able to find your functions and call them. Once you are finished that, you can have a binary file in addition to the declaration file. This binary needs to be loaded into mental ray. That is the next step ‘Load into the Application’, once that is done, you can create nodes inside Maya connected and render.
A) Design the interface
- Determine type of shader
- Specific or general use?
- Determine type and count of result values
- Single or multiple output parameters?
- Determine type and count of input parameters
- Follow common scheme for compatibility?
- Provide reasonable defaults
- Provide UI hints when possible
B) Create Shader Declaration
- Write .mi declaration
- Set apply property
- Set version
- Set requirements with care !
- Set nodeid property for public shaders
- Load into mental ray
*prefer to do in mental ray for Maya because standalone will not catch the Maya errors.
**Open and load the .mi file you have just created into Maya using Windows > mental ray Shader Manager, if it loads fine you have no syntax or other errors, this is good
C) Writing Shader Code
- Write required code
-
- (optional) Use mkmishader tool for prototype to create C code from your .mi file, located in:
-
- C:\Program Files\Autodesk\Maya8.5\bin\mkmishader.exe
- This is validating the .mi shader declaration you just created.
-
- How to Run: C:\(etc.)\mkmishader my_shader.mi
- Help: C:\(etc.)\mkmishader –help
- Verbose Output: C:\(etc.)\mkmishader –v my_shader.mi
- Validate parameter range
- Avoid direct disk access
- Avoid system resource manipulations
D) Build Shader Binary
- Compile and link
- Use any available project and build settings
- Compile and link as shared / dynamic link library
- Windows requires linking shader.lib
- Build non-optimized for testing
- Build optimized for final version
- Load into mental ray
E) Load Into Application
- Register shaders and create Maya node types
- Put .mi and .so/.dll files into single directory
- Load the .mi file (!) with Shader Manager into Maya
- Validate automatic loading of the library
- Put final in any MI_CUSTOM_SHADER_PATH directory
- Write AE template MEL scripts
- Load into Maya using script editor
- Put final in any MAYA_SCRIPT_PATH directory
F) Render using the Shader
- Create a new node (instance) of the shader
- Connect in the shading graph
- Adjust input parameters
- Render the scene
- Tune shading using IMR
This is a general flow of how it works,
~Kristine
Resources: mental images.





Subscribe
This could be helpful:
http://www.wiki.render3d.de/doku.php?id=renderwiki:shaderwriting:shaderwriting
Posted by: haggi | 04/02/2010 at 02:57 PM
Thanks for sharing!
~Kristine
Posted by: Kristine Middlemiss | 04/02/2010 at 06:21 PM
Once you are finished that, you can have a binary file in addition to the declaration file.
Posted by: cell functions | 30/06/2010 at 07:18 AM
Once you are finished that, you can have a binary file in addition to the declaration file.
Posted by: Tadalafil | 03/07/2010 at 06:39 AM