OSL Goodness

Thank you Brecht for the tip, I will look into this.

Color temperature (in Kelvin) to RGB script.

Vectors (a, b, c) were generated from http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html and http://zunzun.com/Equation/2/UserDefinedFunction/UserDefinedFunction/ , with R-squared > 0.9994, the model “A / (X + B) + C” suits perfectly. In some cases Gamma=2.2 should be applied to the generated color.

shader temperature_color
[[ string description = "Color temperature to RGB converter, for 1000 < t < 40000" ]](
    float Temperature = 6500.0,
    output color Color = color(0, 0, 0)
) {
    vector a, b, c;
    if (Temperature <= 6500.0) {
        a = vector(0, -2902.1955373783176, -8257.7997278925690);
        b = vector(0, 1669.5803561666639, 2575.2827530017594);
        c = vector(1, 1.3302673723350029, 1.8993753891711275);
    } else {
        a = vector(1745.0425298314172, 1216.6168361476490, -8257.7997278925690);
        b = vector(-2666.3474220535695, -2173.1012343082230, 2575.2827530017594);
        c = vector(0.55995389139931482, 0.70381203140554553, 1.8993753891711275);
    }

    vector x = a / (Temperature + b) + c;
    Color = color(clamp(x[0], 0, 1), clamp(x[1], 0, 1), clamp(x[2], 0, 1));
}

Recipe for Eyeball stew

ingredients:
1 copy of blender
1 uvsphere
1 osl script

Directions:
Run blender
Add uvshpere
Add osl script to node based material and link em up

A few duplications and your ready to drop them in the bowl for a great centre piece for the dinner table:D

Yep that’s it - no uv unwrap, just add the osl script and you get this simple eyeball


And that’s a 2 sec render with 10 samples.

Sure this can be improved with some better noise in the iris and probably for the veins but just think what you can do with osl scripts.

You can find the script at https://github.com/sambler/osl-shaders/blob/master/character/LGEyeBall/LGEyeBall.osl

Theres quite a nice variation of this in RSL over at http://www.angelfire.com/comics/lyubomir/LK_RenderMan_shaders.html

Sadly its way beyond my understanding :frowning: but I’d love something similar that could map to an edited object, not a sphere, so that the iris part could be indented and removal of its glossy at that part so a seperate object cornea could be placed over it.

I’m guessing that someone with the right knowledge could program the shader to create the whole eye, using a base sphere or empty, and programatically create the indented matt material iris and glossy transparent cornea bulge, if my understand of how shaders might work is correct?

That would then allow for a camera to zoom into a close up of the eye with the detail and physicality preserved as the shader referenced would look wrong when viewed close up from the side of the eye as there would be no bulge for the cornea.

Please excuse the musing and rambling, serious lack of sleep.

There are 3 new Closures in Blender: diffuse ramp, diffuse toon (Re 53189), and specular toon (Re 53189). I spent sometime figuring out how to make a decent looking toon shader, and the result is quite pleasing. FINALLY, real toon shading in cycles!!!

The settings I feel make a good effect are the defaults in the OSL code:

shader Toon(
float Fac = .4,
int High_On = 1, /* On/Off Switch for Highlights /
int Base_On = 1, /
On/Off Switch for Base /
color High_Color = .8, /
Highlight Color /
color Base_Color = .1, /
Base Color /
float High_Size = .05, /
Affects shading area; smaller area = more specular-like /
float High_Smooth = 0, /
Higher values allow light to wrap around object /
float Base_Size = .5, /
Affects shading area; bigger area = more diffuse-like /
float Base_Smooth = .25, /
Higher values allow light to wrap around object */
normal Base_Normal = N,
normal High_Normal = N,
output closure color BSDF = background()
)

{
BSDF = High_On * Fac * High_Color * diffuse_toon(High_Normal, High_Size, High_Smooth)

  • Base_On * (1 - Fac) * Base_Color * diffuse_toon(Base_Normal, Base_Size, Base_Smooth);
    }

I would’ve clamped some values, but clamping has not worked for me…



The lighting is just two planes and a single color background. I originally used both diffuse and specular closures, but I prefer the look of diffuse highlights. Any improvements are welcome.
Thank you devs for all your awesome gypsy magic!!!

I have started an OSL IRC chat room, so if you want to talk about OSL, Cycles and shading, feel free to say hello! :slight_smile:
http://www.openshading.com/about/chat/

DingTo, can we get an OSL forum on BA under scripting? Who do I need to ask?

Charlie: Good idea, I asked Fweeb (one of the Mods here). He will discuss the topic with the other blenderartists people. :slight_smile:

+1 good idea

Great stuff here!

I was wondering if something like this could easily be ported to blender OSL

A pixar style eye with fake caustic and reflections

Done! Check out the new sections under Coding: http://blenderartists.org/forum/forumdisplay.php?47-Coding

Yay, thanks

thanks jonathan

Will OSL ever be able to use the GPU?

So how far can one go with osl? For example, can a good fakeSSS shader be created in osl, similar to mental ray’s misss shaders?

Can cycles functionality be extended through osl, like displacements or volumetrics?

Just curious about how far this thing can go, its such an awesome new feature!

@larmannjan: One day maybe, but there are no immediate plans for it. It’s also not really up to us (Blender) but more up to the OSL team. See also the OSL FAQ: http://www.openshading.com/osl/faq/

@fahr: You cannot implement a closure in OSL, closures still need to be implemented inside of the render engine.
Same for volumetrics and so on, that’s part of the render engine, not the shading system.

Those features can be used/accessed though via OSL after they have been implemented.

Ok, makes sense. Thanks for the clarification.

Where would be a good place to start learning how to program shaders?

You can find a lot of resources (Video Tutorials, Example shaders, written “Getting Started” guide and more here: http://www.openshading.com

It’s a good reference and all, but I mean for ground zero. For someone who doesn’t have any experience in creating shaders.