Minor fixes

This commit is contained in:
CJSatnarine
2024-07-11 21:23:14 -04:00
parent eafb2947cc
commit 2197114459
6 changed files with 155003 additions and 154991 deletions

Binary file not shown.

View File

@@ -8,45 +8,52 @@
class constantMedium : public hittable { class constantMedium : public hittable {
public: public:
constantMedium(shared_ptr<hittable> boundary, double density, shared_ptr<texture> tex): boundary(boundary), negativeInvDensity(-1/density), phaseFunction(make_shared<isotropic>(tex)) {} constantMedium(shared_ptr<hittable> boundary, double density, shared_ptr<texture> tex): boundary(boundary), negInvDensity(-1 / density), phaseFunction(make_shared<isotropic>(tex)) {}
constantMedium(shared_ptr<hittable> boundary, double density, const colour& albedo) : boundary(boundary), negativeInvDensity(-1 / density), phaseFunction(make_shared<isotropic>(albedo)) {} constantMedium(shared_ptr<hittable> boundary, double density, const colour& albedo) : boundary(boundary), negInvDensity(-1 / density), phaseFunction(make_shared<isotropic>(albedo)) {}
bool hit(const ray& r, interval rayT, hitRecord& rec) const override { bool hit(const ray& r, interval ray_t, hitRecord& rec) const override {
// Print occasional samples when debugging. To enable, set enableDebug true; // Print occasional samples when debugging. To enable, set enableDebug true.
const bool enableDebug = false; const bool enableDebug = false;
const bool debugging = enableDebug && randomDouble() < 0.00001; const bool debugging = enableDebug && randomDouble() < 0.00001;
hitRecord rec1, rec2; hitRecord rec1, rec2;
if (!boundary->hit(r, interval::universe, rec1)) return false; if (!boundary->hit(r, interval::universe, rec1))
return false;
if (!boundary->hit(r, interval(rec1.t+0.0001, infinity), rec2)) return false; if (!boundary->hit(r, interval(rec1.t+0.0001, infinity), rec2))
return false;
if (debugging) std::clog << "\ntMin=" << rec1.t << ", tMax=" << rec2.t << '\n'; if (debugging) std::clog << "\nt_min=" << rec1.t << ", t_max=" << rec2.t << '\n';
if (rec1.t < rayT.min) rec1.t = rayT.min; if (rec1.t < ray_t.min) rec1.t = ray_t.min;
if (rec2.t > rayT.max) rec2.t = rayT.max; if (rec2.t > ray_t.max) rec2.t = ray_t.max;
if (rec1.t >= rec2.t) return false; if (rec1.t >= rec2.t)
return false;
if (rec1.t < 0) rec1.t = 0; if (rec1.t < 0)
rec1.t = 0;
auto rayLength = r.direction().length(); auto rayLength = r.direction().length();
auto distanceInsideBoundary = (rec2.t - rec1.t) * rayLength; auto distanceInsideBoundary = (rec2.t - rec1.t) * rayLength;
auto hitDistance = negativeInvDensity * log(randomDouble()); auto hitDistance = negInvDensity * log(randomDouble());
if (hitDistance > distanceInsideBoundary) return false; if (hitDistance > distanceInsideBoundary)
return false;
rec.t = rec1.t + hitDistance / rayLength; rec.t = rec1.t + hitDistance / rayLength;
rec.p = r.at(rec.t); rec.p = r.at(rec.t);
if (debugging) { if (debugging) {
std::clog << "hitDistance = " << hitDistance << '\n' << "rec.t = " << rec.t << '\n' << "rec.p = " << rec.p << '\n'; std::clog << "hit_distance = " << hitDistance << '\n'
<< "rec.t = " << rec.t << '\n'
<< "rec.p = " << rec.p << '\n';
} }
rec.normal = vec3(1, 0, 0); // arbitrary rec.normal = vec3(1,0,0); // arbitrary
rec.frontFace = true; // also abritrary rec.frontFace = true; // also arbitrary
rec.mat = phaseFunction; rec.mat = phaseFunction;
return true; return true;
@@ -58,8 +65,8 @@ class constantMedium : public hittable {
private: private:
shared_ptr<hittable> boundary; shared_ptr<hittable> boundary;
double negativeInvDensity; double negInvDensity;
shared_ptr<material> phaseFunction; shared_ptr<material> phaseFunction;
}; };
#endif #endif

309902
image.ppm

File diff suppressed because it is too large Load Diff

View File

@@ -283,10 +283,10 @@ void cornellBox() {
void cornellSmoke() { void cornellSmoke() {
hittableList world; hittableList world;
auto red = make_shared<lambertian>(colour(0.65, 0.05, 0.05)); auto red = make_shared<lambertian>(colour(.65, .05, .05));
auto white = make_shared<lambertian>(colour(0.73, 0.73, 0.73)); auto white = make_shared<lambertian>(colour(.73, .73, .73));
auto green = make_shared<lambertian>(colour(0.12, 0.45, 0.15)); auto green = make_shared<lambertian>(colour(.12, .45, .15));
auto light = make_shared<diffuseLight>(colour(15, 15, 15)); auto light = make_shared<diffuseLight>(colour(7, 7, 7));
world.add(make_shared<quad>(point3(555,0,0), vec3(0,555,0), vec3(0,0,555), green)); world.add(make_shared<quad>(point3(555,0,0), vec3(0,555,0), vec3(0,0,555), green));
world.add(make_shared<quad>(point3(0,0,0), vec3(0,555,0), vec3(0,0,555), red)); world.add(make_shared<quad>(point3(0,0,0), vec3(0,555,0), vec3(0,0,555), red));
@@ -307,18 +307,20 @@ void cornellSmoke() {
world.add(make_shared<constantMedium>(box2, 0.01, colour(1,1,1))); world.add(make_shared<constantMedium>(box2, 0.01, colour(1,1,1)));
camera cam; camera cam;
cam.aspectRatio = 1.0; cam.aspectRatio = 1.0;
cam.imageWidth = 600; cam.imageWidth = 600;
cam.samplesPerPixel = 200; cam.samplesPerPixel = 200;
cam.maxDepth = 50; cam.maxDepth = 50;
cam.background = colour(0, 0, 0); cam.background = colour(0,0,0);
cam.vFieldOfView = 40; cam.vFieldOfView = 40;
cam.lookFrom = point3(278, 278, -800); cam.lookFrom = point3(278, 278, -800);
cam.lookAt = point3(278, 278, 0); cam.lookAt = point3(278, 278, 0);
cam.vUp = vec3(0, 1, 0); cam.vUp = vec3(0,1,0);
cam.defocusAngle = 0; cam.defocusAngle = 0;
cam.render(world); cam.render(world);
} }
@@ -344,6 +346,8 @@ void finalScene(int imageWidth, int samplesPerPixel, int maxDepth) {
hittableList world; hittableList world;
world.add(make_shared<bvh_node>(boxes1));
auto light = make_shared<diffuseLight>(colour(7, 7, 7)); auto light = make_shared<diffuseLight>(colour(7, 7, 7));
world.add(make_shared<quad>(point3(123, 554, 147), vec3(300, 0, 0), vec3(0, 0, 265), light)); world.add(make_shared<quad>(point3(123, 554, 147), vec3(300, 0, 0), vec3(0, 0, 265), light));
@@ -394,7 +398,7 @@ void finalScene(int imageWidth, int samplesPerPixel, int maxDepth) {
} }
int main(void) { int main(void) {
int sceneToShow = 9; int sceneToShow = 11;
switch (sceneToShow) { switch (sceneToShow) {
case 1: case 1:
@@ -428,7 +432,7 @@ int main(void) {
finalScene(800, 10000, 40); finalScene(800, 10000, 40);
break; break;
default: default:
finalScene(400, 250, 4); finalScene(400, 250, 40);
break; break;
} }
} }

View File

@@ -110,7 +110,8 @@ class isotropic : public material {
isotropic(const colour& albedo) : tex(make_shared<solidColour>(albedo)) {} isotropic(const colour& albedo) : tex(make_shared<solidColour>(albedo)) {}
isotropic(shared_ptr<texture> tex) : tex(tex) {} isotropic(shared_ptr<texture> tex) : tex(tex) {}
bool scatter(const ray& rIn, const hitRecord& rec, colour& attenuation, ray& scattered) { bool scatter(const ray& rIn, const hitRecord& rec, colour& attenuation, ray& scattered)
const override {
scattered = ray(rec.p, randomUnitVector(), rIn.time()); scattered = ray(rec.p, randomUnitVector(), rIn.time());
attenuation = tex->value(rec.u, rec.v, rec.p); attenuation = tex->value(rec.u, rec.v, rec.p);
return true; return true;