I am currently translating the RenderMan shaders in the “Essential RenderMan Fast” book to OSL, for learning purposes.
For instance, I have translated
surface matte(
float Ka = 1;
float Kd = 1;
)
{
normal Nf = faceforward (normalize(N), I);
Oi = Os;
Ci = Oi * Cs * (Ka * ambient() + Kd * diffuse(Nf)));
}
as follows
shader erf_matte(
float Ka = 1,
float Kd = 1,
color inputColor = color(1, 0, 0),
output color outputColor = color(0, 0, 1),
output closure color myBSDF = diffuse(N)
)
{
outputColor = inputColor;
normal Nn = normalize(N);
myBSDF = outputColor
* (Ka * ambient_occlusion() + Kd * diffuse(Nn));
}
However, when I render, my solid is bright [red], not matte.
Is the absence of “matteness” due to the fact that the output color is not multiplied by the Input Opacity Factor (Oi in Renderman Shader), which is not available in OSL [according to the OSL Language Spec], as opposed to Renderman?
I think almost everything you did is good to go, except that the values are too high for OSL everything is already kind of normalized so you should aim for 0 - 1 values (1 is the maximum and almost always to high!), i’ve made some changes to your original code:
shader erf_matte(
float Ka = 0.1,
float Kd = 0.1,
color inputColor = color(0.5, 0, 0),
output color outputColor = color(0, 0, 0.5),
output closure color myBSDF = holdout()
)
{
outputColor = inputColor;
myBSDF = outputColor
* (Ka * ambient_occlusion() + Kd * diffuse(N));
}