From c32e21aa3e4aa40d3d91059244d54b3ce44971ea Mon Sep 17 00:00:00 2001 From: Geoff Birch <137780197+GBirch33@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:03:20 +0100 Subject: [PATCH 1/5] fix: normals and metallicroughness being converted to gamma space (#148) Texture conversion process changes to allow for Normal map and MetallicRoughness map to be recreated as linear because they're data based information and not colour based information. --- .../AssetBundleConverter.cs | 30 ++++- .../TextureTypeManager.cs | 114 ++++++++++++++++++ .../TextureTypeManager.cs.meta | 3 + 3 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 asset-bundle-converter/Assets/AssetBundleConverter/TextureTypeManager.cs create mode 100644 asset-bundle-converter/Assets/AssetBundleConverter/TextureTypeManager.cs.meta diff --git a/asset-bundle-converter/Assets/AssetBundleConverter/AssetBundleConverter.cs b/asset-bundle-converter/Assets/AssetBundleConverter/AssetBundleConverter.cs index c2827964..f51605c3 100644 --- a/asset-bundle-converter/Assets/AssetBundleConverter/AssetBundleConverter.cs +++ b/asset-bundle-converter/Assets/AssetBundleConverter/AssetBundleConverter.cs @@ -333,7 +333,7 @@ private async Task ProcessAllGltfs() string directory = Path.GetDirectoryName(relativePath); - if (textures.Count > 0) { textures = ExtractEmbedTexturesFromGltf(textures, directory); } + if (textures.Count > 0) { textures = ExtractEmbedTexturesFromGltf(textures, gltfImport, directory); } embedExtractTextureTime.Stop(); @@ -729,10 +729,30 @@ private static void RefreshAssetsWithNoLogs() Debug.unityLogger.logEnabled = true; } - private List ExtractEmbedTexturesFromGltf(List textures, string folderName) + + + private List ExtractEmbedTexturesFromGltf(List textures, IGltfImport gltfImport, string folderName) { var newTextures = new List(); + TextureTypeManager textTypeMan = new TextureTypeManager(); + + for (var t = 0; t < gltfImport.MaterialCount; t++) + { + + var originalMaterial = gltfImport.GetMaterial(t); + var textureProperties = originalMaterial.GetTexturePropertyNameIDs(); + var texturePropertiesNames = originalMaterial.GetTexturePropertyNames(); + + for (int i = 0; i < textureProperties.Count(); i++) + { + int propertyId = textureProperties[i]; + Texture currentTexture = originalMaterial.GetTexture(propertyId); + if (currentTexture) + textTypeMan.AddTextureType(currentTexture.name, TextureInfoExtensions.GetTextureTypeFromString(texturePropertiesNames[i])); + } + } + if (textures.Count > 0) { var texturesRoot = $"{folderName}/Textures/"; @@ -788,12 +808,14 @@ private List ExtractEmbedTexturesFromGltf(List textures, s } else { + TextureInfo texInfo = textTypeMan.GetTextureInfo(tex.name); + RenderTexture tmp = RenderTexture.GetTemporary( tex.width, tex.height, 0, - RenderTextureFormat.Default, - RenderTextureReadWrite.Default); + texInfo.HasAnyType(TextureType.BumpMap) ? RenderTextureFormat.RGHalf : RenderTextureFormat.Default, + texInfo.HasAnyType( TextureType.BumpMap | TextureType.MetallicGlossMap | TextureType.OcclusionMap | TextureType.ParallaxMap | TextureType.SpecGlossMap) ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.Default ); Graphics.Blit(tex, tmp); RenderTexture previous = RenderTexture.active; diff --git a/asset-bundle-converter/Assets/AssetBundleConverter/TextureTypeManager.cs b/asset-bundle-converter/Assets/AssetBundleConverter/TextureTypeManager.cs new file mode 100644 index 00000000..e1dcc55f --- /dev/null +++ b/asset-bundle-converter/Assets/AssetBundleConverter/TextureTypeManager.cs @@ -0,0 +1,114 @@ +using UnityEngine; +using System.Collections.Generic; + +[System.Flags] +public enum TextureType +{ + None = 0, + MainTex = 1 << 0, + BaseMap = 1 << 1, + BumpMap = 1 << 2, + MetallicGlossMap = 1 << 3, + ParallaxMap = 1 << 4, + OcclusionMap = 1 << 5, + EmissionMap = 1 << 6, + SpecGlossMap = 1 << 7 +} + +public struct TextureInfo +{ + public string Name; + public TextureType Types; + + public TextureInfo(string name) + { + Name = name; + Types = TextureType.None; + } +} + +public static class TextureInfoExtensions +{ + public static TextureType GetTextureTypeFromString(string input) + { + switch (input) + { + case "_MainTex" : + return TextureType.MainTex; + case "_BaseMap" : + return TextureType.BaseMap; + case "_BumpMap" : + return TextureType.BumpMap; + case "_MetallicGlossMap" : + return TextureType.MetallicGlossMap; + case "_ParallaxMap" : + return TextureType.ParallaxMap; + case "_OcclusionMap" : + return TextureType.OcclusionMap; + case "_EmissionMap" : + return TextureType.EmissionMap; + case "_SpecGlossMap" : + return TextureType.SpecGlossMap; + default : + return TextureType.None; + } + } + + + + public static TextureInfo AddType(this TextureInfo info, TextureType type) + { + info.Types |= type; + return info; + } + + public static TextureInfo RemoveType(this TextureInfo info, TextureType type) + { + info.Types &= ~type; + return info; + } + + public static bool HasType(this TextureInfo info, TextureType type) + { + return (info.Types & type) != 0; + } + + public static bool HasAnyType(this TextureInfo info, TextureType types) + { + return (info.Types & types) != 0; + } + + public static bool HasAllTypes(this TextureInfo info, TextureType types) + { + return (info.Types & types) == types; + } + + public static string GetTypesString(this TextureInfo info) + { + return $"{info.Name}: {info.Types}"; + } +} + +public class TextureTypeManager : MonoBehaviour +{ + private Dictionary textureInfos = new Dictionary(); + + public void AddTextureType(string textureName, TextureType type) + { + if (!textureInfos.TryGetValue(textureName, out TextureInfo info)) + { + info = new TextureInfo(textureName); + } + textureInfos[textureName] = info.AddType(type); + } + + public TextureInfo GetTextureInfo(string textureName) + { + return textureInfos.TryGetValue(textureName, out TextureInfo info) ? info : new TextureInfo(textureName); + } + + public bool HasTextureType(string textureName, TextureType type) + { + return textureInfos.TryGetValue(textureName, out TextureInfo info) && info.HasType(type); + } +} diff --git a/asset-bundle-converter/Assets/AssetBundleConverter/TextureTypeManager.cs.meta b/asset-bundle-converter/Assets/AssetBundleConverter/TextureTypeManager.cs.meta new file mode 100644 index 00000000..f5302623 --- /dev/null +++ b/asset-bundle-converter/Assets/AssetBundleConverter/TextureTypeManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 87f9278eb97f49b8b91cf2a98cb65ead +timeCreated: 1726744442 \ No newline at end of file From ac0e25dad0324b9fb6cab1e0d48c1c3060d6114c Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Sun, 22 Sep 2024 20:44:15 -0300 Subject: [PATCH 2/5] chore: bump up version (#149) --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e537f262..f3c8e3af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,8 +52,8 @@ ENV PATH=$NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH # Change this value ONLY if we have done breaking changes for every material, doing so is VERY costly ENV AB_VERSION=v13 -ENV AB_VERSION_WINDOWS=v22 -ENV AB_VERSION_MAC=v22 +ENV AB_VERSION_WINDOWS=v23 +ENV AB_VERSION_MAC=v23 # NODE_ENV is used to configure some runtime options, like JSON logger ENV NODE_ENV=production From 845ff3f210704bfc86e25c2ba006bc0de93d6230 Mon Sep 17 00:00:00 2001 From: Alejandro Alvarez Melucci <163010988+AlejandroAlvarezMelucciDCL@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:38:08 -0300 Subject: [PATCH 3/5] chore: ff dependencies (#151) --- .../Assets/git-submodules/unity-shared-dependencies | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asset-bundle-converter/Assets/git-submodules/unity-shared-dependencies b/asset-bundle-converter/Assets/git-submodules/unity-shared-dependencies index 6af93c02..13525c21 160000 --- a/asset-bundle-converter/Assets/git-submodules/unity-shared-dependencies +++ b/asset-bundle-converter/Assets/git-submodules/unity-shared-dependencies @@ -1 +1 @@ -Subproject commit 6af93c02a6e14f2d92b287f04724d97195cb1e97 +Subproject commit 13525c215edf9d903a70f55df12010ef3000184f From 5076ceca8992f167c39feaca13c16dc48ad2ea47 Mon Sep 17 00:00:00 2001 From: Alejandro Alvarez Melucci <163010988+AlejandroAlvarezMelucciDCL@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:55:21 -0300 Subject: [PATCH 4/5] chore: ff dependencies (#152) ff dependencies --- .../Assets/git-submodules/unity-shared-dependencies | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asset-bundle-converter/Assets/git-submodules/unity-shared-dependencies b/asset-bundle-converter/Assets/git-submodules/unity-shared-dependencies index 13525c21..3b398bfe 160000 --- a/asset-bundle-converter/Assets/git-submodules/unity-shared-dependencies +++ b/asset-bundle-converter/Assets/git-submodules/unity-shared-dependencies @@ -1 +1 @@ -Subproject commit 13525c215edf9d903a70f55df12010ef3000184f +Subproject commit 3b398bfe4b3848b2cd5ad2b79dddeef79e2f9ab6 From 8aca86c65444dd47e46696e332afbb1e74023a17 Mon Sep 17 00:00:00 2001 From: davidejensen Date: Thu, 3 Oct 2024 09:25:32 +0200 Subject: [PATCH 5/5] chore: bump ab version (#155) Bump ab version to v24 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f3c8e3af..debecea0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,8 +52,8 @@ ENV PATH=$NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH # Change this value ONLY if we have done breaking changes for every material, doing so is VERY costly ENV AB_VERSION=v13 -ENV AB_VERSION_WINDOWS=v23 -ENV AB_VERSION_MAC=v23 +ENV AB_VERSION_WINDOWS=v24 +ENV AB_VERSION_MAC=v24 # NODE_ENV is used to configure some runtime options, like JSON logger ENV NODE_ENV=production