Dragon in box
This commit is contained in:
@@ -10,7 +10,7 @@ set(CMAKE_CXX_FLAGS "-Ofast -mtune=native")
|
||||
set(executable output)
|
||||
set(SrcDIR ./src)
|
||||
set(TestDIR ./test)
|
||||
set(CurrentTest main.cpp)
|
||||
set(CurrentTest stanford_dragon_cornell.cpp)
|
||||
|
||||
set(IncludeDIR ./include)
|
||||
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
# Blender v2.80 (sub 75) OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib box.mtl
|
||||
o cornell
|
||||
v 2.730000 0.000001 -3.629600
|
||||
v 2.730000 -0.000001 3.455100
|
||||
v 2.730000 3.422800 3.455101
|
||||
v 2.730000 3.422801 -3.629599
|
||||
v -0.655200 3.405600 0.558401
|
||||
v -0.655200 3.405600 -0.767799
|
||||
v 0.627900 3.405600 -0.767799
|
||||
v 0.627900 3.405600 0.558401
|
||||
v -2.757300 -0.000001 3.455100
|
||||
v 2.730000 -0.000001 3.455100
|
||||
v 2.730000 0.000001 -3.629600
|
||||
v -2.702700 0.000001 -3.629600
|
||||
v -2.784600 3.422800 3.455101
|
||||
v -2.784600 3.422801 -3.629599
|
||||
v 2.730000 3.422801 -3.629599
|
||||
v 2.730000 3.422800 3.455101
|
||||
v -2.702700 0.000001 -3.629600
|
||||
v 2.730000 0.000001 -3.629600
|
||||
v 2.730000 3.422801 -3.629599
|
||||
v -2.784600 3.422801 -3.629599
|
||||
v -2.757300 -0.000001 3.455100
|
||||
v -2.702700 0.000001 -3.629600
|
||||
v -2.784600 3.422801 -3.629599
|
||||
v -2.784600 3.422800 3.455101
|
||||
vn -1.0000 -0.0000 0.0000
|
||||
vn 0.0000 -1.0000 0.0000
|
||||
vn 0.0000 1.0000 0.0000
|
||||
vn 0.0000 0.0000 -1.0000
|
||||
vn 0.0000 -0.0000 1.0000
|
||||
vn 0.9999 0.0125 0.0022
|
||||
vn 0.9998 0.0194 0.0055
|
||||
vn 1.0000 0.0080 0.0000
|
||||
vn 0.9997 0.0239 0.0077
|
||||
#usemtl rightWall
|
||||
#s 1
|
||||
#f 2//1 4//1 1//1
|
||||
#f 2//1 3//1 4//1
|
||||
#usemtl light
|
||||
#f 6//2 8//2 5//2
|
||||
#f 6//2 7//2 8//2
|
||||
usemtl floor
|
||||
f 10//3 12//3 9//3
|
||||
#f 9//4 16//4 10//4
|
||||
f 10//3 11//3 12//3
|
||||
f 9//4 13//4 16//4
|
||||
#usemtl ceiling
|
||||
#f 14//2 16//2 13//2
|
||||
#f 14//2 15//2 16//2
|
||||
#usemtl backWall
|
||||
#f 17//5 19//5 20//5
|
||||
#f 17//5 18//5 19//5
|
||||
#usemtl leftWall
|
||||
#f 21//6 23//7 24//8
|
||||
#f 21//6 22//9 23//7
|
||||
@@ -50,7 +50,7 @@ Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 30
|
||||
illum 60
|
||||
|
||||
newmtl rightWall
|
||||
Ns 9.803922
|
||||
|
||||
2469553
resources/models/dragon-cornell-size.obj
Normal file
2469553
resources/models/dragon-cornell-size.obj
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,10 +0,0 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl None
|
||||
Ns 500
|
||||
Ka 0.8 0.8 0.8
|
||||
Kd 0.8 0.8 0.8
|
||||
Ks 0.8 0.8 0.8
|
||||
d 1
|
||||
illum 2
|
||||
@@ -1,12 +0,0 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Default_OBJ.001
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.900000 0.900000 0.900000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.0 0.0 0.0
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
File diff suppressed because it is too large
Load Diff
350082
resources/models/lucy.obj
350082
resources/models/lucy.obj
File diff suppressed because it is too large
Load Diff
@@ -142,8 +142,26 @@ void FrameBuffer::Ready() {
|
||||
|
||||
void FrameBuffer::DumpToFile(std::string path) {
|
||||
// int stbi_write_png(char const* filename, int w, int h, int comp, const void* data, int stride_in_bytes);
|
||||
// TODO: Red and Blue channels need to be swapped
|
||||
stbi_write_png(path.c_str(), this->XRes, this->YRes, sizeof(uint32_t), this->RenderData, sizeof(uint32_t) * this->XRes);
|
||||
// TODO: Red and Blue channels need to be swapped, no clue why, saving the framebuffer just doesnt work
|
||||
struct P {
|
||||
unsigned char r, g, b, a;
|
||||
};
|
||||
|
||||
P* imageData = (P*)malloc((XRes * YRes) * sizeof(P));
|
||||
|
||||
for (int x = 0; x < XRes; x++)
|
||||
for (int y = 0; y < YRes; y++) {
|
||||
uint32_t pixel = RenderData[y * this->XRes + x];
|
||||
uint8_t er = (pixel & 0x000000FF);
|
||||
uint8_t eg = (pixel & 0x0000FF00) >> 8;
|
||||
uint8_t eb = (pixel & 0x00FF0000) >> 16;
|
||||
uint8_t ea = (pixel & 0xFF000000) >> 24;
|
||||
|
||||
imageData[y * this->XRes + x] = P{ (unsigned char)eb, (unsigned char)eg, (unsigned char)er, (unsigned char)ea };
|
||||
}
|
||||
|
||||
stbi_write_png(path.c_str(), this->XRes, this->YRes, sizeof(P), imageData, sizeof(P) * this->XRes);
|
||||
free(imageData);
|
||||
}
|
||||
|
||||
void FrameBuffer::CopyData(uint32_t* dest) {
|
||||
|
||||
@@ -74,9 +74,9 @@ void ProgressiveRenderer::Input() {
|
||||
ImGui::Text(str2.str().c_str());
|
||||
|
||||
float upper = 0.0f; float lower = 0.0f;
|
||||
for (int i = 0; i < AllFrameTimes.size(); i++) {
|
||||
if (AllFrameTimes[i] > upper) upper = AllFrameTimes[i];
|
||||
if (AllFrameTimes[i] < lower) lower = AllFrameTimes[i];
|
||||
for (int i = 0; i < FrameTimes.size(); i++) {
|
||||
if (FrameTimes[i] > upper) upper = FrameTimes[i];
|
||||
if (FrameTimes[i] < lower) lower = FrameTimes[i];
|
||||
}
|
||||
ImGui::PlotLines("FrameTimes", FrameTimes.data(), FrameTimes.size(), 0, NULL, lower, upper, ImVec2(0, 40));
|
||||
|
||||
@@ -117,7 +117,7 @@ void ProgressiveRenderer::Render() {
|
||||
m_engine->Mode = m_mode;
|
||||
m_engine->PostProcess(m_threadPool->ThreadFrameBuffer->RenderTarget, m_threadPool->ThreadFrameBuffer->RenderPostProcess, m_scene->w, m_scene->h);
|
||||
|
||||
// Denoise in HDR space
|
||||
// Denoise while still in HDR space
|
||||
|
||||
m_threadPool->ThreadFrameBuffer->PostProcess((ToneMapMode)m_toneMapModeSelected);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ glm::vec3 getNormal(glm::vec3 p0, glm::vec3 p1, glm::vec3 p2) {
|
||||
return normal;
|
||||
}
|
||||
|
||||
std::vector<Triangle*> LoadTrianglesBasic(std::string path, std::string basePath) {
|
||||
std::vector<Triangle*> LoadTrianglesBasic(std::string path, std::string basePath, Material* baseMaterial) {
|
||||
tinyobj::attrib_t attrib;
|
||||
std::vector<tinyobj::shape_t> shapes;
|
||||
std::vector<tinyobj::material_t> materials;
|
||||
@@ -65,38 +65,41 @@ std::vector<Triangle*> LoadTrianglesBasic(std::string path, std::string basePath
|
||||
any[v] = attrib.normals[3 * idx.normal_index + 1];
|
||||
anz[v] = attrib.normals[3 * idx.normal_index + 2];
|
||||
}
|
||||
|
||||
Material* mat;
|
||||
if (baseMaterial == nullptr || !baseMaterial) {
|
||||
tinyobj::material_t material = materials[shapes[s].mesh.material_ids[f]];
|
||||
bool illum = false;
|
||||
if (material.illum > 0.0f) illum = true;
|
||||
mat = new Material({ material.diffuse[0], material.diffuse[1], material.diffuse[2] }, material.illum, 0.0f, 0.0f, 0.0f, false, illum);
|
||||
} else {
|
||||
mat = baseMaterial;
|
||||
}
|
||||
|
||||
// tinyobj::material_t material = materials[shapes[s].mesh.material_ids[f]];
|
||||
// glm::vec3 normal = getNormal(
|
||||
// {avx[0], avy[0], avz[0]},
|
||||
// {avx[1], avy[1], avz[1]},
|
||||
// {avx[2], avy[2], avz[2]}
|
||||
// );
|
||||
|
||||
// Material* mat = new Material({ material.diffuse[0], material.diffuse[1], material.diffuse[2] }, 0.6f, material.illum);
|
||||
Material* mat = new Material({ 0.717f, 0.792f, 0.474 }, 0.5f);
|
||||
//Material* mat = new Material({ 0.8, 0.8f, 0.8f });
|
||||
Triangle* tmp = new Triangle {
|
||||
{avx[0], avy[0], avz[0]},
|
||||
{avx[1], avy[1], avz[1]},
|
||||
{avx[2], avy[2], avz[2]},
|
||||
|
||||
// glm::vec3 normal = getNormal(
|
||||
// {avx[0], avy[0], avz[0]},
|
||||
// {avx[1], avy[1], avz[1]},
|
||||
// {avx[2], avy[2], avz[2]}
|
||||
// );
|
||||
// normal, normal, normal
|
||||
{anx[0], any[0], anz[0]},
|
||||
{anx[1], any[1], anz[1]},
|
||||
{anx[2], any[2], anz[2]},
|
||||
|
||||
mat,
|
||||
};
|
||||
|
||||
Triangle* tmp = new Triangle {
|
||||
{avx[0], avy[0], avz[0]},
|
||||
{avx[1], avy[1], avz[1]},
|
||||
{avx[2], avy[2], avz[2]},
|
||||
|
||||
// normal, normal, normal
|
||||
|
||||
{anx[0], any[0], anz[0]},
|
||||
{anx[1], any[1], anz[1]},
|
||||
{anx[2], any[2], anz[2]},
|
||||
|
||||
mat,
|
||||
};
|
||||
|
||||
triangles.push_back(tmp);
|
||||
}
|
||||
index_offset += fv;
|
||||
triangles.push_back(tmp);
|
||||
}
|
||||
|
||||
index_offset += fv;
|
||||
}
|
||||
}
|
||||
|
||||
return triangles;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
#include <string>
|
||||
|
||||
class Triangle;
|
||||
class Material;
|
||||
|
||||
std::vector<Triangle*> LoadTrianglesBasic(std::string path, std::string basePath = "");
|
||||
std::vector<Triangle*> LoadTrianglesBasic(std::string path, std::string basePath = "", Material* baseMaterial = nullptr);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include "../src/inferno.hpp"
|
||||
|
||||
static const int width = 700;
|
||||
static const int height = 700;
|
||||
static const int width = 1000;
|
||||
static const int height = 1000;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
InfernoEngine inferno;
|
||||
|
||||
@@ -15,11 +15,20 @@ int main(int argc, char** argv) {
|
||||
Scene* scene = new Scene(width, height);
|
||||
scene->camera = new Camera(width, height);
|
||||
|
||||
scene->objects.push_back(new Sphere({ 35.0f, 26.0f, 25.0f }, 15.0f, new Material({ 1.0f, 1.0f, 1.0f }, 0.0f, 5.0f)));
|
||||
scene->objects.push_back(new Sphere({-0.457001f, 0.19f, -3.53899f}, 0.02f, new Material({ 1.0f, 0.9f, 0.8f }, 0.0f, 500.0f)));
|
||||
scene->objects.push_back(new Plane( { 0.0f, -1.0f, 0.0f }, { 0.0f, -1.0f, 0.0f }, new Material({ 0.847f, 0.792f, 0.658f }, 0.2f)));
|
||||
Sky* sky = new GradientSky({ 35.0f / 255.0f, 148.0f / 255.0f, 235.0f / 255.0f }, { 1.0f, 1.0f, 1.0f }, 4.0f);
|
||||
scene->sky = sky;
|
||||
|
||||
std::vector<Triangle*> tris = LoadTrianglesBasic("E://Projects//Inferno//resources//dragon-normals.obj", "E://Projects//Inferno//resources");
|
||||
Sphere* sun = new Sphere({ 35.0f, 50.0f, 25.0f }, 25.0f, new Material({ 1.0f, 1.0f, 1.0f }, 0.0f, 100.0f));
|
||||
scene->objects.push_back(sun);
|
||||
|
||||
Sphere* mouthLight = new Sphere({ -0.457001f, 0.19f, -3.53899f }, 0.02f, new Material({ 1.0f, 0.9f, 0.8f }, 0.0f, 500.0f));
|
||||
scene->objects.push_back(mouthLight);
|
||||
|
||||
Plane* plane = new Plane({ 0.0f, -1.0f, 0.0f }, { 0.0f, -1.0f, 0.0f }, new Material({ 0.847f, 0.792f, 0.658f }, 0.2f));
|
||||
scene->objects.push_back(plane);
|
||||
|
||||
Material* mat = new GlossyMaterial({ 0.717f, 0.792f, 0.474 }, 0.5f, fastDegreetoRadian(20.0f));
|
||||
std::vector<Triangle*> tris = LoadTrianglesBasic("E://Projects//Inferno//resources//models//dragon.obj", "E://Projects//Inferno//models//resources", mat);
|
||||
// std::vector<Triangle*> tris = LoadTrianglesBasic("//home//ben//programming//inferno//resources//dragon-normals.obj", "//home//ben//programming//inferno//resources//resources");
|
||||
|
||||
Mesh* mesh1 = new Mesh(tris);
|
||||
|
||||
41
test/stanford_dragon_cornell.cpp
Normal file
41
test/stanford_dragon_cornell.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "../src/inferno.hpp"
|
||||
|
||||
static const int width = 2000;
|
||||
static const int height = 2000;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
InfernoEngine inferno;
|
||||
|
||||
inferno.SetMode(MODE_OPERATION_PROGRESSIVE_GUI);
|
||||
|
||||
inferno.InitWindow(width, height);
|
||||
|
||||
Scene* scene = new Scene(width, height);
|
||||
scene->camera = new Camera(width, height);
|
||||
|
||||
Sky* sky = new SolidSky({ 0.0f, 0.0f, 0.0f }, 0.0f);
|
||||
scene->sky = sky;
|
||||
|
||||
Material* mat = new GlossyMaterial({ 1.2f, 1.2f, 1.2f }, 0.15f, fastDegreetoRadian(25.0f));
|
||||
std::vector<Triangle*> tris = LoadTrianglesBasic("E://Projects//Inferno//resources//models//dragon-cornell-size.obj", "E://Projects//Inferno//models//resources//", mat);
|
||||
|
||||
Mesh* mesh = new Mesh(tris);
|
||||
mesh->Translate({ 0.01f, -1.0, -3.6f });
|
||||
mesh->Optimise();
|
||||
scene->meshs.push_back(mesh);
|
||||
|
||||
std::vector<Triangle*> tris1 = LoadTrianglesBasic("E://Projects//Inferno//resources//models//cornell-box.obj", "E://Projects//Inferno//resources//models//");
|
||||
|
||||
Mesh* mesh1 = new Mesh(tris1);
|
||||
mesh1->Translate({ 0.01f, -1.0, -3.6f });
|
||||
scene->meshs.push_back(mesh1);
|
||||
|
||||
inferno.SetScene(scene);
|
||||
|
||||
inferno.Ready();
|
||||
inferno.Render();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user