2
$\begingroup$

I've been looking through the blender source code and noticed that nearly all cycles shaders are programmed in OSL.

enter image description here

However, the Wiki mentions the following:

It is also possible to create your own nodes using Open Shading Language (OSL). Note that these nodes will only work for CPU rendering; there is no support for running OSL code on the GPU. (source)

Does this imply that most of the Cycles shader nodes only support CPU rendering?

$\endgroup$
  • 2
    $\begingroup$ Nope, only OSL shaders are not gpu compatible. $\endgroup$ – brockmann Jan 29 at 9:48
  • $\begingroup$ @Robert Do you know / can you describe. at a lower level, how the connection is made from OSL to GPU executable in the OP's reference, and why the same connection can't be made for user-written OSL? I'm probably not even using the right language to ask this... 'pologies.... $\endgroup$ – Robin Betts Jan 29 at 10:15
  • $\begingroup$ @RobinBetts I will write an answer this evening, I'm currently in a thesis presentation at uni. $\endgroup$ – Robert Gützkow Jan 29 at 11:29
  • $\begingroup$ Yours? Hope the answer doesn't have to be a thesis, too :D $\endgroup$ – Robin Betts Jan 29 at 11:31
  • $\begingroup$ @RobinBetts No, not mine. My Master's thesis will hopefully be done before the next Blender Conference. $\endgroup$ – Robert Gützkow Jan 29 at 14:50
3
$\begingroup$

Cycles implements the shaders for both CPU and GPU through the shader virtual machine which can be found in /intern/cycles/kernel/svm. The same nodes are also separately implemented in the Open Shading Language (OSL) and can be found in /intern/cycles/kernel/shaders. For instance you will see that the brick texture node exists both as svm_brick.h and node_brick_texture.osl. OSL only runs on the CPU and integrating a OSO to SVM compiler was previously discussed but abandoned due to maintenance and performance concerns. Therefore your own OSL scripts have the same limitation and will only be executed on the CPU.

Note that using OSL is entirely optional and it's not enabled by default. OSL can be enabled in the Render Properties.

Render Properties

Additional information about Cycles can be found in the wiki. The articles may not always be fully polished, but they should be a good starting point to dig deeper into the code. The structure of Cycles source code is documented in the Source Code Layout page.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Excellent. Thanks. Wish I knew how to track this stuff down, myself... well, I do, now, a bit better. $\endgroup$ – Robin Betts Jan 29 at 17:52

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.