How would I add bump mapping on an OSL shader?
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.