5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2020-03-08

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
        }
    }
}
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?