信号干扰的效果制作

本文介绍了一个Unity Shader的实现案例,用于在游戏中创建电视信号干扰或失真效果。通过调整颜色偏移、扰动贴图、噪波贴图等参数,可以模拟出逼真的电视信号不稳定现象。该Shader利用了多种纹理和时间变量来实现动态的视觉效果。
摘要由CSDN通过智能技术生成

有时候游戏里面会用到信号干扰的电视效果,或者是信号顾兆效果

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"

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值