Unity Shaders that lead to Overdraw Problems

Hi, can someone please help me understand overdraw problems better on iOS devices (where the amount of overdraw happening on screen impacts the performance of the device). The editor’s Overdraw inspector doesn’t pick up on a lot of custom shaders and asset store products, so I need more information to optimize my scene. Actually, the Overdraw inspector just stops working sometimes.

Please help me understand the following:

Alpha blending will be overdrawn… But is this overdraw redrawn per mesh? Per sub-mesh or mesh element? Per UV-set? Or per unity renderer? And/or is it per screen-space pixel? Exact clarification is needed here, as the unity manual doesn’t really specify. I need to know how many time the redrawing is happening.

Shaders with multiple textures… (vertex painted terrain, for example) will often do several passes to render one texture’s coverage over another. Even if this isn’t technically overdraw, does it impact performance in the same way as overdraw? Does a 2-texture blend terrain shader cost double that of an equivalent 1-material shader?

Renderers with more than one material… are also a case where rendering is done several times. For example, a desert terrain has 2 materials:

  • 1 opaque unlit single texture material as a base.
  • 1 second material with alpha channel, animated shader, UV scrolling.
  • Overall effect looks like subtle sand blowing across the surface of the dunes.
    For purposes of optimizing a scene/environment for mobile, is this overdraw?

Single texture materials with other types of blending… Blending that is not alpha-blending (for example, a second texture multiplying the RGB values a first one, not using or modifying alpha channel) -there is no transparency here at all, but the shader is probably an expensive one nonetheless. How does this cost compare to overdraw?

Sorry about all the questions, but I’ve been working around things like this for a while instead of tackling them, and the questions built up over a while

iOS GPU is a tile renderer. Geometry is sorted into tiles. So, all geometry that spans the top left tile is queued up for rendering into that tile. Once this sorting has been performed, you have a list of geometry that needs to be rendered into each tile. Now comes the problem part. This is a mobile GPU. So, to conserve battery life, the shader wants to only render visible pixels. Triangles that affect each pixel are found. Assuming the triangles are opaque, then only the closest (smallest z-depth) pixel needs to go to the shader. This sorting of triangles to tiles, and triangles to pixels is cheaper than doing the PC-style just render everything and rely on a z-buffer to sort. The moment you have any triangle that needs some transparency this per pixel sorting of triangles changes. You still need to sort by depth. But, any transparent triangles will need to be drawn pixel by pixel. A crazy example is a particle system. You might now have hundreds of semi-transparent particles all touching a single pixel, and these particles are sorted (costly) and rendered (more costly) to get the correct colour for the pixel. To come back to your question, the depth complexity (or overdraw) of this particle system is huge.

Where you have a shader that is computing the colour of a pixel, and to do that it’s using alpha effects, that is not costly.

Awesome, that’s exactly what I was looking for. Thanks so much for going into detail :slight_smile:

BTW, for anyone who is looking at this, in order to get the Overdraw inspector to show all your custom shaders and get around the editor bugs… (in the current version 4.5.2)

  • Make sure every shader in your project has a RenderType tag that is correct (i.e. Transparent, for example). If you have written your own or purchased some, you may have to add the tags.

  • Click on isometric scene view (the box in between your “compass” on the scene view) OR change to any main camera rendering mode other than Deferred (which causes the bug)

These two steps are required to make the overdraw inspector work.