完成透明的渲染

This commit is contained in:
xsl
2025-09-26 18:21:06 +08:00
parent 57ac3a674c
commit 326593eb4f
4 changed files with 52 additions and 17 deletions
+44 -13
View File
@@ -568,6 +568,12 @@ void TextureLoading::build_command_buffers()
vkCmdDraw(draw_cmd_buffers[i], 6, 1, 0, 0);
draw_point_cloud(draw_cmd_buffers[i]);
//draw_point_cloud_line(draw_cmd_buffers[i]);
vkCmdBindDescriptorSets(draw_cmd_buffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptor_set, 0, NULL);
vkCmdBindPipeline(draw_cmd_buffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.solid);
@@ -576,9 +582,6 @@ void TextureLoading::build_command_buffers()
vkCmdBindIndexBuffer(draw_cmd_buffers[i], index_buffer->get_handle(), 0, VK_INDEX_TYPE_UINT32);
vkCmdDrawIndexed(draw_cmd_buffers[i], index_count, 1, 0, 0, 0);
draw_point_cloud(draw_cmd_buffers[i]);
//draw_point_cloud_line(draw_cmd_buffers[i]);
//draw_ui(draw_cmd_buffers[i]);
vkCmdEndRenderPass(draw_cmd_buffers[i]);
@@ -1095,15 +1098,37 @@ void TextureLoading::prepare_pipelines()
VK_FRONT_FACE_COUNTER_CLOCKWISE,
0);
VkPipelineColorBlendAttachmentState blend_attachment_state =
vkb::initializers::pipeline_color_blend_attachment_state(
0xf,
VK_FALSE);
//VkPipelineColorBlendAttachmentState blend_attachment_state =
// vkb::initializers::pipeline_color_blend_attachment_state(
// 0xf,
// VK_FALSE);
VkPipelineColorBlendStateCreateInfo color_blend_state =
vkb::initializers::pipeline_color_blend_state_create_info(
1,
&blend_attachment_state);
VkPipelineColorBlendAttachmentState colorBlendAttachment{};
colorBlendAttachment.blendEnable = VK_TRUE;
colorBlendAttachment.colorWriteMask =
VK_COLOR_COMPONENT_R_BIT |
VK_COLOR_COMPONENT_G_BIT |
VK_COLOR_COMPONENT_B_BIT |
VK_COLOR_COMPONENT_A_BIT;
// 常用的Alpha混合公式
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
//VkPipelineColorBlendStateCreateInfo color_blend_state =
// vkb::initializers::pipeline_color_blend_state_create_info(
// 1,
// &blend_attachment_state);
VkPipelineColorBlendStateCreateInfo colorBlending{};
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
colorBlending.logicOpEnable = VK_FALSE;
colorBlending.attachmentCount = 1;
colorBlending.pAttachments = &colorBlendAttachment;
// Note: Using reversed depth-buffer for increased precision, so Greater depth values are kept
VkPipelineDepthStencilStateCreateInfo depth_stencil_state =
@@ -1160,7 +1185,7 @@ void TextureLoading::prepare_pipelines()
pipeline_create_info.pVertexInputState = &vertex_input_state;
pipeline_create_info.pInputAssemblyState = &input_assembly_state;
pipeline_create_info.pRasterizationState = &rasterization_state;
pipeline_create_info.pColorBlendState = &color_blend_state;
pipeline_create_info.pColorBlendState = &colorBlending; //&color_blend_state;
pipeline_create_info.pMultisampleState = &multisample_state;
pipeline_create_info.pViewportState = &viewport_state;
pipeline_create_info.pDepthStencilState = &depth_stencil_state;
@@ -1479,7 +1504,13 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options)
dataSize = lineImage.size();
processWithVulkan(lineImage.data(), width, height, rowStride, dataSize, texture_point_line);
load_texture();
const char* filename_test = "assets/test_trans.png";
std::vector<unsigned char> image_test;
unsigned w_t, h_t;
unsigned error_t = lodepng::decode(image_test, w_t, h_t, filename_test, LCT_RGBA, 8);
processWithVulkan(image_test.data(), w_t, h_t, w_t * 4, image_test.size(), texture);
//load_texture();
generate_quad();
prepare_uniform_buffers();