String handling in OSL shaders

Supported operations on string values

Octane considers strings to be opaque values, and supports only a limited set of operations:

  • assignment (string b = a;)
  • check for equality (a == b, a != b)
  • using strings as arguments in functions and shaders

None of the standard string functions defined by OSL are supported.

Types of string variables

Octane roughly distinguishes between 3 types of string variables:

  • file names: These are strings which are passed into image sampling functions, like texture().
  • enum values: These are strings which are passed into functions which take a well-defined set of possible values, like raytype() or noise().
  • other strings: Strings which are not used for either of the above, or which are used for multiple types of enums.

The octane OSL compiler will use static code analysis to determine how each string variable is used. If a variable is used as both an enum value and file name a compiler error is raised.

Using strings as shader inputs

Octane will represent the three types above with different widgets:

  • A file name is always shown as a file input, and any metadata is ignored.
  • Enum values will by default be represented by an Enum input pin.
  • Other string values will by default be represented by an Enum input pin.

String literals in texture() calls

If the argument of a texture call is a constant string, the compiler will generate a file name input and use the literal value as the default value. This allows loading OSL code which contains file names, and ensures any referenced files will be packed when a scene is exported to ORBX.


Last update: April 12, 2021