40 SkyBox::_pipeline.destroy();
41 SkyBox::_irradianceMapPipeline.destroy();
42 SkyBox::_prefilteredMapPipeline.destroy();
43 SkyBox::_brdfLutPipeline.destroy();
48 constexpr uint32_t irradianceMapSize = 64;
58 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::createIrradianceMap: The skybox doesn't have an environnement");
78 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::build: Can't create irradiance map texture layers");
84 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::build Can't create the irradiance map texture");
99 VkResult result{VK_SUCCESS};
103 if (!graphicsQueue) {
104 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::createIrradianceMap: Can't find queue with name queue_graphics");
110 if (!commandPoolBuilder.build(commandPool, &result)) {
111 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createIrradianceMap: Can't create the graphics command pool: {}", result);
117 commandBufferBuilder.
setLevel(VK_COMMAND_BUFFER_LEVEL_PRIMARY);
120 if (!commandBufferBuilder.build(cmdBuffer, &result)) {
121 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::createIrradianceMap: Can't create the command buffer: {}", result);
131 descriptorPoolBuilder.setMaxSets(42);
133 std::vector<VkDescriptorPoolSize> poolSizes{
135 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
139 descriptorPoolBuilder.setPoolSizes(poolSizes);
141 if (!descriptorPoolBuilder.build(descriptorPool, &result)) {
142 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::createIrradianceMap: Can't create the descriptor pool: {}", result);
150 descriptorSetBuilder.
setDescriptorSetLayouts({
static_cast<VkDescriptorSetLayout
>(SkyBox::_irradianceMapPipeline.getLayout()->getDescriptorSetLayouts()[0])});
152 if (!descriptorSetBuilder.build(descriptorSet, &result)) {
153 LUG_LOG.error(
"DescriptorSetPool: Can't create descriptor set: {}", result);
160 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
163 static_cast<VkSampler
>(texture->
getSampler()),
165 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
175 if (!fenceBuilder.build(fence, &result)) {
176 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::createIrradianceMap: Can't create render fence: {}", result);
184 deviceMemoryBuilder.
setMemoryFlags(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
187 const VkExtent3D extent{
198 imageBuilder.setUsage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
201 imageBuilder.setTiling(VK_IMAGE_TILING_OPTIMAL);
203 if (!imageBuilder.build(offscreenImage, &result)) {
204 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createIrradianceMap: Can't create depth buffer image: {}", result);
208 if (!deviceMemoryBuilder.addImage(offscreenImage)) {
209 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createIrradianceMap: Can't add image to device memory");
216 if (!deviceMemoryBuilder.build(imagesMemory, &result)) {
217 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createIrradianceMap: Can't create device memory: {}", result);
227 imageViewBuilder.setAspectFlags(VK_IMAGE_ASPECT_COLOR_BIT);
229 if (!imageViewBuilder.build(offscreenImageView, &result)) {
230 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createIrradianceMap: Can't create depth buffer image view: {}", result);
241 const API::RenderPass* renderPass = SkyBox::_irradianceMapPipeline.getRenderPass();
243 framebufferBuilder.setRenderPass(renderPass);
244 framebufferBuilder.addAttachment(&offscreenImageView);
245 framebufferBuilder.setWidth(irradianceMapSize);
246 framebufferBuilder.setHeight(irradianceMapSize);
248 if (!framebufferBuilder.build(framebuffer, &result)) {
249 LUG_LOG.error(
"Forward::initFramebuffers: Can't create framebuffer: {}", result);
257 if (!cmdBuffer.
begin()) {
261 cmdBuffer.bindPipeline(SkyBox::_irradianceMapPipeline);
265 const API::CommandBuffer::CmdBindDescriptors skyBoxBind{
266 *SkyBox::_irradianceMapPipeline.getLayout(),
267 VK_PIPELINE_BIND_POINT_GRAPHICS,
273 cmdBuffer.bindDescriptorSets(skyBoxBind);
278 cmdBuffer.bindVertexBuffers(
279 {
static_cast<API::Buffer*
>(primitiveSet.position->_data)},
284 cmdBuffer.bindIndexBuffer(*indicesBuffer, VK_INDEX_TYPE_UINT16);
285 const API::CommandBuffer::CmdDrawIndexed cmdDrawIndexed {
286 primitiveSet.indices->buffer.elementsCount,
291 std::vector<Math::Mat4x4f> matrices = {
292 Math::Geometry::lookAt<float>({0.0f, 0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}),
293 Math::Geometry::lookAt<float>({0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}),
294 Math::Geometry::lookAt<float>({0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}),
295 Math::Geometry::lookAt<float>({0.0f, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}),
296 Math::Geometry::lookAt<float>({0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}),
297 Math::Geometry::lookAt<float>({0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f, 0.0f})
303 pipelineBarrier.imageMemoryBarriers.resize(1);
304 pipelineBarrier.imageMemoryBarriers[0].srcAccessMask = 0;
305 pipelineBarrier.imageMemoryBarriers[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
306 pipelineBarrier.imageMemoryBarriers[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
307 pipelineBarrier.imageMemoryBarriers[0].newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
308 pipelineBarrier.imageMemoryBarriers[0].image = &offscreenImage;
310 cmdBuffer.pipelineBarrier(pipelineBarrier);
316 pipelineBarrier.imageMemoryBarriers.resize(1);
317 pipelineBarrier.imageMemoryBarriers[0].srcAccessMask = 0;
318 pipelineBarrier.imageMemoryBarriers[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
319 pipelineBarrier.imageMemoryBarriers[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
320 pipelineBarrier.imageMemoryBarriers[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
322 pipelineBarrier.imageMemoryBarriers[0].subresourceRange.layerCount = 6;
324 cmdBuffer.pipelineBarrier(pipelineBarrier);
327 for (uint32_t i = 0; i < 6; ++i) {
331 const API::RenderPass* renderPass = SkyBox::_irradianceMapPipeline.getRenderPass();
340 beginRenderPass.renderArea.extent = {irradianceMapSize, irradianceMapSize};
348 const VkViewport vkViewport{
351 static_cast<float>(irradianceMapSize),
352 static_cast<float>(irradianceMapSize),
357 const VkRect2D scissor{
363 static_cast<uint32_t
>(irradianceMapSize),
364 static_cast<uint32_t>(irradianceMapSize)
368 cmdBuffer.setViewport({vkViewport});
369 cmdBuffer.setScissor({scissor});
373 projection * matrices[i]
376 const API::CommandBuffer::CmdPushConstants cmdPushConstants{
377 static_cast<VkPipelineLayout
>(*SkyBox::_irradianceMapPipeline.getLayout()),
378 VK_SHADER_STAGE_VERTEX_BIT,
380 sizeof(pushConstants),
384 cmdBuffer.pushConstants(cmdPushConstants);
386 cmdBuffer.drawIndexed(cmdDrawIndexed);
389 cmdBuffer.endRenderPass();
393 API::CommandBuffer::CmdPipelineBarrier::ImageMemoryBarrier imageMemoryBarrier;
394 imageMemoryBarrier.image = &offscreenImage;
395 imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
396 imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
397 API::CommandBuffer::CmdPipelineBarrier cmdPipelineBarrier;
398 cmdPipelineBarrier.imageMemoryBarriers.push_back(std::move(imageMemoryBarrier));
399 cmdBuffer.pipelineBarrier(cmdPipelineBarrier);
403 VkImageCopy copyRegion = {};
405 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
406 copyRegion.srcSubresource.baseArrayLayer = 0;
407 copyRegion.srcSubresource.mipLevel = 0;
408 copyRegion.srcSubresource.layerCount = 1;
409 copyRegion.srcOffset = { 0, 0, 0 };
411 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
412 copyRegion.dstSubresource.baseArrayLayer = i;
413 copyRegion.dstSubresource.mipLevel = 0;
414 copyRegion.dstSubresource.layerCount = 1;
415 copyRegion.dstOffset = { 0, 0, 0 };
417 copyRegion.extent.width = irradianceMapSize;
418 copyRegion.extent.height = irradianceMapSize;
419 copyRegion.extent.depth = 1;
421 const API::CommandBuffer::CmdCopyImage cmdCopyImage{
423 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
425 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
429 cmdBuffer.copyImage(cmdCopyImage);
433 API::CommandBuffer::CmdPipelineBarrier::ImageMemoryBarrier imageMemoryBarrier;
434 imageMemoryBarrier.image = &offscreenImage;
435 imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
436 imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
437 API::CommandBuffer::CmdPipelineBarrier cmdPipelineBarrier;
438 cmdPipelineBarrier.imageMemoryBarriers.push_back(std::move(imageMemoryBarrier));
439 cmdBuffer.pipelineBarrier(cmdPipelineBarrier);
446 pipelineBarrier.imageMemoryBarriers.resize(1);
447 pipelineBarrier.imageMemoryBarriers[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
448 pipelineBarrier.imageMemoryBarriers[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
449 pipelineBarrier.imageMemoryBarriers[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
450 pipelineBarrier.imageMemoryBarriers[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
452 pipelineBarrier.imageMemoryBarriers[0].subresourceRange.layerCount = 6;
454 cmdBuffer.pipelineBarrier(pipelineBarrier);
457 if (!cmdBuffer.
end()) {
462 if (!graphicsQueue->
submit(
467 static_cast<VkFence>(fence)
469 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createIrradianceMap: Can't submit work to graphics queue: {}", result);
474 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createIrradianceMap:: Can't wait fence");
490 constexpr uint32_t prefilteredMapSize = 512;
491 const uint32_t mipMapCount =
static_cast<uint32_t
>(floor(log2(prefilteredMapSize))) + 1;
503 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::createPrefilteredMap: The skybox doesn't have an environnement");
522 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::build: Can't create prefiltered map texture layers");
528 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::build Can't create the prefiltered map texture");
543 VkResult result{VK_SUCCESS};
547 if (!graphicsQueue) {
548 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::createPrefilteredMap: Can't find queue with name queue_graphics");
554 if (!commandPoolBuilder.build(commandPool, &result)) {
555 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createPrefilteredMap: Can't create the graphics command pool: {}", result);
561 commandBufferBuilder.
setLevel(VK_COMMAND_BUFFER_LEVEL_PRIMARY);
564 if (!commandBufferBuilder.build(cmdBuffer, &result)) {
565 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::createPrefilteredMap: Can't create the command buffer: {}", result);
575 descriptorPoolBuilder.setMaxSets(42);
577 std::vector<VkDescriptorPoolSize> poolSizes{
579 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
583 descriptorPoolBuilder.setPoolSizes(poolSizes);
585 if (!descriptorPoolBuilder.build(descriptorPool, &result)) {
586 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::createPrefilteredMap: Can't create the descriptor pool: {}", result);
594 descriptorSetBuilder.
setDescriptorSetLayouts({
static_cast<VkDescriptorSetLayout
>(SkyBox::_prefilteredMapPipeline.getLayout()->getDescriptorSetLayouts()[0])});
596 if (!descriptorSetBuilder.build(descriptorSet, &result)) {
597 LUG_LOG.error(
"DescriptorSetPool: Can't create descriptor set: {}", result);
604 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
607 static_cast<VkSampler
>(texture->
getSampler()),
609 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
619 if (!fenceBuilder.build(fence, &result)) {
620 LUG_LOG.error(
"Resource::SharedPtr<::lug::Graphics::Render::SkyBox>::createPrefilteredMap: Can't create render fence: {}", result);
628 deviceMemoryBuilder.
setMemoryFlags(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
631 const VkExtent3D extent{
642 imageBuilder.setUsage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
645 imageBuilder.setTiling(VK_IMAGE_TILING_OPTIMAL);
647 if (!imageBuilder.build(offscreenImage, &result)) {
648 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createPrefilteredMap: Can't create depth buffer image: {}", result);
652 if (!deviceMemoryBuilder.addImage(offscreenImage)) {
653 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createPrefilteredMap: Can't add image to device memory");
660 if (!deviceMemoryBuilder.build(imagesMemory, &result)) {
661 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createPrefilteredMap: Can't create device memory: {}", result);
671 imageViewBuilder.setAspectFlags(VK_IMAGE_ASPECT_COLOR_BIT);
673 if (!imageViewBuilder.build(offscreenImageView, &result)) {
674 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createPrefilteredMap: Can't create depth buffer image view: {}", result);
685 const API::RenderPass* renderPass = SkyBox::_prefilteredMapPipeline.getRenderPass();
687 framebufferBuilder.setRenderPass(renderPass);
688 framebufferBuilder.addAttachment(&offscreenImageView);
689 framebufferBuilder.setWidth(prefilteredMapSize);
690 framebufferBuilder.setHeight(prefilteredMapSize);
692 if (!framebufferBuilder.build(framebuffer, &result)) {
693 LUG_LOG.error(
"Forward::initFramebuffers: Can't create framebuffer: {}", result);
701 if (!cmdBuffer.
begin()) {
705 cmdBuffer.bindPipeline(SkyBox::_prefilteredMapPipeline);
709 const API::CommandBuffer::CmdBindDescriptors skyBoxBind{
710 *SkyBox::_prefilteredMapPipeline.getLayout(),
711 VK_PIPELINE_BIND_POINT_GRAPHICS,
717 cmdBuffer.bindDescriptorSets(skyBoxBind);
722 cmdBuffer.bindVertexBuffers(
723 {
static_cast<API::Buffer*
>(primitiveSet.position->_data)},
728 cmdBuffer.bindIndexBuffer(*indicesBuffer, VK_INDEX_TYPE_UINT16);
729 const API::CommandBuffer::CmdDrawIndexed cmdDrawIndexed {
730 primitiveSet.indices->buffer.elementsCount,
735 std::vector<Math::Mat4x4f> matrices = {
736 Math::Geometry::lookAt<float>({0.0f, 0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}),
737 Math::Geometry::lookAt<float>({0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}),
738 Math::Geometry::lookAt<float>({0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}),
739 Math::Geometry::lookAt<float>({0.0f, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}),
740 Math::Geometry::lookAt<float>({0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}),
741 Math::Geometry::lookAt<float>({0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f, 0.0f})
747 pipelineBarrier.imageMemoryBarriers.resize(1);
748 pipelineBarrier.imageMemoryBarriers[0].srcAccessMask = 0;
749 pipelineBarrier.imageMemoryBarriers[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
750 pipelineBarrier.imageMemoryBarriers[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
751 pipelineBarrier.imageMemoryBarriers[0].newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
752 pipelineBarrier.imageMemoryBarriers[0].image = &offscreenImage;
754 cmdBuffer.pipelineBarrier(pipelineBarrier);
760 pipelineBarrier.imageMemoryBarriers.resize(1);
761 pipelineBarrier.imageMemoryBarriers[0].srcAccessMask = 0;
762 pipelineBarrier.imageMemoryBarriers[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
763 pipelineBarrier.imageMemoryBarriers[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
764 pipelineBarrier.imageMemoryBarriers[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
766 pipelineBarrier.imageMemoryBarriers[0].subresourceRange.levelCount = mipMapCount;
767 pipelineBarrier.imageMemoryBarriers[0].subresourceRange.layerCount = 6;
769 cmdBuffer.pipelineBarrier(pipelineBarrier);
773 for (uint32_t m = 0; m < mipMapCount; m++) {
774 const float roughness = (float)m / (
float)(mipMapCount - 1);
776 for (uint32_t i = 0; i < 6; ++i) {
780 const API::RenderPass* renderPass = SkyBox::_prefilteredMapPipeline.getRenderPass();
789 beginRenderPass.renderArea.extent = {prefilteredMapSize, prefilteredMapSize};
797 const VkViewport vkViewport{
800 static_cast<float>(prefilteredMapSize * std::pow(0.5f, m)),
801 static_cast<float>(prefilteredMapSize * std::pow(0.5f, m)),
806 const VkRect2D scissor{
812 static_cast<uint32_t
>(prefilteredMapSize),
813 static_cast<uint32_t>(prefilteredMapSize)
817 cmdBuffer.setViewport({vkViewport});
818 cmdBuffer.setScissor({scissor});
823 projection * matrices[i]
826 const API::CommandBuffer::CmdPushConstants cmdPushConstants{
827 static_cast<VkPipelineLayout
>(*SkyBox::_prefilteredMapPipeline.getLayout()),
828 VK_SHADER_STAGE_VERTEX_BIT,
830 sizeof(pushConstants),
834 cmdBuffer.pushConstants(cmdPushConstants);
838 const API::CommandBuffer::CmdPushConstants cmdPushConstants{
839 static_cast<VkPipelineLayout
>(*SkyBox::_prefilteredMapPipeline.getLayout()),
840 VK_SHADER_STAGE_FRAGMENT_BIT,
841 sizeof(Math::Mat4x4f),
846 cmdBuffer.pushConstants(cmdPushConstants);
849 cmdBuffer.drawIndexed(cmdDrawIndexed);
852 cmdBuffer.endRenderPass();
856 API::CommandBuffer::CmdPipelineBarrier::ImageMemoryBarrier imageMemoryBarrier;
857 imageMemoryBarrier.image = &offscreenImage;
858 imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
859 imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
860 API::CommandBuffer::CmdPipelineBarrier cmdPipelineBarrier;
861 cmdPipelineBarrier.imageMemoryBarriers.push_back(std::move(imageMemoryBarrier));
862 cmdBuffer.pipelineBarrier(cmdPipelineBarrier);
866 VkImageCopy copyRegion = {};
868 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
869 copyRegion.srcSubresource.baseArrayLayer = 0;
870 copyRegion.srcSubresource.mipLevel = 0;
871 copyRegion.srcSubresource.layerCount = 1;
872 copyRegion.srcOffset = { 0, 0, 0 };
874 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
875 copyRegion.dstSubresource.baseArrayLayer = i;
876 copyRegion.dstSubresource.mipLevel = m;
877 copyRegion.dstSubresource.layerCount = 1;
878 copyRegion.dstOffset = { 0, 0, 0 };
880 copyRegion.extent.width =
static_cast<uint32_t
>(prefilteredMapSize * std::pow(0.5f, m));
881 copyRegion.extent.height =
static_cast<uint32_t
>(prefilteredMapSize * std::pow(0.5f, m));
882 copyRegion.extent.depth = 1;
884 const API::CommandBuffer::CmdCopyImage cmdCopyImage{
886 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
888 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
892 cmdBuffer.copyImage(cmdCopyImage);
896 API::CommandBuffer::CmdPipelineBarrier::ImageMemoryBarrier imageMemoryBarrier;
897 imageMemoryBarrier.image = &offscreenImage;
898 imageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
899 imageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
900 API::CommandBuffer::CmdPipelineBarrier cmdPipelineBarrier;
901 cmdPipelineBarrier.imageMemoryBarriers.push_back(std::move(imageMemoryBarrier));
902 cmdBuffer.pipelineBarrier(cmdPipelineBarrier);
910 pipelineBarrier.imageMemoryBarriers.resize(1);
911 pipelineBarrier.imageMemoryBarriers[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
912 pipelineBarrier.imageMemoryBarriers[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
913 pipelineBarrier.imageMemoryBarriers[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
914 pipelineBarrier.imageMemoryBarriers[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
916 pipelineBarrier.imageMemoryBarriers[0].subresourceRange.levelCount = mipMapCount;
917 pipelineBarrier.imageMemoryBarriers[0].subresourceRange.layerCount = 6;
919 cmdBuffer.pipelineBarrier(pipelineBarrier);
922 if (!cmdBuffer.
end()) {
927 if (!graphicsQueue->
submit(
932 static_cast<VkFence>(fence)
934 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createPrefilteredMap: Can't submit work to graphics queue: {}", result);
939 LUG_LOG.error(
"Forward::iniResource::SharedPtr<::lug::Graphics::Render::SkyBox>::createPrefilteredMap:: Can't wait fence");
lug::Graphics::Resource::SharedPtr< lug::Graphics::Render::Texture > _environnementTexture
const API::Sampler & getSampler() const
Resource::SharedPtr< T > add(std::unique_ptr< Resource > resource)
Add a resource to the ResourceManager.
void setMinFilter(Render::Texture::Filter minFilter)
static lug::Graphics::Resource::SharedPtr< lug::Graphics::Render::Mesh > _mesh
void pipelineBarrier(const CmdPipelineBarrier ¶meters, VkDependencyFlags dependencyFlags=VK_DEPENDENCY_BY_REGION_BIT, VkPipelineStageFlags srcStageMask=VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VkPipelineStageFlags dstStageMask=VK_PIPELINE_STAGE_ALL_COMMANDS_BIT) const
const API::Queue * getQueue(const std::string &queueName) const
void setExtent(VkExtent3D extent)
bool submit(const CommandBuffer &commandBuffer, const std::vector< VkSemaphore > &signalSemaphores={}, const std::vector< VkSemaphore > &waitSemaphores={}, const std::vector< VkPipelineStageFlags > &waitDstStageMasks={}, VkFence fence=VK_NULL_HANDLE) const
void setWrapS(Render::Texture::WrappingMode wrapS)
void setLevel(VkCommandBufferLevel level)
static uint32_t _skyBoxCount
Store the number of skybox created to know when to create/destroy the pipeline and mesh...
static API::GraphicsPipeline _pipeline
void setFlags(VkDescriptorPoolCreateFlags flags)
void setMagFilter(Render::Texture::Filter magFilter)
Render::Texture::Filter getMinFilter() const
Resource::SharedPtr< lug::Graphics::Render::SkyBox > createPrefilteredMap(lug::Graphics::Renderer &renderer) const override final
void setDescriptorSetLayouts(const std::vector< VkDescriptorSetLayout > &descriptorSetLayouts)
void beginRenderPass(const API::RenderPass &renderPass, const CmdBeginRenderPass ¶meters, VkSubpassContents contents=VK_SUBPASS_CONTENTS_INLINE) const
bool addLayer(const std::string &filename, bool hdr=false)
API::DescriptorPool descriptorPool
const QueueFamily * getQueueFamily() const
void setWrapT(Render::Texture::WrappingMode wrapT)
static API::GraphicsPipeline _prefilteredMapPipeline
void setFormat(VkFormat format)
const Resource::SharedPtr< lug::Graphics::Render::Texture > getEnvironnementTexture() const
SkyBox(const SkyBox &)=delete
const std::vector< Mesh::PrimitiveSet > & getPrimitiveSets() const
static SharedPtr< T > cast(const SharedPtr< RhsT > &rhs)
Dynamic casting of a SharedPtr to another one (RhsT to T)
VkFormat getFormat() const
static const lug::Graphics::Resource::SharedPtr< lug::Graphics::Render::Mesh > getMesh()
void setMipMapFilter(Render::Texture::Filter mipMapFilter)
void setMemoryFlags(VkMemoryPropertyFlags flags)
API::Device & getDevice()
void updateImages(uint32_t dstBinding, uint32_t dstArrayElement, VkDescriptorType descriptorType, const std::vector< VkDescriptorImageInfo > &imageInfos) const
Update the descriptor set images.
Render::Texture::WrappingMode getWrapT() const
const API::ImageView & getImageView() const
void pushConstants(const CmdPushConstants ¶meters) const
void setMipLevels(uint32_t mipLevels)
Resource::SharedPtr< Render::Texture > build()
static lug::Graphics::Resource::SharedPtr< lug::Graphics::Render::Texture > _brdfLut
ResourceManager * getResourceManager() const
Render::Texture::Filter getMipMapFilter() const
bool begin(VkCommandBufferUsageFlags flags=VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) const
Render::Texture::WrappingMode getWrapS() const
Render::Texture::Filter getMagFilter() const
static API::GraphicsPipeline _irradianceMapPipeline
Matrix< 4, 4, T > perspective(T fovy, T aspect, T zNear, T zFar)
static API::GraphicsPipeline _brdfLutPipeline
Resource::SharedPtr< lug::Graphics::Render::SkyBox > createIrradianceMap(lug::Graphics::Renderer &renderer) const override final