Each shader definition can have one or more renderer definitions associated with it, storing vital information, such as:
Add a renderer definition to the shader definition using the ShaderDef.AddRendererDef or ShaderDef::AddRendererDef method, where you specify the name of your renderer, and which returns the new definition as a MetaShaderRendererDef or MetaShaderRendererDef object. The MetaShaderRendererDef object allows you to specify the following:
MetaShaderRendererDef Access |
Matching SPDL declaration (Renderer section) |
Description |
---|---|---|
MetaShaderRendererDef.SymbolName or MetaShaderRendererDef::PutSymbolName |
Name |
Indicates the symbol name of the shader code to use. For example with mental ray shaders this would indicate the prefix for the symbol (callback) name in the DLL/DSO where the code for the shader is. |
MetaShaderRendererDef.CodePath or MetaShaderRendererDef::PutCodePath |
FileName |
The name of the DLL/DSO that contains the shader code. For example "{LIBS}/sibase.{EXT}". |
MetaShaderRendererDef.CodeText or MetaShaderRendererDef::PutCodeText |
BeginText...EndText |
Provides a placeholder for any arbitrary text that can then be interpreted or compiled into a shader by the rendering engine, including the implementation of a shader. For example: { float4 retcolor; retcolor.x = factor.x * (input.x + input.y + input.z) / 3.0; retcolor.y = retcolor.x; retcolor.z = retcolor.x; retcolor.w = retcolor.x; return retcolor; } |
MetaShaderRendererDef.RendererOptions or MetaShaderRendererDef::GetRendererOptions |
Options |
# You need to set up at least one renderer definition for each shader definition. # Renderer definitions are available via the ShaderDef.RendererDefs property and # allow you to tell Softimage which renderer to use, which procedure to call, how # to set any renderer options, etc. oRendererDef = oShaderDef.AddRendererDef("mental ray") oRendererDef.SymbolName = "XSIModelMap" oRendererDef.CodePath = "{LIBS}/xsibase.{EXT}" # Set the version option oRendererOpts = oRendererDef.RendererOptions oRendererOpts.Set("version", 1)
Renderer options comprise a list of string/value pairs that are passed to the renderer. The option name can be any string. The value can be boolean, integer, float or string. Depending on the renderer, the Options list is used in different ways:
For mental ray, the Options list stores the rendering restrictions for this particular shader, such as whether shadows are on or off. See mental ray Options for details.
For realtime renderers, the Options section can be used to store parameter pairs.
For other renderers, the Options section could provide a path for the location of the source code of the shader. For example, this is useful for the RenderMan shader library where the all the code for a large shader library could be provided as one big SL file. For mental ray, you could also provide a source code which would then be compiled at render time.
# Add a mental ray renderer definition with the location of the library where it is defined oRendererDef = oShaderDef.AddRendererDef("mental ray") oRendererDef.SymbolName = "material-phong" oRendererDef.CodePath = "{LIBS}/sibase.{EXT}" oRendOpts = oRendererDef.RendererOptions oRendOpts.Set("version", 1) oRendOpts.Set("pass channel", "Ambient,Diffuse,Specular,Irradiance,Reflection,Refraction") # Add a Cg version with the code embedded in the definition oRendererDef = oShaderDef.AddRendererDef("Cg") oRendererDef.SymbolName = "mib_color_average_cg" oRendererDef.CodeText = "\tBeginText\n\t{\n\t\t float4 retcolor;\n\n\t\t retcolor.x = factor.x * (input.x + input.y + input.z) / 3.0;\n\t\t retcolor.y = retcolor.x;\n\t\t retcolor.z = retcolor.x;\n\t\t retcolor.w = retcolor.x;\n\n\t\t return retcolor;\n\t}\n\tEndText" oRendOpts = oRendererDef.RendererOptions oRendOpts.Set("param0", "ambient") oRendOpts.Set("param1", "diffuse") oRendOpts.Set("param2", "specular") oRendOpts.Set("param3", "ambience") oRendOpts.Set("param4", "shiny") oRendOpts.Set("const0", "diffuse_inuse") oRendOpts.Set("const1", "specular_inuse") oRendOpts.Set("param7", "radiance")
Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License