赞
踩
- Shader "Custom/Flow"
- {
- Properties
- {
- _MainTex ("Texture", 2D) = "white" {}
- _WaveSpeed("贴图移速",float)=3
-
- }
- SubShader
- {
- Blend One ONE
- CULL OFF
- Tags{"Queue"="Transparent"}
-
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
-
- #include "UnityCG.cginc"
-
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- };
-
-
- struct v2f
- {
- float2 uv : TEXCOORD0;
- float4 vertex : SV_POSITION;
- };
- //下面是顶点着色器,有四个可控量,控制振幅、波长、频率、偏移
- float _Frequency;
- float _Attruibte;
- float _K2;
- float _B2;
- v2f vert (appdata v)
- {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.uv = v.uv;
- return o;
- }
- //下面是片段着色器 控制像素的移动
- sampler2D _MainTex;
- float _WaveSpeed;
- fixed4 frag (v2f i) : SV_Target
- {
- float2 tmpUV=i.uv;
- tmpUV.y+= _WaveSpeed*_Time.y;
- //tmpUV.x+=_WaveSpeed*_Time.x;
- fixed4 col = tex2D(_MainTex,tmpUV);
- return col;
- }
- ENDCG
- }
- }
- }
- Shader "Custom/Glow"
- {
- Properties
- {
- _MainTex ("Texture", 2D) = "white" {}
- _Speed("旋转速度",Float)=1
-
-
- }
- SubShader
- {
- cull off
- Blend SrcAlpha One
- Tags{"Queue"="Geometry+2"}
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
-
- #include "UnityCG.cginc"
-
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- };
-
- struct v2f
- {
- float2 uv : TEXCOORD0;
- float4 vertex : SV_POSITION;
- };
-
- v2f vert (appdata v)
- {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.uv = v.uv;
- return o;
- }
- //像素的矩阵旋转
- //思路:
- //1.先将旋转中心设为(0.5,0.5) 默认中心为(0,0)
- //2.套用旋转公式
- //3.旋转完毕,中心回到(0,0)
- sampler2D _MainTex;
- float _Speed;
- fixed4 frag (v2f i) : SV_Target
- {
- float2 tmpUV =i.uv;
- tmpUV -=float2(0.5,0.5); //变换旋转中心
- float2 angle =_Time*_Speed; //角度随时间变化而变化
- float2 result =float2(0,0); //创建一个容器
- result.x =tmpUV.x * cos(angle) -sin(angle)*tmpUV.y; //套公式
- result.y =tmpUV.x * sin(angle) +cos(angle)*tmpUV.y; //套公式
- tmpUV+=float2(0.5,0.5); //旋转中心回归
- fixed4 col = tex2D(_MainTex, result);
- // just invert the colors
- //col = 1 - col;
-
-
- return col;
- }
- ENDCG
- }
- }
- }
- // 关于矩阵旋转的公式: X: 1 0 0 0 (A为随时间变化而变化的角度,下同)
- // 0 cosA -sinA 0
- // 0 sinA cosA 0
- // 0 0 0 1
-
- // Y: cosA 0 sinA 0
- // 0 1 0 0
- // -sinA 0 cosA 0
- // 0 0 0 1
-
- // Z: cosA -sinA 0 0
- // sinA cosA 0 0
- // 0 0 1 0
- // 0 0 0 1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。