From e6f535fe6e58e48e747c17409ad57021353ab20b Mon Sep 17 00:00:00 2001 From: Ilusha Date: Sat, 16 Mar 2024 20:57:46 +0300 Subject: [PATCH] fix raytracer --- RayTracer/applications/Rayt.cpp | 6 +++++- RayTracer/applications/SceneLoad.cpp | 19 +++++++++++++++++-- RayTracer/private/RayTracer.cpp | 9 +++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/RayTracer/applications/Rayt.cpp b/RayTracer/applications/Rayt.cpp index fb13aeb..310a85a 100644 --- a/RayTracer/applications/Rayt.cpp +++ b/RayTracer/applications/Rayt.cpp @@ -80,6 +80,10 @@ void renderCommand(const std::string& scenePath) { } int main(int argc, const char** argv) { - renderCommand("scene.lua"); + if (argc > 1) { + renderCommand(argv[1]); + } else { + renderCommand("scene.lua"); + } return 0; } \ No newline at end of file diff --git a/RayTracer/applications/SceneLoad.cpp b/RayTracer/applications/SceneLoad.cpp index a17e760..724e62b 100644 --- a/RayTracer/applications/SceneLoad.cpp +++ b/RayTracer/applications/SceneLoad.cpp @@ -8,6 +8,8 @@ extern "C" { #include "OBJ_Loader.h" +#include + bool loadMeshes(tp::Scene& scene, const std::string& objetsPath) { using namespace tp; @@ -127,7 +129,18 @@ void loadScene(tp::Scene& scene, const std::string& scenePath, tp::RayTracer::Re lua_State* L = luaL_newstate(); luaL_openlibs(L); - if (luaL_dofile(L, "script.lua") != 0) { + namespace fs = std::filesystem; + + fs::path fullPath(scenePath); + + // Extract the filename + std::string fileName = fullPath.filename().string(); + + // Remove the filename from the path + fs::path directoryPath = fullPath.remove_filename(); + + + if (luaL_dofile(L, scenePath.c_str()) != 0) { lua_close(L); printf("Cant open scene script.\n"); return; @@ -138,7 +151,9 @@ void loadScene(tp::Scene& scene, const std::string& scenePath, tp::RayTracer::Re if (lua_isstring(L, -1)) { std::string meshesPath = lua_tostring(L, -1); - if (!loadMeshes(scene, meshesPath)) { + directoryPath /= meshesPath; + + if (!loadMeshes(scene, directoryPath.string())) { printf("No 'meshes' loaded - check ur .obj path and validate content of .obj .\n"); return; } diff --git a/RayTracer/private/RayTracer.cpp b/RayTracer/private/RayTracer.cpp index 870ec6c..ab2db13 100644 --- a/RayTracer/private/RayTracer.cpp +++ b/RayTracer/private/RayTracer.cpp @@ -163,6 +163,15 @@ void RayTracer::render(const Scene& scene, OutputBuffers& out, const RenderSetti col.b /= num; }; + // clear colors + for (ualni i = 0; i < mSettings.size.x; i++) { + for (ualni j = 0; j < mSettings.size.y; j++) { + out.color.set({ i, j }, 0.f); + out.normals.set({ i, j }, 0.f); + out.depth.set({ i, j }, 0.f); + } + } + for (ualni i = 0; i < mSettings.size.x; i++) { for (ualni j = 0; j < mSettings.size.y; j++) { for (auto sample = 0; sample < mSettings.multisampling; sample++) {