cloudy-raytracer/scene/simplescene.cpp

40 lines
1,000 B
C++
Raw Permalink Normal View History

2022-11-05 22:08:16 +01:00
#include "scene/simplescene.h"
#include "primitive/primitive.h"
#include "shader/shader.h"
bool SimpleScene::findIntersection(Ray &ray) const
{
bool hit = false;
for (auto i: this->primitives())
hit |= i->intersect(ray);
return hit;
2022-11-05 22:08:16 +01:00
}
bool SimpleScene::findOcclusion(Ray &ray) const
{
for (auto i: this->primitives())
if (i->intersect(ray) && !i->shader()->isTransparent())
return true;
return false;
}
Color SimpleScene::getTransparency(Ray &ray, float maxDistance) const
{
ray.length = maxDistance;
ray.primitive = nullptr;
Color transparency(1, 1, 1);
for (auto i: this->primitives())
{
Ray r = ray;
if (i->intersect(r) && r.length < maxDistance && i->shader()->isTransparent())
{
Color t = i->shader()->transparency(*this, r, maxDistance);
transparency.r *= t.r;
transparency.g *= t.g;
transparency.b *= t.b;
}
}
return transparency;
2022-11-05 22:08:16 +01:00
}