diff --git a/src/GraphicsPipelineBuilder.cpp b/src/GraphicsPipelineBuilder.cpp index 3010d64..9fc0bd0 100644 --- a/src/GraphicsPipelineBuilder.cpp +++ b/src/GraphicsPipelineBuilder.cpp @@ -99,6 +99,41 @@ auto GraphicsPipelineBuilder::disable_blending() -> GraphicsPipelineBuilder & return *this; } +auto GraphicsPipelineBuilder::enable_blending_additive() + -> GraphicsPipelineBuilder & +{ + m_color_blend_attachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT + | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT + | VK_COLOR_COMPONENT_A_BIT; + m_color_blend_attachment.blendEnable = VK_TRUE; + m_color_blend_attachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + m_color_blend_attachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE; + m_color_blend_attachment.colorBlendOp = VK_BLEND_OP_ADD; + m_color_blend_attachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; + m_color_blend_attachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; + m_color_blend_attachment.alphaBlendOp = VK_BLEND_OP_ADD; + + return *this; +} + +auto GraphicsPipelineBuilder::enable_blending_alpha_blend() + -> GraphicsPipelineBuilder & +{ + m_color_blend_attachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT + | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT + | VK_COLOR_COMPONENT_A_BIT; + m_color_blend_attachment.blendEnable = VK_TRUE; + m_color_blend_attachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + m_color_blend_attachment.dstColorBlendFactor + = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + m_color_blend_attachment.colorBlendOp = VK_BLEND_OP_ADD; + m_color_blend_attachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; + m_color_blend_attachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; + m_color_blend_attachment.alphaBlendOp = VK_BLEND_OP_ADD; + + return *this; +} + auto GraphicsPipelineBuilder::set_color_attachment_format(VkFormat format) -> GraphicsPipelineBuilder & { diff --git a/src/GraphicsPipelineBuilder.h b/src/GraphicsPipelineBuilder.h index 18c0a70..77ca58a 100644 --- a/src/GraphicsPipelineBuilder.h +++ b/src/GraphicsPipelineBuilder.h @@ -26,6 +26,8 @@ struct GraphicsPipelineBuilder { -> GraphicsPipelineBuilder &; auto set_multisampling_none() -> GraphicsPipelineBuilder &; auto disable_blending() -> GraphicsPipelineBuilder &; + auto enable_blending_additive() -> GraphicsPipelineBuilder &; + auto enable_blending_alpha_blend() -> GraphicsPipelineBuilder &; auto set_color_attachment_format(VkFormat format) -> GraphicsPipelineBuilder &; auto set_depth_format(VkFormat format) -> GraphicsPipelineBuilder &; diff --git a/src/VulkanRenderer.cpp b/src/VulkanRenderer.cpp index 847beb9..6e9e845 100644 --- a/src/VulkanRenderer.cpp +++ b/src/VulkanRenderer.cpp @@ -417,7 +417,7 @@ auto VulkanRenderer::triangle_pipeline_init() -> void .set_input_topology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) .set_polygon_mode(VK_POLYGON_MODE_FILL) .set_multisampling_none() - .disable_blending() + .enable_blending_additive() .disable_depth_testing() .set_color_attachment_format(m_vk.draw_image.format) .set_depth_format(m_vk.depth_image.format) @@ -781,8 +781,8 @@ auto VulkanRenderer::draw_geometry(VkCommandBuffer cmd) -> void GPUDrawPushConstants push_constants; auto rect_model { smath::scale( - smath::translate(smath::Vec3 { 0.0f, 0.0f, -5.0f }), - smath::Vec3 { 5.0f, 5.0f, 1.0f }) }; + smath::translate(smath::Vec3 { 0.0f, 0.0f, -5.0f }), + smath::Vec3 { 5.0f, 5.0f, 1.0f }) }; push_constants.world_matrix = view_projection * rect_model; push_constants.vertex_buffer = m_vk.rectangle.vertex_buffer_address;