Software:
Blender 2.82 | Cycles
The Cycles render engine in Blender has a very convenient OSL Shader development and usage workflow.
Shaders can be both loaded from external files or written and compiled directly inside Blender.
Before you begin:
Make sure your Blender scene is set to use the Cycles render engine, in CPU rendering mode, and also check the option Open Shading Language:
To write an OSL shader in Blender:
- Write your shader code in Blender‘s Text Editor:
- In your object’s material shader graph (Shader Editor view),
Create a Script node:
- Set the Script node‘s mode to Internal,
And select your shader’s text from the Script node‘s source drop-down:
- If the shader compiles successfully, the Script node will display its input and output parameters, and you can connect it’s output to an appropriate input in your shading graph.
* If your shader is a material (color closure) connect it directly to the Material Output node’s Surface input, is it’s a volume to the Volume input, or if its a texture to other material inputs as needed.
- If the shader code contains errors, it will fail to compile, and you’l be able to read the error messages in Blender‘s System Console window:
- After fixing errors or updating the shader’s code, press the Script Noe Update button on the Script node to re-compile the shader:
Loading an external OSL shader into Cycles:
Exactly the same workflow described in the previous section, except setting the Script node‘s mode to External and either typing a path to the shader file in the Script node or pressing the little folder button to locate it using the file browser:
Related:
I can’t seem to get this hack to work even after doing the copypasta, my object is black.
What hack are you referring to?
does not work on GPU Blender Cycles
True.
I wrote this in the beginning of the post:
Before you begin:
Make sure your Blender scene is set to use the Cycles render engine, in CPU rendering mode, and also check the option Open Shading Language
My object turns to black after following the steps. I’m using cycles. Not sure how to fix this
Hi R,
Are you sure your rendering in CPU mode?
OSL shaders aren’t supported in GPU mode..