frametimes

This commit is contained in:
Ben Kyd
2019-08-05 22:12:58 +01:00
parent f57d75199f
commit ca3cf28a31
5 changed files with 150067 additions and 16 deletions

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"files.associations": {
"chrono": "cpp"
}
}

150016
resources/dragon.obj Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,8 @@
#include "progressiverenderer.hpp"
#include <vector>
#include <chrono>
#include "../common.hpp"
#include "../pixel.hpp"
#include "../display/displayinterface.hpp"
@@ -26,16 +29,21 @@ void ProgressiveRenderer::Render() {
for (const auto& object : m_scene->objects)
object->Translate({ 0.0f, -1.0f, -3.0f });
int frames = 0;
auto startTime = std::chrono::high_resolution_clock::now();
while (m_interface->Active) {
auto frameStartTime = std::chrono::high_resolution_clock::now();
// Take input
SDL_Event e;
while (SDL_PollEvent(&e))
if (e.type == SDL_QUIT) m_interface->Close();
#pragma omp parallel for schedule(dynamic)
for (int x = 0; x < m_scene->w; x++)
#pragma omp parallel for schedule(dynamic)
for (int y = 0; y < m_scene->h; y++) {
SDL_Event e;
while (SDL_PollEvent(&e))
if (e.type == SDL_QUIT) m_interface->Close();
Ray ray = m_scene->camera->CastRay(x, y);
float t, i;
@@ -54,6 +62,17 @@ void ProgressiveRenderer::Render() {
m_interface->SetPixelSafe(x, y, col.rgb());
}
auto endTime = std::chrono::high_resolution_clock::now();
frames++;
std::cout << "Frame: " << frames << std::endl;
std::cout << "Frame Time: " << std::chrono::duration_cast<std::chrono::seconds>(endTime - frameStartTime).count()
<< ":" << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - frameStartTime).count() << std::endl;
std::cout << "Avg Frame Time: " << std::chrono::duration_cast<std::chrono::seconds>(endTime - startTime).count() / frames
<< ":" << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() / frames
<< std::endl << std::endl;
// Swap framebuffers
m_interface->Update();
}

View File

@@ -14,7 +14,7 @@ glm::vec3 getNormal(glm::vec3 p0, glm::vec3 p1, glm::vec3 p2) {
glm::vec3 normal;
normal.x = u.y * v.z - u.z * v.y;
normal.y = u.z * v.x - u.x * v.z;
normal.z = u.x * v.y - u.y - v.x;
normal.z = u.x * v.y - u.y * v.x;
return normal;
}
@@ -66,14 +66,22 @@ std::vector<Primative*> LoadTrianglesBasic(std::string path) {
// tinyobj::material_t material = materials[shapes[s].mesh.material_ids[f]];
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]}
// );
{anx[0], any[0], anz[0]},
{anx[1], any[1], anz[1]},
{anx[2], any[2], anz[2]},
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]},
};
triangles.push_back(tmp);

View File

@@ -1,18 +1,21 @@
#include <iostream>
#include "../src/inferno.hpp"
static const int width = 600;
static const int height = 600;
int main(int argc, char** argv) {
InfernoEngine inferno;
inferno.SetMode(MODE_PROGRESSIVE_GUI);
bool status = inferno.InitWindow(600, 600);
bool status = inferno.InitWindow(width, height);
if (!status) {
std::cout << "Error initializing window: " << inferno.LastError() << std::endl;
}
Scene* scene = new Scene(600, 600);
scene->camera = new Camera(600, 600);
Scene* scene = new Scene(width, height);
scene->camera = new Camera(width, height);
scene->objects.push_back(new Plane({0.0f, -0.5f, 0.0f}, {0.0f, -1.0f, 0.0f}));
scene->objects.push_back(new Sphere({0.0f, 0.0f, -4.0f}, 1.0f));