@@ -702,8 +702,8 @@ class VulkanApplication {
702702 .depthClampEnable = vk::False,
703703 .rasterizerDiscardEnable = vk::False,
704704 .polygonMode = vk::PolygonMode::eFill,
705- .cullMode = vk::CullModeFlagBits::eBack, // Re-enabled culling for better performance
706- .frontFace = vk::FrontFace::eClockwise, // Keeping Clockwise for glTF
705+ .cullMode = vk::CullModeFlagBits::eBack,
706+ .frontFace = vk::FrontFace::eCounterClockwise,
707707 .depthBiasEnable = vk::False
708708 };
709709 rasterizer.lineWidth = 1 .0f ;
@@ -738,8 +738,13 @@ class VulkanApplication {
738738 vk::PipelineLayoutCreateInfo pipelineLayoutInfo{ .setLayoutCount = 1 , .pSetLayouts = &*descriptorSetLayout, .pushConstantRangeCount = 0 };
739739
740740 pipelineLayout = vk::raii::PipelineLayout (device, pipelineLayoutInfo);
741-
742- vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1 , .pColorAttachmentFormats = &swapChainSurfaceFormat.format };
741+
742+ vk::Format depthFormat = findDepthFormat ();
743+ vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{
744+ .colorAttachmentCount = 1 ,
745+ .pColorAttachmentFormats = &swapChainSurfaceFormat.format ,
746+ .depthAttachmentFormat = depthFormat
747+ };
743748 vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo,
744749 .stageCount = 2 ,
745750 .pStages = shaderStages,
@@ -1013,10 +1018,7 @@ class VulkanApplication {
10131018 Vertex vertex{};
10141019
10151020 const float * pos = reinterpret_cast <const float *>(&posBuffer.data [posBufferView.byteOffset + posAccessor.byteOffset + i * 12 ]);
1016- // glTF uses a right-handed coordinate system with Y-up
1017- // Vulkan uses a right-handed coordinate system with Y-down
1018- // We need to flip the Y coordinate
1019- vertex.pos = {pos[0 ], -pos[1 ], pos[2 ]};
1021+ vertex.pos = {pos[0 ], pos[1 ], pos[2 ]};
10201022
10211023 if (hasTexCoords) {
10221024 const float * texCoord = reinterpret_cast <const float *>(&texCoordBuffer->data [texCoordBufferView->byteOffset + texCoordAccessor->byteOffset + i * 8 ]);
@@ -1099,17 +1101,17 @@ class VulkanApplication {
10991101 void setupGameObjects () {
11001102 // Object 1 - Center
11011103 gameObjects[0 ].position = {0 .0f , 0 .0f , 0 .0f };
1102- gameObjects[0 ].rotation = {0 .0f , 0 .0f , 0 .0f };
1104+ gameObjects[0 ].rotation = {0 .0f , glm::radians (- 90 .0f ) , 0 .0f };
11031105 gameObjects[0 ].scale = {1 .0f , 1 .0f , 1 .0f };
11041106
11051107 // Object 2 - Left
11061108 gameObjects[1 ].position = {-2 .0f , 0 .0f , -1 .0f };
1107- gameObjects[1 ].rotation = {0 .0f , glm::radians (45 .0f ), 0 .0f };
1109+ gameObjects[1 ].rotation = {0 .0f , glm::radians (- 45 .0f ), 0 .0f };
11081110 gameObjects[1 ].scale = {0 .75f , 0 .75f , 0 .75f };
11091111
11101112 // Object 3 - Right
11111113 gameObjects[2 ].position = {2 .0f , 0 .0f , -1 .0f };
1112- gameObjects[2 ].rotation = {0 .0f , glm::radians (- 45 .0f ), 0 .0f };
1114+ gameObjects[2 ].rotation = {0 .0f , glm::radians (45 .0f ), 0 .0f };
11131115 gameObjects[2 ].scale = {0 .75f , 0 .75f , 0 .75f };
11141116 }
11151117
@@ -1277,6 +1279,31 @@ class VulkanApplication {
12771279 vk::PipelineStageFlagBits2::eTopOfPipe,
12781280 vk::PipelineStageFlagBits2::eColorAttachmentOutput
12791281 );
1282+ vk::ImageMemoryBarrier2 depthBarrier = {
1283+ .srcStageMask = vk::PipelineStageFlagBits2::eTopOfPipe,
1284+ .srcAccessMask = {},
1285+ .dstStageMask = vk::PipelineStageFlagBits2::eEarlyFragmentTests | vk::PipelineStageFlagBits2::eLateFragmentTests,
1286+ .dstAccessMask = vk::AccessFlagBits2::eDepthStencilAttachmentRead | vk::AccessFlagBits2::eDepthStencilAttachmentWrite,
1287+ .oldLayout = vk::ImageLayout::eUndefined,
1288+ .newLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal,
1289+ .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
1290+ .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
1291+ .image = *depthImage,
1292+ .subresourceRange = {
1293+ .aspectMask = vk::ImageAspectFlagBits::eDepth,
1294+ .baseMipLevel = 0 ,
1295+ .levelCount = 1 ,
1296+ .baseArrayLayer = 0 ,
1297+ .layerCount = 1
1298+ }
1299+ };
1300+ vk::DependencyInfo depthDependencyInfo = {
1301+ .dependencyFlags = {},
1302+ .imageMemoryBarrierCount = 1 ,
1303+ .pImageMemoryBarriers = &depthBarrier
1304+ };
1305+ commandBuffers[currentFrame].pipelineBarrier2 (depthDependencyInfo);
1306+
12801307 vk::ClearValue clearColor = vk::ClearColorValue (0 .0f , 0 .0f , 0 .0f , 1 .0f );
12811308 vk::RenderingAttachmentInfo attachmentInfo = {
12821309 .imageView = *swapChainImageViews[imageIndex],
@@ -1285,11 +1312,20 @@ class VulkanApplication {
12851312 .storeOp = vk::AttachmentStoreOp::eStore,
12861313 .clearValue = clearColor
12871314 };
1315+ vk::ClearValue clearDepth = vk::ClearDepthStencilValue{ 1 .0f , 0 };
1316+ vk::RenderingAttachmentInfo depthAttachmentInfo{
1317+ .imageView = *depthImageView,
1318+ .imageLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal,
1319+ .loadOp = vk::AttachmentLoadOp::eClear,
1320+ .storeOp = vk::AttachmentStoreOp::eDontCare,
1321+ .clearValue = clearDepth
1322+ };
12881323 vk::RenderingInfo renderingInfo = {
12891324 .renderArea = { .offset = { 0 , 0 }, .extent = swapChainExtent },
12901325 .layerCount = 1 ,
12911326 .colorAttachmentCount = 1 ,
1292- .pColorAttachments = &attachmentInfo
1327+ .pColorAttachments = &attachmentInfo,
1328+ .pDepthAttachment = &depthAttachmentInfo
12931329 };
12941330 commandBuffers[currentFrame].beginRendering (renderingInfo);
12951331 commandBuffers[currentFrame].bindPipeline (vk::PipelineBindPoint::eGraphics, *graphicsPipeline);
@@ -1389,6 +1425,8 @@ class VulkanApplication {
13891425 // Camera and projection matrices (shared by all objects)
13901426 glm::mat4 view = glm::lookAt (glm::vec3 (2 .0f , 2 .0f , 6 .0f ), glm::vec3 (0 .0f , 0 .0f , 0 .0f ), glm::vec3 (0 .0f , 1 .0f , 0 .0f ));
13911427 glm::mat4 proj = glm::perspective (glm::radians (45 .0f ), static_cast <float >(swapChainExtent.width ) / static_cast <float >(swapChainExtent.height ), 0 .1f , 20 .0f );
1428+ proj[1 ][1 ] *= -1 ;
1429+
13921430 // Update uniform buffers for each object
13931431 for (auto & gameObject : gameObjects) {
13941432 // Apply continuous rotation to the object based on frame time
0 commit comments