- Home /
Is it possible to pair an animated normal map image sequence to a diffuse sprite sequence?
I have about a dozen separate animations for this character, baked out to several image sequences. The animation is a dirty mix of 3D and 2D, so importing a 3D model and lighting it is not an option. To light him dynamically, I have to use normal maps on 2D sequences.
The problem is, I can't figure out how to get my normal map sequence to animate along with my main sequence. I can't use a sprite sheet, there are too many hundreds of frames, and too many animations.
You can see below how the shader is setup, the sprite sequence works as expected, playing through the animation, and changing as controls are input, but the normal map is only accepting a single image of a single animation. I've managed to create a string that gives the name I need: for example "WalkAnimation_NormalMap_0057.png" under "void Update". So I have the name of the normal map I need at any given time as a string. But I can't figure out how to use that string to load in the correct normal map on that frame.
10 years After Effects 5 years Cinema 4D 6 weeks Unity
Sorry if I appear clueless, because I am. Thanks for your feedback.
Answer by ChrisVranos · Sep 06, 2016 at 06:19 AM
One step closer. I figured out how to load the images of a single sequence, just the character's idle animation. The problem is I'm calling the map by the integer of the array containing the idle normal maps inside my resources folder. I need to figure out how to load the correct animations too, as well as the correct index.
Kinda a cool effect though, right?
using UnityEngine;
using System.Collections;
using System.IO;
public class HopperShaderConnections : MonoBehaviour {
private Texture imageofsprite;
private Texture MainTex;
Material mat;
string animationName;
string frameNumber;
string NormalsName;
Texture currentNormalMap;
Texture2D[] _typedTextures;
int _displayed = 0;
public string _idle_normal_path;
int index_of_idle_normal_seq;
void Start () {
Object[] textures = Resources.LoadAll(_idle_normal_path, typeof(Texture2D));
_typedTextures = new Texture2D[textures.Length];
for (int i = 0; i < textures.Length; i++){
_typedTextures[i] = (Texture2D)textures[i];
}
Debug.Log("Textures Loaded: " + _typedTextures.Length);
}
void Update () {
imageofsprite = gameObject.GetComponent<SpriteRenderer> ().sprite.texture;
frameNumber = imageofsprite.name.Substring (imageofsprite.name.Length - 4, 4);
animationName = imageofsprite.name.Substring (0, imageofsprite.name.Length - 4);
NormalsName = animationName + "Normal_" + frameNumber;
index_of_idle_normal_seq = int.Parse (frameNumber);
Debug.Log (NormalsName);
GetComponent<Renderer>().material.SetTexture ("_BumpMap", _typedTextures[index_of_idle_normal_seq]);
}
}
Your answer
Follow this Question
Related Questions
Don't render an Area behind a plane 0 Answers
Mass assign shaders? 1 Answer
Combining BlinnPhong with WrapDiffuse 0 Answers
About Cg shaders and parameters 3 Answers