Skip to content

Commit

Permalink
Minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SaschaWillems committed May 1, 2024
1 parent 3d641ac commit 2cb468d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions examples/gltfskinning/gltfskinning.h
Original file line number Diff line number Diff line change
@@ -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)
*/
Expand Down Expand Up @@ -202,7 +202,7 @@ class VulkanExample : public VulkanExampleBase
} values;
} shaderData;

VkPipelineLayout pipelineLayout;
VkPipelineLayout pipelineLayout{ VK_NULL_HANDLE };
struct Pipelines
{
VkPipeline solid{ VK_NULL_HANDLE };
Expand Down
18 changes: 9 additions & 9 deletions examples/pbrbasic/pbrbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
*
* 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)
*/

#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 {
Expand Down Expand Up @@ -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]);
}
Expand Down

0 comments on commit 2cb468d

Please sign in to comment.