-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explain sphere uv #762
Explain sphere uv #762
Conversation
Also, get_sphere_uv() is in sphere.h for book 2, but hittable.h for book 3. This change also moves the function to sphere.h for book 3. Resolves #533
The sphere::hit() function calls get_sphere_uv() with the intersection point transformed to its position on a unit sphere centered at the origin. But this calculation was already performed for the normal vector, so we should just reuse that result instead of calculating it twice.
The prior sphere::hit() methods duplicated the main update block with a single change in variable value. This change solves and selects the intersection root first, then updates the hit record for a good hit, simplifying the code and the text.
src/TheNextWeek/sphere.h
Outdated
@@ -43,10 +43,17 @@ bool sphere::bounding_box(double time0, double time1, aabb& output_box) const { | |||
} | |||
|
|||
|
|||
void get_sphere_uv(const point3& p, double& u, double& v) { | |||
static void get_sphere_uv(const point3& p, double& u, double& v) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to make the source static
, you'll need to make the inline src in the text static
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This really should be private, but everything's awkward with our approach of doing everything in a header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made private static.
books/RayTracingTheNextWeek.html
Outdated
@@ -1215,7 +1215,7 @@ | |||
vec3 outward_normal = (rec.p - center) / radius; | |||
rec.set_face_normal(r, outward_normal); | |||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight | |||
get_sphere_uv((rec.p-center)/radius, rec.u, rec.v); | |||
get_sphere_uv(outward_normal, rec.u, rec.v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has some interesting implications.
The functionality is identical before and after change.
A texture shaded on the inside is reversed. Which is what you'd expect.
Uhhh, Steve... Source:
Text:
The |
I'm pretty sure this is what the original issue was bringing up |
Interesting. Later comments suggest that there's no issue. I wasn't aware there was a disagreement between the source and the text; I'll revisit. |
…tracing.github.io into explain-sphere-uv
I added another comment that was what I think @D-K-E was referring to. |
Thanks. Having gone over it, I still think there are issues. What I'm wrestling with right now is a better explanation for the atan2 arguments, which are juggled to move past the sawtooth discrepancy in the return values (0→π / -π→0). I understand that it works, but am trying to find a way to develop it naturally. |
The convention in ce97f02 is taking θ as the angle from the x-z plane and then ϕ as the polar angle from the z-axis, is this intended?
Relates to the geometry: |
I think you might be slurring your variables a bit. Do you propose we make the If you propose making the θ as the angle coming down from the |
I've always seen θ going around the equator (for example, longitude), and φ indicating the angle from one pole to the other (like latitude). Like John, I was all set to assert that the book was "nonstandard". Then I did an image search on {spherical coordinates}, and realized it was just another item on the list of
What's really needed here is a proper illustration (in the same manner that John posted above) and a bit more explanation. |
I have an immense urge to go through your list and explain how there's EXACTLY one right option for each... |
Resolves #533