Merging Textures At Runtime - Not Correct?


I’ve been working on texturing a 3d model for the past few days, and the specific issue I’m working on is being able to turn on and off certain colored regions on the model. This would be similar to layering textures as in [here][1]. The difference being is that none of my textures actually overlap, they exist is different areas of the model with all other parts of the texture being transparent. I got the desired effect to work by writing a custom shader similar to the Decal shader provided by default in Unity; however, my shader took 5+ decals at one time. This runs into the issue where if I want 12+ textures to be merged, then the shader can’t handle it because it runs into the limits of the hardware.

The Issue:

Currently, I am combining textures at run-time and they are not combining properly. Here is what I am getting:

![alt text][2] ![alt text][3] ![alt text][4]

The left two images combined become the right-most image, which clearly is not correct.


public class CNS_Label : MonoBehaviour {
    public Texture2D text1;
    public Texture2D text2;
    public Material material;

    private Texture2D temp;

	// Use this for initialization
	void Start () {
        if (text1 != null && text2 != null)
            temp = new Texture2D(1024, 1024, TextureFormat.ARGB32, false);
            var pixels1 = text1.GetPixels();
            var pixels2 = text2.GetPixels();

            for (int i = 0; i < pixels1.Length; i++)
                pixels1 _+= pixels2*;*_


material.SetTexture(“_DecalTex”, temp);

SaveTextureToFile(temp, “output.png”);
* }*
All the textures are set to the ARGB32 format with mipsmaps turned off.

I fixed the issue somewhat by changing the color combining code:

            for (int i = 0; i < pixels1.Length; i++)
                if (pixels2*.a > 0.5f) {*

pixels1 = pixels2*;*