|
Creating Images by Mathematical Formulas and Logical Conditions |
|
|
|
ST Coloration. After several assignments on models, baking and matrix controls of Renderman's setup, we finally get to the gold of Renderman to come. The RSL shading language.
In this assignment, I am required to mimic the effects of at least 4 of the examples below.... as provided by Professor Malcolm using a Renderman Traditional Shader known as the Surface_Constant. It seems the focus would be on generally on creating diffuse patterns using mathmatical algorithm rather than focusing on any form of response to light etc etc. |
|
 |
|
In general, the make up of the RSL language for the Surface_Constant is not too complex. It generally consists of a Color and a Opacity output into the Renderman engine. |
| |
|
|
|
|
|
|
surface
constant_test(float Kfb = 1) // Variable Declarations
{
color surfcolor = 1; // Event or Logic Code Space
Oi = Os; // Result for Opacity
Ci = Oi * Cs * surfcolor * Kfb; // Result for Coloration
}
|
|
|
|
|
|
|
| |
It is a very simple and common structure commonly known to most programming languages and very C or C++ like. Where the parameters or memory limits are first declared. The program then takes references from such declared parameters to conclude any mathematical or event based coding. This code is then finalized and outputted through the standard Oi and Ci coding at the end for Opacity and Color Respectively.
One difference noted is that the variables will be fixed unless placed within the first section of the coding under the constant_test() sections. This will open up attribute holders in Houdini or Maya for more customization to the shaders. This however will be less important in this assigment as I will be mainly completing it entirely in Maya.
To first begin, I must of course first understand Renderman's interpretation of UV / XY space. This, will come in the forms of S and T. Where S represents the X axial of a graph and T represents the negative Y axial of a graph.
I am using the terms of a rather instead due to the mathematical curves I will be programming on. To better represent, please note the rough Sin wave that I have drawn out below.. which represents the math graphs places on an isometric view. |
|
 |
|
| |
|
| |
So lets start with the first one.... |
| |
 |
| |
Not too hard I would say. Knowing for a fact that the space I have on the plane is an absolute value of 0 to 1 on both S and T axis, it is merely a simple rule of isolating the areas for different color shadings. As I had wanted to more visibly see the shape of the "Plus" sign, I have decided that I want my "special colors" to be applied in the constraints of both 0.25 and 0.75 for S and T. Details on my special shader colors, I will elaborate later.
So for the 2nd example, the formular becomes slightly different. Considering that earlier I was creating it based merely on 1 axis. Now I have to rely on 2 of them to get the box that I need. But it doesnt make it any harder. I simply had to change the rules from 2 values to four by combing the earlier S conditions and T conditions of the "IF" coding into one... |
| |
 |
| |
Now onto the next one. This one isnt so hard either. Its a triangulation formula. By drawing a line 45 degrees to both X and Y axis we know that X will always equate Y... This formula tells us that if either X or Y were to differ by a slight amount, the "line" will be off its 45 degrees course.
And thus, this gives us the below formula for finding the diagonal range. |
| |
 |
| |
Hmmm, I pretty much got what I wanted, but looking back I realise something different about the example compared to the one I have... thats when I realise that this may have been a negative value line instead. So I then proceeded to invert the value and assign a origin shift on it.... |
| |
 |
| |
And on to the next... This one will probably be somewhat tougher as it is a curved quadrant. However, it is easier to look upon it as a curved graph. I have also noted that many are using a formula where by S <= T * T...
I would say however, while that gives a curve, it is not a quadrant but an exponentially increasing curve. To make a perfect circle how ever will require either a factorized formula where the code continually tests for the radius of the the circle from the point of origin. How do we do that?
According to Pythagoras' theorem, a^2 = b^2 + c^2. This formula links the relationship of the all linear equation in a right angle triangle where a represents the longest measuring edge of the triangle. Knowing that the perfect 45 degree diagonal length is 100% the longest measuring distance of a box. It is what we will use to represent both a and also the radius of the circle. Of course, the radius can also be represented by either b or c, but the formula would still be no different otherwise.
Thus. Should a point on the plane be tested, it will be asked this.... if your S and T axis under the Pythagoras' theorem in the sense of radius^2 = S^2 + T^2 returns a radius value of lesser then 1, test true else false. |
| |
 |
| |
Next we have the perfect circle... By shifting the mathematical origin in the same Pythagoras' theorem, we can use the same rules to test for the radius of the circle. To do this, we simply compensate the differences in the S and T values from its orgin by subtracting that value from the tested point... |
| |
 |
| |
Similarly, using the exact same coding, I have added a second logical test parameter to create the crescent (circle over circle) |
| |
 |
| |
And next, we have a curved like value. Hmmm theres no definite representation of such a curve as it can be easily a cos or sin curve or simply a square function. So in this case ... I shall be using the square function instead. My reasons -- I do not wish to be over reliant on cos and sin curves this early on methods achievable by other means.
So~ similarly like the earlier compensation of origin I am going to change the squared formula from S^2 to (S- change in origin)^2.
The final formula should be in this format T <= negative value of (S - change in origin)^2 * Intensity of the Curve + Compensation of differences in the T axis. |
| |
 |
| |
Next we come to the commonly seen sin curves... Where the rules SIN (Direction & Frenquency) * Amplitude + Origin Shifts/Compensation. |
| |
 |
| |
And lastly, we have the oval~
Of course, Oval is just a layman's term. The actual object we are looking at is called an Elipse or an Oblate surface. The math formula for this is similar to that of the circle's formula via Pythagoras' theorem... however to maintain the formulas for an oblate irregular oval, a different set of values needs to be divided onto the original coordinate. These coordinate are also know as the aspect ratio. |
| |
 |
| |
Of course, it is understandable that the formula may be confusing.... To simply put, an Elipse is an irregular circle where one axis tends to be more elongated than the other. This is what we term "Aspect". The circle can be 2 times wider on its X axis than its Y. This makes the aspect 2:1 respectively. This aspect is divided onto the X and Y distances to maintain that ratio which makes a circle an elipse...
So after all these exercises, below are the complication of all my completed shapes |
| |
 |
| |
References :
The Equation of a Circle
The Equation of an Elipse
The Pythagorean Theorem
Function Grapher and Calculator |
| |
|