From 6d05e6016c439c57c9bb9619b7ff14804bee706b Mon Sep 17 00:00:00 2001 From: SoapyMan Date: Thu, 19 Nov 2026 02:24:36 +0300 Subject: [PATCH 1/9] - nvrhi: VK - pass depth attachment read-only flag to the framebuffer - nvrhi: VK - reset queue families on each FindQueueFamilies call - nvrhi: VK - enable synchronization validation with -rhivalidation - nvrhi: update submodule (vulkan-fix-barriers) Co-Authored-By: GLM --- .../Renderers/NVRHI/NVRHILibraryVK.cpp | 23 +++++++++++++++++++ .../Renderers/NVRHI/NVRHILibraryVK.h | 5 ++++ .../NVRHI/NVRHIRenderPassRecorder.cpp | 2 +- src_dependency/nvrhi/NVRHI | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.cpp b/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.cpp index 62e6defa7..006190cfe 100644 --- a/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.cpp +++ b/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.cpp @@ -231,6 +231,17 @@ bool CNVRHIRenderLibVK::InitAPI(const ShaderAPIParams& params) } #endif +#ifdef NVRHI_WITH_VALIDATION + // synchronization validation reports buffer/image hazards that the default + // validation layer does not catch (write-after-read across submissions etc) + if (vulkan_validation.GetBool() && arrayFindIndex(m_optionalExtensions.instance, VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME) != -1) + { + m_enabledExtensions.instance.append(VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME); + m_validationFeatures.setEnabledValidationFeatures({ 1u, &m_syncValidationEnable }); + m_useSyncValidation = true; + } +#endif + Array vkInstExtNames(PP_SL); Array vkLayerNames(PP_SL); @@ -311,6 +322,11 @@ bool CNVRHIRenderLibVK::InitAPI(const ShaderAPIParams& params) .setPpEnabledExtensionNames(vkInstExtNames.ptr()) .setPApplicationInfo(&applicationInfo); +#ifdef NVRHI_WITH_VALIDATION + if (m_useSyncValidation) + info.setPNext(&m_validationFeatures); +#endif + const vk::Result res = vk::createInstance(&info, nullptr, &m_vkInstance); if (res != vk::Result::eSuccess) { @@ -584,6 +600,13 @@ bool CNVRHIRenderLibVK::FindQueueFamilies(vk::PhysicalDevice vkPhysicalDevice, v const bool enableComputeQueue = false; const bool enableCopyQueue = false; + // this may be called multiple times (device probing and the final call for the + // picked device), so the families must be rediscovered from scratch + m_vkGraphicsQueueFamily = -1; + m_vkComputeQueueFamily = -1; + m_vkTransferQueueFamily = -1; + m_vkPresentQueueFamily = -1; + auto queueFamiliyProps = vkPhysicalDevice.getQueueFamilyProperties(); for (int i = 0; i < int(queueFamiliyProps.size()); i++) diff --git a/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.h b/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.h index 5ef644c16..ec38b00aa 100644 --- a/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.h +++ b/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.h @@ -79,6 +79,11 @@ class CNVRHIRenderLibVK vk::Instance m_vkInstance; vk::DebugReportCallbackEXT m_vkDebugReportCallback; +#ifdef NVRHI_WITH_VALIDATION + vk::ValidationFeaturesEXT m_validationFeatures; + vk::ValidationFeatureEnableEXT m_syncValidationEnable{ vk::ValidationFeatureEnableEXT::eSynchronizationValidation }; + bool m_useSyncValidation{ false }; +#endif vk::PhysicalDevice m_vkPhysicalDevice; vk::Device m_vkDevice; vk::Queue m_vkGraphicsQueue; diff --git a/core/materialsystem1/Renderers/NVRHI/NVRHIRenderPassRecorder.cpp b/core/materialsystem1/Renderers/NVRHI/NVRHIRenderPassRecorder.cpp index d517e0c25..f15bb013d 100644 --- a/core/materialsystem1/Renderers/NVRHI/NVRHIRenderPassRecorder.cpp +++ b/core/materialsystem1/Renderers/NVRHI/NVRHIRenderPassRecorder.cpp @@ -342,7 +342,7 @@ static void NVRHIBeginRenderPass(const RenderPassDesc& renderPassDesc, nvrhi::Co .setTexture(depthTexture->GetNVRHITextureHandle()) .setReadOnly(renderPassDesc.depthReadOnly); - rhiFramebufferDesc.setDepthAttachment(depthTexture->GetNVRHITextureHandle()); + rhiFramebufferDesc.setDepthAttachment(rhiDepthAttachment); const bool clearDepth = !renderPassDesc.depthReadOnly && renderPassDesc.depthLoadOp == LOADFUNC_CLEAR; const bool clearStencil = !renderPassDesc.stencilReadOnly && IsStencilFormat(renderPassDesc.depthStencil.texture->GetFormat()) && renderPassDesc.stencilLoadOp == LOADFUNC_CLEAR; diff --git a/src_dependency/nvrhi/NVRHI b/src_dependency/nvrhi/NVRHI index d54097996..be94bb96d 160000 --- a/src_dependency/nvrhi/NVRHI +++ b/src_dependency/nvrhi/NVRHI @@ -1 +1 @@ -Subproject commit d5409799680bbe6eb717203966b0bb9f674be444 +Subproject commit be94bb96dfea3f62b79f485538aecd86913e79ce From 12b25fc9e2f317ccb7f9cad82d7f1af39ae5d1d2 Mon Sep 17 00:00:00 2001 From: SoapyMan Date: Thu, 19 Nov 2026 02:56:18 +0300 Subject: [PATCH 2/9] - render: wait for the frame-present semaphore in vkQueuePresentKHR so the late passes (console, HUD) cannot race the presentation, fixing flickering UI and out-of-order frames - render: signal the frame-present semaphore from an empty submission at the end of the frame, rotated per frame in flight --- .../Renderers/NVRHI/NVRHILibraryVK.cpp | 32 +++++++++++++++++++ .../Renderers/NVRHI/NVRHILibraryVK.h | 8 +++++ .../Renderers/NVRHI/NVRHISwapChainVK.cpp | 19 +++++++---- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.cpp b/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.cpp index 006190cfe..b3b5a4274 100644 --- a/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.cpp +++ b/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.cpp @@ -469,6 +469,12 @@ bool CNVRHIRenderLibVK::InitAPI(const ShaderAPIParams& params) m_nvrhiFrameWaitQuery = m_nvrhiDevice->createEventQuery(); m_nvrhiDevice->setEventQuery(m_nvrhiFrameWaitQuery, nvrhi::CommandQueue::Graphics); + // the presentation waits these semaphores, which are signaled by an empty + // submission at the end of every frame (see EndFrame); one per frame in flight + for (VkSemaphore& semaphore : m_framePresentSemaphores) + semaphore = m_vkDevice.createSemaphore(vk::SemaphoreCreateInfo()); + m_nvrhiFramePresentCmdList = m_nvrhiDevice->createCommandList(); + return true; } @@ -896,6 +902,17 @@ void CNVRHIRenderLibVK::ExitAPI() CNVRHIRenderAPI::Instance.m_rhiDevice = nullptr; m_nvrhiDevice = nullptr; m_nvrhiFrameWaitQuery = nullptr; + m_nvrhiFramePresentCmdList = nullptr; + m_framePresentSemaphore = nullptr; + + for (VkSemaphore& semaphore : m_framePresentSemaphores) + { + if (semaphore) + { + m_vkDevice.destroySemaphore(semaphore); + semaphore = nullptr; + } + } if (m_vkDebugReportCallback) m_vkInstance.destroyDebugReportCallbackEXT(m_vkDebugReportCallback); @@ -946,6 +963,21 @@ void CNVRHIRenderLibVK::EndFrame() stats.textureUpdateCount = 0; g_renderWorker.Execute(__func__, [this]() { + // signal the frame-present semaphore from an empty submission: queue submissions + // execute in order, so it completes only after every pass of this frame, and the + // present (which waits it) cannot show a partially rendered image + if (m_nvrhiFramePresentCmdList) + { + VkSemaphore vkFramePresentSemaphore = m_framePresentSemaphores[m_framePresentSemaphoreIdx]; + m_framePresentSemaphoreIdx = (m_framePresentSemaphoreIdx + 1) % uint32_t(std::size(m_framePresentSemaphores)); + m_framePresentSemaphore = vkFramePresentSemaphore; + m_nvrhiDevice->queueSignalSemaphore(nvrhi::CommandQueue::Graphics, vkFramePresentSemaphore, 0); + + m_nvrhiFramePresentCmdList->open(); + m_nvrhiFramePresentCmdList->close(); + m_nvrhiDevice->executeCommandList(m_nvrhiFramePresentCmdList); + } + m_currentSwapChain->SwapBuffers(); const int bufferCount = 3;// m_currentSwapChain->m_rhiSwapChainTextures.numElem(); diff --git a/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.h b/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.h index ec38b00aa..725cfd6a9 100644 --- a/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.h +++ b/core/materialsystem1/Renderers/NVRHI/NVRHILibraryVK.h @@ -76,6 +76,14 @@ class CNVRHIRenderLibVK PFN_vkGetInstanceProcAddr m_vkGetInstanceProcAddr = nullptr; nvrhi::vulkan::DeviceHandle m_nvrhiDevice; nvrhi::EventQueryHandle m_nvrhiFrameWaitQuery; + // signaled by an empty submission at the end of the frame, the presentation + // waits it so the late passes (console, HUD) don't race the present; + // rotated per frame in flight (same scheme as the swapchain semaphores) + VkSemaphore m_framePresentSemaphores[3]; + uint32_t m_framePresentSemaphoreIdx = 0; + // the semaphore signaled for the current frame (set in EndFrame before the present) + VkSemaphore m_framePresentSemaphore = nullptr; + nvrhi::CommandListHandle m_nvrhiFramePresentCmdList; vk::Instance m_vkInstance; vk::DebugReportCallbackEXT m_vkDebugReportCallback; diff --git a/core/materialsystem1/Renderers/NVRHI/NVRHISwapChainVK.cpp b/core/materialsystem1/Renderers/NVRHI/NVRHISwapChainVK.cpp index 6c09b2119..f935d05ff 100644 --- a/core/materialsystem1/Renderers/NVRHI/NVRHISwapChainVK.cpp +++ b/core/materialsystem1/Renderers/NVRHI/NVRHISwapChainVK.cpp @@ -266,18 +266,23 @@ bool CNVRHISwapChainVK::SetBackbufferSize(int wide, int tall) bool CNVRHISwapChainVK::SwapBuffers() { - nvrhi::vulkan::DeviceHandle nvrhiDevice = CNVRHIRenderLibVK::Instance->m_nvrhiDevice; + CNVRHIRenderLibVK* renderLib = CNVRHIRenderLibVK::Instance; + + // the per-image semaphore is signaled by the FIRST Graphics submission of the frame + // (BeginFrame registers the signal), while the actual rendering is submitted later; + // additionally wait for the frame-present semaphore, which the render library signals + // with an empty submission at the end of the frame, or the last drawn passes + // (console, HUD) race the presentation + vk::Semaphore vkWaitSemaphores[2] = { m_vkCurrentPresentSemaphore, renderLib->m_framePresentSemaphore }; - void* pNext = nullptr; vk::PresentInfoKHR info = vk::PresentInfoKHR() - .setWaitSemaphoreCount(1) - .setPWaitSemaphores(&m_vkCurrentPresentSemaphore) + .setWaitSemaphoreCount(2) + .setPWaitSemaphores(vkWaitSemaphores) .setSwapchainCount(1) .setPSwapchains(&m_vkSwapChain) - .setPImageIndices(&m_swapChainBufferIndex) - .setPNext(pNext); + .setPImageIndices(&m_swapChainBufferIndex); - const vk::Result res = CNVRHIRenderLibVK::Instance->m_vkPresentQueue.presentKHR(&info); + const vk::Result res = renderLib->m_vkPresentQueue.presentKHR(&info); ASSERT_MSG(res == vk::Result::eSuccess || res == vk::Result::eErrorOutOfDateKHR || res == vk::Result::eSuboptimalKHR, "Present failure"); // no semaphore rotation here: m_vkCurrentPresentSemaphore is selected From 2b78c536ba3ebfa459eac92f0bb2169248d3f604 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Thu, 19 Nov 2026 12:25:29 +0300 Subject: [PATCH 3/9] - nvrhi: fix CopyTextureToTexture destination slice and extent handling - wgpu: fix CopyTextureToTexture whole-texture extent and range asserts --- .../Renderers/NVRHI/NVRHICommandRecorder.cpp | 26 +++++++++++-------- .../Renderers/WGPU/WGPUCommandRecorder.cpp | 14 ++++++---- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/core/materialsystem1/Renderers/NVRHI/NVRHICommandRecorder.cpp b/core/materialsystem1/Renderers/NVRHI/NVRHICommandRecorder.cpp index 3804f85f9..3437058e9 100644 --- a/core/materialsystem1/Renderers/NVRHI/NVRHICommandRecorder.cpp +++ b/core/materialsystem1/Renderers/NVRHI/NVRHICommandRecorder.cpp @@ -108,7 +108,7 @@ void CNVRHICommandRecorder::ClearBuffer(IGPUBuffer* buffer, int64 offset, int64 void CNVRHICommandRecorder::CopyTextureToTexture(const TextureCopyInfo& source, const TextureCopyInfo& destination, const TextureExtent& copySize) const { ASSERT(source.origin.x >= 0 && source.origin.y >= 0 && source.origin.arraySlice >= 0); - ASSERT(copySize.width >= 0 && copySize.height >= 0 && copySize.arraySize >= 0); + ASSERT(copySize.arraySize >= 0); CNVRHITexture* srcTexture = static_cast(source.texture); CNVRHITexture* dstTexture = static_cast(destination.texture); @@ -122,25 +122,29 @@ void CNVRHICommandRecorder::CopyTextureToTexture(const TextureCopyInfo& source, ASSERT_MSG(srcTexture->GetFlags() & TEXFLAG_COPY_SRC, "%s don't have TEXFLAG_COPY_SRC flag", srcTexture->GetName()); ASSERT_MSG(dstTexture->GetFlags() & TEXFLAG_COPY_DST, "%s don't have TEXFLAG_COPY_DST flag", dstTexture->GetName()); - ASSERT_MSG(source.origin.x + copySize.width <= srcTexture->GetWidth() && source.origin.y + copySize.height >= srcTexture->GetHeight() && source.origin.arraySlice + copySize.arraySize <= srcTexture->GetArrayLayersSize(), + // a negative extent size copies the whole texture, like the TextureExtent defaults + const int copyWidth = copySize.width < 0 ? srcTexture->GetWidth() : copySize.width; + const int copyHeight = copySize.height < 0 ? srcTexture->GetHeight() : copySize.height; + + ASSERT_MSG(source.origin.x + copyWidth <= srcTexture->GetWidth() && source.origin.y + copyHeight <= srcTexture->GetHeight() && source.origin.arraySlice + copySize.arraySize <= srcTexture->GetArrayLayersSize(), "source texture origin and size outside of source texture size range"); - ASSERT_MSG(destination.origin.x + copySize.width <= dstTexture->GetWidth() && destination.origin.y + copySize.height >= dstTexture->GetHeight() && destination.origin.arraySlice + copySize.arraySize <= dstTexture->GetArrayLayersSize(), + ASSERT_MSG(destination.origin.x + copyWidth <= dstTexture->GetWidth() && destination.origin.y + copyHeight <= dstTexture->GetHeight() && destination.origin.arraySlice + copySize.arraySize <= dstTexture->GetArrayLayersSize(), "dest texture origin and size outside of dest texture size range"); nvrhi::TextureSlice rhiImageSrc{}; - rhiImageSrc.width = copySize.width; - rhiImageSrc.height = copySize.height; + rhiImageSrc.width = copyWidth; + rhiImageSrc.height = copyHeight; rhiImageSrc.mipLevel = source.origin.mipLevel; rhiImageSrc.x = source.origin.x; rhiImageSrc.y = source.origin.y; nvrhi::TextureSlice rhiImageDst{}; - rhiImageSrc.width = copySize.width; - rhiImageSrc.height = copySize.height; - rhiImageSrc.mipLevel = destination.origin.mipLevel; - rhiImageSrc.x = destination.origin.x; - rhiImageSrc.y = destination.origin.y; - + rhiImageDst.width = copyWidth; + rhiImageDst.height = copyHeight; + rhiImageDst.mipLevel = destination.origin.mipLevel; + rhiImageDst.x = destination.origin.x; + rhiImageDst.y = destination.origin.y; + for(int i = 0; i < copySize.arraySize; ++i) { rhiImageSrc.arraySlice = source.origin.arraySlice + i; diff --git a/core/materialsystem1/Renderers/WGPU/WGPUCommandRecorder.cpp b/core/materialsystem1/Renderers/WGPU/WGPUCommandRecorder.cpp index 8c1747592..f8d99068a 100644 --- a/core/materialsystem1/Renderers/WGPU/WGPUCommandRecorder.cpp +++ b/core/materialsystem1/Renderers/WGPU/WGPUCommandRecorder.cpp @@ -80,7 +80,7 @@ void CWGPUCommandRecorder::ClearBuffer(IGPUBuffer* buffer, int64 offset, int64 s void CWGPUCommandRecorder::CopyTextureToTexture(const TextureCopyInfo& source, const TextureCopyInfo& destination, const TextureExtent& copySize) const { ASSERT(source.origin.x >= 0 && source.origin.y >= 0 && source.origin.arraySlice >= 0); - ASSERT(copySize.width >= 0 && copySize.height >= 0 && copySize.arraySize >= 0); + ASSERT(copySize.arraySize >= 0); CWGPUTexture* srcTexture = static_cast(source.texture); CWGPUTexture* dstTexture = static_cast(destination.texture); @@ -94,9 +94,13 @@ void CWGPUCommandRecorder::CopyTextureToTexture(const TextureCopyInfo& source, c ASSERT_MSG(srcTexture->GetFlags() & TEXFLAG_COPY_SRC, "%s don't have TEXFLAG_COPY_SRC flag", srcTexture->GetName()); ASSERT_MSG(dstTexture->GetFlags() & TEXFLAG_COPY_DST, "%s don't have TEXFLAG_COPY_DST flag", dstTexture->GetName()); - ASSERT_MSG(source.origin.x + copySize.width <= srcTexture->GetWidth() && source.origin.y + copySize.height >= srcTexture->GetHeight() && source.origin.arraySlice + copySize.arraySize <= srcTexture->GetArrayLayersSize(), + // a negative extent size copies the whole texture, like the TextureExtent defaults + const int copyWidth = copySize.width < 0 ? srcTexture->GetWidth() : copySize.width; + const int copyHeight = copySize.height < 0 ? srcTexture->GetHeight() : copySize.height; + + ASSERT_MSG(source.origin.x + copyWidth <= srcTexture->GetWidth() && source.origin.y + copyHeight <= srcTexture->GetHeight() && source.origin.arraySlice + copySize.arraySize <= srcTexture->GetArrayLayersSize(), "source texture origin and size outside of source texture size range"); - ASSERT_MSG(destination.origin.x + copySize.width <= dstTexture->GetWidth() && destination.origin.y + copySize.height >= dstTexture->GetHeight() && destination.origin.arraySlice + copySize.arraySize <= dstTexture->GetArrayLayersSize(), + ASSERT_MSG(destination.origin.x + copyWidth <= dstTexture->GetWidth() && destination.origin.y + copyHeight <= dstTexture->GetHeight() && destination.origin.arraySlice + copySize.arraySize <= dstTexture->GetArrayLayersSize(), "dest texture origin and size outside of dest texture size range"); WGPUTexelCopyTextureInfo rhiImageSrc{}; @@ -113,8 +117,8 @@ void CWGPUCommandRecorder::CopyTextureToTexture(const TextureCopyInfo& source, c WGPUExtent3D rhiCopySize; rhiCopySize.depthOrArrayLayers = copySize.arraySize; - rhiCopySize.width = copySize.width; - rhiCopySize.height = copySize.height; + rhiCopySize.width = copyWidth; + rhiCopySize.height = copyHeight; wgpuCommandEncoderCopyTextureToTexture(m_rhiCommandEncoder, &rhiImageSrc, &rhiImageDst, &rhiCopySize); From 508927c8c8bc9c5abc260762194fed263bc8efa9 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Thu, 19 Nov 2026 12:47:25 +0300 Subject: [PATCH 4/9] - render: add Width to DDLine and draw lines wider than 1px as screen quads - sys: esl - expose DDLine Width - docs: describe DbgLine Width --- docs/public_rendering_overview.md | 5 +- public/render/IDebugOverlay.h | 2 + shared/render/DebugOverlay.cpp | 135 +++++++++++++++++++++++- shared/sys/scripting/sys_esl_engine.cpp | 1 + 4 files changed, 140 insertions(+), 3 deletions(-) diff --git a/docs/public_rendering_overview.md b/docs/public_rendering_overview.md index 60bf94d0b..60c527e00 100644 --- a/docs/public_rendering_overview.md +++ b/docs/public_rendering_overview.md @@ -201,7 +201,7 @@ if (snd_scriptsound_debug.GetBool()) | Builder | Shape | Setters | |---|---|---| | `DbgText3D()` | Text at a 3D position | `Text(fmt, ...)`, `Position`, `Distance` (max visible distance), `Color` | -| `DbgLine()` | Line | `Start`, `End`, `Color`, `ColorStart`, `ColorEnd` | +| `DbgLine()` | Line | `Start`, `End`, `Color`, `ColorStart`, `ColorEnd`, `Width` (pixels, up to 1 is a regular line) | | `DbgBox()` | Axis-aligned box | `Box(bbox)`, `Mins`, `Maxs`, `CenterSize`, `Color`, `Fill` | | `DbgOriBox()` | Oriented box | box setters + `Position`, `Rotation(quaternion)` | | `DbgSphere()` | Sphere | `Position`, `Radius`, `Color`, `Fill` | @@ -209,6 +209,9 @@ if (snd_scriptsound_debug.GetBool()) | `DbgPoly()` | Polygon (up to 20 points) | `Point`, `Points`, `ClipPlane(plane, origin, size)`, `Color`, `Fill`, `Outline` | | `DbgVolume()` | Convex volume from planes | `Planes`, `Volume(volume)`, `Color` | +`Width(px)` sets the line thickness in pixels: a line wider than one pixel is drawn as a quad +expanded in screen space and keeps its pixel width at any distance, otherwise it is a regular line. + Common setters (call them last, they return the base builder): - `Time(seconds)` — keep the primitive visible for the given time; `0` (default) — one frame. diff --git a/public/render/IDebugOverlay.h b/public/render/IDebugOverlay.h index e71e695d4..1af289396 100644 --- a/public/render/IDebugOverlay.h +++ b/public/render/IDebugOverlay.h @@ -216,11 +216,13 @@ struct DDLine : DDNodeBase DDLine& Color(const MColor& v) { color1 = color2 = v.pack(); return *this; } DDLine& ColorStart(const MColor& v) { color1 = v.pack(); return *this; } DDLine& ColorEnd(const MColor& v) { color2 = v.pack(); return *this; } + DDLine& Width(float v) { width = v; return *this; } Vector3D start; Vector3D end; uint color1{ color_white.pack() }; uint color2{ color_white.pack() }; + float width{ 0.0f }; // line width in pixels, up to 1 draws a regular line }; struct DDPoly : DDNodeBase diff --git a/shared/render/DebugOverlay.cpp b/shared/render/DebugOverlay.cpp index 00383e227..c85cdf218 100644 --- a/shared/render/DebugOverlay.cpp +++ b/shared/render/DebugOverlay.cpp @@ -24,9 +24,13 @@ static constexpr const int DRAW_MAX_VERTS = 8192; static constexpr const int BOXES_DRAW_SUBDIV = 4096 / 16; static constexpr const int LINES_DRAW_SUBDIV = 2048; +static constexpr const int THICK_LINES_DRAW_SUBDIV = DRAW_MAX_VERTS / 4; // a thick line is a quad of 4 vertices static constexpr const int POLYS_DRAW_SUBDIV = 256; static constexpr const int GRAPH_MAX_VALUES = 400; +// lines with a width up to this value are drawn as regular lines +static constexpr const float THICK_LINE_MIN_WIDTH = 1.0f; + static constexpr const int MAX_MINICON_MESSAGES = 32; static CDebugOverlay g_DebugOverlays; @@ -279,7 +283,99 @@ void CDebugOverlay::Draw3DFunc(const OnDebugDrawFn& func, float fTime, int hashI } #ifdef ENABLE_DEBUG_DRAWING_PROFILE -static void DrawLineArray(ArrayRef lines, float frametime, const Volume& frustum, IGPURenderPassRecorder* rendPassRecorder) +static Vector3D ClipToWorld(const Matrix4x4& invViewProj, const Vector4D& clip) +{ + const Vector4D world = invViewProj * clip; + return world.xyz() / world.w; +} + +// makes a quad expanded across the line in screen space, so the width stays in pixels +static bool DrawThickLine(CMeshBuilder& meshBuilder, const DDLine& line, const Matrix4x4& viewProj, const Matrix4x4& invViewProj, const Vector2D& screenSize) +{ + Vector4D clipStart = viewProj * Vector4D(line.start, 1.0f); + Vector4D clipEnd = viewProj * Vector4D(line.end, 1.0f); + + uint startColor = line.color1; + uint endColor = line.color2; + + // the perspective divide requires a positive w, so clip the part behind the camera + constexpr float CLIP_W_EPSILON = 0.0001f; + if (clipStart.w < CLIP_W_EPSILON && clipEnd.w < CLIP_W_EPSILON) + return false; + + if (clipStart.w < CLIP_W_EPSILON) + { + const float t = (CLIP_W_EPSILON - clipStart.w) / (clipEnd.w - clipStart.w); + clipStart = lerp(clipStart, clipEnd, t); + startColor = lerpRGBAPacked(startColor, endColor, t); + } + else if (clipEnd.w < CLIP_W_EPSILON) + { + const float t = (CLIP_W_EPSILON - clipEnd.w) / (clipStart.w - clipEnd.w); + clipEnd = lerp(clipEnd, clipStart, t); + endColor = lerpRGBAPacked(endColor, startColor, t); + } + + const Vector2D screenStart = Vector2D( + (screenSize.x + screenSize.x * clipStart.x / clipStart.w) * 0.5f, + (screenSize.y - screenSize.y * clipStart.y / clipStart.w) * 0.5f); + const Vector2D screenEnd = Vector2D( + (screenSize.x + screenSize.x * clipEnd.x / clipEnd.w) * 0.5f, + (screenSize.y - screenSize.y * clipEnd.y / clipEnd.w) * 0.5f); + + const Vector2D screenDir = screenEnd - screenStart; + const float screenLength = length(screenDir); + if (screenLength < 0.001f) // the line points at the camera and has no direction on screen + return false; + + // half width offset in pixels, perpendicular to the line on screen + const Vector2D pixelOffset = Vector2D(-screenDir.y, screenDir.x) * (line.width * 0.5f / screenLength); + const Vector2D ndcOffset = Vector2D(pixelOffset.x * 2.0f / screenSize.x, -pixelOffset.y * 2.0f / screenSize.y); + + Vector4D clipStartLeft = clipStart; + Vector4D clipStartRight = clipStart; + clipStartLeft.x -= ndcOffset.x * clipStart.w; + clipStartLeft.y -= ndcOffset.y * clipStart.w; + clipStartRight.x += ndcOffset.x * clipStart.w; + clipStartRight.y += ndcOffset.y * clipStart.w; + + Vector4D clipEndLeft = clipEnd; + Vector4D clipEndRight = clipEnd; + clipEndLeft.x -= ndcOffset.x * clipEnd.w; + clipEndLeft.y -= ndcOffset.y * clipEnd.w; + clipEndRight.x += ndcOffset.x * clipEnd.w; + clipEndRight.y += ndcOffset.y * clipEnd.w; + + const Vector3D startLeft = ClipToWorld(invViewProj, clipStartLeft); + const Vector3D startRight = ClipToWorld(invViewProj, clipStartRight); + const Vector3D endLeft = ClipToWorld(invViewProj, clipEndLeft); + const Vector3D endRight = ClipToWorld(invViewProj, clipEndRight); + + meshBuilder.Color4(MColor(startColor)); + meshBuilder.Position3fv(startLeft); + const int firstVert = meshBuilder.AdvanceVertex(); + + meshBuilder.Color4(MColor(startColor)); + meshBuilder.Position3fv(startRight); + meshBuilder.AdvanceVertex(); + + meshBuilder.Color4(MColor(endColor)); + meshBuilder.Position3fv(endLeft); + meshBuilder.AdvanceVertex(); + + meshBuilder.Color4(MColor(endColor)); + meshBuilder.Position3fv(endRight); + meshBuilder.AdvanceVertex(); + + // two triangles, same vertex order as Quad3 + static const int quadIndices[] = { 0, 1, 2, 2, 1, 3 }; + for (int idx : quadIndices) + meshBuilder.AdvanceVertexIndex(firstVert + idx); + + return true; +} + +static void DrawLineArray(ArrayRef lines, float frametime, const Volume& frustum, const Vector2D& screenSize, const Matrix4x4& viewProj, IGPURenderPassRecorder* rendPassRecorder) { if(!lines.numElem()) return; @@ -297,6 +393,9 @@ static void DrawLineArray(ArrayRef lines, float frametime, const Volume& for(DDLine& line : lines) { line.lifetime -= frametime; + if (line.width > THICK_LINE_MIN_WIDTH) + continue; + if (!frustum.IsBoxInside(line.start, line.end)) continue; @@ -313,6 +412,38 @@ static void DrawLineArray(ArrayRef lines, float frametime, const Volume& if(meshBuilder.End(drawCmd)) g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + + // thick lines are drawn as screen-facing quads + meshBuilder.Init(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); + meshBuilder.Begin(PRIM_TRIANGLES); + + const Matrix4x4 invViewProj = inverse(viewProj); + + int thickLinesDrawn = 0; + for (DDLine& line : lines) + { + if (line.width <= THICK_LINE_MIN_WIDTH) + continue; + + if (!frustum.IsBoxInside(line.start, line.end)) + continue; + + if (thickLinesDrawn > 0 && (thickLinesDrawn % THICK_LINES_DRAW_SUBDIV) == 0) + { + if (meshBuilder.End(drawCmd)) + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + + // start with new mesh + meshBuilder.Init(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); + meshBuilder.Begin(PRIM_TRIANGLES); + } + + if (DrawThickLine(meshBuilder, line, viewProj, invViewProj, screenSize)) + ++thickLinesDrawn; + } + + if (meshBuilder.End(drawCmd)) + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); } static void DrawBoxWire(CMeshBuilder& meshBuilder, const Vector3D& position, const Vector3D& mins, const Vector3D& maxs, const MColor& color, const Quaternion& orientation) @@ -1225,7 +1356,7 @@ void CDebugOverlay::Draw(int winWide, int winTall, float timescale, ITexture* co { Threading::CScopedMutex m(s_debugOverlayMutex); - DrawLineArray(m_LineList, m_frameTime, m_frustum, rendPassRecorder); + DrawLineArray(m_LineList, m_frameTime, m_frustum, Vector2D(winWide, winTall), m_projMat * m_viewMat, rendPassRecorder); } { diff --git a/shared/sys/scripting/sys_esl_engine.cpp b/shared/sys/scripting/sys_esl_engine.cpp index fbf2bd5c3..deb1401f2 100644 --- a/shared/sys/scripting/sys_esl_engine.cpp +++ b/shared/sys/scripting/sys_esl_engine.cpp @@ -162,6 +162,7 @@ EQSCRIPT_TYPE_BEGIN(DDLine) EQSCRIPT_BIND_FUNC(Color) EQSCRIPT_BIND_FUNC(ColorStart) EQSCRIPT_BIND_FUNC(ColorEnd) + EQSCRIPT_BIND_FUNC(Width) EQSCRIPT_BIND_STATIC_FUNC("Time", S_DDNode_Time) EQSCRIPT_BIND_STATIC_FUNC("Name", S_DDNode_Name) EQSCRIPT_TYPE_END From b8cafcc4bb0537c3a469697bb875467128a86a75 Mon Sep 17 00:00:00 2001 From: SoapyMan Date: Thu, 19 Nov 2026 23:32:42 +0300 Subject: [PATCH 5/9] - filesystem: fix POSIX find wildcard matching, the old suffix matching ignored the pattern prefix and matched wrong entries like '.' --- framework/core/platform/OSFindData.cpp | 56 ++++++++++++++++++++------ 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/framework/core/platform/OSFindData.cpp b/framework/core/platform/OSFindData.cpp index 9636494ef..908ae11f1 100644 --- a/framework/core/platform/OSFindData.cpp +++ b/framework/core/platform/OSFindData.cpp @@ -11,6 +11,7 @@ #define WIN32_LEAN_AND_MEAN #include #else +#include #include // rmdir() #include // opendir, readdir #include @@ -18,6 +19,46 @@ #include "OSFindData.h" +#if !defined(PLAT_WIN) +// matches the entry name against a wildcard file name pattern; +// '*' matches any sequence of characters (including empty) and '?' matches any +// single character, case-insensitive - same as the Windows FindFirstFile behavior +static bool MatchWildcardName(const char* pattern, const char* name) +{ + const char* starPattern = nullptr; + const char* starName = nullptr; + + while (*name != 0) + { + if (*pattern == '*') + { + // remember the star position and try to match the rest with an empty sequence + starPattern = ++pattern; + starName = name; + } + else if (*pattern == '?' || CType::LowerChar(*pattern) == CType::LowerChar(*name)) + { + ++pattern; + ++name; + } + else if (starPattern != nullptr) + { + // backtrack: let the last star consume one more character + pattern = starPattern; + name = ++starName; + } + else + return false; + } + + // trailing stars match an empty sequence + while (*pattern == '*') + ++pattern; + + return *pattern == 0; +} +#endif + OSFindData::~OSFindData() { Release(); @@ -74,18 +115,9 @@ bool OSFindData::GetNext() if (*m_entry->d_name == 0) continue; - const int wildcardFileStart = m_wildcard.Find("*"); - if (wildcardFileStart != -1) - { - const char* wildcardFile = m_wildcard.ToCString() + wildcardFileStart + 1; - if (*wildcardFile == 0) - break; - - const char* found = CString::SubStringCaseIns(m_entry->d_name, wildcardFile); - if (found && strlen(found) == strlen(wildcardFile)) - break; - } - else + // only the file name part of the wildcard is matched against the entry name + const EqStringRef wildcardName = fnmPathExtractName(m_wildcard); + if (MatchWildcardName(wildcardName, m_entry->d_name)) break; } while (true); From 0024716f23906d9948573c46e0e305679b3fd724 Mon Sep 17 00:00:00 2001 From: SoapyMan Date: Fri, 20 Nov 2026 03:10:55 +0500 Subject: [PATCH 6/9] - math: lineProjection returns 0 for a zero-length segment instead of dividing by zero Co-Authored-By: Claude Opus 5.5 --- framework/math/Vector.inl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/framework/math/Vector.inl b/framework/math/Vector.inl index 69008fb72..7596db67b 100644 --- a/framework/math/Vector.inl +++ b/framework/math/Vector.inl @@ -1138,14 +1138,22 @@ template inline T lineProjection(const TVec2D &start, const TVec2D &end, const TVec2D &point) { TVec2D v = end - start; - return dot(v, point - start) / dot(v, v); + const T d = dot(v, v); + + if (d < F_EPS) return (T)0; + + return dot(v, point - start) / d; } template inline T lineProjection(const TVec3D &start, const TVec3D &end, const TVec3D &point) { TVec3D v = end - start; - return dot(v, point - start) / dot(v, v); + const T d = dot(v, v); + + if (d < F_EPS) return (T)0; + + return dot(v, point - start) / d; } const float _oneBy255 = 1.0f / 255.0f; From dc6885b1ca3f8d6883550290406e0e399ee03797 Mon Sep 17 00:00:00 2001 From: SoapyMan Date: Fri, 20 Nov 2026 04:48:30 +0500 Subject: [PATCH 7/9] - docs: add the Design philosophy section to AGENTS.md, simplicity and functionality in balance: reuse engine facilities, data first, less code with the same behavior Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index a8e2287a2..b231ba9c3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,7 +12,19 @@ the user's current request wins, followed by this file, then the subsystem docum evidence, compatibility constraints and validation. The human creates the pull request, answers review questions and takes responsibility for the submission; agent assistance does not transfer that responsibility. - + +## Design philosophy + +Equilibrium means simplicity and functionality in balance. Prefer the smallest design that +fully covers the feature: + +- Reuse existing engine facilities (`IGraph`, containers, math helpers) instead of writing + parallel implementations. +- Data comes first: prefer simple data representations and reuse of existing data. Keep only + what is needed or what fits the task best, without sacrificing performance. +- Less code with the same behavior is the better solution; do not trade away required + functionality for brevity. + ## Mandatory preflight Before editing: From 82bd9666cd6c54ff4743e899e6a7bb1cf525f480 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Fri, 20 Nov 2026 18:40:50 +0300 Subject: [PATCH 8/9] - math: add DistanceSegSeg2D, the plane distance between the two segments with the fractions of the closest points --- framework/math/Utility.cpp | 107 +++++++++++++++++++++++++++++++++++++ framework/math/Utility.h | 4 ++ 2 files changed, 111 insertions(+) diff --git a/framework/math/Utility.cpp b/framework/math/Utility.cpp index 6898d80df..abffba3f6 100644 --- a/framework/math/Utility.cpp +++ b/framework/math/Utility.cpp @@ -498,6 +498,113 @@ float DistanceLineSegLineSeg(const Vector3D& L0, const Vector3D& L1, const Vecto return distance(ln, sn); } +float DistanceSegSeg2D(const Vector2D& sA0, const Vector2D& sA1, const Vector2D& sB0, const Vector2D& sB1, float* outFA, float* outFB) +{ + // dist3D_Segment_to_Segment by Dan Sunday reduced to the plane, the 2D variant of + // DistanceLineSegLineSeg + const Vector2D u = sA1 - sA0; + const Vector2D v = sB1 - sB0; + const Vector2D w = sA0 - sB0; + + const float a = dot(u, u); + const float b = dot(u, v); + const float c = dot(v, v); + const float d = dot(u, w); + const float e = dot(v, w); + + // the degenerate segments keep their start as the closest point + if (a < F_EPS && c < F_EPS) + { + if (outFA) *outFA = 0.0f; + if (outFB) *outFB = 0.0f; + return length(w); + } + if (c < F_EPS) // B is a point, its projection on A + { + const float s = clamp(-d / a, 0.0f, 1.0f); + if (outFA) *outFA = s; + if (outFB) *outFB = 0.0f; + return length(lerp(sA0, sA1, s) - sB0); + } + + const float D = a * c - b * b; + float sN = 0.0f; + float sD = D; + float tN = 0.0f; + float tD = D; + + if (D < F_EPS) // the segments are almost parallel + { + sN = 0.0f; + tN = e; + tD = c; + sD = c; + } + else // get the closest points on the infinite lines + { + sN = (b * e - c * d); + tN = (a * e - b * d); + if (sN < 0.0f) // sc < 0 => the s=0 edge is visible + { + sN = 0.0f; + tN = e; + tD = c; + } + else if (sN > sD) // sc > 1 => the s=1 edge is visible + { + sN = sD; + tN = e + b; + tD = c; + } + } + + if (tN < 0.0f) // tc < 0 => the t=0 edge is visible + { + tN = 0.0f; + // recompute sc for this edge + if (-d < 0.0f) + { + sN = 0.0f; + } + else if (-d > a) + { + sN = sD; + } + else + { + sN = -d; + sD = a; + } + } + else if (tN > tD) // tc > 1 => the t=1 edge is visible + { + tN = tD; + // recompute sc for this edge + if ((-d + b) < 0.0f) + { + sN = 0.0f; + } + else if ((-d + b) > a) + { + sN = sD; + } + else + { + sN = (-d + b); + sD = a; + } + } + + // finally do the division to get sc and tc + const float sc = (fabsf(sD) > F_EPS) ? sN / sD : 0.0f; + const float tc = (fabsf(tD) > F_EPS) ? tN / tD : 0.0f; + + if (outFA) *outFA = sc; + if (outFB) *outFB = tc; + + return length(lerp(sA0, sA1, sc) - lerp(sB0, sB1, tc)); +} + static float ConvexOrient2D(const Vector2D& o, const Vector2D& a, const Vector2D& b) { return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x); diff --git a/framework/math/Utility.h b/framework/math/Utility.h index 9ed21503c..e9c502be5 100644 --- a/framework/math/Utility.h +++ b/framework/math/Utility.h @@ -55,6 +55,10 @@ float DistancePointPoly2D(const Vector2D& point, ArrayCRef edgeVerts, float DistanceLineLine(const Vector3D& lB1, const Vector3D& lE1, const Vector3D& lB2, const Vector3D& lE2); float DistanceLineSegLineSeg(const Vector3D& L0, const Vector3D& L1, const Vector3D& S0, const Vector3D& S1, float* Lt = nullptr, Vector3D* Ln = nullptr, float* St = nullptr, Vector3D* Sn = nullptr); +// distance between the two segments in the plane, the fractions of the closest points along them +// (Dan Sunday's segment to segment distance, the degenerate segments keep their start) +float DistanceSegSeg2D(const Vector2D& sA0, const Vector2D& sA1, const Vector2D& sB0, const Vector2D& sB1, float* outFA = nullptr, float* outFB = nullptr); + //--------------------------------------------------------------------------------- void ConvexHull2D(Array& points, Array& out); From 641e7a4c0c63854ee3470bc5d672161a67c4a18c Mon Sep 17 00:00:00 2001 From: SoapyMan Date: Sat, 21 Nov 2026 00:54:45 +0500 Subject: [PATCH 9/9] - math: fix lerpRGBAPacked alpha, the alpha byte overflowed 32 bits and was lost - matsystem: add the DebugDraw shader, the Default pipelines and bindings with the viewport size and the camera position - matsystem: add CMeshBuilder Position4fv and Normal4fv to write the free w components - render: draw the debug overlay 3D primitives with the DebugDraw shader, the lines are clipped and expanded in the vertex shader - render: add DDLine Dash, the dash and gap length in pixels drawn by the fragment shader - render: add the debug primitive effects Pattern (checker, hatch, dots), GapAlpha and Occluded (drawn behind the scene geometry) - render: add Lit to the filled debug boxes, spheres and polygons, lit from the camera - esl: bind the debug primitive effects and the DBG_PATTERN_* constants - docs: describe the DebugDraw shader, its vertex data and the debug primitive effects Co-Authored-By: Claude Opus 5.5 --- core/materialsystem1/DefaultShader.cpp | 41 +++ docs/public_rendering_overview.md | 42 ++- docs/rendering_matsystem_shaders_overview.md | 2 +- framework/math/Vector.cpp | 5 +- public/materialsystem1/MeshBuilder.h | 13 + public/render/IDebugOverlay.h | 66 +++- shared/render/DebugOverlay.cpp | 342 +++++++++---------- shared/render/DebugOverlay.h | 3 + shared/sys/scripting/sys_esl_engine.cpp | 37 ++ 9 files changed, 357 insertions(+), 194 deletions(-) diff --git a/core/materialsystem1/DefaultShader.cpp b/core/materialsystem1/DefaultShader.cpp index 873298df6..0bb2204d6 100644 --- a/core/materialsystem1/DefaultShader.cpp +++ b/core/materialsystem1/DefaultShader.cpp @@ -175,6 +175,7 @@ BEGIN_SHADER_CLASS( FixedArray bufferData; bufferData.append(rendPassInfo->drawColor); bufferData.append(GetTextureTransform(m_baseTextureTransformVar, m_baseTextureScaleVar)); + AppendMaterialParams(bufferData, setupParams); GPUBufferView cameraParamsBuffer; for (const RenderBufferInfo& rendBuffer : setupParams.uniformBuffers) @@ -211,8 +212,48 @@ BEGIN_SHADER_CLASS( return setupParams.pipelineInfo.bindGroup[bindGroupId]; } + // the parameters of the derived shaders after the color and the texture transform + virtual void AppendMaterialParams(FixedArray& bufferData, const BindGroupSetupParams& setupParams) const {} + MatTextureProxy m_baseTexture; mutable GPUBufferView m_currentCameraBuffer; mutable int m_currentCameraId{ -1 }; END_SHADER_CLASS + +//------------------------------------------------------------ +// Debug overlay shader: the Default pipelines and bindings, the GPU shader draws +// the dash and pattern effects from the vertex data (see DebugOverlay.cpp) + +namespace CDebugDrawShaderLocalNamespace { +static const char ThisClassNameStr[] = "DebugDraw"; +static ArrayCRef GetSupportedVertexLayoutIds() +{ + static const int supportedFormats[] = { 0, SHADER_VERTEX_ID(DynMeshVertex) }; + return ArrayCRef(supportedFormats); +} + +class CDebugDrawShader : public CDefaultShaderLocalNamespace::CDefaultShader +{ +public: + CDebugDrawShader(IMaterial* material) : CDefaultShader(material) {} + + ArrayCRef GetSupportedVertexLayoutIds() const override { return CDebugDrawShaderLocalNamespace::GetSupportedVertexLayoutIds(); } + const char* GetName() const override { return ThisClassNameStr; } + int GetNameHash() const override { return StringIdConst24("DebugDraw"); } + + // the viewport size for the lines in pixels and the camera position for Lit + void AppendMaterialParams(FixedArray& bufferData, const BindGroupSetupParams& setupParams) const override + { + const IVector2D targetSize = setupParams.passContext.recorder->GetRenderTargetDimensions(); + const float width = static_cast(max(targetSize.x, 1)); + const float height = static_cast(max(targetSize.y, 1)); + bufferData.append(Vector4D(width, height, 1.0f / width, 1.0f / height)); + + Matrix4x4 view; + g_matSystem->GetMatrix(MATRIXMODE_VIEW, view); + bufferData.append(Vector4D(inverse(view).getTranslationComponentTransposed(), 0.0f)); + } +}; +DEFINE_SHADER(ThisClassNameStr, CDebugDrawShader) +} diff --git a/docs/public_rendering_overview.md b/docs/public_rendering_overview.md index 60c527e00..cc531d33d 100644 --- a/docs/public_rendering_overview.md +++ b/docs/public_rendering_overview.md @@ -201,17 +201,51 @@ if (snd_scriptsound_debug.GetBool()) | Builder | Shape | Setters | |---|---|---| | `DbgText3D()` | Text at a 3D position | `Text(fmt, ...)`, `Position`, `Distance` (max visible distance), `Color` | -| `DbgLine()` | Line | `Start`, `End`, `Color`, `ColorStart`, `ColorEnd`, `Width` (pixels, up to 1 is a regular line) | -| `DbgBox()` | Axis-aligned box | `Box(bbox)`, `Mins`, `Maxs`, `CenterSize`, `Color`, `Fill` | +| `DbgLine()` | Line | `Start`, `End`, `Color`, `ColorStart`, `ColorEnd`, `Width` (pixels, up to 1 is a regular line), `Dash` (dash and gap length in pixels, 0 is solid) | +| `DbgBox()` | Axis-aligned box | `Box(bbox)`, `Mins`, `Maxs`, `CenterSize`, `Color`, `Fill`, `Lit` | | `DbgOriBox()` | Oriented box | box setters + `Position`, `Rotation(quaternion)` | -| `DbgSphere()` | Sphere | `Position`, `Radius`, `Color`, `Fill` | +| `DbgSphere()` | Sphere | `Position`, `Radius`, `Color`, `Fill`, `Lit` | | `DbgCylinder()` | Cylinder | `Position`, `Radius`, `Height`, `Color` | -| `DbgPoly()` | Polygon (up to 20 points) | `Point`, `Points`, `ClipPlane(plane, origin, size)`, `Color`, `Fill`, `Outline` | +| `DbgPoly()` | Polygon (up to 20 points) | `Point`, `Points`, `ClipPlane(plane, origin, size)`, `Color`, `Fill`, `Outline`, `Lit` | | `DbgVolume()` | Convex volume from planes | `Planes`, `Volume(volume)`, `Color` | `Width(px)` sets the line thickness in pixels: a line wider than one pixel is drawn as a quad expanded in screen space and keeps its pixel width at any distance, otherwise it is a regular line. +The 3D primitives are drawn with the `DebugDraw` shader (`core/materialsystem1/DefaultShader.cpp`, +GPU source `E2Base/shadersSRC/source_DebugDraw.fx`): the `Default` shader pipelines and bindings plus +the viewport size and the camera position in the material parameters. The effects add no geometry: +the effect of a primitive is packed into its `DynMeshVertex` vertices by `DbgSetupEffect` and +`DbgLineVertex` in `shared/render/DebugOverlay.cpp`: + +| Vertex value | Lines | Other primitives | +|---|---|---| +| `_position.xyz` | Line end | Position | +| `_position.w` | Thick line width in pixels, the sign is the quad side; `0` for a regular line | — | +| `_normal.xyz` (half) | Vector to the other end | `0` | +| `_normal.w` (half) | `Dash` in pixels, negative at the end vertices | `Lit` | +| `_texCoord.x` (half) | `pattern * 256 + size` (pattern size in whole pixels up to 255) | same | +| `_texCoord.y` (half) | `GapAlpha` | same | + +The vertex shader clips a line by the camera (the vertex behind it moves to the clip point), expands +a thick line across its screen direction and passes the dash start on screen: the line start, or +its end when the start is behind the camera. The dashes stay in place at that point when the +camera moves. + +Effect setters of the 3D builders (all but `DbgText3D` and `DbgVolume`): + +- `Pattern(pattern, sizePx = 4)` — screen-space transparency pattern: `DBG_PATTERN_CHECKER`, + `DBG_PATTERN_HATCH` (diagonal stripes), `DBG_PATTERN_DOTS`. +- `GapAlpha(alpha)` — alpha multiplier of the pattern holes and the dash gaps, `0` (default) cuts + them out. +- `Occluded(pattern = DBG_PATTERN_HATCH)` — the parts behind the scene geometry are drawn too, with + this pattern (`DBG_PATTERN_NONE` draws them solid). The overlay draws the primitives in two + passes: the visible parts, then the occluded parts with the inverted depth test. +- `Lit()` of the filled boxes, spheres and polygons — shades the faces by the angle to the camera + (the face normal comes from the screen derivatives of the world position). + +Scripts get the same setters and the `DBG_PATTERN_*` constants. + Common setters (call them last, they return the base builder): - `Time(seconds)` — keep the primitive visible for the given time; `0` (default) — one frame. diff --git a/docs/rendering_matsystem_shaders_overview.md b/docs/rendering_matsystem_shaders_overview.md index 585e69361..8476019d0 100644 --- a/docs/rendering_matsystem_shaders_overview.md +++ b/docs/rendering_matsystem_shaders_overview.md @@ -11,7 +11,7 @@ pipelines and binds the bind groups for each draw. Each material shader has a ma |---|---| | Interface | `public/materialsystem1/IMatSysShader.h` — `IMatSystemShader`, `EBindGroupId`, `IShaderMeshInstanceProvider`, registration macros | | Base class | `public/materialsystem1/BaseShader.h/.cpp` (`BaseShader` static library) — `CBaseShader`, `BEGIN_SHADER_CLASS` | -| Engine shaders | `core/materialsystem1/Shaders/Base` (`eqBaseShaders`), material system built-ins (`DefaultShader.cpp`) | +| Engine shaders | `core/materialsystem1/Shaders/Base` (`eqBaseShaders`), material system built-ins (`DefaultShader.cpp`: `Default`, `DebugDraw` for the debug overlay) | | Application shaders | Any project that links `BaseShader`, e.g. `samples/GPUDriven/shader_baseunlit.cpp` | | GPU shader sources | Game data `shadersSRC` folders (e.g. E2DevMain `build/E2Base/shadersSRC`, `build/GpuDriven/shadersSRC`) | diff --git a/framework/math/Vector.cpp b/framework/math/Vector.cpp index 37f6ea338..ed534af52 100644 --- a/framework/math/Vector.cpp +++ b/framework/math/Vector.cpp @@ -273,6 +273,7 @@ uint lerpRGBAPacked(uint a, uint b, float v) const uint f2 = 256 * v; const uint f1 = 256 - f2; - return ((((( a & MASK1 ) * f1 ) + ( ( b & MASK1 ) * f2 )) >> 8 ) & MASK1 ) - | ((((( a & MASK2 ) * f1 ) + ( ( b & MASK2 ) * f2 )) >> 8 ) & MASK2 ); + // alpha and green are shifted down first, alpha * 256 overflows 32 bits in place + return ((((( a & MASK1 ) * f1 ) + ( ( b & MASK1 ) * f2 )) >> 8 ) & MASK1 ) + | (((( ( a >> 8 ) & MASK1 ) * f1 ) + ( ( ( b >> 8 ) & MASK1 ) * f2 )) & MASK2 ); } \ No newline at end of file diff --git a/public/materialsystem1/MeshBuilder.h b/public/materialsystem1/MeshBuilder.h index 3ae546e88..453944f69 100644 --- a/public/materialsystem1/MeshBuilder.h +++ b/public/materialsystem1/MeshBuilder.h @@ -32,10 +32,12 @@ class CMeshBuilder void Position3fv(const Vector3D& v); void Position2f(float x, float y); void Position2fv(const Vector2D& v); + void Position4fv(const Vector4D& v); // w is a free value for the shader, 1 by the other setters // normal setup void Normal3f(float nx, float ny, float nz); void Normal3fv(const Vector3D& v); + void Normal4fv(const Vector4D& v); // w is a free value for the shader, 0 by the other setters // texcoord setup void TexCoord2f(float s, float t); @@ -239,6 +241,12 @@ inline void CMeshBuilder::Position2fv(const Vector2D& v) Position2f(v[0], v[1]); } +inline void CMeshBuilder::Position4fv(const Vector4D& v) +{ + m_position.value = v; + m_pushedVert = true; +} + // normal setup inline void CMeshBuilder::Normal3f(float nx, float ny, float nz) { @@ -253,6 +261,11 @@ inline void CMeshBuilder::Normal3fv(const Vector3D& v) Normal3f(v[0], v[1], v[2]); } +inline void CMeshBuilder::Normal4fv(const Vector4D& v) +{ + m_normal.value = v; +} + inline void CMeshBuilder::TexCoord2f(float s, float t) { m_texcoord.value.x = s; diff --git a/public/render/IDebugOverlay.h b/public/render/IDebugOverlay.h index 1af289396..eea94c107 100644 --- a/public/render/IDebugOverlay.h +++ b/public/render/IDebugOverlay.h @@ -69,6 +69,38 @@ struct DDNodeBase DDNodeBase& Name(const char* name) { nameHash = StringId24(name); return *this; } }; +// screen space pattern of the debug geometry, its holes are drawn with DDEffect::gapAlpha +enum EDbgPattern : uint8 +{ + DBG_PATTERN_NONE = 0, + DBG_PATTERN_CHECKER, // checker board of pattern size cells + DBG_PATTERN_HATCH, // diagonal stripes of pattern size width + DBG_PATTERN_DOTS, // dots in pattern size cells +}; + +// the effect of a debug primitive, drawn by the DebugDraw shader +struct DDEffect +{ + float patternSize{ 4.0f }; // pattern cell size in pixels + float gapAlpha{ 0.0f }; // alpha multiplier of the pattern holes and the line dash gaps + EDbgPattern pattern{ DBG_PATTERN_NONE }; + EDbgPattern occludedPattern{ DBG_PATTERN_NONE }; // pattern of the occluded parts + bool occluded{ false }; // the parts behind the scene geometry are drawn too +}; + +// a debug primitive with the DebugDraw shader effects +template +struct DDShapeBase : DDNodeBase +{ + DDShapeBase(PPSourceLine sl) : DDNodeBase(sl) {} + + T& Pattern(EDbgPattern v, float sizePx = 4.0f) { effect.pattern = v; effect.patternSize = sizePx; return static_cast(*this); } + T& GapAlpha(float v) { effect.gapAlpha = v; return static_cast(*this); } + T& Occluded(EDbgPattern v = DBG_PATTERN_HATCH) { effect.occluded = true; effect.occludedPattern = v; return static_cast(*this); } + + DDEffect effect; +}; + struct DDText3D : DDNodeBase { ~DDText3D() @@ -100,7 +132,7 @@ struct DDText3D : DDNodeBase uint color{ color_white.pack() }; }; -struct DDBox : DDNodeBase +struct DDBox : DDShapeBase { ~DDBox() { @@ -108,7 +140,7 @@ struct DDBox : DDNodeBase Dispatch(); } - DDBox(PPSourceLine sl) : DDNodeBase(sl) {} + DDBox(PPSourceLine sl) : DDShapeBase(sl) {} void Dispatch(); @@ -118,14 +150,16 @@ struct DDBox : DDNodeBase DDBox& Maxs(const Vector3D& v) { maxs = v; return *this; } DDBox& Color(const MColor& v) { color = v.pack(); return *this; } DDBox& Fill(bool value) { fill = value; return *this; } + DDBox& Lit(bool v = true) { lit = v; return *this; } // the filled faces are lit from the camera Vector3D mins; Vector3D maxs; uint color{ color_white.pack() }; bool fill{ false }; + bool lit{ false }; }; -struct DDOrientedBox : DDNodeBase +struct DDOrientedBox : DDShapeBase { ~DDOrientedBox() { @@ -133,7 +167,7 @@ struct DDOrientedBox : DDNodeBase Dispatch(); } - DDOrientedBox(PPSourceLine sl) : DDNodeBase(sl) {} + DDOrientedBox(PPSourceLine sl) : DDShapeBase(sl) {} void Dispatch(); @@ -145,15 +179,17 @@ struct DDOrientedBox : DDNodeBase DDOrientedBox& Rotation(const Quaternion& r) { rotation = r; return *this; } DDOrientedBox& Color(const MColor& v) { color = v.pack(); return *this; } DDOrientedBox& Fill(bool value) { fill = value; return *this; } + DDOrientedBox& Lit(bool v = true) { lit = v; return *this; } // the filled faces are lit from the camera Vector3D mins, maxs; Quaternion rotation{ qidentity }; Vector3D position; uint color{ color_white.pack() }; bool fill{ false }; + bool lit{ false }; }; -struct DDSphere : DDNodeBase +struct DDSphere : DDShapeBase { ~DDSphere() { @@ -161,7 +197,7 @@ struct DDSphere : DDNodeBase Dispatch(); } - DDSphere(PPSourceLine sl) : DDNodeBase(sl) {} + DDSphere(PPSourceLine sl) : DDShapeBase(sl) {} void Dispatch(); @@ -169,14 +205,16 @@ struct DDSphere : DDNodeBase DDSphere& Radius(float v) { radius = v; return *this; } DDSphere& Color(const MColor& v) { color = v.pack(); return *this; } DDSphere& Fill(bool value) { fill = value; return *this; } + DDSphere& Lit(bool v = true) { lit = v; return *this; } // the filled faces are lit from the camera Vector3D origin; float radius{ 1.0f }; uint color{ color_white.pack() }; bool fill{ false }; + bool lit{ false }; }; -struct DDCylinder : DDNodeBase +struct DDCylinder : DDShapeBase { ~DDCylinder() { @@ -184,7 +222,7 @@ struct DDCylinder : DDNodeBase Dispatch(); } - DDCylinder(PPSourceLine sl) : DDNodeBase(sl) {} + DDCylinder(PPSourceLine sl) : DDShapeBase(sl) {} void Dispatch(); @@ -199,7 +237,7 @@ struct DDCylinder : DDNodeBase uint color{ color_white.pack() }; }; -struct DDLine : DDNodeBase +struct DDLine : DDShapeBase { ~DDLine() { @@ -207,7 +245,7 @@ struct DDLine : DDNodeBase Dispatch(); } - DDLine(PPSourceLine sl) : DDNodeBase(sl) {} + DDLine(PPSourceLine sl) : DDShapeBase(sl) {} void Dispatch(); @@ -217,15 +255,17 @@ struct DDLine : DDNodeBase DDLine& ColorStart(const MColor& v) { color1 = v.pack(); return *this; } DDLine& ColorEnd(const MColor& v) { color2 = v.pack(); return *this; } DDLine& Width(float v) { width = v; return *this; } + DDLine& Dash(float v) { dash = v; return *this; } Vector3D start; Vector3D end; uint color1{ color_white.pack() }; uint color2{ color_white.pack() }; float width{ 0.0f }; // line width in pixels, up to 1 draws a regular line + float dash{ 0.0f }; // dash and gap length in pixels, 0 draws a solid line }; -struct DDPoly : DDNodeBase +struct DDPoly : DDShapeBase { ~DDPoly() { @@ -233,7 +273,7 @@ struct DDPoly : DDNodeBase Dispatch(); } - DDPoly(PPSourceLine sl) : DDNodeBase(sl) {} + DDPoly(PPSourceLine sl) : DDShapeBase(sl) {} void Dispatch(); @@ -242,11 +282,13 @@ struct DDPoly : DDNodeBase DDPoly& Points(const ArrayCRef _verts) { verts.append(_verts.ptr(), _verts.numElem()); return *this; } DDPoly& Color(const MColor& v) { color = v.pack(); return *this; } DDPoly& Fill(bool v = true) { fill = v; return *this; } + DDPoly& Lit(bool v = true) { lit = v; return *this; } // the filled faces are lit from the camera DDPoly& Outline(bool v = true) { outline = v; return *this; } FixedArray verts; uint color{ color_white.pack() }; bool fill{ true }; + bool lit{ false }; bool outline{ false }; }; diff --git a/shared/render/DebugOverlay.cpp b/shared/render/DebugOverlay.cpp index c85cdf218..19bd81698 100644 --- a/shared/render/DebugOverlay.cpp +++ b/shared/render/DebugOverlay.cpp @@ -9,6 +9,7 @@ #include "core/ConVar.h" #include "math/Utility.h" #include "math/Rectangle.h" +#include "utils/KeyValues.h" #include "DebugOverlay.h" #include "font/IFontCache.h" @@ -102,6 +103,7 @@ void CDebugOverlay::Shutdown() { #ifdef ENABLE_DEBUG_DRAWING_PROFILE m_dbgTexture = nullptr; + m_debugMaterial = nullptr; Clear(); #endif // ENABLE_DEBUG_DRAWING_PROFILE } @@ -283,167 +285,151 @@ void CDebugOverlay::Draw3DFunc(const OnDebugDrawFn& func, float fTime, int hashI } #ifdef ENABLE_DEBUG_DRAWING_PROFILE -static Vector3D ClipToWorld(const Matrix4x4& invViewProj, const Vector4D& clip) + +// a 3D drawing pass of the debug overlay: the visible parts of the primitives, +// or the occluded parts of the primitives with DDEffect::occluded +struct DbgDrawPass +{ + IGPURenderPassRecorder* recorder{ nullptr }; + IMaterial* material{ nullptr }; + const Volume& frustum; + float frameTime{ 0.0f }; // zero in the occluded pass, the lifetime is spent once a frame + bool occluded{ false }; +}; + +static MatSysDefaultRenderPass DbgRenderPassData(const DbgDrawPass& pass, ECullMode cullMode = CULL_NONE) { - const Vector4D world = invViewProj * clip; - return world.xyz() / world.w; + MatSysDefaultRenderPass renderPass; + renderPass.blendMode = SHADER_BLEND_TRANSLUCENT; + renderPass.cullMode = cullMode; + renderPass.depthTest = true; + renderPass.depthWrite = false; + if (pass.occluded) + renderPass.depthFunc = COMPFUNC_LESS; // behind the scene geometry, the depth is reversed + return renderPass; } -// makes a quad expanded across the line in screen space, so the width stays in pixels -static bool DrawThickLine(CMeshBuilder& meshBuilder, const DDLine& line, const Matrix4x4& viewProj, const Matrix4x4& invViewProj, const Vector2D& screenSize) +// sets up the effect of the next vertices for the DebugDraw shader (source_DebugDraw.fx), +// false when the primitive is not drawn in this pass +static bool DbgSetupEffect(CMeshBuilder& meshBuilder, const DbgDrawPass& pass, const DDEffect& effect, bool lit = false) { - Vector4D clipStart = viewProj * Vector4D(line.start, 1.0f); - Vector4D clipEnd = viewProj * Vector4D(line.end, 1.0f); + if (pass.occluded && !effect.occluded) + return false; - uint startColor = line.color1; - uint endColor = line.color2; + // the pattern and its whole pixel size are exact in half + const EDbgPattern pattern = pass.occluded ? effect.occludedPattern : effect.pattern; + const float patternSize = clamp(roundf(effect.patternSize), 1.0f, 255.0f); + meshBuilder.TexCoord2f(pattern * 256.0f + patternSize, effect.gapAlpha); + meshBuilder.Normal4fv(Vector4D(0.0f, 0.0f, 0.0f, lit ? 1.0f : 0.0f)); + return true; +} - // the perspective divide requires a positive w, so clip the part behind the camera - constexpr float CLIP_W_EPSILON = 0.0001f; - if (clipStart.w < CLIP_W_EPSILON && clipEnd.w < CLIP_W_EPSILON) - return false; +// a line end vertex, the shader clips the line by the camera, expands it by the width and draws the dashes; +// side is the quad side of a thick line, the dash sign tells the start from the end +static void DbgLineVertex(CMeshBuilder& meshBuilder, const DDLine& line, bool atStart, float side) +{ + const Vector3D& position = atStart ? line.start : line.end; + const Vector3D& other = atStart ? line.end : line.start; - if (clipStart.w < CLIP_W_EPSILON) - { - const float t = (CLIP_W_EPSILON - clipStart.w) / (clipEnd.w - clipStart.w); - clipStart = lerp(clipStart, clipEnd, t); - startColor = lerpRGBAPacked(startColor, endColor, t); - } - else if (clipEnd.w < CLIP_W_EPSILON) - { - const float t = (CLIP_W_EPSILON - clipEnd.w) / (clipStart.w - clipEnd.w); - clipEnd = lerp(clipEnd, clipStart, t); - endColor = lerpRGBAPacked(endColor, startColor, t); - } + meshBuilder.Color4(MColor(atStart ? line.color1 : line.color2)); + meshBuilder.Normal4fv(Vector4D(other - position, atStart ? line.dash : -line.dash)); + meshBuilder.Position4fv(Vector4D(position, line.width * side)); +} - const Vector2D screenStart = Vector2D( - (screenSize.x + screenSize.x * clipStart.x / clipStart.w) * 0.5f, - (screenSize.y - screenSize.y * clipStart.y / clipStart.w) * 0.5f); - const Vector2D screenEnd = Vector2D( - (screenSize.x + screenSize.x * clipEnd.x / clipEnd.w) * 0.5f, - (screenSize.y - screenSize.y * clipEnd.y / clipEnd.w) * 0.5f); +// a regular line +static void DrawThinLine(CMeshBuilder& meshBuilder, const DDLine& line) +{ + DbgLineVertex(meshBuilder, line, true, 0.0f); + meshBuilder.AdvanceVertex(); - const Vector2D screenDir = screenEnd - screenStart; - const float screenLength = length(screenDir); - if (screenLength < 0.001f) // the line points at the camera and has no direction on screen - return false; + DbgLineVertex(meshBuilder, line, false, 0.0f); + meshBuilder.AdvanceVertex(); +} - // half width offset in pixels, perpendicular to the line on screen - const Vector2D pixelOffset = Vector2D(-screenDir.y, screenDir.x) * (line.width * 0.5f / screenLength); - const Vector2D ndcOffset = Vector2D(pixelOffset.x * 2.0f / screenSize.x, -pixelOffset.y * 2.0f / screenSize.y); - - Vector4D clipStartLeft = clipStart; - Vector4D clipStartRight = clipStart; - clipStartLeft.x -= ndcOffset.x * clipStart.w; - clipStartLeft.y -= ndcOffset.y * clipStart.w; - clipStartRight.x += ndcOffset.x * clipStart.w; - clipStartRight.y += ndcOffset.y * clipStart.w; - - Vector4D clipEndLeft = clipEnd; - Vector4D clipEndRight = clipEnd; - clipEndLeft.x -= ndcOffset.x * clipEnd.w; - clipEndLeft.y -= ndcOffset.y * clipEnd.w; - clipEndRight.x += ndcOffset.x * clipEnd.w; - clipEndRight.y += ndcOffset.y * clipEnd.w; - - const Vector3D startLeft = ClipToWorld(invViewProj, clipStartLeft); - const Vector3D startRight = ClipToWorld(invViewProj, clipStartRight); - const Vector3D endLeft = ClipToWorld(invViewProj, clipEndLeft); - const Vector3D endRight = ClipToWorld(invViewProj, clipEndRight); - - meshBuilder.Color4(MColor(startColor)); - meshBuilder.Position3fv(startLeft); +// a quad expanded across the line in screen space by the shader, so the width stays in pixels +static void DrawThickLine(CMeshBuilder& meshBuilder, const DDLine& line) +{ + // the side is from the direction to the other end, so it is mirrored at the end + DbgLineVertex(meshBuilder, line, true, -1.0f); const int firstVert = meshBuilder.AdvanceVertex(); - meshBuilder.Color4(MColor(startColor)); - meshBuilder.Position3fv(startRight); + DbgLineVertex(meshBuilder, line, true, 1.0f); meshBuilder.AdvanceVertex(); - meshBuilder.Color4(MColor(endColor)); - meshBuilder.Position3fv(endLeft); + DbgLineVertex(meshBuilder, line, false, 1.0f); meshBuilder.AdvanceVertex(); - meshBuilder.Color4(MColor(endColor)); - meshBuilder.Position3fv(endRight); + DbgLineVertex(meshBuilder, line, false, -1.0f); meshBuilder.AdvanceVertex(); // two triangles, same vertex order as Quad3 static const int quadIndices[] = { 0, 1, 2, 2, 1, 3 }; for (int idx : quadIndices) meshBuilder.AdvanceVertexIndex(firstVert + idx); - - return true; } -static void DrawLineArray(ArrayRef lines, float frametime, const Volume& frustum, const Vector2D& screenSize, const Matrix4x4& viewProj, IGPURenderPassRecorder* rendPassRecorder) +static void DrawLineArray(ArrayRef lines, const DbgDrawPass& pass) { if(!lines.numElem()) return; RenderDrawCmd drawCmd; - drawCmd.SetMaterial(g_matSystem->GetDefaultMaterial()); + drawCmd.SetMaterial(pass.material); - MatSysDefaultRenderPass defaultRenderPass; - defaultRenderPass.blendMode = SHADER_BLEND_TRANSLUCENT; - defaultRenderPass.depthTest = true; - defaultRenderPass.depthWrite = false; + MatSysDefaultRenderPass defaultRenderPass = DbgRenderPassData(pass); CMeshBuilder meshBuilder(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); meshBuilder.Begin(PRIM_LINES); for(DDLine& line : lines) { - line.lifetime -= frametime; + line.lifetime -= pass.frameTime; if (line.width > THICK_LINE_MIN_WIDTH) continue; - if (!frustum.IsBoxInside(line.start, line.end)) + if (!pass.frustum.IsBoxInside(line.start, line.end)) continue; - meshBuilder.Color4(line.color1); - meshBuilder.Position3fv(line.start); - - meshBuilder.AdvanceVertex(); - - meshBuilder.Color4(line.color2); - meshBuilder.Position3fv(line.end); + if (!DbgSetupEffect(meshBuilder, pass, line.effect)) + continue; - meshBuilder.AdvanceVertex(); + DrawThinLine(meshBuilder, line); } if(meshBuilder.End(drawCmd)) - g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(pass.recorder, &defaultRenderPass)); // thick lines are drawn as screen-facing quads meshBuilder.Init(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); meshBuilder.Begin(PRIM_TRIANGLES); - const Matrix4x4 invViewProj = inverse(viewProj); - int thickLinesDrawn = 0; for (DDLine& line : lines) { if (line.width <= THICK_LINE_MIN_WIDTH) continue; - if (!frustum.IsBoxInside(line.start, line.end)) + if (!pass.frustum.IsBoxInside(line.start, line.end)) continue; if (thickLinesDrawn > 0 && (thickLinesDrawn % THICK_LINES_DRAW_SUBDIV) == 0) { if (meshBuilder.End(drawCmd)) - g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(pass.recorder, &defaultRenderPass)); // start with new mesh meshBuilder.Init(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); meshBuilder.Begin(PRIM_TRIANGLES); } - if (DrawThickLine(meshBuilder, line, viewProj, invViewProj, screenSize)) - ++thickLinesDrawn; + if (!DbgSetupEffect(meshBuilder, pass, line.effect)) + continue; + + DrawThickLine(meshBuilder, line); + ++thickLinesDrawn; } if (meshBuilder.End(drawCmd)) - g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(pass.recorder, &defaultRenderPass)); } static void DrawBoxWire(CMeshBuilder& meshBuilder, const Vector3D& position, const Vector3D& mins, const Vector3D& maxs, const MColor& color, const Quaternion& orientation) @@ -539,18 +525,15 @@ static void DrawBoxFilled(CMeshBuilder& meshBuilder, const Vector3D& position, c meshBuilder.AdvanceVertexIndex(firstVert + idx); } -static void DrawOrientedBoxArray(ArrayRef boxes, float frametime, const Volume& frustum, IGPURenderPassRecorder* rendPassRecorder) +static void DrawOrientedBoxArray(ArrayRef boxes, const DbgDrawPass& pass) { if (!boxes.numElem()) return; RenderDrawCmd drawCmd; - drawCmd.SetMaterial(g_matSystem->GetDefaultMaterial()); + drawCmd.SetMaterial(pass.material); - MatSysDefaultRenderPass defaultRenderPass; - defaultRenderPass.blendMode = SHADER_BLEND_TRANSLUCENT; - defaultRenderPass.depthTest = true; - defaultRenderPass.depthWrite = false; + MatSysDefaultRenderPass defaultRenderPass = DbgRenderPassData(pass); CMeshBuilder meshBuilder(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); { @@ -562,26 +545,29 @@ static void DrawOrientedBoxArray(ArrayRef boxes, float frametime, if (node.fill) continue; - node.lifetime -= frametime; + node.lifetime -= pass.frameTime; - if (!frustum.IsBoxInside(node.position + node.mins, node.position + node.maxs, 1.0f)) + if (!pass.frustum.IsBoxInside(node.position + node.mins, node.position + node.maxs, 1.0f)) continue; if (i > 0 && (i % BOXES_DRAW_SUBDIV) == 0) { if (meshBuilder.End(drawCmd)) - g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(pass.recorder, &defaultRenderPass)); // start with new mesh meshBuilder.Init(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); meshBuilder.Begin(PRIM_LINES); } + if (!DbgSetupEffect(meshBuilder, pass, node.effect)) + continue; + DrawBoxWire(meshBuilder, node.position, node.mins, node.maxs, node.color, node.rotation); } if (meshBuilder.End(drawCmd)) - g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(pass.recorder, &defaultRenderPass)); } meshBuilder.Init(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); @@ -594,31 +580,31 @@ static void DrawOrientedBoxArray(ArrayRef boxes, float frametime, if (!node.fill) continue; - node.lifetime -= frametime; + node.lifetime -= pass.frameTime; - if (!frustum.IsBoxInside(node.position + node.mins, node.position + node.maxs, 1.0f)) + if (!pass.frustum.IsBoxInside(node.position + node.mins, node.position + node.maxs, 1.0f)) + continue; + + if (!DbgSetupEffect(meshBuilder, pass, node.effect, node.lit)) continue; DrawBoxFilled(meshBuilder, node.position, node.mins, node.maxs, node.color, node.rotation); } if (meshBuilder.End(drawCmd)) - g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(pass.recorder, &defaultRenderPass)); } } -static void DrawBoxArray(ArrayRef boxes, float frametime, const Volume& frustum, IGPURenderPassRecorder* rendPassRecorder) +static void DrawBoxArray(ArrayRef boxes, const DbgDrawPass& pass) { if(!boxes.numElem()) return; RenderDrawCmd drawCmd; - drawCmd.SetMaterial(g_matSystem->GetDefaultMaterial()); + drawCmd.SetMaterial(pass.material); - MatSysDefaultRenderPass defaultRenderPass; - defaultRenderPass.blendMode = SHADER_BLEND_TRANSLUCENT; - defaultRenderPass.depthTest = true; - defaultRenderPass.depthWrite = false; + MatSysDefaultRenderPass defaultRenderPass = DbgRenderPassData(pass); CMeshBuilder meshBuilder(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); { @@ -630,26 +616,29 @@ static void DrawBoxArray(ArrayRef boxes, float frametime, const Volume& f if (node.fill) continue; - node.lifetime -= frametime; + node.lifetime -= pass.frameTime; - if (!frustum.IsBoxInside(node.mins, node.maxs, 1.0f)) + if (!pass.frustum.IsBoxInside(node.mins, node.maxs, 1.0f)) continue; if (i > 0 && (i % BOXES_DRAW_SUBDIV) == 0) { if (meshBuilder.End(drawCmd)) - g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(pass.recorder, &defaultRenderPass)); // start with new mesh meshBuilder.Init(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); meshBuilder.Begin(PRIM_LINES); } + if (!DbgSetupEffect(meshBuilder, pass, node.effect)) + continue; + DrawBoxWire(meshBuilder, vec3_zero, node.mins, node.maxs, node.color, qidentity); } if (meshBuilder.End(drawCmd)) - g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(pass.recorder, &defaultRenderPass)); } meshBuilder.Init(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); @@ -662,20 +651,23 @@ static void DrawBoxArray(ArrayRef boxes, float frametime, const Volume& f if (!node.fill) continue; - node.lifetime -= frametime; + node.lifetime -= pass.frameTime; - if (!frustum.IsBoxInside(node.mins, node.maxs, 1.0f)) + if (!pass.frustum.IsBoxInside(node.mins, node.maxs, 1.0f)) + continue; + + if (!DbgSetupEffect(meshBuilder, pass, node.effect, node.lit)) continue; DrawBoxFilled(meshBuilder, vec3_zero, node.mins, node.maxs, node.color, qidentity); } if (meshBuilder.End(drawCmd)) - g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(pass.recorder, &defaultRenderPass)); } } -static void DrawCylinder(CMeshBuilder& meshBuilder, DDCylinder& cylinder, float frametime) +static void DrawCylinder(CMeshBuilder& meshBuilder, DDCylinder& cylinder) { static const int NUM_SEG = 8; static float dir[NUM_SEG * 2]; @@ -721,7 +713,7 @@ static void DrawCylinder(CMeshBuilder& meshBuilder, DDCylinder& cylinder, float } } -static void DrawCylinderArray(ArrayRef cylArray, float frametime, const Volume& frustum, IGPURenderPassRecorder* rendPassRecorder) +static void DrawCylinderArray(ArrayRef cylArray, const DbgDrawPass& pass) { if (!cylArray.numElem()) return; @@ -729,38 +721,38 @@ static void DrawCylinderArray(ArrayRef cylArray, float frametime, co CMeshBuilder meshBuilder(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); RenderDrawCmd drawCmd; - drawCmd.SetMaterial(g_matSystem->GetDefaultMaterial()); + drawCmd.SetMaterial(pass.material); - MatSysDefaultRenderPass defaultRenderPass; - defaultRenderPass.blendMode = SHADER_BLEND_TRANSLUCENT; - defaultRenderPass.depthTest = true; - defaultRenderPass.depthWrite = false; + MatSysDefaultRenderPass defaultRenderPass = DbgRenderPassData(pass); meshBuilder.Begin(PRIM_LINES); for (int i = 0; i < cylArray.numElem(); ++i) { DDCylinder& node = cylArray[i]; - node.lifetime -= frametime; + node.lifetime -= pass.frameTime; - if (!frustum.IsSphereInside(node.origin, max(node.radius, node.height))) + if (!pass.frustum.IsSphereInside(node.origin, max(node.radius, node.height))) continue; if (i > 0 && (i % BOXES_DRAW_SUBDIV) == 0) { if (meshBuilder.End(drawCmd)) - g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(pass.recorder, &defaultRenderPass)); // start with new mesh meshBuilder.Init(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); meshBuilder.Begin(PRIM_LINES); } - DrawCylinder(meshBuilder, cylArray[i], frametime); + if (!DbgSetupEffect(meshBuilder, pass, node.effect)) + continue; + + DrawCylinder(meshBuilder, node); } if (meshBuilder.End(drawCmd)) - g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(rendPassRecorder, &defaultRenderPass)); + g_matSystem->SetupDrawCommand(drawCmd, RenderPassContext(pass.recorder, &defaultRenderPass)); } static void DrawGraph(DDGraphBucket* graph, int position, IEqFont* pFont, float frame_time, IGPURenderPassRecorder* rendPassRecorder) @@ -852,21 +844,17 @@ static void DrawGraph(DDGraphBucket* graph, int position, IEqFont* pFont, float } -static void DrawPolygons(ArrayRef polygons, float frameTime, IGPURenderPassRecorder* rendPassRecorder) +static void DrawPolygons(ArrayRef polygons, const DbgDrawPass& pass) { if(!polygons.numElem()) return; RenderDrawCmd drawCmd; - drawCmd.SetMaterial(g_matSystem->GetDefaultMaterial()); + drawCmd.SetMaterial(pass.material); - MatSysDefaultRenderPass defaultRenderPass; - defaultRenderPass.blendMode = SHADER_BLEND_TRANSLUCENT; - defaultRenderPass.cullMode = CULL_BACK; - defaultRenderPass.depthTest = true; - defaultRenderPass.depthWrite = false; + MatSysDefaultRenderPass defaultRenderPass = DbgRenderPassData(pass, CULL_BACK); - RenderPassContext defaultPassContext(rendPassRecorder, &defaultRenderPass); + RenderPassContext defaultPassContext(pass.recorder, &defaultRenderPass); CMeshBuilder meshBuilder(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); meshBuilder.Begin(PRIM_TRIANGLES); @@ -876,7 +864,7 @@ static void DrawPolygons(ArrayRef polygons, float frameTime, IGPURenderP DDPoly& node = polygons[i]; if (!node.fill) continue; - node.lifetime -= frameTime; + node.lifetime -= pass.frameTime; if (i > 0 && (i % POLYS_DRAW_SUBDIV) == 0) { @@ -888,6 +876,9 @@ static void DrawPolygons(ArrayRef polygons, float frameTime, IGPURenderP meshBuilder.Begin(PRIM_TRIANGLES); } + if (!DbgSetupEffect(meshBuilder, pass, node.effect, node.lit)) + continue; + meshBuilder.Color4(node.color); for(int j = 0; j < node.verts.numElem()-2; ++j) @@ -903,7 +894,7 @@ static void DrawPolygons(ArrayRef polygons, float frameTime, IGPURenderP DDPoly& node = polygons[i]; if (!node.outline) continue; - node.lifetime -= frameTime; + node.lifetime -= pass.frameTime; if (i > 0 && (i % LINES_DRAW_SUBDIV) == 0) { @@ -915,6 +906,9 @@ static void DrawPolygons(ArrayRef polygons, float frameTime, IGPURenderP meshBuilder.Begin(PRIM_LINES); } + if (!DbgSetupEffect(meshBuilder, pass, node.effect)) + continue; + meshBuilder.Color4(node.color); for (int j = 0; j < node.verts.numElem(); ++j) @@ -1214,20 +1208,17 @@ static void DrawSphereFilled(CMeshBuilder& meshBuilder, DDSphere& sphere, int si } } -static void DrawSphereArray(ArrayRef spheres, float frameTime, const Volume& frustum, IGPURenderPassRecorder* rendPassRecorder) +static void DrawSphereArray(ArrayRef spheres, const DbgDrawPass& pass) { if(!spheres.numElem()) return; RenderDrawCmd drawCmd; - drawCmd.SetMaterial(g_matSystem->GetDefaultMaterial()); + drawCmd.SetMaterial(pass.material); - MatSysDefaultRenderPass defaultRenderPass; - defaultRenderPass.blendMode = SHADER_BLEND_TRANSLUCENT; - defaultRenderPass.depthTest = true; - defaultRenderPass.depthWrite = false; + MatSysDefaultRenderPass defaultRenderPass = DbgRenderPassData(pass); - RenderPassContext defaultPassContext(rendPassRecorder, &defaultRenderPass); + RenderPassContext defaultPassContext(pass.recorder, &defaultRenderPass); CMeshBuilder meshBuilder(g_matSystem->GetDynamicMesh(DRAW_MAX_VERTS)); meshBuilder.Begin(PRIM_LINES); @@ -1238,12 +1229,15 @@ static void DrawSphereArray(ArrayRef spheres, float frameTime, const V if (sphere.fill) continue; - sphere.lifetime -= frameTime; + sphere.lifetime -= pass.frameTime; + + if (!pass.frustum.IsSphereInside(sphere.origin, sphere.radius)) + continue; - if (!frustum.IsSphereInside(sphere.origin, sphere.radius)) + if (!DbgSetupEffect(meshBuilder, pass, sphere.effect)) continue; - DrawSphereWireframe(meshBuilder, spheres[i], 20); + DrawSphereWireframe(meshBuilder, sphere, 20); } if (meshBuilder.End(drawCmd)) @@ -1258,12 +1252,15 @@ static void DrawSphereArray(ArrayRef spheres, float frameTime, const V if (!sphere.fill) continue; - sphere.lifetime -= frameTime; + sphere.lifetime -= pass.frameTime; + + if (!pass.frustum.IsSphereInside(sphere.origin, sphere.radius)) + continue; - if (!frustum.IsSphereInside(sphere.origin, sphere.radius)) + if (!DbgSetupEffect(meshBuilder, pass, sphere.effect, sphere.lit)) continue; - DrawSphereFilled(meshBuilder, spheres[i], 20); + DrawSphereFilled(meshBuilder, sphere, 20); } if (meshBuilder.End(drawCmd)) @@ -1329,39 +1326,34 @@ void CDebugOverlay::Draw(int winWide, int winTall, float timescale, ITexture* co g_matSystem->SetMatrix(MATRIXMODE_WORLD, identity4); // draw all of 3d stuff - { - Threading::CScopedMutex m(s_debugOverlayMutex); - DrawBoxArray(m_BoxList, m_frameTime, m_frustum, rendPassRecorder); - } - - { - Threading::CScopedMutex m(s_debugOverlayMutex); - DrawCylinderArray(m_CylinderList, m_frameTime, m_frustum, rendPassRecorder); - } - - { - Threading::CScopedMutex m(s_debugOverlayMutex); - DrawOrientedBoxArray(m_OrientedBoxList, m_frameTime, m_frustum, rendPassRecorder); - } - { Threading::CScopedMutex m(s_debugOverlayMutex); DrawVolumes(m_volumes, m_frameTime, rendPassRecorder); } + if (!m_debugMaterial) { - Threading::CScopedMutex m(s_debugOverlayMutex); - DrawSphereArray(m_SphereList, m_frameTime, m_frustum, rendPassRecorder); + KVSection debugParams; + debugParams.SetName("DebugDraw"); + m_debugMaterial = g_matSystem->CreateMaterial("_debugDraw", &debugParams); + m_debugMaterial->LoadShaderAndTextures(); } - { - Threading::CScopedMutex m(s_debugOverlayMutex); - DrawLineArray(m_LineList, m_frameTime, m_frustum, Vector2D(winWide, winTall), m_projMat * m_viewMat, rendPassRecorder); - } + DbgDrawPass pass{ rendPassRecorder.Ptr(), m_debugMaterial.Ptr(), m_frustum, m_frameTime, false }; + // the visible parts, then the occluded parts of the primitives that have them + for (int i = 0; i < 2; ++i) { Threading::CScopedMutex m(s_debugOverlayMutex); - DrawPolygons(m_polygons, m_frameTime, rendPassRecorder); + DrawBoxArray(m_BoxList, pass); + DrawCylinderArray(m_CylinderList, pass); + DrawOrientedBoxArray(m_OrientedBoxList, pass); + DrawSphereArray(m_SphereList, pass); + DrawLineArray(m_LineList, pass); + DrawPolygons(m_polygons, pass); + + pass.frameTime = 0.0f; + pass.occluded = true; } // now rendering 2D stuff diff --git a/shared/render/DebugOverlay.h b/shared/render/DebugOverlay.h index 12c2a8527..0e70d7302 100644 --- a/shared/render/DebugOverlay.h +++ b/shared/render/DebugOverlay.h @@ -10,6 +10,8 @@ class ITexture; using ITexturePtr = CRefPtr; +class IMaterial; +using IMaterialPtr = CRefPtr; struct DebugTextNode_t { @@ -87,6 +89,7 @@ class CDebugOverlay : public IDebugOverlay Map m_newNames{ PP_SL }; ITexturePtr m_dbgTexture; + IMaterialPtr m_debugMaterial; // DebugDraw shader of the 3D primitives CEqTimer m_timer; IEqFont* m_debugFont{ nullptr }; diff --git a/shared/sys/scripting/sys_esl_engine.cpp b/shared/sys/scripting/sys_esl_engine.cpp index deb1401f2..19dd09a7f 100644 --- a/shared/sys/scripting/sys_esl_engine.cpp +++ b/shared/sys/scripting/sys_esl_engine.cpp @@ -79,6 +79,27 @@ static T& S_DDNode_Time(const esl::ScriptState& state, T& builder, float time) return static_cast(builder.Time(time)); } +// the pattern is a DBG_PATTERN_* value +template +static T& S_DDShape_Pattern(const esl::ScriptState& state, T& builder, int pattern, float sizePx) +{ + return builder.Pattern(static_cast(pattern), sizePx); +} + +template +static T& S_DDShape_GapAlpha(const esl::ScriptState& state, T& builder, float alpha) +{ + return builder.GapAlpha(alpha); +} + +template +static T& S_DDShape_Occluded(const esl::ScriptState& state, T& builder, int pattern) +{ + return builder.Occluded(static_cast(pattern)); +} + +#define EQSCRIPT_BIND_DDSHAPE_FUNCS(type) EQSCRIPT_BIND_STATIC_FUNC("Pattern", S_DDShape_Pattern) EQSCRIPT_BIND_STATIC_FUNC("GapAlpha", S_DDShape_GapAlpha) EQSCRIPT_BIND_STATIC_FUNC("Occluded", S_DDShape_Occluded) + EQSCRIPT_TYPE_BEGIN( IDebugOverlay ) EQSCRIPT_BIND_STATIC_FUNC("Text", S_IDebugOverlay_Text) EQSCRIPT_BIND_STATIC_FUNC("TextFadeOut", S_IDebugOverlay_TextFadeOut) @@ -107,8 +128,10 @@ EQSCRIPT_TYPE_BEGIN(DDBox) EQSCRIPT_BIND_FUNC(Maxs) EQSCRIPT_BIND_FUNC(Color) EQSCRIPT_BIND_FUNC(Fill) + EQSCRIPT_BIND_FUNC(Lit) EQSCRIPT_BIND_STATIC_FUNC("Time", S_DDNode_Time) EQSCRIPT_BIND_STATIC_FUNC("Name", S_DDNode_Name) + EQSCRIPT_BIND_DDSHAPE_FUNCS(DDBox) EQSCRIPT_TYPE_END static DDBox* S_DbgBox() { return PPNew DDBox(PP_SL); } @@ -122,8 +145,10 @@ EQSCRIPT_TYPE_BEGIN(DDOrientedBox) EQSCRIPT_BIND_FUNC(Rotation) EQSCRIPT_BIND_FUNC(Color) EQSCRIPT_BIND_FUNC(Fill) + EQSCRIPT_BIND_FUNC(Lit) EQSCRIPT_BIND_STATIC_FUNC("Time", S_DDNode_Time) EQSCRIPT_BIND_STATIC_FUNC("Name", S_DDNode_Name) + EQSCRIPT_BIND_DDSHAPE_FUNCS(DDOrientedBox) EQSCRIPT_TYPE_END static DDOrientedBox* S_DbgOriBox() { return PPNew DDOrientedBox(PP_SL); } @@ -135,8 +160,10 @@ EQSCRIPT_TYPE_BEGIN(DDSphere) EQSCRIPT_BIND_FUNC(Radius) EQSCRIPT_BIND_FUNC(Color) EQSCRIPT_BIND_FUNC(Fill) + EQSCRIPT_BIND_FUNC(Lit) EQSCRIPT_BIND_STATIC_FUNC("Time", S_DDNode_Time) EQSCRIPT_BIND_STATIC_FUNC("Name", S_DDNode_Name) + EQSCRIPT_BIND_DDSHAPE_FUNCS(DDSphere) EQSCRIPT_TYPE_END static DDSphere* S_DbgSphere() { return PPNew DDSphere(PP_SL); } @@ -150,6 +177,7 @@ EQSCRIPT_TYPE_BEGIN(DDCylinder) EQSCRIPT_BIND_FUNC(Color) EQSCRIPT_BIND_STATIC_FUNC("Time", S_DDNode_Time) EQSCRIPT_BIND_STATIC_FUNC("Name", S_DDNode_Name) + EQSCRIPT_BIND_DDSHAPE_FUNCS(DDCylinder) EQSCRIPT_TYPE_END static DDCylinder* S_DbgCylinder() { return PPNew DDCylinder(PP_SL); } @@ -163,8 +191,10 @@ EQSCRIPT_TYPE_BEGIN(DDLine) EQSCRIPT_BIND_FUNC(ColorStart) EQSCRIPT_BIND_FUNC(ColorEnd) EQSCRIPT_BIND_FUNC(Width) + EQSCRIPT_BIND_FUNC(Dash) EQSCRIPT_BIND_STATIC_FUNC("Time", S_DDNode_Time) EQSCRIPT_BIND_STATIC_FUNC("Name", S_DDNode_Name) + EQSCRIPT_BIND_DDSHAPE_FUNCS(DDLine) EQSCRIPT_TYPE_END static DDLine* S_DbgLine() { return PPNew DDLine(PP_SL); } @@ -176,8 +206,10 @@ EQSCRIPT_TYPE_BEGIN(DDPoly) EQSCRIPT_BIND_FUNC(Color) EQSCRIPT_BIND_FUNC(Fill) EQSCRIPT_BIND_FUNC(Outline) + EQSCRIPT_BIND_FUNC(Lit) EQSCRIPT_BIND_STATIC_FUNC("Time", S_DDNode_Time) EQSCRIPT_BIND_STATIC_FUNC("Name", S_DDNode_Name) + EQSCRIPT_BIND_DDSHAPE_FUNCS(DDPoly) EQSCRIPT_TYPE_END static DDPoly* S_DbgPoly() { return PPNew DDPoly(PP_SL); } @@ -770,6 +802,11 @@ bool eslSysDebugDrawingInit(const esl::ScriptState& state) state.SetGlobal("DbgLine", EQSCRIPT_CFUNC(S_DbgLine, esl::ToLua, void)); state.SetGlobal("DbgPoly", EQSCRIPT_CFUNC(S_DbgPoly, esl::ToLua, void)); + state.SetGlobal("DBG_PATTERN_NONE", static_cast(DBG_PATTERN_NONE)); + state.SetGlobal("DBG_PATTERN_CHECKER", static_cast(DBG_PATTERN_CHECKER)); + state.SetGlobal("DBG_PATTERN_HATCH", static_cast(DBG_PATTERN_HATCH)); + state.SetGlobal("DBG_PATTERN_DOTS", static_cast(DBG_PATTERN_DOTS)); + #ifdef IMGUI_ENABLED imGuilState = state; LoadImguiBindings();