adrien-ben / imgui-rs-vulkan-renderer

A Vulkan renderer for imgui-rs using Ash
MIT License
63 stars 19 forks source link

Fix blend function #26

Closed Ax9D closed 2 years ago

Ax9D commented 2 years ago

Hello! Thank you for this project! I found this bug while integrating it into my renderer, The alpha values of transparent textures is not being blended properly leading to the alpha of the texture overiding anything below it.

Here's a capture in renderdoc to demonstrate this in the case of font textures: image

This produces artifacts like this when the ui is composited on top, alpha artifact

This is caused by the Dst Alpha Blend Factor being set to vk::BlendFactor::ZERO, resulting in the alpha blending equation

final.a =  src.a * 1.0 + dst.a * 0.0

The correct Dst Alpha Blend Factor would be vk::BlendFactor::ONE_MINUS_SRC_ALPHA, resulting in the alpha blending equation,

final.a = src.a * 1.0 + dst.a * (1.0 - src.a)

which looks like:

image

This is also the blend function used in imgui's reference Vulkan implementation and in the OpenGL glow implementation.

adrien-ben commented 2 years ago

Hi ! Thanks for opening the PR !

Indeed this is bad, nice catch ;)

I'll try to release a 1.1.1 later today.

adrien-ben commented 2 years ago

It's available :)