OSL Overview
OctaneRender® supports the creation of highly detailed textures using Open Shading Language. If you are interested in programming or if you are a programmer, you can produce almost endless variety of textures using OSL. Moreover, OSL is not limited to texture creation — there are also Camera and Projection options. It is worth spending time to learn OSL if you want to push beyond standard materials and texturing. For more information, see the section entitled Open Shading Language (OSL).
Assign OSL Textures to Materials
First create an Octane Diffuse material and open the Node Editor. Drag and drop the diffuse material you created into the Node Editor. Then select the desired OSL node from the OSL group on the left in the Node Editor and drag and drop it into the editor area. Connect this OSL node to the "diffuse" channel of the diffuse material.
Now, select the OSL texture node. Once you have selected the node, go to the "Code group" tab in the settings window on the right. This window allows for basic editing and partial creation operations. Otoy has provided some validated OSL scripts in "Script Category," with categorized scripts in the "Script Presets" section. You can also modify the script parameters in the Parameters turn-down under the Script group turn-down.
Creating and Editing OSL
To do this, first press the "Editor" button as shown in the picture below.
This will open the Octane OSL Editor. You will write, compile and complete, your code in this editor.
Saving and Categorizing your OSL Script
You can save the scripts you wrote in the Editor window or create a new category. To do so, press the "Save" button and a Windows explorer or Mac finder window will pop up. By default, the plugin will take you to the folder where you will save the script. However, the place where you will save the scripts is "C:\Program Files\MAXON\ Cinema 4D [version]\plugins\ C4Doctane\ res\ osl_scripts" folder. Here you can also open a new folder and save your script into it. This creates a new category, and you can see it in the OSL script window.
Things to be aware of when using OSL
OSL scripts assume a generic environment to operate within. Otoy has worked to provide parity with version 1.9.13 of the OSL specification. OSL scripts that operate outside of that specification may not work reliably. Keep that in mind.
OSL is a programming language. As a result, you can write code that can cause Octane to crash. It is your responsibility to ensure that you follow good coding practice and be familiar with what is allowed withing the context of OSL and Octane.
Supported features
Some features within the specification can be offered within Octane, while others cannot. Most texturing primitives (noise, image textures and arithmetic) will work as expected. The two main extensions that have been implemented in Octane are camera shaders and delayed evaluation of texture inputs.
Unsupported Features
- Material shaders and closure variables
- Pointcloud functions
- Dictionary lookup functions
- Message passing is generally not supported, except for the built-ins listed in under Octane Extensions, located in this link.
- Derivatives
- trace (). For AO like effects, you can add a color input and connect the input pin to a dirt node.
- struct variable types.
- The global variables Ps and dPdt
Partially supported features
- noise () doesn't support 4D noise and doesn't support the "simplex" and "gabor" noise types
- The global variable time always has a value between 0 and 1 and represents the time within a subframe.
- getmessage and gettextureinfo must have string literals as attribute names.
More information is available in the "Features and Limitations" topic from this link.
Compile Matters
You may need to press "compile" when a predefined preset script is selected or modified. Do this when a render is not properly reactive in the Live Viewer.
Using External OSL ScrIpts
While Otoy has provided numerous OSL scripts that have been validated to run within Octane, from time to time you will find some examples of OSL shaders that you want to try out. You can use these examples, but you may have to change some aspects of these shaders in order to conform to the OSL implementation in Octane.
For example, some of the code you see in the picture below is found on the web. When we try to use this code in the Octane OSL editor, we encounter an "Output" error because Octane OSL does not allow to use of multiple outputs at the moment. Only one output is available.
Another example is what you see in the picture below. Here, the use of "col.x" to read the first component of the "col" parameter fails. The correct use is shown on the right.