diffuse_toon(N, 0.5, 0);


I've found out by reading through the specifications of OSL that N is a global variable, pertaining to normals, but I'm not certain on how to use it.

If I were to use a Normal Map node to get a vector from an image, how could I make it so I could plug it into an OSL shader and have it come out as a bump-mapped surface?

## Store in a vector/normal variable:

Let's suppose you've got a Normal texture:

OSL Code:

shader Bumped(
normal NormalMap = 0, //the input (normal map vector starting "empty")
output closure color Bumped =0 //the output (closure, AKA the final shader)
) {
N = normal(NormalMap[0], NormalMap[1], NormalMap[2]); // store X, Y, Z component from NormalMap
Bumped = diffuse_toon(N, 0.5, 0); //define closure
}


The code above creates a closure output named "Bumped" which is based on a "diffuse_toon" shader, whose normal information are stored in the variable "N" that we declared.

"Normal" is a vector-like variable (x, y, z).

To access the respective "i" component of the NormalMap use the syntax NormlaMap[i], as it's stored as an array.

• X = NormalMap[0]
• Y = NormalMap[1]
• Z = NormalMap[2]

That said, you can shorten the code by avoiding the use of the variable N, just use your own like in this example.

shader Bumped(
normal NormalMap=0,
output closure color Bumped = 0
){
Bumped=diffuse_toon(NormalMap,0.5,0);
}


Here's a comparison between the result of the OSL shader and the one coming from Cycles nodes.

• Wow, thanks for the in-depth explanation! I'll try it when I get home.
– Poyo
Commented Jul 20, 2015 at 15:13