两个图片实现翻书效果
Shader "Unlit/NewUnlitShader"
{
Properties
{
_MainTex ("主纹理", 2D) = "white" {}
_Angle("旋转角度",Range(0,180))= 0
_NextTex("副纹理",2D)= "white" {}
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#include "UnityCG.cginc"
struct a2v
{
float4 pos: POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 svpos:SV_POSITION;
float2 svuv : TEXCOORD0;
};
sampler2D _NextTex;
v2f vert (a2v i)
{
v2f o;
o.svpos=UnityObjectToClipPos(i.pos);
o.svuv=i.uv;
return o;
}
fixed4 frag (v2f u) : SV_Target
{
// sample the texture
fixed4 tex = tex2D(_NextTex, u.svuv);
return tex;
}
ENDCG
}
Pass
{
Cull off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#include "UnityCG.cginc"
struct a2v
{
float4 pos: POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 svpos:SV_POSITION;
float2 svuv : TEXCOORD0;
};
sampler2D _MainTex;
float _Angle;
v2f vert (a2v i)
{
float sins;
float coss;
//球cos和sin的值
sincos(radians(_Angle),sins,coss);
//绕Z轴旋转的矩阵
float4x4 rotateMatrix ={
coss,sins,0,0,
-sins,coss,0,0,
0,0,1,0,
0,0,0,1,
};
v2f o;
i.pos.x-=float4(5,0,0,0);
i.pos.y=sin(i.pos.x*0.5)*sins; //对y坐标做偏移使其变的波动
i.pos=mul(rotateMatrix,i.pos);
i.pos.x+=float4(5,0,0,0);
o.svpos=UnityObjectToClipPos(i.pos);
o.svuv=i.uv;
return o;
}
fixed4 frag (v2f u) : SV_Target
{
// sample the texture
fixed4 tex = tex2D(_MainTex, u.svuv);
return tex;
}
ENDCG
}
}
}