fix raytracer
This commit is contained in:
parent
69a17a609e
commit
0eaf22cc46
3 changed files with 31 additions and 3 deletions
|
|
@ -80,6 +80,10 @@ void renderCommand(const std::string& scenePath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char** argv) {
|
int main(int argc, const char** argv) {
|
||||||
|
if (argc > 1) {
|
||||||
|
renderCommand(argv[1]);
|
||||||
|
} else {
|
||||||
renderCommand("scene.lua");
|
renderCommand("scene.lua");
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,8 @@ extern "C" {
|
||||||
|
|
||||||
#include "OBJ_Loader.h"
|
#include "OBJ_Loader.h"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
bool loadMeshes(tp::Scene& scene, const std::string& objetsPath) {
|
bool loadMeshes(tp::Scene& scene, const std::string& objetsPath) {
|
||||||
using namespace tp;
|
using namespace tp;
|
||||||
|
|
||||||
|
|
@ -127,7 +129,18 @@ void loadScene(tp::Scene& scene, const std::string& scenePath, tp::RayTracer::Re
|
||||||
lua_State* L = luaL_newstate();
|
lua_State* L = luaL_newstate();
|
||||||
luaL_openlibs(L);
|
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);
|
lua_close(L);
|
||||||
printf("Cant open scene script.\n");
|
printf("Cant open scene script.\n");
|
||||||
return;
|
return;
|
||||||
|
|
@ -138,7 +151,9 @@ void loadScene(tp::Scene& scene, const std::string& scenePath, tp::RayTracer::Re
|
||||||
if (lua_isstring(L, -1)) {
|
if (lua_isstring(L, -1)) {
|
||||||
std::string meshesPath = lua_tostring(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");
|
printf("No 'meshes' loaded - check ur .obj path and validate content of .obj .\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,15 @@ void RayTracer::render(const Scene& scene, OutputBuffers& out, const RenderSetti
|
||||||
col.b /= num;
|
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 i = 0; i < mSettings.size.x; i++) {
|
||||||
for (ualni j = 0; j < mSettings.size.y; j++) {
|
for (ualni j = 0; j < mSettings.size.y; j++) {
|
||||||
for (auto sample = 0; sample < mSettings.multisampling; sample++) {
|
for (auto sample = 0; sample < mSettings.multisampling; sample++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue