Skip to content

Hitrecord

void set_face_normal(const ray&, const vec3&)

Imagine a surface \(S\).
If the dot product1 of incident ray2 and the normal vector1 is negative, the ray2 is outside of the surface \(S\).
Proj_raytracing_surface_normals.svg

If our condition is true then the normal is the outward normal, otherwise it is opposite to outward normal.

void hit_record::set_face_normal(const ray& r, const vec3& outward_normal) {
    // Sets the hit record normal vector.
    // NOTE: the parameter `outward_normal` is assumed to have unit length.

    front_face = dot(r.direction(), outward_normal) < 0;
    normal = front_face ? outward_normal : -outward_normal;
}

References


  1. Read more about dot product

  2. Read more about ray in context of this project.