diff --git a/includes/RT/objects/Portal.hpp b/includes/RT/objects/Portal.hpp index dd5561b..e1ab03f 100644 --- a/includes/RT/objects/Portal.hpp +++ b/includes/RT/objects/Portal.hpp @@ -24,8 +24,6 @@ class Portal : public Object float x1, y1, z1; float x2, y2, z2; - bool invert_normal; - int mat_index; if (!(line >> x >> y >> z)) @@ -37,7 +35,7 @@ class Portal : public Object if (!(line >> x2 >> y2 >> z2)) throw std::runtime_error("Missing Portal's second edge"); - if (!(line >> invert_normal)) + if (!(line >> _invert_normal)) throw std::runtime_error("Missing invert_normal"); if (!(line >> mat_index)) @@ -47,14 +45,18 @@ class Portal : public Object _up = glm::vec3(x1, y1, z1); _right = glm::vec3(x2, y2, z2); - glm::vec3 up = glm::normalize(_up); + // glm::vec3 temp_right = _right; + // _right = _invert_normal ? _up : _right; + // _up = _invert_normal ? temp_right : _up; + glm::vec3 right = glm::normalize(_right); + glm::vec3 up = glm::normalize(_up); glm::vec3 forward = glm::normalize(glm::cross(right, up)); - up = normalize(glm::cross(forward, right)); + // up = normalize(glm::cross(forward, right)); _rotation = glm::mat3(right, up, forward); - _normal = forward * (invert_normal ? -1.0f : 1.0f); + _normal = forward * (_invert_normal ? -1.0f : 1.0f); _linked_portal = -1; @@ -67,19 +69,23 @@ class Portal : public Object { float extension = 0.2f; - glm::vec3 right_dir = glm::normalize(_up); - glm::vec3 up_dir = glm::normalize(_right); + glm::vec3 right_dir = glm::normalize(_right); + glm::vec3 up_dir = glm::normalize(_up); - float right_length = glm::length(_up) + extension; - float up_length = glm::length(_right) + extension; + // glm::vec3 temp_right = right_dir; + // right_dir = _invert_normal ? right_dir : up_dir; + // up_dir = _invert_normal ? up_dir : temp_right; + + float right_length = glm::length(_right) + extension; + float up_length = glm::length(_up) + extension; glm::vec3 center_offset = -(right_dir * (extension / 2.0f) + up_dir * (extension / 2.0f)); - glm::vec3 position = _position + _normal * -0.001f + center_offset; + glm::vec3 position = _position + _normal * 0.001f + center_offset; glm::vec3 right = right_dir * right_length; glm::vec3 up = up_dir * up_length; - - return (new Quad(position, right, up, _mat_index)); + // position += 10; + return (new Quad(position, right, up, _normal, 1, _mat_index)); } glm::vec3 getUp() const { return (_up); } @@ -101,6 +107,7 @@ class Portal : public Object glm::mat3 _rotation; int _linked_portal; + int _invert_normal; }; #endif \ No newline at end of file diff --git a/includes/RT/objects/Quad.hpp b/includes/RT/objects/Quad.hpp index 3df3ff1..e1f17f9 100644 --- a/includes/RT/objects/Quad.hpp +++ b/includes/RT/objects/Quad.hpp @@ -23,6 +23,7 @@ class Quad : public Object float x, y, z; float x1, y1, z1; float x2, y2, z2; + bool double_face; int mat_index; if (!(line >> x >> y >> z)) @@ -33,6 +34,9 @@ class Quad : public Object if (!(line >> x2 >> y2 >> z2)) throw std::runtime_error("Missing quad's second edge"); + + if (!(line >> _single_sided)) + throw std::runtime_error("Missing double_face"); if (!(line >> mat_index)) throw std::runtime_error("Missing material properties"); @@ -41,18 +45,25 @@ class Quad : public Object _up = glm::vec3(x1, y1, z1); _right = glm::vec3(x2, y2, z2); + _normal = glm::normalize(glm::cross(_up, _right)); + _mat_index = mat_index; } - Quad(const glm::vec3 &position, const glm::vec3 &edge1, const glm::vec3 &edge2, const int mat_index) - : Object(position, mat_index), _up(edge1), _right(edge2) {} + Quad(const glm::vec3 &position, const glm::vec3 &edge1, const glm::vec3 &edge2, const glm::vec3 &normal, const int single_sided, const int mat_index) + : Object(position, mat_index), _up(edge1), _right(edge2), _normal(normal), _single_sided(single_sided) {} glm::vec3 getUp() const { return (_up); } glm::vec3 getRight() const { return (_right); } + glm::vec3 getNormal() const { return (_normal); } + int getSingleSided() const { return (_single_sided); } Type getType() const override { return Type::QUAD; } + private: glm::vec3 _up; glm::vec3 _right; + glm::vec3 _normal; + int _single_sided; }; #endif \ No newline at end of file diff --git a/scenes/lambo.rt b/scenes/lambo.rt index bc083a1..f29e63b 100644 --- a/scenes/lambo.rt +++ b/scenes/lambo.rt @@ -2,7 +2,7 @@ CAM -2.41462 2.57199 4.09049 -1.80012 -50.2012 0.02 2.973 45.75 MAT 20 20 20 0. 0.9 0.5 // 0 gray # pl 0 5.2 0 0 -1 0 0 // floor -qu -5 5 -5 10 0 0 0 0 10 0 +qu -5 5 -5 0 0 10 10 0 0 0 MAT 255 100 100 1.0 0.0 0.0 //1 red diff --git a/scenes/noneuclidian.rt b/scenes/noneuclidian.rt new file mode 100644 index 0000000..4a75efa --- /dev/null +++ b/scenes/noneuclidian.rt @@ -0,0 +1,20 @@ +CAM 0 2.59881 7 -4.8 -89.9996 0 1 90 5 + +MAT 100 200 100 0.0 0.0 0.0 // 0 +MAT 200 200 200 0.0 0.0 0.0 // 1 + +MAT 200 200 200 0 0 0 // 2 portal + +pl 0 0 0 0 1 0 0 + +po -1.5 0 4.5 3 0 0 0 3 0 0 2 +po -1.5 0 -4.5 3 0 0 0 3 0 1 2 + +qu -1.5 0 -5 0 3 0 0 0 10 0 1 +qu 1.5 0 -5 0 3 0 0 0 10 0 1 + +qu -1.5 3 -5 3 0 0 0 0 10 0 1 + + + +cu 10 1.5 0 3 3 5 1 diff --git a/scenes/pillard.rt b/scenes/pillard.rt index 6a586e4..a84ba6d 100644 --- a/scenes/pillard.rt +++ b/scenes/pillard.rt @@ -8,7 +8,7 @@ sp +0.000 +17.00 +20.00 4.0 0 sp +0.000 +17.00 +0.000 4.0 1 sp +0.000 +17.00 -20.00 4.0 2 -MAT 250 250 250 0.0 1.5 0.0 DIE -1 // 3 white 0 0 1 +MAT 250 250 250 0.0 1.2 0.0 DIE -1 // 3 white 0 0 1 MAT 250 250 250 0.0 1.0 1.0 // 4 white 0 1 0 MAT 200 200 200 0.0 0.0 0.0 // 5 white 1 0 0 diff --git a/scenes/portalcornell.rt b/scenes/portalcornell.rt index 5f16f4e..15146bc 100644 --- a/scenes/portalcornell.rt +++ b/scenes/portalcornell.rt @@ -22,8 +22,8 @@ qu -1 4 -1 2 0 0 0 0 2 2 cu 0 2.5 0 5 5 5 1 -po -1 1 -1.5 0 2 0 2 0 0 0 3 -po -1 1 1.5 0 2 0 2 0 0 1 4 +po -1 1 -1.5 0 2 0 2 0 0 1 3 +po -1 1 1.5 0 2 0 2 0 0 0 4 -po -1.5 1 -1 0 2 0 0 0 2 1 5 -po 1.5 1 -1 0 2 0 0 0 2 0 6 +po -1.5 1 -1 0 2 0 0 0 2 0 5 +po 1.5 1 -1 0 2 0 0 0 2 1 6 diff --git a/scenes/portalrotation.rt b/scenes/portalrotation.rt index 3278d2e..d765ace 100644 --- a/scenes/portalrotation.rt +++ b/scenes/portalrotation.rt @@ -18,5 +18,5 @@ pl -3 0 0 1 0 0 3 pl 0 0 -3 0 0 1 4 pl 0 0 3 0 0 -1 2 -po -0.33 -0.66 -1 0 1 0 0.5 0.5 -0.5 0 2 -po -0.5 -0.5 1 0 1 0 1 0 0 1 4 \ No newline at end of file +po -0.5 -0.5 -1 0 1 0 1 0.5 0.5 1 2 +po -0.5 -0.5 1 0 1 0 1 0 0 0 4 \ No newline at end of file diff --git a/scenes/roughness.rt b/scenes/roughness.rt index 5e475c7..2eb97be 100644 --- a/scenes/roughness.rt +++ b/scenes/roughness.rt @@ -40,5 +40,5 @@ sp 2.4 1.5 -1 1.5 14 // light quad -qu -1 2.999 -1 2 0 0 0 0 2 0 +qu -1 2.999 -1 0 0 2 2 0 0 0 diff --git a/scenes/stairs.rt b/scenes/stairs.rt index 91b2b84..d3d58a3 100644 --- a/scenes/stairs.rt +++ b/scenes/stairs.rt @@ -65,7 +65,7 @@ cu -9 0.98 3 3 3 3 28 MAT 244 95 28 0.0 0.5 1.0 cu -9 1.23 -6 3 3 3 29 -MAT 200 20 20 0.0 1.0 0.05 LAM 0 +MAT 200 20 20 0.0 1.0 0.05 LAM -1 MAT 255 255 255 0.0 1.8 0.0 DIE -1 MAT 255 255 255 0.0 1.0 1.0 diff --git a/scenes/test.rt b/scenes/test.rt index 0f4cd70..dd47a1b 100644 --- a/scenes/test.rt +++ b/scenes/test.rt @@ -1,6 +1,18 @@ -CAM -0.181956 1.3733 2.83437 -16 -87.8001 0 1 90 5 +CAM 0 1.3733 2.83437 -16 -87.8001 0 1 90 5 -MAT 255 255 255 10.0 1.0 0.0 //white -# sp 0 0 0 1 0 +# MAT 255 255 255 0.0 1.5 0.0 DIE -1 // 0 +# sp 0 0 0 12.5 0 + +TEX skymap.hdr +MAT 255 255 255 1.0 0.0 0.0 LAM 0 // 0 + +MAT 255 255 255 0.0 0.0 0.0 // 1 + + +sp 0 2 0 150 0 + +OBJ scenes/obj/jinx.obj -10 0 0 1.25 0 0 0 +# OBJ scenes/obj/Dragon_800K.obj 0 0 0 35 0 0 0 1 + +OBJ scenes/obj/whitedragon.obj 0 0 0 1 0 0 0 -OBJ scenes/obj/jinx.obj 0 0 0 1 diff --git a/shaders/intersect.glsl b/shaders/intersect.glsl index 543ca42..ddc1fea 100644 --- a/shaders/intersect.glsl +++ b/shaders/intersect.glsl @@ -42,10 +42,10 @@ bool intersectPlane(Ray ray, GPUObject obj, out hitInfo hit) bool intersectQuad(Ray ray, GPUObject obj, out hitInfo hit) { - vec3 normal = normalize(cross(obj.vertex1, obj.vertex2)); + vec3 normal = obj.normal; float d = dot(normal, ray.direction); - if (d == 0.0) return (false); + if (d == 0.0 || (obj.radius != 0.0 && d <= 0)) return (false); // double sided or not float t = dot(obj.position - ray.origin, normal) / d; @@ -64,6 +64,7 @@ bool intersectQuad(Ray ray, GPUObject obj, out hitInfo hit) hit.t = t; hit.position = p + obj.position; hit.normal = normal * -sign(d); + // hit.normal = normal; return (inside); } diff --git a/shaders/trace.glsl b/shaders/trace.glsl index 57ef4d8..50067f2 100644 --- a/shaders/trace.glsl +++ b/shaders/trace.glsl @@ -171,7 +171,7 @@ hitInfo traceRay(Ray ray) hitInfo hitScene; hitInfo hit; - #if 0 + #if 1 for (int i = 0; i < 10; i++) // portal ray { hitBVH = traverseBVHs(ray); diff --git a/srcs/class/Scene.cpp b/srcs/class/Scene.cpp index 7e6ab5d..7c50bc5 100644 --- a/srcs/class/Scene.cpp +++ b/srcs/class/Scene.cpp @@ -91,6 +91,8 @@ void Scene::addObject(Object *obj) auto quad = static_cast(obj); gpu_obj.vertex1 = quad->getUp(); gpu_obj.vertex2 = quad->getRight(); + gpu_obj.normal = quad->getNormal(); + gpu_obj.radius = quad->getSingleSided(); } else if (obj->getType() == Object::Type::CUBE) { diff --git a/srcs/class/SceneParser.cpp b/srcs/class/SceneParser.cpp index b499c3b..cc20dfa 100644 --- a/srcs/class/SceneParser.cpp +++ b/srcs/class/SceneParser.cpp @@ -132,7 +132,7 @@ void SceneParser::parseObj(std::stringstream &line) void SceneParser::parseTexture(std::stringstream &line) { std::string path; - + if (!(line >> path)) throw std::runtime_error("Texture: Missing texture's path");