Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Editor/SmartTextureImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
29 changes: 24 additions & 5 deletions Runtime/TextureChannelPacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down