- Home /
Programmatically generated skinned mesh not lit while animating
I have created a 2D skinned mesh programmatically (xy plane), setting all the normals of each vertex to point toward the camera (0, 0, -1.0f). There are three point light sources in front of my skinned meshes in the scene. At rest, this skinned mesh behaves properly with light sources.
Mesh at rest, before calling play on the walking animation:
When I try to animate, however, the normals seem to be messed up, though I'm not changing them at all once the mesh is created. Here is the walking animation:
You can see that only the helmet, hand, shield and sword vertices are being lit. The other body vertices somehow do not seem to have their normals working.
The standing animation is even worse in that it doesn't show any light at all:
I'm not changing the normals, all that is happening is that the skinned mesh is animating. If i don't play any animations, the light works fine, but obviously this isn't a good solution.
I've tried different shaders, including:
Diffuse
VertexLit
Transparent/Diffuse
Transparent/VertexLit
Particles/VertexLit Blended
Mobile/Particles/VertexLit Blended
The example images are using Mobile/Particles/VertexLit Blended
Running on Unity 3.5.0f5
Anyone encountered this before?
Haven't found an answer, but did find another clue. The vertices that show light are attached to bones that have no x or y scale animation curves for a given animation. For instance, in the above example, the helmet, hand, sword, and shield of the walking animation light up because they have no scale animation curves on those bones for that animation. All of the vertices in the standing animation are attached to bones with scale animation curves so none of them light up.
Why would a scale animation curve affect the normals, especially since the scale is on the x and y axis and the normals are along the z axis?
Answer by echo17 · Mar 21, 2012 at 02:06 AM
Solved!
I was only adding the x and y scale animation curves to my bones, so it was defaulting the z scale curve to zeros, thus making the normals zero as well. Adding in a bogus z scale animation curve filled with ones fixed it.