From ad6028e0bd1d126238eca4572c2a8c2619934984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Tue, 1 Jun 2021 16:38:52 +0200 Subject: [PATCH] Fix last commit --- examples/DeferredShading/main.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/examples/DeferredShading/main.cpp b/examples/DeferredShading/main.cpp index 97d5bae89..4f4f6af90 100644 --- a/examples/DeferredShading/main.cpp +++ b/examples/DeferredShading/main.cpp @@ -499,6 +499,8 @@ int main() } }); + bool forwardEnabled = true; + bool lightAnimation = true; Nz::BakedFrameGraph bakedGraph = [&] { @@ -624,6 +626,9 @@ int main() builder.DrawIndexed(static_cast(cubeMeshGfx->GetIndexCount(0))); }); + forwardPass.SetExecutionCallback([&] + { + return (forwardEnabled) ? Nz::FramePassExecution::Execute : Nz::FramePassExecution::Skip; }); forwardPass.AddInput(backbuffer); @@ -746,7 +751,7 @@ int main() while (window.IsOpen()) { Nz::UInt64 now = Nz::GetElapsedMicroseconds(); - elapsedTime += (now - time) / 1'000'000.f; + if (lightAnimation) elapsedTime += (now - time) / 1'000'000.f; time = now; @@ -785,9 +790,12 @@ int main() whiteLight.position = viewerPos; whiteLight.direction = camQuat * Nz::Vector3f::Forward(); - viewerUboUpdate = true; + lightUpdate = true; } else if (event.key.virtualKey == Nz::Keyboard::VKey::F) + forwardEnabled = !forwardEnabled; + else if (event.key.virtualKey == Nz::Keyboard::VKey::A) + lightAnimation = !lightAnimation; break; } @@ -842,7 +850,7 @@ int main() if (frame.IsFramebufferInvalidated()) RebuildCommandBuffer(); - //if (viewerUboUpdate) + if (viewerUboUpdate || lightAnimation || lightUpdate) { Nz::AccessByOffset(viewerDataBuffer.data(), viewerUboOffsets.viewMatrixOffset) = Nz::Matrix4f::ViewMatrix(viewerPos, camAngles); @@ -856,11 +864,14 @@ int main() { builder.PreTransferBarrier(); - auto& viewerDataAllocation = uploadPool.Allocate(viewerDataBuffer.size()); - std::memcpy(viewerDataAllocation.mappedPtr, viewerDataBuffer.data(), viewerDataBuffer.size()); - builder.CopyBuffer(viewerDataAllocation, viewerDataUBO.get()); + if (viewerUboUpdate) + { + auto& viewerDataAllocation = uploadPool.Allocate(viewerDataBuffer.size()); + std::memcpy(viewerDataAllocation.mappedPtr, viewerDataBuffer.data(), viewerDataBuffer.size()); + builder.CopyBuffer(viewerDataAllocation, viewerDataUBO.get()); + } - if (!spotLights.empty()) + if (!spotLights.empty() && (lightUpdate || lightAnimation)) { auto& lightDataAllocation = uploadPool.Allocate(alignedSpotLightSize * spotLights.size()); Nz::UInt8* lightDataPtr = static_cast(lightDataAllocation.mappedPtr); @@ -888,6 +899,8 @@ int main() } builder.CopyBuffer(lightDataAllocation, lightUbo.get()); + + lightUpdate = false; } spaceshipMat->UpdateBuffers(uploadPool, builder);