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

Performance Q: Sewn UVs vs separate islands.

Discussion in 'General Graphics' started by _watcher_, Apr 14, 2016.

  1. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    259
    Can someone explain how Unity treats these and whats the performance impact when i, say, leave my UVs separated and not sew them together into 1 huge piece (big piece like 1 UV island per mesh as opposed to tons of separated UV islands per mesh)?
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I think no impact at all. (logical guess)
    Unity still reads the texture of the model.
    The only issue - which would not impact performance - is edge seams on the rendered mesh.
    Also if different mesh islands had different UV channels for sub mesh materials - that would impact performance - but that isnt the wuestion you asked.
    There might be an impact if mip mapping is on with a high number of UV islands??
     
    _watcher_ likes this.
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    As far as the actual rendering of multiple islands vs single, there is literally zero difference in cost. GPUs render each triangle as a separate thing with little to no knowledge of what other triangles are rendering. At the point of putting pixels to screen it won't care if everything is perfectly stitched or each triangle is at a completely random location.

    However this is a possible impact on the memory usage of the mesh and the cost of the vertex shader, but usually mesh data and vertex shader cost is so negligible in the overall case that it's not likely to be noticeable.

    As for why it comes down to how real time meshes are stored for real time, and this isn't unique to Unity. Each triangle of the mesh has three vertices, and those vertices only store one "set" of data; normals, color, uvs, position. If there are two triangles next to each other sharing a vertex position, if any other other data needs to be different (like a faceted surface or hard edge means they need different normals, or if there's a hard color change, or if your UVs aren't stitched) then this has to be two different vertices in the mesh data. For modelling programs they can store the data for multiple polygons in each vertex, but this greatly increases the complexity and is mostly only useful for when you're doing the modelling, so real time models just split these vertices apart.
     
    xVergilx, _watcher_ and theANMATOR2b like this.
  4. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    259
    Thank You for the replies guys, in my case it was related to a use-case i later completely avoided, but whatever info is here may it help further users in their projects!
     
  5. Max_Bol

    Max_Bol

    Joined:
    May 12, 2014
    Posts:
    168
    This is almost 1 year old, but I would like to give an update on the matter because, first, this is a result that comes early in Google search and, second, because the answer given is actually wrong depending on the situation.

    For the question Does having multiple UVs island (more seams) have more impact on the performance than having as few UVs island as possible? The short answer is Yes. The long answer is It depends on what you're running your game on.

    The thing the answer above didn't get right is when they wrote "it doesn't change the number of triangles". That's wrong. In fact, the UVs is what determines the number of triangles being rendered. This is because each textured face (even if it's textured with 1 single color) are made out of 3 vertex. The vertex are calculated based on the 3D model, but the actual visual data is taken from the UVs. The model is only the "source" for the 3D space position of the vertex.

    Vertex in the middle of UV islands have 1 ID while the ones on the border can have an semi-infinite number of ID. When the GPU is calculating the shader's data so that it can print out the right pixel color on the screen, it scan each of the active vertex in scene generate the pixel data based on the UVs ID used by those vertex.

    Here's an example:
    UVs-ID-Visual-Explaination.png
    The Blue numbers represent the IDs registered to a UVs Island that is "singled". The Red numbers is the same UVs, but cut into 2 islands. Same model, but the one cut in 2 has 3 additional IDs registered into its UVs. The blue vertex numbered 5 is, in the case of the red version, 3 and 6.

    When your shader refers to the UVs data to take their color data out of the texture, those numbers are what is taken into consideration for each faces. This means that each "edges" in your UVs has at least 2 IDs instead of just 1 and that is kept in the memory and computation process.

    The impact isn't as big as you would guess, but it does pushes things a bit during computation. For example, you could see an impact on low-end mobile phones (512MB-1Go of shared RAM) and tablet if your scene is made with over 50,000 tries (triangles) and the UVs are all broken into small pieces for no reason other than that you didn't want to stitch them up a bit. You could say that, in the worse case scenario, the rendering computation would be more intense on the hardware for maybe an additional 12%-18% if you were to break down all the UVs triangles into 1 Island each. Though I'm still not sure how Unity handle the seams' pixel precision, it could also create lot of seams-based artifacts. That's especially true with baked lightmaps (static gameobject in the scenes).
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    Your example has 6 triangles in both cases. UVs have no impact on the triangle count, and your own example helps prove that.

    It does change the vertex count, which is what your example shows, and what I did refer to in my original post. I did simplify things a bit too much in that in my comment about having zero impact on rendering. I was thinking explicitly about the fragment shader side of things, it does potentially have an impact on rendering overall as it can increase the vertex count and thus the number of vertex shader invocations. However in the real world unless you’re breaking every single triangle into it’s own “island”, the impact on performance is negligible, especially since the UV seams are likely happening in the same places as existing hard shaded edges, which are already going to be duplicated verts.

    Of course the “flat shaded” style has been quite popular the last few years, and everyone seems to implement that by making each triangle’s vertices unique, or using geometry shaders (which is even worse), instead of using fragment shader or interpolator techniques that are much cheaper. So the worst case scenario is happening in the wild, and with out any UVs even.
     
    Last edited: Feb 6, 2018
    hippocoder likes this.
  7. jecky111

    jecky111

    Joined:
    Jun 11, 2016
    Posts:
    17
    Sorry for reviving this thread again but I did some tests.

    Okay so i made 2 differently unwrapped cubes in blender. 1st with 2 UV islands, 2nd is with 6 UV islands. Exported to fbx, imported into Unity. I turned off every optimization in import settings. Then I added a material to them. I cleared the scene, added a camera. I put in 500x cubes with the 2 islands. I checked profiler, screenshoot'd the results. For the next test, I selected all the cubes and changed the meshfilter's mesh to the 6 islands variant, played the scene again and checked the profiler. I compared the results: absolutely the exact same numbers for everything.

    ps. I used 500x cubes because Unity's profiler rounds the tri and vert count to hundreds as I can see. Testing environment is LWRP, no lights except environmental, ambient light.

    Is there anything I missed, did wrong or something, or there's really absolutely no performance effect of UV island numbers?
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    Vertices will be split on any edge. Could be from UVs, normals, tangents, or vertex colors. A box usually has flat sides with hard edges, ie: the box edges are all split regardless of 2 UV islands or 6. Try setting the box to be smoothed and try again and you might see a difference. However the overhead of just rendering 500 of something may not show any measurable differences when it's the difference between using 8 vertices or 36 (worst possible case for drawing the 12 triangles of a cube)
     
  9. jecky111

    jecky111

    Joined:
    Jun 11, 2016
    Posts:
    17
    Thank you, with a few smooth shaded spheres now I successfully bumped the rendered vertices count from 59,4k to 193,5k by directly creating bad uv maps :) these kind of tests and informations are important for me to get a better understanding about Unity's rendering
     
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    Note, this has nothing to do with Unity specifically. This is how real-time rendering on all GPUs works.
     
    jecky111 likes this.