Adds recursion exit for mirror shader
This commit is contained in:
parent
6674549b18
commit
8bd8d4acb0
1 changed files with 6 additions and 0 deletions
|
@ -4,9 +4,15 @@
|
|||
MirrorShader::MirrorShader() {}
|
||||
|
||||
Color MirrorShader::shade(Scene const &scene, Ray const &ray) const {
|
||||
if (ray.getRemainingBounces() <= 0) {
|
||||
return Color(0, 0, 0);
|
||||
}
|
||||
|
||||
Vector3d newDirection = ray.direction - 2 * dotProduct(ray.normal, ray.direction) * ray.normal;
|
||||
|
||||
//TODO: should we reset the ray or use a new ray? Regarding the count of bounces
|
||||
Ray mirroredRay = Ray(ray.origin + ray.length * ray.direction, newDirection);
|
||||
mirroredRay.setRemainingBounces(ray.getRemainingBounces() - 1);
|
||||
|
||||
return scene.traceRay(mirroredRay);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue