Skip to content

Commit

Permalink
feat: improve the material batching
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Oct 27, 2020
1 parent 6b397f3 commit 4be5666
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Scripts/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,20 @@ public static void SortForRendering(this List<ParticleSystem> self, Transform tr
var pa = tr.InverseTransformPoint(a.transform.position).z;
var pb = tr.InverseTransformPoint(b.transform.position).z;

return Mathf.Approximately(pa, pb)
? 0
: pa < pb
? 1
: -1;
if (!Mathf.Approximately(pa, pb))
return pa < pb ? 1 : -1;

var aQueue = ra.sharedMaterial.renderQueue;
var bQueue = rb.sharedMaterial.renderQueue;
if (aQueue != bQueue)
return aQueue < bQueue ? 1 : -1;

var aHash = ra.sharedMaterial.GetHashCode();
var bHash = rb.sharedMaterial.GetHashCode();
if (aHash != bHash)
return aHash < bHash ? 1 : -1;

return 0;
});
}

Expand Down

0 comments on commit 4be5666

Please sign in to comment.