扭曲Blur

Shader "JianZe/Unlit"
{
    Properties
    {
       
		[Enum(X8,8,X16,16,X21,21,X26,26)] _Numberofsamples("偏移次数", Float) = 8
		[Enum(ON,0,OFF,1)]_AddCurve("是否加上曲线控制(UV2_U)", Float) = 1
		_U("U方向中心偏移", Range( 0 , 1)) = 0.5
		_V("V方向中心偏移", Range( 0 , 1)) = 0.5
		_blur("blur", Float) = 0
		_mask("mask", 2D) = "white" {}
		_mask_Scale("mask_Scale", Range( 0 , 1)) = 0
		_DispersionScale("色散占比", Range( 0 , 1)) = 0.5
		[Enum(ON,0,OFF,1)]_AddDispersionCurve("色散占比控制是否加上曲线控制(UV2_V)", Float) = 1
    }
 
    SubShader
    {
       Tags { "Queue"="Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True" "RenderPipeline" = "UniversalPipeline" }
        LOD 100
        Pass
        {
            Name "Unlit"
 
            Tags{ "LightMode"= "Grab" }  
            Blend SrcAlpha OneMinusSrcAlpha
            HLSLPROGRAM
            // Required to compile gles 2.0 with standard srp library
           
            #pragma vertex vert
            #pragma fragment frag
         
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

 
            inline float4  ComputeGrabScreenPos( float4 pos )
			{
				#if UNITY_UV_STARTS_AT_TOP
				float scale = -1.0;
				#else
				float scale = 1.0;
				#endif
				float4 o = pos;
				o.y = pos.w * 0.5f;
				o.y = ( pos.y - o.y ) * _ProjectionParams.x * scale + o.y;
				return o;
			}
            struct Attributes
            {
                float4 positionOS       : POSITION;
                float2 texcoord         : TEXCOORD0;
                float4 texcoord1        : TEXCOORD1;
            };
 
            struct Varyings
            {
                float4 positionCS       : SV_POSITION;
                float4 uv               : TEXCOORD0;
                float4 screen_pos       : TEXCOORD1;
                float4 uv2              : TEXCOORD2;
            };
 
            CBUFFER_START(UnityPerMaterial)
            half _Float8;
            half _Numberofsamples;
            half _U;
            half _V;
            half4 _mask_ST;
            half _mask_Scale;
            half _AddCurve;
            half _DispersionScale;
            half _AddDispersionCurve;
            half _blur;
            CBUFFER_END
            TEXTURE2D (_mask);SAMPLER(sampler_mask);
            SAMPLER(_AfterPostProcessTexture); 
            
 
            Varyings vert(Attributes v)
            {
                Varyings o = (Varyings)0;
                o.positionCS = TransformObjectToHClip(v.positionOS.xyz);
                o.uv=v.texcoord1;
                o.uv2.xy=TRANSFORM_TEX(v.texcoord,_mask);
                o.screen_pos=ComputeScreenPos( o.positionCS);
                return o;
 
                
            }
 
            half4 frag(Varyings i) : SV_Target
            {
                half4 Grab_pos=ComputeGrabScreenPos(i.screen_pos);
                half2 screen_pos=Grab_pos.xy/Grab_pos.w;
                half2 blur_uv=screen_pos-half2(_U,_V);
                half2 blur_scale=_AddCurve==0?(i.uv.x+_blur)*blur_uv*half2(0.1f,0.1f):(_blur)*blur_uv*half2(0.1f,0.1f); 
                half3 source_color=tex2D(_AfterPostProcessTexture,screen_pos).xyz;
                int blur_num=_Numberofsamples;
                half3 final_blurColor=half3(0,0,0);
                half3 dispersion_color=half3(0,0,0);
                half  dispersion_scale=_AddDispersionCurve==0?i.uv.y+_DispersionScale:_DispersionScale;
                for(int num=0;num

你可能感兴趣的:(unity,游戏引擎)