From 8103f3e1f8d9f3a6d76d6b8f364c5b7d41f9c360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Guimar=C3=A3es?= Date: Wed, 16 Jul 2025 00:06:01 -0300 Subject: [PATCH] . --- ARCHITECTURE.md | 4 ++++ src/include/Prism/core/color.hpp | 12 +++++------- src/include/Prism/core/utils.hpp | 5 ++--- src/include/Prism/objects/ObjReader.hpp | 4 ++-- src/include/Prism/objects/mesh.hpp | 4 ++-- src/include/Prism/objects/triangle.hpp | 6 +++--- src/include/Prism/scene/light.hpp | 12 +++++++----- src/include/Prism/scene/scene.hpp | 6 +++--- src/src/core/color.cpp | 9 +++++---- src/src/core/utils.cpp | 2 +- src/src/objects/mesh.cpp | 23 +++++++---------------- src/src/objects/triangle.cpp | 7 ++++--- src/src/scene/scene.cpp | 6 +++--- src/src/scene/scene_parser.cpp | 3 +-- 14 files changed, 49 insertions(+), 54 deletions(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 978acb1..d3bea17 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -125,6 +125,7 @@ graph TD; SCENE["🎬 Scene"]; CAMERA["📷 Camera"]; SCENE_PARSER["📄 SceneParser"]; + LIGHT["💡 Light"]; end subgraph "External Dependency" @@ -132,7 +133,10 @@ graph TD; end SCENE --> CAMERA; + SCENE --> LIGHT; + SCENE_PARSER --> CAMERA; SCENE_PARSER --> YAML_CPP; SCENE_PARSER --> SCENE; + ``` diff --git a/src/include/Prism/core/color.hpp b/src/include/Prism/core/color.hpp index 8726ac7..9f1a7b0 100644 --- a/src/include/Prism/core/color.hpp +++ b/src/include/Prism/core/color.hpp @@ -42,17 +42,15 @@ class PRISM_EXPORT Color { */ Color(const Color& other); - Color operator* (Color other) const; + Color operator*(Color other) const; - Color operator* (double scalar) const; - - Color operator+ (Color other) const; + Color operator*(double scalar) const; - Color operator+= (Color other); - - Color& clamp(); + Color operator+(Color other) const; + Color operator+=(Color other); + Color& clamp(); double r; ///< Red component of the color (0.0 to 1.0) double g; ///< Green component of the color (0.0 to 1.0) diff --git a/src/include/Prism/core/utils.hpp b/src/include/Prism/core/utils.hpp index ea7260a..d14e254 100644 --- a/src/include/Prism/core/utils.hpp +++ b/src/include/Prism/core/utils.hpp @@ -55,8 +55,8 @@ Vector3 PRISM_EXPORT refract(const Vector3& uv, const Vector3& n, double etai_ov /** * @brief Calcs the reflectance using Schlick's approximation. - * This function computes the reflectance based on the angle of incidence and the index of refraction - * using Schlick's approximation. + * This function computes the reflectance based on the angle of incidence and the index of + * refraction using Schlick's approximation. * @param cosine The cosine of the angle between the incident vector and the normal. * @param ref_idx The index of refraction of the material. * @return The reflectance value as a double, which is the probability of reflection at the @@ -65,7 +65,6 @@ Vector3 PRISM_EXPORT refract(const Vector3& uv, const Vector3& n, double etai_ov */ double PRISM_EXPORT schlick(double cosine, double ref_idx); - } // namespace Prism #endif // PRISM_UTILS_HPP_ \ No newline at end of file diff --git a/src/include/Prism/objects/ObjReader.hpp b/src/include/Prism/objects/ObjReader.hpp index 5b102b8..e524271 100644 --- a/src/include/Prism/objects/ObjReader.hpp +++ b/src/include/Prism/objects/ObjReader.hpp @@ -5,6 +5,7 @@ #include "Prism/objects/Colormap.hpp" +#include #include #include #include @@ -12,7 +13,6 @@ #include #include #include -#include namespace Prism { @@ -27,7 +27,7 @@ class ObjReader { std::vector> vertices; std::vector> normals; std::vector faces; - + ObjReader(const std::string& filename) { curMaterial = std::make_shared(); diff --git a/src/include/Prism/objects/mesh.hpp b/src/include/Prism/objects/mesh.hpp index 0ca1fe9..385da6a 100644 --- a/src/include/Prism/objects/mesh.hpp +++ b/src/include/Prism/objects/mesh.hpp @@ -11,9 +11,9 @@ #include "Prism/objects/triangle.hpp" #include +#include #include #include -#include namespace Prism { @@ -59,7 +59,7 @@ class PRISM_EXPORT Mesh : public Object { void setMaterial(std::shared_ptr new_material); private: - std::vector> points; ///< Points that define the vertices of the mesh + std::vector> points; ///< Points that define the vertices of the mesh std::vector> normals; ///< Normals for each vertex in the mesh std::vector mesh; ///< Triangles that make up the mesh, each defined by three points diff --git a/src/include/Prism/objects/triangle.hpp b/src/include/Prism/objects/triangle.hpp index fad0a68..787b23f 100644 --- a/src/include/Prism/objects/triangle.hpp +++ b/src/include/Prism/objects/triangle.hpp @@ -97,9 +97,9 @@ class PRISM_EXPORT MeshTriangle { * @param n3 The normal vector at the third point. * This constructor initializes the MeshTriangle with the specified points. */ - MeshTriangle(std::shared_ptr p1, std::shared_ptr p2, - std::shared_ptr p3, std::shared_ptr n1, - std::shared_ptr n2, std::shared_ptr n3); + MeshTriangle(std::shared_ptr p1, std::shared_ptr p2, std::shared_ptr p3, + std::shared_ptr n1, std::shared_ptr n2, + std::shared_ptr n3); /** * @brief Constructs a MeshTriangle given three Point3 objects. diff --git a/src/include/Prism/scene/light.hpp b/src/include/Prism/scene/light.hpp index 09a2eab..5caeae6 100644 --- a/src/include/Prism/scene/light.hpp +++ b/src/include/Prism/scene/light.hpp @@ -2,8 +2,9 @@ #define PRISM_LIGHT_HPP_ #include "prism_export.h" -#include "Prism/core/point.hpp" + #include "Prism/core/color.hpp" +#include "Prism/core/point.hpp" namespace Prism { @@ -12,9 +13,10 @@ namespace Prism { * @brief Represents a point light source in the scene. */ class PRISM_EXPORT Light { -public: + public: Point3 position; ///< The position of the light in 3D space. - Color color; ///< The color of the light, typically used to determine how it illuminates objects. + Color + color; ///< The color of the light, typically used to determine how it illuminates objects. /** * @brief Default constructor that initializes the light with default values. @@ -23,8 +25,8 @@ class PRISM_EXPORT Light { * - Color: White (1, 1, 1) * - Intensity: 1.0 */ - Light(const Point3& pos, const Color& col) - : position(pos), color(col) {} + Light(const Point3& pos, const Color& col) : position(pos), color(col) { + } }; } // namespace Prism diff --git a/src/include/Prism/scene/scene.hpp b/src/include/Prism/scene/scene.hpp index beb8d5f..bed4383 100644 --- a/src/include/Prism/scene/scene.hpp +++ b/src/include/Prism/scene/scene.hpp @@ -3,10 +3,10 @@ #include "prism_export.h" +#include "Prism/core/color.hpp" #include "Prism/objects/objects.hpp" #include "Prism/scene/camera.hpp" #include "Prism/scene/light.hpp" -#include "Prism/core/color.hpp" #include #include @@ -66,8 +66,8 @@ class PRISM_EXPORT Scene { Color trace(const Ray& ray, int depth) const; std::vector> objects_; ///< Collection of objects in the scene - std::vector> lights_; ///< Collection of light sources in the scene - Color ambient_color_ = Color(0.1, 0.1, 0.1); ///< Ambient color for the scene + std::vector> lights_; ///< Collection of light sources in the scene + Color ambient_color_ = Color(0.1, 0.1, 0.1); ///< Ambient color for the scene Camera camera_; ///< The camera used to view the scene }; } // namespace Prism diff --git a/src/src/core/color.cpp b/src/src/core/color.cpp index 76729e0..018c5e7 100644 --- a/src/src/core/color.cpp +++ b/src/src/core/color.cpp @@ -1,4 +1,5 @@ #include "Prism/core/color.hpp" + #include namespace Prism { @@ -34,10 +35,10 @@ Color Color::operator+=(Color other) { } Color& Color::clamp() { - r = std::max(0.0,std::min(r, 1.0)); - g = std::max(0.0,std::min(g, 1.0)); - b = std::max(0.0,std::min(b, 1.0)); - + r = std::max(0.0, std::min(r, 1.0)); + g = std::max(0.0, std::min(g, 1.0)); + b = std::max(0.0, std::min(b, 1.0)); + return *this; } diff --git a/src/src/core/utils.cpp b/src/src/core/utils.cpp index 90c6087..0fd7a8a 100644 --- a/src/src/core/utils.cpp +++ b/src/src/core/utils.cpp @@ -56,7 +56,7 @@ Vector3 refract(const Vector3& uv, const Vector3& n, double etai_over_etat) { if (sqr(r_out_perp.magnitude()) > 1.0) { return Vector3(0, 0, 0); } - + return r_out_perp + r_out_parallel; } diff --git a/src/src/objects/mesh.cpp b/src/src/objects/mesh.cpp index 9ba07c4..65ea57f 100644 --- a/src/src/objects/mesh.cpp +++ b/src/src/objects/mesh.cpp @@ -1,6 +1,7 @@ #include "Prism/objects/mesh.hpp" #include "Prism/core/matrix.hpp" + #include namespace Prism { @@ -19,14 +20,9 @@ Mesh::Mesh(std::filesystem::path& path) { } for (auto& face : reader.faces) { - mesh.emplace_back( - points[face.vertex_indices[0]], - points[face.vertex_indices[1]], - points[face.vertex_indices[2]], - normals[face.normal_indices[0]], - normals[face.normal_indices[1]], - normals[face.normal_indices[2]] - ); + mesh.emplace_back(points[face.vertex_indices[0]], points[face.vertex_indices[1]], + points[face.vertex_indices[2]], normals[face.normal_indices[0]], + normals[face.normal_indices[1]], normals[face.normal_indices[2]]); } }; @@ -41,14 +37,9 @@ Mesh::Mesh(ObjReader& reader) : material(std::move(reader.curMaterial)) { } for (auto& face : reader.faces) { - mesh.emplace_back( - points[face.vertex_indices[0]], - points[face.vertex_indices[1]], - points[face.vertex_indices[2]], - normals[face.normal_indices[0]], - normals[face.normal_indices[1]], - normals[face.normal_indices[2]] - ); + mesh.emplace_back(points[face.vertex_indices[0]], points[face.vertex_indices[1]], + points[face.vertex_indices[2]], normals[face.normal_indices[0]], + normals[face.normal_indices[1]], normals[face.normal_indices[2]]); } }; diff --git a/src/src/objects/triangle.cpp b/src/src/objects/triangle.cpp index 450a8d7..f2f7e8f 100644 --- a/src/src/objects/triangle.cpp +++ b/src/src/objects/triangle.cpp @@ -69,8 +69,8 @@ bool Triangle::hit(const Ray& ray, double t_min, double t_max, HitRecord& rec) c MeshTriangle::MeshTriangle(std::shared_ptr p1, std::shared_ptr p2, std::shared_ptr p3, std::shared_ptr n1, std::shared_ptr n2, std::shared_ptr n3) - : point1(std::move(p1)), point2(std::move(p2)), point3(std::move(p3)), - normal1(std::move(n1)), normal2(std::move(n2)), normal3(std::move(n3)) { + : point1(std::move(p1)), point2(std::move(p2)), point3(std::move(p3)), normal1(std::move(n1)), + normal2(std::move(n2)), normal3(std::move(n3)) { } MeshTriangle::MeshTriangle(Point3 p1, Point3 p2, Point3 p3) @@ -127,7 +127,8 @@ bool MeshTriangle::hit(const Ray& ray, double t_min, double t_max, HitRecord& re if (t > t_min && t < t_max) { - const double w = 1.0 - u - v;; + const double w = 1.0 - u - v; + ; rec.t = t; rec.normal = ((*normal1 * w) + (*normal2 * u) + (*normal3 * v)).normalize(); return true; diff --git a/src/src/scene/scene.cpp b/src/src/scene/scene.cpp index 1a5ca95..45bd6fb 100644 --- a/src/src/scene/scene.cpp +++ b/src/src/scene/scene.cpp @@ -147,10 +147,10 @@ Color Scene::trace(const Ray& ray, int depth) const { refraction_color = trace(refracted_ray, depth - 1); } - Color trasmited_color = reflection_color * reflectance + refraction_color * (1.0 - reflectance); + Color trasmited_color = + reflection_color * reflectance + refraction_color * (1.0 - reflectance); final_color = final_color * opacity + trasmited_color * (1.0 - opacity); - } - else if (mat->ks.r > 0 || mat->ks.g > 0 || mat->ks.b > 0) { + } else if (mat->ks.r > 0 || mat->ks.g > 0 || mat->ks.b > 0) { Vector3 reflect_dir = ray.direction() - rec.normal * 2 * ray.direction().dot(rec.normal); Ray reflection_ray(rec.p, reflect_dir); final_color += mat->ks * trace(reflection_ray, depth - 1); diff --git a/src/src/scene/scene_parser.cpp b/src/src/scene/scene_parser.cpp index 9c257c6..185b7c9 100644 --- a/src/src/scene/scene_parser.cpp +++ b/src/src/scene/scene_parser.cpp @@ -158,8 +158,7 @@ Scene SceneParser::parse() { Color color(color_vec.x, color_vec.y, color_vec.z); scene.addLight(std::make_unique(pos, color)); } - } - else { + } else { Style::logWarning("'lights' node not found or is not a list. No lights will be added."); }