diff --git a/bloom/bloom.cpp b/bloom/bloom.cpp index fe3002d6..50ea492d 100644 --- a/bloom/bloom.cpp +++ b/bloom/bloom.cpp @@ -129,9 +129,9 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Bloom"; + title = "Bloom (offscreen rendering)"; timerSpeed *= 0.5f; - enableTextOverlay = true; + settings.overlay = true; camera.type = Camera::CameraType::lookat; camera.setPosition(glm::vec3(0.0f, 0.0f, -10.25f)); camera.setRotation(glm::vec3(7.5f, -343.0f, 0.0f)); @@ -914,47 +914,17 @@ public: updateUniformBuffersScene(); } - void changeBlurScale(float delta) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - ubos.blurParams.blurScale += delta; - updateUniformBuffersBlur(); - } - - void toggleBloom() - { - bloom = !bloom; - reBuildCommandBuffers(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeBlurScale(0.25f); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeBlurScale(-0.25f); - break; - case KEY_B: - case GAMEPAD_BUTTON_A: - toggleBloom(); - break; + if (overlay->header("Settings")) { + if (overlay->checkBox("Bloom", &bloom)) { + buildCommandBuffers(); + } + if (overlay->inputFloat("Scale", &ubos.blurParams.blurScale, 0.1f, 2)) { + updateUniformBuffersBlur(); + } } } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("Press \"L1/R1\" to change blur scale", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"Button A\" to toggle bloom", 5.0f, 105.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Press \"NUMPAD +/-\" to change blur scale", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"B\" to toggle bloom", 5.0f, 105.0f, VulkanTextOverlay::alignLeft); -#endif - } }; VULKAN_EXAMPLE_MAIN() diff --git a/computecloth/computecloth.cpp b/computecloth/computecloth.cpp index 4a0239af..9bffce24 100644 --- a/computecloth/computecloth.cpp +++ b/computecloth/computecloth.cpp @@ -109,12 +109,12 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - enableTextOverlay = true; - title = "Vulkan Example - Compute shader cloth simulation"; + title = "Compute shader cloth simulation"; camera.type = Camera::CameraType::lookat; camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f); camera.setRotation(glm::vec3(-30.0f, -45.0f, 0.0f)); camera.setTranslation(glm::vec3(0.0f, 0.0f, -3.5f)); + settings.overlay = true; srand((unsigned int)time(NULL)); } @@ -151,7 +151,7 @@ public: void loadAssets() { textureCloth.loadFromFile(getAssetPath() + "textures/vulkan_cloth_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue); - modelSphere.loadFromFile(ASSET_PATH "models/geosphere.obj", vertexLayout, compute.ubo.sphereRadius * 0.05f, vulkanDevice, queue); + modelSphere.loadFromFile(getAssetPath() + "models/geosphere.obj", vertexLayout, compute.ubo.sphereRadius * 0.05f, vulkanDevice, queue); } void buildCommandBuffers() @@ -743,25 +743,12 @@ public: updateGraphicsUBO(); } - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case KEY_W: - case GAMEPAD_BUTTON_A: - simulateWind = !simulateWind; - break; + if (overlay->header("Settings")) { + overlay->checkBox("Simulate wind", &simulateWind); } } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("\"Button A\" to toggle wind simulation", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("\"w\" to toggle wind simulation", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif - } }; VULKAN_EXAMPLE_MAIN() \ No newline at end of file diff --git a/computecullandlod/computecullandlod.cpp b/computecullandlod/computecullandlod.cpp index 92e3f12e..2bcfd166 100644 --- a/computecullandlod/computecullandlod.cpp +++ b/computecullandlod/computecullandlod.cpp @@ -122,12 +122,12 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - enableTextOverlay = true; title = "Vulkan Example - Compute cull and lod"; camera.type = Camera::CameraType::firstperson; camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f); camera.setTranslation(glm::vec3(0.5f, 0.0f, 0.0f)); camera.movementSpeed = 5.0f; + settings.overlay = true; memset(&indirectStats, 0, sizeof(indirectStats)); } @@ -850,29 +850,18 @@ public: updateUniformBuffer(true); } - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case KEY_F: - case GAMEPAD_BUTTON_A: - fixedFrustum = !fixedFrustum; - updateUniformBuffer(true); - break; + if (overlay->header("Settings")) { + if (overlay->checkBox("Freeze frustum", &fixedFrustum)) { + updateUniformBuffer(true); + } } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("\"Button A\" to freeze frustum", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("\"f\" to freeze frustum", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif - textOverlay->addText("visible: " + std::to_string(indirectStats.drawCount), 5.0f, 110.0f, VulkanTextOverlay::alignLeft); - for (uint32_t i = 0; i < MAX_LOD_LEVEL + 1; i++) - { - textOverlay->addText("lod " + std::to_string(i) + ": " + std::to_string(indirectStats.lodCount[i]), 5.0f, 125.0f + (float)i * 20.0f, VulkanTextOverlay::alignLeft); + if (overlay->header("Statistics")) { + overlay->text("Visible objects: %d", indirectStats.drawCount); + for (uint32_t i = 0; i < MAX_LOD_LEVEL + 1; i++) { + overlay->text("LOD %d: %d", i, indirectStats.lodCount[i]); + } } } }; diff --git a/computenbody/computenbody.cpp b/computenbody/computenbody.cpp index e5c5b425..7f500f24 100644 --- a/computenbody/computenbody.cpp +++ b/computenbody/computenbody.cpp @@ -94,9 +94,8 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - enableTextOverlay = true; - title = "Vulkan Example - Compute shader N-body system"; - + title = "Compute shader N-body system"; + settings.overlay = true; camera.type = Camera::CameraType::lookat; camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f); camera.setRotation(glm::vec3(-26.0f, 75.0f, 0.0f)); diff --git a/computeparticles/computeparticles.cpp b/computeparticles/computeparticles.cpp index 88e217fc..1c007fd4 100644 --- a/computeparticles/computeparticles.cpp +++ b/computeparticles/computeparticles.cpp @@ -88,8 +88,8 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - enableTextOverlay = true; - title = "Vulkan Example - Compute shader particle system"; + title = "Compute shader particle system"; + settings.overlay = true; } ~VulkanExample() @@ -658,19 +658,10 @@ public: updateUniformBuffers(); } - void toggleAnimation() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - animate = !animate; - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_A: - case GAMEPAD_BUTTON_A: - toggleAnimation(); - break; + if (overlay->header("Settings")) { + overlay->checkBox("Moving attractor", &animate); } } }; diff --git a/computeshader/computeshader.cpp b/computeshader/computeshader.cpp index cccde242..b1e8b2fe 100644 --- a/computeshader/computeshader.cpp +++ b/computeshader/computeshader.cpp @@ -62,7 +62,7 @@ public: VkDescriptorSet descriptorSet; // Compute shader bindings VkPipelineLayout pipelineLayout; // Layout of the compute pipeline std::vector pipelines; // Compute pipelines for image filters - uint32_t pipelineIndex = 0; // Current image filtering compute pipeline index + int32_t pipelineIndex = 0; // Current image filtering compute pipeline index uint32_t queueFamilyIndex; // Family index of the graphics queue, used for barriers } compute; @@ -77,16 +77,15 @@ public: glm::mat4 model; } uboVS; - struct { - } pipelines; - int vertexBufferSize; + std::vector shaderNames; + VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { zoom = -2.0f; - enableTextOverlay = true; - title = "Vulkan Example - Compute shader image processing"; + title = "Compute shader image load/store"; + settings.overlay = true; } ~VulkanExample() @@ -673,9 +672,8 @@ public: 0); // One pipeline for each effect - std::vector shaderNames = { "sharpen", "edgedetect", "emboss" }; - for (auto& shaderName : shaderNames) - { + shaderNames = { "sharpen", "edgedetect", "emboss" }; + for (auto& shaderName : shaderNames) { std::string fileName = getAssetPath() + "shaders/computeshader/" + shaderName + ".comp.spv"; computePipelineCreateInfo.stage = loadShader(fileName.c_str(), VK_SHADER_STAGE_COMPUTE_BIT); VkPipeline pipeline; @@ -789,42 +787,13 @@ public: updateUniformBuffers(); } - virtual void switchComputePipeline(int32_t dir) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - if ((dir < 0) && (compute.pipelineIndex > 0)) - { - compute.pipelineIndex--; - buildComputeCommandBuffer(); + if (overlay->header("Settings")) { + if (overlay->comboBox("Shader", &compute.pipelineIndex, shaderNames)) { + buildComputeCommandBuffer(); + } } - if ((dir > 0) && (compute.pipelineIndex < compute.pipelines.size() - 1)) - { - compute.pipelineIndex++; - buildComputeCommandBuffer(); - } - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - switchComputePipeline(1); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - switchComputePipeline(-1); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("Press \"L1/R1\" to change shaders", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Press \"NUMPAD +/-\" to change shaders", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif } }; diff --git a/data/shaders/ssao/composition.frag b/data/shaders/ssao/composition.frag index 321c6d6d..6530f66f 100644 --- a/data/shaders/ssao/composition.frag +++ b/data/shaders/ssao/composition.frag @@ -11,9 +11,9 @@ layout (binding = 4) uniform sampler2D samplerSSAOBlur; layout (binding = 5) uniform UBO { mat4 _dummy; - uint ssao; - uint ssaoOnly; - uint ssaoBlur; + int ssao; + int ssaoOnly; + int ssaoBlur; } uboParams; layout (location = 0) in vec2 inUV; diff --git a/data/shaders/ssao/composition.frag.spv b/data/shaders/ssao/composition.frag.spv index baa06fdd..db4f0de2 100644 Binary files a/data/shaders/ssao/composition.frag.spv and b/data/shaders/ssao/composition.frag.spv differ diff --git a/debugmarker/debugmarker.cpp b/debugmarker/debugmarker.cpp index 75578dd4..0ec1cdb5 100644 --- a/debugmarker/debugmarker.cpp +++ b/debugmarker/debugmarker.cpp @@ -241,8 +241,8 @@ public: rotationSpeed = 0.5f; rotation = { -4.35f, 16.25f, 0.0f }; cameraPos = { 0.1f, 1.1f, 0.0f }; - enableTextOverlay = true; - title = "Vulkan Example - VK_EXT_debug_marker"; + title = "Debugging with VK_EXT_debug_marker"; + settings.overlay = true; } // Enable physical device features required for this example @@ -546,8 +546,8 @@ public: void reBuildCommandBuffers() { - if (!checkCommandBuffers()) - { + vkDeviceWaitIdle(device); + if (!checkCommandBuffers()) { destroyCommandBuffers(); createCommandBuffers(); } @@ -852,8 +852,8 @@ public: VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.postprocess)); // Name shader moduels for debugging - // Shader module count starts at 2 when text overlay in base class is enabled - uint32_t moduleIndex = enableTextOverlay ? 2 : 0; + // Shader module count starts at 2 when UI overlay in base class is enabled + uint32_t moduleIndex = settings.overlay ? 2 : 0; DebugMarker::setObjectName(device, (uint64_t)shaderModules[moduleIndex + 0], VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, "Toon shading vertex shader"); DebugMarker::setObjectName(device, (uint64_t)shaderModules[moduleIndex + 1], VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, "Toon shading fragment shader"); DebugMarker::setObjectName(device, (uint64_t)shaderModules[moduleIndex + 2], VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, "Color-only vertex shader"); @@ -908,8 +908,7 @@ public: VulkanExampleBase::prepareFrame(); // Offscreen rendering - if (glow) - { + if (glow) { // Wait for swap chain presentation to finish submitInfo.pWaitSemaphores = &semaphores.presentComplete; // Signal ready with offscreen semaphore @@ -919,11 +918,15 @@ public: submitInfo.commandBufferCount = 1; submitInfo.pCommandBuffers = &offscreenPass.commandBuffer; VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE)); + + // Wait for offscreen semaphore + submitInfo.pWaitSemaphores = &offscreenPass.semaphore; + } + else { + submitInfo.pWaitSemaphores = &semaphores.presentComplete; } // Scene rendering - // Wait for offscreen semaphore - submitInfo.pWaitSemaphores = &offscreenPass.semaphore; // Signal ready with render complete semaphpre submitInfo.pSignalSemaphores = &semaphores.renderComplete; @@ -947,7 +950,6 @@ public: setupDescriptorSet(); buildCommandBuffers(); buildOffscreenCommandBuffer(); - updateTextOverlay(); prepared = true; } @@ -963,35 +965,20 @@ public: updateUniformBuffers(); } - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case 0x57: - case GAMEPAD_BUTTON_X: - if (deviceFeatures.fillModeNonSolid) - { - wireframe = !wireframe; + if (overlay->header("Info")) { + overlay->text("VK_EXT_debug_marker %s", (DebugMarker::active ? "active" : "not present")); + } + if (overlay->header("Settings")) { + if (overlay->checkBox("Glow", &glow)) { reBuildCommandBuffers(); } - break; - case 0x47: - case GAMEPAD_BUTTON_A: - glow = !glow; - reBuildCommandBuffers(); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - if (DebugMarker::active) - { - textOverlay->addText("VK_EXT_debug_marker active", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - } - else - { - textOverlay->addText("VK_EXT_debug_marker not present", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); + if (deviceFeatures.fillModeNonSolid) { + if (overlay->checkBox("Wireframe", &wireframe)) { + reBuildCommandBuffers(); + } + } } } }; diff --git a/deferred/deferred.cpp b/deferred/deferred.cpp index 6e1f5a7b..ea4b2e0f 100644 --- a/deferred/deferred.cpp +++ b/deferred/deferred.cpp @@ -138,8 +138,7 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Deferred shading (2016 by Sascha Willems)"; - enableTextOverlay = true; + title = "Deferred shading (2016 by Sascha Willems)"; camera.type = Camera::CameraType::firstperson; camera.movementSpeed = 5.0f; #ifndef __ANDROID__ @@ -148,6 +147,7 @@ public: camera.position = { 2.15f, 0.3f, -8.75f }; camera.setRotation(glm::vec3(-0.75f, 12.5f, 0.0f)); camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f); + settings.overlay = true; } ~VulkanExample() @@ -1195,39 +1195,13 @@ public: updateUniformBufferDeferredMatrices(); } - void toggleDebugDisplay() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - debugDisplay = !debugDisplay; - reBuildCommandBuffers(); - updateUniformBuffersScreen(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_F2: - case GAMEPAD_BUTTON_A: - toggleDebugDisplay(); - updateTextOverlay(); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("\"Button A\" to toggle debug display", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("\"F2\" to toggle debug display", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif - // Render targets - if (debugDisplay) - { - textOverlay->addText("World space position", (float)width * 0.25f, (float)height * 0.5f - 25.0f, VulkanTextOverlay::alignCenter); - textOverlay->addText("World space normals", (float)width * 0.75f, (float)height * 0.5f - 25.0f, VulkanTextOverlay::alignCenter); - textOverlay->addText("Albedo", (float)width * 0.25f, (float)height - 25.0f, VulkanTextOverlay::alignCenter); - textOverlay->addText("Final image", (float)width * 0.75f, (float)height - 25.0f, VulkanTextOverlay::alignCenter); + if (overlay->header("Settings")) { + if (overlay->checkBox("Display render targets", &debugDisplay)) { + buildCommandBuffers(); + updateUniformBuffersScreen(); + } } } }; diff --git a/deferredmultisampling/deferredmultisampling.cpp b/deferredmultisampling/deferredmultisampling.cpp index c5b65b66..b197d560 100644 --- a/deferredmultisampling/deferredmultisampling.cpp +++ b/deferredmultisampling/deferredmultisampling.cpp @@ -138,10 +138,7 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - zoom = -8.0f; - rotation = { 0.0f, 0.0f, 0.0f }; - enableTextOverlay = true; - title = "Vulkan Example - Deferred shading (2016 by Sascha Willems)"; + title = "Multi sampled deferred shading"; camera.type = Camera::CameraType::firstperson; camera.movementSpeed = 5.0f; #ifndef __ANDROID__ @@ -151,6 +148,7 @@ public: camera.setRotation(glm::vec3(-0.75f, 12.5f, 0.0f)); camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f); paused = true; + settings.overlay = true; } ~VulkanExample() @@ -1171,51 +1169,19 @@ public: uboFragmentLights.windowSize = glm::ivec2(width, height); } - void toggleDebugDisplay() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - debugDisplay = !debugDisplay; - buildCommandBuffers(); - updateUniformBuffersScreen(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_F2: - useMSAA = !useMSAA; - updateTextOverlay(); - buildCommandBuffers(); - break; - case KEY_F3: - useSampleShading = !useSampleShading; - updateTextOverlay(); - buildCommandBuffers(); - break; - case KEY_F4: - case GAMEPAD_BUTTON_A: - toggleDebugDisplay(); - updateTextOverlay(); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("Press \"Button A\" to toggle debug display", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("MSAA (\"F2\"): " + std::to_string(useMSAA), 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Sample Shading (\"F3\"): " + std::to_string(useSampleShading), 5.0f, 105.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("G-Buffers (\"F4\")", 5.0f, 125.0f, VulkanTextOverlay::alignLeft); -#endif - // Render targets - if (debugDisplay) - { - textOverlay->addText("World space position", (float)width * 0.25f, (float)height * 0.5f - 25.0f, VulkanTextOverlay::alignCenter); - textOverlay->addText("World space normals", (float)width * 0.75f, (float)height * 0.5f - 25.0f, VulkanTextOverlay::alignCenter); - textOverlay->addText("Albedo", (float)width * 0.25f, (float)height - 25.0f, VulkanTextOverlay::alignCenter); - textOverlay->addText("Final image", (float)width * 0.75f, (float)height - 25.0f, VulkanTextOverlay::alignCenter); + if (overlay->header("Settings")) { + if (overlay->checkBox("Display render targets", &debugDisplay)) { + buildCommandBuffers(); + updateUniformBuffersScreen(); + } + if (overlay->checkBox("MSAA", &useMSAA)) { + buildCommandBuffers(); + } + if (overlay->checkBox("Sample rate shading", &useSampleShading)) { + buildDeferredCommandBuffer(); + } } } }; diff --git a/deferredshadows/deferredshadows.cpp b/deferredshadows/deferredshadows.cpp index 549066c0..199c8659 100644 --- a/deferredshadows/deferredshadows.cpp +++ b/deferredshadows/deferredshadows.cpp @@ -170,8 +170,7 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - enableTextOverlay = true; - title = "Vulkan Example - Deferred shading with shadows (2016 by Sascha Willems)"; + title = "Deferred shading with shadows"; camera.type = Camera::CameraType::firstperson; #if defined(__ANDROID__) camera.movementSpeed = 2.5f; @@ -184,6 +183,7 @@ public: camera.setPerspective(60.0f, (float)width / (float)height, zNear, zFar); timerSpeed *= 0.25f; paused = true; + settings.overlay = true; } ~VulkanExample() @@ -1170,46 +1170,20 @@ public: updateUniformBufferDeferredMatrices(); } - void toggleDebugDisplay() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - debugDisplay = !debugDisplay; - reBuildCommandBuffers(); - updateUniformBuffersScreen(); - } - - void toggleShadows() - { - uboFragmentLights.useShadows = !uboFragmentLights.useShadows; - updateUniformBufferDeferredLights(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_F1: - case GAMEPAD_BUTTON_A: - toggleDebugDisplay(); - updateTextOverlay(); - break; - case KEY_F2: - case GAMEPAD_BUTTON_X: - toggleShadows(); - updateTextOverlay(); - break; + if (overlay->header("Settings")) { + if (overlay->checkBox("Display shadow targets", &debugDisplay)) { + buildCommandBuffers(); + updateUniformBuffersScreen(); + } + bool shadows = (uboFragmentLights.useShadows == 1); + if (overlay->checkBox("Shadows", &shadows)) { + uboFragmentLights.useShadows = shadows; + updateUniformBufferDeferredLights(); + } } } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("Press \"Button A\" to toggle debug view", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"Button X\" to toggle shadows", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Press \"F1\" to toggle debug view", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"F2\" to toggle shadows", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); -#endif - } }; VULKAN_EXAMPLE_MAIN() diff --git a/displacement/displacement.cpp b/displacement/displacement.cpp index 5ce1bbce..07d0a0f6 100644 --- a/displacement/displacement.cpp +++ b/displacement/displacement.cpp @@ -83,8 +83,8 @@ public: { zoom = -1.25f; rotation = glm::vec3(-20.0f, 45.0f, 0.0f); - enableTextOverlay = true; - title = "Vulkan Example - Tessellation shader displacement mapping"; + title = "Tessellation shader displacement"; + settings.overlay = true; } ~VulkanExample() @@ -142,16 +142,6 @@ public: } } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); @@ -543,77 +533,26 @@ public: updateUniformBuffers(); } - void changeTessellationLevel(float delta) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - uboTessControl.tessLevel += delta; - uboTessControl.tessLevel = fmax(1.0f, fmin(uboTessControl.tessLevel, 32.0f)); - updateUniformBuffers(); - updateTextOverlay(); - } - - void changeTessellationStrength(float delta) - { - uboTessEval.tessStrength += delta; - uboTessEval.tessStrength = fmax(0.0f, fmin(uboTessEval.tessStrength, 1.0f)); - updateUniformBuffers(); - updateTextOverlay(); - } - - void toggleSplitScreen() - { - splitScreen = !splitScreen; - reBuildCommandBuffers(); - updateUniformBuffers(); - } - - void toggleDisplacement() - { - displacement = !displacement; - updateUniformBuffers(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeTessellationStrength(0.025f); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeTessellationStrength(-0.025f); - break; - case KEY_D: - case GAMEPAD_BUTTON_A: - toggleDisplacement(); - break; - case KEY_S: - case GAMEPAD_BUTTON_X: + if (overlay->header("Settings")) { + if (overlay->checkBox("Tessellation displacement", &displacement)) { + updateUniformBuffers(); + } + if (overlay->inputFloat("Strength", &uboTessEval.tessStrength, 0.025f, 3)) { + updateUniformBuffers(); + } + if (overlay->inputFloat("Level", &uboTessControl.tessLevel, 0.5f, 2)) { + updateUniformBuffers(); + } if (deviceFeatures.fillModeNonSolid) { - toggleSplitScreen(); - }; - break; - } - } + if (overlay->checkBox("Splitscreen", &splitScreen)) { + buildCommandBuffers(); + updateUniformBuffers(); + } + } - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - std::stringstream ss; - ss << std::setprecision(2) << std::fixed << uboTessEval.tessStrength; -#if defined(__ANDROID__) - textOverlay->addText("Tessellation height: " + ss.str() + " (Buttons L1/R1)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"Button A\" to toggle displacement", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - if (deviceFeatures.fillModeNonSolid) { - textOverlay->addText("\"Button X\" to toggle splitscreen", 5.0f, 115.0f, VulkanTextOverlay::alignLeft); } -#else - textOverlay->addText("Tessellation height: " + ss.str() + " (numpad +/-)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"d\" to toggle displacement", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - if (deviceFeatures.fillModeNonSolid) { - textOverlay->addText("\"s\" to toggle splitscreen", 5.0f, 115.0f, VulkanTextOverlay::alignLeft); - } -#endif } }; diff --git a/distancefieldfonts/distancefieldfonts.cpp b/distancefieldfonts/distancefieldfonts.cpp index 97c58877..1703de2a 100644 --- a/distancefieldfonts/distancefieldfonts.cpp +++ b/distancefieldfonts/distancefieldfonts.cpp @@ -112,8 +112,8 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { zoom = -2.0f; - enableTextOverlay = true; - title = "Vulkan Example - Distance field fonts"; + title = "Distance field font rendering"; + settings.overlay = true; } ~VulkanExample() @@ -670,9 +670,7 @@ public: { if (!prepared) return; - vkDeviceWaitIdle(device); draw(); - vkDeviceWaitIdle(device); } virtual void viewChanged() @@ -680,45 +678,20 @@ public: updateUniformBuffers(); } - void toggleSplitScreen() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - splitScreen = !splitScreen; - reBuildCommandBuffers(); - updateUniformBuffers(); - } - - void toggleFontOutline() - { - uboFS.outline = !uboFS.outline; - updateFontSettings(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_S: - case GAMEPAD_BUTTON_X: - toggleSplitScreen(); - break; - case KEY_O: - case GAMEPAD_BUTTON_A: - toggleFontOutline(); - break; - + if (overlay->header("Settings")) { + bool outline = (uboFS.outline == 1.0f); + if (overlay->checkBox("Outline", &outline)) { + uboFS.outline = outline ? 1.0f : 0.0f; + updateFontSettings(); + } + if (overlay->checkBox("Splitscreen", &splitScreen)) { + buildCommandBuffers(); + updateUniformBuffers(); + } } } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("\"Button A\" to toggle outline", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"Button X\" to toggle splitscreen", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("\"o\" to toggle outline", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"s\" to toggle splitscreen", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); -#endif - } }; VULKAN_EXAMPLE_MAIN() \ No newline at end of file diff --git a/dynamicuniformbuffer/dynamicuniformbuffer.cpp b/dynamicuniformbuffer/dynamicuniformbuffer.cpp index 116a76c2..a30b02bd 100644 --- a/dynamicuniformbuffer/dynamicuniformbuffer.cpp +++ b/dynamicuniformbuffer/dynamicuniformbuffer.cpp @@ -113,11 +113,11 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { title = "Vulkan Example - Dynamic uniform buffers"; - enableTextOverlay = true; camera.type = Camera::CameraType::lookat; camera.setPosition(glm::vec3(0.0f, 0.0f, -30.0f)); camera.setRotation(glm::vec3(0.0f)); camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f); + settings.overlay = true; } ~VulkanExample() diff --git a/gears/gears.cpp b/gears/gears.cpp index 06239a57..ca17de89 100644 --- a/gears/gears.cpp +++ b/gears/gears.cpp @@ -45,10 +45,10 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { zoom = -16.0f; - rotation = glm::vec3(-23.75, 41.25, 21.0); + rotation = glm::vec3(-23.75f, 41.25f, 21.0f); timerSpeed *= 0.25f; - enableTextOverlay = true; - title = "Vulkan Example - Gears"; + title = "Rotating gears"; + settings.overlay = true; } ~VulkanExample() diff --git a/geometryshader/geometryshader.cpp b/geometryshader/geometryshader.cpp index 8728f2f9..6304d58b 100644 --- a/geometryshader/geometryshader.cpp +++ b/geometryshader/geometryshader.cpp @@ -74,8 +74,8 @@ public: { zoom = -8.0f; rotation = glm::vec3(0.0f, -25.0f, 0.0f); - enableTextOverlay = true; - title = "Vulkan Example - Geometry shader"; + title = "Geometry shader normal debugging"; + settings.overlay = true; } ~VulkanExample() @@ -470,32 +470,15 @@ public: updateUniformBuffers(); } - void toggleNormals() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - displayNormals = !displayNormals; - reBuildCommandBuffers(); - } - - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_N: - case GAMEPAD_BUTTON_A: - toggleNormals(); - break; + if (overlay->header("Settings")) { + if (overlay->checkBox("Display normals", &displayNormals)) { + buildCommandBuffers(); + } } } - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("Press \"Button A\" to toggle normals", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Press \"n\" to toggle normals", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif - } }; VULKAN_EXAMPLE_MAIN() \ No newline at end of file diff --git a/hdr/hdr.cpp b/hdr/hdr.cpp index 1ce7ad22..8c25082d 100644 --- a/hdr/hdr.cpp +++ b/hdr/hdr.cpp @@ -49,7 +49,7 @@ public: struct Models { vks::Model skybox; std::vector objects; - uint32_t objectIndex = 1; + int32_t objectIndex = 1; } models; struct { @@ -124,14 +124,16 @@ public: VkSampler sampler; } filterPass; + std::vector objectNames; + VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - HDR rendering"; - enableTextOverlay = true; + title = "Hight dynamic range rendering"; camera.type = Camera::CameraType::lookat; camera.setPosition(glm::vec3(0.0f, 0.0f, -4.0f)); camera.setRotation(glm::vec3(0.0f, 180.0f, 0.0f)); camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f); + settings.overlay = true; } ~VulkanExample() @@ -604,6 +606,7 @@ public: // Models models.skybox.loadFromFile(getAssetPath() + "models/cube.obj", vertexLayout, 0.05f, vulkanDevice, queue); std::vector filenames = { "geosphere.obj", "teapot.dae", "torusknot.obj", "venus.fbx" }; + objectNames = { "Sphere", "Teapot", "Torusknot", "Venus" }; for (auto file : filenames) { vks::Model model; model.loadFromFile(getAssetPath() + "models/" + file, vertexLayout, 0.05f * (file == "venus.fbx" ? 3.0f : 1.0f), vulkanDevice, queue); @@ -983,74 +986,23 @@ public: updateUniformBuffers(); } - void toggleSkyBox() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - displaySkybox = !displaySkybox; - reBuildCommandBuffers(); - } - - void toggleBloom() - { - bloom = !bloom; - reBuildCommandBuffers(); - } - - void toggleObject() - { - models.objectIndex++; - if (models.objectIndex >= static_cast(models.objects.size())) - { - models.objectIndex = 0; + if (overlay->header("Settings")) { + if (overlay->comboBox("Object type", &models.objectIndex, objectNames)) { + updateUniformBuffers(); + buildDeferredCommandBuffer(); + } + if (overlay->inputFloat("Exposure", &uboParams.exposure, 0.025f, 3)) { + updateParams(); + } + if (overlay->checkBox("Bloom", &bloom)) { + buildCommandBuffers(); + } + if (overlay->checkBox("Skybox", &displaySkybox)) { + buildDeferredCommandBuffer(); + } } - reBuildCommandBuffers(); - } - - void changeExposure(float delta) - { - uboParams.exposure += delta; - if (uboParams.exposure < 0.0f) { - uboParams.exposure = 0.0f; - } - updateParams(); - updateTextOverlay(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_B: - case GAMEPAD_BUTTON_Y: - toggleBloom(); - break; - case KEY_S: - case GAMEPAD_BUTTON_A: - toggleSkyBox(); - break; - case KEY_SPACE: - case GAMEPAD_BUTTON_X: - toggleObject(); - break; - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeExposure(0.05f); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeExposure(-0.05f); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - std::stringstream ss; - ss << std::setprecision(2) << std::fixed << uboParams.exposure; -#if defined(__ANDROID__) - textOverlay->addText("Exposure: " + ss.str() + " (L1/R1)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Exposure: " + ss.str() + " (+/-)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif } }; diff --git a/indirectdraw/indirectdraw.cpp b/indirectdraw/indirectdraw.cpp index 77bede2b..54d8118e 100644 --- a/indirectdraw/indirectdraw.cpp +++ b/indirectdraw/indirectdraw.cpp @@ -123,13 +123,13 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - enableTextOverlay = true; - title = "Vulkan Example - Indirect rendering"; + title = "Indirect rendering"; camera.type = Camera::CameraType::firstperson; camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f); camera.setRotation(glm::vec3(-12.0f, 159.0f, 0.0f)); camera.setTranslation(glm::vec3(0.4f, 1.25f, 0.0f)); camera.movementSpeed = 5.0f; + settings.overlay = true; } ~VulkanExample() @@ -694,12 +694,15 @@ public: updateUniformBuffer(true); } - virtual void getOverlayText(VulkanTextOverlay *textOverlay) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - textOverlay->addText(std::to_string(objectCount) + " objects", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - if (!vulkanDevice->features.multiDrawIndirect) - { - textOverlay->addText("multiDrawIndirect not supported", 5.0f, 105.0f, VulkanTextOverlay::alignLeft); + if (!vulkanDevice->features.multiDrawIndirect) { + if (overlay->header("Info")) { + overlay->text("multiDrawIndirect not supported"); + } + } + if (overlay->header("Statistics")) { + overlay->text("Objects: %d", objectCount); } } }; diff --git a/instancing/instancing.cpp b/instancing/instancing.cpp index 4ba8e38d..4cfeef5d 100644 --- a/instancing/instancing.cpp +++ b/instancing/instancing.cpp @@ -93,13 +93,13 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Instanced mesh rendering"; - enableTextOverlay = true; + title = "Instanced mesh rendering"; srand(time(NULL)); zoom = -18.5f; rotation = { -17.2f, -4.7f, 0.0f }; cameraPos = { 5.5f, -1.85f, 0.0f }; rotationSpeed = 0.25f; + settings.overlay = true; } ~VulkanExample() @@ -606,9 +606,11 @@ public: updateUniformBuffer(true); } - virtual void getOverlayText(VulkanTextOverlay *textOverlay) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - textOverlay->addText("Rendering " + std::to_string(INSTANCE_COUNT) + " instances", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); + if (overlay->header("Statistics")) { + overlay->text("Instances: %d", INSTANCE_COUNT); + } } }; diff --git a/mesh/mesh.cpp b/mesh/mesh.cpp index 84263896..a8a90cf3 100644 --- a/mesh/mesh.cpp +++ b/mesh/mesh.cpp @@ -102,8 +102,8 @@ public: rotationSpeed = 0.5f; rotation = { -0.5f, -112.75f, 0.0f }; cameraPos = { 0.1f, 1.1f, 0.0f }; - enableTextOverlay = true; - title = "Vulkan Example - Model rendering"; + title = "Model rendering"; + settings.overlay = true; } ~VulkanExample() @@ -132,16 +132,6 @@ public: }; } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); @@ -663,28 +653,12 @@ public: updateUniformBuffers(); } - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case KEY_W: - case GAMEPAD_BUTTON_A: - if (deviceFeatures.fillModeNonSolid) { - wireframe = !wireframe; - reBuildCommandBuffers(); + if (overlay->header("Settings")) { + if (overlay->checkBox("Wireframe", &wireframe)) { + buildCommandBuffers(); } - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - if (deviceFeatures.fillModeNonSolid) { -#if defined(__ANDROID__) - textOverlay->addText("Press \"Button A\" to toggle wireframe", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Press \"w\" to toggle wireframe", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif } } }; diff --git a/multithreading/multithreading.cpp b/multithreading/multithreading.cpp index ffce24af..099b87db 100644 --- a/multithreading/multithreading.cpp +++ b/multithreading/multithreading.cpp @@ -124,8 +124,8 @@ public: zoomSpeed = 2.5f; rotationSpeed = 0.5f; rotation = { 0.0f, 37.5f, 0.0f }; - enableTextOverlay = true; - title = "Vulkan Example - Multi threaded rendering"; + title = "Multi threaded command buffer"; + settings.overlay = true; // Get number of max. concurrrent threads numThreads = std::thread::hardware_concurrency(); assert(numThreads > 0); @@ -630,9 +630,11 @@ public: updateMatrices(); } - virtual void getOverlayText(VulkanTextOverlay *textOverlay) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - textOverlay->addText("Using " + std::to_string(numThreads) + " threads", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); + if (overlay->header("Statistics")) { + overlay->text("Active threads: %d", numThreads); + } } }; diff --git a/occlusionquery/occlusionquery.cpp b/occlusionquery/occlusionquery.cpp index 693c1c01..58b075f6 100644 --- a/occlusionquery/occlusionquery.cpp +++ b/occlusionquery/occlusionquery.cpp @@ -94,8 +94,8 @@ public: zoomSpeed = 2.5f; rotationSpeed = 0.5f; rotation = { 0.0, -123.75, 0.0 }; - enableTextOverlay = true; - title = "Vulkan Example - Occlusion queries"; + title = "Occlusion queries"; + settings.overlay = true; } ~VulkanExample() @@ -624,17 +624,17 @@ public: virtual void viewChanged() { - vkDeviceWaitIdle(device); updateUniformBuffers(); - VulkanExampleBase::updateTextOverlay(); } - virtual void getOverlayText(VulkanTextOverlay *textOverlay) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - textOverlay->addText("Occlusion queries:", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Teapot: " + std::to_string(passedSamples[0]) + " samples passed" , 5.0f, 105.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Sphere: " + std::to_string(passedSamples[1]) + " samples passed", 5.0f, 125.0f, VulkanTextOverlay::alignLeft); + if (overlay->header("Occlusion query results")) { + overlay->text("Teapot: %d samples passed", passedSamples[0]); + overlay->text("Sphere: %d samples passed", passedSamples[1]); + } } + }; VULKAN_EXAMPLE_MAIN() \ No newline at end of file diff --git a/offscreen/offscreen.cpp b/offscreen/offscreen.cpp index e068677e..32996a09 100644 --- a/offscreen/offscreen.cpp +++ b/offscreen/offscreen.cpp @@ -123,8 +123,8 @@ public: rotation = { -2.5f, 0.0f, 0.0f }; cameraPos = { 0.0f, 1.0f, 0.0f }; timerSpeed *= 0.25f; - enableTextOverlay = true; - title = "Vulkan Example - Offscreen rendering"; + title = "Offscreen rendering"; + settings.overlay = true; enabledFeatures.shaderClipDistance = VK_TRUE; } @@ -399,16 +399,6 @@ public: VK_CHECK_RESULT(vkEndCommandBuffer(offscreenPass.commandBuffer)); } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); @@ -992,31 +982,14 @@ public: updateUniformBufferOffscreen(); } - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case KEY_D: - case GAMEPAD_BUTTON_A: - toggleDebugDisplay(); - break; + if (overlay->header("Settings")) { + if (overlay->checkBox("Display render target", &debugDisplay)) { + buildCommandBuffers(); + } } } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("Press \"Button A\" to display offscreen target", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Press \"d\" to display offscreen target", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif - } - - void toggleDebugDisplay() - { - debugDisplay = !debugDisplay; - reBuildCommandBuffers(); - } }; VULKAN_EXAMPLE_MAIN() diff --git a/parallaxmapping/parallaxmapping.cpp b/parallaxmapping/parallaxmapping.cpp index a7680646..69769bd2 100644 --- a/parallaxmapping/parallaxmapping.cpp +++ b/parallaxmapping/parallaxmapping.cpp @@ -81,15 +81,23 @@ public: VkDescriptorSetLayout descriptorSetLayout; VkDescriptorSet descriptorSet; + const std::vector mappingModes = { + "Color only", + "Normal mapping", + "Parallax mapping", + "Steep parallax mapping", + "Parallax occlusion mapping", + }; + VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Parallax Mapping"; - enableTextOverlay = true; + title = "Parallax Mapping"; timerSpeed *= 0.5f; camera.type = Camera::CameraType::firstperson; camera.setPosition(glm::vec3(0.0f, 1.25f, 1.5f)); camera.setRotation(glm::vec3(-45.0f, 180.0f, 0.0f)); camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f); + settings.overlay = true; } ~VulkanExample() @@ -386,39 +394,15 @@ public: updateUniformBuffers(); } - void toggleMappingMode() - { - ubos.fragmentShader.mappingMode++; - if (ubos.fragmentShader.mappingMode > 4) { - ubos.fragmentShader.mappingMode = 0; - }; - updateUniformBuffers(); - updateTextOverlay(); - } - - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case KEY_SPACE: - case GAMEPAD_BUTTON_A: - case TOUCH_DOUBLE_TAP: - toggleMappingMode(); - break; + if (overlay->header("Settings")) { + if (overlay->comboBox("Mode", &ubos.fragmentShader.mappingMode, mappingModes)) { + updateUniformBuffers(); + } } } - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - const std::vector mappingModes = { - "Color only", "Normal mapping", "Parallax mapping", "Steep parallax mapping", "Parallax occlusion mapping", - }; -#if defined(__ANDROID__) - textOverlay->addText("Mode: " + mappingModes[ubos.fragmentShader.mappingMode] + " (\"Button A\")", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Mode: " + mappingModes[ubos.fragmentShader.mappingMode] + " (\"Space\")", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif - } }; VULKAN_EXAMPLE_MAIN() \ No newline at end of file diff --git a/particlefire/particlefire.cpp b/particlefire/particlefire.cpp index 57714c27..cc8ae109 100644 --- a/particlefire/particlefire.cpp +++ b/particlefire/particlefire.cpp @@ -127,8 +127,8 @@ public: { zoom = -75.0f; rotation = { -15.0f, 45.0f, 0.0f }; - enableTextOverlay = true; - title = "Vulkan Example - CPU particle system"; + title = "CPU based particle system"; + settings.overlay = true; zoomSpeed *= 1.5f; timerSpeed *= 8.0f; srand(time(NULL)); diff --git a/pbrbasic/pbrbasic.cpp b/pbrbasic/pbrbasic.cpp index d646984c..b94cc756 100644 --- a/pbrbasic/pbrbasic.cpp +++ b/pbrbasic/pbrbasic.cpp @@ -62,7 +62,7 @@ public: struct Meshes { vks::Model skybox; std::vector objects; - uint32_t objectIndex = 0; + int32_t objectIndex = 0; } models; struct { @@ -91,10 +91,12 @@ public: std::vector materials; int32_t materialIndex = 0; + std::vector materialNames; + std::vector objectNames; + VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Physical based shading basics"; - enableTextOverlay = true; + title = "Physical based shading basics"; camera.type = Camera::CameraType::firstperson; camera.setPosition(glm::vec3(10.0f, 13.0f, 1.8f)); camera.setRotation(glm::vec3(-62.5f, 90.0f, 0.0f)); @@ -103,6 +105,7 @@ public: camera.rotationSpeed = 0.25f; paused = true; timerSpeed *= 0.25f; + settings.overlay = true; // Setup some default materials (source: https://seblagarde.wordpress.com/2011/08/17/feeding-a-physical-based-lighting-mode/) materials.push_back(Material("Gold", glm::vec3(1.0f, 0.765557f, 0.336057f), 0.1f, 1.0f)); @@ -118,6 +121,11 @@ public: materials.push_back(Material("Blue", glm::vec3(0.0f, 0.0f, 1.0f), 0.1f, 1.0f)); materials.push_back(Material("Black", glm::vec3(0.0f), 0.1f, 1.0f)); + for (auto material : materials) { + materialNames.push_back(material.name); + } + objectNames = { "Sphere", "Teapot", "Torusknot", "Venus" }; + materialIndex = 0; } @@ -454,61 +462,19 @@ public: virtual void viewChanged() { updateUniformBuffers(); - updateTextOverlay(); } - void toggleObject() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - models.objectIndex++; - if (models.objectIndex >= static_cast(models.objects.size())) - { - models.objectIndex = 0; + if (overlay->header("Settings")) { + if (overlay->comboBox("Material", &materialIndex, materialNames)) { + buildCommandBuffers(); + } + if (overlay->comboBox("Object type", &models.objectIndex, objectNames)) { + updateUniformBuffers(); + buildCommandBuffers(); + } } - updateUniformBuffers(); - buildCommandBuffers(); - } - - void toggleMaterial(int32_t dir) - { - materialIndex += dir; - if (materialIndex < 0) { - materialIndex = static_cast(materials.size()) - 1; - } - if (materialIndex > static_cast(materials.size()) - 1) { - materialIndex = 0; - } - buildCommandBuffers(); - updateTextOverlay(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_SPACE: - case GAMEPAD_BUTTON_X: - toggleObject(); - break; - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - toggleMaterial(1); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - toggleMaterial(-1); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("Base material: " + materials[materialIndex].name + " (L1/R1)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"X\" to toggle object", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Base material: " + materials[materialIndex].name + " (-/+)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"space\" to toggle object", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); -#endif } }; diff --git a/pbribl/pbribl.cpp b/pbribl/pbribl.cpp index e7c2501a..fec3bf34 100644 --- a/pbribl/pbribl.cpp +++ b/pbribl/pbribl.cpp @@ -73,7 +73,7 @@ public: struct Meshes { vks::Model skybox; std::vector objects; - uint32_t objectIndex = 0; + int32_t objectIndex = 0; } models; struct { @@ -112,11 +112,13 @@ public: std::vector materials; int32_t materialIndex = 0; + std::vector materialNames; + std::vector objectNames; + VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - PBR with image based lighting"; + title = "PBR with image based lighting"; - enableTextOverlay = true; camera.type = Camera::CameraType::firstperson; camera.movementSpeed = 4.0f; camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f); @@ -140,6 +142,13 @@ public: materials.push_back(Material("Red", glm::vec3(1.0f, 0.0f, 0.0f))); materials.push_back(Material("Blue", glm::vec3(0.0f, 0.0f, 1.0f))); + settings.overlay = true; + + for (auto material : materials) { + materialNames.push_back(material.name); + } + objectNames = { "Sphere", "Teapot", "Torusknot", "Venus" }; + materialIndex = 9; } @@ -257,15 +266,15 @@ public: void loadAssets() { // Skybox - models.skybox.loadFromFile(ASSET_PATH "models/cube.obj", vertexLayout, 1.0f, vulkanDevice, queue); + models.skybox.loadFromFile(getAssetPath() + "models/cube.obj", vertexLayout, 1.0f, vulkanDevice, queue); // Objects std::vector filenames = { "geosphere.obj", "teapot.dae", "torusknot.obj", "venus.fbx" }; for (auto file : filenames) { vks::Model model; - model.loadFromFile(ASSET_PATH "models/" + file, vertexLayout, 0.05f * (file == "venus.fbx" ? 3.0f : 1.0f), vulkanDevice, queue); + model.loadFromFile(getAssetPath() + "models/" + file, vertexLayout, 0.05f * (file == "venus.fbx" ? 3.0f : 1.0f), vulkanDevice, queue); models.objects.push_back(model); } - textures.environmentCube.loadFromFile(ASSET_PATH "textures/hdr/pisa_cube.ktx", VK_FORMAT_R16G16B16A16_SFLOAT, vulkanDevice, queue); + textures.environmentCube.loadFromFile(getAssetPath() + "textures/hdr/pisa_cube.ktx", VK_FORMAT_R16G16B16A16_SFLOAT, vulkanDevice, queue); } void setupDescriptors() @@ -391,13 +400,13 @@ public: pipelineCreateInfo.pVertexInputState = &vertexInputState; // Skybox pipeline (background cube) - shaderStages[0] = loadShader(ASSET_PATH "shaders/pbribl/skybox.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - shaderStages[1] = loadShader(ASSET_PATH "shaders/pbribl/skybox.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + shaderStages[0] = loadShader(getAssetPath() + "shaders/pbribl/skybox.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shaderStages[1] = loadShader(getAssetPath() + "shaders/pbribl/skybox.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.skybox)); // PBR pipeline - shaderStages[0] = loadShader(ASSET_PATH "shaders/pbribl/pbribl.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - shaderStages[1] = loadShader(ASSET_PATH "shaders/pbribl/pbribl.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + shaderStages[0] = loadShader(getAssetPath() + "shaders/pbribl/pbribl.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shaderStages[1] = loadShader(getAssetPath() + "shaders/pbribl/pbribl.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); // Enable depth test and write depthStencilState.depthWriteEnable = VK_TRUE; depthStencilState.depthTestEnable = VK_TRUE; @@ -566,8 +575,8 @@ public: pipelineCI.pVertexInputState = &emptyInputState; // Look-up-table (from BRDF) pipeline - shaderStages[0] = loadShader(ASSET_PATH "shaders/pbribl/genbrdflut.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - shaderStages[1] = loadShader(ASSET_PATH "shaders/pbribl/genbrdflut.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + shaderStages[0] = loadShader(getAssetPath() + "shaders/pbribl/genbrdflut.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shaderStages[1] = loadShader(getAssetPath() + "shaders/pbribl/genbrdflut.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); VkPipeline pipeline; VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipeline)); @@ -852,8 +861,8 @@ public: pipelineCI.pVertexInputState = &vertexInputState; pipelineCI.renderPass = renderpass; - shaderStages[0] = loadShader(ASSET_PATH "shaders/pbribl/filtercube.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - shaderStages[1] = loadShader(ASSET_PATH "shaders/pbribl/irradiancecube.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + shaderStages[0] = loadShader(getAssetPath() + "shaders/pbribl/filtercube.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shaderStages[1] = loadShader(getAssetPath() + "shaders/pbribl/irradiancecube.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); VkPipeline pipeline; VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipeline)); @@ -1246,8 +1255,8 @@ public: pipelineCI.pVertexInputState = &vertexInputState; pipelineCI.renderPass = renderpass; - shaderStages[0] = loadShader(ASSET_PATH "shaders/pbribl/filtercube.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - shaderStages[1] = loadShader(ASSET_PATH "shaders/pbribl/prefilterenvmap.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + shaderStages[0] = loadShader(getAssetPath() + "shaders/pbribl/filtercube.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shaderStages[1] = loadShader(getAssetPath() + "shaders/pbribl/prefilterenvmap.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); VkPipeline pipeline; VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipeline)); @@ -1491,90 +1500,30 @@ public: virtual void viewChanged() { updateUniformBuffers(); - updateTextOverlay(); } - void toggleSkyBox() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - displaySkybox = !displaySkybox; - buildCommandBuffers(); - } - - void toggleObject() - { - models.objectIndex++; - if (models.objectIndex >= static_cast(models.objects.size())) - { - models.objectIndex = 0; - } - updateUniformBuffers(); - buildCommandBuffers(); - } - - void toggleMaterial(int32_t dir) - { - materialIndex += dir; - if (materialIndex < 0) { - materialIndex = static_cast(materials.size()) - 1; - } - if (materialIndex > static_cast(materials.size()) - 1) { - materialIndex = 0; - } - buildCommandBuffers(); - updateTextOverlay(); - } - - void changeExposure(float delta) - { - uboParams.exposure += delta; - if (uboParams.exposure < 0.01f) { - uboParams.exposure = 0.01f; - } - updateParams(); - updateTextOverlay(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_F2: - case GAMEPAD_BUTTON_A: - toggleSkyBox(); - break; - case KEY_SPACE: - case GAMEPAD_BUTTON_X: - toggleObject(); - break; - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - case TOUCH_DOUBLE_TAP: - toggleMaterial(1); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - toggleMaterial(-1); - break; - case KEY_F3: - changeExposure(-0.1f); - break; - case KEY_F4: - changeExposure(0.1f); - break; - + if (overlay->header("Settings")) { + if (overlay->comboBox("Material", &materialIndex, materialNames)) { + buildCommandBuffers(); + } + if (overlay->comboBox("Object type", &models.objectIndex, objectNames)) { + updateUniformBuffers(); + buildCommandBuffers(); + } + if (overlay->inputFloat("Exposure", &uboParams.exposure, 0.1f, 2)) { + updateParams(); + } + if (overlay->inputFloat("Gamma", &uboParams.gamma, 0.1f, 2)) { + updateParams(); + } + if (overlay->checkBox("Skybox", &displaySkybox)) { + buildCommandBuffers(); + } } } - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("\"Button A\" to toggle skybox", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"Button X\" to toggle object", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Material: " + materials[materialIndex].name + " (+/-)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Exposure: " + std::to_string(uboParams.exposure) + " (F3/F4)", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); -#endif - } }; VULKAN_EXAMPLE_MAIN() \ No newline at end of file diff --git a/pbrtexture/main.cpp b/pbrtexture/main.cpp index 25fe1bcb..5738d526 100644 --- a/pbrtexture/main.cpp +++ b/pbrtexture/main.cpp @@ -97,9 +97,8 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Textured PBR with IBL"; + title = "Textured PBR with IBL"; - enableTextOverlay = true; camera.type = Camera::CameraType::firstperson; camera.movementSpeed = 4.0f; camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f); @@ -107,6 +106,8 @@ public: camera.setRotation({ -10.75f, 153.0f, 0.0f }); camera.setPosition({ 1.85f, 0.5f, 5.0f }); + + settings.overlay = true; } ~VulkanExample() @@ -1440,67 +1441,21 @@ public: virtual void viewChanged() { updateUniformBuffers(); - updateTextOverlay(); } - void toggleSkyBox() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - displaySkybox = !displaySkybox; - buildCommandBuffers(); - } - - void changeExposure(float delta) - { - uboParams.exposure += delta; - if (uboParams.exposure < 0.01f) { - uboParams.exposure = 0.01f; + if (overlay->header("Settings")) { + if (overlay->inputFloat("Exposure", &uboParams.exposure, 0.1f, 2)) { + updateParams(); + } + if (overlay->inputFloat("Gamma", &uboParams.gamma, 0.1f, 2)) { + updateParams(); + } + if (overlay->checkBox("Skybox", &displaySkybox)) { + buildCommandBuffers(); + } } - updateParams(); - updateTextOverlay(); - } - - void changeGamma(float delta) - { - uboParams.gamma += delta; - if (uboParams.gamma < 0.01f) { - uboParams.gamma = 0.01f; - } - updateParams(); - updateTextOverlay(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_F2: - case GAMEPAD_BUTTON_A: - toggleSkyBox(); - break; - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeExposure(0.1f); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeExposure(-0.1f); - break; - case KEY_F3: - changeGamma(-0.1f); - break; - case KEY_F4: - changeGamma(0.1f); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) -#else - textOverlay->addText("Exposure: " + std::to_string(uboParams.exposure) + " (-/+)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Gamma: " + std::to_string(uboParams.gamma) + " (F3/F4)", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); -#endif } }; diff --git a/pipelines/pipelines.cpp b/pipelines/pipelines.cpp index 217eb5eb..fe45aa61 100644 --- a/pipelines/pipelines.cpp +++ b/pipelines/pipelines.cpp @@ -63,8 +63,8 @@ public: { zoom = -10.5f; rotation = glm::vec3(-25.0f, 15.0f, 0.0f); - enableTextOverlay = true; - title = "Vulkan Example - Pipeline state objects"; + title = "Pipeline state objects"; + settings.overlay = true; } ~VulkanExample() @@ -425,13 +425,12 @@ public: updateUniformBuffers(); } - virtual void getOverlayText(VulkanTextOverlay *textOverlay) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - textOverlay->addText("Phong shading pipeline",(float)width / 6.0f, height - 35.0f, VulkanTextOverlay::alignCenter); - textOverlay->addText("Toon shading pipeline", (float)width / 2.0f, height - 35.0f, VulkanTextOverlay::alignCenter); - textOverlay->addText("Wireframe pipeline", width - (float)width / 6.5f, height - 35.0f, VulkanTextOverlay::alignCenter); if (!deviceFeatures.fillModeNonSolid) { - textOverlay->addText("Non solid fill modes not supported!", width - (float)width / 6.5f, (float)height / 2.0f - 7.5f, VulkanTextOverlay::alignCenter); + if (overlay->header("Info")) { + overlay->text("Non solid fill modes not supported!"); + } } } }; diff --git a/pushconstants/pushconstants.cpp b/pushconstants/pushconstants.cpp index 699bf247..534bd16f 100644 --- a/pushconstants/pushconstants.cpp +++ b/pushconstants/pushconstants.cpp @@ -73,8 +73,8 @@ public: rotationSpeed = 0.5f; timerSpeed *= 0.5f; rotation = { -32.5, 45.0, 0.0 }; - enableTextOverlay = true; - title = "Vulkan Example - Push constants"; + title = "Push constants"; + settings.overlay = true; } ~VulkanExample() diff --git a/radialblur/radialblur.cpp b/radialblur/radialblur.cpp index 095b9440..88cd29e6 100644 --- a/radialblur/radialblur.cpp +++ b/radialblur/radialblur.cpp @@ -120,8 +120,8 @@ public: zoom = -10.0f; rotation = { -16.25f, -28.75f, 0.0f }; timerSpeed *= 0.5f; - enableTextOverlay = true; - title = "Vulkan Example - Radial blur"; + title = "Full screen radial blur effect"; + settings.overlay = true; } ~VulkanExample() @@ -386,16 +386,6 @@ public: VK_CHECK_RESULT(vkEndCommandBuffer(offscreenPass.commandBuffer)); } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); @@ -835,44 +825,17 @@ public: updateUniformBuffersScene(); } - void toggleBlur() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - blur = !blur; - updateUniformBuffersScene(); - reBuildCommandBuffers(); - } - - void toggleTextureDisplay() - { - displayTexture = !displayTexture; - reBuildCommandBuffers(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_B: - case GAMEPAD_BUTTON_A: - toggleBlur(); - break; - case KEY_T: - case GAMEPAD_BUTTON_X: - toggleTextureDisplay(); - break; + if (overlay->header("Settings")) { + if (overlay->checkBox("Radial blur", &blur)) { + buildCommandBuffers(); + } + if (overlay->checkBox("Dsiplay render target", &displayTexture)) { + buildCommandBuffers(); + } } } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("Press \"Button A\" to toggle blur", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"Button X\" to display offscreen texture", 5.0f, 105.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Press \"B\" to toggle blur", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"T\" to display offscreen texture", 5.0f, 105.0f, VulkanTextOverlay::alignLeft); -#endif - } }; VULKAN_EXAMPLE_MAIN() diff --git a/raytracing/raytracing.cpp b/raytracing/raytracing.cpp index b63f265f..edfaa384 100644 --- a/raytracing/raytracing.cpp +++ b/raytracing/raytracing.cpp @@ -93,8 +93,8 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Compute shader ray tracing"; - enableTextOverlay = true; + title = "Compute shader ray tracing"; + settings.overlay = true; compute.ubo.aspectRatio = (float)width / (float)height; timerSpeed *= 0.25f; diff --git a/scenerendering/scenerendering.cpp b/scenerendering/scenerendering.cpp index c3b8e5a3..392836d7 100644 --- a/scenerendering/scenerendering.cpp +++ b/scenerendering/scenerendering.cpp @@ -442,7 +442,7 @@ public: // For displaying only a single part of the scene bool renderSingleScenePart = false; - uint32_t scenePartIndex = 0; + int32_t scenePartIndex = 0; // Default constructor Scene(vks::VulkanDevice *vulkanDevice, VkQueue queue) @@ -583,14 +583,14 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Scene rendering"; + title = "Multi-part scene rendering"; rotationSpeed = 0.5f; - enableTextOverlay = true; camera.type = Camera::CameraType::firstperson; camera.movementSpeed = 7.5f; camera.position = { 15.0f, -13.5f, 0.0f }; camera.setRotation(glm::vec3(5.0f, 90.0f, 0.0f)); camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f); + settings.overlay = true; } ~VulkanExample() @@ -607,16 +607,6 @@ public: }; } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); @@ -863,55 +853,27 @@ public: updateUniformBuffers(); } - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case KEY_SPACE: - case GAMEPAD_BUTTON_A: + if (overlay->header("Settings")) { if (deviceFeatures.fillModeNonSolid) { - wireframe = !wireframe; - reBuildCommandBuffers(); + if (overlay->checkBox("Wireframe", &wireframe)) { + buildCommandBuffers(); + } } - break; - case KEY_P: - scene->renderSingleScenePart = !scene->renderSingleScenePart; - reBuildCommandBuffers(); - updateTextOverlay(); - break; - case KEY_KPADD: - scene->scenePartIndex = (scene->scenePartIndex < static_cast(scene->meshes.size())) ? scene->scenePartIndex + 1 : 0; - reBuildCommandBuffers(); - updateTextOverlay(); - break; - case KEY_KPSUB: - scene->scenePartIndex = (scene->scenePartIndex > 0) ? scene->scenePartIndex - 1 : static_cast(scene->meshes.size()) - 1; - updateTextOverlay(); - reBuildCommandBuffers(); - break; - case KEY_L: - attachLight = !attachLight; - updateUniformBuffers(); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - if (deviceFeatures.fillModeNonSolid) { -#if defined(__ANDROID__) - textOverlay->addText("Press \"Button A\" to toggle wireframe", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Press \"space\" to toggle wireframe", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - if ((scene) && (scene->renderSingleScenePart)) - { - textOverlay->addText("Rendering mesh " + std::to_string(scene->scenePartIndex + 1) + " of " + std::to_string(static_cast(scene->meshes.size())) + "(\"p\" to toggle)", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); + if (scene) { + if (overlay->checkBox("Attach light to camera", &attachLight)) { + updateUniformBuffers(); + } + if (overlay->checkBox("Render single part", &scene->renderSingleScenePart)) { + buildCommandBuffers(); + } + if (scene->renderSingleScenePart) { + if (overlay->sliderInt("Part to render", &scene->scenePartIndex, 0, static_cast(scene->meshes.size()))) { + buildCommandBuffers(); + } + } } - else - { - textOverlay->addText("Rendering whole scene (\"p\" to toggle)", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - } -#endif } } }; diff --git a/screenshot/screenshot.cpp b/screenshot/screenshot.cpp index f75df884..2bdaca0b 100644 --- a/screenshot/screenshot.cpp +++ b/screenshot/screenshot.cpp @@ -52,10 +52,12 @@ public: VkDescriptorSetLayout descriptorSetLayout; VkDescriptorSet descriptorSet; + bool screenshotSaved = false; + VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Screenshot"; - enableTextOverlay = true; + title = "Saving framebuffer to screenshot"; + settings.overlay = true; camera.type = Camera::CameraType::lookat; camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f); @@ -305,6 +307,8 @@ public: // Note: This requires the swapchain images to be created with the VK_IMAGE_USAGE_TRANSFER_SRC_BIT flag (see VulkanSwapChain::create) void saveScreenshot(const char *filename) { + screenshotSaved = false; + // Get format properties for the swapchain color format VkFormatProperties formatProps; @@ -513,6 +517,8 @@ public: vkUnmapMemory(device, dstImageMemory); vkFreeMemory(device, dstImageMemory, nullptr); vkDestroyImage(device, dstImage, nullptr); + + screenshotSaved = true; } void draw() @@ -551,25 +557,18 @@ public: updateUniformBuffers(); } - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case KEY_F2: - case GAMEPAD_BUTTON_A: - saveScreenshot("screenshot.ppm"); - break; + if (overlay->header("Functions")) { + if (overlay->button("Take screenshot")) { + saveScreenshot("screenshot.ppm"); + } + if (screenshotSaved) { + overlay->text("Screenshot saved as screenshot.ppm"); + } } } - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("\"Button A\" to save screenshot", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("\"F2\" to save screenshot", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif - } }; VULKAN_EXAMPLE_MAIN() \ No newline at end of file diff --git a/shadowmapping/shadowmapping.cpp b/shadowmapping/shadowmapping.cpp index 3470a6e1..ca655811 100644 --- a/shadowmapping/shadowmapping.cpp +++ b/shadowmapping/shadowmapping.cpp @@ -144,9 +144,9 @@ public: { zoom = -20.0f; rotation = { -15.0f, -390.0f, 0.0f }; - enableTextOverlay = true; - title = "Vulkan Example - Projected shadow mapping"; + title = "Projected shadow mapping"; timerSpeed *= 0.5f; + settings.overlay = true; } ~VulkanExample() @@ -408,12 +408,10 @@ public: VkDeviceSize offsets[1] = { 0 }; - vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.quad, 0, 1, &descriptorSet, 0, NULL); - vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.quad); - // Visualize shadow map - if (displayShadowMap) - { + if (displayShadowMap) { + vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.quad, 0, 1, &descriptorSet, 0, NULL); + vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.quad); vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &models.quad.vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], models.quad.indices.buffer, 0, VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(drawCmdBuffers[i], models.quad.indexCount, 1, 0, 0, 0); @@ -706,13 +704,8 @@ public: dynamicStateEnables.size(), 0); - // Solid rendering pipeline - // Load shaders std::array shaderStages; - shaderStages[0] = loadShader(getAssetPath() + "shaders/shadowmapping/quad.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - shaderStages[1] = loadShader(getAssetPath() + "shaders/shadowmapping/quad.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); - VkGraphicsPipelineCreateInfo pipelineCreateInfo = vks::initializers::pipelineCreateInfo( pipelineLayouts.quad, @@ -730,9 +723,14 @@ public: pipelineCreateInfo.stageCount = shaderStages.size(); pipelineCreateInfo.pStages = shaderStages.data(); + // Shadow mapping debug quad display + rasterizationState.cullMode = VK_CULL_MODE_NONE; + shaderStages[0] = loadShader(getAssetPath() + "shaders/shadowmapping/quad.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shaderStages[1] = loadShader(getAssetPath() + "shaders/shadowmapping/quad.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.quad)); // Scene rendering with shadows applied + rasterizationState.cullMode = VK_CULL_MODE_BACK_BIT; shaderStages[0] = loadShader(getAssetPath() + "shaders/shadowmapping/scene.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); shaderStages[1] = loadShader(getAssetPath() + "shaders/shadowmapping/scene.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); // Use specialization constants to select between horizontal and vertical blur @@ -925,56 +923,20 @@ public: updateUniformBuffers(); } - void toggleShadowMapDisplay() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - displayShadowMap = !displayShadowMap; - buildCommandBuffers(); - } - - void toogleLightPOV() - { - lightPOV = !lightPOV; - viewChanged(); - } - - void toogleFilterPCF() - { - filterPCF = !filterPCF; - buildCommandBuffers(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_S: - case GAMEPAD_BUTTON_A: - toggleShadowMapDisplay(); - break; - case KEY_L: - case GAMEPAD_BUTTON_X: - toogleLightPOV(); - break; - case KEY_F: - case GAMEPAD_BUTTON_Y: - toogleFilterPCF(); - break; + if (overlay->header("Settings")) { + if (overlay->checkBox("Display shadow render target", &displayShadowMap)) { + buildCommandBuffers(); + } + if (overlay->checkBox("PCF filtering", &filterPCF)) { + buildCommandBuffers(); + } + if (overlay->checkBox("Light POV", &lightPOV)) { + viewChanged(); + } } } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("\"Button A\" to toggle shadow map", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"Button X\" to toggle light's pov", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"Button Y\" to toggle PCF filtering", 5.0f, 115.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("\"s\" to toggle shadow map", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"l\" to toggle light's pov", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"f\" to toggle PCF filtering", 5.0f, 115.0f, VulkanTextOverlay::alignLeft); -#endif - } - }; VULKAN_EXAMPLE_MAIN() diff --git a/shadowmappingomni/shadowmappingomni.cpp b/shadowmappingomni/shadowmappingomni.cpp index 3782d24c..bf305c30 100644 --- a/shadowmappingomni/shadowmappingomni.cpp +++ b/shadowmappingomni/shadowmappingomni.cpp @@ -128,8 +128,8 @@ public: zoomSpeed = 10.0f; timerSpeed *= 0.25f; rotation = { -20.5f, -673.0f, 0.0f }; - enableTextOverlay = true; - title = "Vulkan Example - Point light shadows"; + title = "Point light shadows (cubemap)"; + settings.overlay = true; } ~VulkanExample() @@ -540,16 +540,6 @@ public: VK_CHECK_RESULT(vkEndCommandBuffer(offscreenPass.commandBuffer)); } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); @@ -1048,31 +1038,14 @@ public: updateUniformBuffers(); } - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case KEY_D: - case GAMEPAD_BUTTON_A: - toggleCubeMapDisplay(); - break; + if (overlay->header("Settings")) { + if (overlay->checkBox("Display shadow cube render target", &displayCubeMap)) { + buildCommandBuffers(); + } } } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("Press \"Button A\" to display depth cubemap", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Press \"d\" to display depth cubemap", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif - } - - void toggleCubeMapDisplay() - { - displayCubeMap = !displayCubeMap; - reBuildCommandBuffers(); - } }; VULKAN_EXAMPLE_MAIN() diff --git a/skeletalanimation/skeletalanimation.cpp b/skeletalanimation/skeletalanimation.cpp index b4411eee..8cd88d17 100644 --- a/skeletalanimation/skeletalanimation.cpp +++ b/skeletalanimation/skeletalanimation.cpp @@ -409,9 +409,9 @@ public: zoomSpeed = 2.5f; rotationSpeed = 0.5f; rotation = { -182.5f, -38.5f, 180.0f }; - enableTextOverlay = true; - title = "Vulkan Example - Skeletal animation"; + title = "Skeletal animation (GPU skinning)"; cameraPos = { 0.0f, 0.0f, 12.0f }; + settings.overlay = true; } ~VulkanExample() @@ -1001,14 +1001,12 @@ public: if (!paused) { runningTime += frameTimer * skinnedMesh->animationSpeed; - vkDeviceWaitIdle(device); updateUniformBuffers(false); } } virtual void viewChanged() { - vkDeviceWaitIdle(device); updateUniformBuffers(true); } @@ -1017,32 +1015,10 @@ public: skinnedMesh->animationSpeed += delta; } - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeAnimationSpeed(0.1f); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeAnimationSpeed(-0.1f); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - if (skinnedMesh != nullptr) - { - std::stringstream ss; - ss << std::setprecision(2) << std::fixed << skinnedMesh->animationSpeed; -#if defined(__ANDROID__) - textOverlay->addText("Animation speed: " + ss.str() + " (Buttons L1/R1 to change)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Animation speed: " + ss.str() + " (numpad +/- to change)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif + if (overlay->header("Settings")) { + overlay->sliderFloat("Animation speed", &skinnedMesh->animationSpeed, 0.0f, 10.0f); } } }; diff --git a/specializationconstants/specializationconstants.cpp b/specializationconstants/specializationconstants.cpp index 890ff146..6dbb44b7 100644 --- a/specializationconstants/specializationconstants.cpp +++ b/specializationconstants/specializationconstants.cpp @@ -74,12 +74,12 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Specialization constants"; - enableTextOverlay = true; + title = "Specialization constants"; camera.type = Camera::CameraType::lookat; camera.setPerspective(60.0f, ((float)width / 3.0f) / (float)height, 0.1f, 512.0f); camera.setRotation(glm::vec3(-40.0f, -90.0f, 0.0f)); camera.setTranslation(glm::vec3(0.0f, 0.0f, -2.0f)); + settings.overlay = true; } ~VulkanExample() diff --git a/sphericalenvmapping/sphericalenvmapping.cpp b/sphericalenvmapping/sphericalenvmapping.cpp index 0c15e691..b578ec07 100644 --- a/sphericalenvmapping/sphericalenvmapping.cpp +++ b/sphericalenvmapping/sphericalenvmapping.cpp @@ -77,8 +77,8 @@ public: rotationSpeed = 0.75f; zoomSpeed = 0.25f; rotation = glm::vec3(-25.0f, 23.75f, 0.0f); - enableTextOverlay = true; - title = "Vulkan Example - Spherical Environment Mapping"; + title = "Spherical Environment Mapping"; + settings.overlay = true; } ~VulkanExample() @@ -424,38 +424,15 @@ public: updateUniformBuffers(); } - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case KEY_KPADD: - case KEY_SPACE: - case GAMEPAD_BUTTON_A: - case TOUCH_DOUBLE_TAP: - changeMatCapIndex(1); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_X: - changeMatCapIndex(-1); - break; + if (overlay->header("Settings")) { + if (overlay->sliderInt("Material cap", &uboVS.texIndex, 0, textures.matCapArray.layerCount)) { + updateUniformBuffers(); + } } } - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("\"Button A\" to toggle material cap", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("\"Space\" to toggle material cap", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif - } - - void changeMatCapIndex(int32_t delta) - { - uboVS.texIndex = (uboVS.texIndex + delta + textures.matCapArray.layerCount) % textures.matCapArray.layerCount; - updateUniformBuffers(); - } - }; VULKAN_EXAMPLE_MAIN() \ No newline at end of file diff --git a/ssao/ssao.cpp b/ssao/ssao.cpp index cc76a861..6668c83e 100644 --- a/ssao/ssao.cpp +++ b/ssao/ssao.cpp @@ -68,9 +68,9 @@ public: struct UBOSSAOParams { glm::mat4 projection; - uint32_t ssao = true; - uint32_t ssaoOnly = false; - uint32_t ssaoBlur = true; + int32_t ssao = true; + int32_t ssaoOnly = false; + int32_t ssaoBlur = true; } uboSSAOParams; struct { @@ -157,10 +157,8 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - zoom = -8.0f; - rotation = { 0.0f, 0.0f, 0.0f }; - enableTextOverlay = true; - title = "Vulkan Example - Screen space ambient occlusion"; + title = "Screen space ambient occlusion"; + settings.overlay = true; camera.type = Camera::CameraType::firstperson; camera.movementSpeed = 5.0f; #ifndef __ANDROID__ @@ -1111,55 +1109,20 @@ public: updateUniformBufferSSAOParams(); } - void toggleSSAO() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - uboSSAOParams.ssao = !uboSSAOParams.ssao; - updateUniformBufferSSAOParams(); - } - - void toggleSSAOBlur() - { - uboSSAOParams.ssaoBlur = !uboSSAOParams.ssaoBlur; - updateUniformBufferSSAOParams(); - } - - void toggleSSAOOnly() - { - uboSSAOParams.ssaoOnly = !uboSSAOParams.ssaoOnly; - updateUniformBufferSSAOParams(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_F2: - case GAMEPAD_BUTTON_A: - toggleSSAO(); - break; - case KEY_F3: - case GAMEPAD_BUTTON_X: - toggleSSAOBlur(); - break; - case KEY_F4: - case GAMEPAD_BUTTON_Y: - toggleSSAOOnly(); - break; + if (overlay->header("Settings")) { + if (overlay->checkBox("Enable SSAO", &uboSSAOParams.ssao)) { + updateUniformBufferSSAOParams(); + } + if (overlay->checkBox("SSAO blur", &uboSSAOParams.ssaoBlur)) { + updateUniformBufferSSAOParams(); + } + if (overlay->checkBox("SSAO pass only", &uboSSAOParams.ssaoOnly)) { + updateUniformBufferSSAOParams(); + } } } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("\"Button A\" to toggle SSAO", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"Button X\" to toggle SSAO blur", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"Button Y\" to toggle SSAO display", 5.0f, 115.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("\"F2\" to toggle SSAO", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"F3\" to toggle SSAO blur", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"F4\" to toggle SSAO display", 5.0f, 115.0f, VulkanTextOverlay::alignLeft); -#endif - } }; VULKAN_EXAMPLE_MAIN() diff --git a/stencilbuffer/stencilbuffer.cpp b/stencilbuffer/stencilbuffer.cpp index 5ab614bd..c0ffc1f9 100644 --- a/stencilbuffer/stencilbuffer.cpp +++ b/stencilbuffer/stencilbuffer.cpp @@ -57,13 +57,13 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Stencil buffer outlines"; + title = "Stencil buffer outlines"; timerSpeed *= 0.25f; - enableTextOverlay = true; camera.type = Camera::CameraType::lookat; camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f); camera.setRotation(glm::vec3(2.5f, -35.0f, 0.0f)); camera.setTranslation(glm::vec3(0.08f, 3.6f, -8.4f)); + settings.overlay = true; } ~VulkanExample() @@ -326,37 +326,15 @@ public: updateUniformBuffers(); } - virtual void changeOutlineWidth(float delta) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - if (uboVS.outlineWidth + delta > 0.01f) { - uboVS.outlineWidth += delta; - updateUniformBuffers(); + if (overlay->header("Settings")) { + if (overlay->inputFloat("Outline width", &uboVS.outlineWidth, 0.05f, 2)) { + updateUniformBuffers(); + } } } - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeOutlineWidth(0.01f); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeOutlineWidth(-0.01f); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { -#if defined(__ANDROID__) - textOverlay->addText("\"L1/R1\" to change outline width", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("\"NUMPAD +/-\" to outline width", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif - } }; VULKAN_EXAMPLE_MAIN() diff --git a/subpasses/subpasses.cpp b/subpasses/subpasses.cpp index fa32d2db..682f99ce 100644 --- a/subpasses/subpasses.cpp +++ b/subpasses/subpasses.cpp @@ -113,7 +113,6 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - enableTextOverlay = false; title = "Vulkan Example - Subpasses"; camera.type = Camera::CameraType::firstperson; camera.movementSpeed = 5.0f; @@ -123,6 +122,7 @@ public: camera.setPosition(glm::vec3(-3.2f, 1.0f, 5.9f)); camera.setRotation(glm::vec3(0.5f, 210.05f, 0.0f)); camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f); + settings.overlay = false; } ~VulkanExample() diff --git a/terraintessellation/terraintessellation.cpp b/terraintessellation/terraintessellation.cpp index 6933c148..c5ed0219 100644 --- a/terraintessellation/terraintessellation.cpp +++ b/terraintessellation/terraintessellation.cpp @@ -110,13 +110,13 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - enableTextOverlay = true; - title = "Vulkan Example - Dynamic terrain tessellation"; + title = "Dynamic terrain tessellation"; camera.type = Camera::CameraType::firstperson; camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f); camera.setRotation(glm::vec3(-12.0f, 159.0f, 0.0f)); camera.setTranslation(glm::vec3(18.0f, 22.5f, 57.5f)); camera.movementSpeed = 7.5f; + settings.overlay = true; } ~VulkanExample() @@ -939,70 +939,26 @@ public: updateUniformBuffers(); } - void changeTessellationFactor(float delta) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - uboTess.tessellationFactor += delta; - uboTess.tessellationFactor = fmax(0.25f, fmin(uboTess.tessellationFactor, 4.0f)); - updateUniformBuffers(); - updateTextOverlay(); - } + if (overlay->header("Settings")) { - void toggleWireframe() - { - wireframe = !wireframe; - reBuildCommandBuffers(); - updateUniformBuffers(); - } - - void toggleTessellation() - { - tessellation = !tessellation; - updateUniformBuffers(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeTessellationFactor(0.05f); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeTessellationFactor(-0.05f); - break; - case KEY_F: - case GAMEPAD_BUTTON_A: - if (deviceFeatures.fillModeNonSolid) { - toggleWireframe(); + if (overlay->checkBox("Tessellation", &tessellation)) { + updateUniformBuffers(); + } + if (overlay->inputFloat("Factor", &uboTess.tessellationFactor, 0.05f, 2)) { + updateUniformBuffers(); + } + if (deviceFeatures.fillModeNonSolid) { + if (overlay->checkBox("Wireframe", &wireframe)) { + buildCommandBuffers(); + } } - break; - case KEY_T: - case GAMEPAD_BUTTON_X: - toggleTessellation(); - break; } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - std::stringstream ss; - ss << std::setprecision(2) << std::fixed << uboTess.tessellationFactor; - -#if defined(__ANDROID__) - textOverlay->addText("Tessellation factor: " + ss.str() + " (Buttons L1/R1)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"Button A\" to toggle wireframe", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"Button X\" to toggle tessellation", 5.0f, 115.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Tessellation factor: " + ss.str() + " (numpad +/-)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"f\" to toggle wireframe", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"t\" to toggle tessellation", 5.0f, 115.0f, VulkanTextOverlay::alignLeft); -#endif - - textOverlay->addText("pipeline stats:", width - 5.0f, 5.0f, VulkanTextOverlay::alignRight); - textOverlay->addText("VS:" + std::to_string(pipelineStats[0]), width - 5.0f, 20.0f, VulkanTextOverlay::alignRight); - textOverlay->addText("TE:" + std::to_string(pipelineStats[1]), width - 5.0f, 35.0f, VulkanTextOverlay::alignRight); + if (overlay->header("Pipeline statistics")) { + overlay->text("VS invocations: %d", pipelineStats[0]); + overlay->text("TE invocations: %d", pipelineStats[1]); + } } }; diff --git a/tessellation/tessellation.cpp b/tessellation/tessellation.cpp index bc2dbd0d..668d6738 100644 --- a/tessellation/tessellation.cpp +++ b/tessellation/tessellation.cpp @@ -33,6 +33,7 @@ class VulkanExample : public VulkanExampleBase { public: bool splitScreen = true; + bool wireframe = true; struct { vks::Texture2D colorMap; @@ -87,8 +88,8 @@ public: zoom = -6.5f; rotation = glm::vec3(-350.0f, 60.0f, 0.0f); cameraPos = glm::vec3(-3.0f, 2.3f, 0.0f); - title = "Vulkan Example - Tessellation shader (PN Triangles)"; - enableTextOverlay = true; + title = "Tessellation shader (PN Triangles)"; + settings.overlay = true; } ~VulkanExample() @@ -128,22 +129,10 @@ public: enabledFeatures.fillModeNonSolid = VK_TRUE; } else { - // Wireframe not supported, switch to solid pipelines - pipelineLeft = &pipelines.solidPassThrough; - pipelineRight = &pipelines.solid; + wireframe = false; } } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); @@ -184,16 +173,15 @@ public: vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &models.object.vertices.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], models.object.indices.buffer, 0, VK_INDEX_TYPE_UINT32); - if (splitScreen) - { + if (splitScreen) { vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); - vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineLeft); + vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, wireframe ? pipelines.wirePassThrough : pipelines.solidPassThrough); vkCmdDrawIndexed(drawCmdBuffers[i], models.object.indexCount, 1, 0, 0, 0); viewport.x = float(width) / 2; } vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport); - vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineRight); + vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, wireframe ? pipelines.wire : pipelines.solid); vkCmdDrawIndexed(drawCmdBuffers[i], models.object.indexCount, 1, 0, 0, 0); vkCmdEndRenderPass(drawCmdBuffers[i]); @@ -547,60 +535,6 @@ public: updateUniformBuffers(); } - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeTessellationLevel(0.25); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeTessellationLevel(-0.25); - break; - case KEY_W: - case GAMEPAD_BUTTON_A: - if (deviceFeatures.fillModeNonSolid) { - togglePipelines(); - } - break; - case KEY_S: - case GAMEPAD_BUTTON_X: - toggleSplitScreen(); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - std::stringstream ss; - ss << std::setprecision(2) << std::fixed << uboTessControl.tessLevel; -#if defined(__ANDROID__) - textOverlay->addText("Tessellation level: " + ss.str() + " (Buttons L1/R1 to change)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - if (deviceFeatures.fillModeNonSolid) { - textOverlay->addText("Press \"Button X\" to toggle splitscreen", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"Button A\" to toggle wireframe", 5.0f, 115.0f, VulkanTextOverlay::alignLeft); - - } -#else - textOverlay->addText("Tessellation level: " + ss.str() + " (NUMPAD +/- to change)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - if (deviceFeatures.fillModeNonSolid) { - textOverlay->addText("Press \"s\" to toggle splitscreen", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"w\" to toggle wireframe", 5.0f, 115.0f, VulkanTextOverlay::alignLeft); - } -#endif - } - - void changeTessellationLevel(float delta) - { - uboTessControl.tessLevel += delta; - // Clamp - uboTessControl.tessLevel = fmax(1.0f, fmin(uboTessControl.tessLevel, 32.0f)); - updateUniformBuffers(); - updateTextOverlay(); - } - void togglePipelines() { if (pipelineRight == &pipelines.solid) @@ -613,16 +547,28 @@ public: pipelineRight = &pipelines.solid; pipelineLeft = &pipelines.solidPassThrough; } - reBuildCommandBuffers(); + buildCommandBuffers(); } - void toggleSplitScreen() + + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - splitScreen = !splitScreen; - updateUniformBuffers(); - reBuildCommandBuffers(); + if (overlay->header("Settings")) { + if (overlay->inputFloat("Tessellation level", &uboTessControl.tessLevel, 0.25f, 2)) { + updateUniformBuffers(); + } + if (deviceFeatures.fillModeNonSolid) { + if (overlay->checkBox("Wireframe", &wireframe)) { + updateUniformBuffers(); + buildCommandBuffers(); + } + if (overlay->checkBox("Splitscreen", &splitScreen)) { + updateUniformBuffers(); + buildCommandBuffers(); + } + } + } } - }; VULKAN_EXAMPLE_MAIN() diff --git a/textoverlay/textoverlay.cpp b/textoverlay/textoverlay.cpp index ecc26814..1f737042 100644 --- a/textoverlay/textoverlay.cpp +++ b/textoverlay/textoverlay.cpp @@ -741,8 +741,7 @@ public: zoomSpeed = 2.5f; rotation = { -25.0f, 0.0f, 0.0f }; title = "Vulkan Example - Text overlay"; - // Disable text overlay of the example base class - enableTextOverlay = false; + settings.overlay = false; } ~VulkanExample() diff --git a/texture/texture.cpp b/texture/texture.cpp index afd644f0..8cbd89f3 100644 --- a/texture/texture.cpp +++ b/texture/texture.cpp @@ -79,8 +79,8 @@ public: { zoom = -2.5f; rotation = { 0.0f, 15.0f, 0.0f }; - title = "Vulkan Example - Texture loading"; - enableTextOverlay = true; + title = "Texture loading"; + settings.overlay = true; } ~VulkanExample() @@ -862,46 +862,12 @@ public: updateUniformBuffers(); } - void changeLodBias(float delta) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - uboVS.lodBias += delta; - if (uboVS.lodBias < 0.0f) - { - uboVS.lodBias = 0.0f; - } - if (uboVS.lodBias > texture.mipLevels) - { - uboVS.lodBias = (float)texture.mipLevels; - } - updateUniformBuffers(); - updateTextOverlay(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeLodBias(0.1f); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeLodBias(-0.1f); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - if (vulkanDevice->features.samplerAnisotropy) { - std::stringstream ss; - ss << std::setprecision(2) << std::fixed << uboVS.lodBias; -#if defined(__ANDROID__) - textOverlay->addText("LOD bias: " + ss.str() + " (Buttons L1/R1 to change)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("LOD bias: " + ss.str() + " (numpad +/- to change)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif + if (overlay->header("Settings")) { + if (overlay->sliderFloat("LOD bias", &uboVS.lodBias, 0.0f, (float)texture.mipLevels)) { + updateUniformBuffers(); + } } } }; diff --git a/texture3d/texture3d.cpp b/texture3d/texture3d.cpp index bf403e91..5d3b29de 100644 --- a/texture3d/texture3d.cpp +++ b/texture3d/texture3d.cpp @@ -196,8 +196,8 @@ public: { zoom = -2.5f; rotation = { 0.0f, 15.0f, 0.0f }; - title = "Vulkan Example - 3D textures"; - enableTextOverlay = true; + title = "3D textures"; + settings.overlay = true; srand((unsigned int)time(NULL)); } @@ -816,34 +816,16 @@ public: updateUniformBuffers(); } - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case KEY_N: - case GAMEPAD_BUTTON_A: - if (!regenerateNoise) - { - regenerateNoise = true; - updateTextOverlay(); + if (overlay->header("Settings")) { + if (regenerateNoise) { + overlay->text("Generating new noise texture..."); + } else { + if (overlay->button("Generate new texture")) { + regenerateNoise = true; + } } - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - if (regenerateNoise) - { - textOverlay->addText("Generating new noise texture...", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - } - else - { -#ifdef __ANDROID__ - textOverlay->addText("Press \"Button A\" to generate new noise", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Press \"n\" to generate new noise", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#endif } } }; diff --git a/texturearray/texturearray.cpp b/texturearray/texturearray.cpp index 382358eb..7808ee29 100644 --- a/texturearray/texturearray.cpp +++ b/texturearray/texturearray.cpp @@ -81,8 +81,8 @@ public: zoom = -15.0f; rotationSpeed = 0.25f; rotation = { -15.0f, 35.0f, 0.0f }; - enableTextOverlay = true; - title = "Vulkan Example - Texture arrays"; + title = "Texture arrays"; + settings.overlay = true; } ~VulkanExample() diff --git a/texturecubemap/texturecubemap.cpp b/texturecubemap/texturecubemap.cpp index 340f1a19..cff65742 100644 --- a/texturecubemap/texturecubemap.cpp +++ b/texturecubemap/texturecubemap.cpp @@ -51,7 +51,7 @@ public: struct Meshes { vks::Model skybox; std::vector objects; - uint32_t objectIndex = 0; + int32_t objectIndex = 0; } models; struct { @@ -78,13 +78,15 @@ public: VkPipelineLayout pipelineLayout; VkDescriptorSetLayout descriptorSetLayout; + std::vector objectNames; + VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { zoom = -4.0f; rotationSpeed = 0.25f; rotation = { -7.25f, -120.0f, 0.0f }; - enableTextOverlay = true; - title = "Vulkan Example - Cube map"; + title = "Cube map textures"; + settings.overlay = true; } ~VulkanExample() @@ -322,16 +324,6 @@ public: loadCubemap(getAssetPath() + "textures/" + filename, format, false); } - void reBuildCommandBuffers() - { - if (!checkCommandBuffers()) - { - destroyCommandBuffers(); - createCommandBuffers(); - } - buildCommandBuffers(); - } - void buildCommandBuffers() { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); @@ -389,15 +381,16 @@ public: } } - void loadMeshes() + void loadAssets() { // Skybox models.skybox.loadFromFile(getAssetPath() + "models/cube.obj", vertexLayout, 0.05f, vulkanDevice, queue); // Objects - std::vector filenames = { "sphere.obj", "teapot.dae", "torusknot.obj" }; + std::vector filenames = { "sphere.obj", "teapot.dae", "torusknot.obj", "venus.fbx" }; + objectNames = { "Sphere", "Teapot", "Torusknot", "Venus" }; for (auto file : filenames) { vks::Model model; - model.loadFromFile(getAssetPath() + "models/" + file, vertexLayout, 0.05f, vulkanDevice, queue); + model.loadFromFile(getAssetPath() + "models/" + file, vertexLayout, 0.05f * (file == "venus.fbx" ? 3.0f : 1.0f), vulkanDevice, queue); models.objects.push_back(model); } } @@ -700,7 +693,7 @@ public: { VulkanExampleBase::prepare(); loadTextures(); - loadMeshes(); + loadAssets(); setupVertexDescriptions(); prepareUniformBuffers(); setupDescriptorSetLayout(); @@ -723,73 +716,19 @@ public: updateUniformBuffers(); } - void toggleSkyBox() + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - displaySkybox = !displaySkybox; - reBuildCommandBuffers(); - } - - void toggleObject() - { - models.objectIndex++; - if (models.objectIndex >= static_cast(models.objects.size())) - { - models.objectIndex = 0; + if (overlay->header("Settings")) { + if (overlay->sliderFloat("LOD bias", &uboVS.lodBias, 0.0f, (float)cubeMap.mipLevels)) { + updateUniformBuffers(); + } + if (overlay->comboBox("Object type", &models.objectIndex, objectNames)) { + buildCommandBuffers(); + } + if (overlay->checkBox("Skybox", &displaySkybox)) { + buildCommandBuffers(); + } } - reBuildCommandBuffers(); - } - - void changeLodBias(float delta) - { - uboVS.lodBias += delta; - if (uboVS.lodBias < 0.0f) - { - uboVS.lodBias = 0.0f; - } - if (uboVS.lodBias > cubeMap.mipLevels) - { - uboVS.lodBias = cubeMap.mipLevels; - } - updateUniformBuffers(); - updateTextOverlay(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_S: - case GAMEPAD_BUTTON_A: - toggleSkyBox(); - break; - case KEY_SPACE: - case GAMEPAD_BUTTON_X: - toggleObject(); - break; - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeLodBias(0.1f); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeLodBias(-0.1f); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - std::stringstream ss; - ss << std::setprecision(2) << std::fixed << uboVS.lodBias; -#if defined(__ANDROID__) - textOverlay->addText("Press \"Button A\" to toggle skybox", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"Button X\" to toggle object", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("LOD bias: " + ss.str() + " (Buttons L1/R1 to change)", 5.0f, 115.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("Press \"s\" to toggle skybox", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Press \"space\" to toggle object", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("LOD bias: " + ss.str() + " (numpad +/- to change)", 5.0f, 115.0f, VulkanTextOverlay::alignLeft); -#endif } }; diff --git a/texturemipmapgen/texturemipmapgen.cpp b/texturemipmapgen/texturemipmapgen.cpp index 08010a8a..14aebe32 100644 --- a/texturemipmapgen/texturemipmapgen.cpp +++ b/texturemipmapgen/texturemipmapgen.cpp @@ -43,7 +43,7 @@ public: } texture; // To demonstrate mip mapping and filtering this example uses separate samplers - std::vector samplerNames{ "No mip maps" , "With mip maps (bilinear)" , "With mip maps (anisotropic)" }; + std::vector samplerNames{ "No mip maps" , "Mip maps (bilinear)" , "Mip maps (anisotropic)" }; std::vector samplers; // Vertex layout for the models @@ -71,7 +71,7 @@ public: glm::mat4 model; glm::vec4 viewPos; float lodBias = 0.0f; - uint32_t samplerIndex = 2; + int32_t samplerIndex = 2; } uboVS; struct { @@ -84,14 +84,14 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Runtime mip map generation"; - enableTextOverlay = true; + title = "Runtime mip map generation"; camera.type = Camera::CameraType::firstperson; camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 1024.0f); camera.setRotation(glm::vec3(0.0f, 90.0f, 0.0f)); camera.setTranslation(glm::vec3(40.75f, 0.0f, 0.0f)); camera.movementSpeed = 2.5f; camera.rotationSpeed = 0.5f; + settings.overlay = true; timerSpeed *= 0.05f; paused = true; } @@ -711,58 +711,16 @@ public: updateUniformBuffers(); } - void changeLodBias(float delta) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - uboVS.lodBias += delta; - if (uboVS.lodBias < 0.0f) - { - uboVS.lodBias = 0.0f; + if (overlay->header("Settings")) { + if (overlay->sliderFloat("LOD bias", &uboVS.lodBias, 0.0f, (float)texture.mipLevels)) { + updateUniformBuffers(); + } + if (overlay->comboBox("Sampler type", &uboVS.samplerIndex, samplerNames)) { + updateUniformBuffers(); + } } - if (uboVS.lodBias > texture.mipLevels) - { - uboVS.lodBias = (float)texture.mipLevels; - } - updateUniformBuffers(); - updateTextOverlay(); - } - - void toggleSampler() - { - uboVS.samplerIndex = (uboVS.samplerIndex < static_cast(samplers.size()) - 1) ? uboVS.samplerIndex + 1 : 0; - updateUniformBuffers(); - updateTextOverlay(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeLodBias(0.1f); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeLodBias(-0.1f); - break; - case KEY_F: - case GAMEPAD_BUTTON_A: - toggleSampler(); - break; - } - } - - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - std::stringstream ss; - ss << std::setprecision(2) << std::fixed << uboVS.lodBias; -#if defined(__ANDROID__) - textOverlay->addText("LOD bias: " + ss.str() + " (Buttons L1/R1 to change)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Sampler: " + samplerNames[uboVS.samplerIndex] + " (\"Button A\" to toggle)", 5.0f, 105.0f, VulkanTextOverlay::alignLeft); -#else - textOverlay->addText("LOD bias: " + ss.str() + " (numpad +/- to change)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Sampler: " + samplerNames[uboVS.samplerIndex] + " (\"f\" to toggle)", 5.0f, 105.0f, VulkanTextOverlay::alignLeft); -#endif } }; diff --git a/texturesparseresidency/texturesparseresidency.cpp b/texturesparseresidency/texturesparseresidency.cpp index 4977d790..770d1b07 100644 --- a/texturesparseresidency/texturesparseresidency.cpp +++ b/texturesparseresidency/texturesparseresidency.cpp @@ -229,10 +229,7 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - zoom = -1.3f; - rotation = { 76.25f, 0.0f, 0.0f }; - title = "Vulkan Example - Sparse texture residency"; - enableTextOverlay = true; + title = "Sparse texture residency"; std::cout.imbue(std::locale("")); camera.type = Camera::CameraType::firstperson; camera.movementSpeed = 50.0f; @@ -242,6 +239,7 @@ public: camera.position = { 84.5f, 40.5f, 225.0f }; camera.setRotation(glm::vec3(-8.5f, -200.0f, 0.0f)); camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 1024.0f); + settings.overlay = true; // Device features to be enabled for this example enabledFeatures.shaderResourceResidency = VK_TRUE; enabledFeatures.shaderResourceMinLod = VK_TRUE; @@ -267,16 +265,16 @@ public: uniformBufferVS.destroy(); } - virtual void getEnabledFeatures() - { - if (deviceFeatures.sparseBinding && deviceFeatures.sparseResidencyImage2D) { - enabledFeatures.sparseBinding = VK_TRUE; - enabledFeatures.sparseResidencyImage2D = VK_TRUE; - } - else { - std::cout << "Sparse binding not supported" << std::endl; - } - } + virtual void getEnabledFeatures() + { + if (deviceFeatures.sparseBinding && deviceFeatures.sparseResidencyImage2D) { + enabledFeatures.sparseBinding = VK_TRUE; + enabledFeatures.sparseResidencyImage2D = VK_TRUE; + } + else { + std::cout << "Sparse binding not supported" << std::endl; + } + } glm::uvec3 alignedDivision(const VkExtent3D& extent, const VkExtent3D& granularity) { @@ -944,21 +942,6 @@ public: updateUniformBuffers(); } - void changeLodBias(float delta) - { - uboVS.lodBias += delta; - if (uboVS.lodBias < 0.0f) - { - uboVS.lodBias = 0.0f; - } - if (uboVS.lodBias > texture.mipLevels) - { - uboVS.lodBias = (float)texture.mipLevels; - } - updateUniformBuffers(); - updateTextOverlay(); - } - // Clear all pages of the virtual texture // todo: just for testing void flushVirtualTexture() @@ -1059,43 +1042,28 @@ public: mipLevel--; } - virtual void keyPressed(uint32_t keyCode) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - switch (keyCode) - { - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeLodBias(0.1f); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeLodBias(-0.1f); - break; - case KEY_F: - flushVirtualTexture(); - break; - case KEY_N: - if (lastFilledMip >= 0) - { - fillVirtualTexture(lastFilledMip); + if (overlay->header("Settings")) { + if (overlay->sliderFloat("LOD bias", &uboVS.lodBias, 0.0f, (float)texture.mipLevels)) { + updateUniformBuffers(); + } + overlay->text("Last filled mip level: %d", lastFilledMip); + if (overlay->button("Fill next mip level")) { + if (lastFilledMip >= 0) { + fillVirtualTexture(lastFilledMip); + } + } + if (overlay->button("Flush virtual texture")) { + flushVirtualTexture(); } - break; } - } + if (overlay->header("Statistics")) { + uint32_t respages = 0; + std::for_each(texture.pages.begin(), texture.pages.end(), [&respages](VirtualTexturePage page) { respages += (page.imageMemoryBind.memory != VK_NULL_HANDLE) ? 1 : 0; }); + overlay->text("Resident pages: %d of %d", respages, static_cast(texture.pages.size())); + } - virtual void getOverlayText(VulkanTextOverlay *textOverlay) - { - uint32_t respages = 0; - std::for_each(texture.pages.begin(), texture.pages.end(), [&respages](VirtualTexturePage page) { respages += (page.imageMemoryBind.memory != VK_NULL_HANDLE) ? 1 :0; }); - std::stringstream ss; - ss << std::setprecision(2) << std::fixed << uboVS.lodBias; -#if defined(__ANDROID__) -// textOverlay->addText("LOD bias: " + ss.str() + " (Buttons L1/R1 to change)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); -#else - //textOverlay->addText("LOD bias: " + ss.str() + " (numpad +/- to change)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("Resident pages: " + std::to_string(respages) + " / " + std::to_string(texture.pages.size()), 5.0f, 85.0f, VulkanTextOverlay::alignLeft); - textOverlay->addText("\"n\" to fill next mip level (" + std::to_string(lastFilledMip) + ")", 5.0f, 100.0f, VulkanTextOverlay::alignLeft); -#endif } }; diff --git a/viewportarray/viewportarray.cpp b/viewportarray/viewportarray.cpp index 421b7c0c..ebb23936 100644 --- a/viewportarray/viewportarray.cpp +++ b/viewportarray/viewportarray.cpp @@ -57,12 +57,12 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - title = "Vulkan Example - Viewport arrays"; - enableTextOverlay = true; + title = "Viewport arrays"; camera.type = Camera::CameraType::firstperson; camera.setRotation(glm::vec3(0.0f, 90.0f, 0.0f)); camera.setTranslation(glm::vec3(7.0f, 3.2f, 0.0f)); camera.movementSpeed = 5.0f; + settings.overlay = true; } ~VulkanExample() @@ -378,24 +378,12 @@ public: updateUniformBuffers(); } - void changeEyeSeparation(float delta) + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { - eyeSeparation += delta; - updateUniformBuffers(); - } - - virtual void keyPressed(uint32_t keyCode) - { - switch (keyCode) - { - case KEY_KPADD: - case GAMEPAD_BUTTON_R1: - changeEyeSeparation(0.005); - break; - case KEY_KPSUB: - case GAMEPAD_BUTTON_L1: - changeEyeSeparation(-0.005); - break; + if (overlay->header("Settings")) { + if (overlay->sliderFloat("Eye separation", &eyeSeparation, -1.0f, 1.0f)) { + updateUniformBuffers(); + } } } diff --git a/vulkanscene/vulkanscene.cpp b/vulkanscene/vulkanscene.cpp index ff987d84..a2899b59 100644 --- a/vulkanscene/vulkanscene.cpp +++ b/vulkanscene/vulkanscene.cpp @@ -93,8 +93,8 @@ public: zoom = -3.75f; rotationSpeed = 0.5f; rotation = glm::vec3(15.0f, 0.f, 0.0f); - enableTextOverlay = true; title = "Vulkan Demo Scene - (c) 2016 by Sascha Willems"; + settings.overlay = true; } ~VulkanExample()