From 2cb468dd843c35389cbf74637c6fcbcc89668774 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Wed, 1 May 2024 18:29:52 +0200 Subject: [PATCH] Minor code cleanup --- examples/gltfskinning/gltfskinning.h | 4 ++-- examples/pbrbasic/pbrbasic.cpp | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/gltfskinning/gltfskinning.h b/examples/gltfskinning/gltfskinning.h index 534b2667e..367394c6a 100644 --- a/examples/gltfskinning/gltfskinning.h +++ b/examples/gltfskinning/gltfskinning.h @@ -1,7 +1,7 @@ /* * Vulkan Example - glTF skinned animation * -* Copyright (C) 2020-2023 by Sascha Willems - www.saschawillems.de +* Copyright (C) 2020-2024 by Sascha Willems - www.saschawillems.de * * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) */ @@ -202,7 +202,7 @@ class VulkanExample : public VulkanExampleBase } values; } shaderData; - VkPipelineLayout pipelineLayout; + VkPipelineLayout pipelineLayout{ VK_NULL_HANDLE }; struct Pipelines { VkPipeline solid{ VK_NULL_HANDLE }; diff --git a/examples/pbrbasic/pbrbasic.cpp b/examples/pbrbasic/pbrbasic.cpp index 8e395bd5b..b62f84db8 100644 --- a/examples/pbrbasic/pbrbasic.cpp +++ b/examples/pbrbasic/pbrbasic.cpp @@ -3,7 +3,7 @@ * * See http://graphicrants.blogspot.de/2013/08/specular-brdf-reference.html for a good reference to the different functions that make up a specular BRDF * -* Copyright (C) 2017-2023 by Sascha Willems - www.saschawillems.de +* Copyright (C) 2017-2024 by Sascha Willems - www.saschawillems.de * * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) */ @@ -11,9 +11,6 @@ #include "vulkanexamplebase.h" #include "VulkanglTFModel.h" -#define GRID_DIM 7 -#define OBJ_DIM 0.05f - struct Material { // Parameter block used as push constant block struct PushBlock { @@ -150,13 +147,16 @@ class VulkanExample : public VulkanExampleBase Material mat = materials[materialIndex]; - for (uint32_t y = 0; y < GRID_DIM; y++) { - for (uint32_t x = 0; x < GRID_DIM; x++) { - glm::vec3 pos = glm::vec3(float(x - (GRID_DIM / 2.0f)) * 2.5f, 0.0f, float(y - (GRID_DIM / 2.0f)) * 2.5f); + const uint32_t gridSize = 7; + + // Render a 2D grid of objects with varying PBR parameters + for (uint32_t y = 0; y < gridSize; y++) { + for (uint32_t x = 0; x < gridSize; x++) { + glm::vec3 pos = glm::vec3(float(x - (gridSize / 2.0f)) * 2.5f, 0.0f, float(y - (gridSize / 2.0f)) * 2.5f); vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::vec3), &pos); // Vary metallic and roughness, two important PBR parameters - mat.params.metallic = glm::clamp((float)x / (float)(GRID_DIM - 1), 0.1f, 1.0f); - mat.params.roughness = glm::clamp((float)y / (float)(GRID_DIM - 1), 0.05f, 1.0f); + mat.params.metallic = glm::clamp((float)x / (float)(gridSize - 1), 0.1f, 1.0f); + mat.params.roughness = glm::clamp((float)y / (float)(gridSize - 1), 0.05f, 1.0f); vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(glm::vec3), sizeof(Material::PushBlock), &mat); models.objects[models.objectIndex].draw(drawCmdBuffers[i]); }