Thursday, April 26, 2012

[RenderMan] Ri Filters

The following is a snippet of code I wrote to test with Ri Filters. The goal is to simply replace any polygonal geometry with RiSphere, then replace any RiSphere with RiCone before the final RIB being passed to the renderer.

First filter plugin:
RifPlugin *RifPluginManufacture(int argc, char **argv)
{  
    return new myRifPlugin();
}
myRifPlugin::myRifPlugin()
{
    myRifFilter.PointsGeneralPolygonsV = pointsGeneralPolygons_to_RiSphere;
    myRifFilter.Filtering = RifFilter::k_Continue;
}
RifFilter &myRifPlugin::GetFilter()
{  
    return myRifFilter;
}
The second filter plugin is almost like the first one, except the registered callback needs to be changed to "myRifFilter.SphereV = riSphere_to_RiCone". With riSphere_to_RiCone defined as follow:
RtVoid myRifPlugin2::riSphere_to_RiCone(RtFloat radius, RtFloat zmin, 
      RtFloat zmax, RtFloat tmax, RtInt, RtToken[], RtPointer[])
{
    RiCone(0.5, 0.5, 360, RI_NULL);
}
Now it's about to render! If rendering with RMS (RenderMan Studio), it's better to check the Full Paths box in the Render Settings. Besides, set all the necessary Ri Filters (just new 2 Rif in this case ) and provide the paths toward 2 Plugins. Within command prompt,
render -r rman xxx.ma [ render the image with RMS]
render -r rib xxx.ma [export the rib after replacing]

If using RPS (RenderMan Pro Server),
prman -rif myRifPlugin -rif myRifPlugin2 xxx.rib [ render the image with PRMan]
catrib -o filtered.rib -rif myRifPlugin -rif myRifPlugin2 xxx.rib [export the rib after replacing]
Right, if using RPS, you need to generate rib first for filter processing. RMS accepts .ma for filtering but RPS only accepts .rib.

If everything runs correctly, all the polygonal geometries (lets say if we create 3 cubes in Maya) should be rendered as 3 cones in the final image. Cheers!!

No comments:

Post a Comment