Page tree

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


In order to get C++ and OSL patterns to interact with each other, we need to tell the OSL patterns to not assume their inputs are constant and may be fed by a C++ Pattern output. If you want to allow connecting a non-OSL output to an OSL input, you must set the metadata flag [[ int lockgeom = 0 ]] for that input.

One of the advantages of using OSL is that large networks of Patterns are compiled together on the fly as they are used in the renderer. That means the compiler can take advantage of the current settings for the shaders and optimize away things that aren't used for any given object. However, the OSL compiler can't “see” into C++ based Pattern nodes, and so having them mixed in can defeat some of the optimization process. Additionally, OSL Patterns are grouped together and executed together, while C++ Patterns are executed one at a time. If a C++ Pattern is in the middle of a network, RenderMan may have to split the OSL Patterns into two groups – those that must execute before the C++ Pattern and those that must execute afterwards. Unfortunately, RenderMan currently cannot pass implicit derivatives between these two groups of nodes, and so if something like your texture filtering depends on derivatives of signals upstream, they may be distrupted by mixing in C++ nodes. For this reason, interleaving C++ nodes in the middle of networks is discouraged – though they can be downstream of all OSL nodes without detriment, and entirely upstream of all OSL nodes with little impact.


Refer to the OSL documentation for details on their usage.  You can read more about the current version of OSL by visiting OpenShadingLanguage.

Accessing Shading Contexts

It's possible to access RenderMan specific contexts that C++ shaders can see on the RixShadingContext via the getattribute call with "context" as the object. 

Code Block
string mymode = "unknown"; getattribute("context", "shadingMode", mymode);
if (mymode == "displacement") ...

The values for "shadingMode" correspond to the RixSCShadingMode in RixShading.h:

  • presence
  • opacity
  • scatter
  • volumeTransmission
  • volumeScatter
  • emission
  • bake
  • displacement

If you desire grid-like shading instead of ray hits, rather than use shadingMode, you can query a boolean context attribute which returns either 1 or 0 and includes:

  • eyePath
  • lightPath
  • primaryHit
  • missContext
  • reyesGrid