This assignment demonstrates the basics of scripting using
RenderMan scene description (rib) protocol. Addressed are the fundamentals of xyz coordinate system through the creation of basic geometry that is transformed in 3D space. The preliminary renders have been done using basic shading so that the geometry can be more easily seen.
Figure 1 is the sample picture which I took as a reference for the assignment and tried to match the picture in
RenderMan. In order to do this assignment, I used the following languages and tools:
- Cutter (a handy text editor for use with various scripting languages and is tightly integrated with a lot of
RenderMan compliant renderers (e.g.,
3Delight, etc.) as well as modeling packages such as Maya, etc. The author Malcom Kesson, an awesome guy from SCAD is the author of this tool and he’s the one behind the format of these assignments that I’m following as well. Here is his link: www.fundza.com & http://www.sfdm.scad.edu/faculty/mkesson/.
- Python (an extremely powerful language that is fast becoming the preferred scripting language for most of the CG applications for its neatness, portability and higher-level functionalities). Download it from here: http://www.python.org/
- 3Delight (an amazing
RenderMan compliant renderer that is the best you can get for playing around with
RenderMan for no cost at all!). Get it from here: http://www.3delight.com/en/
For this assignment, I divided my task in different phases. Following are the phases and their details with code snippets.
Step 1 - Internal Pattern of Sunflower
Upon close inspection of the sunflower as seen in the reference image (there are many variants of a sunflower so I just stuck to the one in the reference image), one can see that this sunflower exhibits a very peculiar pattern in the way seeds are arranged internally. Google provided me with more information immediately.
So, the first task was to determine the internal pattern of a Sunflower which follows the specific pattern shown in the matlab sample, downloaded from Wikipedia entry for a sunflower. It uses the following mathematical formula to form this shape:
Using cutter to prototype the ribs and then using Python in order to run a loop, I used the Cone primitive (instead of plotting an ‘
o’ in the matlab sample code above) to make this seed pattern of the sunflower. Following is the code snippet and rendered view:
// While(n < div):
The matlab code above would only draw a seed pattern in 2D (XY plane) but in reality, the seeds are arranged on a sphere and not plane. One could use the true spherical coordinates in order to find the distribution of cones on top of a sphere but instead, I cheated and simply used a linear interpolation between the radius of the imaginary sphere on which the cones were to distributed and the origin of this sphere (in this case, its zero). The interpolation factor was the gradually increasing radius used in the loop above. This way, while the matlab sample code kept increasing the radius by calculating it as a square root of the loop iterator, I kept decreasing the
z value of the seed coordinates all the way down to zero in order to give a ‘bumped’ form where seeds are closer to the camera in the center and gradually push back in the depth as they move towards the boundary. After calculating the appropriate values of x, y and z coordinates, a scaling factor was calculated using linear interpolation as well in order to give the effect of cones (seeds) scaling up as they move towards the boundary. Finally, all these values were applied using appropriate translate and scale commands of rib before drawing the cone primitive.
Step 2 - Randomize Cone based Circle
Next up was the middle ring of seeds. I had to make the cones arrange in a circular ring of a certain width which has cones (seeds) more in dense format and have random positions not exactly following any strict pattern. For this, I used the randomize function of python to get random values, add them to the polar coordinates I calculate using the sin/cos functions and draw the cones on an xy plane in the rib file, using Python.
Add a table with relevant code and images.
Figure 4 is the arrangement of cones in randomize format while in figure 5, you can see the combination of figure 3 and figure 4. To make the randomized pattern of cones, I first take the maximum radius value when I got out of the loop while drawing the inner seed pattern, run a loop up to the radius of the middle ring and by using the random function of python and after some manipulation, get the value of my desired range and then translate the cones and draw them to make the ring.
Step 3 - Randomize Curves on the Circle
If you give a closer look to the inner side of sunflower, you can see it has some hairs type of things which are random in size and also arrange in randomize nature to make this effect I used Curves. In figure 6, you can see the sample of curves by using which I made the third ring of sunflower which is randomized in size and position. Figure 7 is the combination of figure 5 and 6. To make the outermost circle on figure 5, I first take the maximum radius value of figure 5 and after adding some value, define another radius for my curve based circle to make the curves I need the arguments in an array my task Figure 7 Figure 6 was not to make the curves but I have to make it random in size and positions to achieve this task, I first made the function of randomizing between the value required to me and made the array on run time so each curves drawn randomly and change with each other. You can see the function by name of
rf() in the source code of the assignment.
Step 4 - Petals of Sunflower
In this step, I have to make the petals for sunflower, initially I made the petals using subdivision surfaces of
Renderman and rotate the petals to give the effect of petals and resizing the petals using scaling I made three different layers of petals and each layer is indented towards Z axis along with some rotation to give the look of randomize petals, but later I made three different petals in MAYA and then use these Figure 9 Figure 8 petals using Read Archive for sunflower. Initially for petals, I made the petals in
Renderman by using Subdivision Surface and rotate the petals on figure 7 to give the look of random arrangement of petals I scaled the petals and their colors. To give the look of layered petals, I translate the each circle of petal layers in positive Z axis after it I made the three different petals in MAYA and apply them instead of petals which I made in
Renderman by using Subdivision surfaces. Selecting criteria of petal is determined on runtime by using the function name
randomizebound(a,b). I made this function to get the value according to my desired range, you can see this function in the source code which I made using python. This function took two arguments, first is lower range and the second Is higher range and return the value in between the range excluding the boundaries.
Below is the code in Python:
from math import sin, cos, pi ,sqrt,tan
from cgkit.ri import *
a = 0.0
r = 2.0
n = 0.0
[0, 1, -1, -1, 2, -1, -1, 4, -1, -1, 6, -1, 0, 10, -1, 1, 6, -1, 1, 4, -1, 1, 2, -1])
def randomizebound(lowerbound, uperbound):
RiDisplay("circle.tiff", "framebuffer", "rgb")
RiProjection("perspective", "fov", 110)
RiTranslate(0, 0, 50)
while(n < div):
RiTranslate(x+xrand, y+yrand, 0)
while(n < div):
matrix = [[-6, 0 ,0],
RiBasis("bezier", 3, "bezier", 3)
RiCurves("cubic", , "nonperiodic", "P", matrix, "constantwidth",0.8)
while(n < numdiv):
while(n < numdiv):
while(n < numdiv):
if(number>0) and (number <1):
if(number>1) and (number <2):
if (number >2) and (number <3):