Prepare code to be able to get material from some form of a "group leader".
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ray.h>
|
||||
#include <material.h>
|
||||
|
||||
class Shape;
|
||||
class Intersect;
|
||||
@@ -19,9 +20,9 @@ struct Computation
|
||||
{
|
||||
Computation(Shape *object, double t, Tuple point, Tuple eyev, Tuple normalv, Tuple overHitP,
|
||||
bool inside, Tuple reflectV = Vector(0, 0, 0), double n1 = 1.0, double n2 = 1.0,
|
||||
Tuple underHitP = Point(0, 0, 0)) :
|
||||
Tuple underHitP = Point(0, 0, 0), Material *objMat = nullptr) :
|
||||
object(object), t(t), hitPoint(point), eyeVector(eyev), normalVector(normalv), inside(inside),
|
||||
overHitPoint(overHitP), underHitPoint(underHitP), reflectVector(reflectV), n1(n1), n2(n2) { };
|
||||
overHitPoint(overHitP), underHitPoint(underHitP), reflectVector(reflectV), n1(n1), n2(n2), material(objMat) { };
|
||||
|
||||
double schlick()
|
||||
{
|
||||
@@ -58,6 +59,8 @@ struct Computation
|
||||
Tuple normalVector;
|
||||
Tuple reflectVector;
|
||||
|
||||
Material *material;
|
||||
|
||||
double n1;
|
||||
double n2;
|
||||
|
||||
|
||||
@@ -68,6 +68,10 @@ Computation Intersection::prepareComputation(Ray r, Intersect *xs)
|
||||
}
|
||||
}
|
||||
|
||||
Shape *s = this->object;
|
||||
/* For now don't get root group material */
|
||||
//while(s->parent != nullptr) { s = s->parent; }
|
||||
|
||||
return Computation(this->object,
|
||||
this->t,
|
||||
hitP,
|
||||
@@ -78,5 +82,6 @@ Computation Intersection::prepareComputation(Ray r, Intersect *xs)
|
||||
reflectV,
|
||||
n1,
|
||||
n2,
|
||||
underHitP);
|
||||
underHitP,
|
||||
&s->material);
|
||||
}
|
||||
@@ -102,13 +102,13 @@ Tuple World::shadeHit(Computation comps, uint32_t depthCount)
|
||||
{
|
||||
bool isThereAnObstacle = this->isShadowed(comps.overHitPoint, lightIndex);
|
||||
|
||||
surface = surface + comps.object->material.lighting(*this->lightList[lightIndex], comps.overHitPoint, comps.eyeVector,
|
||||
surface = surface + comps.material->lighting(*this->lightList[lightIndex], comps.overHitPoint, comps.eyeVector,
|
||||
comps.normalVector, comps.object, isThereAnObstacle);
|
||||
}
|
||||
Tuple reflected = this->reflectColour(comps, depthCount);
|
||||
Tuple refracted = this->refractedColour(comps, depthCount);
|
||||
|
||||
if ((comps.object->material.reflective > 0) && (comps.object->material.transparency > 0))
|
||||
if ((comps.material->reflective > 0) && (comps.material->transparency > 0))
|
||||
{
|
||||
double reflectance = comps.schlick();
|
||||
|
||||
@@ -159,7 +159,7 @@ bool World::isShadowed(Tuple point, uint32_t light)
|
||||
|
||||
Colour World::reflectColour(Computation comps, uint32_t depthCount)
|
||||
{
|
||||
if ((depthCount == 0) || (comps.object->material.reflective == 0))
|
||||
if ((depthCount == 0) || (comps.material->reflective == 0))
|
||||
{
|
||||
return Colour(0, 0, 0);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ Colour World::reflectColour(Computation comps, uint32_t depthCount)
|
||||
Ray reflectedRay = Ray(comps.overHitPoint, comps.reflectVector);
|
||||
|
||||
Tuple hitColour = this->colourAt(reflectedRay, depthCount - 1);
|
||||
hitColour = hitColour * comps.object->material.reflective;
|
||||
hitColour = hitColour * comps.material->reflective;
|
||||
|
||||
return Colour(hitColour.x, hitColour.y, hitColour.z);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ Colour World::refractedColour(Computation comps, uint32_t depthCount)
|
||||
double cos_i = comps.eyeVector.dot(comps.normalVector);
|
||||
double sin2_t = (nRatio*nRatio) * (1 - cos_i * cos_i);
|
||||
|
||||
if ((sin2_t > 1 ) || (depthCount == 0) || (comps.object->material.transparency == 0))
|
||||
if ((sin2_t > 1 ) || (depthCount == 0) || (comps.material->transparency == 0))
|
||||
{
|
||||
return Colour(0, 0, 0);
|
||||
}
|
||||
@@ -189,7 +189,7 @@ Colour World::refractedColour(Computation comps, uint32_t depthCount)
|
||||
|
||||
Ray refractedRay = Ray(comps.underHitPoint, direction);
|
||||
|
||||
Tuple hitColour = this->colourAt(refractedRay, depthCount - 1) * comps.object->material.transparency;
|
||||
Tuple hitColour = this->colourAt(refractedRay, depthCount - 1) * comps.material->transparency;
|
||||
|
||||
return Colour(hitColour.x, hitColour.y, hitColour.z);
|
||||
}
|
||||
Reference in New Issue
Block a user