Add ray count and duration stats

This commit is contained in:
Eryn Wells 2013-09-12 09:10:22 -07:00
parent a3bdc01d45
commit cc126a153e
2 changed files with 15 additions and 0 deletions

View file

@ -5,6 +5,7 @@
* Eryn Wells <eryn@erynwells.me>
*/
#include <chrono>
#include <cmath>
#include <cstdio>
@ -18,6 +19,7 @@
Scene::Scene()
: width(640), height(480),
max_depth(5),
nrays(0),
pixels(NULL)
{ }
@ -93,6 +95,9 @@ Scene::write(Writer &writer, const std::string &filename)
void
Scene::render()
{
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
pixels = new Color[width * height];
Ray primary_ray;
@ -109,7 +114,11 @@ Scene::render()
}
}
end = std::chrono::system_clock::now();
std::chrono::duration<float> seconds = end - start;
_is_rendered = true;
printf("Scene rendered. %d rays traced in %f seconds.\n", nrays, seconds.count());
}
@ -150,6 +159,9 @@ Scene::trace_ray(const Ray &ray, const int depth)
float nearest_t = INFINITY;
int nints;
// Keep stats.
nrays++;
// Find intersections of this ray with objects in the scene.
for (Shape *s : shapes) {
nints = s->does_intersect(ray, &t);

View file

@ -52,6 +52,9 @@ private:
std::list<Shape *> shapes;
std::list<Light *> lights;
// Rendering stats
unsigned int nrays;
// Rendering output.
bool _is_rendered;
Color *pixels;