How can I draw a part of a texture on a another texture with transparency?

I am trying to draw a certain part of a Texture2D on a different Texture2D. I have tried using Graphics.CopyTexture, but the problem is I hav some transparent pixels, which won’t just get overlaid, but replace the pixels below entirely. I have also tried using a RenderTexture and Graphics.DrawTexture, but that hasn’t worked for me aswell, and the documentation for DrawTexture is really confusing. Can someone help me with this problem? Thank you!

Well, Unity doesn’t have a built in method to blend two textures on the CPU. I’ve written this simple alpha blend implementation. However it only works if the textures are the same size. Though it could be changed to allow drawing just a section of an image and specifing a location.

However using the GPU you would have more options. Here you can use Graphics.DrawTexture and using a RenderTexture as target. Now you can use any shader you want to draw to the render texture. However RenderTextures live in the GPU memory. There are ways to extract the result into a normal Texture2D but it’s kinda slow. Though depending on your needs this may still be worth it.

It’s generally easier to provide specific answers if you ask specific questions. That includes what’s the actual purpose of the drawing? How should the result be used? Some context?

you have to change the import settings of the textures to do this sort of thing. under texture type, you would need to select "advanced so you can make the textures readable. and maybe change the format setting.

then just do a little coding. here is a very basic example of changing pixels to put one image on top the other:

	public Texture2D stamp;
	public Texture2D background;
	public Texture2D output;

	//location to stamp
	public int locationx = 0;
	public int locationy = 0;
	void Start () {
		int x, y;

		//make a copy of your background
		output = new Texture2D (background.width, background.height);
		x = output.width;y = output.height;
		while (x>0) {x--;
			y = output.height;
			while (y>0) {y--;
				output.SetPixel(x,y,background.GetPixel(x,y));}}
		

		// page through all your pixels of stamp
		x = stamp.width;y = stamp.height;
		while (x>0) {x--;
		y = stamp.height;
		while (y>0) {y--;
				if(x+locationx<background.width&&y+locationy<background.height){
				Color cs = stamp.GetPixel(x,y);
				Color cb = background.GetPixel(x+locationx,y+locationy);
				float a = cs.a;//<---alph of the stamp pixel;
					// mix colors based on alpha channel
				float r = (cs.r*a)+(cb.r*(1-a));
				float g = (cs.g*a)+(cb.g*(1-a));
				float b = (cs.b*a)+(cb.b*(1-a));
				      
				output.SetPixel(x+locationx,y+locationy,new Color(r,g,b,1));

				}
						}}
		output.Apply ();
		

	}