diff --git a/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs b/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs index c4628c12f..f7e3f222d 100644 --- a/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs +++ b/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs @@ -49,6 +49,9 @@ public override void Process(BuildContext context, MeshInfo2 target) var meshInfos = skinnedMeshRenderers.Select(context.GetMeshInfoFor) .Concat(staticMeshRenderers.Select(context.GetMeshInfoFor)) .ToArray(); + + foreach (var meshInfo2 in meshInfos) meshInfo2.FlattenMultiPassRendering("Merge Skinned Mesh"); + var sourceMaterials = meshInfos.Select(x => x.SubMeshes.Select(y => y.SharedMaterial).ToArray()).ToArray(); Profiler.EndSample(); diff --git a/Editor/Processors/SkinnedMeshes/MergeToonLitMaterialProcessor.cs b/Editor/Processors/SkinnedMeshes/MergeToonLitMaterialProcessor.cs index 6b4cdd2f3..4fc5296a6 100644 --- a/Editor/Processors/SkinnedMeshes/MergeToonLitMaterialProcessor.cs +++ b/Editor/Processors/SkinnedMeshes/MergeToonLitMaterialProcessor.cs @@ -84,6 +84,7 @@ public override void Process(BuildContext context, MeshInfo2 target) } // merge submeshes + target.FlattenMultiPassRendering("Merge Toon Lit"); var copied = target.SubMeshes.Where((_, i) => !mergingIndices[i]); var materials = target.SubMeshes.Select(x => x.SharedMaterial).ToArray(); var merged = Component.merges.Select(x => new SubMesh( diff --git a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs b/Editor/Processors/SkinnedMeshes/MeshInfo2.cs index b1d4defbb..55051b66d 100644 --- a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs +++ b/Editor/Processors/SkinnedMeshes/MeshInfo2.cs @@ -399,6 +399,22 @@ private void RemoveUnusedBones() Bones.RemoveAll(x => !usedBones.Contains(x)); } + /// true if we flattened multi pass rendering + public void FlattenMultiPassRendering(string reasonComponent) + { + if (SubMeshes.All(x => x.SharedMaterials.Length == 1)) return; + + BuildReport.LogWarning("MeshInfo2:warning:multiPassRendering", reasonComponent) + ?.WithContext(SourceRenderer); + + // flatten SubMeshes + var subMeshes = SubMeshes.ToArray(); + SubMeshes.Clear(); + foreach (var subMesh in subMeshes) + foreach (var material in subMesh.SharedMaterials) + SubMeshes.Add(new SubMesh(subMesh.Triangles, material)); + } + public void WriteToMesh(Mesh destMesh) { Optimize(); diff --git a/Localization/en.po b/Localization/en.po index 881394c91..17729a6e7 100644 --- a/Localization/en.po +++ b/Localization/en.po @@ -440,6 +440,16 @@ msgstr "BlendShape(s) for eyelids are Removed / frozen." #endregion +#region MeshInfo2 + +msgid "MeshInfo2:warning:multiPassRendering" +msgstr "" +"Multi pass rendering with multiple materials is used in mesh with {0}.\n" +"There's no big difference in actual performance, but the number of polygons in the performance rank will increase.\n" +"Using multi pass rendering often not be intended. Please check if you intended to use multi pass rendering." + +#endregion + # region ErrorReporter msgid "ErrorReporter:error.internal_error" diff --git a/Localization/ja.po b/Localization/ja.po index 928e82bdf..26aa55588 100644 --- a/Localization/ja.po +++ b/Localization/ja.po @@ -376,6 +376,16 @@ msgstr "瞬き用のBlendShapeが削除・固定されています" #endregion +#region MeshInfo2 + +msgid "MeshInfo2:warning:multiPassRendering" +msgstr "" +"複数マテリアルによるマルチパスレンダリングが{0}を使用しているメッシュで使用されています。\n" +"実際の負荷に大きな差はありませんが、パフォーマンスランクにおけるポリゴン数が増えるなどの影響があります。\n" +"マルチパスレンダリングを意図して適用しているかを確認してください。" + +#endregion + # region ErrorReporter msgid "ErrorReporter:error.internal_error"