使用shader,矩阵旋转实现图片的旋转动画

常用于loading动画之类的

 

 

 

 

 

 

 

 

具体的实现代码:

fixed4 frag (v2f i) : SV_Target
{
    //1.先将uv平移到原点(让图片中心与原点重合)
    float2 pianyi=(0.5,0.5);
    float2 tempUV=i.uv;
    tempUV -= pianyi;
    
    //距离圆心超过0.5的点渲染为透明
    if(length(tempUV)>0.5){
        return fixed4(0,0,0,0);
    }
    float2 finalUV=0;
    float angle=_Time.x*_Speed;
    //2.确定是按照z轴旋转,选取旋转公式
    finalUV.x=tempUV.x * cos(angle) - tempUV.y*sin(angle);
    finalUV.y=tempUV.x * sin(angle) + tempUV.y*cos(angle);
    //3.将uv还原到以前的位置
    finalUV += pianyi;
    fixed4 col = tex2D(_MainTex, finalUV);
    return col;
}

  

 

posted @ 2019-12-27 16:12  zhoushiya  阅读(1338)  评论(1编辑  收藏  举报