Ray Tracing - CUDA

Ray Tracing Algorithm:

The ray-tracing is a technique that generates image by parsing through each pixel on the screen and calculating color of each pixel on screen. Hence, for each pixel a ray is shot into the scene. The direction of ray is the line tracing from the eye to the center of the pixel. Using the ray Origin and ray direction, we perform various intersection tests to check if the ray intersects any object in the scene. In some scenarios, the ray will intersect more than one object. So, we select the intersection point which is closest to the eye i.e. origin of the ray. Also, we shoot another ray from the intersection point towards the light. If this ray does not intersect with any object on its way to the light, the hit point is illuminated with the color of the light multiplied by material color of the object. If it does intersect with another object, then that pixel of object comes under shadow.


for (int j = 0; j < imageresoultion.y; j++)
       for (int i = 0; i < imageresoultion.x; i++) {
              // compute ray direction
                  Ray r;
                  computeRayDir(i, j, &primRay);
                  vec3 color=vec3(0.0,0.0,0.0);
               // shoot prim ray in the scene and trace it for intersectionpoint
                //apply pixel color to image
                   output(xpix, ypix)->Red =  (int)(color[0]*255);
                   output(xpix, ypix)->Green =(int)( color[1]*255);
                    output(xpix, ypix)->Blue =  (int) (color[2]*255);


First image with CUDA implementation of ray tracing algorithm, with no lighting.

No comments:

Post a Comment