Add renderstat to get some info about rendering.
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#ifndef DORAYME_BOUNDINGBOX_H
|
||||
#define DORAYME_BOUNDINGBOX_H
|
||||
|
||||
#include <renderstat.h>
|
||||
|
||||
struct BoundingBox
|
||||
{
|
||||
private:
|
||||
@@ -110,9 +112,12 @@ public:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
stats.addDiscardedIntersect();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //DORAYME_BOUNDINGBOX_H
|
||||
#endif /* DORAYME_BOUNDINGBOX_H */
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <shape.h>
|
||||
#include <ray.h>
|
||||
#include <intersect.h>
|
||||
#include <renderstat.h>
|
||||
|
||||
class Cone : public Shape {
|
||||
protected:
|
||||
@@ -27,7 +28,7 @@ public:
|
||||
double minCap;
|
||||
double maxCap;
|
||||
|
||||
Cone() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(SHAPE_CONE) {};
|
||||
Cone() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(SHAPE_CONE) { stats.addCone(); };
|
||||
BoundingBox getBounds();
|
||||
bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); };
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <shape.h>
|
||||
#include <ray.h>
|
||||
#include <intersect.h>
|
||||
#include <renderstat.h>
|
||||
|
||||
class Cube : public Shape {
|
||||
private:
|
||||
@@ -22,7 +23,7 @@ private:
|
||||
Tuple localNormalAt(Tuple point);
|
||||
|
||||
public:
|
||||
Cube() : Shape(SHAPE_CUBE) {};
|
||||
Cube() : Shape(SHAPE_CUBE) { stats.addCube(); };
|
||||
};
|
||||
|
||||
#endif /* DORAYME_CUBE_H */
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <shape.h>
|
||||
#include <ray.h>
|
||||
#include <intersect.h>
|
||||
#include <renderstat.h>
|
||||
|
||||
class Cylinder : public Shape {
|
||||
private:
|
||||
@@ -27,7 +28,7 @@ public:
|
||||
double minCap;
|
||||
double maxCap;
|
||||
|
||||
Cylinder() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(SHAPE_CYLINDER) {};
|
||||
Cylinder() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(SHAPE_CYLINDER) { stats.addCylinder(); };
|
||||
|
||||
BoundingBox getBounds();
|
||||
bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); };
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <ray.h>
|
||||
#include <material.h>
|
||||
#include <renderstat.h>
|
||||
|
||||
class Shape;
|
||||
class Intersect;
|
||||
@@ -74,7 +75,7 @@ public:
|
||||
Shape *object;
|
||||
|
||||
public:
|
||||
Intersection(double t, Shape *object) : t(t), object(object) { };
|
||||
Intersection(double t, Shape *object) : t(t), object(object) { stats.addIntersection(); };
|
||||
bool nothing() { return (this->object == nullptr); };
|
||||
|
||||
Computation prepareComputation(Ray r, Intersect *xs = nullptr);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <tuple.h>
|
||||
#include <colour.h>
|
||||
#include <renderstat.h>
|
||||
|
||||
enum LightType
|
||||
{
|
||||
@@ -26,7 +27,8 @@ public:
|
||||
|
||||
public:
|
||||
Light(LightType type = POINT_LIGHT, Tuple position=Point(0, 0, 0),
|
||||
Colour intensity=Colour(1, 1, 1)) : type(type), position(position), intensity(intensity) { };
|
||||
Colour intensity=Colour(1, 1, 1)) : type(type), position(position), intensity(intensity)
|
||||
{ stats.addLight(); };
|
||||
|
||||
bool operator==(const Light &b) const { return this->intensity == b.intensity &&
|
||||
this->position == b.position &&
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#ifndef DORAYME_PLANE_H
|
||||
#define DORAYME_PLANE_H
|
||||
|
||||
#include <renderstat.h>
|
||||
|
||||
class Plane : public Shape
|
||||
{
|
||||
private:
|
||||
@@ -16,7 +18,7 @@ private:
|
||||
Tuple localNormalAt(Tuple point);
|
||||
|
||||
public:
|
||||
Plane() : Shape(SHAPE_PLANE) { };
|
||||
Plane() : Shape(SHAPE_PLANE) { stats.addPlane(); };
|
||||
BoundingBox getBounds();
|
||||
bool haveFiniteBounds() { return false; };
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#define DORAYME_RAY_H
|
||||
|
||||
#include <tuple.h>
|
||||
#include <renderstat.h>
|
||||
|
||||
class Ray
|
||||
{
|
||||
@@ -17,7 +18,7 @@ public:
|
||||
Tuple direction;
|
||||
Tuple origin;
|
||||
|
||||
Ray(Tuple origin, Tuple direction) : origin(origin), direction(direction) { };
|
||||
Ray(Tuple origin, Tuple direction) : origin(origin), direction(direction) { stats.addRay(); };
|
||||
|
||||
Tuple position(double t) { return this->origin + this->direction * t; };
|
||||
};
|
||||
|
||||
125
source/include/renderstat.h
Normal file
125
source/include/renderstat.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* DoRayMe - a quick and dirty Raytracer
|
||||
* Render statistics header
|
||||
*
|
||||
* Created by Manoël Trapier
|
||||
* Copyright (c) 2020 986-Studio.
|
||||
*
|
||||
*/
|
||||
#ifndef DORAYME_RENDERSTAT_H
|
||||
#define DORAYME_RENDERSTAT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef RENDER_STATS
|
||||
#include <stdio.h>
|
||||
|
||||
class RenderStats
|
||||
{
|
||||
private:
|
||||
uint64_t coneCount; /* Total number of cones */
|
||||
uint64_t cylinderCount; /* Total number of cylinder */
|
||||
uint64_t cubeCount; /* Total number of cubes */
|
||||
uint64_t groupCount; /* Total number of groups */
|
||||
uint64_t lightCount; /* Total number of light */
|
||||
uint64_t planeCount; /* Total number of plane */
|
||||
uint64_t sphereCount; /* Total number of sphere */
|
||||
uint64_t triangleCount; /* Total number of triangle */
|
||||
|
||||
uint64_t pixelCount; /* Total number of rendered pixels */
|
||||
uint64_t rayCount; /* Total number of rays */
|
||||
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 */
|
||||
uint64_t intersectCount; /* Total number of intersect object created */
|
||||
uint64_t intersectionCount; /* Total number of intersection for all casted rays, including light and reflections */
|
||||
uint64_t reallocCallCount; /* Total number of time realloc being called */
|
||||
uint64_t mallocCallCount; /* Total number of time malloc/calloc being called */
|
||||
uint64_t discardedIntersectCount; /* Number of time a bounding box check said "no need to test me" */
|
||||
uint64_t maxDepthAttained; /* Report the lowest depth attained during ray recursion */
|
||||
uint64_t maxIntersectOnARay; /* Biggest intersect done */
|
||||
|
||||
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),
|
||||
discardedIntersectCount(0), maxDepthAttained(UINT64_MAX), maxIntersectOnARay(0) {};
|
||||
|
||||
void addCone() { this->coneCount++; };
|
||||
void addCylinder() { this->cylinderCount++; };
|
||||
void addCube() { this->cubeCount++; };
|
||||
void addGroup() { this->groupCount++; };
|
||||
void addLight() { this->lightCount++; };
|
||||
void addPlane() { this->planeCount++; };
|
||||
void addSphere() { this->sphereCount++; };
|
||||
void addTriangle() { this->triangleCount++; };
|
||||
|
||||
void addPixel() { this->pixelCount++; };
|
||||
void addRay() { this->rayCount++; };
|
||||
void addLightRay() { this->lightRayEmitedCount++; };
|
||||
void addReflectRay() { this->reflectionRayCount++; };
|
||||
void addRefractRay() { this->refractedRayCount++; };
|
||||
void addIntersect() { this->intersectCount++; };
|
||||
void addIntersection() { this->intersectionCount++; };
|
||||
void addMalloc() { this->mallocCallCount++; };
|
||||
void addRealloc() { this->reallocCallCount++; };
|
||||
void addDiscardedIntersect() { this->discardedIntersectCount++; };
|
||||
void setMaxDepth(uint32_t depth) { if (this->maxDepthAttained>depth) { this->maxDepthAttained = depth; } };
|
||||
void setMaxIntersect(uint32_t count) { if (this->maxIntersectOnARay<count) { this->maxIntersectOnARay = count; } };
|
||||
void printStats() {
|
||||
printf("Rendering statistics:\n");
|
||||
printf("Cones : %ld\n", this->coneCount);
|
||||
printf("Cubes : %ld\n", this->cubeCount);
|
||||
printf("Cylinders : %ld\n", this->cylinderCount);
|
||||
printf("Groups : %ld\n", this->groupCount);
|
||||
printf("Lights : %ld\n", this->lightCount);
|
||||
printf("Planes : %ld\n", this->planeCount);
|
||||
printf("Spheres : %ld\n", this->sphereCount);
|
||||
printf("Triangles : %ld\n", this->triangleCount);
|
||||
printf("==================================================\n");
|
||||
printf("Pixel rendered : %ld\n", this->pixelCount);
|
||||
printf("Ray casted : %ld\n", this->rayCount);
|
||||
printf("Light Ray casted : %ld\n", this->lightRayEmitedCount);
|
||||
printf("Reflection ray casted : %ld\n", this->reflectionRayCount);
|
||||
printf("Refraction ray casted : %ld\n", this->refractedRayCount);
|
||||
printf("Intersect object created: %ld\n", this->intersectCount);
|
||||
printf("Intersection created : %ld\n", this->intersectionCount);
|
||||
printf("Malloc called : %ld\n", this->mallocCallCount);
|
||||
printf("Realloc called : %ld\n", this->reallocCallCount);
|
||||
printf("Bounding box missed : %ld\n", this->discardedIntersectCount);
|
||||
printf("Min depth atteined : %ld\n", this->maxDepthAttained);
|
||||
printf("Max intersect count : %ld\n", this->maxIntersectOnARay);
|
||||
printf("==================================================\n");
|
||||
};
|
||||
};
|
||||
#else
|
||||
class RenderStats
|
||||
{
|
||||
public:
|
||||
static void addCone() {};
|
||||
static void addCylinder() {};
|
||||
static void addCube() {};
|
||||
static void addGroup() {};
|
||||
static void addLight() {};
|
||||
static void addPlane() {};
|
||||
static void addSphere() {};
|
||||
static void addTriangle() {};
|
||||
static void printStats() {};
|
||||
static void addPixel() {};
|
||||
static void addRay() {};
|
||||
static void addLightRay() {};
|
||||
static void addReflectRay() {};
|
||||
static void addRefractRay() {};
|
||||
static void addIntersection() {};
|
||||
static void addDiscardedIntersect() {};
|
||||
static void setMaxDepth(uint32_t depth) {};
|
||||
static void addIntersect() {};
|
||||
static void addMalloc() {};
|
||||
static void addRealloc() {};
|
||||
static void setMaxIntersect(uint32_t count) {};
|
||||
};
|
||||
#endif
|
||||
|
||||
extern RenderStats stats;
|
||||
|
||||
#endif /* DORAYME_RENDERSTAT_H */
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <shape.h>
|
||||
#include <ray.h>
|
||||
#include <intersect.h>
|
||||
#include <renderstat.h>
|
||||
|
||||
class Sphere : public Shape
|
||||
{
|
||||
@@ -20,7 +21,7 @@ protected:
|
||||
Tuple localNormalAt(Tuple point);
|
||||
|
||||
public:
|
||||
Sphere() : Shape(SHAPE_SPHERE) { };
|
||||
Sphere() : Shape(SHAPE_SPHERE) { stats.addSphere(); };
|
||||
/* All sphere are at (0, 0, 0) and radius 1 in the object space */
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user