diff --git a/shaders/ambient_occlusion/ground_truth/gtao.comp b/shaders/ambient_occlusion/ground_truth/gtao.comp deleted file mode 100644 index a7cc35fb..00000000 --- a/shaders/ambient_occlusion/ground_truth/gtao.comp +++ /dev/null @@ -1,92 +0,0 @@ -#version 460 - -void main() { - -} -// -//void XeGTAO_PrefilterDepths16x16( -//uvec2 dispatchThreadID, -//uvec2 groupThreadID, -//const GTAOConstants consts, -//sampler2D sourceNDCDepth, -//out writeonly image2D outDepth0, -//out writeonly image2D outDepth1, -//out writeonly image2D outDepth2, -//out writeonly image2D outDepth3, -//out writeonly image2D outDepth4 -//) { -// // MIP 0 -// const uvec2 baseCoord = dispatchThreadID; -// // 2x because ao image is downsampled -// const uvec2 pixCoord = baseCoord * 2u; -// -// -// // todo: get width and height from sceneData -// vec2 uvCoord = vec2(pixCoord) * consts.ViewportPixelSize; -// -// vec4 depths 4; -// depths4.w = texture(sourceNDCDepth, uvCoord + vec2(0.0, 0.0) * consts.ViewportPixelSize).r; -// depths4.z = texture(sourceNDCDepth, uvCoord + vec2(1.0, 0.0) * consts.ViewportPixelSize).r; -// depths4.x = texture(sourceNDCDepth, uvCoord + vec2(0.0, 1.0) * consts.ViewportPixelSize).r; -// depths4.y = texture(sourceNDCDepth, uvCoord + vec2(1.0, 1.0) * consts.ViewportPixelSize).r; -// -// float depth0 = XeGTAO_ClampDepth(XeGTAO_ScreenSpaceToViewSpaceDepth(depths4.w, consts)); -// float depth1 = XeGTAO_ClampDepth(XeGTAO_ScreenSpaceToViewSpaceDepth(depths4.z, consts)); -// float depth2 = XeGTAO_ClampDepth(XeGTAO_ScreenSpaceToViewSpaceDepth(depths4.x, consts)); -// float depth3 = XeGTAO_ClampDepth(XeGTAO_ScreenSpaceToViewSpaceDepth(depths4.y, consts)); -// -// imageStore(outDepth0, ivec2(pixCoord + uvec2(0, 0)), vec4(depth0, 0.0, 0.0, 0.0)); -// imageStore(outDepth0, ivec2(pixCoord + uvec2(1, 0)), vec4(depth1, 0.0, 0.0, 0.0)); -// imageStore(outDepth0, ivec2(pixCoord + uvec2(0, 1)), vec4(depth2, 0.0, 0.0, 0.0)); -// imageStore(outDepth0, ivec2(pixCoord + uvec2(1, 1)), vec4(depth3, 0.0, 0.0, 0.0)); -// -// // MIP 1 -// float dm1 = XeGTAO_DepthMIPFilter(depth0, depth1, depth2, depth3, consts); -// imageStore(outDepth1, ivec2(baseCoord), vec4(dm1, 0.0, 0.0, 0.0)); -// g_scratchDepths[groupThreadID.x][groupThreadID.y] = dm1; -// -// memoryBarrierShared(); -// barrier(); -// -// // MIP 2 -// if (all(equal(groupThreadID.xy % 2u, uvec2(0u, 0u)))) { -// float inTL = g_scratchDepths[groupThreadID.x+0u][groupThreadID.y+0u]; -// float inTR = g_scratchDepths[groupThreadID.x+1u][groupThreadID.y+0u]; -// float inBL = g_scratchDepths[groupThreadID.x+0u][groupThreadID.y+1u]; -// float inBR = g_scratchDepths[groupThreadID.x+1u][groupThreadID.y+1u]; -// -// float dm2 = XeGTAO_DepthMIPFilter(inTL, inTR, inBL, inBR, consts); -// imageStore(outDepth2, ivec2(baseCoord / 2u), vec4(dm2, 0.0, 0.0, 0.0)); -// g_scratchDepths[groupThreadID.x][groupThreadID.y] = dm2; -// } -// -// memoryBarrierShared(); -// barrier(); -// -// // MIP 3 -// if (all(equal(groupThreadID.xy % 4u, uvec2(0u, 0u)))) { -// float inTL = g_scratchDepths[groupThreadID.x+0u][groupThreadID.y+0u]; -// float inTR = g_scratchDepths[groupThreadID.x+2u][groupThreadID.y+0u]; -// float inBL = g_scratchDepths[groupThreadID.x+0u][groupThreadID.y+2u]; -// float inBR = g_scratchDepths[groupThreadID.x+2u][groupThreadID.y+2u]; -// -// float dm3 = XeGTAO_DepthMIPFilter(inTL, inTR, inBL, inBR, consts); -// imageStore(outDepth3, ivec2(baseCoord / 4u), vec4(dm3, 0.0, 0.0, 0.0)); -// g_scratchDepths[groupThreadID.x][groupThreadID.y] = dm3; -// } -// -// memoryBarrierShared(); -// barrier(); -// -// // MIP 4 -// if (all(equal(groupThreadID.xy % 8u, uvec2(0u, 0u)))) { -// float inTL = g_scratchDepths[groupThreadID.x+0u][groupThreadID.y+0u]; -// float inTR = g_scratchDepths[groupThreadID.x+4u][groupThreadID.y+0u]; -// float inBL = g_scratchDepths[groupThreadID.x+0u][groupThreadID.y+4u]; -// float inBR = g_scratchDepths[groupThreadID.x+4u][groupThreadID.y+4u]; -// -// float dm4 = XeGTAO_DepthMIPFilter(inTL, inTR, inBL, inBR, consts); -// imageStore(outDepth4, ivec2(baseCoord / 8u), vec4(dm4, 0.0, 0.0, 0.0)); -// // g_scratchDepths[groupThreadID.x][groupThreadID.y] = dm4; // commented out as in original -// } -//} \ No newline at end of file diff --git a/shaders/deferredMrt.frag b/shaders/deferredMrt.frag index 2fba856a..49bbdee8 100644 --- a/shaders/deferredMrt.frag +++ b/shaders/deferredMrt.frag @@ -17,8 +17,8 @@ layout (location = 6) in vec4 inPrevMvpPosition; layout (location = 0) out vec4 normalTarget;// 10,10,10, (2 unused) layout (location = 1) out vec4 albedoTarget;// 10,10,10, (2 -> 0 = environment Map, 1 = renderObject) -layout (location = 2) out vec4 pbrTarget;// 8 metallic, 8 roughness, 8 emissive (unused), 8 unused -layout (location = 3) out vec2 velocityTarget;// 16 X, 16 Y +layout (location = 2) out vec4 pbrTarget; // metal/roughness/unused/unused +layout (location = 3) out vec2 velocityTarget; // layout (std140, set = 0, binding = 0) uniform SceneData - scene.glsl diff --git a/shaders/deferredMrt.vert b/shaders/deferredMrt.vert index a12fd33f..102cc3fd 100644 --- a/shaders/deferredMrt.vert +++ b/shaders/deferredMrt.vert @@ -49,9 +49,6 @@ void main() { outUV = uv; outMaterialIndex = materialIndex; - //outCurrMvpPosition = sceneData.viewProj * worldPos; - //outPrevMvpPosition = sceneData.prevViewProj * models.previousModelMatrix * vec4(position, 1.0); - vec4 currClipPos = sceneData.viewProj * worldPos; vec4 prevClipPos = sceneData.prevViewProj * models.previousModelMatrix * vec4(position, 1.0); currClipPos.xy += currClipPos.w * sceneData.jitter.xy; diff --git a/shaders/postProcess.comp b/shaders/postProcess.comp index 54c68c98..ffd28788 100644 --- a/shaders/postProcess.comp +++ b/shaders/postProcess.comp @@ -1,9 +1,11 @@ #version 460 +#include "scene.glsl" + layout (local_size_x = 16, local_size_y = 16) in; -layout (set = 0, binding = 0) uniform sampler2D inputImage; -layout (rgba16f, set = 0, binding = 1) uniform image2D outputImage; +layout (set = 1, binding = 0) uniform sampler2D inputImage; +layout (rgba16f, set = 1, binding = 1) uniform image2D outputImage; layout (push_constant) uniform PushConstants { @@ -52,19 +54,16 @@ void main() { return; } - vec2 uv = (vec2(pixel.x, pixel.y) + 0.5) / vec2(push.width, push.height); - + vec2 uv = (vec2(pixel.x, pixel.y) + 0.5) / sceneData.renderTargetSize; // Flip final image (cause vulkan images starts from top-left) uv.y = 1 - uv.y; + // Unjitter + uv += sceneData.jitter.xy / 2.0f; + vec3 color = texture(inputImage, uv).rgb; vec2 texelSize = 1.0 / vec2(push.width, push.height); - if (push.flags == 0) { - imageStore(outputImage, pixel, vec4(color, 1.0)); - return; - } - if ((push.flags & 2) != 0) { color = sharpen(color, texelSize, uv); } diff --git a/src/core/engine.cpp b/src/core/engine.cpp index 65288151..dc710e5c 100644 --- a/src/core/engine.cpp +++ b/src/core/engine.cpp @@ -10,10 +10,8 @@ #include #include -#include #include "identifier/identifier_manager.h" -#include "src/physics/physics_filters.h" #include "camera/free_camera.h" #include "game_object/game_object.h" @@ -103,7 +101,8 @@ void Engine::init() createDrawResources(); // Command Pools - const VkCommandPoolCreateInfo commandPoolInfo = vk_helpers::commandPoolCreateInfo(context->graphicsQueueFamily, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); + const VkCommandPoolCreateInfo commandPoolInfo = vk_helpers::commandPoolCreateInfo(context->graphicsQueueFamily, + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); for (auto& frame : frames) { VK_CHECK(vkCreateCommandPool(context->device, &commandPoolInfo, nullptr, &frame._commandPool)); VkCommandBufferAllocateInfo cmdAllocInfo = vk_helpers::commandBufferAllocateInfo(frame._commandPool); @@ -202,13 +201,14 @@ void Engine::initRenderer() deferredMrtPipeline = new deferred_mrt::DeferredMrtPipeline(*resourceManager); ambientOcclusionPipeline = new ambient_occlusion::GroundTruthAmbientOcclusionPipeline(*resourceManager); deferredResolvePipeline = new deferred_resolve::DeferredResolvePipeline(*resourceManager, environmentMap->getDiffSpecMapDescriptorSetlayout(), - cascadedShadowMap->getCascadedShadowMapUniformLayout(), cascadedShadowMap->getCascadedShadowMapSamplerLayout()); + cascadedShadowMap->getCascadedShadowMapUniformLayout(), + cascadedShadowMap->getCascadedShadowMapSamplerLayout()); temporalAntialiasingPipeline = new temporal_antialiasing_pipeline::TemporalAntialiasingPipeline(*resourceManager); postProcessPipeline = new post_process_pipeline::PostProcessPipeline(*resourceManager); ambientOcclusionPipeline->setupDepthPrefilterDescriptorBuffer(depthImage.imageView); ambientOcclusionPipeline->setupAmbientOcclusionDescriptorBuffer(normalRenderTarget.imageView); - ambientOcclusionPipeline->setupSpatialFilteringDescriptorBuffer(depthImage.imageView, normalRenderTarget.imageView); + ambientOcclusionPipeline->setupSpatialFilteringDescriptorBuffer(); const deferred_resolve::DeferredResolveDescriptor deferredResolveDescriptor{ normalRenderTarget.imageView, @@ -298,7 +298,7 @@ void Engine::run() profiler.beginTimer("3Total"); profiler.beginTimer("0Physics"); - physics::Physics::get()->update(deltaTime); + updatePhysics(deltaTime); profiler.endTimer("0Physics"); profiler.beginTimer("1Game"); @@ -310,6 +310,15 @@ void Engine::run() } } +void Engine::updatePhysics(const float deltaTime) const +{ + if (bPausePhysics) { + return; + } + + physics::Physics::get()->update(deltaTime); +} + void Engine::updateGame(const float deltaTime) { if (camera) { camera->update(deltaTime); } @@ -352,7 +361,7 @@ void Engine::updateGame(const float deltaTime) hierarchicalDeletionQueue.clear(); } -void Engine::updateRender(const float deltaTime, const int32_t currentFrameOverlap, const int32_t previousFrameOverlap) const +void Engine::updateRender(VkCommandBuffer cmd, const float deltaTime, const int32_t currentFrameOverlap, const int32_t previousFrameOverlap) const { const AllocatedBuffer& previousSceneDataBuffer = sceneDataBuffers[previousFrameOverlap]; const AllocatedBuffer& sceneDataBuffer = sceneDataBuffers[currentFrameOverlap]; @@ -366,6 +375,10 @@ void Engine::updateRender(const float deltaTime, const int32_t currentFrameOverl glm::vec2 currentJitter = HaltonSequence::getJitterHardcoded(frameNumber) * 2.0f - 1.0f; currentJitter.x /= RENDER_EXTENT_WIDTH; currentJitter.y /= RENDER_EXTENT_HEIGHT; + if (bDisableJitter) { + prevJitter = {}; + currentJitter = {}; + } pSceneData->jitter = bEnableTaa ? glm::vec4(currentJitter.x, currentJitter.y, prevJitter.x, prevJitter.y) : glm::vec4(0.0f); @@ -421,6 +434,11 @@ void Engine::updateRender(const float deltaTime, const int32_t currentFrameOverl pDebugSceneData->renderTargetSize = {RENDER_EXTENT_WIDTH, RENDER_EXTENT_HEIGHT}; pDebugSceneData->texelSize = {1.0f / RENDER_EXTENT_WIDTH, 1.0f / RENDER_EXTENT_HEIGHT}; pDebugSceneData->deltaTime = deltaTime; + + vk_helpers::synchronizeUniform(cmd, sceneDataBuffer, VK_PIPELINE_STAGE_2_HOST_BIT, VK_ACCESS_2_HOST_WRITE_BIT, + VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT, VK_ACCESS_2_UNIFORM_READ_BIT); + vk_helpers::synchronizeUniform(cmd, debugSceneDataBuffer, VK_PIPELINE_STAGE_2_HOST_BIT, VK_ACCESS_2_HOST_WRITE_BIT, + VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT, VK_ACCESS_2_UNIFORM_READ_BIT); } void Engine::draw(float deltaTime) @@ -462,7 +480,7 @@ void Engine::draw(float deltaTime) } // Updates Scene Data buffer - updateRender(deltaTime, currentFrameOverlap, previousFrameOverlap); + updateRender(cmd, deltaTime, currentFrameOverlap, previousFrameOverlap); // Updates Cascaded Shadow Map Properties cascadedShadowMap->update(mainLight, camera, currentFrameOverlap); @@ -481,11 +499,16 @@ void Engine::draw(float deltaTime) vk_helpers::clearColorImage(cmd, drawImage.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); - vk_helpers::transitionImage(cmd, depthImage.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL, VK_IMAGE_ASPECT_DEPTH_BIT); - vk_helpers::transitionImage(cmd, normalRenderTarget.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); - vk_helpers::transitionImage(cmd, albedoRenderTarget.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); - vk_helpers::transitionImage(cmd, pbrRenderTarget.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); - vk_helpers::transitionImage(cmd, velocityRenderTarget.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, depthImage.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL, + VK_IMAGE_ASPECT_DEPTH_BIT); + vk_helpers::transitionImage(cmd, normalRenderTarget.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, albedoRenderTarget.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, pbrRenderTarget.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, velocityRenderTarget.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); environment_pipeline::EnvironmentDrawInfo environmentPipelineDrawInfo{ true, @@ -560,11 +583,16 @@ void Engine::draw(float deltaTime) deferredMrtPipeline->draw(cmd, debugDeferredMrtDrawInfo); } - vk_helpers::transitionImage(cmd, normalRenderTarget.image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); - vk_helpers::transitionImage(cmd, albedoRenderTarget.image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); - vk_helpers::transitionImage(cmd, pbrRenderTarget.image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); - vk_helpers::transitionImage(cmd, velocityRenderTarget.image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); - vk_helpers::transitionImage(cmd, depthImage.image, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_ASPECT_DEPTH_BIT); + vk_helpers::transitionImage(cmd, normalRenderTarget.image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, albedoRenderTarget.image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, pbrRenderTarget.image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, velocityRenderTarget.image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, depthImage.image, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_IMAGE_ASPECT_DEPTH_BIT); vk_helpers::transitionImage(cmd, drawImage.image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_ASPECT_COLOR_BIT); ambient_occlusion::GTAOPushConstants gtaoPush{}; @@ -606,23 +634,38 @@ void Engine::draw(float deltaTime) }; temporalAntialiasingPipeline->draw(cmd, taaDrawInfo); - vk_helpers::transitionImage(cmd, taaResolveTarget.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); - vk_helpers::transitionImage(cmd, historyBuffer.image, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, taaResolveTarget.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, historyBuffer.image, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); vk_helpers::copyImageToImage(cmd, taaResolveTarget.image, historyBuffer.image, RENDER_EXTENTS, RENDER_EXTENTS); - vk_helpers::transitionImage(cmd, taaResolveTarget.image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, taaResolveTarget.image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); vk_helpers::transitionImage(cmd, postProcessOutputBuffer.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_ASPECT_COLOR_BIT); - postProcessPipeline->draw(cmd, post_process::PostProcessType::Sharpening); - vk_helpers::transitionImage(cmd, postProcessOutputBuffer.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); - vk_helpers::transitionImage(cmd, swapchainImages[swapchainImageIndex], VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); + + const post_process_pipeline::PostProcessDrawInfo postProcessDrawInfo{ + postProcessData, + sceneDataDescriptorBuffer.getDescriptorBufferBindingInfo(), + sceneDataDescriptorBuffer.getDescriptorBufferSize() * currentFrameOverlap + }; + + postProcessPipeline->draw(cmd, postProcessDrawInfo); + + vk_helpers::transitionImage(cmd, postProcessOutputBuffer.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, swapchainImages[swapchainImageIndex], VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_IMAGE_ASPECT_COLOR_BIT); vk_helpers::copyImageToImage(cmd, postProcessOutputBuffer.image, swapchainImages[swapchainImageIndex], RENDER_EXTENTS, swapchainExtent); // draw ImGui into Swapchain Image - vk_helpers::transitionImage(cmd, swapchainImages[swapchainImageIndex], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, swapchainImages[swapchainImageIndex], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); imguiWrapper->drawImgui(cmd, swapchainImageViews[swapchainImageIndex], swapchainExtent); - vk_helpers::transitionImage(cmd, swapchainImages[swapchainImageIndex], VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_ASPECT_COLOR_BIT); + vk_helpers::transitionImage(cmd, swapchainImages[swapchainImageIndex], VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, + VK_IMAGE_ASPECT_COLOR_BIT); // End Command Buffer Recording VK_CHECK(vkEndCommandBuffer(cmd)); @@ -631,8 +674,10 @@ void Engine::draw(float deltaTime) // Submission const VkCommandBufferSubmitInfo cmdSubmitInfo = vk_helpers::commandBufferSubmitInfo(cmd); - const VkSemaphoreSubmitInfo waitInfo = vk_helpers::semaphoreSubmitInfo(VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT_KHR, getCurrentFrame()._swapchainSemaphore); - const VkSemaphoreSubmitInfo signalInfo = vk_helpers::semaphoreSubmitInfo(VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT, getCurrentFrame()._renderSemaphore); + const VkSemaphoreSubmitInfo waitInfo = vk_helpers::semaphoreSubmitInfo(VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT_KHR, + getCurrentFrame()._swapchainSemaphore); + const VkSemaphoreSubmitInfo signalInfo = + vk_helpers::semaphoreSubmitInfo(VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT, getCurrentFrame()._renderSemaphore); const VkSubmitInfo2 submit = vk_helpers::submitInfo(&cmdSubmitInfo, &signalInfo, &waitInfo); //submit command buffer to the queue and execute it. @@ -908,9 +953,11 @@ void Engine::createDrawResources() VmaAllocationCreateInfo taaResolveAllocationInfo = {}; taaResolveAllocationInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; taaResolveAllocationInfo.requiredFlags = static_cast(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - vmaCreateImage(context->allocator, &taaResolveImageInfo, &taaResolveAllocationInfo, &taaResolveTarget.image, &taaResolveTarget.allocation, nullptr); + vmaCreateImage(context->allocator, &taaResolveImageInfo, &taaResolveAllocationInfo, &taaResolveTarget.image, &taaResolveTarget.allocation, + nullptr); - const VkImageViewCreateInfo taaResolveImageViewInfo = vk_helpers::imageviewCreateInfo(taaResolveTarget.imageFormat, taaResolveTarget.image, VK_IMAGE_ASPECT_COLOR_BIT); + const VkImageViewCreateInfo taaResolveImageViewInfo = vk_helpers::imageviewCreateInfo( + taaResolveTarget.imageFormat, taaResolveTarget.image, VK_IMAGE_ASPECT_COLOR_BIT); VK_CHECK(vkCreateImageView(context->device, &taaResolveImageViewInfo, nullptr, &taaResolveTarget.imageView)); } // Draw History @@ -927,9 +974,11 @@ void Engine::createDrawResources() VmaAllocationCreateInfo historyBufferAllocationInfo = {}; historyBufferAllocationInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; historyBufferAllocationInfo.requiredFlags = static_cast(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - vmaCreateImage(context->allocator, &historyBufferImageInfo, &historyBufferAllocationInfo, &historyBuffer.image, &historyBuffer.allocation, nullptr); + vmaCreateImage(context->allocator, &historyBufferImageInfo, &historyBufferAllocationInfo, &historyBuffer.image, &historyBuffer.allocation, + nullptr); - const VkImageViewCreateInfo historyBufferImageViewInfo = vk_helpers::imageviewCreateInfo(historyBuffer.imageFormat, historyBuffer.image, VK_IMAGE_ASPECT_COLOR_BIT); + const VkImageViewCreateInfo historyBufferImageViewInfo = vk_helpers::imageviewCreateInfo( + historyBuffer.imageFormat, historyBuffer.image, VK_IMAGE_ASPECT_COLOR_BIT); VK_CHECK(vkCreateImageView(context->device, &historyBufferImageViewInfo, nullptr, &historyBuffer.imageView)); } // Post Process Resolve @@ -945,9 +994,11 @@ void Engine::createDrawResources() VmaAllocationCreateInfo imageAllocationInfo = {}; imageAllocationInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; imageAllocationInfo.requiredFlags = static_cast(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - vmaCreateImage(context->allocator, &imageCreateInfo, &imageAllocationInfo, &postProcessOutputBuffer.image, &postProcessOutputBuffer.allocation, nullptr); + vmaCreateImage(context->allocator, &imageCreateInfo, &imageAllocationInfo, &postProcessOutputBuffer.image, + &postProcessOutputBuffer.allocation, nullptr); - VkImageViewCreateInfo rview_info = vk_helpers::imageviewCreateInfo(postProcessOutputBuffer.imageFormat, postProcessOutputBuffer.image, VK_IMAGE_ASPECT_COLOR_BIT); + VkImageViewCreateInfo rview_info = vk_helpers::imageviewCreateInfo(postProcessOutputBuffer.imageFormat, postProcessOutputBuffer.image, + VK_IMAGE_ASPECT_COLOR_BIT); VK_CHECK(vkCreateImageView(context->device, &rview_info, nullptr, &postProcessOutputBuffer.imageView)); } } diff --git a/src/core/engine.h b/src/core/engine.h index 299ad7a3..08558dc8 100644 --- a/src/core/engine.h +++ b/src/core/engine.h @@ -18,6 +18,7 @@ #include "src/renderer/assets/asset_manager.h" #include "src/renderer/descriptor_buffer/descriptor_buffer_uniform.h" #include "src/renderer/lighting/directional_light.h" +#include "src/renderer/post_process/post_process_types.h" class ResourceManager; @@ -112,9 +113,11 @@ class Engine void run(); + void updatePhysics(float deltaTime) const; + void updateGame(float deltaTime); - void updateRender(float deltaTime, int32_t currentFrameOverlap, int32_t previousFrameOverlap) const; + void updateRender(VkCommandBuffer cmd, float deltaTime, int32_t currentFrameOverlap, int32_t previousFrameOverlap) const; void draw(float deltaTime); @@ -177,6 +180,8 @@ class Engine int32_t deferredDebug{0}; int32_t gtaoDebug{4}; bool bDrawTerrainLines{false}; + bool bPausePhysics{true}; + bool bDisableJitter{false}; void hotReloadShaders() const; @@ -189,6 +194,8 @@ class Engine DirectionalLight mainLight{glm::normalize(glm::vec3(-0.8f, -0.6f, -0.6f)), 1.0f, glm::vec3(0.0f)}; int32_t environmentMapIndex{0}; + post_process::PostProcessType postProcessData{post_process::PostProcessType::ALL}; + std::unordered_set activeMaps; std::unordered_set activeTerrains; diff --git a/src/core/game_object/game_object.cpp b/src/core/game_object/game_object.cpp index 44602431..592713ad 100644 --- a/src/core/game_object/game_object.cpp +++ b/src/core/game_object/game_object.cpp @@ -33,11 +33,13 @@ GameObject::GameObject(std::string gameObjectName, const uint64_t gameObjectId) GameObject::~GameObject() { if (!children.empty()) { - fmt::print("Error: GameObject destroyed with children, potentially not destroyed with ::destroy. This will result in orphaned children and null references"); + fmt::print( + "Error: GameObject destroyed with children, potentially not destroyed with ::destroy. This will result in orphaned children and null references"); } if (parent) { - fmt::print("Error: GameObject destroyed with a parent, potentially not destroyed with ::destroy. This will result in orphaned children and null references"); + fmt::print( + "Error: GameObject destroyed with a parent, potentially not destroyed with ::destroy. This will result in orphaned children and null references"); } } @@ -188,7 +190,8 @@ const Transform& GameObject::getGlobalTransform() if (bIsGlobalTransformDirty) { if (transformableParent != nullptr) { const Transform& parentGlobal = transformableParent->getGlobalTransform(); - const glm::vec3 globalPosition = parentGlobal.getPosition() + parentGlobal.getRotation() * (parentGlobal.getScale() * transform.getPosition()); + const glm::vec3 globalPosition = parentGlobal.getPosition() + parentGlobal.getRotation() * ( + parentGlobal.getScale() * transform.getPosition()); const glm::quat globalRotation = parentGlobal.getRotation() * transform.getRotation(); const glm::vec3 globalScale = parentGlobal.getScale() * transform.getScale(); @@ -305,6 +308,22 @@ void GameObject::setGlobalTransform(const Transform& newGlobalTransform) void GameObject::setGlobalTransformFromPhysics(const glm::vec3& position, const glm::quat& rotation) { + const glm::vec3 pos = getPosition(); + const glm::quat rot = getRotation(); + + constexpr float positionEpsilonSquared = 0.000001f; + constexpr float rotationEpsilon = 0.0001f; + + const float posDistSquared = + (position.x - pos.x) * (position.x - pos.x) + + (position.y - pos.y) * (position.y - pos.y) + + (position.z - pos.z) * (position.z - pos.z); + + const bool positionUnchanged = posDistSquared < positionEpsilonSquared; + const bool rotationUnchanged = glm::abs(dot(rotation, rot)) > (1.0f - rotationEpsilon); + if (positionUnchanged && rotationUnchanged) { return; } + + if (transformableParent) { const glm::vec3 parentPos = transformableParent->getPosition(); const glm::quat parentRot = transformableParent->getRotation(); diff --git a/src/renderer/imgui_wrapper.cpp b/src/renderer/imgui_wrapper.cpp index b8605098..3e407790 100644 --- a/src/renderer/imgui_wrapper.cpp +++ b/src/renderer/imgui_wrapper.cpp @@ -199,10 +199,14 @@ void ImguiWrapper::imguiInterface(Engine* engine) } ImGui::Separator(); - ImGui::Text("Temporal Anti-Aliasing"); - ImGui::Checkbox("Enable TAA", &engine->bEnableTaa); - ImGui::DragFloat("Taa Blend Value", &engine->taaBlendValue, 0.01, 0.1f, 0.5f); - ImGui::Separator(); + ImGui::Checkbox("Disable Physics", &engine->bPausePhysics); + + + if (ImGui::CollapsingHeader("Temporal Antialiasing", ImGuiTreeNodeFlags_DefaultOpen)) { + ImGui::Checkbox("Enable TAA", &engine->bEnableTaa); + ImGui::DragFloat("Taa Blend Value", &engine->taaBlendValue, 0.01, 0.1f, 0.5f); + ImGui::Checkbox("Disable Jitter", &engine->bDisableJitter); + } ImGui::Text("Deferred Debug"); const char* deferredDebugOptions[]{"None", "Depth", "Velocity", "Albedo", "Normal", "PBR", "Shadows", "Cascade Level", "nDotL", "AO"}; @@ -214,6 +218,31 @@ void ImguiWrapper::imguiInterface(Engine* engine) ImGui::EndTabItem(); } + if (ImGui::BeginTabItem("Post-Processing")) { + static bool tonemapping = (engine->postProcessData & post_process::PostProcessType::Tonemapping) != post_process::PostProcessType::None; + if (ImGui::CollapsingHeader("Tonemapping", ImGuiTreeNodeFlags_DefaultOpen)) { + if (ImGui::Checkbox("Enable Tonemapping", &tonemapping)) { + if (tonemapping) { + engine->postProcessData |= post_process::PostProcessType::Tonemapping; + } else { + engine->postProcessData &= ~post_process::PostProcessType::Tonemapping; + } + } + } + if (ImGui::CollapsingHeader("Sharpening", ImGuiTreeNodeFlags_DefaultOpen)) { + static bool sharpening = (engine->postProcessData & post_process::PostProcessType::Sharpening) != post_process::PostProcessType::None; + if (ImGui::Checkbox("Enable Sharpening", &sharpening)) { + if (sharpening) { + engine->postProcessData |= post_process::PostProcessType::Sharpening; + } else { + engine->postProcessData &= ~post_process::PostProcessType::Sharpening; + } + } + } + + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("Ambient Occlusion")) { ambient_occlusion::GTAOPushConstants& gtao = engine->ambientOcclusionPipeline->gtaoPush; if (ImGui::CollapsingHeader("GTAO Settings")) { diff --git a/src/renderer/lighting/ambient_occlusion/ground_truth/ground_truth_ambient_occlusion.cpp b/src/renderer/lighting/ambient_occlusion/ground_truth/ground_truth_ambient_occlusion.cpp index 1f8ddba1..513a116d 100644 --- a/src/renderer/lighting/ambient_occlusion/ground_truth/ground_truth_ambient_occlusion.cpp +++ b/src/renderer/lighting/ambient_occlusion/ground_truth/ground_truth_ambient_occlusion.cpp @@ -332,8 +332,7 @@ void will_engine::ambient_occlusion::GroundTruthAmbientOcclusionPipeline::setupA resourceManager.setupDescriptorBufferSampler(ambientOcclusionDescriptorBuffer, imageDescriptors, 0); } -void will_engine::ambient_occlusion::GroundTruthAmbientOcclusionPipeline::setupSpatialFilteringDescriptorBuffer(const VkImageView& depthImageView, - const VkImageView& normalsImageView) +void will_engine::ambient_occlusion::GroundTruthAmbientOcclusionPipeline::setupSpatialFilteringDescriptorBuffer() { std::vector imageDescriptors{}; imageDescriptors.reserve(5); @@ -344,18 +343,6 @@ void will_engine::ambient_occlusion::GroundTruthAmbientOcclusionPipeline::setupS {depthSampler, ambientOcclusionImage.imageView, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL}, false }); - // imageDescriptors.push_back( - // { - // VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - // {depthSampler, depthImageView, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL}, - // false - // }); - // imageDescriptors.push_back( - // { - // VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - // {normalsSampler, normalsImageView, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL}, - // false - // }); imageDescriptors.push_back( { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, diff --git a/src/renderer/lighting/ambient_occlusion/ground_truth/ground_truth_ambient_occlusion.h b/src/renderer/lighting/ambient_occlusion/ground_truth/ground_truth_ambient_occlusion.h index f5a78a74..6ad88426 100644 --- a/src/renderer/lighting/ambient_occlusion/ground_truth/ground_truth_ambient_occlusion.h +++ b/src/renderer/lighting/ambient_occlusion/ground_truth/ground_truth_ambient_occlusion.h @@ -25,7 +25,7 @@ class GroundTruthAmbientOcclusionPipeline void setupAmbientOcclusionDescriptorBuffer(const VkImageView& normalsImageView); - void setupSpatialFilteringDescriptorBuffer(const VkImageView& depthImageView, const VkImageView& normalsImageView); + void setupSpatialFilteringDescriptorBuffer(); void draw(VkCommandBuffer cmd, const GTAODrawInfo& drawInfo); diff --git a/src/renderer/pipelines/deferred_mrt/deferred_mrt.cpp b/src/renderer/pipelines/deferred_mrt/deferred_mrt.cpp index 862c8592..54eec1c6 100644 --- a/src/renderer/pipelines/deferred_mrt/deferred_mrt.cpp +++ b/src/renderer/pipelines/deferred_mrt/deferred_mrt.cpp @@ -4,6 +4,7 @@ #include "deferred_mrt.h" +#include #include #include "volk/volk.h" @@ -47,11 +48,16 @@ void will_engine::deferred_mrt::DeferredMrtPipeline::draw(VkCommandBuffer cmd, c VkClearValue clearValue = {0.0f, 0.0f}; - VkRenderingAttachmentInfo normalAttachment = vk_helpers::attachmentInfo(drawInfo.normalTarget, drawInfo.bClearColor ? &clearValue : nullptr, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); - VkRenderingAttachmentInfo albedoAttachment = vk_helpers::attachmentInfo(drawInfo.albedoTarget, drawInfo.bClearColor ? &clearValue : nullptr, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); - VkRenderingAttachmentInfo pbrAttachment = vk_helpers::attachmentInfo(drawInfo.pbrTarget, drawInfo.bClearColor ? &clearValue : nullptr, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); - VkRenderingAttachmentInfo velocityAttachment = vk_helpers::attachmentInfo(drawInfo.velocityTarget, drawInfo.bClearColor ? &clearValue : nullptr, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); - VkRenderingAttachmentInfo depthAttachment = vk_helpers::attachmentInfo(drawInfo.depthTarget, drawInfo.bClearColor ? &clearValue : nullptr, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL); + VkRenderingAttachmentInfo normalAttachment = vk_helpers::attachmentInfo(drawInfo.normalTarget, drawInfo.bClearColor ? &clearValue : nullptr, + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + VkRenderingAttachmentInfo albedoAttachment = vk_helpers::attachmentInfo(drawInfo.albedoTarget, drawInfo.bClearColor ? &clearValue : nullptr, + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + VkRenderingAttachmentInfo pbrAttachment = vk_helpers::attachmentInfo(drawInfo.pbrTarget, drawInfo.bClearColor ? &clearValue : nullptr, + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + VkRenderingAttachmentInfo velocityAttachment = vk_helpers::attachmentInfo(drawInfo.velocityTarget, drawInfo.bClearColor ? &clearValue : nullptr, + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + VkRenderingAttachmentInfo depthAttachment = vk_helpers::attachmentInfo(drawInfo.depthTarget, drawInfo.bClearColor ? &clearValue : nullptr, + VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL); VkRenderingInfo renderInfo{}; renderInfo.sType = VK_STRUCTURE_TYPE_RENDERING_INFO; @@ -98,22 +104,28 @@ void will_engine::deferred_mrt::DeferredMrtPipeline::draw(VkCommandBuffer cmd, c constexpr uint32_t addressIndex{1}; constexpr uint32_t texturesIndex{2}; - VkDescriptorBufferBindingInfoEXT descriptorBufferBindingInfo[3]; - descriptorBufferBindingInfo[0] = drawInfo.sceneDataBinding; - descriptorBufferBindingInfo[1] = renderObject->getAddressesDescriptorBuffer().getDescriptorBufferBindingInfo(); - descriptorBufferBindingInfo[2] = renderObject->getTextureDescriptorBuffer().getDescriptorBufferBindingInfo(); - vkCmdBindDescriptorBuffersEXT(cmd, 3, descriptorBufferBindingInfo); + std::array descriptorBufferBindingInfos{ + drawInfo.sceneDataBinding, + renderObject->getAddressesDescriptorBuffer().getDescriptorBufferBindingInfo(), + renderObject->getTextureDescriptorBuffer().getDescriptorBufferBindingInfo(), + }; - const VkDeviceSize sceneDataOffset{drawInfo.sceneDataOffset}; - const VkDeviceSize addressOffset{renderObject->getAddressesDescriptorBuffer().getDescriptorBufferSize() * drawInfo.currentFrameOverlap}; + vkCmdBindDescriptorBuffersEXT(cmd, 3, descriptorBufferBindingInfos.data()); - vkCmdSetDescriptorBufferOffsetsEXT(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &sceneDataIndex, &sceneDataOffset); - vkCmdSetDescriptorBufferOffsetsEXT(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 1, 1, &addressIndex, &addressOffset); - vkCmdSetDescriptorBufferOffsetsEXT(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 2, 1, &texturesIndex, &zeroOffset); + constexpr std::array indices{0, 1, 2}; + + std::array offsets{ + drawInfo.sceneDataOffset, + renderObject->getAddressesDescriptorBuffer().getDescriptorBufferSize() * drawInfo.currentFrameOverlap, + ZERO_DEVICE_SIZE + }; + + vkCmdSetDescriptorBufferOffsetsEXT(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 3, indices.data(), offsets.data()); vkCmdBindVertexBuffers(cmd, 0, 1, &renderObject->getVertexBuffer().buffer, &zeroOffset); vkCmdBindIndexBuffer(cmd, renderObject->getIndexBuffer().buffer, 0, VK_INDEX_TYPE_UINT32); - vkCmdDrawIndexedIndirect(cmd, renderObject->getIndirectBuffer(drawInfo.currentFrameOverlap).buffer, 0, renderObject->getDrawIndirectCommandCount(), sizeof(VkDrawIndexedIndirectCommand)); + vkCmdDrawIndexedIndirect(cmd, renderObject->getIndirectBuffer(drawInfo.currentFrameOverlap).buffer, 0, + renderObject->getDrawIndirectCommandCount(), sizeof(VkDrawIndexedIndirectCommand)); } vkCmdEndRendering(cmd); diff --git a/src/renderer/pipelines/post_process/post_process_pipeline.cpp b/src/renderer/pipelines/post_process/post_process_pipeline.cpp index 97b4de9e..6810c0ed 100644 --- a/src/renderer/pipelines/post_process/post_process_pipeline.cpp +++ b/src/renderer/pipelines/post_process/post_process_pipeline.cpp @@ -4,6 +4,8 @@ #include "post_process_pipeline.h" +#include + #include "volk/volk.h" #include "src/renderer/renderer_constants.h" @@ -21,14 +23,15 @@ will_engine::post_process_pipeline::PostProcessPipeline::PostProcessPipeline(Res pushConstants.size = sizeof(PostProcessPushConstants); pushConstants.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; - VkDescriptorSetLayout setLayouts[1]; - setLayouts[0] = descriptorSetLayout; + VkDescriptorSetLayout setLayouts[2]; + setLayouts[0] = resourceManager.getSceneDataLayout(); + setLayouts[1] = descriptorSetLayout; VkPipelineLayoutCreateInfo layoutInfo{}; layoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; layoutInfo.pNext = nullptr; layoutInfo.pSetLayouts = setLayouts; - layoutInfo.setLayoutCount = 1; + layoutInfo.setLayoutCount = 2; layoutInfo.pPushConstantRanges = &pushConstants; layoutInfo.pushConstantRangeCount = 1; @@ -67,7 +70,7 @@ void will_engine::post_process_pipeline::PostProcessPipeline::setupDescriptorBuf resourceManager.setupDescriptorBufferSampler(descriptorBuffer, descriptors, 0); } -void will_engine::post_process_pipeline::PostProcessPipeline::draw(VkCommandBuffer cmd, post_process::PostProcessType postProcessFlags) const +void will_engine::post_process_pipeline::PostProcessPipeline::draw(VkCommandBuffer cmd, PostProcessDrawInfo drawInfo) const { if (!descriptorBuffer.isIndexOccupied(0)) { fmt::print("Descriptor buffer not yet set up"); @@ -84,16 +87,19 @@ void will_engine::post_process_pipeline::PostProcessPipeline::draw(VkCommandBuff PostProcessPushConstants push{}; push.width = RENDER_EXTENTS.width; push.height = RENDER_EXTENTS.height; - push.postProcessFlags = static_cast(postProcessFlags); + push.postProcessFlags = static_cast(drawInfo.postProcessFlags); vkCmdPushConstants(cmd, pipelineLayout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(PostProcessPushConstants), &push); - const VkDescriptorBufferBindingInfoEXT bindingInfo = descriptorBuffer.getDescriptorBufferBindingInfo(); - vkCmdBindDescriptorBuffersEXT(cmd, 1, &bindingInfo); + const std::array bindingInfos{ + drawInfo.sceneDataBinding, + descriptorBuffer.getDescriptorBufferBindingInfo() + }; + vkCmdBindDescriptorBuffersEXT(cmd, 2, bindingInfos.data()); - constexpr VkDeviceSize zeroOffset{0}; - constexpr uint32_t descriptorIndex{0}; - vkCmdSetDescriptorBufferOffsetsEXT(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0, 1, &descriptorIndex, &zeroOffset); + constexpr std::array indices{0, 1}; + const std::array offsets{drawInfo.sceneDataOffset, 0}; + vkCmdSetDescriptorBufferOffsetsEXT(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0, 2, indices.data(), offsets.data()); const auto x = static_cast(std::ceil(RENDER_EXTENT_WIDTH / 16.0f)); const auto y = static_cast(std::ceil(RENDER_EXTENT_HEIGHT / 16.0f)); diff --git a/src/renderer/pipelines/post_process/post_process_pipeline.h b/src/renderer/pipelines/post_process/post_process_pipeline.h index a64ec460..d28a2659 100644 --- a/src/renderer/pipelines/post_process/post_process_pipeline.h +++ b/src/renderer/pipelines/post_process/post_process_pipeline.h @@ -25,6 +25,13 @@ struct PostProcessPushConstants int32_t padding; }; +struct PostProcessDrawInfo +{ + post_process::PostProcessType postProcessFlags{post_process::PostProcessType::ALL}; + VkDescriptorBufferBindingInfoEXT sceneDataBinding{}; + VkDeviceSize sceneDataOffset{0}; +}; + class PostProcessPipeline { public: @@ -34,7 +41,7 @@ class PostProcessPipeline void setupDescriptorBuffer(const PostProcessDescriptor& bufferInfo); - void draw(VkCommandBuffer cmd, post_process::PostProcessType postProcessFlags) const; + void draw(VkCommandBuffer cmd, PostProcessDrawInfo drawInfo) const; void reloadShaders() { createPipeline(); } diff --git a/src/renderer/post_process/post_process_types.h b/src/renderer/post_process/post_process_types.h index c00a95ea..620264fc 100644 --- a/src/renderer/post_process/post_process_types.h +++ b/src/renderer/post_process/post_process_types.h @@ -5,8 +5,6 @@ #ifndef POST_PROCESS_TYPES_H #define POST_PROCESS_TYPES_H -#include - namespace post_process { enum class PostProcessType : uint32_t @@ -17,6 +15,26 @@ enum class PostProcessType : uint32_t ALL = 0xFFFFFFFF }; +inline PostProcessType operator|(PostProcessType a, PostProcessType b) { + return static_cast(static_cast(a) | static_cast(b)); +} + +inline PostProcessType operator&(PostProcessType a, PostProcessType b) { + return static_cast(static_cast(a) & static_cast(b)); +} + +inline PostProcessType operator~(PostProcessType a) { + return static_cast(~static_cast(a)); +} + +inline PostProcessType& operator|=(PostProcessType& a, PostProcessType b) { + return a = a | b; +} + +inline PostProcessType& operator&=(PostProcessType& a, PostProcessType b) { + return a = a & b; +} + } #endif //POST_PROCESS_TYPES_H diff --git a/src/renderer/renderer_constants.h b/src/renderer/renderer_constants.h index b383e60b..33e96269 100644 --- a/src/renderer/renderer_constants.h +++ b/src/renderer/renderer_constants.h @@ -10,16 +10,17 @@ constexpr int32_t FRAME_OVERLAP = 2; constexpr char ENGINE_NAME[] = "Will Engine"; constexpr bool USING_REVERSED_DEPTH_BUFFER = true; constexpr VkDeviceSize ZERO_DEVICE_SIZE = 0; -//constexpr VkExtent2D RENDER_EXTENTS{1920, 1080}; -constexpr VkExtent2D RENDER_EXTENTS{3840, 2160}; +constexpr VkExtent2D RENDER_EXTENTS{1920, 1080}; +//constexpr VkExtent2D RENDER_EXTENTS{3840, 2160}; constexpr float RENDER_EXTENT_WIDTH{RENDER_EXTENTS.width}; constexpr float RENDER_EXTENT_HEIGHT{RENDER_EXTENTS.height}; constexpr VkFormat DRAW_FORMAT{VK_FORMAT_R16G16B16A16_SFLOAT}; constexpr VkFormat DEPTH_FORMAT{VK_FORMAT_D32_SFLOAT}; constexpr VkFormat VELOCITY_FORMAT{VK_FORMAT_R16G16_SFLOAT}; -constexpr VkFormat NORMAL_FORMAT{VK_FORMAT_R8G8B8A8_SNORM}; -constexpr VkFormat ALBEDO_FORMAT{VK_FORMAT_A2R10G10B10_UNORM_PACK32}; +constexpr VkFormat NORMAL_FORMAT{VK_FORMAT_R16G16B16A16_SNORM}; +// Be careful, environment map is in HDR format, so non-float formats wont work +constexpr VkFormat ALBEDO_FORMAT{VK_FORMAT_R16G16B16A16_UNORM}; constexpr VkFormat PBR_FORMAT{VK_FORMAT_R8G8B8A8_UNORM}; #endif // RENDERER_CONSTANTS_H diff --git a/src/util/halton.h b/src/util/halton.h index 4091cbff..3934a9f0 100644 --- a/src/util/halton.h +++ b/src/util/halton.h @@ -13,8 +13,8 @@ class HaltonSequence { public: // Pre-computed 16-point Halton sequence (base 2, 3) - static constexpr glm::vec2 HALTON_SEQUENCE[16] = { - {0.5, 0.33333334}, + static constexpr std::array HALTON_SEQUENCE = { + glm::vec2(0.5, 0.33333334), {0.25, 0.66666667}, {0.75, 0.11111111}, {0.125, 0.44444445},