-
Notifications
You must be signed in to change notification settings - Fork 927
Added isotropic changes for book 3. Made some changes to prior books. #885
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d043154
Added isotropic changes for book 3. Made some changes to prior books.
trevordblack 397cb70
Added CHANGELOG differences
trevordblack e9af17a
Merge branch 'dev-major' into tdb/isotropic
hollasch 3ab99ec
Added isotropic changes for book 3. Made some changes to prior books.
trevordblack 34ca9bc
Added CHANGELOG differences
trevordblack c5871d0
Changes made as per comments
trevordblack 4854d72
Merge branch 'tdb/isotropic' of https://github.com/RayTracing/raytrac…
trevordblack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#ifndef CONSTANT_MEDIUM_H | ||
#define CONSTANT_MEDIUM_H | ||
//============================================================================================== | ||
// Originally written in 2016 by Peter Shirley <ptrshrl@gmail.com> | ||
// | ||
// To the extent possible under law, the author(s) have dedicated all copyright and related and | ||
// neighboring rights to this software to the public domain worldwide. This software is | ||
// distributed without any warranty. | ||
// | ||
// You should have received a copy (see file COPYING.txt) of the CC0 Public Domain Dedication | ||
// along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
//============================================================================================== | ||
|
||
#include "rtweekend.h" | ||
|
||
#include "hittable.h" | ||
#include "material.h" | ||
#include "texture.h" | ||
|
||
|
||
class constant_medium : public hittable { | ||
public: | ||
constant_medium(shared_ptr<hittable> b, double d, shared_ptr<texture> a) | ||
: boundary(b), neg_inv_density(-1/d), phase_function(make_shared<isotropic>(a)) | ||
{} | ||
|
||
constant_medium(shared_ptr<hittable> b, double d, color c) | ||
: boundary(b), neg_inv_density(-1/d), phase_function(make_shared<isotropic>(c)) | ||
{} | ||
|
||
bool hit(const ray& r, interval ray_t, hit_record& rec) const override { | ||
// Print occasional samples when debugging. To enable, set enableDebug true. | ||
const bool enableDebug = false; | ||
const bool debugging = enableDebug && random_double() < 0.00001; | ||
|
||
hit_record rec1, rec2; | ||
|
||
if (!boundary->hit(r, interval::universe, rec1)) | ||
return false; | ||
|
||
if (!boundary->hit(r, interval(rec1.t+0.0001, infinity), rec2)) | ||
return false; | ||
|
||
if (debugging) std::cerr << "\nt_min=" << rec1.t << ", t_max=" << rec2.t << '\n'; | ||
|
||
if (rec1.t < ray_t.min) rec1.t = ray_t.min; | ||
if (rec2.t > ray_t.max) rec2.t = ray_t.max; | ||
|
||
if (rec1.t >= rec2.t) | ||
return false; | ||
|
||
if (rec1.t < 0) | ||
rec1.t = 0; | ||
|
||
const auto ray_length = r.direction().length(); | ||
const auto distance_inside_boundary = (rec2.t - rec1.t) * ray_length; | ||
const auto hit_distance = neg_inv_density * log(random_double()); | ||
|
||
if (hit_distance > distance_inside_boundary) | ||
return false; | ||
|
||
rec.t = rec1.t + hit_distance / ray_length; | ||
rec.p = r.at(rec.t); | ||
|
||
if (debugging) { | ||
std::cerr << "hit_distance = " << hit_distance << '\n' | ||
<< "rec.t = " << rec.t << '\n' | ||
<< "rec.p = " << rec.p << '\n'; | ||
} | ||
|
||
rec.normal = vec3(1,0,0); // arbitrary | ||
rec.front_face = true; // also arbitrary | ||
rec.mat = phase_function; | ||
|
||
return true; | ||
} | ||
|
||
aabb bounding_box() const override { return boundary->bounding_box(); } | ||
|
||
public: | ||
shared_ptr<hittable> boundary; | ||
double neg_inv_density; | ||
shared_ptr<material> phase_function; | ||
}; | ||
|
||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.