A scales shader, or how to use the new Open Shading Language features in Blender II

have not seen yet OSL functions!
is there a list of OSL commands for cycles
and link to get it !

thanks

Well, I have played around a bit more and looked into the Blender source code to see what attributes we can get with the getattribute() function, and voila! you can get enough information to calculate the light vector! I wrote down a quick howto on my
blog: http://blenderthings.blogspot.nl/2012/11/getting-light-vector-in-osl-for-blender.html

Note: if you are curious what other attributes can be queried in Blenders OSL implementation check the

get_object_standard_attribute() method in the cycles source code https://svn.blender.org/svnroot/bf-blender/trunk/blender/intern/cycles/kernel/osl/osl_services.cpp
Cheers

Check the link ‘language specification’ on http://code.google.com/p/openshadinglanguage/

Blender pretty much implements it completely (and adds some of its own). Remember that OSL is not yet part of any official release so maybe Thomas Dinges or one of the other devs might add some specific documentation on the Blender specifics later on.

cheers

i did get the official OSL 2.0 PDF list of commands
and there seems to be a lot more commands
i mean there are pages of commands
but don’t know if cycles has all these commands!

thanks

I wasn’t aware there was a version 2 (aren’t you confusing things with OpenGL? can you point me to the 2.0 pdf that you mention?)

Blender certainly implements version 1.1 and of course you can always try if a function is available.

edit: actually Blender uses 1.2 and that is the version from august 30, 2012 so I am pretty sure the is not yet a version 2.0 of OSL available. Check the notes in svn:
https://svn.blender.org/svnroot/bf-blender/trunk/lib/win64/osl/CHANGES

cheers

https://github.com/imageworks/OpenShadingLanguage/blob/master/src/doc/osl-languagespec.pdf

sorry it’s version 1.1

but the qty of commands is huge !

is there a list of osl command for cycles to compare it with this official osl 1.1?

or is cycles only a sub set of the official osl!

salutations

There is no need for such list: Blender uses the external OSL libray, i.e. implements everything. It might differ in a few aspects (because it’s up to the developers on how to actually implement stuff) and that is mainly in the area of available object attributes and in the actual closures available. In fact, besides the closures listed in chapter 7.10 (like diffuse() and ward() it actually adds some closures of its own, notably phong_ramp() and ambient_occlusion(), so in a sense its a superset.

And once you realize OSL is just another C-like language, the list isn’t that huge. Just read the manual a few times, experiment with some simple shaders and experiment a lot.
Much can be learned from the way most standard Cycles nodes are implemented in OSL: just check the stuff in https://svn.blender.org/svnroot/bf-blender/trunk/blender/intern/cycles/kernel/shaders/for inspiration.

cheers

Awesome!!! Thank you give me a straight way to get the cel shader:) Cycles can do anything!I’ll follow your clue to playaround the blender shader system. Thanks again!:smiley:

You’re welcome. I am interested to see what you will create.

cheers


Hi,again.
This my quick test .I add a suzanne to scene,and mix the toon shader and oink shader code of this site http://blenderthings.blogspot.nl.
this is my shader


shader outline(
    color Color = 1,
    float Angle = 50,
    float Angle1 = 70,
    output color Cout = 0
)
{
    vector L;
    getattribute("Lamp","Suzanne:location",L);
    P=transform("Suzanne","world",P);
    float cost = abs(dot(normalize(L-P),N));
    float angle = cos(radians(Angle));
    float angle1 = cos(radians(Angle1));
    if(cost < angle && cost >angle1 ) Cout = Color ;
    else   Cout = Color + 0.2;
}

the node setup use this link http://blenderthings.blogspot.nl/2012/11/a-toon-osl-shader-for-blender.html
And I find a weak point of this method, if I move object Lamp,the shader color of suzanne will not change, but move suzanne color will change well. I’ll check https://svn.blender.org/svnroot/bf-blender/trunk/blender/intern/cycles/kernel/osl/osl_services.cpp for more test.

Hi Yuzupei,

looks nice already! Maybe your problem is caused by the getattribute() call: I think it should look like this:


    getattribute("Lamp","object:location",L);

The way you used it refers to the attribute “Suzanne:location”, which is unknown for the object called “Lamp”, so getattribute will silently return a null vector (0,0,0).

Cheers

I change a bit the code,the shader color more likely a toon now.



shader outline(
    color Color = 1,
    float Angle = 50,
    float Angle1 = 70,
    output color Cout = 0
)
{
    vector L;
    getattribute("Lamp","Object:Location",L);
    P=transform("Suzanne","world",P);
    float cost = max((dot(normalize(L-P),N)),0);
    float angle = cos(radians(Angle));
    float angle1 = cos(radians(Angle1));
    if(cost < angle && cost >angle1 ) Cout = Color + 0.2;
    else   Cout = Color ;
}

And I find whatever I put in getattribute(), it’s doesn’t work too. I can’t change Lamp object position to change shader color, maybe there are some sync mechanism to the getattribute() fuction.

toon shader in blender also has some sort of color toon edges wich are not there yet in your model!

salutations