美文网首页
ASE Shader 实现热空气扭曲效果(局部,不是屏幕后处理)

ASE Shader 实现热空气扭曲效果(局部,不是屏幕后处理)

作者: Boyce_Lig | 来源:发表于2022-09-01 17:23 被阅读0次

    Snipaste_2022-09-02_17-07-17.png

    附上源代码

    // Made with Amplify Shader Editor
    // Available at the Unity Asset Store - http://u3d.as/y3X 
    Shader "Custom/Effect/ScreenDistorted"
    {
        Properties
        {
            _NoiseTexture("Noise Texture", 2D) = "white" {}
            [PowerSlider(3)]_DistortStrength("Distort Strength", Range( 0 , 0.1)) = 0
            _DistortTimeFactor("Distort Time Factor", Float) = 0.324
    
        }
        
        SubShader
        {
            
            
            Tags { "RenderType"="Transparent" "Queue"="Transparent+100" }
        LOD 100
    
            CGINCLUDE
            #pragma target 3.0
            ENDCG
            Blend SrcAlpha OneMinusSrcAlpha
            AlphaToMask Off
            Cull Back
            ColorMask RGB
            ZWrite Off
            ZTest LEqual
            
            
            GrabPass{ }
    
            Pass
            {
                Name "Unlit"
                Tags { "LightMode"="ForwardBase" }
                CGPROGRAM
    
                #if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
                #define ASE_DECLARE_SCREENSPACE_TEXTURE(tex) UNITY_DECLARE_SCREENSPACE_TEXTURE(tex);
                #else
                #define ASE_DECLARE_SCREENSPACE_TEXTURE(tex) UNITY_DECLARE_SCREENSPACE_TEXTURE(tex)
                #endif
    
    
                #ifndef UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX
                //only defining to not throw compilation error over Unity 5.5
                #define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
                #endif
                #pragma vertex vert
                #pragma fragment frag
                #pragma multi_compile_instancing
                #include "UnityCG.cginc"
                #include "UnityShaderVariables.cginc"
    
    
                struct appdata
                {
                    float4 vertex : POSITION;
                    float4 color : COLOR;
                    float4 ase_texcoord : TEXCOORD0;
                    UNITY_VERTEX_INPUT_INSTANCE_ID
                };
                
                struct v2f
                {
                    float4 vertex : SV_POSITION;
                    #ifdef ASE_NEEDS_FRAG_WORLD_POSITION
                    float3 worldPos : TEXCOORD0;
                    #endif
                    float4 ase_texcoord1 : TEXCOORD1;
                    float4 ase_texcoord2 : TEXCOORD2;
                    UNITY_VERTEX_INPUT_INSTANCE_ID
                    UNITY_VERTEX_OUTPUT_STEREO
                };
    
                ASE_DECLARE_SCREENSPACE_TEXTURE( _GrabTexture )
                uniform sampler2D _NoiseTexture;
                uniform float4 _NoiseTexture_ST;
                uniform float _DistortTimeFactor;
                uniform float _DistortStrength;
    
                
                v2f vert ( appdata v )
                {
                    v2f o;
                    UNITY_SETUP_INSTANCE_ID(v);
                    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
                    UNITY_TRANSFER_INSTANCE_ID(v, o);
    
                    float4 ase_clipPos = UnityObjectToClipPos(v.vertex);
                    float4 screenPos = ComputeScreenPos(ase_clipPos);
                    o.ase_texcoord1 = screenPos;
                    
                    o.ase_texcoord2.xy = v.ase_texcoord.xy;
                    
                    //setting value to unused interpolator channels and avoid initialization warnings
                    o.ase_texcoord2.zw = 0;
                    float3 vertexValue = float3(0, 0, 0);
                    #if ASE_ABSOLUTE_VERTEX_POS
                    vertexValue = v.vertex.xyz;
                    #endif
                    vertexValue = vertexValue;
                    #if ASE_ABSOLUTE_VERTEX_POS
                    v.vertex.xyz = vertexValue;
                    #else
                    v.vertex.xyz += vertexValue;
                    #endif
                    o.vertex = UnityObjectToClipPos(v.vertex);
    
                    #ifdef ASE_NEEDS_FRAG_WORLD_POSITION
                    o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
                    #endif
                    return o;
                }
                
                fixed4 frag (v2f i ) : SV_Target
                {
                    UNITY_SETUP_INSTANCE_ID(i);
                    UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
                    fixed4 finalColor;
                    #ifdef ASE_NEEDS_FRAG_WORLD_POSITION
                    float3 WorldPosition = i.worldPos;
                    #endif
                    float4 screenPos = i.ase_texcoord1;
                    float4 ase_screenPosNorm = screenPos / screenPos.w;
                    ase_screenPosNorm.z = ( UNITY_NEAR_CLIP_VALUE >= 0 ) ? ase_screenPosNorm.z : ase_screenPosNorm.z * 0.5 + 0.5;
                    float2 uv_NoiseTexture = i.ase_texcoord2.xy * _NoiseTexture_ST.xy + _NoiseTexture_ST.zw;
                    float2 appendResult41 = (float2(_Time.x , _Time.y));
                    float4 tex2DNode13 = tex2D( _NoiseTexture, ( uv_NoiseTexture - ( _DistortTimeFactor * appendResult41 ) ) );
                    float2 appendResult44 = (float2(tex2DNode13.r , tex2DNode13.r));
                    float2 lerpResult48 = lerp( (ase_screenPosNorm).xy , appendResult44 , _DistortStrength);
                    float4 screenColor5 = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_GrabTexture,lerpResult48);
                    
                    
                    finalColor = screenColor5;
                    return finalColor;
                }
                ENDCG
            }
        }
        CustomEditor "ASEMaterialInspector"
        
        
    }
    /*ASEBEGIN
    Version=18935
    2816;457.3333;1920;737;2843.686;264.8875;1;True;True
    Node;AmplifyShaderEditor.TimeNode;40;-2070.99,451.3773;Inherit;False;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
    Node;AmplifyShaderEditor.RangedFloatNode;37;-1929.271,346.9508;Inherit;False;Property;_DistortTimeFactor;Distort Time Factor;2;0;Create;True;0;0;0;False;0;False;0.324;0;0;0;0;1;FLOAT;0
    Node;AmplifyShaderEditor.DynamicAppendNode;41;-1861.926,460.1844;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
    Node;AmplifyShaderEditor.TexturePropertyNode;26;-2021.414,20.93176;Inherit;True;Property;_NoiseTexture;Noise Texture;0;0;Create;True;0;0;0;False;0;False;None;None;False;white;Auto;Texture2D;-1;0;2;SAMPLER2D;0;SAMPLERSTATE;1
    Node;AmplifyShaderEditor.TextureCoordinatesNode;25;-1723.944,206.2565;Inherit;False;0;-1;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
    Node;AmplifyShaderEditor.SimpleMultiplyOpNode;42;-1638.926,343.1844;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT2;0,0;False;1;FLOAT2;0
    Node;AmplifyShaderEditor.SimpleSubtractOpNode;38;-1438.29,267.5774;Inherit;False;2;0;FLOAT2;0,0;False;1;FLOAT2;0,0;False;1;FLOAT2;0
    Node;AmplifyShaderEditor.SamplerNode;13;-1219,248.5;Inherit;True;Property;_Noise;Noise;0;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
    Node;AmplifyShaderEditor.ScreenPosInputsNode;10;-1143.08,61.48767;Float;False;0;False;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
    Node;AmplifyShaderEditor.DynamicAppendNode;44;-903.9174,251.0217;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
    Node;AmplifyShaderEditor.ComponentMaskNode;11;-865.7279,123.5183;Inherit;False;True;True;False;False;1;0;FLOAT4;0,0,0,0;False;1;FLOAT2;0
    Node;AmplifyShaderEditor.RangedFloatNode;15;-970.7999,436.9;Inherit;False;Property;_DistortStrength;Distort Strength;1;0;Create;True;0;0;0;False;1;PowerSlider(3);False;0;0;0;0.1;0;1;FLOAT;0
    Node;AmplifyShaderEditor.LerpOp;48;-543.916,139.4866;Inherit;False;3;0;FLOAT2;0,0;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;1;FLOAT2;0
    Node;AmplifyShaderEditor.ScreenColorNode;5;-367.2881,116.9806;Inherit;False;Global;_GrabScreen0;Grab Screen 0;0;0;Create;True;0;0;0;False;0;False;Object;-1;False;False;False;False;2;0;FLOAT2;0,0;False;1;FLOAT;0;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
    Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;1;-179.1348,106.1555;Float;False;True;-1;2;ASEMaterialInspector;100;1;Custom/Effect/ScreenDistorted;0770190933193b94aaa3065e307002fa;True;Unlit;0;0;Unlit;2;True;True;2;5;False;-1;10;False;-1;0;1;False;-1;0;False;-1;True;0;False;-1;0;False;-1;False;False;False;False;False;False;False;False;False;True;0;False;-1;False;True;0;False;-1;True;True;True;True;True;False;0;False;-1;False;False;False;False;False;False;False;True;False;255;False;-1;255;False;-1;255;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;True;True;2;False;-1;True;0;False;-1;True;False;0;False;-1;0;False;-1;True;2;RenderType=Transparent=RenderType;Queue=Transparent=Queue=100;True;2;False;0;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;1;LightMode=ForwardBase;False;False;0;;0;0;Standard;1;Vertex Position,InvertActionOnDeselection;1;0;0;1;True;False;;False;0
    WireConnection;41;0;40;1
    WireConnection;41;1;40;2
    WireConnection;25;2;26;0
    WireConnection;42;0;37;0
    WireConnection;42;1;41;0
    WireConnection;38;0;25;0
    WireConnection;38;1;42;0
    WireConnection;13;0;26;0
    WireConnection;13;1;38;0
    WireConnection;13;7;26;1
    WireConnection;44;0;13;1
    WireConnection;44;1;13;1
    WireConnection;11;0;10;0
    WireConnection;48;0;11;0
    WireConnection;48;1;44;0
    WireConnection;48;2;15;0
    WireConnection;5;0;48;0
    WireConnection;1;0;5;0
    ASEEND*/
    //CHKSM=AEA5BBAD009167D36C40D8B177EBE7032F2289DD
    

    相关文章

      网友评论

          本文标题:ASE Shader 实现热空气扭曲效果(局部,不是屏幕后处理)

          本文链接:https://www.haomeiwen.com/subject/nhhynrtx.html