Skip to content

Commit

Permalink
fix: Support multi pass rendering in Merge Skinned Mesh and MergeToon…
Browse files Browse the repository at this point in the history
…Lit with warning
  • Loading branch information
anatawa12 committed Oct 30, 2023
1 parent 9f4384f commit 05e3af4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions Editor/Processors/SkinnedMeshes/MeshInfo2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,22 @@ private void RemoveUnusedBones()
Bones.RemoveAll(x => !usedBones.Contains(x));
}

/// <returns>true if we flattened multi pass rendering</returns>
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();
Expand Down
10 changes: 10 additions & 0 deletions Localization/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions Localization/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 05e3af4

Please sign in to comment.