Open Shading Language is a text-based system for writing custom shaders in Blender

Open Shading Language (OSL) is a programming language that lets you write instructions for how surfaces look and behave in Blender's Cycles render engine. Instead of clicking buttons to combine pre-built shader nodes, you write code that describes material properties — how light bounces off a surface, what color it is, how rough or shiny it appears. Blender reads your code and applies it when rendering an image.

OSL was created by Sony Pictures Imageworks and is used in professional visual effects studios. Blender integrated it as an alternative to its node-based shader system. You do not have to use OSL; most Blender users build materials by connecting shader nodes in the Shader Editor. But if you want precise control, the ability to reuse code, or the speed of writing instead of clicking, OSL gives you that option.

The language is designed specifically for shaders — the programs that define how surfaces render. It is not a general-purpose language like Python. OSL code runs only during rendering, not in Blender's viewport or interface.

Key Takeaways

  • OSL is a text-based alternative to Blender's node-based shader system, letting you write code instead of connecting visual blocks.
  • You write OSL code in a text editor, save it as a .osl file, and Blender compiles and applies it during rendering with Cycles.
  • OSL is useful when you need to reuse the same shader logic across many materials, create complex math-based effects, or work faster than the node interface allows.
  • OSL code runs only during final render, not in the viewport, so you cannot see results until you render or switch to rendered viewport shading.
  • Learning OSL requires basic programming knowledge — variables, functions, loops — but the language is smaller and simpler than general-purpose languages.

How OSL code connects to Blender's render engine

When you enable Cycles as your render engine and turn on OSL support in Blender's render settings, you can add an OSL Script node to your shader network. This node points to a .osl file on your computer — a plain text file containing shader code. Blender reads that file, compiles it into machine instructions, and runs it for every pixel in your render.

The OSL code receives input data about each point on the surface: its position in 3D space, the direction light is coming from, the surface normal (which way it faces), and any custom data you pass in. Your code calculates an output — usually a color or a number — and sends it to the next shader node or directly to the render output.

Because OSL runs during rendering, not in real time, you do not see results in Blender's viewport while you work. You must either render a frame or switch to rendered viewport shading (which is slower) to see what your shader does. This is different from the node-based system, where changes appear when ready.

When to use OSL instead of shader nodes

Shader nodes are visual, intuitive, and fast for most work. You should consider OSL when nodes become cumbersome or when you need to repeat the same logic many times. If you are building a procedural wood texture with dozens of nodes, you might write a single OSL function instead. If you are creating a custom effect that requires loops or conditional logic (if this, then that), nodes force you to duplicate sections of the network, while OSL lets you write it once.

OSL is also faster to write if you are comfortable coding. Typing a few lines of math is quicker than clicking and dragging nodes across the screen. Professional studios use OSL because it is version-controllable — you can save shader code in a text file, track changes, and share it with other artists. A .blend file with nodes is harder to diff and merge.

OSL is not the right choice if you need to see results in real time or if you are not comfortable reading and writing code. Blender's EEVEE render engine does not support OSL, only Cycles does. If you work primarily in EEVEE, you are limited to nodes.

Basic structure of an OSL shader

An OSL shader file starts with a shader declaration that names the shader and lists its inputs and outputs. Here is a minimal example:

shader simple_color(color input_color = color(1, 0, 0), output result = 0) { result = input_color; }

This shader takes one input (a color, defaulting to red) and one output (the result). The code inside the curly braces assigns the input to the output. When you add this shader to Blender, the OSL Script node will show two sockets: one for input_color and one for result.

A more realistic shader might calculate a value based on the surface position or explore a mathematical function. OSL provides built-in variables like P (position), N (surface normal), and I (incoming light direction). You can use these to create effects that respond to the geometry or lighting of your scene.

How to use an OSL shader in Blender

First, write your OSL code in any text editor and save it with a .osl extension. Then open Blender, select the object you want to explore the shader to, and go to the Shader Editor. Make sure Cycles is your active render engine and OSL is enabled in the render settings under Shader Compilation.

Add an OSL Script node to your shader network (Shift+A, then Script, then OSL Script). Click the folder icon next to the node and browse to your .osl file. Blender will compile the code and display input and output sockets based on what you declared in the shader. Connect the output to a Principled BSDF or another shader, then render to see the result.

If you edit the .osl file in your text editor, Blender will recompile it the next time you render or switch viewport shading modes. You do not have to reload the file manually.

Learning OSL: what you need to know first

OSL syntax is similar to C and C++, so if you have written code in those languages, you will recognize the structure. If you have not coded before, expect a learning curve. You need to understand variables (containers that hold numbers or colors), functions (reusable blocks of code), and basic math operations.

The Blender manual includes an OSL documentation page with examples and a reference of built-in functions. The Blender Developers website hosts the full OSL specification. Many tutorials on YouTube walk through straightforward shaders step by step. Start with a basic procedural texture — something that generates a pattern based on position — before moving to more complex effects.

The OSL community is smaller than the node-based community, so you may find fewer tutorials or examples for specific effects. However, the language itself is stable and well-documented. If you are already comfortable with Blender's nodes and want to deepen your technical skills, OSL is a natural next step.

OSL performance and limitations

OSL code is compiled before rendering, so there is a small compilation cost the first time you render. After that, performance depends on how complex your shader is. A straightforward OSL shader can be as fast as an equivalent node setup. A shader with many loops or expensive calculations will slow down your render.

OSL does not work in EEVEE, Blender's real-time render engine. It works only in Cycles. If you export your Blender file to another process, OSL shaders will not transfer — you will need to rebuild them in that process's shader system or convert them to nodes first.

OSL also cannot access Blender's modifiers, geometry nodes, or animation data directly. You can pass values into your shader through the OSL Script node's inputs, but the shader itself cannot read or change the mesh. This keeps shaders isolated and predictable.

Frequently Asked Questions

Do I need to know programming to use OSL?

Yes, you need to be comfortable reading and writing code. If you have never written code before, start with Blender's node-based system first. Once you understand how shaders work conceptually, learning OSL syntax becomes easier. Many online tutorials assume you know basic programming concepts like variables and functions.

Can I see OSL shader results in the viewport?

Not in real time. OSL shaders only render in Cycles. You can switch to rendered viewport shading to see results faster than a full render, but it will be slower than the default viewport. To iterate quickly, render small test images or use a low sample count.

What is the difference between OSL and Blender's built-in shader nodes?

Nodes are visual and when ready to preview. OSL is text-based and requires compilation, but lets you write loops, conditionals, and reusable functions. Nodes are better for quick work; OSL is better for complex, repeatable logic or when you want version control.

Can I convert my node shaders to OSL?

Not automatically. You would need to rewrite the logic in OSL code. For straightforward shaders, this is straightforward. For complex node trees, it may be faster to keep using nodes. There is no built-in converter in Blender.

Will OSL shaders work if I send my .blend file to someone else?

Only if you also send the .osl files and the person has them in the correct folder path. The .blend file stores a reference to the file location, not the code itself. To share safely, include the .osl files and document where they should be placed.