Is there a Sprites-Default shader without transparency (and does it make sense)?

Hi!

I read this great blog post about Performance Optimizations for Mobile Devices by Robot Invader and I think a lot of stuff in that post is what’s causing our FPS-drops on older devices.

Now, Unity comes with the standard Sprites-Default shader, but I’m not seeing any shader for sprites without transparency? I’m thinking that if we show a sprite with the default sprite shader, then those pixels will be rendered to several times independent of if the actual sprite is transparent or not, because the shader calculates alpha. Is this correct? If so, it seems we could get better performance by using a sprite shader without alpha (where we don’t need the alpha). Googling around, I’m not finding any sprite shader without transparency so I’m worried I might be completely wrong here and that it doesn’t work the way I think it does.

If doesn’t seem completely wacky, does anyone know where to find a version of the Sprites-Default shader without transparency?

Currently there are only 2 official sprite shaders. But yes, blending hardware can be deactivated with Blend None in the shader, and then values are directly written to the screen instead of reading the backbiter and doing combining math… can gain a bit there. Most gains are probably from having sprite geometry that fits the shape of the object, because that eliminates a lot of fragments that don’t even need to be processed.

Thanks for responding imaginaryhuman. Your last sentence is a bit interesting. “Most gains are probably from having sprite geometry that fits the shape of the object, because that eliminates a lot of fragments that don’t even need to be processed.”. As far as I understand it, Unity already does that for me? In the scene view, if I change how things are viewed from Textured to Wireframe, I can see that the sprites I’m using are rendered with a geometry that fits the sprite. If I have a sprite of a transparent circle, I can see that the wireframe isn’t a square but a polygon forming a circle. So, “most gains” are already gained by default then?

yes. however as you suspect, even the pixels that do get drawn, would get drawn faster if they didn’t have to do alpha blending. so a non-blending sprite shader should still perform faster than one that blends. if you can get the source code to the shader, just change the Blend GL_ONE GL_ONE_MINUS_SRC_ALPHA to Blend None.

What some people also do is enable alpha blending for the perimeter of an object by sectioning that off into a separate piece of geometry/sprite, then ‘fill’ the interior with solid non-blended pixels using a different shader.

1 Like

Thanks for explaining. At least I know what I’m going to experiment with now. I’ll do some profiling as my project is now and then with the modified opaque sprite shader and compare the results.

I’m not sure the unity 5 shaders compile the code for parts that are unused… would assume the same applies to their sprite shader?.. a way of testing it would be to try and change the alpha while the compiled game is running I guess, since trying to do so on the normal standard shaders results in no change unless you manually adjust their shader during runtime (which doesnt carry through to the compiled game from my small tests)

e.g…material.EnableKeyword (“_EMISSION”);

only works in the editor for me