├── FishAnimation.shader ├── LICENSE └── README.md /FishAnimation.shader: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Alberto Mellado Cruz 3 | Date: 09/11/2017 4 | 5 | Comments: 6 | This is just a test that would depend on the 3D Model used. 7 | Vertex animations would allow the use of GPU Instancing, 8 | enabling the use of a dense amount of animated fish. 9 | The code may not be optimized but it was just a test 10 | */ 11 | 12 | Shader "Custom/FishAnimation" { 13 | Properties{ 14 | _MainTex("Albedo (RGB)", 2D) = "white" {} 15 | _SpeedX("SpeedX", Range(0, 10)) = 1 16 | _FrequencyX("FrequencyX", Range(0, 10)) = 1 17 | _AmplitudeX("AmplitudeX", Range(0, 0.2)) = 1 18 | _SpeedY("SpeedY", Range(0, 10)) = 1 19 | _FrequencyY("FrequencyY", Range(0, 10)) = 1 20 | _AmplitudeY("AmplitudeY", Range(0, 0.2)) = 1 21 | _SpeedZ("SpeedZ", Range(0, 10)) = 1 22 | _FrequencyZ("FrequencyZ", Range(0, 10)) = 1 23 | _AmplitudeZ("AmplitudeZ", Range(0, 2)) = 1 24 | _HeadLimit("HeadLimit", Range(-2, 2)) = 0.05 25 | } 26 | SubShader{ 27 | Tags{ "RenderType" = "Opaque" } 28 | Cull off 29 | 30 | Pass{ 31 | 32 | CGPROGRAM 33 | #pragma vertex vert 34 | #pragma fragment frag 35 | #include "UnityCG.cginc" 36 | 37 | sampler2D _MainTex; 38 | float4 _MainTex_ST; 39 | 40 | struct v2f { 41 | float4 pos : SV_POSITION; 42 | float2 uv : TEXCOORD0; 43 | }; 44 | 45 | // X AXIS 46 | 47 | float _SpeedX; 48 | float _FrequencyX; 49 | float _AmplitudeX; 50 | 51 | // Y AXIS 52 | 53 | float _SpeedY; 54 | float _FrequencyY; 55 | float _AmplitudeY; 56 | 57 | // Z AXIS 58 | 59 | float _SpeedZ; 60 | float _FrequencyZ; 61 | float _AmplitudeZ; 62 | 63 | // Head Limit (Head wont shake so much) 64 | 65 | float _HeadLimit; 66 | 67 | v2f vert(appdata_base v) 68 | { 69 | v2f o; 70 | 71 | //Z AXIS 72 | 73 | v.vertex.z += sin((v.vertex.z + _Time.y * _SpeedX) * _FrequencyX)* _AmplitudeX; 74 | 75 | //Y AXIS 76 | 77 | v.vertex.y += sin((v.vertex.z + _Time.y * _SpeedY) * _FrequencyY)* _AmplitudeY; 78 | 79 | //X AXIS 80 | 81 | if (v.vertex.z > _HeadLimit) 82 | { 83 | v.vertex.x += sin((0.05 + _Time.y * _SpeedZ) * _FrequencyZ)* _AmplitudeZ * _HeadLimit; 84 | } 85 | else 86 | { 87 | v.vertex.x += sin((v.vertex.z + _Time.y * _SpeedZ) * _FrequencyZ)* _AmplitudeZ * v.vertex.z; 88 | } 89 | 90 | 91 | o.pos = UnityObjectToClipPos(v.vertex); 92 | o.uv = TRANSFORM_TEX(v.texcoord, _MainTex); 93 | return o; 94 | 95 | } 96 | 97 | fixed4 frag(v2f i) : SV_Target 98 | { 99 | return tex2D(_MainTex, i.uv); 100 | } 101 | 102 | ENDCG 103 | 104 | } 105 | } 106 | FallBack "Diffuse" 107 | } 108 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Alberto Mellado Cruz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fish-Animation 2 | Test Vertex Animation Shader for Unity3D 3 | 4 | Author: Alberto Mellado Cruz 5 | Date: 09/11/2017 6 | 7 | This is just a test that would depend on the 3D Model used. 8 | Vertex animations would allow the use of GPU Instancing, enabling the use of a dense amount of animated fish. 9 | The code may not be optimized but it was just a test 10 | --------------------------------------------------------------------------------