diff --git a/Editor/SmartTextureImporter.cs b/Editor/SmartTextureImporter.cs index f479a4d..3dd61f5 100644 --- a/Editor/SmartTextureImporter.cs +++ b/Editor/SmartTextureImporter.cs @@ -114,10 +114,8 @@ public override void OnImportAsset(AssetImportContext ctx) ApplyPropertiesViaSerializedObj(texture); } - - //If we pass the tex to the 3rd arg we can have it show in an Icon as normal, maybe configurable? - //ctx.AddObjectToAsset("mask", texture, texture); - ctx.AddObjectToAsset("mask", texture); + + ctx.AddObjectToAsset("mask", texture, texture); ctx.SetMainObject(texture); } diff --git a/Runtime/TextureChannelPacker.cs b/Runtime/TextureChannelPacker.cs index 20cd558..64bc174 100644 --- a/Runtime/TextureChannelPacker.cs +++ b/Runtime/TextureChannelPacker.cs @@ -39,6 +39,18 @@ private static Material packChannelMaterial } } + static bool CompressedTextureFormat(TextureFormat format) + { + //There should be a much better way to work this out, this might not even be an exhaustive list :( + return format == TextureFormat.BC4 + || format == TextureFormat.BC5 + || format == TextureFormat.BC6H + || format == TextureFormat.BC7 + || format == TextureFormat.DXT1 + || format == TextureFormat.DXT1Crunched + || format == TextureFormat.DXT5 + || format == TextureFormat.DXT5Crunched; + } public static void PackChannels(this Texture2D mask, Texture2D[] textures, TexturePackingSettings[] settings = null, bool generateOnGPU = true) { if (textures == null || textures.Length != 4) @@ -58,24 +70,31 @@ public static void PackChannels(this Texture2D mask, Texture2D[] textures, Textu int width = mask.width; int height = mask.height; int pixelCount = width * height; + bool invalidTextures = false; - foreach (Texture2D t in textures) + for (int i = 0; i < textures.Length; i++) { + var t = textures[i]; if (t != null) { if (!generateOnGPU && !t.isReadable) { - Debug.LogError(t + " texture is not readable. Toogle Read/Write Enable in texture importer. "); - return; + Debug.LogError($"SmartTexture Aborting: {t.name} texture is not readable so we cannot import on CPU. Toogle Read/Write Enable in texture importer. ", t); + invalidTextures = true; } if (t.width != width || t.height != height) { - Debug.LogError(t + " input textures must have the same size."); - return; + Debug.LogWarning($"SmartTexture: {t.name} does not match expected size. This can cause artfacts as the texture will be sampled onto a different size target, mismatches are not advised", t); + } + + if (CompressedTextureFormat(t.format)) + { + Debug.LogWarning($"SmartTexture: {t.name} is already compressed, channel {i} will be double compressed. Please use an uncompressed format, input texture size isn't relevant to the build", t); } } } + if (invalidTextures) return; if (generateOnGPU) {