Include generates error

Hello,
just put this line in an external osl file, that is in the same folder of the blend file as well as the header file:

#include “a.h”

but I receive this error:

ERROR: error: No shader function defined

If I comment that line, the shader works.

Header file:

vector sum(vector v){
  return vector(v[0]+1, v[1]+1, v[2]+1);
}

Shader file:

#include "a.h"

shader wood4 (
    point p = P,

    color ColA = color(0.8, 0.6, 0.5),
    color ColB = color(0.6, 0.4, 0.2),

    output color Co = 1.0
){
    point pshad = transform("shader", p);
    
    color cols[4] = {ColA, ColA, ColB, ColB};

    Co = spline("linear", p[0], cols);
}

They are very simple as I’m just testing osl in Blender.
Thank you a lot for any help.

The header file must be placed in 2.xx/scripts/addons/cycles/shaders/, not where your blend file is.

1 Like

@Secrop, I did it where you said, but I have always the same error message:

ERROR: error: No shader function defined
Error: OSL script compilation failed, see console for errors

Tried include with both “” and <>, but no good result till now.

Check if you have an empty line in the end of your header file…
So instead of this:

vector sum(vector v){
  return vector(v[0]+1, v[1]+1, v[2]+1);
}

you need to have this:

vector sum(vector v){
  return vector(v[0]+1, v[1]+1, v[2]+1);
}

This is an old limitation of the OSL compiler…

First, thank you a lot, it’s working now.

Then, whaaat? Reeeaaally?
Just put some empty lines in the header file in the same folder of blend and shader file and it wored… but really?
Is that written somewhere? You know, just not to bang my head against wall thinking I don’t know the basic of scripting… :smiley:

Thank you again, dear, have a nice day.

That’s new! since ages that i’m saving my header files in the cycles/shaders folder, that i never noticed that it’s now working in other paths!! :smiley:

1 Like

While the header file is working in the same folder of blend and shader file and in the folder you suggested early, I can see it’s not working in the following path like the other scripts I’m using:

AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons\cycles\shader

The reason I’m asking for that is because it would be easier updating to the last 2.8, while having all my everyday scripts and shaders in a folder untouched. Hoping it makes sense.
Thank you again

I’ve it tested right now… the header file works in the same folder where the osl file is. No need to be the blend folder.

1 Like