Thursday, January 8, 2015

Image Plane Setup

With the help of Image plane setup we calculate the direction of ray i.e. (s - e) in ray equation. For calculating ray direction we need to find the center of pixels on image plane. We determine the pixel centers with the below calculation
Given:
1. Aspect ratio (aspect ratio = W / H)
2. Distance between image plane and eye (camera)
3. Angle Q shown in the figure
Calculate:
Tan(Q/2) = (H/2)/d = H/2d ---1
With the help of 1 we can derive the height of Image plane (H)
H = 2d * Tan(Q/2) ---2
With the help of 2 and given aspect ratio we can derive width of image plane
aspect ration = W / H
W = H * aspect ratio ---3
Now we want to know the position of center (C) of image plane
C = e - n * d ---4
Here e = eye or camera position
     n = vector that we calculated from eye coordinate system
     d = distance between image plane and eye or camera
With the help of 4 we can find the image plane left most bottom corner (L)
L = C - W/2 - H/2 ---5
Assume Image Plane has resolution x and y. We know the height (H) and width (W) of image plane. With these we can easily find out the height and width of pixel i.e. pixel height and pixel width

Pixel Height = H / y
Pixel Width = W / x
With the help of above calculations we can determine the location of center of pixels on image plane using two for loops.

Pixel center = L + (u * i * pixel width) + (v * j * pixel height)
Here u = vector along x direction, we calculated in eye coordinate system
v = vector along y direction, we calculated in eye coordinate system
i, j = looping variable
Code for calculating Direction is:
for(int i=y-1;i >= 0;i--){
    for(int j=0;j < x;j++){
 pixelCenterCordinate = L + (pixelWidth) * (j) * u + (pixelHeight) * (i) * v ;
 rayDirection = pixelCenterCordinate - rayStart ;
 rayDirection.normalize();
        ...........
    }
}
Here rayStart = eye or camera position

Note: Never forget to normalize a direction!!

No comments:

Post a Comment