立方体切换数字
Shader "Sbin/Texture04"
{
Properties
{
_MainTex("MainTex",2D)=""{}
}
SubShader
{
pass
{
CGPROGRAM
#pragma Vertex vert
#pragma fragment frag
#include "unitycg.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;//scale,transform,相当于平铺和偏移
struct v2f
{
float4 pos:POSITION;
float2 uv:TEXCOORD0;
};
v2f vert(appdata_base v)
{
v2f o;
o.pos=mul(UNITY_MATRIX_MVP,v.Vertex);
//o.uv=v.texcoord.xy*_MainTex_ST.xy+_MainTex_ST.zw;
return o;
}
fixed4 frag(v2f IN):COLOR
{
fixed4 color= tex2D(_MainTex,IN.uv);
return color;
}
ENDCG
}
}
}
模拟波纹,从中间向四周扩散
Shader "Sbin/Texture05"
{
Properties
{
_MainTex("MainTex",2D)=""{}
_F("F",Range(1,30))=10//周期
_A("A",Range(0,0.1))=0.01//幅度
_R("R",Range(0,1))=0
}
SubShader
{
pass
{
CGPROGRAM
#pragma Vertex vert
#pragma fragment frag
#include "unitycg.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;//scale,transform,相当于平铺和偏移
float _F;
float _A;
float _R;
struct v2f
{
float4 pos:POSITION;
float2 uv:TEXCOORD0;
};
v2f vert(appdata_base v)
{
v2f o;
o.pos=mul(UNITY_MATRIX_MVP,v.Vertex);
//o.uv=v.texcoord.xy*_MainTex_ST.xy+_MainTex_ST.zw;
return o;
}
fixed4 frag(v2f IN):COLOR
{
//IN.uv+=_Time.x;//播放动画,xy同时进行偏移
//IN.uv.x+=0.01*sin(IN.uv.x*3.14*_F+_Time.y);//石头在水里的波纹效果
//IN.uv.y+=0.01*sin(IN.uv.y*3.14*_F+_Time.y);//石头在水里的波纹效果
//IN.uv+=_A*sin(IN.uv*3.14*_F+_Time.y);//石头在水里的波纹效果
float2 uv=IN.uv;
float dis=distance(uv,float2(0.5,0.5));
float scale=0;
//if(dis<_R)
//{
_A=saturate(1-dis/_R);//距离中心点的距离,R为波的波动半径,离重点点近幅度大,离中心点远幅度小
scale=_A*sin(-dis*3.14*_F+_Time.y);//距离中心点的位置
uv=uv+uv*scale;
//}
fixed4 color= tex2D(_MainTex,IN.uv);//+fixed4(1,1,1,)*saturate(scale)*100;
return color;
}
ENDCG
}
}
}
旋转模糊
Shader "Sbin/Texture06"
{
Properties
{
_MainTex("MainTex",2D)=""{}
_F("F",Range(1,30))=10//周期
_A("A",Range(0,0.1))=0.01//幅度
_R("R",Range(0,1))=0
}
SubShader
{
pass
{
CGPROGRAM
#pragma Vertex vert
#pragma fragment frag
#include "unitycg.cginc"
#pragma target 3.0
sampler2D _MainTex;
float4 _MainTex_ST;//scale,transform,相当于平铺和偏移
float _F;
float _A;
float _R;
struct v2f
{
float4 pos:POSITION;
float2 uv:TEXCOORD0;
float z:TEXCOORD1;//z轴上的深度
};
v2f vert(appdata_base v)
{
v2f o;
o.pos=mul(UNITY_MATRIX_MVP,v.Vertex);
o.uv=TRANSFORM_TEX(v.texcoord,_MainTex)
o.z=mul(_object2World,v.Vertex).z;
return o;
}
fixed4 frag(v2f IN):COLOR
{
//模糊处理
//float dx=ddx(IN.uv.x)*10;
//float2 dsdx=float2(dx,dx);
//float dy=ddy(IN.uv.y)*10;
//float2 dsdy=float2(dy,dy);
//z方向上的偏导
float2 dsdx=ddx(IN.z)*10;
float2 dsdy=ddy(IN.z)*10;
fixed4 color= tex2D(_MainTex,IN.uv,dsdx,dsdy);
return color;
}
ENDCG
}
}
}