ImageRef Scene::parallelRaytrace(CameraRef camera, RenderOption option) { Rect leftRect(0.0f, 0.0f, camera->width(), floor(camera->height() / 2.0f)); Rect rightRect(0.0f, leftRect.maxY(), camera->width(), camera->height() - leftRect.size.height); p1.scene = this; p1.camera = camera; p1.rect = leftRect; p1.option = option; p1.image = new Image(leftRect.size.width, leftRect.size.height); p2.scene = this; p2.camera = camera; p2.rect = rightRect; p2.option = option; p2.image = new Image(rightRect.size.width, rightRect.size.height); pthread_t thread1, thread2; int iret1, iret2; std::cout << this; iret1 = pthread_create(&thread1, NULL, raytraceThread, &p1); iret2 = pthread_create(&thread2, NULL, raytraceThread, &p2); pthread_join(thread1, NULL); pthread_join(thread2, NULL); ImageRef image = new Image(camera->width(), camera->height()); image->drawImageAtPoint(p1.image, p1.rect.origin); image->drawImageAtPoint(p2.image, p2.rect.origin); delete p1.image; delete p2.image; return image; }
ImageRef Scene::raytrace(CameraRef camera, RenderOption option) { Rect rect(0.0f, 0.0f, camera->width(), camera->height()); ImageRef image = new Image(rect.size.width, rect.size.height); raytrace(camera, Rect(0.0f, 0.0f, camera->width(), camera->height()), option, image); return image; }
ImageRef Scene::rasterize(CameraRef camera) { ImageRef image = new Image(camera->width(), camera->height()); for (unsigned int y = 0; y < camera->height(); y++) { for (unsigned int x = 0; x < camera->width(); x++) { float xPos = (float)x / (float) camera->width() - 0.5f; float yPos = (float)y / (float) camera->height() - 0.5f; Ray viewRay = camera->viewRay(xPos, yPos); HitInfo hitInfo; if (m_rootGroup->hit(viewRay, &hitInfo)) { image->setPixelColor(x, y, hitInfo.material->color()); } } } return image; }
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()); } } } }