Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to get fillrate or average overdraw from unity profiler

Discussion in 'Scripting' started by prayshouse, Sep 12, 2017.

  1. prayshouse

    prayshouse

    Joined:
    Sep 11, 2017
    Posts:
    27
    Hello, I am trying to get fillrate and average overdraw value of each frame with unity profiler. Then I am able to draw a line chart with the data. But it seems there is no way to achieve it with unity profiler, isn't it? I have googled a lot, but I cannot find the way to solve it.
     
    scarofsky likes this.
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I'm not entirely sure that's possible, at least not in a practical way. Measuring overdraw would require you to count the number of times each pixel is drawn to on the graphics card, which would represent a fair bit of overhead. You could probably do custom shaders to achieve this, but I'm not sure the results would be meaningful.
     
  3. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    There is an option to visually see the overdraw right in the editor.
    In the scene tab right in the top left corner there is a drop down that defaults to shaded, you can drop that down and get quite a few different options and Overdraw is one of them.
     
    Kiwasi likes this.
  4. prayshouse

    prayshouse

    Joined:
    Sep 11, 2017
    Posts:
    27
    Thanks a lot. I guess you are right. I am trying to write a shader to view it.
     
  5. prayshouse

    prayshouse

    Joined:
    Sep 11, 2017
    Posts:
    27
    Thank you! Do you know how to measure it in the runtime? For example, we can get to know there is 5x overdraw per pixel in a frame.
     
  6. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    I have no idea how to do that, I use dual monitor setup with the game on one and the editor on the other. I can then watch the editor in Overdraw mode to see how dark the overdraw is, then try to correct it. Did that with alpha as well, as mobile phones are horrible at drawing nothing and drawing too much.
     
  7. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,991
  8. prayshouse

    prayshouse

    Joined:
    Sep 11, 2017
    Posts:
    27
    Oh!! Thank you so much!! That's exactly what I need. It helps a lot!
     
  9. prayshouse

    prayshouse

    Joined:
    Sep 11, 2017
    Posts:
    27
  10. Meceka

    Meceka

    Joined:
    Dec 23, 2013
    Posts:
    420
    Hello prayshouse, I could open the OverdrawToolWindow which is an editor window that shows average overdraw, but I couldn't get the overdraw debug view to show in the game view as in your screenshot. Can you please explain how you could prepare it to work?

    Thanks.
     
  11. prayshouse

    prayshouse

    Joined:
    Sep 11, 2017
    Posts:
    27
    Code (CSharp):
    1. public class OverdrawMonitor : MonoBehaviour
    2. {
    3.     private static OverdrawMonitor instance;
    4.     public static OverdrawMonitor Instance
    5.     {
    6.         get
    7.         {
    8.             if (instance == null)
    9.             {
    10.                 instance = GameObject.FindObjectOfType<OverdrawMonitor>();
    11.                 if (instance == null)
    12.                 {
    13.                     var go = new GameObject("OverdrawMonitor");
    14.                     instance = go.AddComponent<OverdrawMonitor>();
    15.                 }
    16.             }
    17.             return instance;
    18.         }
    19.     }
    20.  
    21.     private new Camera camera;
    22.     private Shader replacementShader;
    23.  
    24.     public void Awake()
    25.     {
    26.         if (Application.isPlaying) DontDestroyOnLoad(gameObject);
    27.         replacementShader = Shader.Find("Debug/OverdrawInt");
    28.  
    29.         camera = GetComponent<Camera>();
    30.         if (camera == null) camera = gameObject.AddComponent<Camera>();
    31.         camera.CopyFrom(Camera.main);
    32.         camera.SetReplacementShader(replacementShader, null);
    33.     }
    34.  
    35.  
    36.     // Use this for initialization
    37.     void Start()
    38.     {
    39.         camera.enabled = false;
    40.     }
    41.  
    42.     // Update is called once per frame
    43.     void Update()
    44.     {
    45.  
    46.     }
    47.  
    48.     public void LateUpdate()
    49.     {
    50.         Camera main = Camera.main;
    51.         camera.CopyFrom(main);
    52.         camera.clearFlags = CameraClearFlags.SolidColor;
    53.         camera.backgroundColor = Color.black;
    54.         camera.SetReplacementShader(replacementShader, null);
    55.  
    56.         transform.position = main.transform.position;
    57.         transform.rotation = main.transform.rotation;
    58.     }
    59. }
    I use the code to create a overdraw camera. In this camera, shaders are replaced by the overdraw shader. Once you switch to the overdraw camera, you will see what I see in the screenshot.
     
    Meceka likes this.
  12. wangjiangang

    wangjiangang

    Joined:
    May 5, 2015
    Posts:
    15
    hi., your platform is android? on android platform shader is wrong~~
     
  13. prayshouse

    prayshouse

    Joined:
    Sep 11, 2017
    Posts:
    27
    I have test my project on xiaomi 5. It works well.