# OSL Goodness

Here is a description of OSL:

Is this just available on Windows only graphicall builds?

More OSL fun! I ported the Yin Yang shape from Inigo Quilez (written in OpenGL) to OSL, was pretty straight forward.
In this example I also use a “Value” node to animate the rotation of the pattern, really powerful!

``````/* Based on OpenGL Code by Inigo Quilez

#include &lt;stdosl.h&gt;

float yinyang(float x, float y, float rot)
{
float nx = x;
float ny = y;
x = 1.5*(nx*cos(0.2*rot) - ny*sin(0.2*rot));
y = 1.5*(nx*sin(0.2*rot) + ny*cos(0.2*rot));
float h = x*x + y*y;
float d = abs(y)-h;
float a = d-0.23;
float b = h-1.00;
float c = sign(a*b*(y+x + (y-x)*sign(d)));

c = mix( c, 0.0, smoothstep(0.98,1.00,h) );
c = mix( c, 1.0, smoothstep(1.00,1.02,h) );
return c;
}

float Scale = 1.0,
float Rotation = 1.0,
point Vector = P,
output color Color = (0.0),
output float Fac = 0.0)
{
point p= Scale*Vector;

Fac = yinyang(float(p[0]),float(p[1]), Rotation);
Color = color(Fac);
}

``````

ok… maybe i’ll mess with it some…
anyone know how to compile with OSL on
Windows 64bit MinGW? or is it only for Linux ATM?

what sort of NPR shaders (i am sure there are many) are possible with OSL? I have never touched it, but have been following this thread a bit, it looks VERY interesting.

Is it possible to do specular shapes with this?

just looked at the Blender Open Shading Language wiki…
its only available for the failing OS’s(Linux 1% and Mac 7%),
the rest of us have to wait…
“Open” is only considered “Open” when you’re invited

Wait, or get involved and help us compile the OSL binaries on Windows. :yes: It’s not easy on Windows.

@jikz: I am sure you can achieve several NPR effects/shaders with OSL, can’t give you an example though.

Pretty cool stuff guys. Unfortunately, the most useful part for me in the OSL pdf is not written, the “example shaders” chapter :ba:

Anyone is aware about a few simple shader examples with OSL? Some really basic to get familiar with it.

I think I already pointed you to the example Shaders we have in SVN? Lot of easy examples there. https://svn.blender.org/svnroot/bf-blender/trunk/blender/intern/cycles/kernel/osl/nodes/

I really start to love this feature!
I ported another OpenGL shader, this time from here: http://glsl.heroku.com/e#4549.0

Here is the shader in Cycles:

``````// Based on OpenGL Code:
// http://glsl.heroku.com/e#4549.0

#include &lt;stdosl.h&gt;

float Offset = 1.0,
float Time = 1.0,
point Vector = P,
output color Color = (0.0))
{
vector V = Vector;
V -= Offset;
color Col = color(0.0);
float vertColor = 0.0;
for( float i = 0.; i &lt; 7.; ++i ) {
V[1] += sin(V[0]*(i) + (Time * i * i * .03) ) * 0.15;
float fTemp = abs(1.0 / V[1] / 50.0);
vertColor += fTemp;
Col += color( fTemp*(7.0-i)/7.0, fTemp*i/10.0, pow(fTemp,0.9)*1.5 );
}
Color = Col;
}
``````

Edit: Animated version:

Looks fantastic!!!
Is planned to put the linux64 libraries of the OSL in svn? I would like to compile and try this myself.

Yes, I think we will upload them soon. The OSL Script Node is not in trunk yet, but should be included this week.

For Linux users it’s quite easy though to compile the dependencies themselves. I will update my Compile instructions when the node is in SVN.

So excited to finally try this out.
I took down a build from graphical for OSX. When I try to compile, I get a crash and a message in the console that it cannot find the stdosl.h file in /usr/bin/cpp, which I think doesn’t even exist on my Mac.
Can you let me know if and what the prerequisites are so I can get it up and running.

Thx R.

cell noise looks good -very useful for tiles,bricks…

could fake specular(like blender internal) achieved with OSL?

Edit: ok that was a dumb question.

so this is in SVN trunk now? ans script will come soooonn please?

The Node is not in trunk yet, but will be soon. Here I made a workflow video to show OSL in action:

Another pattern, this time a heart.

``````/* Based on OpenGL Code by Inigo Quilez

#include &lt;stdosl.h&gt;

float heart(float x, float y)
{
float s = mod(1.0, 2.0 )/2.0;
s = 0.9 + 0.1*(1.0-exp(-5.0*s)*sin(50.0*s));
x *= s;
y *= s;
float a = atan2(x,y)/3.141593;
float r = sqrt(x*x+y*y);

float h = abs(a);
float d = (13.0*h - 22.0*h*h + 10.0*h*h*h)/(6.0-5.0*h);

return smoothstep(d-0.02,d,r);
}

float Scale = 1.0,
point Vector = P,
color Heart = color(0.8, 0.0, 0.0),
color Background = color (0.2, 0.2, 0.2),
output color Color = (0.0),
output float Fac = 0.0)
{
point p= Scale*Vector;

Fac = heart(float(p[0]),float(p[1]));

if (Fac == 0.0)
Color = Heart;
else
Color = Background;
}
``````

looks prety cool, but hearts come on all shapes and sizes…
(skinny ones, fat ones, long ones, long tailed ones… etc)

would neat if it had an adjuster to make the different sizes automatically…
instead of having to go inside of the code and doing math etc…

off-topic: LOL “failing OS’s” - you mean the ones that have been around for just as long as either Windows or Mac OS, and are gaining in popularity all the time?

back on topic: could someone by any chance do a quick tutorial on writing shaders? i’m pretty new to C, and can write a basic CLI program, and i saw in the OSL spec that the language is quite a bit like C… but writing a shader seems like it begs a detailed understanding of the OSL specification and such, and i’m a little confused by what i saw on the Light Paths wiki page on the OSL site. i’d like to start getting my feet wet without having to fully understand the whole specification, if that’s possible.

PS: thought i should mention, i AM reading through the specification right now.

You can find some infos here: http://wiki.blender.org/index.php/User:DingTo/OpenShadingLanguage
And yes the Language Spec PDF is the first thing you should read.