Пример #1
0
 void Scene::raytrace(CameraRef camera, Rect rect, RenderOption option, ImageRef image)
 {
     ASSERT(image->width() == rect.size.width && image->height() == rect.size.height);
     for (unsigned int y = 0; y < rect.size.height; y++) {
         for (unsigned int x = 0; x < rect.size.width; x++) {
             float xPos = (float)(x + rect.origin.x) / (float) camera->width() - 0.5f;
             float yPos = (float)(y + rect.origin.y) / (float) camera->height() - 0.5f;
             Ray viewRay = camera->viewRay(xPos, yPos);
             HitInfo hitInfo;
             Color color;
             
             if (traceRay(viewRay, option, 1.0f, 0, &color, &hitInfo)) {
                 image->setPixelColor(x, y, color);
             } else {
                 // set Background ccolor
                 //image->setPixelColor(x, y, hitInfo.material->color());
             }
             
         }
     }
 }