diff options
| author | yum <yum.food.vr@gmail.com> | 2026-01-18 09:02:07 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-01-18 09:02:07 -0800 |
| commit | a3c74c361ccba6f0ecee686d7e336cf905246c38 (patch) | |
| tree | c5ff736ddad6be070302a8c83de533103bb5f4ae /Scripts | |
| parent | 50e451441f628aa3a28241af118700ae12147583 (diff) | |
Impostors: combine metallic gloss & depth atlases
Diffstat (limited to 'Scripts')
| -rwxr-xr-x | Scripts/Impostors.cs | 39 |
1 files changed, 30 insertions, 9 deletions
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]); |
