Vertex Animation (Dolphin)

For my current project (Lowboat) I created some shaders with vertex animations. Since there is not much information on this subject, I thought posting the following shader might be helpful. Of course, any tipps on how to improve it are welcome. :smile:

1471409--80912--$dolphin2.gif

Shader "Vertex Animations/Dolphin" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_Shade ("Shade Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal }
   		_AnimationSpeed ("Animation Speed", Range(1, 50)) = 50
   		_AnimationAmount ("Animation Amount", Range(0.01, 0.5)) = 0.5
   		_AnimationLength ("Animation Length", Range(0.001, 10)) = 0.1
	}


	SubShader {
		Tags {"IgnoreProjector"="True"  }
		Pass {
			Name "BASE"
			
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma fragmentoption ARB_precision_hint_fastest 
			#pragma glsl_no_auto_normalization
			#include "UnityCG.cginc"

			sampler2D _MainTex;
			samplerCUBE _Shade;
			fixed4 _MainTex_ST;
			float _AnimationSpeed;
			float _AnimationAmount;
			float _AnimationLength;

			struct appdata {
				fixed4 vertex : POSITION;
				float2 texcoord : TEXCOORD0;
				float3 normal : NORMAL;
			};
			
			struct v2f {
				fixed4 pos : POSITION;
				float2 texcoord : TEXCOORD0;
				float3 cubenormal : TEXCOORD1;
			};

			v2f vert (appdata v)
			{
				v2f o;			
				float s = sin(_Time.y * _AnimationSpeed + (v.vertex.z + v.vertex.x * 0.6f)* _AnimationLength) * _AnimationAmount * v.vertex.z;
				v.vertex.y += s;
				o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
				o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
				o.cubenormal = mul (UNITY_MATRIX_MV, float4(v.normal,0));
				return o;
			}

			fixed4 frag (v2f i) : COLOR
			{
				fixed4 col = tex2D(_MainTex, i.texcoord);
				fixed4 cube = texCUBE(_Shade, i.cubenormal);
				return fixed4( cube.rgb * col.rgb, col.a);
			}
			ENDCG			
		}
	} 
	
	Fallback "VertexLit"
}

This is incredible, really I love it.
Someone knows how to make the animation axis selectable ?
I’m not used with shader and I don’t think I can do it myself.

Now I uess, is it possible to make this kind of shader for birds
I mean if the bird is directed on 1 axis,we can move it wings vertex this way ?

Just play around with x, y and z. Since a bird flaps its wings simetrically you might also have to use abs(). Something like this:

float s = sin(_Time.y * _AnimationSpeed + abs(v.vertex.z)* _AnimationLength) * _AnimationAmount * v.vertex.z;
v.vertex.y += s;

(not tested)

However, a bird’s wing flaps are a bit more complicated and not as fluid as a fish’s movement. With this animation the bird will look quite boneless.

Thanks a lot, I’lll try it. I have to learn how shaders are working because it seems we can do more like I thougth with them.