fix raytracer
This commit is contained in:
parent
1ead32d84a
commit
e6f535fe6e
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) {
|
||||
renderCommand("scene.lua");
|
||||
if (argc > 1) {
|
||||
renderCommand(argv[1]);
|
||||
} else {
|
||||
renderCommand("scene.lua");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ extern "C" {
|
|||
|
||||
#include "OBJ_Loader.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue