Minor fixes
This commit is contained in:
Binary file not shown.
BIN
build/Raytracer
BIN
build/Raytracer
Binary file not shown.
@@ -8,45 +8,52 @@
|
||||
|
||||
class constantMedium : public hittable {
|
||||
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 {
|
||||
// Print occasional samples when debugging. To enable, set enableDebug true;
|
||||
bool hit(const ray& r, interval ray_t, hitRecord& rec) const override {
|
||||
// Print occasional samples when debugging. To enable, set enableDebug true.
|
||||
const bool enableDebug = false;
|
||||
const bool debugging = enableDebug && randomDouble() < 0.00001;
|
||||
|
||||
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 (rec2.t > rayT.max) rec2.t = rayT.max;
|
||||
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 >= rec2.t)
|
||||
return false;
|
||||
|
||||
if (rec1.t < 0) rec1.t = 0;
|
||||
if (rec1.t < 0)
|
||||
rec1.t = 0;
|
||||
|
||||
auto rayLength = r.direction().length();
|
||||
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.p = r.at(rec.t);
|
||||
|
||||
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.frontFace = true; // also abritrary
|
||||
rec.frontFace = true; // also arbitrary
|
||||
rec.mat = phaseFunction;
|
||||
|
||||
return true;
|
||||
@@ -58,7 +65,7 @@ class constantMedium : public hittable {
|
||||
|
||||
private:
|
||||
shared_ptr<hittable> boundary;
|
||||
double negativeInvDensity;
|
||||
double negInvDensity;
|
||||
shared_ptr<material> phaseFunction;
|
||||
};
|
||||
|
||||
|
16
main.cpp
16
main.cpp
@@ -283,10 +283,10 @@ void cornellBox() {
|
||||
void cornellSmoke() {
|
||||
hittableList world;
|
||||
|
||||
auto red = make_shared<lambertian>(colour(0.65, 0.05, 0.05));
|
||||
auto white = make_shared<lambertian>(colour(0.73, 0.73, 0.73));
|
||||
auto green = make_shared<lambertian>(colour(0.12, 0.45, 0.15));
|
||||
auto light = make_shared<diffuseLight>(colour(15, 15, 15));
|
||||
auto red = make_shared<lambertian>(colour(.65, .05, .05));
|
||||
auto white = make_shared<lambertian>(colour(.73, .73, .73));
|
||||
auto green = make_shared<lambertian>(colour(.12, .45, .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(0,0,0), vec3(0,555,0), vec3(0,0,555), red));
|
||||
@@ -307,6 +307,7 @@ void cornellSmoke() {
|
||||
world.add(make_shared<constantMedium>(box2, 0.01, colour(1,1,1)));
|
||||
|
||||
camera cam;
|
||||
|
||||
cam.aspectRatio = 1.0;
|
||||
cam.imageWidth = 600;
|
||||
cam.samplesPerPixel = 200;
|
||||
@@ -319,6 +320,7 @@ void cornellSmoke() {
|
||||
cam.vUp = vec3(0,1,0);
|
||||
|
||||
cam.defocusAngle = 0;
|
||||
|
||||
cam.render(world);
|
||||
}
|
||||
|
||||
@@ -344,6 +346,8 @@ void finalScene(int imageWidth, int samplesPerPixel, int maxDepth) {
|
||||
|
||||
hittableList world;
|
||||
|
||||
world.add(make_shared<bvh_node>(boxes1));
|
||||
|
||||
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));
|
||||
|
||||
@@ -394,7 +398,7 @@ void finalScene(int imageWidth, int samplesPerPixel, int maxDepth) {
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int sceneToShow = 9;
|
||||
int sceneToShow = 11;
|
||||
|
||||
switch (sceneToShow) {
|
||||
case 1:
|
||||
@@ -428,7 +432,7 @@ int main(void) {
|
||||
finalScene(800, 10000, 40);
|
||||
break;
|
||||
default:
|
||||
finalScene(400, 250, 4);
|
||||
finalScene(400, 250, 40);
|
||||
break;
|
||||
}
|
||||
}
|
@@ -110,7 +110,8 @@ class isotropic : public material {
|
||||
isotropic(const colour& albedo) : tex(make_shared<solidColour>(albedo)) {}
|
||||
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());
|
||||
attenuation = tex->value(rec.u, rec.v, rec.p);
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user