- Home /
Is it possible to use the unity standard shader with a sprite renderer to add normal maps to sprites, without needing a new material for each sprite sheet?
I've seen examples of people making their own custom shaders that allow you to put normal maps and bump maps on sprite sheets. However, these seem to require a different material for every sprite sheet.
I tried making a game object with a sprite renderer, setting it's material to a new material with the standard shader, and using as script like this to try to set the normal map:
using UnityEngine;
using System.Collections;
public class SpriteNormal : MonoBehaviour {
public Sprite NormalMap;
SpriteRenderer sr;
// Use this for initialization
void Awake () {
sr = GetComponent<SpriteRenderer>();
MaterialPropertyBlock mpb = new MaterialPropertyBlock();
sr.GetPropertyBlock(mpb);
mpb.SetTexture("_BumpMap", NormalMap.texture);
//Not sure how to set the offset on the normal map
sr.SetPropertyBlock(mpb);
}
}
However, that doesn't seem to have any effect at all. Another interesting thing: with or without this script, the sprite will have flat diffuse shading, but it will be at it's maximum brighness when light is pointing off to one side, rather than when the light is pointing straight at the sprite.
Answer by Andreas Loew · Nov 12, 2015 at 05:51 PM
You need 1 material for each sprite sheet - but you can, of course, pack as many sprites into the sheet as your want. It also works with animations.
The sprite sheet for the normal map has to have the same layout as the sprite sheet for the diffuse map.
If you are using the TexturePacker Importer plugin from the asset store, you'll get the material created for you automatically.
You can also check out my tutorial about 2d light effects in Unity.