Material randomization, added sample to readme

This commit is contained in:
saschawillems 2018-10-07 11:44:47 +02:00
parent e36b0ae021
commit 6e30114b1d
2 changed files with 18 additions and 16 deletions

View file

@ -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).

View file

@ -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<Object, 16> 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) {