cloudy-raytracer/shader/mirrorshader.cpp
2022-11-17 20:34:37 +01:00

17 lines
539 B
C++

#include "scene/scene.h"
#include "shader/mirrorshader.h"
MirrorShader::MirrorShader() = default;
Color MirrorShader::shade(Scene const &scene, Ray const &ray) const {
if (ray.getRemainingBounces() <= 0) {
return {0, 0, 0};
}
Vector3d newDirection = ray.direction - 2 * dotProduct(ray.normal, ray.direction) * ray.normal;
Ray mirroredRay = Ray(ray.origin + ray.length * ray.direction, newDirection);
mirroredRay.setRemainingBounces(ray.getRemainingBounces() - 1);
return scene.traceRay(mirroredRay);
}