we are doing stuff

This commit is contained in:
Benjamin Kyd
2023-03-14 16:52:00 +00:00
parent 5cf173cd91
commit 617750ea47
12 changed files with 91 additions and 7936 deletions

View File

@@ -25,11 +25,11 @@ inline bool AABBIntersection(glm::vec3 min, glm::vec3 max, const Ray* r)
}
bool hit = (tmin <= tmax);
if (hit) {
std::cout << "Ray hits AABB: " << tmin << ", " << tmax << std::endl;
} else {
std::cout << "Ray misses AABB" << std::endl;
}
//if (hit) {
//std::cout << "Ray hits AABB: " << tmin << ", " << tmax << std::endl;
//} else {
//std::cout << "Ray misses AABB" << std::endl;
//}
return hit;
}
@@ -85,7 +85,7 @@ class KDTree {
void intersect(const Ray* ray, std::vector<uint32_t>& outIndices) {
intersect(mRoot, ray, outIndices);
}
KDNode* getRoot() const {
return mRoot;
}
@@ -103,7 +103,7 @@ class KDTree {
printTree(node->LeftChild, depth + 1);
printTree(node->RightChild, depth + 1);
}
private:
KDNode* buildNode(std::vector<uint32_t>& indicesToProcess, uint32_t startIdx, uint32_t endIdx, uint32_t depth) {
if (startIdx >= endIdx || depth >= mDepthLimit) {
@@ -146,26 +146,26 @@ class KDTree {
return;
}
std::cout << "Checking node bounds: " << glm::to_string(node->MinBounds) << " " << glm::to_string(node->MaxBounds) << std::endl;
//std::cout << "Checking node bounds: " << glm::to_string(node->MinBounds) << " " << glm::to_string(node->MaxBounds) << std::endl;
if (AABBIntersection(node->MinBounds, node->MaxBounds, ray)) {
std::cout << "Ray intersects node, num tris: " << (node->LeftChild || node->RightChild ? -1 : 1) << std::endl;
//std::cout << "Ray intersects node, num tris: " << (node->LeftChild || node->RightChild ? -1 : 1) << std::endl;
if (node->LeftChild || node->RightChild) {
intersect(node->LeftChild, ray, outIndices);
intersect(node->RightChild, ray, outIndices);
}
else {
std::cout << "Ray hit leaf node with triangle index: " << node->TriIdx << std::endl;
//std::cout << "Ray hit leaf node with triangle index: " << node->TriIdx << std::endl;
outIndices.push_back(node->TriIdx);
}
}
else {
std::cout << "Ray does not intersect node" << std::endl;
//std::cout << "Ray does not intersect node" << std::endl;
}
std::cout << std::endl;
exit(0);
//std::cout << std::endl;
//exit(0);
}
glm::vec3 getVertexBounds(uint32_t index) const {
return { mVertices[index * 3], mVertices[index * 3 + 1], mVertices[index * 3 + 2] };
}
@@ -174,7 +174,7 @@ class KDTree {
uint32_t partition(std::vector<uint32_t>& indicesToProcess, uint32_t startIdx, uint32_t endIdx, uint32_t axis) {
uint32_t medianIdx = (startIdx + endIdx) / 2;
glm::vec3 pivot = getVertexBounds(mIndices[indicesToProcess[medianIdx] * 3]);
std::nth_element(indicesToProcess.begin() + startIdx, indicesToProcess.begin() + medianIdx, indicesToProcess.begin() + endIdx,
std::nth_element(indicesToProcess.begin() + startIdx, indicesToProcess.begin() + medianIdx, indicesToProcess.begin() + endIdx,
[this, &pivot, axis](uint32_t a, uint32_t b) { return getVertexBounds(mIndices[a * 3])[axis] < getVertexBounds(mIndices[b * 3])[axis]; });
return medianIdx;
}
@@ -194,7 +194,7 @@ class KDTree {
return true;
}
private:
float* mVertices;
uint32_t* mIndices;

View File

@@ -25,7 +25,7 @@ public:
~HARTCPU()
{
this->stop(true);
this->stop(true);
mMasterWorker.detach();
}
@@ -33,10 +33,10 @@ public:
void* norm,
int vc,
void* indices,
int ic) override
int ic) override
{
std::lock_guard<std::mutex> lock(_mData);
mState = EModuleState::Build;
mVert = (float*)vert; mNorm = (float*)norm; mVc = vc; mIndices = (uint32_t*)indices; mIc = ic;
yolo::info(mLogModule, "Recieved {} verticies ({}) and {} indicies ({})", vc / 3, vert, ic / 3, indices);
@@ -53,24 +53,24 @@ public:
mState = EModuleState::Idle;
}
void updateTris() override {}
void start() override
void start() override
{
std::lock_guard<std::mutex> signalLock(_mSignalMut);
mIsRunning = true;
mState = EModuleState::Trace;
_mSignalCv.notify_all();
yolo::info(mLogModule, "Signal master to start");
{
std::unique_lock<std::mutex> doneLock(_mDoneMut);
_mDoneCv.wait(doneLock, [this] { return mState == EModuleState::Idle; });
}
}
void stop(bool interrupt) override
{
if (!interrupt)
@@ -86,7 +86,7 @@ public:
for (;;)
{
std::unique_lock<std::mutex> lock(_mData);
if (!mIsRunning)
if (!mIsRunning)
{
_mSignalCv.wait(lock, [this]{ return (mIsRunning || mState == EModuleState::Trace); });
}
@@ -106,11 +106,10 @@ public:
glm::vec2 bestTexcoord;
float bestDist = INFINITY;
float dist;
// Traverse the K-D tree to identify the set of triangles that may intersect the ray.
std::vector<uint32_t> candidateIndices;
mKdTree->intersect(ray, candidateIndices);
//std::cout << "Ray Candidates Available: " << candidateIndices.size() << std::endl;
for (uint32_t idx : candidateIndices)
{
@@ -121,20 +120,20 @@ public:
const glm::vec3 a = { mVert[ind1], mVert[ind1 + 1], mVert[ind1 + 2] };
const glm::vec3 b = { mVert[ind2], mVert[ind2 + 1], mVert[ind2 + 2] };
const glm::vec3 c = { mVert[ind3], mVert[ind3 + 1], mVert[ind3 + 2] };
// Perform intersection test...
if (!glm::intersectRayTriangle(ray->Origin, ray->Direction, a, b, c, coords, dist)) { continue; }
if (dist > bestDist || dist < 0.0f) { continue; }
bestIdx = idx;
bestDist = dist;
bestTexcoord = coords;
}
HitInfo hit;
hit.Caller = ray;
// If no hit, we still need to inform the HHM
if (bestIdx < 0)
if (bestIdx < 0)
{
mToTrace.pop();
continue;
@@ -156,19 +155,19 @@ private:
std::mutex _mSignalMut;
std::mutex _mDoneMut;
std::condition_variable _mSignalCv;
std::condition_variable _mDoneCv;
std::condition_variable _mDoneCv;
private:
// Scene Data
KDTree* mKdTree;
// Scene Data
KDTree* mKdTree;
float* mVert;
float* mNorm;
int mVc;
uint32_t* mIndices;
int mIc;
uint8_t mLogModule;
uint8_t mLogModule;
};
HART_INTERFACE void* _GET()

29
libhart/hart.md Normal file
View File

@@ -0,0 +1,29 @@
# inferno HART modules
Modules are registered at load time - instantiated when selected
_GET, _DESTROY & _CREDIT must be defined and return valid context's
Inferno will first initialise the module and then wait for the Ready state.
The possible states a module can be in are:
- Bad (Not ready)
- Idle (Ready for rays)
- Build (Scene is submitted and being processed)
- Trace (Tracing!)
Once the HHM dispatches a new scene to the module, it will wait until
the state is Done to dispatch work during scene building the modules
state must be Build.
Once the scene is ready and so is the trace, the HHM will start the tracing
state by calling the start function of the module, the module must go
through the rays added to it before start was called and then
for each ray, call Hit and pass the current context, this may result
in Inferno to push another ray to the queue, the module will go until
empty or signaled to stop.
Once empty the module will switch to the Ready state again, so Inferno
can get the next frame ready and repeat.
The HART Module also has the option to

View File

@@ -10,37 +10,6 @@
// TODO: C-ify the HART interface
/**
* infero HART modules
* Modules are registered at load time - instantiated when selected
* _GET, _DESTROY & _CREDIT must be defined and return valid context's
*
* Inferno will first initialise the module and then wait for the Ready state.
*
* The possible states a module can be in are:
* - Bad (Not ready)
* - Idle (Ready for rays)
* - Build (Scene is submitted and being processed)
* - Trace (Tracing!)
*
* Once the HHM dispatches a new scene to the module, it will wait until
* the state is Done to dispatch work during scene building the modules
* state must be Build.
*
* Once the scene is ready and so is the trace, the HHM will start the tracing
* state by calling the start function of the module, the module must go
* through the rays added to it before start was called and then
* for each ray, call Hit and pass the current context, this may result
* in Inferno to push another ray to the queue, the module will go until
* empty or signaled to stop.
*
* Once empty the module will switch to the Ready state again, so Inferno
* can get the next frame ready and repeat.
*
* The HART Module also has the option to
*
*/
namespace inferno {
#ifdef _WIN32
@@ -53,14 +22,12 @@ namespace inferno {
#define HART_INTERFACE extern "C"
#endif
//#define REGISTER_MODULE
HART_INTERFACE typedef void* (*HART_INIT_F)(void);
HART_INTERFACE typedef void (*HART_DESTROY_F)(void*);
HART_INTERFACE typedef void* (*HART_CREDIT_F)(void);
class HARTViz
{
};
class Ray;
class HitInfo;
@@ -69,6 +36,11 @@ typedef void (*HART_HIT_CALLBACK)(void* context, HitInfo* hit);
class HARTModule
{
public:
class HARTViz
{
};
enum class EModuleState : uint8_t
{
Bad, // Not ready!

View File

@@ -46,7 +46,7 @@ public:
private:
glm::vec2 mViewport = { 100.0f, 100.0f };
glm::vec2 mRayViewport = { 3.0f, 3.0f };
glm::vec2 mRayViewport = { 200.0f, 200.0f };
glm::mat4 mViewMatrix = {};
glm::mat4 mProjMatrix = {};
glm::mat4 mCameraLook = {};

File diff suppressed because it is too large Load Diff

View File

@@ -28,7 +28,7 @@ HARTModuleDirectory* HHM::getModuleDirectory()
return &mDirectory;
}
EModuleState HHM::getModuleState()
HARTModule::EModuleState HHM::getModuleState()
{
HARTModule* mod = mDirectory.getActiveModule();
return mod->getState();

View File

@@ -16,17 +16,17 @@ class HitInfo;
class HARTModule;
class RayRenderer;
class HHM
class HHM
{
public:
HHM();
~HHM();
HARTModuleDirectory* getModuleDirectory();
EModuleState getModuleState();
HARTModule::EModuleState getModuleState();
void newScene(Scene* scene);
void notifySceneUpdate();
void notifySceneUpdate();
void rayReturn(HitInfo* hit);
void bounce(Ray* newRay);

View File

@@ -57,14 +57,14 @@ static void HelpMarker(const char* desc)
}
}
void Inferno::uiPreset()
void Inferno::uiPreset()
{
ImGuiID dockspace_id = ImGui::GetID("main");
ImGui::DockBuilderRemoveNode(dockspace_id); // Clear out existing layout
ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_DockSpace); // Add empty node
ImGui::DockBuilderSetNodeSize(dockspace_id, {1000, 1000});
ImGuiID dock_main_id = dockspace_id; // This variable will track the document node, however we are not using it here as we aren't docking anything into it.
ImGuiID dock_left = ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Left, 0.5f, NULL, &dock_main_id);
ImGui::DockBuilderDockWindow("Preview", dock_left);
@@ -112,7 +112,7 @@ void Inferno::moveInput()
movementDelta |= 0b00010000;
if (glfwGetKey(mWin->getGLFWWindow(), GLFW_KEY_SPACE) == GLFW_PRESS)
movementDelta |= 0b00001000;
if (glfwGetKey(mWin->getGLFWWindow(), GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
if (glfwGetKey(mWin->getGLFWWindow(), GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
movementDelta |= 0b00000100;
}
@@ -148,7 +148,7 @@ int Inferno::run()
mRasterRenderer->setScene(mScene);
mRayRenderer->getRenderer()->setScene(mScene);
while (true)
while (true)
{
if (!mWin->newFrame()) { break; }
camera.newFrame();
@@ -320,8 +320,8 @@ int Inferno::run()
default: error = std::to_string((uint32_t)err); break;
}
yolo::error("[GL]: {} {}", err, error);
}
}
mWin->render();
}

View File

@@ -3,13 +3,13 @@
#include <exception>
int main(int argc, char** argv)
int main(int argc, char** argv)
{
try
try
{
return inferno::Inferno::GetInstance().run();
}
catch (std::exception e)
catch (std::exception e)
{
yolo::error(e.what());
return -1;

View File

@@ -39,7 +39,7 @@ ReferencedRayField RaySource::getInitialRays(bool MSAA)
const float aspect = mReferenceCamera->getRayViewport().x / mReferenceCamera->getRayViewport().y;
float scale = tan(mReferenceCamera->FOV / 2.0f * helpers::PI / 180.0f);
glm::mat4 cameraToWorld = mReferenceCamera->getCameraLook();
glm::vec3 origin = mReferenceCamera->Position;
@@ -53,7 +53,7 @@ ReferencedRayField RaySource::getInitialRays(bool MSAA)
float Py = (2.0f * ((y + 0.5f) / mReferenceCamera->getRayViewport().y) - 1.0f) * scale;
Ray* ray = new Ray{};
glm::vec4 dir4 = glm::vec4(Px, Py, -1.0f, 1.0f) * cameraToWorld;
glm::vec3 dir3 = glm::vec3(dir4) / dir4.w;
ray->Direction = glm::normalize(dir3);

View File

@@ -15,7 +15,7 @@ class HitInfo;
class RaySource;
class RenderDispatcher;
class RayRenderer
class RayRenderer
{
public:
RayRenderer(HHM* accelIface);
@@ -46,7 +46,7 @@ private:
std::mutex _RenderData;
std::condition_variable _RenderPause;
glm::ivec2 mRenderTargetSize = {3, 3};
glm::ivec2 mRenderTargetSize = {200, 200};
Scene* mCurrentScene = nullptr;
RaySource* mRaySource = nullptr;