Skip to content

Commit

Permalink
feat: ignore rendering of particle systems that do not have a SharedM…
Browse files Browse the repository at this point in the history
…aterial and TrailMaterial

Close #118
  • Loading branch information
mob-sakai committed Nov 20, 2020
1 parent 44889c8 commit 08c4aba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Scripts/UIParticleUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ private static void BakeMesh(UIParticle particle)
// No particle to render.
var currentPs = particle.particles[i];
if (!currentPs || !currentPs.IsAlive() || currentPs.particleCount == 0) continue;
var r = currentPs.GetComponent<ParticleSystemRenderer>();
if (!r.sharedMaterial && !r.trailMaterial) continue;

// Calc matrix.
Profiler.BeginSample("[UIParticle] Bake Mesh > Calc matrix");
Expand Down Expand Up @@ -218,7 +220,6 @@ private static void BakeMesh(UIParticle particle)
#endif

// Bake main particles.
var r = currentPs.GetComponent<ParticleSystemRenderer>();
if (CanBakeMesh(r))
{
Profiler.BeginSample("[UIParticle] Bake Mesh > Bake Main Particles");
Expand Down
8 changes: 6 additions & 2 deletions Scripts/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,12 @@ public static void SortForRendering(this List<ParticleSystem> self, Transform tr
var bRenderer = b.GetComponent<ParticleSystemRenderer>();

// Render queue: ascending
var aMat = aRenderer.sharedMaterial;
var bMat = bRenderer.sharedMaterial;
var aMat = aRenderer.sharedMaterial ?? aRenderer.trailMaterial;
var bMat = bRenderer.sharedMaterial ?? bRenderer.trailMaterial;
if (!aMat && !bMat) return 0;
if (!aMat) return -1;
if (!bMat) return 1;

if (aMat.renderQueue != bMat.renderQueue)
return aMat.renderQueue - bMat.renderQueue;

Expand Down

0 comments on commit 08c4aba

Please sign in to comment.