I want to know if i can do light effects with spritesheet-animated 2D characters (not body-part animated) I found how to do this with a single normal map: http://robotloveskitty.tumblr.com/post/33164532086/legend-of-dungeon-dynamic-lighting-on-sprites But our characters have different normal Maps depending on the current Sprite of the animator, see that mockup: How can i achieve that the normal maps are linked to each Sprite? Do i have to create a new Material with the right normal Map for every character? I am clueless, my current setup is a SpriteRenderer with Animator
Create 2 sprite sheets - one with the normals and one with the sprite. They must have the same layout - this is important. Import the normal map, set the Texture Type to Normal Map. Make sure to uncheck Create from Grayscale - Unity will otherwise interpret your image as height map and create a normal map from it. Create a material that uses the normal map as Normal Map and the sprite texture as Albedo. Add the material to the sprite. See Screenshot. We've created a short tutorial here: Unity Normal Mapped Sprites
What is actually linking the normal map spritesheet to the albedo spritesheet? When you change the sprite on the renderer (in an animation clip for instance), is it that the material knows which region that sprite represents, and updates the maps to the same region? Is this possible for any map, like Emission for instance?
Yes - it works with animations. The sprite renderer uses the regions from the sprite sheet. They are used for all textures/map assigned to the material. The important thing is that they all use the exact same layout.
Thanks for the quick response. Cool. That's some magic under the hood that I was not aware of! I am reading that playing an animation with a different spritesheet cannot also switch to the appropriate secondary maps, so either multiple materials are necessary, or switching them in code is necessary. I found this script which builds a dictionary of maintexture to secondary maps, and watches for when the maintexture changes to swap the maps automatically. I'm not sure this is the most efficient way, but it's easier than having to worry about one material per spritesheet and swapping them appropriately. Download in this article: http://www.snakehillgames.com/multiple-sprite-sheets-sprite-lamp-and-unity/ Thanks again! Took me awhile to find some definitive information about how this works for spritesheets.
Thanks for the info. Do you know how to flip the sprite in another direction? I got the lighting working with an animation, but if I want to face my character the other way (either by the flipX option in the sprite renderer or setting the scale to -1) it turns invisible.
Sorry if I must dig up an old question, but I have the same problem and I see that @timcommandeur never got an answer... For now the only way I see would be: creating a flipped version of the player, flipping the normal maps, adding the two versions of the player to a single empty object, creating the flipped animations, using a script to specify what sprite renderer to use when the player must be flipped...
you probably want a shader that flips your normal map depending on if ur rendering front face or back face.
Well well, you made me curious. I explored the shaders list on the material I use for the player and selected "Sprites", I tested and it appears that "Diffuse" is doing the trick. The player doesn't react to the light as realistically as it does with the Standard shader but it still reacts to the lights. And now I can flip it!