 # OSL to bump

Hello,
I’m exploring OSL in Blender, but I stopped because I can’t see bumps driven by my texture.
Here’s a screenshot:

The code is this:

``````shader mgs_wood(
point Point = P,
float ring = 5.0,
color ColorA = color(1, 0, 0),
color ColorB = color(0, 1, 0),
output color Col = color(0.0, 0.0, 0.0),
output float flo = 0.0)
{
float f = 0.0;

f = step(sin((P)*ring), 0);

Col = mix(ColorA, ColorB, f);
flo = f;
}
``````

What I’m doing wrong?
Thank you

You need to plug a builtin vector into your script node, instead of using P from the globals. The reason is that OSL’s P is fixed, and it doesn’t allow Cycles to calculate the texture derivative.

I was stupid, I had to write Point instead of P inside the formula!
Sorry humanity! This is the correct code.

``````shader mgs_wood(
point Point = P,
float ring = 5.0,
color ColorA = color(1, 0, 0),
color ColorB = color(0, 1, 0),
output color Col = color(0.0, 0.0, 0.0),
output float flo = 0.0)
{
float f = 0.0;

f = step(sin((***Point***)*ring), 0);

Col = mix(ColorA, ColorB, f);
flo = f;
}
``````

But even with that correction you’ll still need to connect a vector from any builtin node, so that Cycles can shift the coordinate and calculate the texture derivative.
This is just if you want to use the bump node.

You can however calculate the derivatives of f in osl, thought it will be in screen space, which you then need to convert to world or tangent space.

1 Like

Yeap, Secrop, you are right, I need to use texture coordinate node for that.
Thank you again.