Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Sprite normal mapping - is my approach acceptable?

Discussion in '2D' started by s-m-k, Mar 8, 2014.

  1. s-m-k


    Oct 26, 2013
    Hello there, like many of you, I encountered the problem of sprites and normal mapping.

    What I wanted to do was to solve the problem as simply as possible. In other words, I didn't want to manually mess with sprite packer and other issues related to it, so I wanted to use normal maps as typical sprites - they would match the size of their color version, they would be packed automatically etc.

    So, I generate normal maps by myself (but it's just a batch processing outside of Unity, so it's not that difficult to do) and each sprite becomes something like this (say, I want to just lit some edges):


    Then I cut the sprites inside Unity (using multi-sprites). The left one becomes, for example, "Sprite", the right one becomes "Sprite_Normal". Sizes must match, so I just select the whole rectangles, but that's not a problem for Packer, since Unity converts the sprite to mesh and ignores transparent areas.

    So far, I've got two sprites: "Sprite" and "Sprite_Normal". In the editor mode, I put only the "Sprite" to the scene and attach the script. That script creates a second sprite (on game start) - "Sprite_Normal", attaches it to "Sprite", resets its local transformation and changes the shared material to "LitEdges" (which uses my own shader that deals with normals - it generates only the highlight, nothing more):


    It works and looks pretty good (and it's tweakable). But what bothers me is that for 1 sprite I need 2 sprites in-game, so it probably means an additional draw call per sprite (and per light ofc). On the other side, normal maps are now fully supported by sprite packer, so I don't need to worry about sizes, coordinates and other stuff like that, because Unity does all that dirty work by itself. The workflow seems to be pretty much the same without messing with the "lower-level" stuff too much. Also, I use shared material, so I don't need to duplicate material per sprite. So, is that 1 additional call per sprite (and light) a crime? Or is it good enough if it works for me (it will work smoothly on devices that are our "low limit") and it's simple enough to be physically comfortable with it?

    Or perhaps I completely misunderstand everything and I can easily attach two sprites (I'm not talking about "raw" textures, since I want them to be fully and automatically supported by sprite packers) to one sprite-mesh :) ?

    I'd really love some advices/opinions from more experienced Unity users.

    Attached Files:

    Last edited: Mar 12, 2014