Alpha blending on Image

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By exuin

I want to generate an image that looks exactly like (color-wise) what I see on-screen when I have a partially transparent TextureRect over another TextureRect. I can’t take a screenshot because the generated image will be at a higher resolution than the screen. I think it’s called alpha blending? But Color.blend doesn’t seem to return the right value.

:bust_in_silhouette: Reply From: exuin

Nevermind I found an algorithm on wikipedia lol

here is the implementation

func alpha_blend(color_1, color_2) -> Color:
	var result_a = color_1.a + color_2.a * (1 - color_1.a)
	var result_rgb = (color_1 * color_1.a + color_2 * color_2.a * (1 - color_1.a)) / result_a
	result_rgb.a = result_a
	return result_rgb

thanks self best answer

exuin | 2020-12-23 19:47

:bust_in_silhouette: Reply From: exuin

THERE WAS A FUNCTION FOR IT ALREADY AAAAAAAAA