0 votes

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.

Godot version 3.2.3
in Engine by (7,034 points)

2 Answers

0 votes
Best answer


by (7,034 points)
0 votes

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
by (7,034 points)

thanks self best answer

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.