From 6e30114b1d5c392eb9fb0b173a170f706a8249fb Mon Sep 17 00:00:00 2001 From: saschawillems Date: Sun, 7 Oct 2018 11:44:47 +0200 Subject: [PATCH] Material randomization, added sample to readme --- README.md | 10 +++++--- .../inlineuniformblocks.cpp | 24 +++++++++---------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a66a767c..7675ced4 100644 --- a/README.md +++ b/README.md @@ -298,15 +298,19 @@ Uses conservative rasterization to change the way fragments are generated by the Uses push descriptors apply the push constants concept to descriptor sets. Instead of creating per-object descriptor sets for rendering multiple objects, this example passes descriptors at command buffer creation time. -#### [03 - Multiview rendering (VK_KHR_multiview)](examples/multiview/) +#### [03 - Inline uniform blocks (VK_EXT_inline_uniform_block)](examples/inlineuniformblocks/) + +Makes use of inline uniform blocks to pass uniform data directly at descriptor set creation time and also demonstrates how to update data for those descriptors at runtime. + +#### [04 - Multiview rendering (VK_KHR_multiview)](examples/multiview/) Renders a scene to to multiple views (layers) of a single framebuffer to simulate stereoscopic rendering in one pass. Broadcasting to the views is done in the vertex shader using ```gl_ViewIndex```. -#### [04 - Conditional rendering (VK_EXT_conditional_rendering)](examples/conditionalrender) +#### [05 - Conditional rendering (VK_EXT_conditional_rendering)](examples/conditionalrender) Demonstrates the use of VK_EXT_conditional_rendering to conditionally dispatch render commands based on values from a dedicated buffer. This allows e.g. visibility toggles without having to rebuild command buffers ([blog post](https://www.saschawillems.de/?p=3098)). -#### [05 - Debug markers (VK_EXT_debug_marker)](examples/debugmarker/) +#### [06 - Debug markers (VK_EXT_debug_marker)](examples/debugmarker/) Uses the VK_EXT_debug_marker extension to set debug markers, regions and to name Vulkan objects for advanced debugging in graphics debuggers like [RenderDoc](https://www.renderdoc.org). Details can be found in [this tutorial](https://www.saschawillems.de/?page_id=2017). diff --git a/examples/inlineuniformblocks/inlineuniformblocks.cpp b/examples/inlineuniformblocks/inlineuniformblocks.cpp index 4b1e95f3..a00260b2 100644 --- a/examples/inlineuniformblocks/inlineuniformblocks.cpp +++ b/examples/inlineuniformblocks/inlineuniformblocks.cpp @@ -54,6 +54,14 @@ public: float ambient; } material; VkDescriptorSet descriptorSet; + void setRandomMaterial() { + material.r = rnd(); + material.g = rnd(); + material.b = rnd(); + material.ambient = 0.0025f; + material.roughness = glm::clamp(rnd(), 0.005f, 1.0f); + material.metallic = glm::clamp(rnd(), 0.005f, 1.0f); + } }; std::array objects; @@ -116,7 +124,7 @@ public: VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkClearValue clearValues[2]; - clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 1.0f } }; + clearValues[0].color = { { 0.15f, 0.15f, 0.15f, 1.0f } }; clearValues[1].depthStencil = { 1.0f, 0 }; VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo(); @@ -181,12 +189,7 @@ public: // Setup random materials for every object in the scene for (uint32_t i = 0; i < objects.size(); i++) { - objects[i].material.r = rnd(); - objects[i].material.g = rnd(); - objects[i].material.b = rnd(); - objects[i].material.ambient = 0.05f; - objects[i].material.roughness = glm::clamp(rnd(), 0.005f, 1.0f); - objects[i].material.metallic = glm::clamp(rnd(), 0.005f, 1.0f); + objects[i].setRandomMaterial(); } } @@ -393,12 +396,7 @@ public: void updateMaterials() { // Setup random materials for every object in the scene for (uint32_t i = 0; i < objects.size(); i++) { - objects[i].material.r = glm::clamp(rnd(), 0.005f, 1.0f); - objects[i].material.g = glm::clamp(rnd(), 0.005f, 1.0f); - objects[i].material.b = glm::clamp(rnd(), 0.005f, 1.0f); - objects[i].material.ambient = 0.05f; - objects[i].material.roughness = glm::clamp(rnd(), 0.005f, 1.0f); - objects[i].material.metallic = glm::clamp(rnd(), 0.005f, 1.0f); + objects[i].setRandomMaterial(); } for (auto &object : objects) {