KEMBAR78
Maths&programming forartists wip | PDF
Understanding Maths and Programming
for
CG Artists
BY
M KEDARNATH
M_kedar_nath@yahoo.com
Programming and scripting
Maths
CG requirements
Connecting the above
Note :
The syntax used in this notes may not be accurate and directly usable. To write script
please refer to help file of the software. Also here I am not concentrating on any
programming or scripting language like MEL, Python, VEX (Houdini), Lua etc but focusing on
the base of it.
I am not a professional programmer so there can be better or optimized way of doing
the tasks which I have done in this notes. This is mainly to understanding how to connect
Maths and programming to create what we want in CG. Also once we understand the
concepts then it is almost same in different scripting/ programming languages except the
syntax.
Programming and scripting
• Frame work
• Pipeline programming
• Understanding software scripting language and SDK
• Automation
◦ Script to add render layers
◦ Script to adjust cloth sim
• Expanding the capability of the software
◦ Creating plugins
• Creating new CG software
Maths
• simple mathematics equation
◦ Trigonometry
• 3D geometry
• Dynamics
CG Requirements
• Lookdev/Shading
• Lighting
• CHF
• Assets etc
Connecting all above
• Understanding equation of a shader
• Understanding an equation of rendering and render a sphere color
Few terminologies to understand
Design – what you are going to do is called Design of a software
Architecture – Is a design which tells us how we are going to connect the different parts of
the program.
Framework – A programming framework is a structure (or implementation of the
Architecture) which defines or makes the software development part easier and faster.
API – Application programming interface – is a set of functionalities or classes which can be
used to extend the capabilities of the software.
SDK – software development kit is a set of tools used to develop applications.
Understanding programming for Artists
Pipeline programming
Pipeline programming can be anything from folder creation to automatic data transfer to
software integration using single desktop application.
WIP
Few free pipeline tools available -
Prism -
There is a free animation pipeline to combine all tools - Prism manages your complete
workflow from the initial project setup to managing scenefiles to comparing renderings and
composit them to create the final images.
Prism includes many different features to automate your workflow
https://prism-pipeline.com/
Flamenco -
It is a free and opensource render farm management sotware
https://www.flamenco.io/
CGRU
Free and open source CG tool pack
http://cgru.info/
Automation/software workflow
We can do different types of automation using scripting. In any production software like
Maya, Nuke, Houdini, Mari etc., we can create own shelf and call different scripts from
different departments.
• We can create different types of scripts/Procedures to do procedural modeling.
• Automate the process of exporting the data and saving with standard naming
structure and folder structure.
• Nuke
◦ We can create own write nodes with shot specific folder structure included by
default.
◦ Create a script to automate the compositing template.
◦ Etc
• Maya
◦ Create a script with all the render settings put in one UI.
◦ Setting for different render types like preview/high quality, through which control
the texture size, AOVs to render, LOD of model etc.
Scripting And Programming
Scripting doesn't require an explicit compilation step. As an example MEL or Python in
Maya doesnt need any specific compilation before running. We can directly run that inside
Maya. But while creating plugins in C++, we need to compile the program as .mll file and load
through plugin manager.
Lets understand to combine math formulas with programming to get the output.
WIP
Trigonometry –
Trigonometry is a branch of mathematics which deals with angles and the angular
relationships of planar and 3D figures.
Value of sin(theta) – ranges from -1 to 1 based on the angle.
If we need to increase the frequency then we need to use
sin(a * theta) (where a is a constant).
Similarly if we need to increase the value from 1 then we need to use
a * sin(theta) (where a is a constant)
Value of cos(theta) – similarly value of cos(theta) is also ranges from -1 to 1 based on angle
We can use same multiplication as sin(theta) to increase the feequency.
Lets use these above formula to create some animation using expressions in Maya.
pSphere1.translateX = sin(frame) ( frame number can be used as theta)
pSphere1.translateX = sin(frame/5) (to make the animation 5 times slower)
pSphere1.translateX = 5* sin(frame) (to move the sphere to 5 times distance)
We can combine sin and cos values in translateX and translateY to animation the sphere in
circular direction.
Use the below expressions in translateX and translateY to move the sphere in circular (x,y)
direction.
pSphere1.translateX = 5*(sin(frame/15))
pSphere1.translatey = 5*(cos(frame/15))
If we want to move the object in constant value then we can use “frame” without any
trigonometric functions.
Use the below expression in translateZ along with above X and y to move the sphere in
circular direction and towards z, like spring.
pSphere1.translateZ = frame/10
The same way trigonometry can be used to create spheres and place them in a circular path.
Here we defined the number of spheres within 360 degrees and place them in equal distance.
Also if we need to create spring type of formation then we can use z value which is
incremental. Either we can use $i or we cab define any new number and do the increment in
the loop.
//
int $theta, $i;
int $number = 20;
int $step = 360/$number;
for ($i==0; $i<$number; $i++)
{
int $theta = $i*$step;
float $x = 5*sin(deg_to_rad($theta));
float $y = 5*cos(deg_to_rad($theta));
polySphere;
move $x $y 0;
}
//
To understand the values we can directly write the functions and get the value. Based on the
formulas we can write our own scripts to create what ever we want.
sin(deg_to_rad(90)); //which will give us value 1 as output.
Similarly we can try using other functions in our scripts and expressions.
Matrices
Matrices is a collection of numbers arranged in rows and columns ,
A matrix of m rows and n columns is called a m x n matrix (m by n), where m and n are
matrix dimensions.
In CG what can be defined in a matrix –
• A color is 1 x 3 matrix
• Translate or rotation or scale are 1 x 3 matrix ( we can use these in our
scripting or expressions.
• In CG usually the whole transformation defined in 4 x 4 matrix.
WIP
Vector Mathematics
A vector represents a quantity that has both magnitude and direction.
Below is the example of setting color value using vector.
vector $col = << 1, 0, 0>>;
setAttr "lambert2.color" ($col.x) ($col.y) ($col.z);
WIP

Maths&programming forartists wip

  • 1.
    Understanding Maths andProgramming for CG Artists BY M KEDARNATH M_kedar_nath@yahoo.com
  • 2.
    Programming and scripting Maths CGrequirements Connecting the above Note : The syntax used in this notes may not be accurate and directly usable. To write script please refer to help file of the software. Also here I am not concentrating on any programming or scripting language like MEL, Python, VEX (Houdini), Lua etc but focusing on the base of it. I am not a professional programmer so there can be better or optimized way of doing the tasks which I have done in this notes. This is mainly to understanding how to connect Maths and programming to create what we want in CG. Also once we understand the concepts then it is almost same in different scripting/ programming languages except the syntax.
  • 3.
    Programming and scripting •Frame work • Pipeline programming • Understanding software scripting language and SDK • Automation ◦ Script to add render layers ◦ Script to adjust cloth sim • Expanding the capability of the software ◦ Creating plugins • Creating new CG software Maths • simple mathematics equation ◦ Trigonometry • 3D geometry • Dynamics CG Requirements • Lookdev/Shading • Lighting • CHF • Assets etc Connecting all above • Understanding equation of a shader • Understanding an equation of rendering and render a sphere color
  • 4.
    Few terminologies tounderstand Design – what you are going to do is called Design of a software Architecture – Is a design which tells us how we are going to connect the different parts of the program. Framework – A programming framework is a structure (or implementation of the Architecture) which defines or makes the software development part easier and faster. API – Application programming interface – is a set of functionalities or classes which can be used to extend the capabilities of the software. SDK – software development kit is a set of tools used to develop applications. Understanding programming for Artists Pipeline programming Pipeline programming can be anything from folder creation to automatic data transfer to software integration using single desktop application. WIP Few free pipeline tools available - Prism - There is a free animation pipeline to combine all tools - Prism manages your complete workflow from the initial project setup to managing scenefiles to comparing renderings and composit them to create the final images. Prism includes many different features to automate your workflow https://prism-pipeline.com/ Flamenco - It is a free and opensource render farm management sotware
  • 5.
    https://www.flamenco.io/ CGRU Free and opensource CG tool pack http://cgru.info/ Automation/software workflow We can do different types of automation using scripting. In any production software like Maya, Nuke, Houdini, Mari etc., we can create own shelf and call different scripts from different departments. • We can create different types of scripts/Procedures to do procedural modeling. • Automate the process of exporting the data and saving with standard naming structure and folder structure. • Nuke ◦ We can create own write nodes with shot specific folder structure included by default. ◦ Create a script to automate the compositing template. ◦ Etc • Maya ◦ Create a script with all the render settings put in one UI. ◦ Setting for different render types like preview/high quality, through which control the texture size, AOVs to render, LOD of model etc. Scripting And Programming Scripting doesn't require an explicit compilation step. As an example MEL or Python in Maya doesnt need any specific compilation before running. We can directly run that inside Maya. But while creating plugins in C++, we need to compile the program as .mll file and load through plugin manager. Lets understand to combine math formulas with programming to get the output. WIP
  • 6.
    Trigonometry – Trigonometry isa branch of mathematics which deals with angles and the angular relationships of planar and 3D figures. Value of sin(theta) – ranges from -1 to 1 based on the angle. If we need to increase the frequency then we need to use sin(a * theta) (where a is a constant). Similarly if we need to increase the value from 1 then we need to use a * sin(theta) (where a is a constant) Value of cos(theta) – similarly value of cos(theta) is also ranges from -1 to 1 based on angle We can use same multiplication as sin(theta) to increase the feequency.
  • 7.
    Lets use theseabove formula to create some animation using expressions in Maya. pSphere1.translateX = sin(frame) ( frame number can be used as theta) pSphere1.translateX = sin(frame/5) (to make the animation 5 times slower) pSphere1.translateX = 5* sin(frame) (to move the sphere to 5 times distance) We can combine sin and cos values in translateX and translateY to animation the sphere in circular direction. Use the below expressions in translateX and translateY to move the sphere in circular (x,y) direction. pSphere1.translateX = 5*(sin(frame/15)) pSphere1.translatey = 5*(cos(frame/15)) If we want to move the object in constant value then we can use “frame” without any trigonometric functions. Use the below expression in translateZ along with above X and y to move the sphere in circular direction and towards z, like spring. pSphere1.translateZ = frame/10 The same way trigonometry can be used to create spheres and place them in a circular path.
  • 8.
    Here we definedthe number of spheres within 360 degrees and place them in equal distance. Also if we need to create spring type of formation then we can use z value which is incremental. Either we can use $i or we cab define any new number and do the increment in the loop. // int $theta, $i; int $number = 20; int $step = 360/$number; for ($i==0; $i<$number; $i++) { int $theta = $i*$step; float $x = 5*sin(deg_to_rad($theta)); float $y = 5*cos(deg_to_rad($theta)); polySphere; move $x $y 0; } // To understand the values we can directly write the functions and get the value. Based on the formulas we can write our own scripts to create what ever we want. sin(deg_to_rad(90)); //which will give us value 1 as output. Similarly we can try using other functions in our scripts and expressions.
  • 9.
    Matrices Matrices is acollection of numbers arranged in rows and columns , A matrix of m rows and n columns is called a m x n matrix (m by n), where m and n are matrix dimensions. In CG what can be defined in a matrix – • A color is 1 x 3 matrix • Translate or rotation or scale are 1 x 3 matrix ( we can use these in our scripting or expressions. • In CG usually the whole transformation defined in 4 x 4 matrix. WIP Vector Mathematics
  • 10.
    A vector representsa quantity that has both magnitude and direction. Below is the example of setting color value using vector. vector $col = << 1, 0, 0>>; setAttr "lambert2.color" ($col.x) ($col.y) ($col.z); WIP