Is it possible to include one OSL file in another so I can use the functions from it or must I copy and paste everything every time I want to reuse it?

OSL seems to have #include functionality, but is there a way to use it for script files within Blender?

(I'm using internal script files, but I can change if that helps.)


After some experimentation, it appears that #include-ing OSL files works with external scripts, but not internal.

The OSL compiler takes a shader file as input, and seems to use the directory of that file as a base for further includes. It also looks in the \scripts\addons\cycles\shader directory.

If external scripts are used, the OSL compiler therefore looks in the correct directory, and will find included files correctly.

If internal scripts are used, the script being compiled is moved by itself to a temporary directory, given a random name, and deleted afterwards. This means that internal scripts cannot use #includes unless the included files are placed in the \scripts\addons\cycles\shader directory.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.