How to apply a decal in the main texture at the right position of the UV?
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:
My function:
public void GenerateFinalTexture()
{
Texture2D mergedTexture = new Texture2D(baseTexture.width, baseTexture.height);
for (int i = 1; i < mergedTexture.width; i++)
{
for (int j = 1; j < mergedTexture.height; j++)
{
if(i<=decalTexture.width && j <= decalTexture.height)
{
Color decalPixelColor = decalTexture.GetPixel(i, j);
mergedTexture.SetPixel(i, j, decalPixelColor);
}
else
{
Color basePixelColor = baseTexture.GetPixel(i, j);
mergedTexture.SetPixel(i, j, basePixelColor);
}
}
}
mergedTexture.Apply();
baseTexture = mergedTexture;
}
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?
Your answer
![](https://koobas.hobune.stream/wayback/20220612215739im_/https://answers.unity.com/themes/thub/images/avi.jpg)