diff --git a/Assets/Scripts/OpenTS2/Rendering/Batching.cs b/Assets/Scripts/OpenTS2/Rendering/Batching.cs index e8bc2b9..7e42dc0 100644 --- a/Assets/Scripts/OpenTS2/Rendering/Batching.cs +++ b/Assets/Scripts/OpenTS2/Rendering/Batching.cs @@ -8,26 +8,15 @@ namespace OpenTS2.Rendering { public static class Batching { - struct NonBatchedCandidate - { - public Mesh Mesh; - public Material Material; - public Transform Transform; - public NonBatchedCandidate(Mesh mesh, Material material, Transform transform) - { - Mesh = mesh; - Material = material; - Transform = transform; - } - } - struct BatchCandidate { + public Material Material; public Mesh Mesh; public Transform Transform; public int SubMesh; - public BatchCandidate(Mesh mesh, Transform transform, int submesh) + public BatchCandidate(Material material, Mesh mesh, Transform transform, int submesh) { + Material = material; Mesh = mesh; Transform = transform; SubMesh = submesh; @@ -76,7 +65,7 @@ namespace OpenTS2.Rendering { // TODO - Maybe make this function multithreaded. var candidatesByMaterial = new Dictionary>(); - var nonBatchedCandidates = new List(); + var nonBatchedCandidates = new List(); var renderers = parent.GetComponentsInChildren(); foreach (var element in renderers) { @@ -84,14 +73,16 @@ namespace OpenTS2.Rendering if (filter == null) continue; var materials = element.sharedMaterials; + for (var i = 0; i < materials.Length; i++) { var mat = materials[i]; if (filter.sharedMesh.subMeshCount <= i) continue; + var candidate = new BatchCandidate(mat, filter.sharedMesh, filter.transform, i); if (!CanBatchShader(mat.shader)) { - nonBatchedCandidates.Add(new NonBatchedCandidate(filter.sharedMesh, mat, filter.transform)); + nonBatchedCandidates.Add(candidate); continue; } if (!candidatesByMaterial.TryGetValue(mat, out List candidates)) @@ -99,7 +90,7 @@ namespace OpenTS2.Rendering candidates = new List(); candidatesByMaterial[mat] = candidates; } - candidates.Add(new BatchCandidate(filter.sharedMesh, filter.transform, i)); + candidates.Add(candidate); } } var finalGameObject = new GameObject("Batched Objects");