Jun 11, 2012

Unity, I Love You, But Your UV Is Horrible

I love Unity.  This is the first engine I felt like I can't make anything better than this.  Of course, it's mostly due to its awesome editor.  But the other day, I found one thing that annoys me: UV coordinates system.

Normally, I(or most graphics programmer, I think?) would map UV coordinates to a texture this way: top-left: (0,0) and bottom-right: (1,1)

(0,0)        (1,0)                 
  +-----+-----+
  |     |     |
  |     |     |
  +-----+-----+
  |     |     |
  |     |     |
  +-----+-----+
(0,1)        (1,1)

This one has a nice benefit: the memory layout of textures match UV coordinate system. So any UV-based texture manipulation becomes easy and straight forward. One example, would be copying a sub rect of a texture based on the UV coords.

But for some reason, Unity maps UV coords differently:  bottom-left(0,0) and top-right(1,1).... so basically it's flipped vertically.


(0,1)        (1,1)                 
  +-----+-----+
  |     |     |
  |     |     |
  +-----+-----+
  |     |     |
  |     |     |
  +-----+-----+
(0,0)        (1,0)


What..? why would you ever do that?  I know some math books use this way, but I can't think of any practical benefits of mapping UVs in this way.  Sometimes we rendering programmer make a wrong decision we are so used to certain notations. And, to me, this is clearly the case.

If there's any benefit i'm missing here, please let me know.  But just don't tell me "it's traditionally done this way, so it must be right". If I was a person who'd accept that kinda BS argument, I'd be a good Christian believing that Jesus was reborn in 3 days after he was killed.









5 comments:

  1. No argument. Unity3D does a lot of stupid things.

    I've tried to bring them up in the forum, but the mods there are more about nuking threads to protect the bottom line then they are about helping people.

    Unity handles UV the same way it handles any other asset. Ass backwards.

    ReplyDelete
  2. Short answer is "OpenGL". Unity started as OpenGL-only, Mac-only engine many many years ago. OpenGL has texture coordinates where zero Y is "bottom" and one is "top".

    Then when other rendering platforms were added, we've implemented a lot of hoops to make the conventions match between GL-like and D3D-like approach. At some point in 2007 or so it seemed that we should just switch to D3D-like convention across the board. But then "mobile" happened, and that has OpenGL ES which uses GL-style convention. At this point the relative importance of GL-like and D3D-like sound about the same, so we're sticking with GL-like.

    So it's "backwards" for programmers who are used to D3D like convention, and "just fine" for ones who are used to GL one.

    @Anonymous: we generally don't delete threads on our forums (the only exceptions; spam, racism, links to pirated software etc. i.e. your usual causes). Discussion "why Unity's UVs are flipped upside down?" is perfectly fine topic and I can't imagine it being deleted. Of course if you start discussion with only "Unity is all ass backwards, discuss!" then I'd say it's fair to lock it since it's not exactly constructive.

    ReplyDelete
    Replies
    1. aras, thanks for clearing that up. but since this opengl UV way doesn't really have any benefit.. is it possible that Unity uses the D3D way and do the "hidden" conversion for opengl at the background?

      I think that would be just so easier for everyone :)

      Delete
  3. What a maggot you are.. Take a swipe at Islam why don't you? No? Much easier to pick on people who won't harm you isn't it? There are much, much smarter people than you who believe Jesus rose in 3 1/2 days & for good reason.

    ReplyDelete
    Replies
    1. My point proven. You failed to give me that good reason you are referring to here. Personal insult like that doesn't work for me. Good rational arguments please. I'm willing to discuss this matter with any intelligent people.

      Delete