使用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;
}

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM