From a3c74c361ccba6f0ecee686d7e336cf905246c38 Mon Sep 17 00:00:00 2001 From: yum Date: Sun, 18 Jan 2026 09:02:07 -0800 Subject: Impostors: combine metallic gloss & depth atlases --- Scripts/Impostors.cs | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'Scripts') diff --git a/Scripts/Impostors.cs b/Scripts/Impostors.cs index 3212341..29d92d0 100755 --- a/Scripts/Impostors.cs +++ b/Scripts/Impostors.cs @@ -444,21 +444,42 @@ public class Impostors : MonoBehaviour string baseName = gameObject.name.Replace(" ", "_"); + // Dilate before combining + DilateTexture(albedoAtlas, albedoAtlas, preserveAlpha: true); + DilateTexture(normalAtlas, albedoAtlas); + DilateTexture(metallicGlossAtlas, albedoAtlas); + DilateDepthTexture(depthAtlas, albedoAtlas); + + // Combine metallic_gloss (RG) with depth (B) into a single texture + Texture2D combinedAtlas = new Texture2D(metallicGlossAtlas.width, metallicGlossAtlas.height, TextureFormat.RGBA32, false); + Color[] metallicGlossPixels = metallicGlossAtlas.GetPixels(); + Color[] depthPixels = depthAtlas.GetPixels(); + Color[] combinedPixels = new Color[metallicGlossPixels.Length]; + + for (int i = 0; i < combinedPixels.Length; i++) + { + combinedPixels[i] = new Color( + metallicGlossPixels[i].r, // Metallic + metallicGlossPixels[i].g, // Gloss + depthPixels[i].r, // Depth + 1.0f // Alpha (unused) + ); + } + combinedAtlas.SetPixels(combinedPixels); + combinedAtlas.Apply(); + + // Clean up the separate textures + DestroyImmediate(metallicGlossAtlas); + DestroyImmediate(depthAtlas); + var exportSettings = new (TextureExportSettings settings, string materialProp)[] { (new TextureExportSettings("albedo", mipmaps: true, sRGB: true, alphaTransparency: true), "_Impostors_Atlas"), (new TextureExportSettings("normal", mipmaps: true, sRGB: false), "_Impostors_Normal_Atlas"), - (new TextureExportSettings("metallic_gloss", mipmaps: true, sRGB: false), "_Impostors_Metallic_Gloss_Atlas"), - (new TextureExportSettings("depth", isEXR: false, mipmaps: false, sRGB: false, filter: FilterMode.Bilinear, uncompressed: true), "_Impostors_Depth_Atlas") + (new TextureExportSettings("metallic_gloss_depth", mipmaps: true, sRGB: false, uncompressed: true), "_Impostors_Metallic_Gloss_Depth_Atlas") }; - // Dilate RGB to prevent dark halos from texture filtering - DilateTexture(albedoAtlas, albedoAtlas, preserveAlpha: true); - DilateTexture(normalAtlas, albedoAtlas); - DilateTexture(metallicGlossAtlas, albedoAtlas); - DilateDepthTexture(depthAtlas, albedoAtlas); - - Texture2D[] atlases = { albedoAtlas, normalAtlas, metallicGlossAtlas, depthAtlas }; + Texture2D[] atlases = { albedoAtlas, normalAtlas, combinedAtlas }; string[] paths = new string[exportSettings.Length]; for (int i = 0; i < exportSettings.Length; i++) SaveAndConfigureTexture(atlases[i], exportSettings[i].settings, baseName, out paths[i]); -- cgit v1.2.3