Skip to content

Instantly share code, notes, and snippets.

@KenneyNL
Last active December 14, 2021 22:58
Show Gist options
  • Select an option

  • Save KenneyNL/d431d45f0fd669601f03aad968a02c5d to your computer and use it in GitHub Desktop.

Select an option

Save KenneyNL/d431d45f0fd669601f03aad968a02c5d to your computer and use it in GitHub Desktop.

Revisions

  1. KenneyNL revised this gist Aug 14, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions textureCombine.cs
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@

    }

    baseTexture.SetPixels(baseColors);
    baseTexture.Apply();
    compiledTexture.SetPixels(baseColors);
    compiledTexture.Apply();

    }
  2. KenneyNL created this gist Aug 14, 2018.
    25 changes: 25 additions & 0 deletions textureCombine.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    Texture2D[] layers;

    Texture2D compiledTexture = new Texture2D(layers[0].width, layers[0].height);

    foreach(Texture2D layer in layers){

    Color[] baseColors = compiledTexture.GetPixels();
    Color[] layerColors = layer.GetPixels();

    for(int p = 0; p < baseColors.Length; p++){

    Color resultColor = baseColors[p];

    resultColor.r = baseColors[p].r * (1.0f - layerColors[p].a) + layerColors[p].r * layerColors[p].a;
    resultColor.g = baseColors[p].g * (1.0f - layerColors[p].a) + layerColors[p].g * layerColors[p].a;
    resultColor.b = baseColors[p].b * (1.0f - layerColors[p].a) + layerColors[p].b * layerColors[p].a;

    baseColors[p] = resultColor;

    }

    baseTexture.SetPixels(baseColors);
    baseTexture.Apply();

    }