torch_in_sky

Rat animation shader

Jun 14th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.42 KB | None | 0 0
  1. Shader "Unlit/Rat"
  2. {
  3.     Properties
  4.     {
  5.         _JumpSpeed("Jump Speed", float) = 10
  6.         _JumpAmplitude("Jump Amplitude", float) = 0.18
  7.         _JumpFrequency("Jump Frequency", float) = 2
  8.         _JumpVerticalOffset("Jump Vertical Offset", float) = 0.33
  9.         _TailExtraSwing("Tail Extra Swing", float) = 0.15
  10.         _LegsAmplitude("Legs Amplitude", float) = 0.10
  11.         _LegsFrequency("Legs Frequency", float) = 10
  12.         _LegsPhaseOffset("Legs Phase Offset", float) = -1
  13.         [NoScaleOffset]
  14.         _MainTex ("Texture", 2D) = "white" {}
  15.     }
  16.     SubShader
  17.     {
  18.         Tags { "RenderType"="Opaque" }
  19.         LOD 100
  20.  
  21.         Pass
  22.         {
  23.             CGPROGRAM
  24.             #pragma vertex vert
  25.             #pragma fragment frag
  26.  
  27.             #include "UnityCG.cginc"
  28.  
  29.             struct appdata
  30.             {
  31.                 float4 vertex : POSITION;
  32.                 float2 uv : TEXCOORD0;
  33.             };
  34.  
  35.             struct v2f
  36.             {
  37.                 float2 uv : TEXCOORD0;
  38.                 float4 vertex : SV_POSITION;
  39.             };
  40.  
  41.             sampler2D _MainTex;
  42.             float4 _MainTex_ST;
  43.             half _JumpSpeed;
  44.             half _JumpAmplitude;
  45.             half _JumpFrequency;
  46.             half _JumpVerticalOffset;
  47.             half _TailExtraSwing;
  48.             half _LegsAmplitude;
  49.             half _LegsFrequency;
  50.             half _LegsPhaseOffset;
  51.  
  52.             v2f vert (appdata v)
  53.             {
  54.                 float bodyPos = max((abs(sin(_Time.y * _JumpSpeed + v.uv.x * _JumpFrequency)) - _JumpVerticalOffset), 0);
  55.                 float tailMask = smoothstep(0.6, 0.0, v.uv.x) * _TailExtraSwing + _JumpAmplitude;
  56.                 bodyPos *= tailMask;
  57.                 v.vertex.y += bodyPos;
  58.                
  59.                 float legsPos = sin(_Time.y * _JumpSpeed * 2 + _LegsPhaseOffset + v.uv.x * _LegsFrequency) * _LegsAmplitude;
  60.                 float legsMask = smoothstep(0.4, 0.1, v.uv.y);
  61.                 legsPos *= legsMask;
  62.                 v.vertex.z += legsPos;
  63.                
  64.                 v2f o;
  65.                 o.vertex = UnityObjectToClipPos(v.vertex);
  66.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  67.                 return o;
  68.             }
  69.  
  70.             fixed4 frag (v2f i) : SV_Target
  71.             {
  72.                 fixed4 col = tex2D(_MainTex, i.uv);
  73.                 return col;
  74.             }
  75.             ENDCG
  76.         }
  77.     }
  78. }
Add Comment
Please, Sign In to add comment