Jacob's Blog Buttons (custom HTML)

portfolio
animation
character
digital art
Showing posts with label Animated Texture Offset. Show all posts
Showing posts with label Animated Texture Offset. Show all posts

Saturday, March 29, 2014

Sneak Peek at Animated Facial Textures Script Update


Centering on texture and pupil secondary-offset control.
Tile offset, U and V tweaking, working all in one!

I am currently working on a Version 2.0 of my Animated Texture Offset script.  The biggest things I am adding are the option to choose the attribute to read in (position, rotate, scale, X, Y, Z) and support for pupils as mentioned in this post.

Choosing the attribute-in was something I had thought about when I was writing the first version, but it adds a significant amount of complexity to the process, though mostly on the Maya end.  That's actually why I'm writing the Unity C# script first.  I might have to do some weird fanagling with some local variables Maya's Expression Editor.  It could be on the simple side, of setting some variables and copying a script in, or it could be much more than that.

The second bit, the pupil animation, is actually easy to do in Maya.  I was originally going to write a second script to focus on a single pupil texture and offsets with that, but I realized I could merge it with the tiling texture script, allowing for multiple pupil types, as well as keeping it all in one package.  It makes the math significantly more complex, and the script a little harder to read, but it functions just fine.  The one reason it will be more difficult in Unity is because Unity's default shaders take RGB and A all in one channel, so I can't separate out the Place2DTexture of the diffuse and opacity.  I think the solution to that is to include with the script a custom shader that separates out those two maps.  At least that will be easy to write.

On top of those two things, I also refactored the code to just make it a little cleaner and a bit more robust.  The Inspector public variables are much nicer (for example, it takes a GameObject now, rather than a string name), and I have some good error checking in there.



Monday, October 7, 2013

Animated Facial Features with Pupil

I recently received an email asking about moving a pupil around with the animated texture.  (Thanks for the email, Tom.)

The solution I came up with was using the same offset trick for the eye frames, and then using offset to control the pupil under the eye.  A LERP blended the two together.  It actually ended up being a simpler layout than I had anticipated:


The first Place2DTexture would control the offsets as shown in the the first tutorial to change eye shape, blinking, etc.  The second Place2DTexture would control the eyeball offset, which would cause the pupil to move around 'under' the mask.

The problem, though, was that I could do this in UDK or Maya, but not in Unity.  I'm not familiar enough with materials in Unity to work without a visual editor.  Strumpy Shader is a great node based editor for Unity, but it was designed to work in Unity 3.x, and isn't supported anymore.

Tom came up with a clever solution; he used an additional plane for the pupil.  The back plane had the eye outline (with lashes and the like) and the sclera colored in.  The front plane had the pupil and sclera color, with a mask applied over it that matched the shape of the sclera of eye in the back plane.  As a result, it was a very functional solution that worked very similarly to using a lerp, but it didn't require any special shader system.

If you wanted to keep the animation on the joints, controlling the pupil with either system would just require a script to handle rotation on the joints.  Say, when it rotates on Y to +/-180 , it offsets the left-right a set amount, and when it rotates on Z, offsets the up-down; the X will always point in the direction it's looking.  An aim constraint in either Maya or Unity (say, if you wanted dynamic eye direction) could drive the rotation on the existing joints, and the script would go from that information.

Friday, July 26, 2013

Animated Facial Textures in Maya and Unity

Download the pdf document here:
Direct link

Check it out online here:
Animated Facial Textures in Maya and Unity - Full Document

You can check my further notes on the subject here:
More on Animated Facial Textures

Essentially, my goal was to create a texture-driven facial animation system that worked in both Maya and Unity.  Making one in Maya is very simple, but I found very little on getting it to work in Unity, and nothing about getting it to export from Maya.

To give a bit of a background, for FIEA, one of our assignments was to document or write a tutorial about something we learned or wanted to learn.  I took this opportunity to pick up Unity, and solve a possible problem for a game I will be working on soon, and a problem I'd been curious about since when I was working on Intrepid.


I came up with a solution using joint animation that can be baked out of Maya and used in Unity.  The Maya portion gave me some practice with Maya Expressions, which is great considering I want to rig up the rest of the character soon.  And the Unity portion gave me a chance to learn Unity, and also learn some C#.  C# wasn't too difficult to pick up, having studied C and Java in the past; the code to get it all working can pretty much be copy-pasted from the document.

Download the pdf from the link above.  It should be very accessible - it breaks it down really small to start; getting it in engine, and how the math of the expressions and the image offset method will work.  And in sections 4 and 5, it gets to the meat of the whole operation.

If anyone has any questions on how it works, or why I did something; or any comments on how I can improve this method, I'd love to hear it.  Send me an email, or drop me a message here.

Animated Facial Textures in Maya and Unity - Full Document

Click 'Read More' below to see the full document.