diff --git a/src/pt/hybrid_renderer.cpp b/src/pt/hybrid_renderer.cpp index daae70c..5458bf8 100644 --- a/src/pt/hybrid_renderer.cpp +++ b/src/pt/hybrid_renderer.cpp @@ -205,6 +205,41 @@ void HybridRenderer::render( wgpuQueueSubmit(gpuContext.queue, 1, &cmdBuffer); } +void HybridRenderer::renderDebug( + const GpuContext& gpuContext, + const glm::mat4& viewProjectionMat, + const WGPUTextureView textureView) +{ + wgpuDeviceTick(gpuContext.device); + + const WGPUCommandEncoder encoder = [&gpuContext]() { + const WGPUCommandEncoderDescriptor cmdEncoderDesc{ + .nextInChain = nullptr, + .label = "Command encoder", + }; + return wgpuDeviceCreateCommandEncoder(gpuContext.device, &cmdEncoderDesc); + }(); + + mGbufferPass.render( + gpuContext, + viewProjectionMat, + encoder, + mDepthTextureView, + mAlbedoTextureView, + mNormalTextureView); + + mDebugPass.render(mGbufferBindGroup, encoder, textureView); + + const WGPUCommandBuffer cmdBuffer = [encoder]() { + const WGPUCommandBufferDescriptor cmdBufferDesc{ + .nextInChain = nullptr, + .label = "HybridRenderer command buffer", + }; + return wgpuCommandEncoderFinish(encoder, &cmdBufferDesc); + }(); + wgpuQueueSubmit(gpuContext.queue, 1, &cmdBuffer); +} + void HybridRenderer::resize(const GpuContext& gpuContext, const Extent2u& newSize) { NLRS_ASSERT(newSize.x > 0 && newSize.y > 0); diff --git a/src/pt/hybrid_renderer.hpp b/src/pt/hybrid_renderer.hpp index 92fc2b8..2d5811a 100644 --- a/src/pt/hybrid_renderer.hpp +++ b/src/pt/hybrid_renderer.hpp @@ -50,6 +50,7 @@ class HybridRenderer const glm::vec3& cameraPosition, const Sky& sky, WGPUTextureView targetTextureView); + void renderDebug(const GpuContext&, const glm::mat4&, WGPUTextureView); void resize(const GpuContext&, const Extent2u&); private: diff --git a/src/pt/main.cpp b/src/pt/main.cpp index 4623f17..1e04536 100644 --- a/src/pt/main.cpp +++ b/src/pt/main.cpp @@ -41,6 +41,7 @@ enum RendererType { RendererType_PathTracer, RendererType_Hybrid, + RendererType_Debug, }; struct UiState @@ -313,6 +314,8 @@ try ImGui::RadioButton("path tracer", &appState.ui.rendererType, RendererType_PathTracer); ImGui::SameLine(); ImGui::RadioButton("hybrid", &appState.ui.rendererType, RendererType_Hybrid); + ImGui::SameLine(); + ImGui::RadioButton("debug", &appState.ui.rendererType, RendererType_Debug); ImGui::Separator(); ImGui::Text("Renderer stats"); @@ -439,6 +442,12 @@ try textureBlitter.textureView()); break; } + case RendererType_Debug: + { + const glm::mat4 viewProjectionMat = appState.cameraController.viewProjectionMatrix(); + hybridRenderer.renderDebug(gpuContext, viewProjectionMat, textureBlitter.textureView()); + break; + } } textureBlitter.render(gpuContext, gui, swapChain); };