Shader "Custom/TrigonometricRotation"
{
Properties
{
_RotateSpeed("旋转幅度",Range(1,4)) = 1
_MainTex("贴图",2D) = "White"{}
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue" = "Geometry" "IgnoreProjector" = "True" "DisableBatching" = "True" }
pass
{
CGPROGRAM
//相当于 引入编辑顶点方法的 程序集
#pragma vertex vert
//相当于 引入编辑片元的程序集
#pragma fragment frag
//引入Unity自建的函数库
#include "UnityCG.cginc"
struct appdata
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
float _RotateSpeed;
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert(in appdata data)
{
float angle = length(data.pos) * _SinTime.w / _RotateSpeed;
v2f v;
//所谓得观察空间就是 剪裁空间
//视图矩阵 * 投影矩阵 * 模型矩阵 +=》 模型到 视图投影得转换 // 相机视图
float4x4 m =
{
float4(cos(angle),0,sin(angle),0),
float4(0,1,0,0),
float4(-sin(angle),0,cos(angle),0),
float4(0,0,0,1)
};
float4 p = mul(m,data.pos);
v.pos = UnityObjectToClipPos(p);
v.uv = TRANSFORM_TEX(data.uv,_MainTex);
return v;
}
fixed4 frag(v2f IN) : SV_TARGET
{
return tex2D(_MainTex,IN.uv);
}
ENDCG
}
}
}
?
|