Reworked DebugDraw system (only lines now)

This commit is contained in:
Kah Wei 2022-12-14 01:20:12 +08:00
parent 8df2d66f79
commit 06cc969658
12 changed files with 571 additions and 520 deletions

View File

@ -0,0 +1,27 @@
#version 450
#extension GL_KHR_vulkan_glsl : enable
layout(location = 0) in vec4 aVertexPos;
layout(location = 1) in mat4 worldTransform;
layout(location = 5) in vec4 color;
// Output
layout(location = 0) out struct
{
vec4 Color;
} Out;
layout(set = 2, binding = 0) uniform CameraData
{
vec4 position;
mat4 vpMat;
mat4 viewMat;
mat4 perspectiveMat;
mat4 orthoMat;
} cameraData;
void main()
{
gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos.xyz, 1.0f);
Out.Color = color;
}

Binary file not shown.

View File

@ -0,0 +1,3 @@
Name: DebugDrawMesh_VS
ID: 42127043
Type: 2

View File

@ -4,11 +4,10 @@
layout(location = 0) in vec4 aVertexPos; layout(location = 0) in vec4 aVertexPos;
layout(location = 1) in vec4 aVertColor; layout(location = 1) in vec4 aVertColor;
// Output
layout(location = 0) out struct layout(location = 0) out struct
{ {
vec4 vertColor; // location 0 vec4 vertColor; // location 0
} Out; } Out;
layout(set = 2, binding = 0) uniform CameraData layout(set = 2, binding = 0) uniform CameraData

View File

@ -25,308 +25,326 @@ of DigiPen Institute of Technology is prohibited.
namespace SHADE namespace SHADE
{ {
/*---------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* DrawRoutine */ /* DrawRoutine */
/*---------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
SHDebugDrawSystem::ProcessPointsRoutine::ProcessPointsRoutine() SHDebugDrawSystem::ProcessPointsRoutine::ProcessPointsRoutine()
: SHSystemRoutine("Debug Draw", true) : SHSystemRoutine("Debug Draw", true)
{
SystemFamily::GetID<SHDebugDrawSystem>();
}
void SHDebugDrawSystem::ProcessPointsRoutine::Execute(double dt) noexcept
{
auto gfxSys = SHSystemManager::GetSystem<SHGraphicsSystem>();
if (!gfxSys)
{ {
SystemFamily::GetID<SHDebugDrawSystem>(); SHLOG_ERROR("[DebugDraw] Attempted to do debug draw without a graphics system.");
return;
} }
void SHDebugDrawSystem::ProcessPointsRoutine::Execute(double dt) noexcept // Get the system
SHDebugDrawSystem* system = static_cast<SHDebugDrawSystem*>(GetSystem());
// Get current frame index
const uint32_t FRAME_IDX = gfxSys->GetCurrentFrameIndex();
for (auto& batch : system->lineBatches)
{ {
auto gfxSys = SHSystemManager::GetSystem<SHGraphicsSystem>(); system->prepareBatch(batch, FRAME_IDX);
if (!gfxSys) batch.Points.clear();
{
SHLOG_WARNING("[DebugDraw] Attempted to do debug draw without a graphics system.");
return;
}
// Get the system
SHDebugDrawSystem* system = static_cast<SHDebugDrawSystem*>(GetSystem());
// Get current frame index
const uint32_t FRAME_IDX = gfxSys->GetCurrentFrameIndex();
/* Non-Persistent Buffer */
// Update the buffer
system->numPoints[FRAME_IDX] = system->points.size();
const uint32_t DATA_SIZE = sizeof(PointVertex) * system->points.size();
if (DATA_SIZE > 0)
{
system->vertexBuffers[FRAME_IDX]->WriteToMemory(system->points.data(), DATA_SIZE, 0, 0);
}
// Reset for next frame
system->points.clear();
/* Persistent Buffer */
// Check if there are changes
if (system->persistentBuffersCleared[FRAME_IDX]
||
system->numPersistentPoints[FRAME_IDX] != system->persistentPoints.size())
{
// Update Buffer
system->numPersistentPoints[FRAME_IDX] = system->persistentPoints.size();
const uint32_t DATA_SIZE = sizeof(PointVertex) * system->persistentPoints.size();
if (DATA_SIZE > 0)
{
system->persistentVertexBuffers[FRAME_IDX]->WriteToMemory(system->persistentPoints.data(), DATA_SIZE, 0, 0);
}
// Reset Flag
system->persistentBuffersCleared[FRAME_IDX] = false;
}
} }
for (auto& batch : system->persistentLineBatches)
/*---------------------------------------------------------------------------------*/
/* SHSystem overrides */
/*---------------------------------------------------------------------------------*/
void SHDebugDrawSystem::Init()
{ {
// Register function for subpass system->prepareBatch(batch, FRAME_IDX);
const auto* GFX_SYSTEM = SHSystemManager::GetSystem<SHGraphicsSystem>(); }
auto const& RENDERERS = GFX_SYSTEM->GetDefaultViewport()->GetRenderers(); }
auto renderGraph = RENDERERS[SHGraphicsConstants::RenderGraphIndices::WORLD]->GetRenderGraph();
auto subPass = renderGraph->GetNode("Debug Draw")->GetSubpass("Debug Draw");
subPass->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle<SHVkCommandBuffer>& cmdBuffer, uint32_t frameIndex)
{
// Get Current frame index
const uint32_t FRAME_IDX = GFX_SYSTEM->GetCurrentFrameIndex();
// Don't draw if no points /*-----------------------------------------------------------------------------------*/
if (numPoints[FRAME_IDX] > 0) /* SHSystem overrides */
{ /*-----------------------------------------------------------------------------------*/
cmdBuffer->BeginLabeledSegment("SHDebugDraw"); void SHDebugDrawSystem::Init()
cmdBuffer->BindPipeline(GFX_SYSTEM->GetDebugDrawPipeline()); {
cmdBuffer->SetLineWidth(LineWidth); const auto* GFX_SYSTEM = SHSystemManager::GetSystem<SHGraphicsSystem>();
cmdBuffer->BindVertexBuffer(0, vertexBuffers[FRAME_IDX], 0); if (!GFX_SYSTEM)
cmdBuffer->DrawArrays(numPoints[FRAME_IDX], 1, 0, 0); {
} SHLOG_ERROR("[DebugDraw] Attempted to do debug draw without a graphics system.");
}); return;
auto subPassWithDepth = renderGraph->GetNode("Debug Draw with Depth")->GetSubpass("Debug Draw with Depth");
subPassWithDepth->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle<SHVkCommandBuffer>& cmdBuffer, uint32_t frameIndex)
{
// Get Current frame index
const uint32_t FRAME_IDX = GFX_SYSTEM->GetCurrentFrameIndex();
// Don't draw if no points
if (numPersistentPoints[FRAME_IDX] > 0)
{
cmdBuffer->BeginLabeledSegment("SHDebugDraw (Persistent)");
cmdBuffer->BindPipeline(GFX_SYSTEM->GetDebugDrawDepthPipeline());
cmdBuffer->SetLineWidth(LineWidth);
cmdBuffer->BindVertexBuffer(0, persistentVertexBuffers[FRAME_IDX], 0);
cmdBuffer->DrawArrays(numPersistentPoints[FRAME_IDX], 1, 0, 0);
cmdBuffer->EndLabeledSegment();
}
});
// Reset trackers
std::fill_n(numPoints.begin(), numPoints.size(), 0);
std::fill_n(numPersistentPoints.begin(), numPersistentPoints.size(), 0);
for (bool& cleared : persistentBuffersCleared)
cleared = true;
// Allocate buffers
// - Non-Persistent Draws
static constexpr uint32_t BUFFER_SIZE = MAX_POINTS * sizeof(PointVertex);
for (Handle<SHVkBuffer>& bufHandle : vertexBuffers)
{
bufHandle = GFX_SYSTEM->GetDevice()->CreateBuffer
(
BUFFER_SIZE,
nullptr,
0,
vk::BufferUsageFlagBits::eVertexBuffer,
VmaMemoryUsage::VMA_MEMORY_USAGE_AUTO,
VmaAllocationCreateFlagBits::VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VmaAllocationCreateFlagBits::VMA_ALLOCATION_CREATE_MAPPED_BIT,
"Debug Draw Non-Persistent Vertex Buffer"
);
}
// - Persistent Draws
for (Handle<SHVkBuffer>& bufHandle : persistentVertexBuffers)
{
bufHandle = GFX_SYSTEM->GetDevice()->CreateBuffer
(
BUFFER_SIZE,
nullptr,
0,
vk::BufferUsageFlagBits::eVertexBuffer,
VmaMemoryUsage::VMA_MEMORY_USAGE_AUTO,
VmaAllocationCreateFlagBits::VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VmaAllocationCreateFlagBits::VMA_ALLOCATION_CREATE_MAPPED_BIT,
"Debug Draw Persistent Vertex Buffer"
);
}
} }
void SHDebugDrawSystem::Exit() // Create all batches
createLineBatches();
createMeshBatches();
// Register function for subpass
auto const& RENDERERS = GFX_SYSTEM->GetDefaultViewport()->GetRenderers();
auto renderGraph = RENDERERS[SHGraphicsConstants::RenderGraphIndices::WORLD]->GetRenderGraph();
auto subPass = renderGraph->GetNode("Debug Draw")->GetSubpass("Debug Draw");
subPass->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle<SHVkCommandBuffer>& cmdBuffer, uint32_t frameIndex)
{ {
for (auto vertexBuffer : vertexBuffers) const uint32_t FRAME_IDX = GFX_SYSTEM->GetCurrentFrameIndex();
{ renderBatch(lineBatches[static_cast<int>(LineRenderMode::NoDepthTest)], cmdBuffer, FRAME_IDX);
if (vertexBuffer) renderBatch(persistentLineBatches[static_cast<int>(LineRenderMode::NoDepthTest)], cmdBuffer, FRAME_IDX);
vertexBuffer.Free(); });
} auto subPassWithDepth = renderGraph->GetNode("Debug Draw with Depth")->GetSubpass("Debug Draw with Depth");
for (auto vertexBuffer : persistentVertexBuffers) subPassWithDepth->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle<SHVkCommandBuffer>& cmdBuffer, uint32_t frameIndex)
{ {
if (vertexBuffer) const uint32_t FRAME_IDX = GFX_SYSTEM->GetCurrentFrameIndex();
vertexBuffer.Free(); renderBatch(lineBatches[static_cast<int>(LineRenderMode::DepthTested)], cmdBuffer, FRAME_IDX);
} renderBatch(persistentLineBatches[static_cast<int>(LineRenderMode::DepthTested)], cmdBuffer, FRAME_IDX);
});
}
void SHDebugDrawSystem::Exit()
{
// Destroy buffers in the batches
destroyLineBatches();
destroyMeshBatches();
}
/*-----------------------------------------------------------------------------------*/
/* Draw Functions */
/*-----------------------------------------------------------------------------------*/
void SHDebugDrawSystem::DrawLine(const SHVec3& start, const SHVec3& end, const SHColour& color, bool depthTested)
{
// Insert into the batch
drawLine(getLineBatch(depthTested), start, end, color);
}
void SHDebugDrawSystem::DrawLineLoop(std::initializer_list<SHVec3> points, const SHColour& color, bool depthTested)
{
DrawLineLoop(points.begin(), points.end(), color, depthTested);
}
void SHDebugDrawSystem::DrawTri(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHColour& color, bool depthTested)
{
DrawLineLoop({ p1, p2, p3 }, color, depthTested);
}
/*-----------------------------------------------------------------------------------*/
/* Persistent Draw Functions */
/*-----------------------------------------------------------------------------------*/
void SHDebugDrawSystem::DrawPersistentLine(const SHVec3& start, const SHVec3& end, const SHColour& color, bool depthTested)
{
// Insert into the batch
drawLine(getPersistentLineBatch(depthTested), start, end, color);
}
void SHDebugDrawSystem::DrawPersistentLineLoop(std::initializer_list<SHVec3> points, const SHColour& color, bool depthTested)
{
DrawPersistentLineLoop(points.begin(), points.end(), color, depthTested);
}
void SHDebugDrawSystem::DrawPersistentTri(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHColour& color, bool depthTested)
{
DrawPersistentLineLoop({ p1, p2, p3 }, color, depthTested);
}
/*-----------------------------------------------------------------------------------*/
/* Helper Draw Functions */
/*-----------------------------------------------------------------------------------*/
void SHDebugDrawSystem::drawLine(LinesBatch& batch, const SHVec3& start, const SHVec3& end, const SHColour& color)
{
// Check if points exceeded max
if (batch.Points.size() >= MAX_POINTS)
{
SHLOG_WARNING("[SHDebugDrawSystem] Exceeded maximum size of drawable debug lines. Ignoring.");
return;
} }
/*---------------------------------------------------------------------------------*/ batch.Points.emplace_back(start, color);
/* Draw Functions */ batch.Points.emplace_back(end, color);
/*---------------------------------------------------------------------------------*/ }
void SHDebugDrawSystem::DrawLine(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt)
/*-----------------------------------------------------------------------------------*/
/* Helper Batch Functions - Lines */
/*-----------------------------------------------------------------------------------*/
SHDebugDrawSystem::LinesBatch& SHDebugDrawSystem::getLineBatch(bool depthTested)
{
return depthTested ? lineBatches[static_cast<int>(LineRenderMode::DepthTested)]
: lineBatches[static_cast<int>(LineRenderMode::NoDepthTest)];
}
SHDebugDrawSystem::LinesBatch& SHDebugDrawSystem::getPersistentLineBatch(bool depthTested)
{
return depthTested ? persistentLineBatches[static_cast<int>(LineRenderMode::DepthTested)]
: persistentLineBatches[static_cast<int>(LineRenderMode::NoDepthTest)];
}
void SHDebugDrawSystem::createLineBatches()
{
auto gfxSys = SHSystemManager::GetSystem<SHGraphicsSystem>();
if (!gfxSys)
{ {
drawLine(points, color, startPt, endPt); SHLOG_ERROR("[DebugDraw] Attempted to do debug draw without a graphics system.");
return;
} }
void SHDebugDrawSystem::DrawTri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3) // Line Batches
initBatch
(
getLineBatch(false),
gfxSys->GetDebugDrawPipeline(DebugDrawPipelineType::LineNoDepthTest),
"Debug Draw Non-Persistent Vertex Buffer"
);
initBatch
(
getLineBatch(true),
gfxSys->GetDebugDrawPipeline(DebugDrawPipelineType::LineDepthTested),
"Debug Draw Depth Tested Non-Persistent Vertex Buffer"
);
// Persistent Line Batches
initBatch
(
getPersistentLineBatch(false),
gfxSys->GetDebugDrawPipeline(DebugDrawPipelineType::LineNoDepthTest),
"Debug Draw Persistent Vertex Buffer"
);
initBatch
(
getPersistentLineBatch(true),
gfxSys->GetDebugDrawPipeline(DebugDrawPipelineType::LineDepthTested),
"Debug Draw Depth Tested Persistent Vertex Buffer"
);
}
void SHDebugDrawSystem::initBatch(LinesBatch& batch, Handle<SHVkPipeline> pipeline, const std::string& vertexBufferName)
{
auto gfxSys = SHSystemManager::GetSystem<SHGraphicsSystem>();
if (!gfxSys)
{ {
drawPoly(points, color, { pt1, pt2, pt3 }); SHLOG_WARNING("[DebugDraw] Attempted to do debug draw without a graphics system.");
return;
} }
void SHDebugDrawSystem::DrawQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4) batch.Pipeline = pipeline;
for (auto& vBuffer : batch.VertexBuffers)
{ {
drawPoly(points, color, { pt1, pt2, pt3, pt4 }); vBuffer = gfxSys->GetDevice()->CreateBuffer
(
sizeof(PointVertex) * MAX_POINTS,
nullptr,
0,
vk::BufferUsageFlagBits::eVertexBuffer,
VmaMemoryUsage::VMA_MEMORY_USAGE_AUTO,
VmaAllocationCreateFlagBits::VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT |
VmaAllocationCreateFlagBits::VMA_ALLOCATION_CREATE_MAPPED_BIT,
vertexBufferName
);
}
}
void SHDebugDrawSystem::prepareBatch(LinesBatch& batch, uint32_t frameIndex)
{
// Parameter checks
if (frameIndex > batch.VertexBuffers.size())
{
SHLOG_ERROR("[SHDebugDrawSystem] An invalid frame index was specified for debug drawing. Skipping.");
return;
} }
void SHDebugDrawSystem::DrawPoly(const SHVec4& color, std::initializer_list<SHVec3> pointList) // Fill data into the buffers
batch.NumPoints[frameIndex] = batch.Points.size();
const uint32_t DATA_SIZE = sizeof(PointVertex) * batch.Points.size();
if (DATA_SIZE > 0)
{ {
drawPoly(points, color, pointList.begin(), pointList.end()); batch.VertexBuffers[frameIndex]->WriteToMemory(batch.Points.data(), DATA_SIZE, 0, 0);
}
}
void SHDebugDrawSystem::renderBatch(LinesBatch& batch, Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex)
{
if (batch.NumPoints[frameIndex] > 0)
{
cmdBuffer->BeginLabeledSegment("SHDebugDraw");
cmdBuffer->BindPipeline(batch.Pipeline);
cmdBuffer->SetLineWidth(LineWidth);
cmdBuffer->BindVertexBuffer(0, batch.VertexBuffers[frameIndex], 0);
cmdBuffer->DrawArrays(batch.NumPoints[frameIndex], 1, 0, 0);
}
}
void SHDebugDrawSystem::destroyBatch(LinesBatch& batch)
{
for (auto& vBuffer : batch.VertexBuffers)
{
if (vBuffer)
{
vBuffer.Free();
vBuffer = {};
}
}
}
void SHDebugDrawSystem::destroyLineBatches()
{
destroyBatch(getLineBatch(true));
destroyBatch(getLineBatch(false));
destroyBatch(getPersistentLineBatch(true));
destroyBatch(getPersistentLineBatch(false));
}
/*-----------------------------------------------------------------------------------*/
/* Helper Batch Functions - Meshes */
/*-----------------------------------------------------------------------------------*/
void SHDebugDrawSystem::createMeshBatches()
{
auto gfxSys = SHSystemManager::GetSystem<SHGraphicsSystem>();
if (!gfxSys)
{
SHLOG_ERROR("[DebugDraw] Attempted to do debug draw without a graphics system.");
return;
} }
void SHDebugDrawSystem::DrawCube(const SHVec4& color, const SHVec3& pos, const SHVec3& size) // Set up batches
initBatch
(
meshBatches[static_cast<int>(MeshRenderMode::FilledNoDepthTest)],
gfxSys->GetDebugDrawPipeline(DebugDrawPipelineType::FilledMeshNoDepthTest)
);
initBatch
(
meshBatches[static_cast<int>(MeshRenderMode::FilledDepthTested)],
gfxSys->GetDebugDrawPipeline(DebugDrawPipelineType::FilledMeshDepthTested)
);
initBatch
(
meshBatches[static_cast<int>(MeshRenderMode::WireNoDepthTest)],
gfxSys->GetDebugDrawPipeline(DebugDrawPipelineType::LineMeshNoDepthTest)
);
initBatch
(
meshBatches[static_cast<int>(MeshRenderMode::WireDepthTested)],
gfxSys->GetDebugDrawPipeline(DebugDrawPipelineType::LineMeshDepthTested)
);
}
void SHDebugDrawSystem::initBatch(MeshBatch& batch, Handle<SHVkPipeline> pipeline)
{
batch.Pipeline = pipeline;
}
void SHDebugDrawSystem::destroyBatch(MeshBatch& batch)
{
for (auto& buffer : batch.InstanceDataBuffer)
{ {
drawCube(points, color, pos, size); if (buffer)
{
buffer.Free();
buffer = {};
}
} }
for (auto& buffer : batch.MDIBuffer)
void SHDebugDrawSystem::DrawSphere(const SHVec4& color, const SHVec3& pos, double radius)
{ {
drawSphere(points, color, pos, radius); if (buffer)
} {
buffer.Free();
/*---------------------------------------------------------------------------------*/ buffer = {};
/* Persistent Draw Functions */ }
/*---------------------------------------------------------------------------------*/
void SHDebugDrawSystem::DrawPersistentLine(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt)
{
drawLine(persistentPoints, color, startPt, endPt);
}
void SHDebugDrawSystem::DrawPersistentTri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3)
{
drawPoly(persistentPoints, color, { pt1, pt2, pt3 });
}
void SHDebugDrawSystem::DrawPersistentQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4)
{
drawPoly(persistentPoints, color, { pt1, pt2, pt3, pt4 });
}
void SHDebugDrawSystem::DrawPersistentPoly(const SHVec4& color, std::initializer_list<SHVec3> pointList)
{
drawPoly(persistentPoints, color, pointList.begin(), pointList.end());
}
void SHDebugDrawSystem::DrawPersistentCube(const SHVec4& color, const SHVec3& pos, const SHVec3& size)
{
drawCube(persistentPoints, color, pos, size);
}
void SHDebugDrawSystem::DrawPersistentSphere(const SHVec4& color, const SHVec3& pos, double radius)
{
drawSphere(persistentPoints, color, pos, radius);
}
void SHDebugDrawSystem::ClearPersistentDraws()
{
persistentPoints.clear();
for (bool& cleared : persistentBuffersCleared)
cleared = true;
}
void SHDebugDrawSystem::drawLine(std::vector<PointVertex>& storage, const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt)
{
if (storage.size() > MAX_POINTS)
{
SHLOG_WARNING("[DebugDraw] Exceeded maximum size of drawable debug elements.");
return;
}
storage.emplace_back(PointVertex{ startPt, color });
storage.emplace_back(PointVertex{ endPt, color });
}
void SHDebugDrawSystem::drawLineSet(std::vector<PointVertex>& storage, const SHVec4& color, std::initializer_list<SHVec3> pointList)
{
drawLineSet(storage, color, pointList.begin(), pointList.end());
}
void SHDebugDrawSystem::drawPoly(std::vector<PointVertex>& storage, const SHVec4& color, std::initializer_list<SHVec3> pointList)
{
drawPoly(storage, color, pointList.begin(), pointList.end());
}
void SHDebugDrawSystem::drawCube(std::vector<PointVertex>& storage, const SHVec4& color, const SHVec3& pos, const SHVec3& size)
{
static const SHVec3 EXTENTS = SHVec3{ 0.5f, 0.5f, 0.5f };
static const SHVec3 UNIT_BOT_LEFT_FRONT = SHVec3{ pos - EXTENTS };
static const SHVec3 UNIT_BOT_RIGHT_FRONT = SHVec3{ pos + SHVec3 { EXTENTS.x, -EXTENTS.y, -EXTENTS.z } };
static const SHVec3 UNIT_BOT_RIGHT_BACK = SHVec3{ pos + SHVec3 { EXTENTS.x, -EXTENTS.y, EXTENTS.z } };
static const SHVec3 UNIT_BOT_LEFT_BACK = SHVec3{ pos + SHVec3 { -EXTENTS.x, -EXTENTS.y, EXTENTS.z } };
static const SHVec3 UNIT_TOP_LEFT_BACK = SHVec3{ pos + SHVec3 { -EXTENTS.x, EXTENTS.y, EXTENTS.z } };
static const SHVec3 UNIT_TOP_RIGHT_FRONT = SHVec3{ pos + SHVec3 { EXTENTS.x, EXTENTS.y, -EXTENTS.z } };
static const SHVec3 UNIT_TOP_LEFT_FRONT = SHVec3{ pos + SHVec3 { -EXTENTS.x, EXTENTS.y, -EXTENTS.z } };
static const SHVec3 UNIT_TOP_RIGHT_BACK = SHVec3{ pos + EXTENTS };
const SHVec3 BOT_LEFT_BACK = UNIT_BOT_LEFT_BACK * size;
const SHVec3 BOT_RIGHT_BACK = UNIT_BOT_RIGHT_BACK * size;
const SHVec3 BOT_LEFT_FRONT = UNIT_BOT_LEFT_FRONT * size;
const SHVec3 BOT_RIGHT_FRONT = UNIT_BOT_RIGHT_FRONT * size;
const SHVec3 TOP_LEFT_BACK = UNIT_TOP_LEFT_BACK * size;
const SHVec3 TOP_RIGHT_BACK = UNIT_TOP_RIGHT_BACK * size;
const SHVec3 TOP_LEFT_FRONT = UNIT_TOP_LEFT_FRONT * size;
const SHVec3 TOP_RIGHT_FRONT = UNIT_TOP_RIGHT_FRONT * size;
drawLineSet
(
storage,
color,
{
// Bottom Square
BOT_LEFT_BACK , BOT_RIGHT_BACK,
BOT_RIGHT_BACK , BOT_RIGHT_FRONT,
BOT_RIGHT_FRONT, BOT_LEFT_FRONT,
BOT_LEFT_FRONT , BOT_LEFT_BACK,
// Top Square
TOP_LEFT_BACK , TOP_RIGHT_BACK,
TOP_RIGHT_BACK , TOP_RIGHT_FRONT,
TOP_RIGHT_FRONT, TOP_LEFT_FRONT,
TOP_LEFT_FRONT , TOP_LEFT_BACK,
// Middle Lines
TOP_LEFT_BACK , BOT_LEFT_BACK,
TOP_RIGHT_BACK , BOT_RIGHT_BACK,
TOP_RIGHT_FRONT, BOT_RIGHT_FRONT,
TOP_LEFT_FRONT , BOT_LEFT_FRONT
}
);
}
void SHDebugDrawSystem::drawSphere(std::vector<PointVertex>& storage, const SHVec4& color, const SHVec3& pos, double radius)
{
//if (spherePoints.empty())
{
spherePoints.clear();
// Generate
static const SHMeshData SPHERE = SHPrimitiveGenerator::Sphere();
for (const auto& idx : SPHERE.Indices)
{
spherePoints.emplace_back(SPHERE.VertexPositions[idx] * radius + pos);
}
}
drawLineSet(storage, color, spherePoints.begin(), spherePoints.end());
} }
}
void SHDebugDrawSystem::destroyMeshBatches()
{
destroyBatch(meshBatches[static_cast<int>(MeshRenderMode::FilledNoDepthTest)]);
destroyBatch(meshBatches[static_cast<int>(MeshRenderMode::FilledDepthTested)]);
destroyBatch(meshBatches[static_cast<int>(MeshRenderMode::WireNoDepthTest)]);
destroyBatch(meshBatches[static_cast<int>(MeshRenderMode::WireDepthTested)]);
}
} }

View File

@ -18,6 +18,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Math/Vector/SHVec2.h" #include "Math/Vector/SHVec2.h"
#include "Math/Vector/SHVec3.h" #include "Math/Vector/SHVec3.h"
#include "Math/Vector/SHVec4.h" #include "Math/Vector/SHVec4.h"
#include "Math/SHMatrix.h"
#include "ECS_Base/System/SHSystem.h" #include "ECS_Base/System/SHSystem.h"
#include "ECS_Base/System/SHSystemRoutine.h" #include "ECS_Base/System/SHSystemRoutine.h"
#include "Resource/SHHandle.h" #include "Resource/SHHandle.h"
@ -31,6 +32,8 @@ namespace SHADE
/* Forward Declarations */ /* Forward Declarations */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
class SHVkBuffer; class SHVkBuffer;
class SHMesh;
class SHVkPipeline;
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Type Definitions */ /* Type Definitions */
@ -42,6 +45,29 @@ namespace SHADE
{ {
public: public:
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Type Definitions */
/*---------------------------------------------------------------------------------*/
/// <summary>
/// Defines the rendering mode for debug lines.
/// </summary>
enum class LineRenderMode : uint32_t
{
NoDepthTest,
DepthTested,
Count
};
/// <summary>
/// Defines the rendering mode for debug meshes.
/// </summary>
enum class MeshRenderMode : uint32_t
{
FilledNoDepthTest,
FilledDepthTested,
WireNoDepthTest,
WireDepthTested,
Count
};
/*---------------------------------------------------------------------------------*/
/* System Routines */ /* System Routines */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
class SH_API ProcessPointsRoutine final : public SHSystemRoutine class SH_API ProcessPointsRoutine final : public SHSystemRoutine
@ -68,185 +94,130 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Draw Functions */ /* Draw Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/// <summary> void DrawLine(const SHVec3& start, const SHVec3& end, const SHColour& color = SHColour::WHITE, bool depthTested = false);
/// Renders a line between two points in world space. void DrawLineLoop(std::initializer_list<SHVec3> points, const SHColour& color = SHColour::WHITE, bool depthTested = false);
/// </summary>
/// <param name="color">Colour of the line.</param>
/// <param name="startPt">First point of the line.</param>
/// <param name="endPt">Second point of the line.</param>
void DrawLine(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt);
/// <summary>
/// Renders a triangle indicated by three points in world space.
/// </summary>
/// <param name="color">Colour of the triangle.</param>
/// <param name="pt1">First point of the triangle.</param>
/// <param name="pt2">Second point of the triangle.</param>
/// <param name="pt3">Third point of the triangle.</param>
void DrawTri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3);
/// <summary>
/// Renders a quadrilateral indicated by four points in world space.
/// </summary>
/// <param name="color">Colour of the quadrilateral.</param>
/// <param name="pt1">First point of the triangle.</param>
/// <param name="pt2">Second point of the quadrilateral.</param>
/// <param name="pt3">Third point of the quadrilateral.</param>
/// <param name="pt4">Third point of the quadrilateral.</param>
void DrawQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4);
/// <summary>
/// Renders a polygon indicated by the specified set of points in world space.
/// </summary>
/// <param name="color">Colour of the polygon.</param>
/// <param name="pointList">List of points for the polygon.</param>
void DrawPoly(const SHVec4& color, std::initializer_list<SHVec3> pointList);
/// <summary>
/// Renders a polygon indicated by the specified set of points in world space.
/// </summary>
/// <typeparam name="IterType">Iterator for a STL-like container.</typeparam>
/// <param name="color">Colour of the polygon.</param>
/// <param name="pointListBegin">
/// Iterator to the first point of the point container.
/// </param>
/// <param name="pointListEnd">
/// One past last iterator of the point container.
/// </param>
template<typename IterType> template<typename IterType>
void DrawPoly(const SHVec4& color, IterType pointListBegin, IterType pointListEnd); void DrawLineLoop(IterType pointListBegin, IterType pointListEnd, const SHColour& color = SHColour::WHITE, bool depthTested = false);
/// <summary> void DrawTri(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHColour& color = SHColour::WHITE, bool depthTested = false);
/// Renders a wireframe cube centered around the position specified in world space. //void DrawWireBox(const SHVec3& position, const SHVec3& scale, const SHColour& color = SHColour::WHITE, bool depthTested = false);
/// </summary>
/// <param name="color">Colour of the cube.</param>
/// <param name="pos">Position where the cube wil be centered at.</param>
/// <param name="size">Size of the rendered cube.</param>
void DrawCube(const SHVec4& color, const SHVec3& pos, const SHVec3& size);
/// <summary>
/// Renders a wireframe sphere centered around the position specified in world space.
/// </summary>
/// <param name="color">Colour of the sphere.</param>
/// <param name="pos">Position where the sphere wil be centered at.</param>
/// <param name="size">Size of the rendered sphere.</param>
void DrawSphere(const SHVec4& color, const SHVec3& pos, double radius);
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Persistent Draw Functions */ /* Persistent Draw Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/// <summary> void DrawPersistentLine(const SHVec3& start, const SHVec3& end, const SHColour& color = SHColour::WHITE, bool depthTested = false);
/// Renders a line between two points in world space that will persist until void DrawPersistentLineLoop(std::initializer_list<SHVec3> points, const SHColour& color = SHColour::WHITE, bool depthTested = false);
/// ClearPersistentDraws() is called. These lines are depth tested.
/// </summary>
/// <param name="color">Colour of the line.</param>
/// <param name="startPt">First point of the line.</param>
/// <param name="endPt">Second point of the line.</param>
void DrawPersistentLine(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt);
/// <summary>
/// Renders a triangle indicated by three points in world space that will persist
/// until ClearPersistentDraws() is called. These lines are depth tested.
/// </summary>
/// <param name="color">Colour of the triangle.</param>
/// <param name="pt1">First point of the triangle.</param>
/// <param name="pt2">Second point of the triangle.</param>
/// <param name="pt3">Third point of the triangle.</param>
void DrawPersistentTri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3);
/// <summary>
/// Renders a quadrilateral indicated by four points in world space that will persist
/// until ClearPersistentDraws() is called. These lines are depth tested.
/// </summary>
/// <param name="color">Colour of the quadrilateral.</param>
/// <param name="pt1">First point of the triangle.</param>
/// <param name="pt2">Second point of the quadrilateral.</param>
/// <param name="pt3">Third point of the quadrilateral.</param>
/// <param name="pt4">Third point of the quadrilateral.</param>
void DrawPersistentQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4);
/// <summary>
/// Renders a polygon indicated by the specified set of points in world space that
/// will persist until ClearPersistentDraws() is called. These lines are depth
/// tested.
/// </summary>
/// <param name="color">Colour of the polygon.</param>
/// <param name="pointList">List of points for the polygon.</param>
void DrawPersistentPoly(const SHVec4& color, std::initializer_list<SHVec3> pointList);
/// <summary>
/// Renders a polygon indicated by the specified set of points in world space that
/// will persist until ClearPersistentDraws() is called. These lines are depth
/// tested.
/// </summary>
/// <typeparam name="IterType">Iterator for a STL-like container.</typeparam>
/// <param name="color">Colour of the polygon.</param>
/// <param name="pointListBegin">
/// Iterator to the first point of the point container.
/// </param>
/// <param name="pointListEnd">
/// One past last iterator of the point container.
/// </param>
template<typename IterType> template<typename IterType>
void DrawPersistentPoly(const SHVec4& color, IterType pointListBegin, IterType pointListEnd); void DrawPersistentLineLoop(IterType pointListBegin, IterType pointListEnd, const SHColour& color = SHColour::WHITE, bool depthTested = false);
/// <summary> void DrawPersistentTri(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHColour& color = SHColour::WHITE, bool depthTested = false);
/// Renders a wireframe cube centered around the position specified in world space
/// that will persist until ClearPersistentDraws() is called. These lines are depth
/// tested.
/// </summary>
/// <param name="color">Colour of the cube.</param>
/// <param name="pos">Position where the cube wil be centered at.</param>
/// <param name="size">Size of the rendered cube.</param>
void DrawPersistentCube(const SHVec4& color, const SHVec3& pos, const SHVec3& size);
/// <summary>
/// Renders a wireframe sphere centered around the position specified in world space
/// that will persist until ClearPersistentDraws() is called. These lines are depth
/// tested.
/// </summary>
/// <param name="color">Colour of the sphere.</param>
/// <param name="pos">Position where the sphere wil be centered at.</param>
/// <param name="size">Size of the rendered sphere.</param>
void DrawPersistentSphere(const SHVec4& color, const SHVec3& pos, double radius);
/// <summary>
/// Clears any persistent drawn debug primitives.
/// </summary>
void ClearPersistentDraws();
private: private:
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Type Definitions */ /* Type Definitions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
using TripleBuffer = std::array<Handle<SHVkBuffer>, SHGraphicsConstants::NUM_FRAME_BUFFERS>;
using TripleUInt = std::array<uint32_t , SHGraphicsConstants::NUM_FRAME_BUFFERS>;
using TripleBool = std::array<bool , SHGraphicsConstants::NUM_FRAME_BUFFERS>;
/// <summary>
/// Defines a coloured Vertex
/// </summary>
struct SH_API PointVertex struct SH_API PointVertex
{ {
SHVec4 Position; SHVec4 Position;
SHVec4 Color; SHVec4 Color;
}; };
using TripleBuffer = std::array<Handle<SHVkBuffer>, SHGraphicsConstants::NUM_FRAME_BUFFERS>; struct Batch
using TripleUInt = std::array<uint32_t , SHGraphicsConstants::NUM_FRAME_BUFFERS>; {
using TripleBool = std::array<bool , SHGraphicsConstants::NUM_FRAME_BUFFERS>; /*-------------------------------------------------------------------------------*/
/* Data Members */
/*-------------------------------------------------------------------------------*/
Handle<SHVkPipeline> Pipeline;
};
struct LinesBatch : public Batch
{
/*-------------------------------------------------------------------------------*/
/* Data Members */
/*-------------------------------------------------------------------------------*/
// CPU Buffers
std::vector<PointVertex> Points;
// GPU Buffers
TripleBuffer VertexBuffers;
TripleUInt NumPoints;
};
struct MeshBatch : public Batch
{
/*-------------------------------------------------------------------------------*/
/* Type Definitions */
/*-------------------------------------------------------------------------------*/
struct InstanceData
{
SHMatrix Transform;
SHVec4 Color;
};
struct MultiDrawSet
{
Handle<SHMesh> Mesh;
std::vector<InstanceData> Instances;
};
/*-------------------------------------------------------------------------------*/
/* Data Members */
/*-------------------------------------------------------------------------------*/
// CPU Buffers
std::vector<MultiDrawSet> SubBatches;
std::vector<InstanceData> InstanceData;
// GPU Buffers
TripleBuffer MDIBuffer;
TripleBuffer InstanceDataBuffer;
};
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Constants */ /* Constants */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
static constexpr uint32_t MAX_POINTS = 100'000; static constexpr uint32_t MAX_POINTS = 100'000;
static constexpr size_t LINE_MODE_COUNT = static_cast<size_t>(LineRenderMode::Count);
static constexpr size_t MESH_MODE_COUNT = static_cast<size_t>(MeshRenderMode::Count);
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Data Members */ /* Data Members */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
// CPU Buffers // Batches
std::vector<PointVertex> points; std::array<LinesBatch, LINE_MODE_COUNT> lineBatches;
std::vector<PointVertex> persistentPoints; std::array<LinesBatch, LINE_MODE_COUNT> persistentLineBatches;
// GPU Buffers std::array<MeshBatch , MESH_MODE_COUNT> meshBatches;
TripleBuffer vertexBuffers; // Tracking
TripleUInt numPoints; TripleBool persistentBuffersCleared; // TODO: Use this
TripleBuffer persistentVertexBuffers;
TripleUInt numPersistentPoints;
TripleBool persistentBuffersCleared;
// Cached Points for polygon drawing
std::vector<SHVec3> spherePoints;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Helper Draw Functions */ /* Helper Draw Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
void drawLine(std::vector<PointVertex>& storage, const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt); void drawLine(LinesBatch& batch, const SHVec3& start, const SHVec3& end, const SHColour& color);
void drawLineSet(std::vector<PointVertex>& storage, const SHVec4& color, std::initializer_list<SHVec3> pointList);
template<typename IterType> template<typename IterType>
void drawLineSet(std::vector<PointVertex>& storage, const SHVec4& color, IterType pointListBegin, IterType pointListEnd); void drawLineLoop(LinesBatch& batch, IterType pointListBegin, IterType pointListEnd, const SHColour& color);
void drawPoly(std::vector<PointVertex>& storage, const SHVec4& color, std::initializer_list<SHVec3> pointList);
template<typename IterType> /*---------------------------------------------------------------------------------*/
void drawPoly(std::vector<PointVertex>& storage, const SHVec4& color, IterType pointListBegin, IterType pointListEnd); /* Helper Batch Functions - Lines */
void drawCube(std::vector<PointVertex>& storage, const SHVec4& color, const SHVec3& pos, const SHVec3& size); /*---------------------------------------------------------------------------------*/
void drawSphere(std::vector<PointVertex>& storage, const SHVec4& color, const SHVec3& pos, double radius); LinesBatch& getLineBatch(bool depthTested);
LinesBatch& getPersistentLineBatch(bool depthTested);
void createLineBatches();
void initBatch(LinesBatch& batch, Handle<SHVkPipeline> pipeline, const std::string& vertexBufferName);
void prepareBatch(LinesBatch& batch, uint32_t frameIndex);
void renderBatch(LinesBatch& batch, Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex);
void destroyBatch(LinesBatch& batch);
void destroyLineBatches();
/*---------------------------------------------------------------------------------*/
/* Helper Batch Functions - Meshes */
/*---------------------------------------------------------------------------------*/
void createMeshBatches();
void initBatch(MeshBatch& batch, Handle<SHVkPipeline> pipeline);
void prepareBatch(MeshBatch& batch, uint32_t frameIndex);
void renderBatch(MeshBatch& batch, Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex);
void destroyBatch(MeshBatch& batch);;
void destroyMeshBatches();
}; };
} }

View File

@ -17,73 +17,44 @@ namespace SHADE
{ {
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Draw Functions */ /* Draw Functions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
template<typename IterType> template<typename IterType>
void SHDebugDrawSystem::DrawPoly(const SHVec4& color, IterType pointListBegin, IterType pointListEnd) void SHDebugDrawSystem::DrawLineLoop(IterType pointListBegin, IterType pointListEnd, const SHColour& color, bool depthTested)
{ {
drawPoly(points, color, pointListBegin, pointListEnd); // Get Batch
drawLineLoop(getLineBatch(depthTested), pointListBegin, pointListEnd, color);
} }
template<typename IterType>
void SHADE::SHDebugDrawSystem::DrawPersistentLineLoop(IterType pointListBegin, IterType pointListEnd, const SHColour& color , bool depthTested)
{
// Get Batch
drawLineLoop(getPersistentLineBatch(depthTested), pointListBegin, pointListEnd, color);
}
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Helper Draw Functions */ /* Helper Draw Functions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
template<typename IterType> template<typename IterType>
void SHDebugDrawSystem::drawLineSet(std::vector<PointVertex>& storage, const SHVec4& color, IterType pointListBegin, IterType pointListEnd) void SHDebugDrawSystem::drawLineLoop(LinesBatch& batch, IterType pointListBegin, IterType pointListEnd, const SHColour& color)
{ {
// Ensure dereferenced type is SHVec3 // Ensure dereferenced type is SHVec3
static_assert(std::is_same_v<SHVec3, std::remove_cvref_t<decltype(*pointListBegin)>>, "Parameters to DrawPoly must be SHVec3."); static_assert(std::is_same_v<SHVec3, std::remove_cvref_t<decltype(*pointListBegin)>>, "Parameters to DrawLineLoop must be SHVec3.");
// Check if points exceeded max
if (storage.size() > MAX_POINTS)
{
SHLOG_WARNING("[DebugDraw] Exceeded maximum size of drawable debug elements.");
return;
}
const size_t POINTS_COUNT = pointListEnd - pointListBegin;
// Invalid polygon // Invalid polygon
const size_t POINTS_COUNT = pointListEnd - pointListBegin;
if (POINTS_COUNT < 2) if (POINTS_COUNT < 2)
{ {
SHLOG_WARNING("[SHDebugDraw] Invalid polygon provided to DrawPoly()."); SHLOG_WARNING("[SHDebugDrawSystem] Insufficient points provided to drawLineLoop().");
return;
}
const size_t POINTS_ROUNDED_COUNT = POINTS_COUNT / 2 * 2;
for (auto pointIter = pointListBegin; pointIter != (pointListBegin + POINTS_ROUNDED_COUNT); ++pointIter)
{
storage.emplace_back(PointVertex{ *pointIter, color });
}
}
template<typename IterType>
void SHDebugDrawSystem::drawPoly(std::vector<PointVertex>& storage, const SHVec4& color, IterType pointListBegin, IterType pointListEnd)
{
// Ensure dereferenced type is SHVec3
static_assert(std::is_same_v<SHVec3, std::remove_cvref_t<decltype(*pointListBegin)>>, "Parameters to DrawPoly must be SHVec3.");
// Check if points exceeded max
if (storage.size() > MAX_POINTS)
{
SHLOG_WARNING("[DebugDraw] Exceeded maximum size of drawable debug elements.");
return;
}
const size_t POINTS_COUNT = pointListEnd - pointListBegin;
// Invalid polygon
if (POINTS_COUNT < 2)
{
SHLOG_WARNING("[SHDebugDraw] Invalid polygon provided to DrawPoly().");
return; return;
} }
// Trace the polygon // Trace the polygon
for (auto pointIter = pointListBegin + 1; pointIter != pointListEnd; ++pointIter) for (auto pointIter = pointListBegin + 1; pointIter != pointListEnd; ++pointIter)
{ {
storage.emplace_back(PointVertex{ *(pointIter - 1), color }); drawLine(batch, *(pointIter - 1), *pointIter, color);
storage.emplace_back(PointVertex{ *pointIter , color });
} }
// Close the line loop // Close the line loop
storage.emplace_back(PointVertex{ *(pointListEnd - 1), color }); drawLine(batch, *(pointListEnd - 1), *pointListBegin, color);
storage.emplace_back(PointVertex{ *pointListBegin , color });
} }
} }

View File

@ -124,20 +124,12 @@ namespace SHADE
SHFreetypeInstance::Init(); SHFreetypeInstance::Init();
//SHAssetManager::CompileAsset("../../Assets/Shaders/Text_VS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/Text_FS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_VS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/UI_VS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/UI_FS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Models/Quad.gltf", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/ToSwapchain_VS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/ToSwapchain_FS.glsl", false);
// Load Built In Shaders // Load Built In Shaders
static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT); static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT);
static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEFAULT); static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEFAULT);
static constexpr AssetID VS_DEBUG = 48002439; debugVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEBUG); static constexpr AssetID VS_DEBUG = 48002439; debugVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEBUG);
static constexpr AssetID FS_DEBUG = 36671027; debugFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEBUG); static constexpr AssetID FS_DEBUG = 36671027; debugFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEBUG);
static constexpr AssetID VS_DEBUG_MESH = 42127043; debugMeshVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEBUG_MESH);
static constexpr AssetID CS_COMPOSITE = 45072428; deferredCompositeShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(CS_COMPOSITE); static constexpr AssetID CS_COMPOSITE = 45072428; deferredCompositeShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(CS_COMPOSITE);
static constexpr AssetID SSAO = 38430899; ssaoShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(SSAO); static constexpr AssetID SSAO = 38430899; ssaoShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(SSAO);
static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(SSAO_BLUR); static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(SSAO_BLUR);
@ -335,14 +327,31 @@ namespace SHADE
screenRenderer->SetCamera(screenCamera); screenRenderer->SetCamera(screenCamera);
screenRenderer->SetCameraDirector(worldCameraDirector); screenRenderer->SetCameraDirector(worldCameraDirector);
// Create debug draw pipeline // Create debug draw pipeline
debugDrawPipeline = createDebugDrawPipeline(debugDrawNode->GetRenderpass(), debugDrawSubpass); debugDrawPipeline = createDebugDrawPipeline(debugDrawNode->GetRenderpass(), debugDrawSubpass, false, false, false);
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipeline, debugDrawPipeline->GetVkPipeline(), "[Pipeline] Debug Draw"); SET_VK_OBJ_NAME(device, vk::ObjectType::ePipeline, debugDrawPipeline->GetVkPipeline(), "[Pipeline] Debug Draw");
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipelineLayout, debugDrawPipeline->GetPipelineLayout()->GetVkPipelineLayout(), "[Pipeline Layout] Debug Draw Pipeline Layout"); SET_VK_OBJ_NAME(device, vk::ObjectType::ePipelineLayout, debugDrawPipeline->GetPipelineLayout()->GetVkPipelineLayout(), "[Pipeline Layout] Debug Draw");
debugDrawDepthPipeline = createDebugDrawPipeline(debugDrawNodeDepth->GetRenderpass(), debugDrawDepthSubpass); debugDrawDepthPipeline = createDebugDrawPipeline(debugDrawNodeDepth->GetRenderpass(), debugDrawDepthSubpass, false, false, false);
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipeline, debugDrawDepthPipeline->GetVkPipeline(), "[Pipeline Layout] Debug Draw with Depth Test"); SET_VK_OBJ_NAME(device, vk::ObjectType::ePipeline, debugDrawDepthPipeline->GetVkPipeline(), "[Pipeline Layout] Debug Draw with Depth Test");
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipelineLayout, debugDrawDepthPipeline->GetPipelineLayout()->GetVkPipelineLayout(), "[Pipeline] Debug Draw with Depth Test Pipeline Layout"); SET_VK_OBJ_NAME(device, vk::ObjectType::ePipelineLayout, debugDrawDepthPipeline->GetPipelineLayout()->GetVkPipelineLayout(), "[Pipeline] Debug Draw with Depth Test");
debugDrawLineMeshPipeline = createDebugDrawPipeline(debugDrawNode->GetRenderpass(), debugDrawSubpass, false, false, true);
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipeline, debugDrawLineMeshPipeline->GetVkPipeline(), "[Pipeline] Debug Draw Line Mesh");
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipelineLayout, debugDrawLineMeshPipeline->GetPipelineLayout()->GetVkPipelineLayout(), "[Pipeline Layout] Debug Draw Line Mesh");
debugDrawLineMeshDepthPipeline = createDebugDrawPipeline(debugDrawNodeDepth->GetRenderpass(), debugDrawDepthSubpass, false, false, true);
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipeline, debugDrawLineMeshDepthPipeline->GetVkPipeline(), "[Pipeline Layout] Debug Draw Line Mesh with Depth Test");
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipelineLayout, debugDrawLineMeshDepthPipeline->GetPipelineLayout()->GetVkPipelineLayout(), "[Pipeline] Debug Draw Line Mesh with Depth Test");
debugDrawWireMeshPipeline = createDebugDrawPipeline(debugDrawNode->GetRenderpass(), debugDrawSubpass, false, true, true);
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipeline, debugDrawWireMeshPipeline->GetVkPipeline(), "[Pipeline] Debug Draw Wire Mesh");
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipelineLayout, debugDrawWireMeshPipeline->GetPipelineLayout()->GetVkPipelineLayout(), "[Pipeline Layout] Debug Draw Wire Mesh");
debugDrawWireMeshDepthPipeline = createDebugDrawPipeline(debugDrawNodeDepth->GetRenderpass(), debugDrawDepthSubpass, false, true, true);
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipeline, debugDrawWireMeshDepthPipeline->GetVkPipeline(), "[Pipeline Layout] Debug Draw Wire Mesh with Depth Test");
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipelineLayout, debugDrawWireMeshDepthPipeline->GetPipelineLayout()->GetVkPipelineLayout(), "[Pipeline] Debug Draw Wire Mesh with Depth Test");
debugDrawFilledPipeline = createDebugDrawPipeline(debugDrawNode->GetRenderpass(), debugDrawSubpass, true, true, true);
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipeline, debugDrawFilledPipeline->GetVkPipeline(), "[Pipeline] Debug Draw Filled Mesh");
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipelineLayout, debugDrawFilledPipeline->GetPipelineLayout()->GetVkPipelineLayout(), "[Pipeline Layout] Debug Draw Filled Mesh");
debugDrawFilledDepthPipeline = createDebugDrawPipeline(debugDrawNodeDepth->GetRenderpass(), debugDrawDepthSubpass, true, true, true);
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipeline, debugDrawFilledDepthPipeline->GetVkPipeline(), "[Pipeline Layout] Debug Draw Filled Mesh with Depth Test");
SET_VK_OBJ_NAME(device, vk::ObjectType::ePipelineLayout, debugDrawFilledDepthPipeline->GetPipelineLayout()->GetVkPipelineLayout(), "[Pipeline] Debug Draw Filled Mesh with Depth Test");
} }
void SHGraphicsSystem::InitMiddleEnd(void) noexcept void SHGraphicsSystem::InitMiddleEnd(void) noexcept
@ -1083,34 +1092,68 @@ namespace SHADE
return worldRenderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data()); return worldRenderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data());
} }
SHADE::SHFontLibrary const& SHGraphicsSystem::GetFontLibrary(void) const noexcept Handle<SHVkPipeline> SHGraphicsSystem::GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept
{
switch (type)
{
case DebugDrawPipelineType::LineNoDepthTest: return debugDrawPipeline;
case DebugDrawPipelineType::LineDepthTested: return debugDrawDepthPipeline;
case DebugDrawPipelineType::LineMeshNoDepthTest: return debugDrawLineMeshPipeline;
case DebugDrawPipelineType::LineMeshDepthTested: return debugDrawLineMeshDepthPipeline;
case DebugDrawPipelineType::WireMeshNoDepthTest: return debugDrawWireMeshPipeline;
case DebugDrawPipelineType::WireMeshDepthTested: return debugDrawWireMeshDepthPipeline;
case DebugDrawPipelineType::FilledMeshNoDepthTest: return debugDrawFilledPipeline;
case DebugDrawPipelineType::FilledMeshDepthTested: return debugDrawFilledDepthPipeline;
}
SHLOG_WARNING("[SHGraphicsSystem] Attempted to retrieve an invalid Debug Draw Pipeline. Default Debug Draw Pipeline returned.");
return debugDrawPipeline;
}
SHFontLibrary const& SHGraphicsSystem::GetFontLibrary(void) const noexcept
{ {
return fontLibrary; return fontLibrary;
} }
Handle<SHVkPipeline> SHGraphicsSystem::createDebugDrawPipeline(Handle<SHVkRenderpass> renderPass, Handle<SHSubpass> subpass) Handle<SHVkPipeline> SHGraphicsSystem::createDebugDrawPipeline(Handle<SHVkRenderpass> renderPass, Handle<SHSubpass> subpass, bool filled, bool triMesh, bool instanced)
{ {
auto pipelineLayout = resourceManager.Create<SHVkPipelineLayout> auto pipelineLayout = resourceManager.Create<SHVkPipelineLayout>
( (
device, SHPipelineLayoutParams device, SHPipelineLayoutParams
{ {
.shaderModules = { debugVertShader, debugFragShader }, .shaderModules = { (triMesh ? debugMeshVertShader : debugVertShader) , debugFragShader },
.globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts() .globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts()
} }
); );
auto pipeline = resourceManager.Create<SHVkPipeline>(device, pipelineLayout, nullptr, renderPass, subpass); auto pipeline = resourceManager.Create<SHVkPipeline>(device, pipelineLayout, nullptr, renderPass, subpass);
pipeline->GetPipelineState().SetRasterizationState(SHRasterizationState pipeline->GetPipelineState().SetRasterizationState(SHRasterizationState
{ {
.polygonMode = vk::PolygonMode::eLine, .polygonMode = filled ? vk::PolygonMode::eFill : vk::PolygonMode::eLine,
.cull_mode = vk::CullModeFlagBits::eNone .cull_mode = filled ? vk::CullModeFlagBits::eBack : vk::CullModeFlagBits::eNone
}); });
pipeline->GetPipelineState().SetInputAssemblyState(SHInputAssemblyState pipeline->GetPipelineState().SetInputAssemblyState(SHInputAssemblyState
{ {
.topology = vk::PrimitiveTopology::eLineList .topology = triMesh ? vk::PrimitiveTopology::eTriangleList : vk::PrimitiveTopology::eLineList
}); });
SHVertexInputState debugDrawVertexInputState; SHVertexInputState debugDrawVertexInputState;
debugDrawVertexInputState.AddBinding(false, true, { SHVertexAttribute(SHAttribFormat::FLOAT_4D), SHVertexAttribute(SHAttribFormat::FLOAT_4D) }); if (instanced)
{
debugDrawVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_4D) }); // 0: Vertex World Space Position
debugDrawVertexInputState.AddBinding(true , true , { SHVertexAttribute(SHAttribFormat::MAT_4D) }); // 1: Instance Transform Matrix (4 Slots)
debugDrawVertexInputState.AddBinding(true , true , { SHVertexAttribute(SHAttribFormat::FLOAT_4D) }); // 5: Instance Color
}
else
{
debugDrawVertexInputState.AddBinding
(
false, true,
{
SHVertexAttribute(SHAttribFormat::FLOAT_4D), // Vertex World Space Position
SHVertexAttribute(SHAttribFormat::FLOAT_4D) // Vertex Color
}
);
}
pipeline->GetPipelineState().SetVertexInputState(debugDrawVertexInputState); pipeline->GetPipelineState().SetVertexInputState(debugDrawVertexInputState);
SHColorBlendState colorBlendState{}; SHColorBlendState colorBlendState{};
colorBlendState.logic_op_enable = VK_FALSE; colorBlendState.logic_op_enable = VK_FALSE;

View File

@ -73,6 +73,18 @@ namespace SHADE
Sphere Sphere
}; };
static constexpr int MAX_PRIMITIVE_TYPES = 2; static constexpr int MAX_PRIMITIVE_TYPES = 2;
enum class DebugDrawPipelineType
{
LineNoDepthTest,
LineDepthTested,
LineMeshNoDepthTest,
LineMeshDepthTested,
WireMeshNoDepthTest,
WireMeshDepthTested,
FilledMeshNoDepthTest,
FilledMeshDepthTested
};
static constexpr int MAX_DEBUG_DRAW_PIPELINE_TYPES = 8;
/***********************************************************************************/ /***********************************************************************************/
/*! /*!
@ -371,8 +383,7 @@ namespace SHADE
Handle<SHMousePickSystem> GetMousePickSystem(void) const noexcept {return mousePickSystem;}; Handle<SHMousePickSystem> GetMousePickSystem(void) const noexcept {return mousePickSystem;};
Handle<SHPostOffscreenRenderSystem> GetPostOffscreenRenderSystem(void) const noexcept {return postOffscreenRender;}; Handle<SHPostOffscreenRenderSystem> GetPostOffscreenRenderSystem(void) const noexcept {return postOffscreenRender;};
Handle<SHRenderGraphNode> GetPrimaryRenderpass() const noexcept; Handle<SHRenderGraphNode> GetPrimaryRenderpass() const noexcept;
Handle<SHVkPipeline> GetDebugDrawPipeline(void) const noexcept { return debugDrawPipeline; } Handle<SHVkPipeline> GetDebugDrawPipeline(DebugDrawPipelineType type) const noexcept;
Handle<SHVkPipeline> GetDebugDrawDepthPipeline(void) const noexcept { return debugDrawDepthPipeline; }
uint32_t GetCurrentFrameIndex(void) const noexcept { return renderContext.GetCurrentFrame(); } uint32_t GetCurrentFrameIndex(void) const noexcept { return renderContext.GetCurrentFrame(); }
SHFontLibrary const& GetFontLibrary (void) const noexcept; SHFontLibrary const& GetFontLibrary (void) const noexcept;
@ -439,6 +450,7 @@ namespace SHADE
Handle<SHVkShaderModule> defaultFragShader; Handle<SHVkShaderModule> defaultFragShader;
Handle<SHVkShaderModule> debugVertShader; Handle<SHVkShaderModule> debugVertShader;
Handle<SHVkShaderModule> debugFragShader; Handle<SHVkShaderModule> debugFragShader;
Handle<SHVkShaderModule> debugMeshVertShader;
Handle<SHVkShaderModule> deferredCompositeShader; Handle<SHVkShaderModule> deferredCompositeShader;
Handle<SHVkShaderModule> ssaoShader; Handle<SHVkShaderModule> ssaoShader;
Handle<SHVkShaderModule> ssaoBlurShader; Handle<SHVkShaderModule> ssaoBlurShader;
@ -454,6 +466,12 @@ namespace SHADE
Handle<SHMaterial> defaultMaterial; Handle<SHMaterial> defaultMaterial;
Handle<SHVkPipeline> debugDrawPipeline; Handle<SHVkPipeline> debugDrawPipeline;
Handle<SHVkPipeline> debugDrawDepthPipeline; Handle<SHVkPipeline> debugDrawDepthPipeline;
Handle<SHVkPipeline> debugDrawLineMeshPipeline;
Handle<SHVkPipeline> debugDrawLineMeshDepthPipeline;
Handle<SHVkPipeline> debugDrawWireMeshPipeline;
Handle<SHVkPipeline> debugDrawWireMeshDepthPipeline;
Handle<SHVkPipeline> debugDrawFilledPipeline;
Handle<SHVkPipeline> debugDrawFilledDepthPipeline;
// Built-In Textures // Built-In Textures
Handle<SHTexture> defaultTexture; Handle<SHTexture> defaultTexture;
@ -482,6 +500,6 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Helper Functions */ /* Helper Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
Handle<SHVkPipeline> createDebugDrawPipeline(Handle<SHVkRenderpass> renderPass, Handle<SHSubpass> subpass); Handle<SHVkPipeline> createDebugDrawPipeline(Handle<SHVkRenderpass> renderPass, Handle<SHSubpass> subpass, bool filled, bool triMesh, bool instanced);
}; };
} }

View File

@ -195,7 +195,7 @@ namespace SHADE
const auto& TRI_ARRAY = rp3dRenderer->getTrianglesArray(); const auto& TRI_ARRAY = rp3dRenderer->getTrianglesArray();
for (int i = 0; i < NUM_TRIS; ++i) for (int i = 0; i < NUM_TRIS; ++i)
debugRenderer->DrawTri(SHColour::RED, TRI_ARRAY[i].point1, TRI_ARRAY[i].point2, TRI_ARRAY[i].point3); debugRenderer->DrawTri(TRI_ARRAY[i].point1, TRI_ARRAY[i].point2, TRI_ARRAY[i].point3, SHColour::RED);
} }
#else #else
@ -207,7 +207,7 @@ namespace SHADE
const auto& TRI_ARRAY = rp3dRenderer->getTrianglesArray(); const auto& TRI_ARRAY = rp3dRenderer->getTrianglesArray();
for (int i = 0; i < NUM_TRIS; ++i) for (int i = 0; i < NUM_TRIS; ++i)
debugRenderer->DrawTri(SHColour::RED, TRI_ARRAY[i].point1, TRI_ARRAY[i].point2, TRI_ARRAY[i].point3); debugRenderer->DrawTri(TRI_ARRAY[i].point1, TRI_ARRAY[i].point2, TRI_ARRAY[i].point3, SHColour::RED);
#endif #endif
} }
@ -225,7 +225,7 @@ namespace SHADE
const auto& LINE_ARRAY = rp3dRenderer->getLinesArray(); const auto& LINE_ARRAY = rp3dRenderer->getLinesArray();
for (int i = 0; i < NUM_LINES; ++i) for (int i = 0; i < NUM_LINES; ++i)
debugRenderer->DrawLine(SHColour::RED, LINE_ARRAY[i].point1, LINE_ARRAY[i].point2); debugRenderer->DrawLine(LINE_ARRAY[i].point1, LINE_ARRAY[i].point2, SHColour::RED);
} }
#else #else
@ -237,7 +237,7 @@ namespace SHADE
const auto& LINE_ARRAY = rp3dRenderer->getLinesArray(); const auto& LINE_ARRAY = rp3dRenderer->getLinesArray();
for (int i = 0; i < NUM_LINES; ++i) for (int i = 0; i < NUM_LINES; ++i)
debugRenderer->DrawLine(SHColour::RED, LINE_ARRAY[i].point1, LINE_ARRAY[i].point2); debugRenderer->DrawLine(LINE_ARRAY[i].point1, LINE_ARRAY[i].point2, SHColour::RED);
#endif #endif
} }
@ -261,7 +261,7 @@ namespace SHADE
const float RENDER_DIST = raycastResult.distance == std::numeric_limits<float>::infinity() ? SHRay::MAX_RAYCAST_DIST : raycastResult.distance; const float RENDER_DIST = raycastResult.distance == std::numeric_limits<float>::infinity() ? SHRay::MAX_RAYCAST_DIST : raycastResult.distance;
const SHVec3 END_POS = ray.position + (ray.direction * RENDER_DIST); const SHVec3 END_POS = ray.position + (ray.direction * RENDER_DIST);
debugRenderer->DrawLine(RAY_COLOUR, ray.position, END_POS); debugRenderer->DrawLine(ray.position, END_POS, RAY_COLOUR);
} }
} }
@ -306,16 +306,16 @@ namespace SHADE
transformedVertices[IDX2] = SHVec3::Transform(boxVertices[IDX2], FINAL_TRS); transformedVertices[IDX2] = SHVec3::Transform(boxVertices[IDX2], FINAL_TRS);
// Draw 4 line to connect the quads // Draw 4 line to connect the quads
debugRenderer->DrawLine(COLLIDER_COLOUR, transformedVertices[IDX1], transformedVertices[IDX2]); debugRenderer->DrawLine(transformedVertices[IDX1], transformedVertices[IDX2], COLLIDER_COLOUR);
} }
// A, B, C, D // A, B, C, D
std::array backQuad { transformedVertices[0], transformedVertices[1], transformedVertices[3], transformedVertices[2] }; std::array backQuad { transformedVertices[0], transformedVertices[1], transformedVertices[3], transformedVertices[2] };
debugRenderer->DrawPoly(COLLIDER_COLOUR, backQuad.begin(), backQuad.end()); debugRenderer->DrawLineLoop(backQuad.begin(), backQuad.end(), COLLIDER_COLOUR);
// E, F, G, H // E, F, G, H
std::array frontQuad { transformedVertices[4], transformedVertices[5], transformedVertices[7], transformedVertices[6] }; std::array frontQuad { transformedVertices[4], transformedVertices[5], transformedVertices[7], transformedVertices[6] };
debugRenderer->DrawPoly(COLLIDER_COLOUR, frontQuad.begin(), frontQuad.end()); debugRenderer->DrawLineLoop(frontQuad.begin(), frontQuad.end(), COLLIDER_COLOUR);
} }
void SHPhysicsDebugDrawSystem::debugDrawSphere(SHDebugDrawSystem* debugRenderer, const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept void SHPhysicsDebugDrawSystem::debugDrawSphere(SHDebugDrawSystem* debugRenderer, const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept
@ -327,8 +327,9 @@ namespace SHADE
// Calculate final position & orientation // Calculate final position & orientation
const SHQuaternion FINAL_ROT = colliderComponent.GetOrientation() * SHQuaternion::FromEuler(collisionShape.GetRotationOffset()); const SHQuaternion FINAL_ROT = colliderComponent.GetOrientation() * SHQuaternion::FromEuler(collisionShape.GetRotationOffset());
const SHMatrix TR = SHMatrix::Rotate(FINAL_ROT) * SHMatrix::Translate(colliderComponent.GetPosition()); const SHMatrix TR = SHMatrix::Rotate(FINAL_ROT) * SHMatrix::Translate(colliderComponent.GetPosition());
debugRenderer->DrawSphere(COLLIDER_COLOUR, SHVec3::Transform(collisionShape.GetPositionOffset(), TR), SPHERE->GetWorldRadius()); /* #KWFix */
//debugRenderer->DrawSphere(COLLIDER_COLOUR, SHVec3::Transform(collisionShape.GetPositionOffset(), TR), SPHERE->GetWorldRadius());
} }
} // namespace SHADE } // namespace SHADE

View File

@ -43,67 +43,67 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void SHDebugDraw::Line(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt) void SHDebugDraw::Line(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt)
{ {
dbgDrawSys->DrawLine(color, startPt, endPt); dbgDrawSys->DrawLine(startPt, endPt, color);
} }
void SHDebugDraw::Tri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3) void SHDebugDraw::Tri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3)
{ {
dbgDrawSys->DrawTri(color, pt1, pt2, pt3); //dbgDrawSys->DrawTri(color, pt1, pt2, pt3);
} }
void SHDebugDraw::Quad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4) void SHDebugDraw::Quad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4)
{ {
dbgDrawSys->DrawQuad(color, pt1, pt2, pt3, pt4); //dbgDrawSys->DrawQuad(color, pt1, pt2, pt3, pt4);
} }
void SHDebugDraw::Poly(const SHVec4& color, std::initializer_list<SHVec3> pointList) void SHDebugDraw::Poly(const SHVec4& color, std::initializer_list<SHVec3> pointList)
{ {
dbgDrawSys->DrawPoly(color, pointList); //dbgDrawSys->DrawPoly(color, pointList);
} }
void SHDebugDraw::Cube(const SHVec4& color, const SHVec3& pos, const SHVec3& size) void SHDebugDraw::Cube(const SHVec4& color, const SHVec3& pos, const SHVec3& size)
{ {
dbgDrawSys->DrawCube(color, pos, size); //dbgDrawSys->DrawCube(color, pos, size);
} }
void SHDebugDraw::Sphere(const SHVec4& color, const SHVec3& pos, double radius) void SHDebugDraw::Sphere(const SHVec4& color, const SHVec3& pos, double radius)
{ {
dbgDrawSys->DrawSphere(color, pos, radius); //dbgDrawSys->DrawSphere(color, pos, radius);
} }
void SHDebugDraw::PersistentLine(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt) void SHDebugDraw::PersistentLine(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt)
{ {
dbgDrawSys->DrawPersistentLine(color, startPt, endPt); dbgDrawSys->DrawPersistentLine(startPt, endPt, color);
} }
void SHDebugDraw::PersistentTri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3) void SHDebugDraw::PersistentTri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3)
{ {
dbgDrawSys->DrawPersistentTri(color, pt1, pt2, pt3); //dbgDrawSys->DrawPersistentTri(color, pt1, pt2, pt3);
} }
void SHDebugDraw::PersistentQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4) void SHDebugDraw::PersistentQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4)
{ {
dbgDrawSys->DrawPersistentQuad(color, pt1, pt2, pt3, pt4); //dbgDrawSys->DrawPersistentQuad(color, pt1, pt2, pt3, pt4);
} }
void SHDebugDraw::PersistentPoly(const SHVec4& color, std::initializer_list<SHVec3> pointList) void SHDebugDraw::PersistentPoly(const SHVec4& color, std::initializer_list<SHVec3> pointList)
{ {
dbgDrawSys->DrawPersistentPoly(color, pointList); //dbgDrawSys->DrawPersistentPoly(color, pointList);
} }
void SHDebugDraw::PersistentCube(const SHVec4& color, const SHVec3& pos, const SHVec3& size) void SHDebugDraw::PersistentCube(const SHVec4& color, const SHVec3& pos, const SHVec3& size)
{ {
dbgDrawSys->DrawPersistentCube(color, pos, size); //dbgDrawSys->DrawPersistentCube(color, pos, size);
} }
void SHDebugDraw::PersistentSphere(const SHVec4& color, const SHVec3& pos, double radius) void SHDebugDraw::PersistentSphere(const SHVec4& color, const SHVec3& pos, double radius)
{ {
dbgDrawSys->DrawPersistentSphere(color, pos, radius); //dbgDrawSys->DrawPersistentSphere(color, pos, radius);
} }
void SHDebugDraw::ClearPersistentDraws() void SHDebugDraw::ClearPersistentDraws()
{ {
dbgDrawSys->ClearPersistentDraws(); //dbgDrawSys->ClearPersistentDraws();
} }
} }