diff --git a/pbrbasic/pbrbasic.cpp b/pbrbasic/pbrbasic.cpp index 0dcded72..8d009d48 100644 --- a/pbrbasic/pbrbasic.cpp +++ b/pbrbasic/pbrbasic.cpp @@ -32,12 +32,21 @@ #define OBJ_DIM 0.05f struct Material { - float roughness; - float metallic; - float r, g, b; // Color components as single floats because we use push constants + // Parameter block used as push constant block + struct PushBlock { + float roughness; + float metallic; + float r, g, b; + } params; std::string name; Material() {}; - Material(std::string n, glm::vec3 c, float r, float m) : name(n), roughness(r), metallic(m), r(c.r), g(c.g), b(c.b) { }; + Material(std::string n, glm::vec3 c, float r, float m) : name(n) { + params.roughness = r; + params.metallic = m; + params.r = c.r; + params.g = c.g; + params.b = c.b; + }; }; class VulkanExample : public VulkanExampleBase @@ -181,17 +190,16 @@ public: Material mat = materials[materialIndex]; - //#define SINGLE_MESH 1 -#ifdef SINGLE_MESH - mat.metallic = 1.0; - mat.roughness = 0.1; +//#define SINGLE_ROW 1 +#ifdef SINGLE_ROW + mat.params.metallic = 1.0; uint32_t objcount = 10; for (uint32_t x = 0; x < objcount; x++) { glm::vec3 pos = glm::vec3(float(x - (objcount / 2.0f)) * 2.5f, 0.0f, 0.0f); - mat.roughness = glm::clamp((float)x / (float)objcount, 0.005f, 1.0f); + mat.params.roughness = glm::clamp((float)x / (float)objcount, 0.005f, 1.0f); vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::vec3), &pos); - vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(glm::vec3), sizeof(Material), &mat); + vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(glm::vec3), sizeof(Material::PushBlock), &mat); vkCmdDrawIndexed(drawCmdBuffers[i], models.objects[models.objectIndex].indexCount, 1, 0, 0, 0); } #else @@ -199,9 +207,9 @@ public: 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); vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::vec3), &pos); - mat.metallic = (float)x / (float)(GRID_DIM - 1); - mat.roughness = glm::clamp((float)y / (float)(GRID_DIM - 1), 0.05f, 1.0f); - vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(glm::vec3), sizeof(Material), &mat); + mat.params.metallic = (float)x / (float)(GRID_DIM - 1); + mat.params.roughness = glm::clamp((float)y / (float)(GRID_DIM - 1), 0.05f, 1.0f); + vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(glm::vec3), sizeof(Material::PushBlock), &mat); vkCmdDrawIndexed(drawCmdBuffers[i], models.objects[models.objectIndex].indexCount, 1, 0, 0, 0); } } @@ -242,7 +250,7 @@ public: std::vector pushConstantRanges = { vks::initializers::pushConstantRange(VK_SHADER_STAGE_VERTEX_BIT, sizeof(glm::vec3), 0), - vks::initializers::pushConstantRange(VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(Material), sizeof(glm::vec3)), + vks::initializers::pushConstantRange(VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(Material::PushBlock), sizeof(glm::vec3)), }; pipelineLayoutCreateInfo.pushConstantRangeCount = 2; diff --git a/pbribl/pbribl.cpp b/pbribl/pbribl.cpp index 775a8879..59cb3717 100644 --- a/pbribl/pbribl.cpp +++ b/pbribl/pbribl.cpp @@ -34,14 +34,20 @@ #define GRID_DIM 7 struct Material { - // Set in object rendering loop - float roughness = 0.0f; - float metallic = 0.0f; - float specular = 0.0f; - float r, g, b; + // Parameter block used as push constant block + struct PushBlock { + float roughness = 0.0f; + float metallic = 0.0f; + float specular = 0.0f; + float r, g, b; + } params; std::string name; Material() {}; - Material(std::string n, glm::vec3 c) : r(c.r), g(c.g), b(c.b), name(n) { }; + Material(std::string n, glm::vec3 c) : name(n) { + params.r = c.r; + params.g = c.g; + params.b = c.b; + }; }; class VulkanExample : public VulkanExampleBase @@ -221,25 +227,25 @@ public: #define SINGLE_ROW 1 #ifdef SINGLE_ROW - mat.metallic = 1.0; + mat.params.metallic = 1.0; uint32_t objcount = 10; for (uint32_t x = 0; x < objcount; x++) { glm::vec3 pos = glm::vec3(float(x - (objcount / 2.0f)) * 2.15f, 0.0f, 0.0f); - mat.roughness = glm::clamp((float)x / (float)objcount, 0.005f, 1.0f); - mat.metallic = 1.0f - glm::clamp((float)x / (float)objcount, 0.005f, 1.0f); + mat.params.roughness = glm::clamp((float)x / (float)objcount, 0.005f, 1.0f); + mat.params.metallic = 1.0f - glm::clamp((float)x / (float)objcount, 0.005f, 1.0f); vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::vec3), &pos); - vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(glm::vec3), sizeof(Material), &mat); + vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(glm::vec3), sizeof(Material::PushBlock), &mat); vkCmdDrawIndexed(drawCmdBuffers[i], models.objects[models.objectIndex].indexCount, 1, 0, 0, 0); } #else for (uint32_t y = 0; y < GRID_DIM; y++) { - mat.metallic = (float)y / (float)(GRID_DIM); + mat.params.metallic = (float)y / (float)(GRID_DIM); 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); vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::vec3), &pos); - mat.roughness = glm::clamp((float)x / (float)(GRID_DIM), 0.05f, 1.0f); - vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(glm::vec3), sizeof(Material), &mat); + mat.params.roughness = glm::clamp((float)x / (float)(GRID_DIM), 0.05f, 1.0f); + vkCmdPushConstants(drawCmdBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(glm::vec3), sizeof(Material::PushBlock), &mat); vkCmdDrawIndexed(drawCmdBuffers[i], models.objects[models.objectIndex].indexCount, 1, 0, 0, 0); } } @@ -344,7 +350,7 @@ public: // Push constant ranges std::vector pushConstantRanges = { vks::initializers::pushConstantRange(VK_SHADER_STAGE_VERTEX_BIT, sizeof(glm::vec3), 0), - vks::initializers::pushConstantRange(VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(Material), sizeof(glm::vec3)), + vks::initializers::pushConstantRange(VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(Material::PushBlock), sizeof(glm::vec3)), }; pipelineLayoutCreateInfo.pushConstantRangeCount = 2; pipelineLayoutCreateInfo.pPushConstantRanges = pushConstantRanges.data(); diff --git a/texturesparseresidency/texturesparseresidency.cpp b/texturesparseresidency/texturesparseresidency.cpp index 4d9cc403..4a239f19 100644 --- a/texturesparseresidency/texturesparseresidency.cpp +++ b/texturesparseresidency/texturesparseresidency.cpp @@ -109,7 +109,7 @@ struct VirtualTexture VkBindSparseInfo bindSparseInfo; // Sparse queue binding information std::vector pages; // Contains all virtual pages of the texture std::vector sparseImageMemoryBinds; // Sparse image memory bindings of all memory-backed virtual tables - std::vector opaqueMemoryBinds; // Sparse ópaque memory bindings for the mip tail (if present) + std::vector opaqueMemoryBinds; // Sparse ópaque memory bindings for the mip tail (if present) VkSparseImageMemoryBindInfo imageMemoryBindInfo; // Sparse image memory bind info VkSparseImageOpaqueMemoryBindInfo opaqueMemoryBindInfo; // Sparse image opaque memory bind info (mip tail) uint32_t mipTailStart; // First mip level in mip tail @@ -654,7 +654,7 @@ public: void loadAssets() { - textures.source.loadFromFile(getAssetPath() + "textures/ground_dry_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT); + textures.source.loadFromFile(getAssetPath() + "textures/ground_dry_bc3_unorm.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT); } // Generate a terrain quad patch for feeding to the tessellation control shader