Adding simple test for RT
This commit is contained in:
parent
4d00ef1296
commit
15c5576273
8 changed files with 402 additions and 217 deletions
|
|
@ -26,6 +26,9 @@ file(COPY "applications/rsc" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/")
|
|||
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} Utils)
|
||||
add_test(NAME ${PROJECT_NAME}Tests COMMAND ${PROJECT_NAME}Tests)
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ bool loadMeshes(tp::Scene& scene, const tp::String& objetsPath) {
|
|||
auto object = &scene.mObjects.last();
|
||||
|
||||
for (auto& vertex : curMesh.Vertices) {
|
||||
// printf("{ %f, %f, %f }, \n", vertex.Position.X, vertex.Position.Y, vertex.Position.Z);
|
||||
object->mTopology.Points.append(Vec3F {vertex.Position.X, vertex.Position.Y, vertex.Position.Z});
|
||||
object->mTopology.Normals.append(Vec3F {vertex.Normal.X, vertex.Normal.Y, vertex.Normal.Z});
|
||||
}
|
||||
|
|
@ -32,6 +33,7 @@ bool loadMeshes(tp::Scene& scene, const tp::String& objetsPath) {
|
|||
int idx1 = (int) curMesh.Indices[j];
|
||||
int idx2 = (int) curMesh.Indices[j + 1];
|
||||
int idx3 = (int) curMesh.Indices[j + 2];
|
||||
// printf("{ %i, %i, %i },\n", idx1, idx2, idx3);
|
||||
object->mTopology.Indexes.append(Vec3I {idx1, idx2, idx3});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
Meshes = "meshes.obj"
|
||||
|
||||
Camera = {
|
||||
pos = { 4, 4, 4 },
|
||||
size_x = 400,
|
||||
size_y = 600,
|
||||
pos = { 3, 3, 3 },
|
||||
size_x = 10,
|
||||
size_y = 10,
|
||||
}
|
||||
|
||||
Lights = {
|
||||
{
|
||||
pos = { 4, 3, 3 },
|
||||
intensity = 4
|
||||
pos = { 4, 2, 3 },
|
||||
intensity = 5
|
||||
}
|
||||
}
|
||||
|
|
@ -171,6 +171,9 @@ void RayTracer::render(const Scene& scene, RayTracer::RenderBuffer& buff, const
|
|||
buff.set({i, j}, 0.f);
|
||||
}
|
||||
|
||||
auto tmp = buff.get({i, j});
|
||||
// printf(" %f, %f, %f, %f, ", tmp.r, tmp.g, tmp.b, tmp.a);
|
||||
|
||||
mProgress.percentage = (halnf) currIter / (halnf) maxIterations;
|
||||
currIter++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,125 @@
|
|||
|
||||
int main(int argc, char* argv[]) { return 1; }
|
||||
// #include "NewPlacement.hpp"
|
||||
|
||||
#include "RayTracer.hpp"
|
||||
#include "Testing.hpp"
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image_write.h"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
stbi_write_png("output.png", converted.size().x, converted.size().y, 4, converted.getBuff(), converted.size().x * 4);
|
||||
}
|
||||
|
||||
bool compareCols(const RGBA& l, const RGBA& r) {
|
||||
auto small = 0.0001f;
|
||||
if ((l.r - r.r) > small) {
|
||||
return false;
|
||||
}
|
||||
if ((l.g - r.g) > small) {
|
||||
return false;
|
||||
}
|
||||
if ((l.b - r.b) > small) {
|
||||
return false;
|
||||
}
|
||||
if ((l.a - r.a) > small) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void testRT() {
|
||||
using namespace tp;
|
||||
|
||||
Scene scene;
|
||||
|
||||
scene.mCamera.lookAtPoint({0, 0, 0}, {2, 2, 2}, {0, 0, 1});
|
||||
scene.mCamera.setFOV(3.14 / 4);
|
||||
|
||||
scene.mLights.append({
|
||||
{0, 0, 1.1f},
|
||||
1.f, 0.3f
|
||||
});
|
||||
|
||||
scene.mObjects.append(Object());
|
||||
auto& object = scene.mObjects.last();
|
||||
|
||||
object.mTopology.Points = {
|
||||
{1.000000, 0.000000, 0.000000},
|
||||
{0.000000, 1.000000, 0.000000},
|
||||
{0.000000, 0.000000, 1.000000},
|
||||
};
|
||||
|
||||
object.mTopology.Normals = {
|
||||
{1.000000, 1.000000, 1.000000},
|
||||
{1.000000, 1.000000, 1.000000},
|
||||
{1.000000, 1.000000, 1.000000},
|
||||
};
|
||||
|
||||
object.mTopology.Indexes = {
|
||||
{0, 1, 2},
|
||||
};
|
||||
|
||||
object.mCache.Source = &object.mTopology;
|
||||
object.mCache.updateCache();
|
||||
|
||||
RayTracer::RenderSettings settings = {
|
||||
0,
|
||||
0,
|
||||
{10, 10},
|
||||
};
|
||||
|
||||
RayTracer::RenderBuffer output;
|
||||
output.reserve(RayTracer::RenderBuffer::Index2D(settings.size.x, settings.size.y));
|
||||
|
||||
RayTracer rt;
|
||||
rt.render(scene, output, settings);
|
||||
|
||||
TEST(compareCols(output.get({6, 4}), RGBA {0.560100f, 0.560100f, 0.560100f, 1.000000f}));
|
||||
TEST(compareCols(output.get({6, 5}), RGBA {0.353739f, 0.353739f, 0.353739f, 1.000000f}));
|
||||
TEST(compareCols(output.get({6, 6}), RGBA {0.242577f, 0.242577f, 0.242577f, 1.000000f}));
|
||||
TEST(compareCols(output.get({6, 7}), RGBA {0.176313f, 0.176313f, 0.176313f, 1.000000f}));
|
||||
TEST(compareCols(output.get({6, 8}), RGBA {0.000000f, 0.000000f, 0.000000f, 0.000000f}));
|
||||
|
||||
if (0) {
|
||||
writeImage(output);
|
||||
for (auto i = 0; i < output.size().x; i++) {
|
||||
for (auto j = 0; j < output.size().y; j++) {
|
||||
auto tmp = output.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
tp::ModuleManifest* ModuleDependencies[] = {&tp::gModuleRayTracer, nullptr};
|
||||
tp::ModuleManifest TestModule("TokenizerTest", nullptr, nullptr, ModuleDependencies);
|
||||
|
||||
if (!TestModule.initialize()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
testRT();
|
||||
|
||||
TestModule.deinitialize();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue