-
Notifications
You must be signed in to change notification settings - Fork 827
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
Fix problems with material::scatter() methods #728
Conversation
- In book 1, the code for material::dielectric::scatter() divereged from the source code. - In book 2, we neglected to include the code changes to handle ray time for material::metal and material::dielectric. Resolves #133
The text in the book having
the "redundant" if statement is to make the code as easy to read as possible. I agree that chunking the two if statements together is certainly "cleaner", I think it's harder to understand. The src has the cleaner:
The dielectric chapter is already the densest chapter in the book and I wanted the source to be incredibly simple to understand. But, having redundant code makes transcription errors more likely, not less. The |
I would happy with:
|
@trevordblack -- can you take a look at this latest change? I think my hang-up with the earlier code was that I usually think of indices of refraction, but in our code we're really dealing with a baked-in ratio of indices of refraction. I've updated the naming in the refraction code to reflect that. What do you think? If it looks good, then I'll go ahead and tie up all the remaining loose ends. |
src/InOneWeekend/material.h
Outdated
scattered = ray(rec.p, refracted); | ||
return true; | ||
} | ||
|
||
public: | ||
double ref_idx; | ||
double refraction_ratio; // Ratio of the two materials' indices of refraction |
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.
oh no
This member variable is supposed to be the refractive index.
double etai_over_etat = rec.front_face ? (1.0 / ref_idx) : ref_idx;
the variable etai_over_etat
is the refractive ratio. so your change of variable name there is fine.
the 1.0
is because we assume that the ray is coming-from/going-to a region with a refractive index of 1.0 (a vacuum)
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.
We're not dealing with a baked in refractive ratio. At least, that's not what our text is saying. The member variable is supposed to be the refractive index of the media.
It just so happens to also be the reciprocal refractive ratio if the outside is a vacuum
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.
Ah! Of course; now I get it.
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 change refraction_ratio
back to ref_idx
I'm otherwise perfectly happy with this commit
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.
Ok, fixed in next change, I think.
Looks good to me, make sure changes to source make their way back into the inlined source in the text. |
Yup, thanks! |
This also adds the changes to the scatter specular updates in book 3 that were omitted.
Ok @trevordblack , this last change should do it. Also found updates to the PDF specular component for dielectric materials that were missed in book 3. |
All changes now squashed and fixed up in PR #739. |
In book 1, the code for material::dielectric::scatter() divereged from
the source code.
In book 2, we neglected to include the code changes to handle ray time
for material::metal and material::dielectric.
Resolves #133