-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhittable.h
More file actions
63 lines (54 loc) · 1.91 KB
/
hittable.h
File metadata and controls
63 lines (54 loc) · 1.91 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef HITTABLE_H
#define HITTABLE_H
#include <memory>
#include "constants.h"
#include "ray.h"
class material;
/*
structure to store ray hits
*/
class hit_record {
public:
// the hit point
point3 p;
// surface normal of the hit point
vec3 normal;
// parameter t of the ray equation P = A + Bt
float t;
// whether the ray hit the object from the inside or outside
// true if outside, false if inside
bool front_face;
// material of the object hit
material * mat = nullptr;
/*
Set the **SURFACE** normal of the hit point.
The outward normal is calculated from an object's hit
function.
As implied, it always points from the object's inside
out towards the hit point.
This function determines the surface normal, which determines
which side the ray hit the object's surface (inside or outside).
The dot product of the ray and the outward normal is negative if
the ray hit the outside surface, positive if the ray
hit the object on the inside surface.
We use an implementation where the surface normal points
inward if the ray hit on the inside, points outward if the
ray hit on the outside of the object.
@param r the ray that hit the point
@param outward_normal the
*/
__device__ void set_face_normal(const ray &r, const vec3 &outward_normal) {
front_face = dot(r.direction(), outward_normal) < 0;
normal = front_face ? outward_normal : -outward_normal;
}
};
/*
abstract class representing a hittable object
*/
class hittable {
public:
hittable() = default;
virtual ~hittable() = default;
__device__ virtual bool hit(const ray &r, interval ray_t, hit_record &rec) const = 0;
};
#endif