-
Should we unit rec.normal vector in thic code? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Took me a bit to crawl back through the sample code to figure out what's happening. In code listing The sphere class with normal determination, you can find Still, if Thanks for the question. |
Beta Was this translation helpful? Give feedback.
Took me a bit to crawl back through the sample code to figure out what's happening. In code listing The sphere class with normal determination, you can find
vec3 outward_normal = (rec.p - center) / radius;
. Sincerec.p
is the hit point on the surface of the sphere,rec.p - center
must be a vector of lengthradius
. Thus, dividing by the radius should make this a unit vector. This may be different in your code (you might just haverec.p - center
only).Still, if
set_face_normal()
expects given vectors to be of unit length, there's nothing really that guarantees or checks that. Further, the color computation above clearly expectsrec.normal
to be of unit length, so we need to address this.S…