Script Node

The Cycles render engine supports the Open Scripting Language (OSL) and you can develop your own shader scripts, or download public-domain scripts from the net. To use them requires the Script node.

Learning how to write shaders in OSL is beyond the scope of this manual, but you can find many references on the net by searching for 'Open Scripting Language' in Google.

Node Interface

The node is very simple and there is nothing to edit in the node itself. If you select the node and look in the right-hand pane of the node editor, you see this:

Click the small button to load an OSL script. These have the extension .OSL. You may also see files with an .OSO extension - these are precompiled versions of the script. Do not try to load these directly into the node, they will not work.

Points to note

There are three important points to note when using OSL shaders in Cycles:

  • the rendering device must be the CPU, OSL shaders are not yet supported by the GPU;
  • you must enable the 'Open Shading Language' switch in the render settings;
  • and unfortunately you cannot use an OSL script over Team Render. This is because Cinema 4D refuses to recognise anything other than a small set of image file formats as assets, so you cannot use an OSL script as an asset. This is not a bug in Cycles 4D, it is a limitation in Team Render itself.

If you don't meet both these points, the shader will not work and the result is plain black.

Note that the preview of the material will not show the result of the script. You will probably see a plain grey or black material preview in most cases, but the script will still work correctly when rendered (including in the real-time preview).

Sample script

The Blender reference manual shows a very simple script which simply generates a pale green colour. If you load this script into a script node, you see this:

As you see, it now looks exactly like an inbuilt node. The script name ('simple_material') can be seen in the title bar. The node has two inputs, one for a colour and one for a numeric value, and it outputs a BSDF result, which you can link directly to the Surface input port of an Output node, for example.

In the right-hand pane of the node editor you would see this, like any other node:

Objects given this material would now render pale green (with the Noise_Factor set to zero):

Example scripts

We have prepared a set of example scripts from various sources which you can download from this link. Please be sure to read the readme.txt file in this archive; in particular, the section on licensing as not all may be used for commercial purposes.

Using scripts from other sources

There are many OSL scripts available on the web and they are worth trying out, but you should be aware of some potential problems which may cause the script to fail. You will know if it has failed if the script seems to load but the script node does not show the expected user interface (i.e. the input and/or output ports). If this happens, the node has failed to compile correctly and you will need to look at the source code to see why. Alternatively, The script may compile correctly but fail to produce any output (e.g. a black render).

These are some of the reasons a script may fail to compile or output a result if it does:

  1. Some OSL scripts use functions which are proprietary to the render engine they are intended for - those written for Vray seem to use a lot of add-on functions presumably added by the creators of Vray, and of course they won't run on Cycles at all.
  2. Some OSL functions are implementation-dependent and the Cycles engine won't necessarily have implemented all of those, so they won't run in this version.
  3. Some use external files (e.g. bitmaps) which may be missing from the script download so you will need to source these elsewhere.
  4. Some just don't compile successfully even when it looks as if they should, and you will need to inspect the script carefully to discover why that is.
  5. Even when the script loads and compiles successfully, some scripts need a fairly complex node tree to use them, they aren't all just 'out-of-the-box and plug it in to the output node' by any means.

However, if you can get them working they can offer some really interesting and useful shaders, so it's worth persevering if you find one you like.