WELL WELL LOOK WHOS INSIDE AGAIN

This commit is contained in:
Benjamin Kyd
2023-01-23 16:12:31 +00:00
parent 200ecad6b3
commit 7eb251e145
7 changed files with 52 additions and 85 deletions

View File

@@ -44,7 +44,7 @@ public:
{
std::unique_lock<std::mutex> lock(_mData);
mLastState = mState.load();
if (mToTrace.empty())
if (mToTrace.size() == 0)
{
lock.unlock();
mState = EModuleState::Ready;
@@ -57,7 +57,7 @@ public:
spdlog::info("[hartcpu] Signal start");
}
auto* ray = mToTrace.front();
Ray* ray = mToTrace.front();
int bestIdx = -1;
glm::vec2 coords;
glm::vec2 bestTexcoord;
@@ -78,7 +78,8 @@ public:
bestTexcoord = coords;
}
HitInfo* hit = new HitInfo{};
HitInfo hit;
hit.Caller = ray;
// If no hit, we still need to inform the HHM
if (bestIdx < 0)
{
@@ -86,10 +87,10 @@ public:
continue;
}
hit->Distance = bestDist;
hit->UV = bestTexcoord;
hit.Distance = bestDist;
hit.UV = bestTexcoord;
Hit(mCtx, hit);
Hit(mCtx, &hit);
mToTrace.pop();
}

View File

@@ -44,8 +44,8 @@ void HHM::newScene(Scene* scene)
// which would involve a lot of mesh copying (avoid!) if i were to chain them
for (auto* mesh : meshs) {
void* verticies; void* normals; void* indicies;
int vertexCount = mesh->getVerticies(verticies, normals);
int indexCount = mesh->getIndicies(indicies);
int vertexCount = mesh->getVerticies(&verticies, &normals);
int indexCount = mesh->getIndicies(&indicies);
spdlog::debug("Mesh for module ready... {} {}", verticies, normals);
mod->submitTris(verticies, normals, vertexCount, indicies, indexCount);
}
@@ -64,13 +64,11 @@ void rayHitCallback(void* hhm, HitInfo* hit)
void HHM::rayReturn(HitInfo* hit)
{
HARTModule* mod = mDirectory.getActiveModule();
Renderer->computeHit(hit);
}
void HHM::bounce(Ray* newRay)
{
HARTModule* mod = mDirectory.getActiveModule();
}

View File

@@ -45,14 +45,14 @@ ReferencedRayField RaySource::getInitialRays(bool MSAA)
std::unordered_map<uint32_t, glm::ivec2> reference;
int i = 0;
uint32_t i = 0;
for (int x = 0; x < mReferenceCamera->getRayViewport().x; x++)
for (int y = 0; y < mReferenceCamera->getRayViewport().y; y++)
{
float Px = (2.0f * ((x + 0.5f) / mReferenceCamera->getRayViewport().x) - 1.0f) * scale * aspect;
float Py = (1.0f - 2.0f * ((y + 0.5f) / mReferenceCamera->getRayViewport().y) * scale);
Ray* ray = new Ray;
Ray* ray = new Ray{};
ray->Origin = origin;
ray->Direction = glm::normalize((glm::vec4(Px, Py, -1.0f, 1.0f) * cameraToWorld));
ray->Reference = i;

View File

@@ -83,10 +83,33 @@ void RayRenderer::prepare()
assert(mCurrentScene != NULL);
if (mCurrentScene->didUpdate())
{
spdlog::debug("New Scene!");
mIface->newScene(mCurrentScene);
}
}
void RayRenderer::mHaultWait()
{
bool frameStatus = false;
while (!frameStatus)
{
std::lock_guard<std::mutex> lock(this->_mTarget);
switch(mIface->getModuleState())
{
case EModuleState::Bad:
spdlog::error("MODULE STATE BAD");
break;
case EModuleState::Build:
spdlog::error("MODULE STATE BUILD");
case EModuleState::Trace:
break;
case EModuleState::Ready:
frameStatus = true;
break;
}
}
}
void RayRenderer::draw()
{
mCurrentScene->newFrame();
@@ -99,74 +122,12 @@ void RayRenderer::draw()
mTarget[y * mRenderTargetSize.x + x] = { 1.0f, 0.0f, 0.0f, 1.0f };
}
mHaultWait();
mCurrentRefTable = &startRays.Reference;
// mIface->startTrace(startRays.Field);
mIface->startTrace(startRays.Field);
// hault wait for the module to finish
// bool frameStatus = false;
// while (!frameStatus)
// {
// switch(mIface->getModuleState())
// {
// case EModuleState::Bad:
// spdlog::error("MODULE STATE BAD");
// break;
// case EModuleState::Build:
// spdlog::error("MODULE STATE BUILD");
// case EModuleState::Trace:
// break;
// case EModuleState::Ready:
// frameStatus = true;
// break;
// }
// }
while(!startRays.Field.empty())
{
void* verticies; void* normals; void* indicies;
int vertexCount = mCurrentScene->getRenderables()[0]->getVerticies(verticies, normals);
int indexCount = mCurrentScene->getRenderables()[0]->getIndicies(indicies);
float* mVert = (float*)verticies; float* mNorm = (float*)normals;
int mVc = vertexCount; uint32_t* mIndicies = (uint32_t*)indicies; int mIc = indexCount;
auto* ray = startRays.Field.front();
int bestIdx = -1;
glm::vec2 coords;
glm::vec2 bestTexcoord;
float bestDist = INFINITY;
float dist;
for (int i = 0; i < mCurrentScene->getRenderables()[0]->getIndexCount() ; i += 9)
{
uint32_t ind = mIndicies[i];
// Check if the ray intersects
const glm::vec3 a = { mVert[ind + 1], mVert[ind + 2], mVert[ind + 3] };
const glm::vec3 b = { mVert[ind + 4], mVert[ind + 5], mVert[ind + 6] };
const glm::vec3 c = { mVert[ind + 7], mVert[ind + 8], mVert[ind + 9] };
if (!glm::intersectRayTriangle(ray->Origin, ray->Direction, a, b, c, coords, dist)) { continue; }
if (dist > bestDist || dist < 0.0f) { continue; }
bestIdx = i;
bestDist = dist;
bestTexcoord = coords;
}
HitInfo* hit = new HitInfo{};
// If no hit, we still need to inform the HHM
if (bestIdx < 0)
{
startRays.Field.pop_back();
continue;
}
hit->Distance = bestDist;
hit->UV = bestTexcoord;
glm::ivec2 pos = (*mCurrentRefTable)[ray->Reference];
spdlog::debug("HIT!!");
mTarget[pos.y * mRenderTargetSize.x + pos.x] = { bestDist, bestDist, bestDist, 1.0f };
startRays.Field.pop_back();
// this->computeHit(hit);
}
mHaultWait();
spdlog::info("Sample complete");
@@ -179,6 +140,11 @@ void RayRenderer::draw()
void RayRenderer::computeHit(HitInfo* info)
{
spdlog::debug("HIT!!");
if (!(*mCurrentRefTable).count(info->Caller->Reference))
{
spdlog::warn("Why is the ray not in the map?!");
return;
}
glm::ivec2 pos = (*mCurrentRefTable)[info->Caller->Reference];
std::lock_guard<std::mutex> lock(this->_mTarget);
float d = info->Distance;

View File

@@ -34,6 +34,8 @@ public:
void computeHit(HitInfo* info);
private:
void mHaultWait();
std::unordered_map<uint32_t, glm::ivec2>* mCurrentRefTable;
private:

View File

@@ -74,17 +74,17 @@ void Mesh::ready()
spdlog::debug("Mesh for preview ready...");
}
int Mesh::getVerticies(void*& v, void*& n)
int Mesh::getVerticies(void** v, void** n)
{
v = (void*)&mObjLoader->getPositions()[0];
n = (void*)&mObjLoader->getNormals()[0];
*v = (void*)&mObjLoader->getPositions()[0];
*n = (void*)&mObjLoader->getNormals()[0];
// spdlog::debug("Mesh get {} {}", v, n);
return mObjLoader->getVertCount();
}
int Mesh::getIndicies(void*& i)
int Mesh::getIndicies(void** i)
{
i = (void*)&mObjLoader->getFaces()[0];
*i = (void*)&mObjLoader->getFaces()[0];
return mObjLoader->getIndexCount();
}

View File

@@ -26,8 +26,8 @@ public:
void loadOBJ(std::filesystem::path file);
void ready();
int getVerticies(void*& v, void*& n);
int getIndicies(void*& i);
int getVerticies(void** v, void** n);
int getIndicies(void** i);
int getIndexCount();