Tuesday, July 05, 2011

Certification - I have started seeing some Value In It.

As most professionals reach mid life career crisis , they resort to a new hobby. They collect certifications like ITIL,PMP,TOGAF,CISA etc. to name a few.

Most people use it to get their way into higher position.

These certifications are catalog of best practices in a domain. They cannot be understood fully , unless you have become a practitioner in all aspects of a domain. In the era of specialization , It hard for a single professional to master the nuances of best practices in a objective manner.

People go for certification to motivate themselves to study these "dogmas" and examination fee acts as a deterrent from choking away from the pursuit.

At the end of the day , the Individual will emerge home with some Ideas for sure. For me , that is the key take away.

To learn procedural skills , one needs to be lucky or go for certification. ( This is akin to teaching management at a B-school.)

GPU Programming














The importance of writing small gpu programs has its highest need these days.
The following is the result of my battle with shader designer for my pet project Rubiks cube with minimum data in to the gpu.


//vertex program
//mapping of colors on to object based on the vertex normals

varying vec3 color;

void main()
{
if( abs(gl_Normal.x) > 0.5 )
{

if(sign(gl_Normal.x) == 1)
{
color.rgb = vec3(1.0, 0.55, 0.0); //orange;
}
else
{
color.rgb = vec3(0.0,0.9, 0.0); //green
}
}
else if( abs(gl_Normal.y) > 0.5 )
{
if(sign(gl_Normal.y) == 1)
{
color.rgb = vec3(1, 0, 0); //red
}
else
{
color.rgb = vec3(0, 0, 0.8);//blue;
}
}
else if( abs(gl_Normal.z) > 0.5 )
{
if(sign(gl_Normal.z) == 1)
{
color.rgb = vec3(1, 1, 1);//white
}
else
{
color.rgb = vec3(1, 1, 0);//yellow
}
}
gl_Position = ftransform();
}

//Fragment program
varying vec3 vcolor;

void main()
{
gl_FragColor = vec4( vcolor, 1);
}


//[todo:more text in this post]

Thursday, June 23, 2011

Meshes

3D Models are made up of vertices that can form drawing primitives.
Thus conceptually a mesh can be defined by a set of vertices and a set of indices.
Vertices have information for position, color, lighting etc.
And indices group those vertices into drawing primitives.


//A simple vertex
Vertex
{
position,
normal,
texture

};
VertexArray[] = {...} //What are the vertices that form the model
IndexArray[] = {...} //What is the order of the vertices that form the drawing primitive

Where
drawing primitive = {point, line, triangle, ... }

Now we can.

Strem the mesh data between graphics card memory and system memory.
Define local axes,angles, axial and object bounding volumes.
Connect the mesh with a scene graph system.
Connect the mesh with a phsics system.
Apply transforms on meshes to make simple animations;
Register a bone hierarchy suitable to the mesh with transforms and weights.
Chain a list of morph targets.
Chain a list of meshes with decreasing level of detail.
Add a list of vertex/fragment shaders.
Change the state of rendering/animation with game/graphics events.

and so on.

All of this start from how to render the vertices with less space and in minimum time.

Ref:
OpenGL : begin .. end paradigm, vertex arrays, VBO

For commercial file formats refer
3D File formats: Obj, 3DS, PVR, X

Sunday, May 24, 2009

Camera

The following is a common camera definition in games which helps to make view transform and projection transform.

Camera
{
//tripod and aim
ViewerPosition,
ViewerTarget,
ViewerTilt,
LocalAxesIJK,
RotationAnglesAroundLocalAxesPitchYawRoll,

//lens
aspectRatio,
nearPlane,
farPlane;
}

Animation

Definition
Animation is realistically affecting any visual change in a scene with respect to time. The variables may include position, size, orientation, color, transparency or surface texture of the graphics object. "It is all about timing and positioning"
Frame Animation
Normally 30 to 60 frames of a 3D scene is to be rendered per second for a convincing animation. Although game engines usually expose a setFrameRate() interface for controlling frame rate, the efffective framerate depends on the scene complexity.
Character Animation
It deals with creating the moving pictures of the actors in the scene. In game development, it is done using two techniques: - Morph animation and Skelton animation.
In skeletal animation, a character is represented in two parts: a surface representation (skin) used to draw the character and a hierarchical set of bones used for animation only. By using skeletal animation one can control of every joint, bone, and muscle of the character's body to alter the shape of its skin.
Morphing is the transformation of one shape to another using some kind of interpolation. It is the kind of animation used for modeling character's expressions and lip synchronization.
Every type of animation requires key frames. Pre calculated key frames add the realism of character animation. 3D artists work with models using packages such as Maya or use motion capture for this purpose. Simulation of rigid body is not enough for certain situations. Descriptions of object behavior under the influence of force are generally referred to as physics based modeling. Some examples for these objects are cloths, ropes, soft bodies etc.

Collision Handling

Collision handling is the next important thing after rendering.
Steps:
1. Detect whether two objects collide
This is achieved through standard and AABB or OBB intersection test using computational geometry algorithms.
Space subdivision methods coupled with occlusion culling reduce the amount of checking.

2.Determine where the collision point.
Once the the collision is detected, the relative location of the collision point with respect the center of mass from each objects need to be taken into account.

3.Implementing the expected the result of the collision
Rigid bodies collide and respond to collisions obeying the laws of Newton.

Curves and Surfaces

Curves and curved surfaces describe most commonly the non-planar geometry with mathematical expressions rather than a mesh. These expressions can be converted to mesh representation on the fly. Thus, it saves some amount vertex memory. In addition, curved geometry provides scalable, smoother and continuous primitives than straight lines and planar polygons.

Reflection

Planar reflection follows the law of reflection and works reasonably fast.
Ray tracing is the solution for high quality reflection mapping but it may not work at real time. Environment mapping is a fast technique that simulates highly reflective surfaces.

Transparency

A transparent surfaces in general produce both reflected and refracted light.
It is assumed that for simple transmittance, the incoming light comes from directly beyond the transmitter. This is a reasonable assumption when the front and back surfaces of the transmitter are parallel and the thickness is not great, e.g., for a pane of glass. A transparent surface can be treated as a blend color. When blending, the transmitter's color is mixed with the incoming color from the objects seen through the transmitter. For other transparent media, the refractive index by Snell's law plays a role.

Shadows

The keywords in shadowing process are light sources, shadow casters and shadow receivers. The light source can be a point source or area source. Calculating the shadow for point sources is easier compared that for area sources.
Point light sources generate only fully shadowed regions, while area light sources produce a fully shadowed region (umbra), and a partially shadowed region (penumbra).
Fully shadowed regions are called hard shadows and partially shadowed region are called soft shadows.
A basic technique for shadowing is projected planar shadows.

It is a simple technique. First, a three points are chosen so that the triangle formed by them defines the projection plane. The four plane coefficients are calculated from the three points that define the projection plane. Light position vector and these coefficients are used to pack a matrix called shadow matrix. This matrix squishes the 3D object on to the plane. To render the shadow, this matrix is applied to the objects that should cast shadow and the objects are rendered in dark color with no lighting. In this scheme, the three-dimensional object is rendered in two passes to create a shadow. In the first pass, the scene is rendered normally with lighting and depth test switched on. Then in the second pass, the depth test is disabled to deal with the z fighting between the shadow and the projection plane. While depth testing is disabled, the things that render last lie on top. The shadow receiver is already drawn in the pass. To cast the shadow, the shadow matrix is applied as described early.

Some other techniques are:
Projected Shadows
Shadow Mapping
Vertex Projection
Shadow Volumes