Search Unity

Performance drop when changing vertex colors

Discussion in 'iOS and tvOS' started by Vavius, Aug 31, 2012.

  1. Vavius

    Vavius

    Joined:
    Aug 31, 2012
    Posts:
    20
    I am making a game with procedurally generated levels and geometry (long trails from some game objects).
    Unfortunately, Unity works in a wrong way with modification of mesh attributes (position, colors, etc).

    Another posts about the same problem:
    http://forum.unity3d.com/threads/11...loss-in-Mesh.CreateVBO-for-dynamic-meshes-IOS
    http://forum.unity3d.com/threads/111870-Procedural-mesh-update-slow-on-iphone-4

    I'm creating a regular grid mesh (440 verts and 798 tris) that is something like a half-pipe with regular grid. I want to colorize a subset of vertices dynamically.

    Here some stats from my iPhone 4. Rendering a mesh takes 0.5 ms, but when changing vertex colors each frame (for each vertex) i get 9ms. Using double buffering from posts above improves it to 6ms.
    Using colors32 instead of colors not making any difference.

    Actually, when I modify any attributes on mesh - vertices, normals, tangents, colors, I get spikes and renderer utilization about 6-9ms.

    Maybe it is possible to achieve the same effect using vertex shaders?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Setting vertex colors is relatively slow because Unity has to convert the Color array into something usable. Fortunately Unity 4 has Mesh.colors32, so you can use a Color32 array instead.

    --Eric
     
  3. Vavius

    Vavius

    Joined:
    Aug 31, 2012
    Posts:
    20
    I get same slowdown even when not touching the colors array. I also tried storing colors in tangents.
    When I comment just one line in my update:
    Code (csharp):
    1. mesh.vertices = localVertices;
    the mesh render takes 0.5ms. Just assigning new values (but with the same tris count and layout) to any of mesh arrays cause huge performance drop. That's strange...