23 VkPushConstantRange pushConstantRange{};
24 pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
25 pushConstantRange.offset = 0;
28 const std::vector<VkDescriptorSetLayout> descriptorSetLayouts{globalSetLayout};
30 VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
31 pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
32 pipelineLayoutInfo.setLayoutCount =
static_cast<uint32_t
>(descriptorSetLayouts.size());
33 pipelineLayoutInfo.pSetLayouts = descriptorSetLayouts.data();
34 pipelineLayoutInfo.pushConstantRangeCount = 1;
35 pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange;
36 if (vkCreatePipelineLayout(m_device.device(), &pipelineLayoutInfo,
nullptr, &m_pipelineLayout) != VK_SUCCESS)
38 throw std::runtime_error(
"Failed to create pipeline layout");
59 for (
auto &kv : frameInfo.
objects)
61 Object &
object = kv.second;
62 if (
object.pointLight ==
nullptr)
continue;
64 push.
position = glm::vec4(
object.transform3D.translation, 1.F);
65 push.color = glm::vec4(
object.color,
object.pointLight->lightIntensity);
66 push.radius =
object.transform3D.scale.x;
75 const auto rotateLight = rotate(glm::mat4(1.F), frameInfo.
frameTime, {0.F, -1.F, 0.F});
76 unsigned long lightIndex = 0;
77 for (
auto &kv : frameInfo.
objects)
79 Object &
object = kv.second;
80 if (
object.pointLight ==
nullptr)
continue;
81 assert(lightIndex <
MAX_LIGHTS &&
"Too many lights");
82 object.transform3D.translation = glm::vec3(rotateLight * glm::vec4(
object.transform3D.translation, 1.F));
83 ubo.
pointLights[lightIndex].position = glm::vec4(
object.transform3D.translation, 1.F);
84 ubo.
pointLights[lightIndex].color = glm::vec4(
object.color,
object.pointLight->lightIntensity);
87 ubo.
numLights =
static_cast<int>(lightIndex);