question

Andrey Babak avatar image
Andrey Babak asked ·

How to setup OSL shader?

Can you show how to use OSL shaders in KtoA? Either I am doing something wrong or there's a bug that prevents using OSL on Windows. The log shows that KtoA can't find the shader in search path and can't find include file "stdosl.h" (the reason for that is that it loses a leading slash in its path).

Thank you.

shadersarnold5
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

1 Answer

· Write an Answer
Mike Farnsworth avatar image
Mike Farnsworth answered ·

On Linux at least, you have to set the environment variable ARNOLD_PLUGIN_PATH to include the directory containing OSL code (any combination of .osl or already-compiled .oso files). Arnold will attempt to auto-compile .osl files for you. If it can't find it's own stdosl.h, then that is indeed a bug.

A workaround is to compile your own .oso files. Using oslc (in the same directory as kick) you should be able to manually compile your .osl files to .oso and tell it where to find stdosl.h, along with any other headers you need for your OSL code. Place your .oso files in another directory, and set ARNOLD_PLUGIN_PATH to point to that directory, and they should load.

One final hint: Arnold will refuse to use any OSL shaders that don't have an output parameter. For example, this shader will be rejected:

surface
metal
    [[ string help = "Shiny metallic material" ]]
(
    float Ks = 1
        [[  string help = "Specular scaling",
            float min = 0, float max = 1 ]],
    float eta = 10
        [[  string help = "Index of refraction (controls fresnel effect)",
            float min = 1, float max = 100 ]],
    color Cs = 1
        [[  string help = "Base color",
            float min = 0, float max = 1 ]]
  )
{
    Ci = Ks * Cs * reflection (N, eta);
}

But this will be accepted:

surface
metal
    [[ string help = "Shiny metallic material" ]]
(
    float Ks = 1
        [[  string help = "Specular scaling",
            float min = 0, float max = 1 ]],
    float eta = 10
        [[  string help = "Index of refraction (controls fresnel effect)",
            float min = 1, float max = 100 ]],
    color Cs = 1
        [[  string help = "Base color",
            float min = 0, float max = 1 ]],
    // NOTE the explicit output parameter!
    output closure color Cout = 0
  )
{
    Cout = Ks * Cs * reflection (N, eta);
}
4 comments Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Hi Mike,

Thank you for posting this information!

May I ask you to show the complete setup in Katana? I am not sure what result should I get. Currently, I've copied the latter script into "metal.osl" and added the folder to ARNOLD_PLUGIN_PATH. I tried adding the full path to "osl" node's "code" attribute. Finally, I was able to compile "metal.oso" and tried with its path. Should I get some controls in Katana?

Thank you.

Cheers,
Andrey

0 Likes 0 · ·

So, if you're trying to use the osl_shader node, it won't work (it's not yet supported, in that KtoA won't create the UI once you paste your code in there). All you should need to do is have the .oso file in ARNOLD_PLUGIN_PATH, and the metal shader should automatically show up in the list of available shaders.

I am going to try to reproduce the .osl compilation failure, and if I can get that fixed I plan on releasing a bugfix version of KtoA that should make this easier. I will also put up a tutorial on support.solidangle.com in the KtoA area showing how it's done.

1 Like 1 · ·

Hello @Mike Farnsworth,

Sorry, forgot to mention your username in my previous post to issue a notification.

Andrey

0 Likes 0 · ·

Ah, I see. I was expecting the UI to show up right inside the osl node. Thank you.

0 Likes 0 · ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.