Open Shading Language (OSL)

Open shading language (OSL) lets you use a new OSL Map, an entire category of various OSL maps, and you can create your own OSL maps using development tools for use with any renderer.

Open shading language (OSL) is an open source shading language that is fairly simple to understand. It can be used in several different ways. You can use the OSL Map, which is an execution environment for OSL shaders inside of 3ds Max, and it works like any regular built-in 3ds Max map. There is also a category of pre-loaded OSL maps that you can easily use. In addition, you can use any OSL maps you download from the internet. Finally, you can creating a shader or map in OSL using our development tools. This is a much simpler method to create custom maps than developing the equivalent functionality as a 3ds Max C++ map.

OSL works in any renderer supporting the regular 3ds Max shading API (Scanline, vRay, Corona, etc.). It also works outside of renderers, anywhere in 3ds Max where a regular map is requested, such as in the Displacement modifier. It also works with renderers that support OSL natively, such as Arnold. In those cases, the execution environment inside the OSL map is not sued, instead, the OSL source code, the parameter values and shader bindings are sent to the renderer, which executes the OSL code. More renderers supporting OSL natively are appearing daily.

OSL uses "just-in-time" compilation and optimization of entire shade trees at once, as long as all the shaders in the shade tree are OSL shaders. You can mix OSL shaders and regular shaders, but the optimizations will suffer.

Note: Computer graphics terminology is not always precise, and words like shader, map, texture, procedural and material mean different things when used in different contexts, applications, and renderers. Since OSL in 3ds Max does not support closures, it appears as maps. However, since OSL is a shading language, the term shaders and maps will be used synonymously in the context of OSL.
Note: The original rendering API did not support multiple outputs. This is an extension that was introduced later. For this reason, most materials and maps do not understand connecting to a map with multiple outputs. To solve this, the Output Selector map was introduced as a go-between that is automatically inserted between something that has multiple outputs, and something that does not understand multiple outputs. The Output Selector map is automatically hidden in the Slate Material Editor, where it looks like a normal connection (except the wire is blue instead of red). The option can be turned on or off by choosing Preferences from the Options menu in the Slate Material Editor, and toggling Hide Single Map Output Selectors.

OSL limitations

The OSL map has a few limitations in 3ds Max.

Limitation Description
Only supports maps, not materials

A shader written in OSL can have multiple outputs returning different data types like colors, floating point values, integers, strings, and so on. This is all supported.

However, OSL also supports a special type known as a closure. You can think of closures as being materials. This is not supported. In practice, this means, the OSL map can only be used to build procedural textures (maps), and not to build materials.

Therefore, the recommended workflow is to build your procedural texture maps in OSL, but connect the outputs to a standardized, well-defined, renderer-independent material such as the Physical Material.

If an OSL shader you find online doesn't appear to do anything, or doesn't appear to have any outputs, it might be an OSL material.

Only supports plain data types

The OSL Map in 3ds Max only support the plain data types: colors, vectors, floats, integers, and strings. It does not support arrays or structs as inputs.

This is rarely a problem in practice, because very few OSL shaders actually use arrays or structs as inputs. The limitation only applies to parameters, arrays and structs still work fine inside the OSL code.

Viewport Support

Many OSL maps now use their actual shader for viewport display, resulting in better performance and vastly improving their visual representation. To do this, run the viewport in "Realistic Mode with Maps." OSL maps that use the shader will show the notification Viewport: shader used above their parameters in the Material Editor. OSL maps that still use baking however will show Viewport: baked texture used.

Note that the following OSL shaders currently still use baked textures:

UVW

Root

Scene

Values

Note: This viewport improvement is also not supported by the Arnold material which always uses baked textures.