OSL : Displacement Functions

In the OSL language specification, we read :

Shader types include the following: surface, displacement, light, volume, and generic
shader. Some operations may only be performed from within certain types of shaders (e.g.,
one may only call displace()or alter Pin a displacement shader), and some global variables
may only be accessed from within certain types of shaders (e.g., dPdu is not defined inside a
volume shader).

I try to make a displacement shader like it :

displacement DisplacementShader
    vector Coordinates = 0
    float cloudsTexture = noise("perlin", 25*(Coordinates+0*Coordinates[1]));

But i don’t know how to apply this displacement shader to my cube :no:.

Another question : Could we use OSL shader without use node that means without Scripts Node ?


First thing first: you have to use a Script node to make use of an OSL shader. Your code lacks an output socket for the displacement. You can do it as such:

Also here is the OSL bump code that Blender is using:


is there a way to use this shader as real displacement? not only a bump?

turn experimental features on plug the bump into the materials displacement output?

Cycles has no real render-time displacement at the moment, at least none worth trying to use. Dicing and hole patching is broken. Displacement via the OpenSubdiv standard is coming at some point in the future.

Actually i have a script that enables true Cycles displacement you just have to turn experimental features on and true displacement with subdivisions on and finally plug the script below into the displacement input of your material:

displacement Displacer(
output float Fact = 0
P += (distance(Ng,P,I0.1)0.1)(noise(P10))*10;

You’ll then be able to achieve results like this one below:

And another one from the same object:


Waaaa ! Thank you tree3d !

That sounds GREAT ! I’m going tpo play with this asap!

Waaaa ! Thank you tree3d !

That sounds GREAT ! I’m going tpo play with this asap!

Thanks Youpi3D! Please let me know if you have any issues with it, i wrote it yesterday and haven’t properly tested it yet!