This commit is contained in:
Ilusha 2024-03-16 12:07:49 +03:00
parent 65cb26a627
commit 1ead32d84a
71 changed files with 199 additions and 282 deletions

View file

@ -3,26 +3,18 @@ project(RayTracer)
### ---------------------- Static Library --------------------- ###
file(GLOB SOURCES "./private/*.cpp" "./private/*/*.cpp")
file(GLOB HEADERS "./public/*.hpp" "./public/*/*.hpp" "./applications/*.hpp")
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} PUBLIC ./public/)
target_link_libraries(${PROJECT_NAME} PUBLIC Math Connection)
### -------------------------- Applications -------------------------- ###
add_executable(rayt ./applications/Rayt.cpp applications/SceneLoad.cpp
applications/Rayt.hpp)
add_executable(rayt ./applications/Rayt.cpp applications/SceneLoad.cpp applications/Rayt.hpp)
target_link_libraries(rayt ${PROJECT_NAME} Lua ImageIO)
file(COPY "applications/rsc" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/")
### -------------------------- Tests -------------------------- ###
enable_testing()
file(GLOB TEST_SOURCES "./tests/*.cpp" "./tests/*/*.cpp")
add_executable(${PROJECT_NAME}Tests ${TEST_SOURCES})
target_include_directories(${PROJECT_NAME}Tests PUBLIC ./applications/)
target_link_libraries(${PROJECT_NAME}Tests ${PROJECT_NAME} UnitTest++ ImageIO)
add_test(NAME ${PROJECT_NAME}Tests COMMAND ${PROJECT_NAME}Tests)
add_executable(Test${PROJECT_NAME} ${TEST_SOURCES})
target_include_directories(Test${PROJECT_NAME} PUBLIC ./applications/)
target_link_libraries(Test${PROJECT_NAME} ${PROJECT_NAME} UnitTest++ ImageIO)
add_test(NAME Test${PROJECT_NAME} COMMAND Test${PROJECT_NAME})

View file

@ -23,8 +23,8 @@ void writeImage(const RayTracer::RenderBuffer& output, const char* name) {
Buffer2D<urgb> converted;
converted.reserve(output.size());
for (RayTracer::RenderBuffer::Index i = 0; i < output.size().x; i++) {
for (RayTracer::RenderBuffer::Index j = 0; j < output.size().y; j++) {
for (Index i = 0; i < output.size().x; i++) {
for (Index j = 0; j < output.size().y; j++) {
converted.get({ i, j }).r = uint1(output.get({ i, j }).r * 255);
converted.get({ i, j }).g = uint1(output.get({ i, j }).g * 255);
converted.get({ i, j }).b = uint1(output.get({ i, j }).b * 255);
@ -51,7 +51,7 @@ void printStatus(const halnf* percentage) {
}
}
void renderCommand(const String& scenePath) {
void renderCommand(const std::string& scenePath) {
Scene scene;
RayTracer::RenderSettings settings;
@ -80,14 +80,6 @@ void renderCommand(const String& scenePath) {
}
int main(int argc, const char** argv) {
tp::ModuleManifest* deps[] = { &gModuleRayTracer, nullptr };
tp::ModuleManifest module("Rayt", nullptr, nullptr, deps);
if (module.initialize()) {
renderCommand("scene.lua");
module.deinitialize();
}
renderCommand("scene.lua");
return 0;
}

View file

@ -1,6 +1,7 @@
#pragma once
#include "RayTracer.hpp"
#include "Strings.hpp"
void loadScene(tp::Scene& scene, const tp::String& scenePath, tp::RayTracer::RenderSettings& settings);
#include <string>
void loadScene(tp::Scene& scene, const std::string& scenePath, tp::RayTracer::RenderSettings& settings);

View file

@ -8,12 +8,12 @@ extern "C" {
#include "OBJ_Loader.h"
bool loadMeshes(tp::Scene& scene, const tp::String& objetsPath) {
bool loadMeshes(tp::Scene& scene, const std::string& objetsPath) {
using namespace tp;
objl::Loader Loader;
if (!Loader.LoadFile(objetsPath.read())) {
if (!Loader.LoadFile(objetsPath.c_str())) {
std::cout << "Failed to Load File. May have failed to find it or it was not an .obj file.\n";
return false;
}
@ -123,7 +123,7 @@ int readLight(lua_State* L, tp::PointLight* light) {
return 1; // Success
}
void loadScene(tp::Scene& scene, const tp::String& scenePath, tp::RayTracer::RenderSettings& settings) {
void loadScene(tp::Scene& scene, const std::string& scenePath, tp::RayTracer::RenderSettings& settings) {
lua_State* L = luaL_newstate();
luaL_openlibs(L);
@ -136,7 +136,7 @@ void loadScene(tp::Scene& scene, const tp::String& scenePath, tp::RayTracer::Ren
lua_getglobal(L, "Meshes");
if (lua_isstring(L, -1)) {
tp::String meshesPath = lua_tostring(L, -1);
std::string meshesPath = lua_tostring(L, -1);
if (!loadMeshes(scene, meshesPath)) {
printf("No 'meshes' loaded - check ur .obj path and validate content of .obj .\n");

View file

@ -43,10 +43,6 @@ normal = n1 * barycentric.x + n2 * barycentric.y + n3 * barycentric.z;
using namespace tp;
ModuleManifest* sDependencies[] = { &gModuleMath, &gModuleConnection, nullptr };
ModuleManifest tp::gModuleRayTracer = ModuleManifest("RayTracer", nullptr, nullptr, sDependencies);
void RayTracer::castRay(const Ray& ray, RayCastData& out, alnf farVal) {
out.hit = false;
@ -167,8 +163,8 @@ void RayTracer::render(const Scene& scene, OutputBuffers& out, const RenderSetti
col.b /= num;
};
for (auto i = 0; i < mSettings.size.x; i++) {
for (auto j = 0; j < mSettings.size.y; j++) {
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++) {
auto randX = randomFloat();
auto randY = randomFloat();

View file

@ -49,7 +49,7 @@ namespace tp {
uhalni depth = 2;
uhalni spray = 1;
ualni multisampling = 1;
Vec2I size;
Vec2<ualni> size;
};
struct OutputBuffers {

View file

@ -18,8 +18,8 @@ void writeImage(const RayTracer::RenderBuffer& output) {
Buffer2D<urgb> converted;
converted.reserve(output.size());
for (RayTracer::RenderBuffer::Index i = 0; i < output.size().x; i++) {
for (RayTracer::RenderBuffer::Index j = 0; j < output.size().y; j++) {
for (Index i = 0; i < output.size().x; i++) {
for (Index j = 0; j < output.size().y; j++) {
converted.get({ i, j }).r = uint1(output.get({ i, j }).r * 255);
converted.get({ i, j }).g = uint1(output.get({ i, j }).g * 255);
converted.get({ i, j }).b = uint1(output.get({ i, j }).b * 255);
@ -101,8 +101,8 @@ SUITE(RayTracer) {
if (0) {
writeImage(output.color);
for (auto i = 0; i < output.color.size().x; i++) {
for (auto j = 0; j < output.color.size().y; j++) {
for (Index i = 0; i < output.color.size().x; i++) {
for (Index j = 0; j < output.color.size().y; j++) {
auto tmp = output.color.get({ i, j });
printf(
"TEST(compareCols(output.get({%i, %i}), RGBA{ %ff, %ff, %ff, %ff }));\n", i, j, tmp.r, tmp.g, tmp.b, tmp.a
@ -114,16 +114,5 @@ SUITE(RayTracer) {
}
int main(int argc, char* argv[]) {
tp::ModuleManifest* ModuleDependencies[] = { &tp::gModuleRayTracer, nullptr };
tp::ModuleManifest TestModule("TokenizerTest", nullptr, nullptr, ModuleDependencies);
if (!TestModule.initialize()) {
return 1;
}
bool res = UnitTest::RunAllTests();
TestModule.deinitialize();
return res;
return UnitTest::RunAllTests();
}