完成透明的渲染
This commit is contained in:
@@ -21,9 +21,9 @@ android {
|
|||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
abiFilters.addAll( 'arm64-v8a')
|
abiFilters.addAll( 'arm64-v8a')
|
||||||
//arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static', '-DVKB_VALIDATION_LAYERS=OFF'
|
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static', '-DVKB_VALIDATION_LAYERS=OFF'
|
||||||
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static', '-DVKB_VALIDATION_LAYERS=OFF', "-DCMAKE_BUILD_TYPE=Release"
|
//arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static', '-DVKB_VALIDATION_LAYERS=OFF', "-DCMAKE_BUILD_TYPE=Release"
|
||||||
cppFlags "-DRELEASE_MODE"
|
//cppFlags "-DRELEASE_MODE"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -568,6 +568,12 @@ void TextureLoading::build_command_buffers()
|
|||||||
|
|
||||||
vkCmdDraw(draw_cmd_buffers[i], 6, 1, 0, 0);
|
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);
|
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);
|
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);
|
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);
|
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]);
|
//draw_ui(draw_cmd_buffers[i]);
|
||||||
|
|
||||||
vkCmdEndRenderPass(draw_cmd_buffers[i]);
|
vkCmdEndRenderPass(draw_cmd_buffers[i]);
|
||||||
@@ -1095,15 +1098,37 @@ void TextureLoading::prepare_pipelines()
|
|||||||
VK_FRONT_FACE_COUNTER_CLOCKWISE,
|
VK_FRONT_FACE_COUNTER_CLOCKWISE,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
VkPipelineColorBlendAttachmentState blend_attachment_state =
|
//VkPipelineColorBlendAttachmentState blend_attachment_state =
|
||||||
vkb::initializers::pipeline_color_blend_attachment_state(
|
// vkb::initializers::pipeline_color_blend_attachment_state(
|
||||||
0xf,
|
// 0xf,
|
||||||
VK_FALSE);
|
// VK_FALSE);
|
||||||
|
|
||||||
VkPipelineColorBlendStateCreateInfo color_blend_state =
|
VkPipelineColorBlendAttachmentState colorBlendAttachment{};
|
||||||
vkb::initializers::pipeline_color_blend_state_create_info(
|
colorBlendAttachment.blendEnable = VK_TRUE;
|
||||||
1,
|
colorBlendAttachment.colorWriteMask =
|
||||||
&blend_attachment_state);
|
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
|
// Note: Using reversed depth-buffer for increased precision, so Greater depth values are kept
|
||||||
VkPipelineDepthStencilStateCreateInfo depth_stencil_state =
|
VkPipelineDepthStencilStateCreateInfo depth_stencil_state =
|
||||||
@@ -1160,7 +1185,7 @@ void TextureLoading::prepare_pipelines()
|
|||||||
pipeline_create_info.pVertexInputState = &vertex_input_state;
|
pipeline_create_info.pVertexInputState = &vertex_input_state;
|
||||||
pipeline_create_info.pInputAssemblyState = &input_assembly_state;
|
pipeline_create_info.pInputAssemblyState = &input_assembly_state;
|
||||||
pipeline_create_info.pRasterizationState = &rasterization_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.pMultisampleState = &multisample_state;
|
||||||
pipeline_create_info.pViewportState = &viewport_state;
|
pipeline_create_info.pViewportState = &viewport_state;
|
||||||
pipeline_create_info.pDepthStencilState = &depth_stencil_state;
|
pipeline_create_info.pDepthStencilState = &depth_stencil_state;
|
||||||
@@ -1479,7 +1504,13 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options)
|
|||||||
dataSize = lineImage.size();
|
dataSize = lineImage.size();
|
||||||
processWithVulkan(lineImage.data(), width, height, rowStride, dataSize, texture_point_line);
|
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();
|
generate_quad();
|
||||||
|
|
||||||
prepare_uniform_buffers();
|
prepare_uniform_buffers();
|
||||||
|
|||||||
@@ -37,5 +37,9 @@ void main()
|
|||||||
vec3 diffuse = max(dot(N, L), 0.0) * vec3(1.0);
|
vec3 diffuse = max(dot(N, L), 0.0) * vec3(1.0);
|
||||||
float specular = pow(max(dot(R, V), 0.0), 16.0) * color.a;
|
float specular = pow(max(dot(R, V), 0.0), 16.0) * color.a;
|
||||||
|
|
||||||
outFragColor = vec4(diffuse * color.rgb + specular, 1.0);
|
vec4 textureColor = color;
|
||||||
|
if (textureColor.a < 0.1) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
outFragColor = textureColor;
|
||||||
}
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user