- Procedural Tree
In order to color a full set of leaves with different color variations we can take advantage of a simple shader in created in RSL to create a slim template that will allow us to create quick variations of multiple geometry a only using one main shader.
- TECHNICAL BREAKDOWN
- How are the Branches Created?
In this case i used a simple idea of translating the leaves on the normal of the face. So basically I create a leaf and then I move along the face normal where it was created by a spread amount. There I create the next one.
How do the branches curve?
One of the main flaws of moving along the normal is that we get these straight un-natural looking branches. To chance that I used a simple concept of usint the negative parabola of x^2 (x square). We can control the arching of this function dividing x^2 by a factor (or multiplying it by the inverse factor).
Here is a visual example of what happens with this function:
- So what we need to do is each time we move along the face normal, we change the y component for:
y = -archingFactor*x^2.
- Building the Leaf Shader
We wanted to create a leaf shader that was a little more complex than just a texture on a plane. The basic parts we wanted to have after looking at some references were:
Front and Back :Leaves have two differentiated parts in terms of texture, the back that is normally more shiny and the back that is normally lighter and more matte.
Specularity: For the front part of the leaf as we said before we wanted to have some specularity.
Translucence: Leaves are translucent when sunlight shines through them so we wanted to incorporate this to our shader.
- #1 Front Leaf Color
#2 ColorByName Shader
- The texture for the front leaf color that will be combined with our utility shader.
#3 Back Leaf Color
- This is where all the magic happens. This node outputs a color based on the name of the object it is attached to and an average color decided by the user.
#4 Leaf Alpha
- For the back of the leaf we have a different texture file.
#5 Specular Map
- We use this alpha to cut out the shape of the leaf from the plane where the shader is assigned.
#6 Facing direction
- We control the specularity of the front part of the leaf with this black and white maps.
#7 Mix Colors
- This node is used as a mask to reveal the back leaf color file if we are looking at the back of the leaf.
#8 All Purpose shader
- These two nodes mix the color from the ColorByName Shader with the two front and back leaf textures.
- This is the main shader that combines everything. It has two layers (the back and the front of the leaves) revealed with the facing direction node. The back layer of the leaves has also translucency.
- #1 Front Leaf Color
- USING RIB ARCHIVES
In order to speed the interaction with the tree mesh in the viewpor we've used the ability to load pre-baked rib files as our leaves to be rendered dring rendertime. But as this approach is valid for rendering one image, if we are rendering a sequence, or once we are happy with the distribution of our leaves, we want the posibility to not have to compute the creation of the leaves any more. So in essence what we've done is implemented the function to bake our rib files of the ditributions that we've created and then the ability to reuse these bakes rib files so we only have to compute the distribution of the foliage once. This is where the menu that we saw on the UI shines. I set to compute the rib file with the distribution is baked and then read to render. If it's set to reuse, we read this baked rib file and we render it and if it's set to off then we do nothing.