what's that? a segfault???

This commit is contained in:
benkyd
2023-01-12 16:06:30 +00:00
parent 68cc749fde
commit 5008af7681
9 changed files with 59 additions and 9 deletions

View File

@@ -4,8 +4,11 @@
namespace inferno { namespace inferno {
class Ray;
struct HitInfo struct HitInfo
{ {
Ray* Caller;
// indicie of hit ^ mesh idx of hit // indicie of hit ^ mesh idx of hit
int Identifier; int Identifier;
glm::vec2 UV; glm::vec2 UV;

View File

@@ -8,6 +8,7 @@ struct Ray
{ {
glm::vec3 Origin; glm::vec3 Origin;
glm::vec3 Direction; glm::vec3 Direction;
uint32_t Reference;
}; };
} }

View File

@@ -1,6 +1,8 @@
#include "hart_module.hpp" #include "hart_module.hpp"
#include <renderer/ray_source.hpp> #include <renderer/ray_source.hpp>
#include <renderer/renderer.hpp>
#include <scene/scene.hpp> #include <scene/scene.hpp>
#include <scene/mesh.hpp> #include <scene/mesh.hpp>
@@ -64,6 +66,7 @@ void HHM::rayReturn(HitInfo* hit)
{ {
HARTModule* mod = mDirectory.getActiveModule(); HARTModule* mod = mDirectory.getActiveModule();
spdlog::debug("HIT!!"); spdlog::debug("HIT!!");
Renderer->computeHit(hit);
} }
void HHM::bounce(Ray* newRay) void HHM::bounce(Ray* newRay)

View File

@@ -14,6 +14,7 @@ class Scene;
class Ray; class Ray;
class HitInfo; class HitInfo;
class HARTModule; class HARTModule;
class RayRenderer;
class HHM class HHM
{ {
@@ -32,6 +33,8 @@ public:
void startTrace(RayField sourceScatter); void startTrace(RayField sourceScatter);
RayRenderer* Renderer;
private: private:
HARTModuleDirectory mDirectory; HARTModuleDirectory mDirectory;
}; };

View File

@@ -15,6 +15,7 @@ RenderDispatcher::RenderDispatcher()
{ {
mHHM = new HHM(); mHHM = new HHM();
mRenderer = new RayRenderer(mHHM); mRenderer = new RayRenderer(mHHM);
mHHM->Renderer = mRenderer;
} }
RenderDispatcher::~RenderDispatcher() RenderDispatcher::~RenderDispatcher()

View File

@@ -27,7 +27,7 @@ void RaySource::generate()
// float scale = tan(mReferenceCamera->FOV / 2.0f * helpers::PI / 180.0f); // float scale = tan(mReferenceCamera->FOV / 2.0f * helpers::PI / 180.0f);
} }
RayField RaySource::getInitialRays(bool MSAA) ReferencedRayField RaySource::getInitialRays(bool MSAA)
{ {
if (mReferenceCamera->didUpdate()) if (mReferenceCamera->didUpdate())
{ {
@@ -43,6 +43,9 @@ RayField RaySource::getInitialRays(bool MSAA)
glm::mat4 cameraToWorld = mReferenceCamera->getCameraLook(); glm::mat4 cameraToWorld = mReferenceCamera->getCameraLook();
glm::vec3 origin = mReferenceCamera->Position; glm::vec3 origin = mReferenceCamera->Position;
std::unordered_map<uint32_t, glm::ivec2> reference;
int i = 0;
for (int x = 0; x < mReferenceCamera->getRayViewport().x; x++) for (int x = 0; x < mReferenceCamera->getRayViewport().x; x++)
for (int y = 0; y < mReferenceCamera->getRayViewport().y; y++) for (int y = 0; y < mReferenceCamera->getRayViewport().y; y++)
{ {
@@ -52,9 +55,12 @@ RayField RaySource::getInitialRays(bool MSAA)
Ray* ray = new Ray; Ray* ray = new Ray;
ray->Origin = origin; ray->Origin = origin;
ray->Direction = glm::normalize((glm::vec4(Px, Py, -1.0f, 1.0f) * cameraToWorld)); ray->Direction = glm::normalize((glm::vec4(Px, Py, -1.0f, 1.0f) * cameraToWorld));
ray->Reference = i;
reference[i] = {x, y};
field.push_back(ray); field.push_back(ray);
i++;
} }
return field; return { field, reference };
} }

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include <unordered_map>
#include <graphics.hpp> #include <graphics.hpp>
@@ -10,6 +11,12 @@ namespace inferno {
class Camera; class Camera;
struct ReferencedRayField
{
RayField Field;
std::unordered_map<uint32_t, glm::ivec2> Reference;
};
class RaySource class RaySource
{ {
public: public:
@@ -17,7 +24,7 @@ public:
~RaySource(); ~RaySource();
void generate(); void generate();
RayField getInitialRays(bool MSAA); ReferencedRayField getInitialRays(bool MSAA);
private: private:
Camera* mReferenceCamera; Camera* mReferenceCamera;

View File

@@ -1,7 +1,11 @@
#include "renderer.hpp" #include "renderer.hpp"
#include <graphics.hpp>
#include <scene/camera.hpp> #include <scene/camera.hpp>
#include <scene/scene.hpp> #include <scene/scene.hpp>
#include <tracing/ray.hpp>
#include <tracing/hit.hpp>
#include "hart_module.hpp" #include "hart_module.hpp"
#include "ray_source.hpp" #include "ray_source.hpp"
@@ -86,21 +90,27 @@ void RayRenderer::draw()
{ {
mCurrentScene->newFrame(); mCurrentScene->newFrame();
RayField startRays = mRaySource->getInitialRays(true); ReferencedRayField startRays = mRaySource->getInitialRays(true);
mIface->startTrace(startRays);
for (int x = 0; x < mRenderTargetSize.x; x++)
for (int y = 0; y < mRenderTargetSize.y; y++)
{
mTarget[y * mRenderTargetSize.x + x] = { 1.0f, 0.0f, 0.0f, 1.0f };
}
mCurrentRefTable = &startRays.Reference;
mIface->startTrace(startRays.Field);
// hault wait for the module to finish // hault wait for the module to finish
bool frameStatus = false; bool frameStatus = false;
while (!frameStatus) while (!frameStatus)
{ {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
switch(mIface->getModuleState()) switch(mIface->getModuleState())
{ {
case EModuleState::Bad: case EModuleState::Bad:
spdlog::error("MODULE STATE BAD"); spdlog::error("MODULE STATE BAD");
case EModuleState::Build: case EModuleState::Build:
case EModuleState::Trace: case EModuleState::Trace:
spdlog::debug("MODULE BUSY..");
break; break;
case EModuleState::Ready: case EModuleState::Ready:
frameStatus = true; frameStatus = true;
@@ -110,8 +120,16 @@ void RayRenderer::draw()
spdlog::info("Sample complete"); spdlog::info("Sample complete");
for (auto* ray : startRays) for (auto* ray : startRays.Field)
{ {
delete ray; delete ray;
} }
} }
void RayRenderer::computeHit(HitInfo* info)
{
glm::ivec2 pos = (*mCurrentRefTable)[info->Caller->Reference];
std::lock_guard<std::mutex> lock(this->_mTarget);
float d = info->Distance;
mTarget[pos.y * mRenderTargetSize.x + pos.x] = { d, d, d, 1.0f };
}

View File

@@ -3,12 +3,14 @@
#include <graphics.hpp> #include <graphics.hpp>
#include <mutex> #include <mutex>
#include <unordered_map>
namespace inferno { namespace inferno {
class HHM; class HHM;
class Scene; class Scene;
class HitInfo;
class RaySource; class RaySource;
class RenderDispatcher; class RenderDispatcher;
@@ -28,6 +30,12 @@ public:
void prepare(); void prepare();
void draw(); void draw();
public:
void computeHit(HitInfo* info);
private:
std::unordered_map<uint32_t, glm::ivec2>* mCurrentRefTable;
private: private:
GLuint mRenderTargetTexture = 0; GLuint mRenderTargetTexture = 0;
glm::fvec4* mTarget; glm::fvec4* mTarget;