有时候游戏里面会用到信号干扰的电视效果,或者是信号顾兆效果
Shader "signal" {
Properties {
// _Color ("Color", Color) = (0.07843138,0.3921569,0.7843137,1)
_MainTex ("Main Tex", 2D) = "white" {}
_ColorOffset("ColorOffset",range(-0.5,0.5))=0.25
_MainSpeedY("MainSpeedY",float)=0
[Space][Space][Space][Space][Space][Space][Space][Space]
_DistortTex("Distort Tex",2D)="gray"{}
_DistortScale("Distort Strenth",range(-2,2))=0.1
_DistortSpeedX("Distort SpeedX",float)=0
_DistortSpeedY("Distort SpeedY",float)=0
[Space][Space][Space][Space][Space][Space][Space][Space]
_NoiseTex("Noise Tex",2D)="gray"{}
_NoiseStrenth("Noise Strenth",float)=0
_NoiseSpeedX("Noise SpeedX",float)=0
_NoiseSpeedY("Noise SpeedY",float)=0
[Space][Space][Space][Space][Space][Space][Space][Space]
// _ColorScale ("ColorScale", Float ) = 1
[HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
[Enum(off,0,On,1)] _ZWrite("ZWrite",Float)=0
}
SubShader {
Tags {
"IgnoreProjector"="True"
"Queue"="Transparent"
"RenderType"="Transparent"
}
Pass {
Name "FORWARD"
Tags {
"LightMode"="ForwardBase"
}
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
ZWrite [_ZWrite]
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase
// #pragma only_renderers d3d9 d3d11 glcore gles
#pragma target 3.0
// uniform float4 _Color;
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
float _ColorOffset;
float _MainSpeedY;
sampler2D _DistortTex;
float4 _DistortTex_ST;
float _DistortScale;
float _DistortSpeedX;
float _DistortSpeedY;
sampler2D _NoiseTex;
float4 _NoiseTex_ST;
float _NoiseStrenth;
float _NoiseSpeedX;
float _NoiseSpeedY;
//uniform float _ColorScale;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
float4 vertexColor : COLOR;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float2 mainUV:TEXCOORD1;
float2 distortUV:TEXCOORD2;
float2 noiseUV:TEXCOORD3;
float4 vertexColor : COLOR;
};
VertexOutput vert (VertexInput v) {
VertexOutput o;
o.uv0 = v.texcoord0;
//主贴图uv计算
o.mainUV=TRANSFORM_TEX(v.texcoord0,_MainTex)+float2(0,_MainSpeedY*_Time.x);
//扰动贴图uv计算,以及流动速度
//o.distortUV=TRANSFORM_TEX(v.texcoord0,_DistortTex)+float2(_DistortSpeedX*_Time.x,_DistortSpeedY*_Time.x);
float2 distortUV_var;
distortUV_var.x=_Time.y;
distortUV_var.y=v.texcoord0.y+_DistortSpeedY*_Time.y;
distortUV_var=TRANSFORM_TEX(distortUV_var,_DistortTex);
o.distortUV=distortUV_var;
//燥波贴图uv计算
float2 noiseuv_var=TRANSFORM_TEX(v.texcoord0,_NoiseTex)+float2(_NoiseSpeedX*_Time.y,_NoiseSpeedY*_Time.y);
noiseuv_var.x=noiseuv_var*frac(2000*sin(_Time.y)+0);
o.noiseUV=noiseuv_var.xy;
o.vertexColor = v.vertexColor;
o.pos = UnityObjectToClipPos( v.vertex );
return o;
}
float4 frag(VertexOutput i) : COLOR {
//定义输出颜色
fixed4 color;
//采样扭曲贴图
fixed4 _DistortTex_var=tex2D(_DistortTex,i.distortUV);
//R通道颜色偏移
color.r = tex2D(_MainTex,float2(i.mainUV.x+_ColorOffset+_DistortTex_var.r*_DistortScale,i.mainUV.y)).r;
//G通道颜色保持不变
color.g=tex2D(_MainTex,float2(i.mainUV.x+_DistortTex_var.r*_DistortScale,i.mainUV.y)).g;
//B 通道偏移
color.b=tex2D(_MainTex,float2(i.mainUV.x-_ColorOffset+_DistortTex_var.r*_DistortScale,i.mainUV.y)).b;
//采样噪点贴图
fixed4 _NoiseTex_var=tex2D(_NoiseTex,i.noiseUV);
//主纹理贴图与噪点混合
color.rgb=color.rgb+(1-color.rgb)*_NoiseTex_var*_NoiseStrenth;
return fixed4(color.rgb,1);
//return _DistortTex_var;
}
ENDCG
}
}
// FallBack "Diffuse"
}