逐行/列扫描
Shader "LSQ/ImageProcessing/PerLineScan"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
[Enum(Up,1,Down,2,Left,3,Right,4)] _ScanDirection ("Scan Direction", Int) = 1
_Value ("Value", Range(0, 1)) = 0
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
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;
}
sampler2D _MainTex;
float4 _MainTex_TexelSize;
int _ScanDirection;
float _Value;
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
int lineIndex = 1;
int valueIndex = 0;
if(_ScanDirection == 1) //向上
{
lineIndex = i.uv.y * _MainTex_TexelSize.w;
valueIndex = _Value * _MainTex_TexelSize.w;
}
else if(_ScanDirection == 2) //向下
{
lineIndex = (1 - i.uv.y) * _MainTex_TexelSize.w;
valueIndex = _Value * _MainTex_TexelSize.w;
}
else if(_ScanDirection == 3) //向左
{
lineIndex = i.uv.x * _MainTex_TexelSize.z;
valueIndex = _Value * _MainTex_TexelSize.z;
}
else //向右
{
lineIndex = (1 - i.uv.x) * _MainTex_TexelSize.z;
valueIndex = _Value * _MainTex_TexelSize.z;
}
clip(lineIndex - valueIndex);
return col;
}
ENDCG
}
}
}
移动
Shader "LSQ/ImageProcessing/MoveIn"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
[Enum(Up,1,Down,2,Left,3,Right,4)] _ScanDirection ("Scan Direction", Int) = 1
_Value ("Value", Range(0, 1)) = 0
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
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;
}
sampler2D _MainTex;
float4 _MainTex_TexelSize;
int _ScanDirection;
float _Value;
fixed4 frag (v2f i) : SV_Target
{
if(_ScanDirection == 1) //向上
{
i.uv.y = i.uv.y + 1 - _Value;
}
else if(_ScanDirection == 2) //向下
{
i.uv.y = i.uv.y - 1 + _Value;
}
else if(_ScanDirection == 3) //向左
{
i.uv.x = i.uv.x - 1 + _Value;
}
else //向右
{
i.uv.x = i.uv.x + 1 - _Value;
}
fixed4 col = tex2D(_MainTex, i.uv);
if(i.uv.x > 1 || i.uv.y > 1 || i.uv.x < 0 || i.uv.y < 0)
return 1;
return col;
}
ENDCG
}
}
}
交叉飞入
Shader "LSQ/ImageProcessing/CrossFlight"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
[Enum(Horizontal,1,Vertical,2)] _Direction ("Direction", Int) = 1
_Value ("Value", Range(0, 1)) = 0
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
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;
}
sampler2D _MainTex;
float4 _MainTex_TexelSize;
int _Direction;
float _Value;
fixed4 frag (v2f i) : SV_Target
{
if(_Direction == 1) //水平
{
if(i.uv.y > 0.5) //上行
{
i.uv.x = i.uv.x + 1 - _Value;
}
else //下行
{
i.uv.x = i.uv.x - 1 + _Value;
}
}
else if(_Direction == 2) //竖直
{
if(i.uv.x > 0.5) //右列
{
i.uv.y = i.uv.y + 1 - _Value;
}
else //左列
{
i.uv.y = i.uv.y - 1 + _Value;
}
}
fixed4 col = tex2D(_MainTex, i.uv);
if(i.uv.x > 1 || i.uv.y > 1 || i.uv.x < 0 || i.uv.y < 0)
return 1;
return col;
}
ENDCG
}
}
}
中间扩张/收缩
Shader "LSQ/ImageProcessing/CenterExtend"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
[Enum(Horizontal,1,Vertical,2)] _Direction ("Direction", Int) = 1
[Enum(Extend,1,Shrink,2)] _Type ("Direction", Int) = 1
_Value ("Value", Range(0, 1)) = 0
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
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;
}
sampler2D _MainTex;
int _Direction;
int _Type;
float _Value;
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
float value = 1;
if(_Direction == 1) //水平
{
if(_Type == 1) //扩张
{
value = abs(i.uv.x - 0.5) * 2;
}
else //收缩
{
value = 1 - abs(i.uv.x - 0.5) * 2;
}
}
else if(_Direction == 2) //竖直
{
if(_Type == 2) //扩张
{
value = 1 - abs(i.uv.y - 0.5) * 2;
}
else //收缩
{
value = abs(i.uv.y - 0.5) * 2;
}
}
clip(_Value - value);
return col;
}
ENDCG
}
}
}
栅条特效
Shader "LSQ/ImageProcessing/GridBar"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
[Enum(Horizontal,1,Vertical,2)] _Direction ("Direction", Int) = 1
_Count ("Count", int) = 10
_Value ("Value", Range(0, 1)) = 0
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
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;
}
sampler2D _MainTex;
int _Direction;
int _Count;
float _Value;
fixed4 frag (v2f i) : SV_Target
{
if(_Direction == 1) //水平
{
float lineIndex = i.uv.y * _Count;
lineIndex = floor(lineIndex);
if(lineIndex % 2 == 0)
{
i.uv.x = i.uv.x - 1 + _Value;
}
else
{
i.uv.x = i.uv.x + 1 - _Value;
}
}
else if(_Direction == 2) //竖直
{
float lineIndex = i.uv.x * _Count;
lineIndex = floor(lineIndex);
if(lineIndex % 2 == 0)
{
i.uv.y = i.uv.y + 1 - _Value;
}
else
{
i.uv.y = i.uv.y - 1 + _Value;
}
}
fixed4 col = tex2D(_MainTex, i.uv);
if(i.uv.x > 1 || i.uv.y > 1 || i.uv.x < 0 || i.uv.y < 0)
return 1;
return col;
}
ENDCG
}
}
}
图像渐显
Shader "LSQ/ImageProcessing/FadeIn"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Value ("Value", Range(0, 1)) = 0
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
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;
}
sampler2D _MainTex;
float _Value;
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
//灰度值
float value = (0.299 * col.r + 0.587 * col.g + 0.114 * col.b);
clip(_Value - value);
return col;
}
ENDCG
}
}
}
百叶窗
Shader "LSQ/ImageProcessing/Shutter"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
[Enum(Horizontal,1,Vertical,2)] _Direction ("Direction", Int) = 1
_Count ("Count", int) = 10
_Value ("Value", Range(0, 1)) = 0
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
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;
}
sampler2D _MainTex;
int _Direction;
int _Count;
float _Value;
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
float value = 1;
if(_Direction == 1) //水平
{
value = i.uv.x * _Count;
value = value - floor(value);
}
else if(_Direction == 2) //竖直
{
value = i.uv.y * _Count;
value = value - floor(value);
}
clip(_Value - value);
return col;
}
ENDCG
}
}
}
马赛克
Shader "LSQ/ImageProcessing/Mosaic"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Value ("Value", Range(0, 1)) = 0
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
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;
}
sampler2D _MainTex;
float4 _MainTex_TexelSize;
float _Value;
fixed4 frag (v2f i) : SV_Target
{
fixed2 uv = round(i.uv * _MainTex_TexelSize.zw * _Value) / (_MainTex_TexelSize.zw * _Value);
fixed4 col = tex2D(_MainTex, uv);
return col;
}
ENDCG
}
}
}



