OSL Texture

 

The OSL Texture node is a scriptable node where users may write scripts using the OSL (Open Shader Language) standard programming language to define arbitrary texture types to create highly customized OctaneRender materials and shaders. OSL is a standard created by Sony Imageworks. To learn about the generic OSL standard, information is provided from the OSL Readme and PDF documentation.

Figure 1: Select the OSL Texture node from the pop-up context menu of the Node Graph Editor pane

 

An OSL script is written into the OSL Texture node via the script editor window. Click on the pencil icon to go to the script editor window. If the script exists as an external .osl file, insert the .osl file into the node through the load icon. Any existing file used within an OSL Texture node may be edited. To refresh file with the edits, reload the file via the reload icon.

The OSL Texture is only for textures and requires one output color. One OSL Texture node is one OSL compilation unit which contains only one shader, thus, it has only one output attribute pin that connects to the texture input pin of other Octane Texture nodes (e.g. Turbulence texture node) or to the texture input pin of Octane materials (e.g. DiffuseAmount of diffusion, or the reflection of light photons at different angles from an uneven or granular surface. Used for dull, non-reflecting materials or mesh emitters. MaterialThe representation of the surface or volume properties of an object. node).

 

Note: Multiple outputs for OSL Texture is not yet supported at this stage.

 

As of version 3.08.x, OctaneRender supports most of the texturing functions (eg. textures or noises) in the OSL Specification.

 

When an OSL Texture node is invoked, it is provided with an initial script with a declaration component that bares one output variable which represents a color. The initial script’s function body then initializes the color to black based on the standard RGB color mode. Customize the script to create a customized OSL Texture shader. A custom script may have many variables, some of which may require user input via input nodes. So depending on the custom script, the OSL Texture may have an input of 0, or many input nodes.

 

Figure 2: An OSL Texture node’s initial script containing an OSL program code to calculate the output color

 

Figure 3: Click on the Compile button to compile the script. Compilation messages will display below the script window

 

The example in Figure 4 below shows an OSL shader that adds two RGB textures.

Shader Add (
color a = 0,
color b = 0,
output color c = 0)
{
c = a + b;
}

The script’s declaration component has three variables, two are input variables of Input Type color and the third one is the required output represented by a variable of Output Type color. The OSL Input/Output Typecolor“ corresponds to an Octane Texture Attribute node. The script’s function body adds the two input parameters and places the result into the output variable.

 

For a list of OSL variable declaration Input/Output types in the OSL Specification that OctaneRender supports, refer to the Appendix topic on OSL Implementation in Octane. To learn more about scripting within OctaneRender using the Open Shader Language, refer to The Octane OSL Guide.

 

Figure 4: An example of an OSL Texture node with an OSL script to logically add two input texture nodes and send the result to one output

 

Once the OSL Texture is available, it is plugged into the texture input pin of an OctaneRender material node. And similar to other procedural texture types, its own initial attributes can be replaced with other applicable texture types in the course of the texturing process. For example, the OctaneRender texture attribute in the example provided in Figure 3 is initially an RGB Color texture, however this may be changed to any applicable OctaneRender texture via its representation on the inspector node to further customize the OSL shader (Figure 5).

Figure 5: Changing the input node to customize the OSL Shader

 

To learn more about coding in OSL, refer to the OSL Implementation In Octane topic in the Appendix.

 

Note: When using OSL, you should ensure shaders never lock up or run for exceedingly long times. This may cause the system to freeze, or to reset the display driver. Also, some operations, like out-of-bounds array access, may cause kernel crashes.