Huge speed up by changing how Intersect are shared.

This commit is contained in:
Godzil
2020-03-12 00:11:26 +00:00
parent 0aa949c60b
commit b00bb75189
38 changed files with 116 additions and 153 deletions

View File

@@ -17,7 +17,7 @@
class Cone : public Shape {
protected:
Intersect localIntersect(Ray r);
void localIntersect(Ray r, Intersect &xs);
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);

View File

@@ -28,7 +28,7 @@ protected:
BoundingBox bounds;
protected:
Intersect localIntersect(Ray r);
void localIntersect(Ray r, Intersect &xs);
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
BoundingBox getLocalBounds();
@@ -42,7 +42,7 @@ protected:
public:
CSG(OperationType operation, Shape *left, Shape *right);
Intersect intersect(Ray r);
void intersect(Ray &r, Intersect &xs);
bool includes(Shape *b);

View File

@@ -19,7 +19,7 @@ class Cube : public Shape {
protected:
void checkAxis(double axeOrigin, double axeDirection, double *axeMin, double *axeMax);
Intersect localIntersect(Ray r);
void localIntersect(Ray r, Intersect &xs);
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);

View File

@@ -18,7 +18,7 @@
class Cylinder : public Shape {
protected:
Intersect localIntersect(Ray r);
void localIntersect(Ray r, Intersect &xs);
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);

View File

@@ -28,7 +28,7 @@ private:
char name[32 + 1];
protected:
Intersect localIntersect(Ray r);
void localIntersect(Ray r, Intersect &xs);
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
BoundingBox bounds;
@@ -43,7 +43,7 @@ public:
Shape *getObject(const int p) { return this->objectList[p]; };
Shape *getUnboxable(const int p) { return this->unboxableObjectList[p]; };
Intersect intersect(Ray r);
void intersect(Ray &r, Intersect &xs);
BoundingBox getLocalBounds();
BoundingBox getBounds();
@@ -59,6 +59,8 @@ public:
void lock();
void setBounds(BoundingBox &bb) { this->bounds | bb; };
const char *getName() { return this->name; };
void dumpMe(FILE * fp);

View File

@@ -31,7 +31,7 @@ private:
uint32_t vertexNormalCount;
private:
Intersect localIntersect(Ray r);
void localIntersect(Ray r, Intersect &xs);
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
public:
@@ -59,7 +59,7 @@ public:
Point vertices(uint32_t i) { return *this->vertexList[i - 1]; };
Vector verticesNormal(uint32_t i) { return *this->vertexNormalList[i - 1]; };
Group *groups(const char *groupName);
Intersect intersect(Ray r);
void intersect(Ray &r, Intersect &xs);
BoundingBox getLocalBounds();
BoundingBox getBounds();

View File

@@ -14,7 +14,7 @@
class Plane : public Shape
{
protected:
Intersect localIntersect(Ray r);
void localIntersect(Ray r, Intersect &xs);
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
public:

View File

@@ -44,7 +44,7 @@ protected:
bool locked;
protected:
virtual Intersect localIntersect(Ray r) = 0;
virtual void localIntersect(Ray r, Intersect &xs) = 0;
virtual Tuple localNormalAt(Tuple point, Intersection *hit) = 0;
public:
@@ -62,7 +62,7 @@ public:
ShapeType getType() { return this->type; };
virtual Intersect intersect(Ray r);
virtual void intersect(Ray &r, Intersect &xs);
Tuple normalAt(Tuple point, Intersection *hit = nullptr);
/* Bounding box points are always world value */
@@ -92,8 +92,8 @@ public:
void setTransform(Matrix transform);
void setMaterial(Material material) { this->material = material; this->materialSet = true; };
Ray transform(Ray r) { return Ray(this->transformMatrix * r.origin, this->transformMatrix * r.direction); };
Ray invTransform(Ray r) { return Ray(this->inverseTransform * r.origin, this->inverseTransform * r.direction); };
Ray transform(Ray &r) { return Ray(this->transformMatrix * r.origin, this->transformMatrix * r.direction); };
Ray invTransform(Ray &r) { return Ray(this->inverseTransform * r.origin, this->inverseTransform * r.direction); };
bool operator==(const Shape &b) const { return this->material == b.material &&
this->type == b.type &&

View File

@@ -18,7 +18,7 @@
class Sphere : public Shape
{
protected:
Intersect localIntersect(Ray r);
void localIntersect(Ray r, Intersect &xs);
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
public:

View File

@@ -16,7 +16,7 @@
class TestShape : public Shape
{
private:
Intersect localIntersect(Ray r);
void localIntersect(Ray r, Intersect &xs);
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
public:

View File

@@ -15,7 +15,7 @@
class Triangle : public Shape
{
protected:
Intersect localIntersect(Ray r);
void localIntersect(Ray r, Intersect &xs);
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
public:

View File

@@ -63,7 +63,7 @@ public:
Colour reflectColour(Computation comps, uint32_t depthCount = 4);
Colour refractedColour(Computation comps, uint32_t depthCount = 4);
Intersect intersect(Ray r);
void intersect(Ray &r, Intersect &xs);
void finalise(WorldOptimiser &opt);