Help us understand the problem. What is going on with this article?

テレビノイズImageEffectのシェーダコード

Twitterで書いたテレビノイズImageEffectのシェーダコードを置いておきます

TvNoise.shader
Shader "ScreenPocket/ImageEffect/TvNoise"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        noiseSpeed ("Noise Speed", Float) = 30
        noiseClampNum ("Noise Clamp", Float) = 1.0
        noiseWaveNum ("Noise Wave", Float) = 32.0
        noisePower ("Noise Power", Float) = 0.05
    }
    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
            {
                float4 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            float noiseSpeed;
            float noiseClampNum;
            float noiseWaveNum;
            float noisePower;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv.xy = v.uv;

                //はみ出し部分を考慮してループ
                float div = 1.0 / noiseWaveNum;
                o.uv.z = frac(_Time.w * noiseSpeed) * (1.0 + div * 2) - div;

                //Clamp値
                o.uv.w = 360.0 * noiseClampNum;
                return o;
            }

            sampler2D _MainTex;

            fixed4 frag (v2f i) : SV_Target
            {
                float noise = i.uv.z - (1 - i.uv.y);
                i.uv.x += sin( radians( clamp( noise * 360.0 * noiseWaveNum, 0, i.uv.w ) ) ) * noisePower;
                return tex2D(_MainTex, i.uv.xy);
            }
            ENDCG
        }
    }
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away