Skip to content

Commit

Permalink
Rename tl and br to min_vert and max_vert
Browse files Browse the repository at this point in the history
  • Loading branch information
Aniruddha-Deb committed Apr 7, 2024
1 parent 48ee919 commit 249a1ad
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion a3_cpp/src/cornell_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CornellBoxScene : public Scene
spheres.push_back(refractive_sphere);

AxisAlignedBox refractive_box =
AxisAlignedBox({.tl = glm::vec3(0.f, -2.f, -5.f), .br = glm::vec3(1.f, 0.f, -4.5f)}, glass_material);
AxisAlignedBox({.min_vert = glm::vec3(0.f, -2.f, -5.f), .max_vert = glm::vec3(1.f, 0.f, -4.5f)}, glass_material);
boxes.push_back(refractive_box);

objects.insert(objects.end(), walls.begin(), walls.end());
Expand Down
2 changes: 1 addition & 1 deletion a3_cpp/src/cornell_box_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class CornellBoxScene : public Scene
// spheres.push_back(refractive_sphere);

// AxisAlignedBox refractive_box =
// AxisAlignedBox({.tl = glm::vec3(0.f, -2.f, -5.f), .br = glm::vec3(1.f, 0.f, -4.5f)}, glass_material);
// AxisAlignedBox({.min_vert = glm::vec3(0.f, -2.f, -5.f), .max_vert = glm::vec3(1.f, 0.f, -4.5f)}, glass_material);
// boxes.push_back(refractive_box);

objects.insert(objects.end(), walls.begin(), walls.end());
Expand Down
2 changes: 1 addition & 1 deletion a3_cpp/src/cornell_box_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CornellBoxScene : public Scene
// spheres.push_back(refractive_sphere);

// AxisAlignedBox refractive_box =
// AxisAlignedBox({.tl = glm::vec3(0.f, -2.f, -5.f), .br = glm::vec3(1.f, 0.f, -4.5f)}, glass_material);
// AxisAlignedBox({.min_vert = glm::vec3(0.f, -2.f, -5.f), .max_vert = glm::vec3(1.f, 0.f, -4.5f)}, glass_material);
// boxes.push_back(refractive_box);

objects.insert(objects.end(), walls.begin(), walls.end());
Expand Down
2 changes: 1 addition & 1 deletion a3_cpp/src/cornell_box_transformed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CornellBoxScene : public Scene
// spheres.push_back(refractive_sphere);

AxisAlignedBox refractive_box =
AxisAlignedBox({.tl = glm::vec3(-.5f, -2.0f, -.5f), .br = glm::vec3(.5f, .5f, .5f)}, glass_material);
AxisAlignedBox({.min_vert = glm::vec3(-.5f, -2.0f, -.5f), .max_vert = glm::vec3(.5f, .5f, .5f)}, glass_material);
glm::mat4x4 box_rotate = glm::rotate(glm::mat4x4(1.f), glm::radians(45.f), glm::vec3(0.f, 1.f, 0.f));
glm::mat4x4 box_translate = glm::translate(glm::mat4x4(1.f), glm::vec3(3.f, 0.f, -2.f));
refractive_box.transform(box_rotate);
Expand Down
2 changes: 1 addition & 1 deletion a3_cpp/src/creative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class CornellBoxScene : public Scene
spheres.push_back(refractive_sphere);

AxisAlignedBox reflective_box =
AxisAlignedBox({.tl = glm::vec3(0.75f, 0.0f, -4.f), .br = glm::vec3(1.0f, 1.0f, -5.0f)}, copper_material);
AxisAlignedBox({.min_vert = glm::vec3(1.5f, 0.0f, -4.f), .max_vert = glm::vec3(2.0f, 1.0f, -3.0f)}, glass_material);
boxes.push_back(reflective_box);

reflective_box.transform(glm::rotate(glm::mat4(1.0f), glm::radians(10.0f), glm::vec3(1.0f, 0.0f, 0.0f)));
Expand Down
32 changes: 16 additions & 16 deletions a3_cpp/src/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ bool Sphere::hit(const Ray& ws_ray, float t_min, float t_max, HitRecord& rec) co
Box Sphere::bounding_box()
{
Box box;
box.tl = center - glm::vec3(radius, radius, radius);
box.br = center + glm::vec3(radius, radius, radius);
box.min_vert = center - glm::vec3(radius, radius, radius);
box.max_vert = center + glm::vec3(radius, radius, radius);
return box;
}

Expand All @@ -144,8 +144,8 @@ Box Plane::bounding_box()
{
Box box;
// Assume the plane is infinite, so return a large bounding box
box.tl = glm::vec3(-1e9, -1e9, -1e9);
box.br = glm::vec3(1e9, 1e9, 1e9);
box.min_vert = glm::vec3(-1e9, -1e9, -1e9);
box.max_vert = glm::vec3(1e9, 1e9, 1e9);
return box;
}

Expand All @@ -156,8 +156,8 @@ bool AxisAlignedBox::hit(const Ray& ws_ray, float t_min, float t_max, HitRecord&

glm::vec3 inv_direction = 1.0f / d;

glm::vec3 t0 = (box.tl - o) * inv_direction;
glm::vec3 t1 = (box.br - o) * inv_direction;
glm::vec3 t0 = (box.min_vert - o) * inv_direction;
glm::vec3 t1 = (box.max_vert - o) * inv_direction;

glm::vec3 tmin = glm::min(t0, t1);
glm::vec3 tmax = glm::max(t0, t1);
Expand Down Expand Up @@ -188,21 +188,21 @@ bool AxisAlignedBox::hit(const Ray& ws_ray, float t_min, float t_max, HitRecord&
glm::vec3 os_pos = o + os_t * d;
glm::vec3 os_normal;

if (glm::abs(os_pos.x - box.tl.x) < EPS)
if (glm::abs(os_pos.x - box.min_vert.x) < EPS)
os_normal = glm::vec3(-1, 0, 0);
else if (glm::abs(os_pos.x - box.br.x) < EPS)
else if (glm::abs(os_pos.x - box.max_vert.x) < EPS)
os_normal = glm::vec3(1, 0, 0);
else if (glm::abs(os_pos.y - box.tl.y) < EPS)
else if (glm::abs(os_pos.y - box.min_vert.y) < EPS)
os_normal = glm::vec3(0, -1, 0);
else if (glm::abs(os_pos.y - box.br.y) < EPS)
else if (glm::abs(os_pos.y - box.max_vert.y) < EPS)
os_normal = glm::vec3(0, 1, 0);
else if (glm::abs(os_pos.z - box.tl.z) < EPS)
else if (glm::abs(os_pos.z - box.min_vert.z) < EPS)
os_normal = glm::vec3(0, 0, -1);
else if (glm::abs(os_pos.z - box.br.z) < EPS)
else if (glm::abs(os_pos.z - box.max_vert.z) < EPS)
os_normal = glm::vec3(0, 0, 1);

bool ray_originated_in_object = (box.tl.x - EPS < o.x && box.br.x + EPS > o.x && box.tl.y - EPS < o.y &&
box.br.y + EPS > o.y && box.tl.z - EPS < o.z && box.br.z + EPS > o.z);
bool ray_originated_in_object = (box.min_vert.x - EPS < o.x && box.max_vert.x + EPS > o.x && box.min_vert.y - EPS < o.y &&
box.max_vert.y + EPS > o.y && box.min_vert.z - EPS < o.z && box.max_vert.z + EPS > o.z);

populate_hitrecord(ws_ray, os_ray, os_pos, os_normal, ray_originated_in_object, *this, rec);
return true;
Expand Down Expand Up @@ -248,8 +248,8 @@ bool Triangle::hit(const Ray& ws_ray, float t_min, float t_max, HitRecord& rec)
Box Triangle::bounding_box()
{
Box box;
box.tl = glm::min(glm::min(p0, p1), p2);
box.br = glm::max(glm::max(p0, p1), p2);
box.min_vert = glm::min(glm::min(p0, p1), p2);
box.max_vert = glm::max(glm::max(p0, p1), p2);
return box;
}

Expand Down
1 change: 1 addition & 0 deletions a3_cpp/src/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class Mesh : public Object
public:
std::vector<glm::vec3> verts;
std::vector<glm::ivec3> idxs;
Box bbox;
Mesh(std::shared_ptr<Material>& _mat) :
Object{_mat} {}

Expand Down
2 changes: 1 addition & 1 deletion a3_cpp/src/ray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct Ray

struct Box
{
glm::vec3 tl, br;
glm::vec3 min_vert, max_vert;
};

struct HitRecord
Expand Down
4 changes: 2 additions & 2 deletions a3_cpp/src/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ glm::vec3 tone_map(glm::vec3 color)
return glm::min(glm::vec3(1.f, 1.f, 1.f), color);
}

Renderer::Renderer(Window &_w, Scene &_s, int _spp, bool _path_traced, int _curr_sample_no)
: win{_w}, scene{_s}, spp{_spp}, path_traced{_path_traced}, curr_sample_no{_curr_sample_no}
Renderer::Renderer(Window &_w, Scene &_s, int _spp, bool _path_traced)
: win{_w}, scene{_s}, spp{_spp}, path_traced{_path_traced}, curr_sample_no{0}
{
framebuffer = SDL_CreateRGBSurface(0, win.w, win.h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0);
if (path_traced)
Expand Down
2 changes: 1 addition & 1 deletion a3_cpp/src/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Renderer
bool path_traced;

public:
Renderer(Window& w, Scene& s, int _spp = 1, bool path_traced = false, int _curr_sample_no = 0);
Renderer(Window& w, Scene& s, int _spp = 1, bool path_traced = false);
~Renderer();

void render();
Expand Down
9 changes: 6 additions & 3 deletions a3_cpp/todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
- [X] AxisAlignedBox
- [X] Triangle
- [X] Mouse right click camera
- [ ] Path tracing
- [X] Path tracing
- [X] Russian Roulette
- [X] Importance Sampling
- [X] Accumulating samples
- [X] Materials ported
- [X] Diffuse
- [X] Emissive
- [ ] Reflective
- [ ] Transparent
- [X] Reflective
- [X] Transparent
- [X] Mesh loading
- [X] Mesh intersection
- [ ] BB hit test (early exit)
- [ ] Get max, min of all verts that make up the mesh
- [X] Interesting Scene

- [ ] Multisampling?
- [ ] Parallelizing
- [ ] Cook-Torrance material?

0 comments on commit 249a1ad

Please sign in to comment.