home
contents
resume
showreel
portfolio

resources
renderman
maya
massive
houdini

friends
professor malcolm kesson
professor ron bernard
aleksander rodic
andrew dehner
billy dongyoon jang
kiki poh
sandro blattner
zahari dichev

contact
01. 912 . 272 . 2209
davekcw@yahoo.com.sg
Procedural Leaf Generation and Shading - Creating a canopy of leaves
By incorporating all that we have learnt earlier, this project explores a different but more efficient way of channeling more data information compared to the earlier and more (using python to generate a RIB file) concept. Instead of writing to file, this process explores the use of RIB data while it is being generated on the fly~ by piping it directly into the rendering engine,

Notes!
This project may differ from the initial assignment writeup written for Professor Malcolm Kesson. It would have been edited to also reflect my later experiences, clearer tutorial techniques/codes and also later advancements made to the projects as well.
   
Re-Introduction

As the focus of this class is on the ideal of Procedural Shaders, it seems that most of the topics covered would involve in the further extentions of lessons already learnt in past Renderman classes. For this particular tutorial, we are using the exact same RIB Archive techniques seen in VSFX 319 and a Procedural RIB generation technique seen in VSFX 705.

This generally means that a series of random leaves are generated using python scripts and these generated RIB files which contains thousands of leaves are used in Maya using RIB Archival / Replacement techniques which occurs only at Render-time.

However the difference of this tutorial is in the study of obviously, leaves and also in the implementation of Proceduralism by further extending the use of RIB files in conditional / logical statements and evaluations; and also in the usage of the options command to implement production customizations and user variables.

The result of such can be seen in the preview render below:-



Research
So as mentioned, the focus is on the shader itself, and not the generation of the geometry data... Thus research would be most vital. To better preview the effects of Proceduralism itself, the leaf shader would first need to demostrate the capablities of an intensive amount of variations... as such, I have chosen to use Autumn leaves as my research base...

 

 

The leaf in particular is of the Acer Palmatum (Japanese Maple Tree). The reason being the speciality of the Japanese Autumn festivals and the extremely unique shape of its leaves which would add to the beauty and technical aspects of this shader.

Unlike an ordinary mundane leaf, the maple is shaped into a combination of multiple leaf like shapes, a shape seemingly merged with the structure of multiple spiked leaves. It is not the commonly seen "undulate" type leaves that are a simple mere oval, but rather spikes out in a clusters of irregular beauty, slender and vigorous in its form.

Its color, as a seasonal tree varies greatly from green to yellow, gold, orche and red, most often pigmenting from its extremes to its inner core allow of a non-uniform coloration of the tree, which when illuminateed in the autumn sunlight becomes a beautiful field of golden illumination which is most symbolic of the seasons.

And thus makes it the best subject for testing under the regime of intense proceduralism.

 
 
 



  Using RIB Python and Pre-Node Shapes
 

After going thru quickly on the scope of the class, we were introduced to the use of the Mel Procedure "RunProgramRI" which would quickly replace the use of Archived RIB files. This procedure calls up the PRMAN command known as RiProcedural which allows us to run a coded program/script such as Python which will then directly pipe information straight into the PRMAN renderer instead of user generated RIB files which takes up not only memory but physical harddrive space as well.

This instant generation process is extremely fast and powerful, allowing for the use of possibly millions of polygons while using a minimal amount of resources. Using this technique, we are then to recreate an example tree which would demonstrate our mastery of this program. (an example is shown below...)

 

  Fixing the LeafHelper.py
 

As an example, we were provided a rough python script similar to that which generated the RIB files in the earlier stages of this project. However, these files were laden with a vast amount of restricts and flaws which I have tweaked to better and correctly generate a better canopy of leaves.

 

For starters, the concept of the new canopy script involves various factors. The polygon is now first translated to shift its pivot to the appropriate location, jittered to give variety scaled to its appropriate custom sizes and then give a droop factor which would possibly vary base on the angle of its canopy slope.

Such leaf is then translated to the Y height between the maximum and minimum values of the canopy size before the leaf is then rotated onto the canopy slope and then distributed in a 360 degrees rotation around the spherical distribution.

This gives us a more appropriate looking canopy as compare to the earlier "normals facing"-like canopy which looks more applicable as a visual effects shield of sorts.

An example of such canopy can be seen in the below 2 diagrams which demonstrates the capablities of the new generation technique.

 
 
 

Other correction that occured with the new technique also involved a correct of earlier flaws in the provided codes...

One, being an necessary "while" loop in the script which could leads to the possible catastrophic demise of system resources see in this sentence:-

args = sys.stdin.readline()
while args: <commands> args = sys.stdin.readline()
## End the generation of the procedural primitive_______

While a while loop is a common form of loops beside a for loop, it is what I would term as a dangerous loop due to the reasons that a variable, once declared cannot be easily be removed in certain languages. In this case however, the while loop runs as long as args is declared, and there seems to be nothing set in motion to undeclare this variable... as seen in the last sentence of the loop.

In conclusion, I was suffering from frequent halts in Maya, often view with duplicates of prman and python running in RHEL's process list, it was evident that something is wrong with the code and I have thus removed the loop statement which never really did serve any purpose in the first place.

The Second fixed flaw, was in the mel script RunProgramRI() which was unable to use maya's Xform syntax to properly detect object space bounding boxes. While it is easily confused to try to get the correct bounds under Maya's weird syntax of OS and WS, it is important to remember that World Space is transformation applied onto Object space vertices. Therefore, using a concept from Maxscript, (which had a clone to Mesh syntax) the proper bounding box parameters were easily acheived by first querying the transformation matrices of the object, undoing all transformation on a duplicate object to obtain proper parameters and then removed said duplicate.

And based on the references, a rough attempt of generating a Japanese Acer Palmatum can be seen below.

 




  Expansions?
 

At this point, there are still certain glitches left in the attempts. One sometimes the leaves would simply refuse to render while other times, it would just work... I was not yet able to determine the cause, however that is something to look at in the future expansions. I was also unable to determine a proper transluscency shader for the leaves either. The leaves seen above had a ambient mulitplier added over them to create a glowing effect. This sadly, diminishes the color variations of the leaves and is something that I will be looking at.

Lastly, I intend to make a stronger procedural shader for the leaves, basing on the studies and research of Dr David A Young of Lawrence Livermore National Laborartory who had created a somewhat convincing equation to the shapes of leaves relative to its grow spurts.

 
   


 
dave kin chang wei - visual effects artist / technical director - davekcw@yahoo.com.sg - www.kamid.net