Z
Z
zeni1agent2022-02-24 19:16:56
Unity
zeni1agent, 2022-02-24 19:16:56

How to merge two textures into one and add them to the model?

I want to apply two transparent textures on one 3d model.

public static Texture2D CombineTexture(Texture2D background, Texture2D TodrawLogo)
  {
    int width = TodrawLogo.width;
    int height = TodrawLogo.height;

    int backWidth = background.width;
    int backHeight = background.height;
    // bottom right corner
    int startX = backWidth - width;
    int startY = backHeight - height;

    // loop through texture
    int y = 0;
    while (y < backHeight) {
      int x = 0;
      while (x < backWidth) {
        // set normal pixels
        background.SetPixel(x,y,background.GetPixel(x,y));
        // if we are at bottom right apply logo 
        //TODO also check alpha, if there is no alpha apply it!
        if(x >= startX && y < backHeight- startY)
          background.SetPixel(x,y,TodrawLogo.GetPixel(x-startX,y-startY));
        ++x;
      }
      ++y;
    }
    background.Apply();
    return background;
  }
  
  public GameObject TestObject;
  public Texture2D Back1, Back2, NewTexture;
  public Material NewMaterial;
  
  
  //
  
  
  public void RunTest()
  {
    TestObject = GameObject.Find("TestCart");
    TestObject.GetComponent<Animator>().Play("Action");
    Back1.LoadImage("Sprite/Back/1");
    Back2.LoadImage("Sprite/Back/2");
    NewTexture = CombineTexture(Back1,Back2);
    NewMaterial.Albedo.Add(NewTexture);
    TestObject.Materials = NewMaterial;
  }


I'm new to Unity, so I don't know what properties and functions to use to do it.
Api did not help me because there is too much information and I don't know which one I need.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question