# Help blending 2 textures together?

**URL:** <https://forum.godotengine.org/t/help-blending-2-textures-together/80302>\
**Category:** Help\
**Tags:** godot-4, gdscript, 2d\
**Created:** [August 30, 2024, 4:35pm UTC](https://forum.godotengine.org/t/help-blending-2-textures-together/80302 "2024-08-30T16:35:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dowda](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/d/da6949/32.png) [@Dowda](https://forum.godotengine.org/u/Dowda)\
**Post date:** [August 30, 2024, 4:35pm UTC](https://forum.godotengine.org/t/help-blending-2-textures-together/80302/1 "2024-08-30T16:35:08Z")

</div>

### Godot Version

4.3

### Question

I’m trying to create 1 texture out of 2, so I can assign a sprite to work as a clipping mask. The textures are both 32x32 pixels.

Here is the code I’m using to blend the textures together.

 ![help](https://forum.godotengine.org/uploads/default/original/3X/9/7/97ed2b99425c80128d578b910e01ffe131bc9cd9.png)

When I run this code I want the blended texture to matched up, and contain the full textures like this:

 ![help_2](https://forum.godotengine.org/uploads/default/original/3X/0/3/035e29d28b3d8781ee7dc464df6a49db92e5535a.png)

but instead, when I run it, parts of one texture is missing. They are also not aligned.

 ![help_3](https://forum.godotengine.org/uploads/default/original/3X/2/e/2ef3eb426e7f5d1411e151c88c5e2427fda2358b.png)  
I have no idea what I’m doing wrong. Any help is appreciated. Thank you!

---

<div class="post-metadata">

**Author:** ![herrspaten](https://forum.godotengine.org/user_avatar/forum.godotengine.org/herrspaten/32/37079_2.png) [@herrspaten](https://forum.godotengine.org/u/herrspaten)\
**Post date:** [August 30, 2024, 4:46pm UTC](https://forum.godotengine.org/t/help-blending-2-textures-together/80302/2 "2024-08-30T16:46:34Z")

</div>

Can you make sure that the textures are the same size by printing the size? And also print out the “image2.get\_used\_rect()” to make sure its correct. And print the format with “.get\_format()” since they need the same

---

<div class="post-metadata">

**Author:** ![Dowda](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/d/da6949/32.png) [@Dowda](https://forum.godotengine.org/u/Dowda)\
**Post date:** [August 30, 2024, 4:58pm UTC](https://forum.godotengine.org/t/help-blending-2-textures-together/80302/3 "2024-08-30T16:58:56Z")

</div>

I printed all of that out, and yeah they’re the same size and format. When I print “image2.get\_used\_rect()” I get: “[P: (6, 8), S: (20, 17)]”. Do you have any ideas of what I could be doing wrong?

---

<div class="post-metadata">

**Author:** ![tayacan](https://forum.godotengine.org/user_avatar/forum.godotengine.org/tayacan/32/27953_2.png) [@tayacan](https://forum.godotengine.org/u/tayacan)\
**Post date:** [August 30, 2024, 5:01pm UTC](https://forum.godotengine.org/t/help-blending-2-textures-together/80302/4 "2024-08-30T17:01:27Z")

</div>

The documentation for `Image.get_used_rect()` says:

> Returns a Rect2i enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.

So as I understand it, it cuts away the sides of the image if those are transparent. You can probably manually construct a `Rect2i`, something like:

```auto
var rect = Rect2i(Vector2i.ZERO, image1.get_size())
image2.blend_rect(image1, rect, Vector2i.ZERO)

```

---

<div class="post-metadata">

**Author:** ![Dowda](https://forum.godotengine.org/letter_avatar_proxy/v4/letter/d/da6949/32.png) [@Dowda](https://forum.godotengine.org/u/Dowda)\
**Post date:** [August 30, 2024, 5:04pm UTC](https://forum.godotengine.org/t/help-blending-2-textures-together/80302/5 "2024-08-30T17:04:16Z")

</div>

This worked perfectly. Thank you so much!

---

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [September 29, 2024, 5:05pm UTC](https://forum.godotengine.org/t/help-blending-2-textures-together/80302/6 "2024-09-29T17:05:08Z")

</div>

Closed on September 29, 2024, 5:05pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
