Leaf_Shader


When I first thought about this RSL shader for this project, I have to show the advantage of the RSL function attribute.
The problem that i had to face and solve was that each object had to be unique and different even if they were
the same of that were spread around the scene. In this case it was a leaves.

By assigning the values for Max and Minimum height, it controls the color mixing of the leaves.
The position of the tree determines the color of the leaves.
// Getting the points from the micropolygon
point pp = transform(forest, point "object" (0,0,0));
float Ypos = pp[1];
// Setting the color range for the blend
float blend = smoothstep(minheight, maxheight, Ypos*0.7);
surfcolor = mix(mincolor, maxcolor, blend);
By getting the identifier:name attribute from the object, The shader will use the number at the end of the object to decide
what color the object will have when it is shaded by this shader.
// The shader will get the number of each polygon, and use the number at the end to shade the poly.
if (attribute("identifier:name",name) == 1 ){
if(match ("1$", name))
surfcolor =mix(ranmaxcolor, ranmincolor, 0.3);
else if(match ("2$", name))
surfcolor =mix(ranmaxcolor, ranmincolor, 0.9);
else if(match ("3$", name))
surfcolor =mix(ranmaxcolor, ranmincolor, 0.8);
else if(match ("4$", name))
surfcolor =mix(ranmaxcolor, ranmincolor, 0.1);
else if(match ("5$", name))
surfcolor =mix(ranmaxcolor, ranmincolor, 0.7);
else if(match ("6$", name))
surfcolor =mix(ranmaxcolor, ranmincolor, 0.2);
else if(match ("7$", name))
surfcolor =mix(ranmaxcolor, ranmincolor, 0.6);
else if(match ("8$", name))
surfcolor =mix(ranmaxcolor, ranmincolor, 0.4);
else if(match ("9$", name))
surfcolor =mix(ranmaxcolor, ranmincolor, 0.5);
else surfcolor = ranmincolor;
}
Using polyMeshArchiveRI;
The polyMeshArchiveRI is a procedure that you can use to read Archives from the vertices.
The Script for the reading vertex is:
global proc polyMeshArchiveRI(string $pathToArchive)
{
string $shape = 'rman ctxGetObject';
int $num[] = `polyEvaluate -v $shape`;
for($n = 0; $n < $num[0]; $n++) {
string $vert = $shape + ".vtx[" + $n + "]";
$pos = `pointPosition -local $vert`;
RiTransformBegin();
RiTranslate($pos[0], $pos[1], $pos[2]);
RiReadArchive($pathToArchive);
RiTransformEnd();
}
RiAttribute "visibility" "int camera" 0;
RiAttribute "visibility" "int transmission" 0;
RiAttribute "visibility" "int diffuse" 0;
RiAttribute "visibility" "int specular" 0;
RiAttribute "visibility" "int photon" 0;
}
After sourcing the MEL global proc polyMeshArchiveRI() into the scripting panel,
it can be used in the RenderMan Extra Attribute PreShape MEL just like the method of using proxies.
By Putting the code :: polyMeshArchiveRI("$path");
in the PreShape MEL, vertex is going to read the rib files automatically.

By using this technique, I thought that i could use this shader with idea of where the leaves are going to be placed
also have greater understanding of where the blends, max, min values are going to appear on the leaves.
The Final Image look like this:

In conclusion, I think this Leaf_shader was very sucessful for these kind of situation where there is lots of object and had to have unique shader.
By shader itself, i think it did great job of doing something that could be done with very expensive way.
All CopyRight Reserved 2009 @ mrgentle.net