-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMirror.cpp
More file actions
28 lines (23 loc) · 793 Bytes
/
Mirror.cpp
File metadata and controls
28 lines (23 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "Mirror.h"
#include "Ray.h"
#include "Scene.h"
#include <algorithm>
#define MAX_RELF_DEPTH 8
Mirror::Mirror(const Vector3 & ks): m_ks(ks) {}
Mirror::~Mirror() {}
Vector3
Mirror::shade(const Ray& ray, const HitInfo& hit, const Scene& scene) const
{
Vector3 L = Vector3(0.0f, 0.0f, 0.0f);
// calculate reflection ray
Vector3 tmpD = Vector3();
tmpD = -2*(dot(ray.d, hit.N)*hit.N) + ray.d;
tmpD = tmpD / sqrt(tmpD.length2());
Ray reflRay = Ray(hit.P, tmpD, ray.reflDepth+1);
HitInfo tmpHit;
if (reflRay.reflDepth < MAX_RELF_DEPTH && scene.trace(tmpHit, reflRay))
L += ks() * tmpHit.material->shade(reflRay, tmpHit, scene);
else if (reflRay.reflDepth < MAX_RELF_DEPTH)
L += scene.environment()->getColor(reflRay.d);
return L;
}