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


I am really getting into this OSL thing and I like to share a second shader with you all. Detailed instructions and an example noodle can be found here:
I have called it a scales texture but it can be used for things like roof tiles (or shingles) or perhaps for a pine cone as well. I have built in a neat trick to output a random-but-constant vector for each scale so by plugging that vector into a noise texture you can give each scale its own, unique color or texture. In the image below I have used that to color the scales on this abstract Koi carp (yeah I know, it takes some imaganition :slight_smile: ) Anyway, the example noodle in the article is the one that produced this image so you can have a look at how it was done.


Very cool!

Do you know: is OSL usable with the Blender Internal renderer or just Cycles? I haven’t noticed anyone talking about that side of it.

Nice work on the shaders. I would be interested to know if one can create acceptable toon shaders with OSL.
Possible? Have any interest in giving it a go ?

OSL in Blender is just for Cycles and from what I read in the discussions I think it is very unlikely that it will be made available in BI, but you never know :slight_smile:

I am no expert on toon shading but I think it wouldn’t be that big a deal to create a shader which for example adds a black edge to an object or something. I might give it a go (but no promises :slight_smile:


I took a shot at a toon shader, have a look at the details here:

http://blenderthings.blogspot.nl/2012/11/a-toon-osl-shader-for-blender.html .

Here is an example with our always charming model Suzanne in the spotlight:

If this is an ‘acceptable’ toon shader is up to you of course :slight_smile:


Nice start. Only 8 lines of code? Willikers ! I’m going to play around with it and see what I can come up with.
Thanks for taking the time.

played a little with the scales shader

and if you move the light up and down you can see shadows up or down

how come this is changing shadows on model ?

it is supposed to be a virtual UV play only not supposed to make shadows!
in normal blender bumps don’t make shadows!


Are you sure it’s not just a combination of the shape of the bumpmap and the lighting, because any bumpmap in this kind of situation will have sides that are in shadow and sides that are in light like they’re supposed to.

The only reason there wouldn’t be shadow is if it was a fake bumpmap that’s really a diffuse map with an emboss filter applied in a paint program.

i used a spot light to illuminate a plane with node set up

we can see what looks like some shadows botttom or dow or may be an illusion!

and there is not glossy node on this so normal effect involved

happy cycles

It’s not inverted, is it?

It looks in part like you just need to invert the values.

the normal are outwards ?
all the same except for the light direction one is above in front and the other lower

so strange behavior seems to be affected by the light somehow

i did another test on the Egg and it does not seem to do that !


Thanks, varkenvarken.

the texture doesn’t produce normals but a distance to the centre of a scale. The example noodle takes this distance, inverts it and plugs it into the displacement input of the material output node. In Cycles this means a real displacement, not just a slightly altered normal, so you really can get shadows here.

I do agree that the inverse of the distance to centre of the scale is a rather crude way to determine the displacement because at the edge of the scale you get a very abrupt step which will probably cause ugly shadows. In a shader it is difficult to blur a value like you might do in the compositor so a better approach would be to produce a smooth function instead of just the distance to the centre. I will think about it but it is not easy to come up with such a function. Simply reducing the amount of displacement may already improve the appearance.

i don’t remember to have seen this in normal blender render!

and i tested the Egg with scales and it does not show this shadow effect

why is it working only on the plane ?

cause shadows must have some physical bump i tought UV were only virtual bumps and not influencing the light to create shadows


Have you tried stringing the input through a bump node so as to plug it into the new normal input of the shader nodes, because I believe that might solve your issue on how to create normals for the scales. (this is for creating bumpmaps only though).

The toon shader was helpful to me. May I ask a question, the solution of Toon shader on the blog http://blenderthings.blogspot.nl/2012/11/a-toon-osl-shader-for-blender.html was dot view vector and surface normal, how can I change the judgement to dot light source to surface’s position vector and surface normal ?

that is a good idea, I’ll give it a try. Thanks.

I am afraid you cannot, or not in any direct way. (If anyone thinks differently, please let me know!). In OSL there is no direct information about the light, only so called closures that behave like parameterized functions that incorporate the behavior of a surface in response to light, including sampling probability and what not.

Having said that, a diffuse() shader does more or less what you want, i.e. returns a closure that is the sum over all products of lights and surface normal, however the sad thing is that you can only multiply or add colors and other closures to closures (you cannot access the color components for example) so I don’t see a way to for example make the color completely black if the luminance is less than some threshold.

Thank you for your reply,a diffuse() could be use in this way. It’s a clue for me to try.
I think though there arn’t a light direct infomation in OSL, should we add a new node which can give arbitrarily mesh/object position in scene. If this can be implement,as in OSL/cycles any light is surface, we should get the light position and calculate the dot which light direct and surface normal. :slight_smile: