public override bool Calculate() { if (Inputs[0].connection != null) { inputResolution = Inputs[0].connection.GetValue<IntPairClass>(); if (inputResolution.GetProduct() != 0) { outputImage = ImageHelperClass.MakeMonoSolidColor(value, inputResolution); Outputs[0].SetValue<Texture2D>(outputImage); } } return true; }
public static Texture2D MakeSolidColor(Color color, IntPairClass resolution) { if(resolution.GetProduct() > 0) { Texture2D toReturn = new Texture2D(resolution.value01, resolution.value02, TextureFormat.RGBA32, true); Color[] colors = new Color[resolution.GetProduct()]; for(int i = 0; i < colors.Length; i++) { colors[i] = color; } toReturn.SetPixels(0, 0, toReturn.width, toReturn.height, colors); toReturn.Apply(true); return toReturn; } else { return Texture2D.whiteTexture; } }
public static Texture2D MakeReplaceAlpha(Texture2D image, Texture2D alpha) { Color[] originalColors = image.GetPixels(0, 0, image.width, image.height); Color[] alphaColors = alpha.GetPixels(0, 0, alpha.width, alpha.height); IntPairClass originalResolution = new IntPairClass(image); IntPairClass alphaResolution = new IntPairClass(alpha); IntPairClass res = new IntPairClass(); res.SetFromMinimum(originalResolution, alphaResolution); Color[] contrastedColors = new Color[res.GetProduct()]; for (int i = 0; i < contrastedColors.Length; i++) { Color c = originalColors[i]; contrastedColors[i] = new Color(c.r, c.g, c.b, alphaColors[i].a); } Texture2D toReturn = new Texture2D(res.value01, res.value02, TextureFormat.RGBA32, true); toReturn.SetPixels(0, 0, res.value01, res.value02, contrastedColors); toReturn.Apply(true); return toReturn; }