先上最终效果图
1.Shader内置的时间相关函数
_Time: float4类型 (t/20, t, t*2, t*3),_SinTime :float4类型 (sin(t/8),sin(t/4),sin(t/2),sin(t))_CosTime :float4类型(cos(t/8),cos(t/4),cos(t/2),cos(t))
2.具体实现
Shader "Unlit/ScaleVertices"{Properties{_MainTex ("Texture", 2D) = "white" {}}SubShader{Tags {"RenderType"="Opaque" }LOD 100Pass{CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"struct appdata{float4 vertex : POSITION;float4 uv : TEXCOORD0;};struct v2f{float4 uv : TEXCOORD0;float4 vertex : SV_POSITION;};sampler2D _MainTex;float4 _MainTex_ST;float _duringTime;v2f vert (appdata v){v2f o;v.vertex.xz *= clamp((_SinTime.w + 2)*0.5, 1.0, 2.0);o.vertex = UnityObjectToClipPos(v.vertex);o.uv.xy = TRANSFORM_TEX(v.uv, _MainTex);return o;}fixed4 frag (v2f i) : SV_Target{// sample the texturefixed4 col = tex2D(_MainTex, i.uv);return col;}ENDCG}}}
3.遗留问题…
如果觉得《简易Shader实践记录2-图片式心跳》对你有帮助,请点赞、收藏,并留下你的观点哦!