Monday, 9 September 2013

?: ternary opertor

?: in programming language is a ternary operator. In a nutshell it means:

condition ? value_if_true : value_if_false

use in the min and max function in C:

float min(float a, float b)
{
       return (a<b?a:b);
}

float max(float a, float b)
{
      return (a<b?b:a);
}

Sunday, 8 September 2013

faceforward

Definition from RSL documentation:

vector faceforward(vector N, I [,Nref = Ng])
{
          return sign(-I.Nref) * N;
}

This function is taking I, the incident ray from camera to the shading point, inverse it so that the ray direction is from the shading point back to camera. Then perform a dot product with Ng (surface geometric normal). Any shading point that is facing away from the camera view (the green lines on the image) will have the dot product to return a negative value. The sign function simply return -1 if the dot product calculation returns a negative value. If it is a positive value, the sign function will return positive 1.  Multiply again with the input N, (surface shading normal), the faceforward function eventually return a normal vector that is in negative value if it is facing away from camera.




















Sunday, 1 September 2013

Texture Spaces

Current space
- is the one in which shading calculations are normally done. In most renderers,currentspace will turn out to be either cameraspace or worldspace, but you shouldn’t depend on this.

World Space
- is the coordinate system in which the overall layout of your scene is defined. It is the starting point for all other spaces.

Object Space
- is the one in which the surface being shaded was defined. For instance, if the shader is shading a sphere, theobjectspace of the sphere is the coordinate system that was in effect when theRiSpherecall was made to create the sphere. Note that an object made up of several surfaces all using the same shader might have different object spaces for each of the surfaces if there are geometric transformations between the surfaces.

Shader Space
-  is the coordinate system that existed when the shader was invoked (e.g., by anRiSurfacecall). This is a very useful space because it can be attached to a user-defined collection of surfaces at an appropriate point in the hierarchy of the geometric model so that all of the related surfaces share the sameshaderspace.

Cross Product

When performing a cross product operation, the result will be a vector that is perpendicular to both supplied vectors with a length equal to the area of the parallelogram they span.

The most common use for this operation in the computer graphics is to find the rendering normal of surfaces and to find the normal to any given plain in space

Dot Product


Normalize

Formula for normalizing a vector:


Length of a vector










Length of a vector can also be written as square root of dot product v (v.v)