RayTracer Initial Framework setup
This commit is contained in:
parent
25b66804a4
commit
15b56a876a
741 changed files with 3146 additions and 1 deletions
29
RayTracer/CMakeLists.txt
Normal file
29
RayTracer/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
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 CommandLine Connection)
|
||||
|
||||
### -------------------------- Applications -------------------------- ###
|
||||
add_executable(rayt ./applications/Rayt.cpp )
|
||||
|
||||
target_link_libraries(rayt ${PROJECT_NAME})
|
||||
|
||||
### -------------------------- Tests -------------------------- ###
|
||||
enable_testing()
|
||||
file(GLOB TEST_SOURCES "./tests/*.cpp" "./tests/*/*.cpp")
|
||||
add_executable(${PROJECT_NAME}Tests ${TEST_SOURCES})
|
||||
target_link_libraries(${PROJECT_NAME}Tests ${PROJECT_NAME} Utils)
|
||||
add_test(NAME ${PROJECT_NAME}Tests COMMAND ${PROJECT_NAME}Tests)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/lib)
|
||||
21
RayTracer/applications/OBJ_LOADER_LICENSE.txt
Normal file
21
RayTracer/applications/OBJ_LOADER_LICENSE.txt
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2016 Robert Smith
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
1167
RayTracer/applications/OBJ_Loader.h
Normal file
1167
RayTracer/applications/OBJ_Loader.h
Normal file
File diff suppressed because it is too large
Load diff
95
RayTracer/applications/Rayt.cpp
Normal file
95
RayTracer/applications/Rayt.cpp
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
|
||||
// #include "NewPlacement.hpp"
|
||||
|
||||
#include "Buffer.hpp"
|
||||
#include "RayTracer.hpp"
|
||||
#include "Strings.hpp"
|
||||
#include "Vec.hpp"
|
||||
|
||||
#include "OBJ_Loader.h"
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image_write.h"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
void loadScene(Scene& scene, const String& scenePath) {
|
||||
objl::Loader Loader;
|
||||
|
||||
if (!Loader.LoadFile(scenePath.read())) {
|
||||
std::cout << "Failed to Load File. May have failed to find it or it was not an .obj file.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto& curMesh : Loader.LoadedMeshes) {
|
||||
// Go through each vertex and print its number,
|
||||
// position, normal, and texture coordinate
|
||||
for (int j = 0; j < curMesh.Vertices.size(); j++) {
|
||||
// file << "V" << j << ": "
|
||||
// << "P(" << curMesh.Vertices[j].Position.X << ", " << curMesh.Vertices[j].Position.Y << ", " << curMesh.Vertices[j].Position.Z << ") "
|
||||
// << "N(" << curMesh.Vertices[j].Normal.X << ", " << curMesh.Vertices[j].Normal.Y << ", " << curMesh.Vertices[j].Normal.Z << ") "
|
||||
// << "TC(" << curMesh.Vertices[j].TextureCoordinate.X << ", " << curMesh.Vertices[j].TextureCoordinate.Y << ")\n";
|
||||
}
|
||||
|
||||
// Print Indices
|
||||
// Go through every 3rd index and print the
|
||||
// triangle that these indices represent
|
||||
for (int j = 0; j < curMesh.Indices.size(); j += 3) {
|
||||
// file << "T" << j / 3 << ": " << curMesh.Indices[j] << ", " << curMesh.Indices[j + 1] << ", " << curMesh.Indices[j + 2] << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeImage(const RayTracer::RenderBuffer& output) {
|
||||
// Save the data to a PNG file
|
||||
struct urgb {
|
||||
uint1 r, g, b, a;
|
||||
};
|
||||
|
||||
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++) {
|
||||
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);
|
||||
converted.get({i, j}).a = uint1(output.get({i, j}).a * 255);
|
||||
}
|
||||
}
|
||||
|
||||
if (stbi_write_png("output.png", converted.size().x, converted.size().y, 4, converted.getBuff(), converted.size().x * 4) != 0) {
|
||||
// Image saved successfully
|
||||
std::cout << "Image saved successfully." << std::endl;
|
||||
} else {
|
||||
std::cerr << "Error saving the image." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void renderCommand(const String& scenePath, RayTracer::RenderBuffer::Index2D size) {
|
||||
Scene scene;
|
||||
|
||||
loadScene(scene, scenePath);
|
||||
|
||||
RayTracer::RenderBuffer output;
|
||||
output.reserve(size);
|
||||
|
||||
RayTracer rayt;
|
||||
|
||||
rayt.render(scene, output);
|
||||
|
||||
writeImage(output);
|
||||
}
|
||||
|
||||
int main() {
|
||||
tp::ModuleManifest* deps[] = {&gModuleRayTracer, nullptr};
|
||||
tp::ModuleManifest module("Rayt", nullptr, nullptr, deps);
|
||||
|
||||
if (module.initialize()) {
|
||||
renderCommand("scene.obj", {1000, 1000});
|
||||
|
||||
module.deinitialize();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
12
RayTracer/applications/rsc/scene.mtl
Normal file
12
RayTracer/applications/rsc/scene.mtl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material
|
||||
Ns 323.999994
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
40
RayTracer/applications/rsc/scene.obj
Normal file
40
RayTracer/applications/rsc/scene.obj
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# Blender v3.0.1 OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib scene.mtl
|
||||
o Cube
|
||||
v 1.000000 1.000000 -1.000000
|
||||
v 1.000000 -1.000000 -1.000000
|
||||
v 1.000000 1.000000 1.000000
|
||||
v 1.000000 -1.000000 1.000000
|
||||
v -1.000000 1.000000 -1.000000
|
||||
v -1.000000 -1.000000 -1.000000
|
||||
v -1.000000 1.000000 1.000000
|
||||
v -1.000000 -1.000000 1.000000
|
||||
vt 0.625000 0.500000
|
||||
vt 0.875000 0.500000
|
||||
vt 0.875000 0.750000
|
||||
vt 0.625000 0.750000
|
||||
vt 0.375000 0.750000
|
||||
vt 0.625000 1.000000
|
||||
vt 0.375000 1.000000
|
||||
vt 0.375000 0.000000
|
||||
vt 0.625000 0.000000
|
||||
vt 0.625000 0.250000
|
||||
vt 0.375000 0.250000
|
||||
vt 0.125000 0.500000
|
||||
vt 0.375000 0.500000
|
||||
vt 0.125000 0.750000
|
||||
vn 0.0000 1.0000 0.0000
|
||||
vn 0.0000 0.0000 1.0000
|
||||
vn -1.0000 0.0000 0.0000
|
||||
vn 0.0000 -1.0000 0.0000
|
||||
vn 1.0000 0.0000 0.0000
|
||||
vn 0.0000 0.0000 -1.0000
|
||||
usemtl Material
|
||||
s off
|
||||
f 1/1/1 5/2/1 7/3/1 3/4/1
|
||||
f 4/5/2 3/4/2 7/6/2 8/7/2
|
||||
f 8/8/3 7/9/3 5/10/3 6/11/3
|
||||
f 6/12/4 2/13/4 4/5/4 8/14/4
|
||||
f 2/13/5 1/1/5 3/4/5 4/5/5
|
||||
f 6/11/6 5/10/6 1/1/6 2/13/6
|
||||
1724
RayTracer/applications/stb_image_write.h
Normal file
1724
RayTracer/applications/stb_image_write.h
Normal file
File diff suppressed because it is too large
Load diff
20
RayTracer/private/RayTracer.cpp
Normal file
20
RayTracer/private/RayTracer.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
#include "NewPlacement.hpp"
|
||||
|
||||
#include "CommandLine.hpp"
|
||||
#include "Module.hpp"
|
||||
#include "RayTracer.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
ModuleManifest* sDependencies[] = {&gModuleMath, &gModuleCommandLine, &gModuleConnection, nullptr};
|
||||
|
||||
ModuleManifest tp::gModuleRayTracer = ModuleManifest("RayTracer", nullptr, nullptr, sDependencies);
|
||||
|
||||
void RayTracer::render(const Scene& scene, RayTracer::RenderBuffer& buff) {
|
||||
for (RayTracer::RenderBuffer::Index i = 0; i < buff.size().x; i++) {
|
||||
for (RayTracer::RenderBuffer::Index j = 0; j < buff.size().y; j++) {
|
||||
buff.set({i, j}, RGBA(1.f, 1.f, 1.f, 1.f));
|
||||
}
|
||||
}
|
||||
}
|
||||
31
RayTracer/public/RayTracer.hpp
Normal file
31
RayTracer/public/RayTracer.hpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Buffer2D.hpp"
|
||||
#include "Camera.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Module.hpp"
|
||||
#include "Topology.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
||||
extern ModuleManifest gModuleRayTracer;
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
Scene() = default;
|
||||
|
||||
public:
|
||||
Buffer<Topology> mObjects;
|
||||
Camera mCamera;
|
||||
};
|
||||
|
||||
class RayTracer {
|
||||
public:
|
||||
typedef Buffer2D<RGBA> RenderBuffer;
|
||||
|
||||
public:
|
||||
RayTracer() = default;
|
||||
void render(const Scene& scene, RenderBuffer& buff);
|
||||
};
|
||||
}
|
||||
3
RayTracer/tests/Test.cpp
Normal file
3
RayTracer/tests/Test.cpp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
int main(int argc, char* argv[]) { return 1; }
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue