Friday, June 13, 2025
HomeGame DevelopmentVulkan vertex from again peeking by means of

Vulkan vertex from again peeking by means of


I’m making an attempt to render a .obj mannequin with Vulkan 1.4. The thing is rotated with a quaternion over time. The "entrance" geometry of the mannequin is rendered as anticipated, however when the mannequin rotates and reveals the again, some components of the geometry from the entrance is peeking by means of the mannequin. I’ve tried a mannequin with a texture, and the again of the mannequin appears clear.

The VkPipeline i’ve setup comply with the one within the depth buffering code from the Khronos Vulkan-tutorial 1

VkPipelineShaderStageCreateInfo shader_stages[info->shader_count];
for (size_t i = 0; i < info->shader_count; ++i)  VK_COLOR_COMPONENT_G_BIT
        

const VkPipelineVertexInputStateCreateInfo vertex_input =  VK_COLOR_COMPONENT_B_BIT ;

const VkPipelineInputAssemblyStateCreateInfo input_assembly =  VK_COLOR_COMPONENT_B_BIT ;

const VkPipelineViewportStateCreateInfo viewport = {
    .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
    .viewportCount = 1,
    .scissorCount = 1,
};

const VkPipelineRasterizationStateCreateInfo rasterization = {
    .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
    .depthClampEnable = VK_FALSE,
    .rasterizerDiscardEnable = VK_FALSE,
    .polygonMode = VK_POLYGON_MODE_FILL,
    .cullMode = VK_CULL_MODE_BACK_BIT,
    .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE,
    .lineWidth = 1.f,
    .depthBiasEnable = VK_FALSE,
};

const VkPipelineMultisampleStateCreateInfo multisampling = {
    .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
    .sampleShadingEnable = VK_FALSE,
    .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
    .minSampleShading = 0.0f,
    .pSampleMask = NULL,
    .alphaToCoverageEnable = VK_FALSE,
    .alphaToOneEnable = VK_FALSE,
};

const VkPipelineDepthStencilStateCreateInfo depth_stencil = {
    .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
    .depthTestEnable = VK_TRUE,
    .depthWriteEnable = VK_TRUE,
    .depthCompareOp = VK_COMPARE_OP_GREATER_OR_EQUAL,
    .depthBoundsTestEnable = VK_FALSE,
    .stencilTestEnable = VK_FALSE,
};

const VkPipelineColorBlendAttachmentState color_blend =  VK_COLOR_COMPONENT_G_BIT
        ;

const VkPipelineColorBlendStateCreateInfo color_blending = {
    .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
    .logicOpEnable = VK_FALSE,
    .logicOp = VK_LOGIC_OP_COPY,
    .attachmentCount = 1,
    .pAttachments = &color_blend,
    .blendConstants[0] = 0.f,
    .blendConstants[1] = 0.f,
    .blendConstants[2] = 0.f,
    .blendConstants[3] = 0.f,
};

const VkDynamicState dynamic_states[] = {
    VK_DYNAMIC_STATE_VIEWPORT,
    VK_DYNAMIC_STATE_SCISSOR,
};

const VkPipelineDynamicStateCreateInfo dynamic_state = {
    .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
    .dynamicStateCount = ARRAY_SIZE(dynamic_states),
    .pDynamicStates = dynamic_states,
};

const VkPipelineRenderingCreateInfo rendering = {
    .sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
    .colorAttachmentCount = 1,
    .pColorAttachmentFormats = &info->shade,
    .depthAttachmentFormat = VK_FORMAT_D32_SFLOAT,
};

const VkGraphicsPipelineCreateInfo pipeline_info = {
    .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
    .pNext = &rendering,
    .stageCount = ARRAY_SIZE(shader_stages),
    .pStages = shader_stages,
    .pVertexInputState = &vertex_input,
    .pInputAssemblyState = &input_assembly,
    .pViewportState = &viewport,
    .pRasterizationState = &rasterization,
    .pMultisampleState = &multisampling,
    .pDepthStencilState = &depth_stencil,
    .pColorBlendState = &color_blending,
    .pDynamicState = &dynamic_state,
    .format = pipeline->format,
    .renderPass = NULL,
    .basePipelineHandle = VK_NULL_HANDLE,
};

The color attachment is utilizing the format VK_FORMAT_R8G8B8A8_SRGB and the depth VK_FORMAT_D32_SFLOAT when rendering with VkRenderingInfo.

Right here is the entrance of a colored Suzanne, you’ll be able to see the ear showing by means of the face on the correct

Vulkan vertex from again peeking by means of

And the again, with the geometry from the face peeking by means of.

enter image description here

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments