-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetal.cpp
More file actions
15 lines (12 loc) · 913 Bytes
/
Copy pathMetal.cpp
File metadata and controls
15 lines (12 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "Metal.h"
#include "VectorFunc.h"
bool Metal::isScattered(const Ray& inRay, const HitRecord& inRecord, dp::PhysicsVector<3>& inColourAtten, Ray& scatteredRay) const {
//First calculate the direction of the reflected ray using the smooth reflect method inside the Vector3D class.
auto reflectedDirection{ smoothReflect(inRay.direction().getUnitVector(),inRecord.m_normal) };
//Then assign it to the ray, and add a small random perturbation according to the fuzziness of the material.
scatteredRay = Ray(inRecord.m_point, reflectedDirection + dp::randInUnitSphere().scaledBy(m_fuzz));
inColourAtten = m_albedoColour;
//It only makes sense for our reflected ray to travel outwards from the material and not inwards through it, or exactly parallel.
//So we return false for the cases where that happens and discard the reflection.
return (reflectedDirection.innerProduct(inRecord.m_normal) > 0);
}