2022-11-11 14:39:48 +01:00
|
|
|
#include "scene/scene.h"
|
|
|
|
#include "shader/mirrorshader.h"
|
|
|
|
|
|
|
|
MirrorShader::MirrorShader() {}
|
|
|
|
|
|
|
|
Color MirrorShader::shade(Scene const &scene, Ray const &ray) const {
|
|
|
|
// Calculate the reflection vector
|
2022-11-18 11:43:53 +01:00
|
|
|
Vector3d const reflection = ray.direction - 2 * dotProduct(ray.normal, ray.direction) * ray.normal;
|
|
|
|
|
2022-11-11 14:39:48 +01:00
|
|
|
// Create a new reflection ray
|
2022-11-18 11:43:53 +01:00
|
|
|
Ray reflectionRay = ray;
|
|
|
|
reflectionRay.origin = ray.origin + (ray.length - REFR_EPS) * ray.direction;
|
|
|
|
reflectionRay.direction = normalized(reflection);
|
|
|
|
reflectionRay.length = INFINITY;
|
|
|
|
reflectionRay.primitive = nullptr;
|
|
|
|
|
2022-11-11 14:39:48 +01:00
|
|
|
// Send the new ray out into the scene and return the result
|
2022-11-18 11:43:53 +01:00
|
|
|
return scene.traceRay(reflectionRay);
|
2022-11-11 14:39:48 +01:00
|
|
|
}
|