I’m trying to show a texture of a circular object on a flat mesh. I’m going to be showing thousands of these in a VR experience (mobile), so I’d like it to be as performant as possible.
First, I created a flat mesh as a 16-vertex circular plane. The circular texture fits quite well in this polygon. However, the VR experience was not great (low FPS).
Then, I had the idea of going down to just 3 vertices. I made the circular texture such that anything outside of it has an alpha of 0 and I enabled the “Alpha Is Transparency” option. In the material (Particles/Standard Unlit), I changed the “Rendering Mode” to “Cutout”. Everything works, but it’s actually a little slower than using the 16-vertex polygon, which kind of surprised me. Is transparency that expensive?
Is there a more performant way of doing what I’m trying to do? By the way, I’m using Unity 2020.3.22f1.
I would guess the most performant way would either use a shader to make the circles onto a triangle (using alpha clip and opaque to avoid overdraw), or to simply model the circle, so you can use the opaque geometry optimisations.
Yep, transparency is expensive. You should use the particle system for this. Or if the balls aren’t moving then you could just merge them all into a single mesh.
Also consider using vertex lighting and avoiding pixel shaders in general.
Can you explain what you mean by using a shader to make the circles onto a triangle, or provide a link that explains this? I’m new to this concept, and I would like to learn more about it. Thank you!
The balls aren’t moving, so I’m relying on Unity’s static batching to merge the meshes automatically, which it does (I can see that batching is very low).
Could you explain a little more on using vertex lighting for what I’m doing, or provide a link that explains this topic? Currently, I’m using emission lighting to illuminate the balls (lanterns). Thank you.
I think you could draw them using the VFX graph with gpu particles
Drawing a 8ish sided circle with a tiny bit of alpha clipping might be best I assume
Generally speaking, if you’re going to use transparency on mobile then you’ll want to use full alpha transparency rather than cutout. Mobile GPUs are notoriously bad at using the clip() command which is what alpha cutout utilizes so it’s often somewhat better to just use alpha blending even if the blend factor is actually zero. The downside is of course you’ll have to pay the cost of a lot of overdraw.
I’m also of the opinion that you should look into a way of modeling the geometry closer to a circle than a triangle. Even though your platform is also quite notorious for having low vertex capacity as well (you really just have all the short sticks in this case don’t you ) it still might be a great deal faster than having lots of overdraw or lots of alpha clipping.
Vertex Lighting is a rendering path that you can select from the Camera’s inspector settings. It’s the old way of shading triangles by giving each vertex a color and then having the GPU quickly interpolate the triangle’s pixels colors using the vertex colors.