Implenting volume
This commit is contained in:
@@ -7,6 +7,7 @@ add_executable(Raytracer
|
||||
bvh.h
|
||||
camera.h
|
||||
colour.h
|
||||
constantMedium.h;
|
||||
hittable.h
|
||||
hittableList.h
|
||||
interval.h
|
||||
|
@@ -39,7 +39,7 @@
|
||||
{
|
||||
"directoryIndex" : 0,
|
||||
"id" : "Raytracer::@6890427a1f51a3e7e1df",
|
||||
"jsonFile" : "target-Raytracer-Debug-a7a28e10c70f59ab4ce6.json",
|
||||
"jsonFile" : "target-Raytracer-Debug-80207c993d1920bba46e.json",
|
||||
"name" : "Raytracer",
|
||||
"projectIndex" : 0
|
||||
}
|
@@ -26,7 +26,7 @@
|
||||
"objects" :
|
||||
[
|
||||
{
|
||||
"jsonFile" : "codemodel-v2-4489d9e12eae5f29aa72.json",
|
||||
"jsonFile" : "codemodel-v2-3366258bf3196947391e.json",
|
||||
"kind" : "codemodel",
|
||||
"version" :
|
||||
{
|
||||
@@ -99,7 +99,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"jsonFile" : "codemodel-v2-4489d9e12eae5f29aa72.json",
|
||||
"jsonFile" : "codemodel-v2-3366258bf3196947391e.json",
|
||||
"kind" : "codemodel",
|
||||
"version" :
|
||||
{
|
@@ -96,7 +96,8 @@
|
||||
13,
|
||||
14,
|
||||
15,
|
||||
16
|
||||
16,
|
||||
17
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -128,6 +129,11 @@
|
||||
"path" : "colour.h",
|
||||
"sourceGroupIndex" : 1
|
||||
},
|
||||
{
|
||||
"backtrace" : 1,
|
||||
"path" : "constantMedium.h",
|
||||
"sourceGroupIndex" : 1
|
||||
},
|
||||
{
|
||||
"backtrace" : 1,
|
||||
"path" : "hittable.h",
|
@@ -7,6 +7,7 @@ CMakeFiles/Raytracer.dir/main.cpp.o
|
||||
/home/cjsatnarine/Code/Raytracer/bvh.h
|
||||
/home/cjsatnarine/Code/Raytracer/camera.h
|
||||
/home/cjsatnarine/Code/Raytracer/colour.h
|
||||
/home/cjsatnarine/Code/Raytracer/constantMedium.h
|
||||
/home/cjsatnarine/Code/Raytracer/external/stb_image.h
|
||||
/home/cjsatnarine/Code/Raytracer/hittable.h
|
||||
/home/cjsatnarine/Code/Raytracer/hittableList.h
|
||||
|
@@ -6,6 +6,7 @@ CMakeFiles/Raytracer.dir/main.cpp.o: /home/cjsatnarine/Code/Raytracer/main.cpp \
|
||||
/home/cjsatnarine/Code/Raytracer/bvh.h \
|
||||
/home/cjsatnarine/Code/Raytracer/camera.h \
|
||||
/home/cjsatnarine/Code/Raytracer/colour.h \
|
||||
/home/cjsatnarine/Code/Raytracer/constantMedium.h \
|
||||
/home/cjsatnarine/Code/Raytracer/external/stb_image.h \
|
||||
/home/cjsatnarine/Code/Raytracer/hittable.h \
|
||||
/home/cjsatnarine/Code/Raytracer/hittableList.h \
|
||||
@@ -277,6 +278,8 @@ CMakeFiles/Raytracer.dir/main.cpp.o: /home/cjsatnarine/Code/Raytracer/main.cpp \
|
||||
|
||||
/usr/include/x86_64-linux-gnu/sys/cdefs.h:
|
||||
|
||||
/usr/include/x86_64-linux-gnu/gnu/stubs.h:
|
||||
|
||||
/usr/include/c++/13/math.h:
|
||||
|
||||
/usr/include/c++/13/bits/ostream_insert.h:
|
||||
@@ -361,10 +364,6 @@ CMakeFiles/Raytracer.dir/main.cpp.o: /home/cjsatnarine/Code/Raytracer/main.cpp \
|
||||
|
||||
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h:
|
||||
|
||||
/usr/include/c++/13/new:
|
||||
|
||||
/usr/include/c++/13/ext/alloc_traits.h:
|
||||
|
||||
/usr/include/c++/13/bits/stl_heap.h:
|
||||
|
||||
/usr/include/c++/13/bits/stl_construct.h:
|
||||
@@ -407,6 +406,8 @@ CMakeFiles/Raytracer.dir/main.cpp.o: /home/cjsatnarine/Code/Raytracer/main.cpp \
|
||||
|
||||
/usr/include/c++/13/bits/move.h:
|
||||
|
||||
/usr/include/c++/13/bits/memoryfwd.h:
|
||||
|
||||
/usr/include/x86_64-linux-gnu/bits/long-double.h:
|
||||
|
||||
/usr/include/c++/13/bits/algorithmfwd.h:
|
||||
@@ -495,6 +496,10 @@ CMakeFiles/Raytracer.dir/main.cpp.o: /home/cjsatnarine/Code/Raytracer/main.cpp \
|
||||
|
||||
/home/cjsatnarine/Code/Raytracer/hittable.h:
|
||||
|
||||
/usr/include/c++/13/ext/alloc_traits.h:
|
||||
|
||||
/usr/include/c++/13/new:
|
||||
|
||||
/usr/include/c++/13/bits/alloc_traits.h:
|
||||
|
||||
/usr/include/c++/13/bits/concept_check.h:
|
||||
@@ -559,22 +564,20 @@ CMakeFiles/Raytracer.dir/main.cpp.o: /home/cjsatnarine/Code/Raytracer/main.cpp \
|
||||
|
||||
/usr/include/x86_64-linux-gnu/bits/types.h:
|
||||
|
||||
/usr/include/c++/13/bits/localefwd.h:
|
||||
|
||||
/usr/include/c++/13/bits/streambuf_iterator.h:
|
||||
|
||||
/usr/include/x86_64-linux-gnu/bits/flt-eval-method.h:
|
||||
|
||||
/usr/include/c++/13/bits/cxxabi_init_exception.h:
|
||||
|
||||
/usr/include/c++/13/typeinfo:
|
||||
|
||||
/usr/include/c++/13/bits/exception.h:
|
||||
|
||||
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:
|
||||
|
||||
/usr/include/x86_64-linux-gnu/bits/uintn-identity.h:
|
||||
|
||||
/usr/include/c++/13/typeinfo:
|
||||
|
||||
/usr/include/c++/13/bits/localefwd.h:
|
||||
|
||||
/usr/include/c++/13/bits/streambuf_iterator.h:
|
||||
|
||||
/usr/include/x86_64-linux-gnu/bits/flt-eval-method.h:
|
||||
|
||||
/usr/include/c++/13/bits/functional_hash.h:
|
||||
|
||||
/usr/include/errno.h:
|
||||
@@ -591,6 +594,10 @@ CMakeFiles/Raytracer.dir/main.cpp.o: /home/cjsatnarine/Code/Raytracer/main.cpp \
|
||||
|
||||
/usr/include/stdint.h:
|
||||
|
||||
/usr/include/c++/13/bits/cxxabi_init_exception.h:
|
||||
|
||||
/home/cjsatnarine/Code/Raytracer/constantMedium.h:
|
||||
|
||||
/usr/include/c++/13/bits/uniform_int_dist.h:
|
||||
|
||||
/usr/include/c++/13/bits/locale_classes.tcc:
|
||||
@@ -605,8 +612,6 @@ CMakeFiles/Raytracer.dir/main.cpp.o: /home/cjsatnarine/Code/Raytracer/main.cpp \
|
||||
|
||||
/usr/include/wchar.h:
|
||||
|
||||
/usr/include/c++/13/bits/memoryfwd.h:
|
||||
|
||||
/usr/include/c++/13/exception:
|
||||
|
||||
/usr/include/c++/13/pstl/glue_memory_defs.h:
|
||||
@@ -691,8 +696,6 @@ CMakeFiles/Raytracer.dir/main.cpp.o: /home/cjsatnarine/Code/Raytracer/main.cpp \
|
||||
|
||||
/usr/include/x86_64-linux-gnu/bits/endian.h:
|
||||
|
||||
/usr/include/x86_64-linux-gnu/gnu/stubs.h:
|
||||
|
||||
/usr/include/c++/13/bits/requires_hosted.h:
|
||||
|
||||
/usr/include/x86_64-linux-gnu/bits/floatn-common.h:
|
||||
|
Binary file not shown.
@@ -215,5 +215,6 @@ CMakeFiles/Raytracer.dir/main.cpp.o: \
|
||||
/home/cjsatnarine/Code/Raytracer/external/stb_image.h \
|
||||
/usr/include/c++/13/stdlib.h /usr/include/string.h \
|
||||
/usr/include/strings.h /usr/include/c++/13/math.h /usr/include/assert.h \
|
||||
/home/cjsatnarine/Code/Raytracer/constantMedium.h \
|
||||
/home/cjsatnarine/Code/Raytracer/quad.h \
|
||||
/home/cjsatnarine/Code/Raytracer/sphere.h
|
||||
|
BIN
build/Raytracer
BIN
build/Raytracer
Binary file not shown.
65
constantMedium.h
Normal file
65
constantMedium.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef CONSTANT_MEDIUM_H
|
||||
#define CONSTANT_MEDIUM_H
|
||||
|
||||
#include "rayTracer.h"
|
||||
#include "hittable.h"
|
||||
#include "material.h"
|
||||
#include "texture.h"
|
||||
|
||||
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, const colour& albedo) : boundary(boundary), negativeInvDensity(-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;
|
||||
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(rec1.t+0.0001, infinity), rec2)) return false;
|
||||
|
||||
if (debugging) std::clog << "\ntMin=" << rec1.t << ", tMax=" << rec2.t << '\n';
|
||||
|
||||
if (rec1.t < rayT.min) rec1.t = rayT.min;
|
||||
if (rec2.t > rayT.max) rec2.t = rayT.max;
|
||||
|
||||
if (rec1.t >= rec2.t) return false;
|
||||
|
||||
if (rec1.t < 0) rec1.t = 0;
|
||||
|
||||
auto rayLength = r.direction().length();
|
||||
auto distanceInsideBoundary = (rec2.t - rec1.t) * rayLength;
|
||||
auto hitDistance = negativeInvDensity * log(randomDouble());
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
rec.normal = vec3(1, 0, 0); // arbitrary
|
||||
rec.frontFace = true; // also abritrary
|
||||
rec.mat = phaseFunction;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
aabb boundingBox() const override {
|
||||
return boundary->boundingBox();
|
||||
}
|
||||
|
||||
private:
|
||||
shared_ptr<hittable> boundary;
|
||||
double negativeInvDensity;
|
||||
shared_ptr<material> phaseFunction;
|
||||
};
|
||||
|
||||
#endif
|
48
main.cpp
48
main.cpp
@@ -1,6 +1,7 @@
|
||||
#include "rayTracer.h"
|
||||
#include "bvh.h"
|
||||
#include "camera.h"
|
||||
#include "constantMedium.h"
|
||||
#include "hittable.h"
|
||||
#include "hittableList.h"
|
||||
#include "material.h"
|
||||
@@ -279,8 +280,50 @@ void cornellBox() {
|
||||
cam.render(world);
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
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(113,554,127), vec3(330,0,0), vec3(0,0,305), light));
|
||||
world.add(make_shared<quad>(point3(0,555,0), vec3(555,0,0), vec3(0,0,555), white));
|
||||
world.add(make_shared<quad>(point3(0,0,0), vec3(555,0,0), vec3(0,0,555), white));
|
||||
world.add(make_shared<quad>(point3(0,0,555), vec3(555,0,0), vec3(0,555,0), white));
|
||||
|
||||
shared_ptr<hittable> box1 = box(point3(0,0,0), point3(165,330,165), white);
|
||||
box1 = make_shared<rotateY>(box1, 15);
|
||||
box1 = make_shared<translate>(box1, vec3(265,0,295));
|
||||
|
||||
shared_ptr<hittable> box2 = box(point3(0,0,0), point3(165,165,165), white);
|
||||
box2 = make_shared<rotateY>(box2, -18);
|
||||
box2 = make_shared<translate>(box2, vec3(130,0,65));
|
||||
|
||||
world.add(make_shared<constantMedium>(box1, 0.01, colour(0,0,0)));
|
||||
world.add(make_shared<constantMedium>(box2, 0.01, colour(1,1,1)));
|
||||
|
||||
camera cam;
|
||||
cam.aspectRatio = 1.0;
|
||||
cam.imageWidth = 600;
|
||||
cam.samplesPerPixel = 200;
|
||||
cam.maxDepth = 50;
|
||||
cam.background = colour(0, 0, 0);
|
||||
|
||||
cam.vFieldOfView = 40;
|
||||
cam.lookFrom = point3(278, 278, -800);
|
||||
cam.lookAt = point3(278, 278, 0);
|
||||
cam.vUp = vec3(0, 1, 0);
|
||||
|
||||
cam.defocusAngle = 0;
|
||||
cam.render(world);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int sceneToShow = 8;
|
||||
int sceneToShow = 9;
|
||||
|
||||
switch (sceneToShow) {
|
||||
case 1:
|
||||
@@ -307,5 +350,8 @@ int main(void) {
|
||||
case 8:
|
||||
cornellBox();
|
||||
break;
|
||||
case 9:
|
||||
cornellSmoke();
|
||||
break;
|
||||
}
|
||||
}
|
15
material.h
15
material.h
@@ -105,4 +105,19 @@ class diffuseLight : public material {
|
||||
shared_ptr<texture> tex;
|
||||
};
|
||||
|
||||
class isotropic : public material {
|
||||
public:
|
||||
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) {
|
||||
scattered = ray(rec.p, randomUnitVector(), rIn.time());
|
||||
attenuation = tex->value(rec.u, rec.v, rec.p);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
shared_ptr<texture> tex;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user