Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Disable Depth Stencil Test for Colliders #568

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rootex/framework/components/physics/rigid_body_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "common/types.h"

#include "framework/systems/physics_system.h"
#include "framework/systems/render_system.h"
#include "script/script.h"

#include "entity.h"
Expand Down Expand Up @@ -230,10 +231,12 @@ void RigidBodyComponent::setKinematic(bool enabled)

void RigidBodyComponent::highlight()
{
RenderSystem::GetSingleton()->enableSubmitLinesOnTop();
PhysicsSystem::GetSingleton()->debugDrawComponent(
m_Body->getWorldTransform(),
m_CollisionShape.get(),
VecTobtVector3({ 0.8f, 0.1f, 0.1f }));
RenderSystem::GetSingleton()->disableSubmitLinesOnTop();
}

JSON::json RigidBodyComponent::getJSON() const
Expand Down
57 changes: 49 additions & 8 deletions rootex/framework/systems/render_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ RenderSystem::RenderSystem()
m_LineMaterial = ResourceLoader::CreateBasicMaterialResourceFile("rootex/assets/materials/line.basic.rmat");
m_CurrentFrameLines.m_Endpoints.reserve(LINE_MAX_VERTEX_COUNT * LINE_VERTEX_COUNT * 3);
m_CurrentFrameLines.m_Indices.reserve(LINE_MAX_VERTEX_COUNT * LINE_VERTEX_COUNT);
m_CurrentFrameLinesOnTop.m_Endpoints.reserve(LINE_MAX_VERTEX_COUNT * LINE_VERTEX_COUNT * 3);
m_CurrentFrameLinesOnTop.m_Indices.reserve(LINE_MAX_VERTEX_COUNT * LINE_VERTEX_COUNT);

m_SubmitLinesOnTop = false;

m_PerFrameVSCB = RenderingDevice::GetSingleton()->createBuffer(PerFrameVSCB(), D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
m_PerCameraChangeVSCB = RenderingDevice::GetSingleton()->createBuffer(Matrix(), D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
Expand Down Expand Up @@ -291,6 +295,9 @@ void RenderSystem::update(float deltaMilliseconds)
ZoneNamedN(alphaRenderPass, "Alpha Render Pass", true);
renderPassRender(deltaMilliseconds, RenderPass::Alpha);
}
{
renderLinesOnTop();
}
}

void RenderSystem::renderLines()
Expand All @@ -313,18 +320,52 @@ void RenderSystem::renderLines()
}
}

void RenderSystem::renderLinesOnTop()
{
if (m_CurrentFrameLinesOnTop.m_Endpoints.size())
{
m_Renderer->bind(m_LineMaterial.get());

enableLineRenderMode();
RenderingDevice::GetSingleton()->disableDSS();

VertexBuffer vb((const char*)m_CurrentFrameLinesOnTop.m_Endpoints.data(), m_CurrentFrameLinesOnTop.m_Endpoints.size() / 3, sizeof(float) * 3, D3D11_USAGE_IMMUTABLE, 0);
IndexBuffer ib(m_CurrentFrameLinesOnTop.m_Indices);

m_Renderer->draw(&vb, &ib);

m_CurrentFrameLinesOnTop.m_Endpoints.clear();
m_CurrentFrameLinesOnTop.m_Indices.clear();

RenderingDevice::GetSingleton()->enableDSS();
resetRenderMode();
}
}

void RenderSystem::enableSubmitLinesOnTop()
{
m_SubmitLinesOnTop = true;
}

void RenderSystem::disableSubmitLinesOnTop()
{
m_SubmitLinesOnTop = false;
}

void RenderSystem::submitLine(const Vector3& from, const Vector3& to)
{
m_CurrentFrameLines.m_Endpoints.push_back(from.x);
m_CurrentFrameLines.m_Endpoints.push_back(from.y);
m_CurrentFrameLines.m_Endpoints.push_back(from.z);
LineRequests& currentFrameLines = m_SubmitLinesOnTop ? m_CurrentFrameLinesOnTop : m_CurrentFrameLines;

currentFrameLines.m_Endpoints.push_back(from.x);
currentFrameLines.m_Endpoints.push_back(from.y);
currentFrameLines.m_Endpoints.push_back(from.z);

m_CurrentFrameLines.m_Endpoints.push_back(to.x);
m_CurrentFrameLines.m_Endpoints.push_back(to.y);
m_CurrentFrameLines.m_Endpoints.push_back(to.z);
currentFrameLines.m_Endpoints.push_back(to.x);
currentFrameLines.m_Endpoints.push_back(to.y);
currentFrameLines.m_Endpoints.push_back(to.z);

m_CurrentFrameLines.m_Indices.push_back(m_CurrentFrameLines.m_Indices.size());
m_CurrentFrameLines.m_Indices.push_back(m_CurrentFrameLines.m_Indices.size());
currentFrameLines.m_Indices.push_back(currentFrameLines.m_Indices.size());
currentFrameLines.m_Indices.push_back(currentFrameLines.m_Indices.size());
}

void RenderSystem::submitBox(const Vector3& min, const Vector3& max)
Expand Down
7 changes: 7 additions & 0 deletions rootex/framework/systems/render_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class RenderSystem : public System

Ref<BasicMaterialResourceFile> m_LineMaterial;
LineRequests m_CurrentFrameLines;
LineRequests m_CurrentFrameLinesOnTop; // these lines will be rendered on top of everything else

bool m_SubmitLinesOnTop;

Microsoft::WRL::ComPtr<ID3D11Buffer> m_PerFrameVSCB;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_PerCameraChangeVSCB;
Expand All @@ -56,6 +59,10 @@ class RenderSystem : public System
void setConfig(const SceneSettings& sceneSettings) override;
void update(float deltaMilliseconds) override;
void renderLines();
void renderLinesOnTop();

void enableSubmitLinesOnTop();
void disableSubmitLinesOnTop();

void submitLine(const Vector3& from, const Vector3& to);

Expand Down