shared_ptr<Image> RayTracer::render (const Settings& settings, const LightingEnvironment& lighting, const shared_ptr<Camera>& camera, Stats& stats) { RealTime start; debugAssert(notNull(camera)); if (m_settings.photon != settings.photon) { // Photon settings changed; reset the photon map m_photonMapUpdateTime = 0; } m_camera = camera; m_lighting = lighting; m_settings = settings; maybeUpdateTree(); maybeUpdatePhotonMap(); app->drawMessage("Tracing Backward Rays"); stats.buildTriTreeTimeMilliseconds = (float)m_buildTriTreeTimeMilliseconds; stats.photonTraceTimeMilliseconds = (float)m_photonTraceTimeMilliseconds; stats.buildPhotonMapTimeMilliseconds = (float)m_buildPhotonMapTimeMilliseconds; // Allocate the image m_image = Image::create(settings.width, settings.height, ImageFormat::RGB32F()); // Render the image start = System::time(); const int numThreads = settings.multithreaded ? GThread::NUM_CORES : 1; traceAllPixels(numThreads); stats.rayTraceTimeMilliseconds = float((System::time() - start) / units::milliseconds()); shared_ptr<Image> temp(m_image); stats.lights = m_lighting.lightArray.size(); stats.pixels = settings.width * settings.height; stats.triangles = m_triTree.size(); stats.storedPhotons = m_photonMap.size(); // Reset pointers to NULL to allow garbage collection m_camera.reset(); m_image.reset(); return temp; }
shared_ptr<Image> RayTracer::render(const Settings& settings, const Array< shared_ptr<Surface> >& surfaceArray, const shared_ptr<LightingEnvironment>& lighting, const shared_ptr<Camera>& camera, Stats& stats) { RealTime start; debugAssert(notNull(lighting) && notNull(camera)); // store member copies of the arguments // so that they can propagate inside the callbacks m_settings = settings; m_lighting = lighting; m_camera = camera; m_stats = &stats; stats.indirectRays = 0; stats.shadowRays = 0; // Build the TriTree start = System::time(); m_triTree.setContents(surfaceArray); stats.buildTriTreeTimeMilliseconds = float((System::time() - start) / units::milliseconds()); // Allocate the image m_image = Image::create(settings.width, settings.height, ImageFormat::RGB32F()); // Create Photon Map if (m_settings.enablePhotonMapping){ start = System::time(); createPhotonMap(); stats.buildPhotonMapMilliseconds = float((System::time() - start) / units::milliseconds()); stats.photonMapSize = photons.size(); } // Render the image start = System::time(); const int numThreads = settings.multithreaded ? GThread::NUM_CORES : 1; traceAllPixels(numThreads); stats.rayTraceTimeMilliseconds = float((System::time() - start) / units::milliseconds()); // Fill out other stats stats.triangles = m_triTree.size(); stats.pixels = settings.width * settings.height; stats.lights = lighting->lightArray.size(); stats.primaryRays = stats.pixels * settings.raysPerPixel; stats.totalRays = stats.primaryRays + stats.indirectRays + stats.shadowRays; shared_ptr<Image> temp(m_image); m_triTree.clear(); photons.clear(); // Reset pointers to NULL to allow garbage collection m_lighting.reset(); m_camera.reset(); m_image.reset(); return temp; }