最后的效果,左为顶点shader,右为蒙皮 10根骨骼
有些远景动画、小动画,用骨骼蒙皮来做太费了。一个好的办法是用顶点动画。比如在顽皮狗GDC的分享Technical Art Techniques of Naughty Dog:Vertex Shaders and Beyond用这种方法模拟鸟的人群的运动。
Houdini集成了Game Development Tools里可以做到导出顶点动画,直接看这篇教程就好。Houdini官方做了Game Development Toolset的工具包,直接可以用的,在Github上有。包含了Houdini中的一些节点和Unity的shader。
制作流程
安装
导入
生成

导出
贴图设置


Unity材质

原理
位置

float4 texturePos = tex2Dlod(_posTex,float4(v.texcoord1.x, (timeInFrames + v.texcoord1.y), 0, 0));
1 2 3 4 5 |
float expand = _boundingMax - _boundingMin; texturePos.xyz *= expand; texturePos.xyz += _boundingMin; texturePos.x *= -1; //flipped to account for right-handedness of unity v.vertex.xyz += texturePos.xzy; |
法线

float alpha = texturePos.w * 1024
float2 f2;
f2.x = floor(alpha / 32.0) / 31.5;
f2.y = (alpha - (floor(alpha / 32.0)*32.0)) / 31.5;
float3 f3;
f2 *= 4;
f2 -= 2;
float f2dot = dot(f2,f2);
f3.xy = sqrt(1 - (f2dot/4.0)) * f2;
f3.z = 1 - (f2dot/2.0);
f3 = clamp(f3, -1.0, 1.0);
f3 = f3.xzy;
f3.x *= -1;
v.normal = f3;
textureN = textureN.xzy;
textureN *= 2;
textureN -= 1;
textureN.x *= -1;
v.normal = textureN;
2 thoughts on “Mesh Vertex Animation In Unity | Unity中顶点动画”