Files
HelloVulkan/Engine/include/Engine/Renderer/Passes/PhysicsDebugPass.h
T
atdunbg 36b1fc0566 新增调试绘制体系:DebugDraw 服务 + 物理调试 pass + 脚本侧力学线
通用图元(线/箭头四翼头/球/胶囊/盒)瞬时+持久双缓冲聚合;
物理 pass 画刚体速度/重力/接触反力;角色 collider 与力学
线归位(引擎只画资产、脚本画行为);线宽按设备上限钳制
2026-10-08 17:02:27 +08:00

96 lines
3.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// PhysicsDebugPass:调试图元叠加 pass(双源)。
// 物理源 = PhysicsWorld 收集的 PhysicsDebugFrame(collider 线框/
// 约束,Application 注入帧缓冲指针)
// 通用源 = Engine::Debug 调试服务(脚本/任意层的 Line/Arrow/Wire*,
// Unity Debug.DrawLine 同位;批次自带线宽/深度测试/拓扑)
//
// 画在 HDRColor(Forward 之后、TAA 之前):调试图元进入场景主链路——
// TAA 时域累积抗锯齿、Bloom/Tonemap 正常消费,kDebugTransparent 诊断
// 模式下也可见。深度只测不写(被不透明几何正确遮挡),无混合直写
// (fullscreen pass 状态泄漏教训)。
//
// 空帧零绘制:两源顶点数均 0 时提前短路。
//
#ifndef HELLOVULKAN_PHYSICSDEBUGPASS_H
#define HELLOVULKAN_PHYSICSDEBUGPASS_H
#include <Engine/Core/Types.h>
#include <Engine/Debug/DebugDraw.h>
#include <Engine/Renderer/Passes/RenderPass.h>
#include <Engine/Renderer/SceneTypes.h>
#include <Engine/Vulkan/UniformBuffer.h>
#include <Engine/Vulkan/ShaderManager.h>
#include <vector>
#include <vulkan/vulkan.hpp>
namespace Engine {
struct PhysicsDebugFrame; // PhysicsDebugTypes.h(Jolt 零依赖契约)
class Device;
class ShaderManager;
class DescriptorManager;
namespace Passes {
class PhysicsDebugPass final : public RenderPass {
public:
// 顶点预算(每帧槽位,按顶点数):物理调试几十个 body 的
// 线框 + 箭头远用不满;溢出截断并告警一次
static constexpr u32 kMaxLineVerts = 1 << 16;
static constexpr u32 kMaxTriVerts = 1 << 16;
PhysicsDebugPass(Device& device, MemoryAllocator& allocator,
ShaderManager& shaders,
DescriptorManager& descriptors,
FrameSceneData& frame,
RG::TextureHandle hdrColor,
RG::TextureHandle depth,
UniformBuffer& lineVB, UniformBuffer& triVB,
UniformBuffer& debugVB);
~PhysicsDebugPass();
PhysicsDebugPass(const PhysicsDebugPass&) = delete;
PhysicsDebugPass& operator=(const PhysicsDebugPass&) = delete;
void Register(RG::RenderGraph& rg) override;
// 每帧 Renderer::Render 里(该槽位 fence 等待后)上传当帧
// 图元。dbg 为 nullptr = 通用调试源禁用/空
void PrepareFrame(u32 frameSlot, const PhysicsDebugFrame& src,
const Debug::DebugFrame* dbg);
private:
// 一个可绘制段:独立拓扑/线宽/深度测试(动态状态逐批设置)
struct Span {
bool tris;
f32 width;
bool depthTest;
u32 first; // 顶点偏移(对应 VB 内顶点序号)
u32 count;
};
Device& m_Device;
DescriptorManager& m_Descriptors;
FrameSceneData& m_Frame;
RG::TextureHandle m_HDRColor;
RG::TextureHandle m_Depth;
UniformBuffer& m_LineVB; // per-slot ring(物理源,Renderer 持有)
UniformBuffer& m_TriVB;
UniformBuffer& m_DebugVB; // 通用调试源 ring(Renderer 持有)
vk::PipelineLayout m_Layout; // 无描述符,push = viewProj 64B
ShaderManager::ShaderRef m_Vert, m_Frag; // 析构自动销毁
std::array<u32, kMaxFramesInFlight> m_LineCounts{};
std::array<u32, kMaxFramesInFlight> m_TriCounts{};
std::array<std::vector<Span>, kMaxFramesInFlight> m_Spans;
bool m_TruncationWarned = false;
};
} // namespace Passes
} // namespace Engine
#endif //HELLOVULKAN_PHYSICSDEBUGPASS_H