Skip to content

Question on Book 1 Chapter 6.7 ray_color function #1060

Answered by hollasch
VxDxK asked this question in Q&A
Discussion options

You must be logged in to vote

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;. Since rec.p is the hit point on the surface of the sphere, rec.p - center must be a vector of length radius. Thus, dividing by the radius should make this a unit vector. This may be different in your code (you might just have rec.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 expects rec.normal to be of unit length, so we need to address this.

S…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@VxDxK
Comment options

Answer selected by VxDxK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants