(学习笔记)流动的照片效果

Shader "Custom/FoldEffect" {
	Properties {
		_MainTex("Main Tex",2D)="white"{}
		_Scale("Scale",float)=1
		_ZScale("ZScale",int)=100
	}
	SubShader {
		Tags{"LightMode"="ForwardBase"}

		Pass{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			
			sampler2D _MainTex;
			float4 _MainTex_ST;
			float _Scale;
			int _ZScale;

			struct a2v{
				float4 vertex:POSITION;
				float4 texcoord:TEXCOORD0;
			};

			struct v2f{
				float4 pos:SV_POSITION;
				float2 uv:TEXCOORD0;
			};

			v2f vert(a2v v){
				v2f o;
				float4 p=v.vertex;
				//三角函数曲线-梯形曲线
				p.y=sin(v.vertex.x*_Scale+_Time.y)-floor(v.vertex.z/_ZScale);
				//转换到裁切坐标系
				o.pos=UnityObjectToClipPos(p);
				//UV平移动画
				o.uv.xy=v.texcoord.xy*_MainTex_ST.xy+_MainTex_ST.zw-float2(_Time.x,0);
				return o;
			}

			fixed4 frag(v2f i):SV_TARGET{
				fixed3 c=tex2D(_MainTex,i.uv.xy);
				return fixed4(c,1);
			}

			ENDCG
		}
	}
	FallBack "Diffuse"
}

动画比较简陋,初学者水平.

(学习笔记)流动的照片效果_第1张图片

你可能感兴趣的:(Shader笔记)