Anyone here who can use OSL?

Hey everyone,

I need a really specific OSL Texture for the Procedural Planet I am making in Octane, but I didn´t find good resources to learn OSL on my own.

Do you have a tips where and how to start learning OSL because it seems there are not a lot of comprehensive and easy to understand videos or articles out there. Or maybe its just cause I am not good at coding. Anyways I would love to have good introduction to OSL somewhere.
Or maybe someone is so Corona-Quarantine-bored he/she wants to quickly type it out for me?

1 Like

Michel Anders has a variety of osl textures on his blog:

I can also recommend his book Open Shading Language for Blender.

Sample pages: https://michelanders.nl/wp-content/uploads/2017/05/Open-Shading-Language-for-Blender-Michel-Anders-sample.pdf

Book available here:

or on Blendermarket:

If you search github there are a number of repositories for osl shaders.

One of the ones in this collection is a planet surface:

1 Like

Check out Zap Andersson. He’s one of THE OSL gurus. He’s head of Max’s rendering team. This is a 7 video OSL course. It’s for Max, but doesn’t matter.

2 Likes

Is the book “Open Shading Language for Blender” still available? The sample chapter seems not to be around any more, so I fear that if I buy the book I will just get another dead link.

I have been fighting with OSL in Blender the past weeks and get absolutely nowhere. Cycles, CPU render, OSL active, enter simple compiling OSL code, gets black surface out whatever I do. Will the book help me? Do I really need an entire book to get a super simple shader to work?

The link to the sample chapter works for me. The book itself is on blendermarket, which has been one of the main sources for blender addons and resources for many years, I don’t think you have to worry about a dead link there.

You don’t need a book, there are many resources on the internet, but it is a good general introduction if the expense is small for you.

I just downloaded firstshader.osl from the github repository for the book’s sample code and it compiles for me.

If you post a script that isn’t working for you perhaps we can help.

Thanks! If the book ius safe I will buy it. I just got worried by the dead links. One link went to a poker site, another gave an empty window.

I am trying the simplest possible shaders I can figure out:

shader test(color cin = color(1.0, 0.0, 0.0),
output color cout = color(1.0, 0.0, 0.0)
)
{
cout = cin;
}

I attach a color input in the shading view, and pass it through a Diffuse BSDF stage. Black.

I think this was the exanple from the Blender documentation:

shader simple_material(
color Diffuse_Color = color(0.4, 0.8, 0.4),
float Noise_Factor = 0.5,
output closure color BSDF = diffuse(N))
{
color material_color = Diffuse_Color * mix(1.0, noise(P * 10.0), Noise_Factor);
BSDF = material_color * diffuse(N);
}

Again, just black. If I build the shader sequence without any OSL, then it works fine.

Here I got another worry: It originally had a default output of 0.6 0.8 0.6, which was confirmed in the shading view. However, when I edited it to 0.4 0.8 0.4, and hit the double arrow update button, the values did not change!

“Render properties” are set to Cycles/Supported/CPU and with OSL checked. The shaders compile successfully.

Follow-up question: Did I miss something in the setup? The ones I mentioned are the ones I have found while searching, use Cycles, use CPU, activate OSL. Is there something more? Some trick/command to make Blender re-render after editing?

the first shader is working for me. do you have a light or world background in your scene?

I am completely lost. We are doing the same thing, except that I have the default skybox (because I want to change as little as possible beyong the shader). My rendering is either black or is rendered as if my shader wasn’t there. No messages in the console more than “Info: OSL shader compilation succeeded”.

One thing looks odd with your result: The default input is red but the output is magenta. Isn’t the color RGB?

I am primarily using a Mac but I have tried this on Windows and Linux as well with the same result so it I am definitely doing something wrong.

PS: Found it! Of course it was one of these things that you don’t even think about when you have used Blender for a long time, but for me who have not used OSL before, it was not obvious that I had to hit Z and select “rendered” when everything rendered correctly as long as I didn’t involve OSL.

Well, that goes into my “how to” list. Thanks for your replies!

Glad its working. The magenta is because I clicked on the colour swatch, and that overrode the default 1,0,0.