aboutsummaryrefslogtreecommitdiff
path: root/src/Engine/Scene.h
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-20 02:27:02 +0200
committerhachem <im@hachem.wtf>2026-08-20 02:40:07 +0200
commit5b361d81dbd2af0d0e99b9eb1adebea76ff05db0 (patch)
tree34db1df17e8c7248aeeb92156d635d31c2484e3f /src/Engine/Scene.h
parente3abaaf59777258ba06705135a0cafcb5918ad12 (diff)
[chore]: MASSIVE refactor + more vulkan bs
Diffstat (limited to 'src/Engine/Scene.h')
-rw-r--r--src/Engine/Scene.h71
1 files changed, 36 insertions, 35 deletions
diff --git a/src/Engine/Scene.h b/src/Engine/Scene.h
index f85fc13..4b41203 100644
--- a/src/Engine/Scene.h
+++ b/src/Engine/Scene.h
@@ -3,67 +3,68 @@
#include <vector>
#include <limits>
-#include "Object.h"
+#include "object.h"
namespace Donut
{
- class Scene
+ class Scene
{
public:
- std::vector<Object> objs;
- glm::vec3 m_LightPos;
+ Scene()
+ : m_light_pos(5.0f, 5.0f, 5.0f) { }
- Scene()
- : m_LightPos(5.0f, 5.0f, 5.0f) { }
-
- glm::vec3 Trace(Ray &ray)
+ auto trace(Ray& ray) -> glm::vec3
{
float closest = std::numeric_limits<float>::infinity();
- const Object* hitObj = nullptr;
-
- for(auto& obj : objs)
+ const Object* hit_obj = nullptr;
+
+ for (auto& obj : objs)
{
float t;
- if(obj.Intersect(ray, t))
- if(t < closest)
+ if (obj.intersect(ray, t))
+ if (t < closest)
{
closest = t;
- hitObj = &obj;
+ hit_obj = &obj;
}
}
-
- if(hitObj)
+
+ if (hit_obj)
{
- glm::vec3 hitPoint = ray.m_Origin + ray.m_Direction * closest;
- glm::vec3 normal = hitObj->GetNormal(hitPoint);
- glm::vec3 lightDir = glm::normalize(m_LightPos - hitPoint);
-
- float diff = std::max(glm::dot(normal, lightDir), 0.0f);
-
- Ray shadowRay(hitPoint + normal * 0.001f, lightDir);
- bool inShadow = false;
-
- for(auto& obj : objs)
+ glm::vec3 hit_point = ray.m_origin + ray.m_direction * closest;
+ glm::vec3 normal = hit_obj->get_normal(hit_point);
+ glm::vec3 light_dir = glm::normalize(m_light_pos - hit_point);
+
+ float diff = std::max(glm::dot(normal, light_dir), 0.0f);
+
+ Ray shadow_ray(hit_point + normal * 0.001f, light_dir);
+ bool in_shadow = false;
+
+ for (auto& obj : objs)
{
float t;
- if(obj.Intersect(shadowRay, t))
+ if (obj.intersect(shadow_ray, t))
{
- inShadow = true;
+ in_shadow = true;
break;
}
}
-
- glm::vec3 color = hitObj->m_Material.m_Color;
+
+ glm::vec3 color = hit_obj->m_material.m_color;
float ambient = 0.1f;
-
- if (inShadow)
+
+ if (in_shadow)
return color * ambient;
return color * (ambient + diff * 0.9f);
}
-
- return glm::vec3(0.0f, 0.0f, 0.1f);
+
+ return glm::vec3(0.0f, 0.0f, 0.1f);
}
+
+ public:
+ std::vector<Object> objs;
+ glm::vec3 m_light_pos;
};
-}; \ No newline at end of file
+};