With this code we'll realize a lambert shader with 3 custom parameter: diffuse color, texture color, opacity.
Here the code with some comment due to explain all the lines.
\\definition of the shader tipe "surface" and the name. Between the brackets there's the parameter, one of color type, one of string type and one of float type.
surface Lambert(color diffuseColor=color(1,0,0); string colorTexture=""; float opacity=1)
{
\\definition of the texture projection coordinates in world space
point worldP = transform("world",P);
\\function to normalize vector normal
normal Nn = normalize(N);
\\with this function we normalize the vector for pointing to the camera eye ("I")
vector Nf = faceforward(Nn,I);
\\definition of a texture file with path passed by the parameter with the coordinates u and v (s,t)
color textureFile = texture(colorTexture,s,t);
\\if there is a texture file use that else use the color
if (colorTexture!=""){
Ci = textureFile;
}else{
Ci = diffuseColor;
}
\\multiply the previous Ci (output color magic variable) by the diffuse of the normal faceforwarded vector
Ci *= diffuse(Nf);
\\apply the opacity
Oi = opacity;
}
Don't forget to prepare the texture with the tdlmake command. Open a terminal and write the following code line inside the image directory:
tdlmake -mode periodic imagename.imageextension imagename.tif
Comments
Post a Comment