Graphic Performance Heatmap in Scene View?

Hey;

Is any kind of graphic performance heatmap available in Unity? Like a scene view mode where you see objects with lots of vertices (> 100.000) marked red and objects with lower vertices green?
Or some kind of view which marks all materials in one color, so you can see which objects have a different material on them (to reduce setPassCalls/DrawCalls).
Maybe something which highlights objects with a performance intensive shader.

Fixing performance issues, especially in high quality games would be a lot easier if you could just see the problems.

If these features are not implemented, how would I go about it? Counting vertices or drawing objects with colors based on their material is more than just a shader because the shader never knows about the gameObject, right? So SetSceneViewShaderReplace is no valid solution.

wow i did i talk about that Unity Unite tokyo.

I did some thing like this

Small version in English
https://www.reddit.com/r/Unity3D/comments/e9gz6h/my_own_unity_report_profiler_mobile_how_i/

Basically you need to do all by yourself, and now with URP it gets more complicated.

Some screens

6092532--661830--p72s5jppx3441.png
6092532--661833--hy066hppx3441.png
6092532--661836--qfwbiinpx3441.png

This looks exactly how I imagined it.

Could you give me a brief overview how you were able to get the data from your GameObjects into a visual representation?
Is this some kind of PostProcessing effect or did you swap out all materials on your MeshRenderers?

The most interresting ones for me, are the heatmap and the material-to-color-map.

Material-to-color-map: My first guess would be to loop through all renderers in the scene, get all their materials and create a dictionary where each material gets a random color value.
Then I’d need to write these colors to a buffer? Respecting depth? And draw it with a custom screen space shader on the screen?
Or just swap out all those materials by runtime generated ones, which only have a color and no texture (while the game is running)?

Heatmap - I’ve no idea where I would even try to get the cpu/gpu computation time per pixel … or does it just count the vertices?

Overdraw - this checks if pixels are drawn twice on the screen, right? This information is available in the FrameDebugger, but again, I have no idea how I’d draw it on the screen in realtime. FrameDebugger doesn’t have an API afaik, so I can’t just call it from a C# script to get the required information.

Actually is vesy basic.

For the material i take all rendering inside a layer and create a dictionary, then i just swap the materials, that give me a representation of how many unique materials i have per screen. I gather the materials by GetInstanceID so i dont end with copies.

if (m.GetInstanceID() == r.sharedMaterial.GetInstanceID())
                    {
                        //Already Have Material
                        haveMat = true;
                        break;
                    }

The materials output only color , one color per material.

I use the same for swaping all materials texture for checker texture (is not in the screen above).

The main idea is to have it running on actual machine and not editor. So i can check if the shaders on that layer are heavy, or the texture are heavy etc.

Had some cases that swaping all material inside layer (for example; small assets) gave me performance boost, or changing background layer textures from 512 > 256.

Bad is that it run only one frame, if you load any asset after you turn the viewer ON it wont be affected. (need to gather data again)

Overdraw is unity base implementation (replacement shaders, you can download unity shader library), i have updated it for URP like this;

    public override void Create()
    {

        Material overrideMaterial = CoreUtils.CreateEngineMaterial(settings.overDrawShader);
        RenderObjects.CustomCameraSettings cameraSettings = new RenderObjects.CustomCameraSettings();

        FilterSettings filter = settings.filterSettings;
        renderObjectsPass = new RenderObjectsPass("OverDraw", RenderPassEvent.AfterRenderingTransparents, null,
           RenderQueueType.Transparent, filter.LayerMask, cameraSettings);

        renderObjectsPass.overrideMaterial = overrideMaterial;
        renderObjectsPass.overrideMaterialPassIndex = 0;
       
        //Heat Map
        blitRenderPass = new BlitHeatMapPass(RenderPassEvent.AfterRenderingTransparents, settings.heatMapShader);
    }

HeatMap is an awful trick, is a map for overdraw.
First i decide my target device, then i do some calculations to check overdraw size ratio and performance (Snapdragon profiler, Adreno, Mali Graphic Profiler), after i get an aproximation of my target device i draw a certain amount of red for that fragment.
At the end i use post process to convert the black/red to ramp map (heat map). Not at all 100% (maybe 70+%?) correct but it work well for the target device.

We do computantion time per pixel using MOC and PVR Editor. but that depends on game resolution, amount of pixels to draw with that shader, culling, etc. So basicaly we have a list of heavy shaders with ID.

Vertex count is the basic, get gertices and actualmemory from object.

Memory, use native calls in java or object-c for ios.

Again, i think is the best to make all that stuff running on the device, if possible one frame so the next frame is clean. Profile after and before, compare.

All that data is gather inside a json file and sent to the server with cool visualization.

There is one guy inside the company who made a polyreduction, he take all mesh and reduce the vertices to check optimization. Im pretty sure he duplicate and remake the mesh at runtime, that will have a lot of overhead for profiling memory, but is good idea, bad is that you can crash the device.

Thanks a lot for all that useful information, I’ll try to implement something like it. :smile:

I hope that some day, unity will add some of these tools into unity.
BTW. when you press all buttons on an X-Box Controller (R1, R2, R3, L1, L2, L3) inside Unity, you get a custom debug menu which I’ve never seen before - there are also some graphic debugging opions.

Runtime Debug Canvas: Debug canvas shows up in play mode

omg thats awesome, will try asap

oh…looks like is HDRP only. i sue URP. :frowning:

Didn’t know that, I was just testing some inputs when it showed up, I was quite surprised.