Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Is possible to use GetPixel and SetPixel for this?

Discussion in 'General Graphics' started by gabrimo, Dec 5, 2019.

  1. gabrimo

    gabrimo

    Joined:
    May 2, 2015
    Posts:
    92
    Hi everyone, been trying to make a uniform edit system for quite a while now with a small progression. My current scenario consists into a 3D jersey with 2 UV's, first one have the main texture for the whole uniform kit while the second one is being used as reference for the decal placement. I'm using a simple shader created by a friend, which has 2 texture slots, one for the main texture and another for the decal texture itself.

    This small video shows my progress so far:



    I'm changing the offset and tiling values in order to move and scale the decal, not sure if there's a better way to do that. Now my challenge is to apply that decal at the main kit texture, but this is being too hard to figure out by myself. My current attempt envolves GetPixel() and SetPixel() methods, with this texture result:

    https://ibb.co/SXGyFmq

    My function:

    Code (CSharp):
    1. public void GenerateFinalTexture()
    2.     {
    3.         Texture2D mergedTexture = new Texture2D(baseTexture.width, baseTexture.height);
    4.  
    5.         for (int i = 1; i < mergedTexture.width; i++)
    6.         {
    7.             for (int j = 1; j < mergedTexture.height; j++)
    8.             {
    9.                 if(i<=decalTexture.width && j <= decalTexture.height)
    10.                 {
    11.                     Color decalPixelColor = decalTexture.GetPixel(i, j);
    12.                     mergedTexture.SetPixel(i, j, decalPixelColor);
    13.                 }
    14.                 else
    15.                 {
    16.                     Color basePixelColor = baseTexture.GetPixel(i, j);
    17.                     mergedTexture.SetPixel(i, j, basePixelColor);
    18.                 }
    19.             }
    20.         }
    21.         mergedTexture.Apply();
    22.         baseTexture = mergedTexture;
    23.     }
    I kinda understand how I got that image result considering my code, my problem is that I don't know where to go now in order to actually apply the decal into the main texture using the correct position and scale. Does anyone have some ideas to help me out?
     
  2. gabrimo

    gabrimo

    Joined:
    May 2, 2015
    Posts:
    92
    Bump, still need help.