Add support for multiple lights

This commit is contained in:
Godzil
2020-02-22 15:12:06 +00:00
parent 4cdf7a4264
commit 935c8ebff7
2 changed files with 11 additions and 7 deletions

View File

@@ -44,7 +44,7 @@ public:
Tuple shadeHit(Computation comps, uint32_t depthCount = 4); Tuple shadeHit(Computation comps, uint32_t depthCount = 4);
Tuple colourAt(Ray r, uint32_t depthCount = 4); Tuple colourAt(Ray r, uint32_t depthCount = 4);
bool isShadowed(Tuple point); bool isShadowed(Tuple point, uint32_t light = 0);
Colour reflectColour(Computation comps, uint32_t depthCount = 4); Colour reflectColour(Computation comps, uint32_t depthCount = 4);
Colour refractedColour(Computation comps, uint32_t depthCount = 4); Colour refractedColour(Computation comps, uint32_t depthCount = 4);

View File

@@ -95,12 +95,17 @@ Intersect World::intersect(Ray r)
Tuple World::shadeHit(Computation comps, uint32_t depthCount) Tuple World::shadeHit(Computation comps, uint32_t depthCount)
{ {
/* TODO: Add support for more than one light */ /* TODO: Add support for more than one light */
uint32_t lightIndex;
bool isThereAnObstacle = this->isShadowed(comps.overHitPoint); Tuple surface = Colour(0, 0, 0);
Tuple surface = comps.object->material.lighting(*this->lightList[0], comps.overHitPoint, comps.eyeVector, for(lightIndex = 0; lightIndex < this->lightCount; lightIndex++)
comps.normalVector, comps.object, isThereAnObstacle); {
bool isThereAnObstacle = this->isShadowed(comps.overHitPoint, lightIndex);
surface = surface + comps.object->material.lighting(*this->lightList[lightIndex], comps.overHitPoint, comps.eyeVector,
comps.normalVector, comps.object, isThereAnObstacle);
}
Tuple reflected = this->reflectColour(comps, depthCount); Tuple reflected = this->reflectColour(comps, depthCount);
Tuple refracted = this->refractedColour(comps, depthCount); Tuple refracted = this->refractedColour(comps, depthCount);
@@ -109,7 +114,6 @@ Tuple World::shadeHit(Computation comps, uint32_t depthCount)
double reflectance = comps.schlick(); double reflectance = comps.schlick();
return surface + reflected * reflectance + refracted * (1 - reflectance); return surface + reflected * reflectance + refracted * (1 - reflectance);
} }
return surface + reflected + refracted; return surface + reflected + refracted;
@@ -130,11 +134,11 @@ Tuple World::colourAt(Ray r, uint32_t depthCount)
} }
} }
bool World::isShadowed(Tuple point) bool World::isShadowed(Tuple point, uint32_t light)
{ {
/* TODO: Add support for more than one light */ /* TODO: Add support for more than one light */
Tuple v = this->lightList[0]->position - point; Tuple v = this->lightList[light]->position - point;
double distance = v.magnitude(); double distance = v.magnitude();
Tuple direction = v.normalise(); Tuple direction = v.normalise();