Unity shader 抖音效果(屏幕特效)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/y90o08u28/article/details/87275090

douyinpic1

Shader "Douyin/gt"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        scale ("scale", float) = 1
    }
    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 scale;

            fixed4 frag (v2f i) : SV_Target
            {
                float2 textureCoordinate = i.uv;

                float2 newTextureCoordinate = float2((scale - 1.0) *0.5 + textureCoordinate.x / scale ,(scale - 1.0) *0.5 + textureCoordinate.y /scale);
                

                fixed4 textureColor = tex2D(_MainTex, newTextureCoordinate);
    
                fixed4 shiftColor1 = tex2D(_MainTex, newTextureCoordinate+float2(-0.05 * (scale - 1.0), - 0.05 *(scale - 1.0)));
    
                fixed4 shiftColor2 = tex2D(_MainTex, newTextureCoordinate+float2(-0.1 * (scale - 1.0), - 0.1 *(scale - 1.0)));
    
                fixed3 blendFirstColor = fixed3(textureColor.r , textureColor.g, shiftColor1.b);
    
                fixed3 blend3DColor = fixed3(shiftColor2.r, blendFirstColor.g, blendFirstColor.b);
    
                return fixed4(blend3DColor, textureColor.a);

            }
            ENDCG
        }
    }
}

本人qq:344810449,一起研究技术。

猜你喜欢

转载自blog.csdn.net/y90o08u28/article/details/87275090