Skip to content

Instantly share code, notes, and snippets.

@xzbobzx
Forked from KenneyNL/textureCombine.cs
Created August 14, 2018 20:15
Show Gist options
  • Save xzbobzx/c6c617c94e9b80b89c6d0ed9cce08b70 to your computer and use it in GitHub Desktop.
Save xzbobzx/c6c617c94e9b80b89c6d0ed9cce08b70 to your computer and use it in GitHub Desktop.
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;
}
compiledTexture.SetPixels(baseColors);
compiledTexture.Apply();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment