diff --git a/CMakeLists.txt b/CMakeLists.txt index cb4ba4b..724e18b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,11 +12,17 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/external/covera option(PACKAGE_TESTS "Build the tests" ON) option(ENABLE_COVERAGE "Build for code coverage" OFF) -option(SHOW_STATS "Show rendering stat" ON) +option(SHOW_STATS "Show rendering stat" OFF) if (SHOW_STATS) add_compile_options(-DRENDER_STATS) endif() +option(USE_GPROF "Enable profiling" OFF) +if (USE_GPROF) + add_compile_options(-pg) + add_link_options(-pg) +endif() + option(USE_LUA "Enable the use of Lua" ON) if (USE_LUA) add_compile_options(-DENABLE_LUA_SUPPORT) diff --git a/source/camera.cpp b/source/camera.cpp index 0f0170e..5b97421 100644 --- a/source/camera.cpp +++ b/source/camera.cpp @@ -54,6 +54,7 @@ Ray Camera::rayForPixel(uint32_t pixelX, uint32_t pixelY) Tuple origin = this->inverseTransform * Point(0, 0, 0); Tuple direction = (pixel - origin).normalise(); + stats.addCastedRay(); return Ray(origin, direction); } diff --git a/source/include/renderstat.h b/source/include/renderstat.h index e9df33c..eea618b 100644 --- a/source/include/renderstat.h +++ b/source/include/renderstat.h @@ -27,7 +27,8 @@ private: uint64_t csgCount; /* Total number of CSG */ uint64_t pixelCount; /* Total number of rendered pixels */ - uint64_t rayCount; /* Total number of rays */ + uint64_t rayCount; /* Total number of rays object created */ + uint64_t rayCasted; /* Total number of rays actually casted */ uint64_t lightRayEmitedCount; /* Total number of ray launched for light tests */ uint64_t reflectionRayCount; /* Total number of reflection ray launched */ uint64_t refractedRayCount; /* Total number of refracted ray launched */ @@ -43,7 +44,8 @@ public: RenderStats() : coneCount(0), cylinderCount(0), cubeCount(0), groupCount(0), lightCount(0), planeCount(0), sphereCount(0), triangleCount(0), pixelCount(0), rayCount(0), lightRayEmitedCount(0), reflectionRayCount(0), refractedRayCount(0), intersectCount(0), intersectionCount(0), reallocCallCount(0), mallocCallCount(0), smoothTriangleCount(0), - discardedIntersectCount(0), maxDepthAttained(UINT64_MAX), maxIntersectOnARay(0), objfileCount(0), csgCount(0) {}; + discardedIntersectCount(0), maxDepthAttained(UINT64_MAX), maxIntersectOnARay(0), objfileCount(0), + csgCount(0), rayCasted(0) {}; #ifdef RENDER_STATS void addCone(); void addCylinder(); @@ -59,6 +61,7 @@ public: void printStats(); void addPixel(); void addRay(); + void addCastedRay(); void addLightRay(); void addReflectRay(); void addRefractRay(); @@ -82,6 +85,7 @@ public: static void printStats() {}; static void addPixel() {}; static void addRay() {}; + static void addCastedRay() {}; static void addLightRay() {}; static void addReflectRay() {}; static void addRefractRay() {}; diff --git a/source/include/shape.h b/source/include/shape.h index 86ae7ad..4b97993 100644 --- a/source/include/shape.h +++ b/source/include/shape.h @@ -65,7 +65,7 @@ public: ShapeType getType() { return this->type; }; - virtual void intersect(Ray &r, Intersect &xs); + virtual void intersect(Ray &r, Intersect &xs) { this->localIntersect(this->invTransform(r), xs); }; Tuple normalAt(Tuple point, Intersection *hit = nullptr); uint64_t getObjectId() { return this->objectId; }; diff --git a/source/renderstat.cpp b/source/renderstat.cpp index 7bd487f..fb7ce15 100644 --- a/source/renderstat.cpp +++ b/source/renderstat.cpp @@ -85,20 +85,32 @@ void RenderStats::addRay() this->rayCount++; }; +void RenderStats::addCastedRay() +{ +#pragma omp atomic + this->rayCasted++; +}; + void RenderStats::addLightRay() { + this->addCastedRay(); + #pragma omp atomic this->lightRayEmitedCount++; }; void RenderStats::addReflectRay() { + this->addCastedRay(); + #pragma omp atomic this->reflectionRayCount++; }; void RenderStats::addRefractRay() { + this->addCastedRay(); + #pragma omp atomic this->refractedRayCount++; }; @@ -172,7 +184,8 @@ void RenderStats::printStats() printf("CSG : %lld\n", this->csgCount); printf("==================================================\n"); printf("Pixel rendered : %lld\n", this->pixelCount); - printf("Ray casted : %lld\n", this->rayCount); + printf("Ray created : %lld\n", this->rayCount); + printf("Ray casted : %lld\n", this->rayCasted); printf("Light Ray casted : %lld\n", this->lightRayEmitedCount); printf("Reflection ray casted : %lld\n", this->reflectionRayCount); printf("Refraction ray casted : %lld\n", this->refractedRayCount); diff --git a/source/shapes/shape.cpp b/source/shapes/shape.cpp index 5d4b9cd..a93ab2b 100644 --- a/source/shapes/shape.cpp +++ b/source/shapes/shape.cpp @@ -36,12 +36,6 @@ uint64_t Shape::newObjectId() return ret; } - -void Shape::intersect(Ray &r, Intersect &xs) -{ - this->localIntersect(this->invTransform(r), xs); -}; - Tuple Shape::normalToWorld(Tuple normalVector) { Tuple world_normal = this->transposedInverseTransform * normalVector; diff --git a/tests/christmasball_render.cpp b/tests/christmasball_render.cpp index 908627d..f4cdd27 100644 --- a/tests/christmasball_render.cpp +++ b/tests/christmasball_render.cpp @@ -229,13 +229,14 @@ int main() w.addObject(s); /* ----------------------------- */ - + /* FILE *fpOut = fopen("christmas_worlddump.json", "wt"); if (fpOut) { w.dumpMe(fpOut); fclose(fpOut); } + */ /* ----------------------------- */ diff --git a/tests/dragon_scene.cpp b/tests/dragon_scene.cpp index 03ddd73..7014e62 100644 --- a/tests/dragon_scene.cpp +++ b/tests/dragon_scene.cpp @@ -117,14 +117,7 @@ int main() w.addObject(dragon); /* ----------------------------- */ -/* - FILE *fpOut = fopen("dragon_worlddump.json", "wt"); - if (fpOut) - { - w.dumpMe(fpOut); - fclose(fpOut); - } -*/ + OctreeOptimisation opt; w.finalise(opt);