RfM
|
IntroductionAlthough RfM19 introduced the possibility of creating custom RIS pattern nodes using the Open Shading Language (OSL) it did not provide a fully functional PxrOSL node. The PxrOSL node can reference an OSL shader but it does not have the functionality to dynamically add UI parameter widgets that "connect" to a shaders inputs. For example, figure 1 shows the attribute editor for a PxrOSL node that references a shader named colorByObjOrigin.oso. Note there are no UI widgets.
Figure 2 shows what a UI-savvy PxrOSL node will look like when version 21
of RfM is released. In the meantime the work-around introduced in this tutorial and a more complicated
approach explained in the tutorial "RfM: OSL RIB Box + TCL Hack" will allow the reader to
explore the use of OSL with Maya.
|
WorkflowThe code for a very simple OSL shader is given in listing 1. Listing 1 (RedLeft.osl)
Step 1 - Compile the ShaderUse Cutter to compile the shader. When Cutter uses the "oslc" shader compiler to create the RedLeft.oso file it's location will be reported in the Process Monitor window.
Step 2 - Test the Shader & Develop a Shading NetworkRight mouse click on the .osl document and generate a beauty pass Rib file that can be used to test the shader - for example figure 4.
Save the Rib file and render the scene.
Of course any of the RedLeft's parametes, such as "cutoff" can receive an input from an existing node such as PxrFractal and as a consequence somewhat more interesting shading results can be achieved - figure 6. Pattern "PxrFractal" "PxrFractal1" "int layers" [6] "float frequency" [4.0] Pattern "PxrOSL" "RedLeft1" "string shader" "RedLeft" "color patcolor" [1 0 0] "color bakcolor" [1 1 1] "reference float cutoff" ["PxrFractal1:resultF"] Bxdf "PxrDisney" "PxrDisney1" "reference color baseColor" ["RedLeft1:resultRGB"]
|
Step 3 - Create a Duplicate of the Shader for Use with Maya
When using a OSL shader with Maya it is convenient to have the shader located
in Maya's project directory. Rather than changing the pref that controls where
the OSLC compiler saves a shader a duplicate of the shader can be automatically created
by Cutter.
Compile the shader again but notice the Process Monitor will report where a duplicate of the shader has been placed - figure 8.
|
Step 4 - Prepare a Rib Archive for Use with MayaCopy and paste the code of the shading network into an archive rib file. Save the file in the Maya project directory that will use the OSL shader. For example, the following rib was saved as RedLeftNetwork.rib. Listing 2 (RedLeftNetwork.rib)
|
Step 5 - Prepare a Rib Box in Maya for Use with MayaMake sure that both the RedLeft.oso shader and the RedLeftNetwork.rib have been saved in the Maya project directory. Assign any material (Reyes or RIS) to the geometry that will be shaded with the OSL shader. In the materials shading group node go to the menu Attributes->RenderMan and add a RIB Box.
Enter the following text to the RIB Box.
Finally, render the scene. |
© 2002- Malcolm Kesson. All rights reserved.