Model is loaded and added, started to implement ray generation
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "scene/Scene.h"
|
||||
#include "util/ModelLoader.h"
|
||||
#include "window/Window.h"
|
||||
#include "util/ModelLoader.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -17,6 +18,7 @@ int main()
|
||||
.height = 1080,
|
||||
.numSamples = 10000,
|
||||
});
|
||||
|
||||
while (true)
|
||||
{
|
||||
window.update(scene.getImage());
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <algorithm>
|
||||
#include "util/Ray.h"
|
||||
#include <iostream>
|
||||
|
||||
struct AABB
|
||||
{
|
||||
@@ -45,9 +46,13 @@ struct AABB
|
||||
}
|
||||
bool intersects(Ray ray, float tmin, float tmax)
|
||||
{
|
||||
std::cout << "Hello1" << std::endl;
|
||||
glm::vec3 invD = 1.0f / ray.direction;
|
||||
std::cout << "Hello2: " << min.x << " " << min.y << " " << min.z << " " << max.x << " " << max.y << " " << max.z << " " << std::endl;
|
||||
glm::vec3 t0s = glm::vec3(min - ray.origin) * invD;
|
||||
std::cout << "Hello3" << std::endl;
|
||||
glm::vec3 t1s = glm::vec3(max - ray.origin) * invD;
|
||||
std::cout << "Hello4" << std::endl;
|
||||
|
||||
glm::vec3 tsmaller = glm::min(t0s, t1s);
|
||||
glm::vec3 tbigger = glm::max(t0s, t1s);
|
||||
|
||||
+9
-8
@@ -1,6 +1,7 @@
|
||||
#include "BVH.h"
|
||||
#include <algorithm>
|
||||
#include <ranges>
|
||||
#include <iostream>
|
||||
|
||||
void BVH::addModel(PModel model, glm::mat4 transform)
|
||||
{
|
||||
@@ -10,10 +11,10 @@ void BVH::addModel(PModel model, glm::mat4 transform)
|
||||
|
||||
void BVH::addModels(std::vector<PModel> _models, glm::mat4 transform)
|
||||
{
|
||||
for (int i = 0; i < _models.size(); ++i)
|
||||
for (auto& _model : _models)
|
||||
{
|
||||
_models[i]->boundingBox.transform(transform);
|
||||
models.push_back(std::move(_models[i]));
|
||||
_model->boundingBox.transform(transform);
|
||||
models.push_back(std::move(_model));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,13 +61,13 @@ std::optional<IntersectionInfo> BVH::traceRay(Ray ray)
|
||||
{
|
||||
auto results = generateIntersections(hierarchy, ray);
|
||||
float closestT = std::numeric_limits<float>::max();
|
||||
IntersectionInfo info;
|
||||
for (uint32_t i = 0; i < results.size(); ++i)
|
||||
std::optional<IntersectionInfo> info = {};
|
||||
for (auto& result : results)
|
||||
{
|
||||
if (results[i].t < closestT)
|
||||
if (result.t < closestT)
|
||||
{
|
||||
closestT = results[i].t;
|
||||
info = results[i];
|
||||
closestT = result.t;
|
||||
info = result;
|
||||
}
|
||||
}
|
||||
if (closestT < std::numeric_limits<float>::max())
|
||||
|
||||
+17
-3
@@ -1,8 +1,16 @@
|
||||
#include "Scene.h"
|
||||
#include "util/ModelLoader.h"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
Scene::Scene() {}
|
||||
Scene::Scene()
|
||||
{
|
||||
bvh.addModels(ModelLoader::loadModel("../cube.fbx"),
|
||||
glm::mat4(glm::vec4(1.0f, 0.0f, 0.0f, 0.0f),
|
||||
glm::vec4(0.0f, 1.0f, 0.0f, 0.0f),
|
||||
glm::vec4(0.0f, 0.0f, 1.0f, 0.0f),
|
||||
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)));
|
||||
}
|
||||
|
||||
Scene::~Scene() {}
|
||||
|
||||
@@ -35,8 +43,14 @@ void Scene::render(Camera cam, RenderParameter params)
|
||||
{
|
||||
for (int h = 0; h < params.height; ++h)
|
||||
{
|
||||
// Ray r = Ray();
|
||||
// bvh.traceRay(r);
|
||||
Ray r = Ray{
|
||||
.origin = glm::vec3(0.0f),
|
||||
.direction = glm::vec3(0.0f, 0.0f, 1.0f)
|
||||
};
|
||||
bvh.traceRay(r);
|
||||
|
||||
std::cout << "HELLO" << std::endl;
|
||||
|
||||
accumulator[w + h * params.width] +=
|
||||
glm::vec3(w / float(params.width * params.numSamples), h / float(params.height * params.numSamples), 0);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ std::vector<PModel> ModelLoader::loadModel(std::string_view filename)
|
||||
model->indices.push_back(face.mIndices[1]);
|
||||
model->indices.push_back(face.mIndices[2]);
|
||||
|
||||
auto e0 = model->positions[face.mIndices[1] - face.mIndices[0]];
|
||||
auto e1 = model->positions[face.mIndices[2] - face.mIndices[0]];
|
||||
auto e0 = model->positions[face.mIndices[1]] - model->positions[face.mIndices[0]];
|
||||
auto e1 = model->positions[face.mIndices[2]] - model->positions[face.mIndices[0]];
|
||||
model->es.push_back(e0);
|
||||
model->es.push_back(e1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user