diff --git a/Shaders/Depth.spv b/Shaders/Depth.spv index 630e3ab..c6aff93 100644 Binary files a/Shaders/Depth.spv and b/Shaders/Depth.spv differ diff --git a/Shaders/Depth.vert b/Shaders/Depth.vert index 534dc1b..3f1cd19 100644 --- a/Shaders/Depth.vert +++ b/Shaders/Depth.vert @@ -20,5 +20,6 @@ layout(push_constant) uniform ModelMatrixID { void main() { - gl_Position = camera.projView * modelMatrix[modelMatrixID] * vec4(vPosition, 1.0); + vec4 vWorldSpace = modelMatrix[modelMatrixID] * vec4(vPosition, 1.0); + gl_Position = camera.projView * vWorldSpace; } \ No newline at end of file diff --git a/Shaders/SSAO.frag b/Shaders/SSAO.frag index 9695e31..dea53b7 100644 --- a/Shaders/SSAO.frag +++ b/Shaders/SSAO.frag @@ -72,7 +72,7 @@ float LinearDepth(float d) } void main() { - vec2 noiseScale = vec2(params.screenWidth/params.noiseScale, params.screenHeight/params.noiseScale); + vec2 noiseScale = vec2(params.screenWidth, params.screenHeight) / params.noiseScale; vec3 viewPos = GetViewPosition(fTexcoord); vec3 viewNormal = normalize(cross(dFdx(viewPos.xyz), dFdy(viewPos.xyz))); @@ -92,12 +92,15 @@ void main() vec3 samplePos = TBN * kernels[i]; samplePos = viewPos + samplePos * params.radius; - vec4 offset = vec4(samplePos, 1.0); - offset = camera.proj * offset; - offset.xy /= offset.w; + // Faster and shorter form of: + //vec4 offset = camera.proj * vec4(samplePos, 1.0); + //offset.xyz /= offset.w; - float sampleDepth = GetViewZ(offset.xy * 0.5 + 0.5); + vec2 offsetXY = vec2(camera.proj[0][0] * samplePos.x, camera.proj[1][1] * samplePos.y); + offsetXY /= camera.proj[2][3] * samplePos.z; + float sampleDepth = GetViewZ(offsetXY * 0.5 + 0.5); + float rangeCheck = smoothstep(0.0, 1.0, params.radius / abs(viewPos.z - sampleDepth)); occlusion += (sampleDepth >= samplePos.z + params.bias ? 1.0 : 0.0) * rangeCheck * params.multiplier; } diff --git a/Shaders/SSAO.spv b/Shaders/SSAO.spv index c837bad..0ed76b3 100644 Binary files a/Shaders/SSAO.spv and b/Shaders/SSAO.spv differ diff --git a/Source/Core/Eruption.cpp b/Source/Core/Eruption.cpp index 1fea129..1a9bb8a 100644 --- a/Source/Core/Eruption.cpp +++ b/Source/Core/Eruption.cpp @@ -51,12 +51,6 @@ void Eruption::Update() if (m_Input->IsKey(en::Key::LShift) && m_Input->IsKey(en::Key::R, en::InputState::Pressed)) m_Renderer->ReloadBackend(); - else if (m_Input->IsKey(en::Key::Y, en::InputState::Pressed)) - { - m_Renderer->SetVSyncEnabled(false); - //m_Renderer->m_PostProcessParams.antialiasingMode = en::Renderer::AntialiasingMode::None; - } - double deltaTime = m_Renderer->GetFrameTime(); static float targetYaw = m_Camera->m_Yaw; @@ -103,9 +97,9 @@ void Eruption::Render() m_Renderer->Render(); } - void Eruption::CreateExampleScene() { + /* m_AssetManager->LoadMesh("SkullModel", "Models/Skull/Skull.gltf"); m_AssetManager->LoadTexture("SkullAlbedo", "Models/Skull/SkullAlbedo.jpg"); @@ -117,9 +111,9 @@ void Eruption::CreateExampleScene() m_AssetManager->GetMesh("SkullModel")->m_SubMeshes[0].SetMaterial(m_AssetManager->GetMaterial("SkullMaterial")); m_AssetManager->LoadMesh("Sponza", "Models/Sponza/Sponza.gltf"); - + */ m_ExampleScene = en::MakeHandle(); - + /* auto m_Sponza = m_ExampleScene->CreateSceneObject("Sponza", m_AssetManager->GetMesh("Sponza")); m_Sponza->SetScale(glm::vec3(1.2f)); @@ -130,7 +124,7 @@ void Eruption::CreateExampleScene() auto m_Skull = m_ExampleScene->CreateSceneObject("SkullModel", m_AssetManager->GetMesh("SkullModel")); m_Skull->SetPosition(glm::vec3(0, 0.5f, -0.3)); m_Skull->SetRotation(glm::vec3(45.0f, 90.0f, 0.0f)); - + */ @@ -160,7 +154,6 @@ void Eruption::CreateExampleScene() m_Renderer->BindScene(m_ExampleScene); } - void Eruption::Run() { Init(); diff --git a/Source/Editor/UIPanels/SettingsPanel.cpp b/Source/Editor/UIPanels/SettingsPanel.cpp index 227aedd..2046db1 100644 --- a/Source/Editor/UIPanels/SettingsPanel.cpp +++ b/Source/Editor/UIPanels/SettingsPanel.cpp @@ -89,8 +89,6 @@ namespace en ImGui::DragFloat("SSAO Bias", &ssao.bias, 0.05f, 0.0f, 1.0f), "%.2f", ImGuiSliderFlags_AlwaysClamp; ImGui::DragFloat("SSAO Radius", &ssao.radius, 0.1f, 0.0f, 5.0f, "%.1f", ImGuiSliderFlags_AlwaysClamp); ImGui::DragFloat("SSAO Multiplier", &ssao.multiplier, 0.1f, 0.0f, 5.0f, "%.1f", ImGuiSliderFlags_AlwaysClamp); - ImGui::DragFloat("ssao_noise_scale", &ssao._noiseScale, 0.1f, 1.0f, 8.0f, "%.1f", ImGuiSliderFlags_AlwaysClamp); - ImGui::DragInt("ssao_samples", &s, 1.0f, 1.0f, 64.0f, "%.1f", ImGuiSliderFlags_AlwaysClamp); break; diff --git a/Source/Renderer/Renderer.cpp b/Source/Renderer/Renderer.cpp index c2a4226..2022882 100644 --- a/Source/Renderer/Renderer.cpp +++ b/Source/Renderer/Renderer.cpp @@ -436,16 +436,16 @@ namespace en switch (m_Settings.ambientOcclusionQuality) { case QualityLevel::Low: - m_Settings.ambientOcclusion._samples = 16U; - m_Settings.ambientOcclusion._noiseScale = 4.0f; + m_Settings.ambientOcclusion._samples = 8U; + m_Settings.ambientOcclusion._noiseScale = 2.0f; break; case QualityLevel::Medium: - m_Settings.ambientOcclusion._samples = 32U; - m_Settings.ambientOcclusion._noiseScale = 4.0f; + m_Settings.ambientOcclusion._samples = 16U; + m_Settings.ambientOcclusion._noiseScale = 2.0f; break; case QualityLevel::High: - m_Settings.ambientOcclusion._samples = 32U; - m_Settings.ambientOcclusion._noiseScale = 2.0f; + m_Settings.ambientOcclusion._samples = 16U; + m_Settings.ambientOcclusion._noiseScale = 1.0f; break; case QualityLevel::Ultra: m_Settings.ambientOcclusion._samples = 32U; @@ -1239,7 +1239,7 @@ namespace en .enableDepthWrite = !m_Settings.depthPrePass, .blendEnable = false, - .compareOp = m_Settings.depthPrePass ? VK_COMPARE_OP_LESS_OR_EQUAL : VK_COMPARE_OP_LESS, + .compareOp = m_Settings.depthPrePass ? VK_COMPARE_OP_EQUAL : VK_COMPARE_OP_LESS, .polygonMode = VK_POLYGON_MODE_FILL, }; diff --git a/Source/Renderer/Renderer.hpp b/Source/Renderer/Renderer.hpp index 4555743..8cfa729 100644 --- a/Source/Renderer/Renderer.hpp +++ b/Source/Renderer/Renderer.hpp @@ -80,12 +80,12 @@ namespace en float screenWidth = 1920.0f; float screenHeight = 1080.0f; - float radius = 0.85f; + float radius = 0.75f; float bias = 0.025f; - float multiplier = 1.2f; + float multiplier = 1.0f; - uint32_t _samples = 64U; - float _noiseScale = 4.0f; + uint32_t _samples = 16U; + float _noiseScale = 2.0f; }; void SetVSyncEnabled(const bool enabled); diff --git a/Source/Renderer/Swapchain.cpp b/Source/Renderer/Swapchain.cpp index 1bb5131..68235c5 100644 --- a/Source/Renderer/Swapchain.cpp +++ b/Source/Renderer/Swapchain.cpp @@ -27,7 +27,7 @@ namespace en .imageColorSpace = surfaceFormat.colorSpace, .imageExtent = extent, .imageArrayLayers = 1U, - .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, + .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, .preTransform = swapChainSupport.capabilities.currentTransform, .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, .presentMode = presentMode, @@ -80,7 +80,7 @@ namespace en { UseContext(); - for (auto& imageView : m_ImageViews) + for (const auto& imageView : m_ImageViews) vkDestroyImageView(ctx.m_LogicalDevice, imageView, nullptr); vkDestroySwapchainKHR(ctx.m_LogicalDevice, m_Swapchain, nullptr); diff --git a/imgui.ini b/imgui.ini index 4bdc090..45d530c 100644 --- a/imgui.ini +++ b/imgui.ini @@ -1,6 +1,6 @@ [Window][DockSpace Demo] Pos=0,33 -Size=2560,1336 +Size=1920,1047 Collapsed=0 [Window][Debug##Default] @@ -9,14 +9,14 @@ Size=400,400 Collapsed=0 [Window][Asset Manager] -Pos=273,732 -Size=1400,348 +Pos=273,1021 +Size=2287,348 Collapsed=0 DockId=0x00000008,0 [Window][Camera Properties] -Pos=0,909 -Size=271,460 +Pos=0,720 +Size=271,360 Collapsed=0 DockId=0x00000004,0 @@ -26,19 +26,19 @@ Size=405,428 Collapsed=0 [Window][Debug Menu] -Pos=1683,398 +Pos=1387,230 Size=322,194 Collapsed=0 [Window][Scene Hierarchy] Pos=0,33 -Size=271,874 +Size=271,685 Collapsed=0 DockId=0x00000003,0 [Window][Inspector] -Pos=2315,33 -Size=245,1336 +Pos=1675,33 +Size=245,1047 Collapsed=0 DockId=0x00000006,0 @@ -58,12 +58,12 @@ Size=409,172 Collapsed=0 [Window][Settings] -Pos=1621,648 -Size=500,449 +Pos=1441,546 +Size=500,504 Collapsed=0 [Docking][Data] -DockSpace ID=0x1315676B Window=0x4647B76E Pos=0,33 Size=2560,1336 Split=X +DockSpace ID=0x1315676B Window=0x4647B76E Pos=0,33 Size=1920,1047 Split=X DockNode ID=0x00000005 Parent=0x1315676B SizeRef=1673,1047 Split=X DockNode ID=0x00000001 Parent=0x00000005 SizeRef=271,1047 Split=Y Selected=0x2E9237F7 DockNode ID=0x00000003 Parent=0x00000001 SizeRef=499,496 Selected=0x2E9237F7