/// <summary> /// Invert green channel of the selected texture 2D /// </summary> public static void FlipGreenChannel() { try { string sourcePath = MegascansUtilities.GetSelectedTexture(); if (sourcePath == null) { return; } EditorUtility.DisplayProgressBar("Bridge Plugin", "Flipping green channel...", 0.5f); UnityEngine.Color[] rgbCols = ImportJPG(sourcePath).GetPixels(); UnityEngine.Color[] rgbaCols = new UnityEngine.Color[width * height]; for (int i = 0; i < width * height; ++i) { rgbaCols[i] = rgbCols != null ? rgbCols[i] : new UnityEngine.Color(1.0f, 1.0f, 1.0f); rgbaCols[i].g = 1.0f - rgbaCols[i].g; rgbaCols[i].a = 1.0f; } Texture2D tex = new Texture2D(width, height, TextureFormat.RGBAFloat, false); tex.SetPixels(rgbaCols); File.WriteAllBytes(sourcePath, tex.EncodeToPNG()); AssetDatabase.ImportAsset(sourcePath); MegascansUtilities.HideProgressBar(); Debug.Log("Successfully flipped green channel."); } catch (Exception ex) { Debug.Log("Exception::MegascansImageUtils::Flip Green Channel:: " + ex.ToString()); MegascansUtilities.HideProgressBar(); } }