what's that? a segfault???
This commit is contained in:
@@ -4,8 +4,11 @@
|
||||
|
||||
namespace inferno {
|
||||
|
||||
class Ray;
|
||||
|
||||
struct HitInfo
|
||||
{
|
||||
Ray* Caller;
|
||||
// indicie of hit ^ mesh idx of hit
|
||||
int Identifier;
|
||||
glm::vec2 UV;
|
||||
|
||||
@@ -8,6 +8,7 @@ struct Ray
|
||||
{
|
||||
glm::vec3 Origin;
|
||||
glm::vec3 Direction;
|
||||
uint32_t Reference;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "hart_module.hpp"
|
||||
|
||||
#include <renderer/ray_source.hpp>
|
||||
#include <renderer/renderer.hpp>
|
||||
|
||||
#include <scene/scene.hpp>
|
||||
#include <scene/mesh.hpp>
|
||||
|
||||
@@ -64,6 +66,7 @@ void HHM::rayReturn(HitInfo* hit)
|
||||
{
|
||||
HARTModule* mod = mDirectory.getActiveModule();
|
||||
spdlog::debug("HIT!!");
|
||||
Renderer->computeHit(hit);
|
||||
}
|
||||
|
||||
void HHM::bounce(Ray* newRay)
|
||||
|
||||
@@ -14,6 +14,7 @@ class Scene;
|
||||
class Ray;
|
||||
class HitInfo;
|
||||
class HARTModule;
|
||||
class RayRenderer;
|
||||
|
||||
class HHM
|
||||
{
|
||||
@@ -32,6 +33,8 @@ public:
|
||||
|
||||
void startTrace(RayField sourceScatter);
|
||||
|
||||
RayRenderer* Renderer;
|
||||
|
||||
private:
|
||||
HARTModuleDirectory mDirectory;
|
||||
};
|
||||
|
||||
@@ -15,6 +15,7 @@ RenderDispatcher::RenderDispatcher()
|
||||
{
|
||||
mHHM = new HHM();
|
||||
mRenderer = new RayRenderer(mHHM);
|
||||
mHHM->Renderer = mRenderer;
|
||||
}
|
||||
|
||||
RenderDispatcher::~RenderDispatcher()
|
||||
|
||||
@@ -27,7 +27,7 @@ void RaySource::generate()
|
||||
// float scale = tan(mReferenceCamera->FOV / 2.0f * helpers::PI / 180.0f);
|
||||
}
|
||||
|
||||
RayField RaySource::getInitialRays(bool MSAA)
|
||||
ReferencedRayField RaySource::getInitialRays(bool MSAA)
|
||||
{
|
||||
if (mReferenceCamera->didUpdate())
|
||||
{
|
||||
@@ -43,6 +43,9 @@ RayField RaySource::getInitialRays(bool MSAA)
|
||||
glm::mat4 cameraToWorld = mReferenceCamera->getCameraLook();
|
||||
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 y = 0; y < mReferenceCamera->getRayViewport().y; y++)
|
||||
{
|
||||
@@ -52,9 +55,12 @@ RayField RaySource::getInitialRays(bool MSAA)
|
||||
Ray* ray = new Ray;
|
||||
ray->Origin = origin;
|
||||
ray->Direction = glm::normalize((glm::vec4(Px, Py, -1.0f, 1.0f) * cameraToWorld));
|
||||
ray->Reference = i;
|
||||
reference[i] = {x, y};
|
||||
|
||||
field.push_back(ray);
|
||||
i++;
|
||||
}
|
||||
|
||||
return field;
|
||||
return { field, reference };
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <graphics.hpp>
|
||||
|
||||
@@ -10,6 +11,12 @@ namespace inferno {
|
||||
|
||||
class Camera;
|
||||
|
||||
struct ReferencedRayField
|
||||
{
|
||||
RayField Field;
|
||||
std::unordered_map<uint32_t, glm::ivec2> Reference;
|
||||
};
|
||||
|
||||
class RaySource
|
||||
{
|
||||
public:
|
||||
@@ -17,7 +24,7 @@ public:
|
||||
~RaySource();
|
||||
|
||||
void generate();
|
||||
RayField getInitialRays(bool MSAA);
|
||||
ReferencedRayField getInitialRays(bool MSAA);
|
||||
|
||||
private:
|
||||
Camera* mReferenceCamera;
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
#include "renderer.hpp"
|
||||
|
||||
#include <graphics.hpp>
|
||||
|
||||
#include <scene/camera.hpp>
|
||||
#include <scene/scene.hpp>
|
||||
#include <tracing/ray.hpp>
|
||||
#include <tracing/hit.hpp>
|
||||
|
||||
#include "hart_module.hpp"
|
||||
#include "ray_source.hpp"
|
||||
@@ -86,21 +90,27 @@ void RayRenderer::draw()
|
||||
{
|
||||
mCurrentScene->newFrame();
|
||||
|
||||
RayField startRays = mRaySource->getInitialRays(true);
|
||||
mIface->startTrace(startRays);
|
||||
ReferencedRayField startRays = mRaySource->getInitialRays(true);
|
||||
|
||||
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
|
||||
bool frameStatus = false;
|
||||
while (!frameStatus)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
switch(mIface->getModuleState())
|
||||
{
|
||||
case EModuleState::Bad:
|
||||
spdlog::error("MODULE STATE BAD");
|
||||
case EModuleState::Build:
|
||||
case EModuleState::Trace:
|
||||
spdlog::debug("MODULE BUSY..");
|
||||
break;
|
||||
case EModuleState::Ready:
|
||||
frameStatus = true;
|
||||
@@ -110,8 +120,16 @@ void RayRenderer::draw()
|
||||
|
||||
spdlog::info("Sample complete");
|
||||
|
||||
for (auto* ray : startRays)
|
||||
for (auto* ray : startRays.Field)
|
||||
{
|
||||
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 };
|
||||
}
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
#include <graphics.hpp>
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace inferno {
|
||||
|
||||
class HHM;
|
||||
|
||||
class Scene;
|
||||
class HitInfo;
|
||||
class RaySource;
|
||||
class RenderDispatcher;
|
||||
|
||||
@@ -28,6 +30,12 @@ public:
|
||||
void prepare();
|
||||
void draw();
|
||||
|
||||
public:
|
||||
void computeHit(HitInfo* info);
|
||||
|
||||
private:
|
||||
std::unordered_map<uint32_t, glm::ivec2>* mCurrentRefTable;
|
||||
|
||||
private:
|
||||
GLuint mRenderTargetTexture = 0;
|
||||
glm::fvec4* mTarget;
|
||||
|
||||
Reference in New Issue
Block a user