17.1 C
New York
Tuesday, June 10, 2025

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 3

VkPipelineShaderStageCreateInfo shader_stages[info->shader_count];
for (size_t i = 0; i < info->shader_count; ++i) {
    shader_stages[i] = (VkPipelineShaderStageCreateInfo) {
        .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
        .stage = (VkShaderStageFlagBits)info->shaders[i]->module.shader_stage,
        .module = info->shaders[i]->deal with,
        .pName = "most important",
    };
}

const VkPipelineVertexInputStateCreateInfo vertex_input = {
    .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
};

const VkPipelineInputAssemblyStateCreateInfo input_assembly = {
    .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
    .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
    .primitiveRestartEnable = VK_FALSE,
};

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,
};

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_LESS,
    .depthBoundsTestEnable = VK_FALSE,
    .stencilTestEnable = VK_FALSE,
};

const VkPipelineColorBlendAttachmentState color_blend =  VK_COLOR_COMPONENT_A_BIT,
    .blendEnable = VK_FALSE,
;

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,
};

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,
};

Right here is the entrance of Suzanne rendered with VK_POLYGON_MODE_LINE to see the geometry accurately

And the again, with the within of the eyes on the entrance peeking by means of. Some a part of the ear are additionally showing from the again facet.

suzanne back

I’ve tried completely different mixture of VkCullModeFlagBits and VkCompareOp with none success.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles