朋友约我看水,我反手用可视化搞出水面倒影(Shader Graph)

简介: 众所周知,人生是一个漫长的流程,不断克服困难,不断反思前进的过程。在这个过程中会产生很多对于人生的质疑和思考,于是我决定将自己的思考,经验和故事全部分享出来,以此寻找共鸣!!!

👉关于作者

众所周知,人生是一个漫长的流程,不断克服困难,不断反思前进的过程。在这个过程中会产生很多对于人生的质疑和思考,于是我决定将自己的思考,经验和故事全部分享出来,以此寻找共鸣!!!

专注于Android/Unity和各种游戏开发技巧,以及各种资源分享(网站、工具、素材、源码、游戏等)

👉即将学会

Shader Graph可视化Shader编辑工具创作一个水面倒影效果,不需要写代码就能实现效果。

👉效果预看

网络异常,图片无法展示
|

👉背景

在某一个周末的傍晚,小芝突然找到小空。

🙎小芝:你看,你看,夕阳映射的晚霞特别美。

🙈小空:恩,确实。

🙎小芝:……你根本没有认真看,老敷衍怪了。你想想要是在海边倒映出来那多幸福啊。

🙈小空沉思:倒影,倒影,这个怎么能让她在Unity中搞起来呢?

🙎小芝:……,完了完了,又沉寂进去了。

👉案例环境

Unity 2020.3系列f1

Package Manager包管理器中确保安装了Shader Graph

思路:

  1. 利用另外一个相机捕捉画面,翻转后放到下面。
  2. 利用Shader Graph为画面添加水波效果。

👉实践过程

首先建立一个WaterShadow的文件夹,以下创建全部在此文件夹下。

右键在里面创建一个Render Texture(渲染器纹理)起名叫做Water Render,尺寸可以看着效果对应着改。

在场景中创建一个Camera(相机),改名为WaterCamera,相机属性和Main Camera(主相机)相同,不同的是摄像的内容是你想要映射的内容。稍微自己调下位置即可。

网络异常,图片无法展示
|

重点——指定WaterCamera的Output Texture为刚才创建的Water Render。原理:将相机摄入的内容渲染到Water Render中,将这个Render借住其他组件在场景中展示出来即可。

网络异常,图片无法展示
|

创建一个Square(右键-创建-2D-Sprites中),并且拖拽到场景中,改名为WaterSquare,然后调整合适的位置。

网络异常,图片无法展示
|

创建一个Shader(右键-Shader-URP-Sprite Unlit Shader),改名为WaterShader,双击就能打开它

网络异常,图片无法展示
|

网络异常,图片无法展示
|

超级重点

在这里右键我们可以创建节点Node(有各种各样的类型)

为了在外部能够随时更改里面的内容,我们先创建一个Texture2D变量,然后将变量拖拽到舞台中,接着创建一个Sample Texture 2D节点,最后将变量节点指向此节点的Texture

网络异常,图片无法展示
|

我们想要先预览一下效果,在WaterShadow文件夹中创建材质Material,改名为WaterMaterial,然后将Shader赋给这个Material一种是直接拖拽WaterShader到WaterMaterial上,一种是在WaterMaterial右侧选择,然后我们将WaterMaterial拖拽赋值给WaterSquare(直接拖拽到场景中赋值即可),接着你就会看到效果啦。

这种效果我们还并不满足,我们要继续往下优化,将内容翻转,所有需要创建Tiling And Offset翻转节点。

接着运行查看发现很像水面的效果了。但这还不够逼真,我们需要模拟出水面的波纹效果。那么我们就需要去继续添加噪点的节点Simple Noise。

这时候还没够,这时候还是静态的,我们需要动态的,那么我们就需要利用时间的变化来动起来(创建Time节点)

经过各种连接后,我们创建了下面一个可视化的Shader。

网络异常,图片无法展示
|

我们看看运行后的效果:

网络异常,图片无法展示
|

最后我们附上代码的Shader。文末有想项目源码下载地址。

Shader "WaterShader"
{
    Properties
    {
        [NoScaleOffset]Texture2D_40d3e1ffef7f43f6b3648f291bb5974d("WaterTexture", 2D) = "white" {}
        Vector1_3b055a08b82546ffbbe80087a02fe9cb("Speed", Float) = 0.2
        Vector1_23db7fea7a93488a82f726fa778690e9("Strength", Float) = 0.02
        Color_cfca9819e86340599cd882083808e8c0("Color", Color) = (0.4185208, 0.8962264, 0.8486329, 0.5019608)
        [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
        [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
        [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
    }
    SubShader
    {
        Tags
        {
            "RenderPipeline"="UniversalPipeline"
            "RenderType"="Transparent"
            "UniversalMaterialType" = "Unlit"
            "Queue"="Transparent"
        }
        Pass
        {
            Name "Sprite Unlit"
            Tags
            {
                "LightMode" = "Universal2D"
            }
            // Render State
            Cull Off
        Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
        ZTest LEqual
        ZWrite Off
            // Debug
            // <None>
            // --------------------------------------------------
            // Pass
            HLSLPROGRAM
            // Pragmas
            #pragma target 2.0
        #pragma exclude_renderers d3d11_9x
        #pragma vertex vert
        #pragma fragment frag
            // DotsInstancingOptions: <None>
            // HybridV1InjectedBuiltinProperties: <None>
            // Keywords
            // PassKeywords: <None>
            // GraphKeywords: <None>
            // Defines
            #define _SURFACE_TYPE_TRANSPARENT 1
            #define ATTRIBUTES_NEED_NORMAL
            #define ATTRIBUTES_NEED_TANGENT
            #define ATTRIBUTES_NEED_TEXCOORD0
            #define ATTRIBUTES_NEED_COLOR
            #define VARYINGS_NEED_TEXCOORD0
            #define VARYINGS_NEED_COLOR
            #define FEATURES_GRAPH_VERTEX
            /* WARNING: $splice Could not find named fragment 'PassInstancing' */
            #define SHADERPASS SHADERPASS_SPRITEUNLIT
            /* WARNING: $splice Could not find named fragment 'DotsInstancingVars' */
            // Includes
            #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
        #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
        #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
            // --------------------------------------------------
            // Structs and Packing
            struct Attributes
        {
            float3 positionOS : POSITION;
            float3 normalOS : NORMAL;
            float4 tangentOS : TANGENT;
            float4 uv0 : TEXCOORD0;
            float4 color : COLOR;
            #if UNITY_ANY_INSTANCING_ENABLED
            uint instanceID : INSTANCEID_SEMANTIC;
            #endif
        };
        struct Varyings
        {
            float4 positionCS : SV_POSITION;
            float4 texCoord0;
            float4 color;
            #if UNITY_ANY_INSTANCING_ENABLED
            uint instanceID : CUSTOM_INSTANCE_ID;
            #endif
            #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
            uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
            #endif
            #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
            uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
            #endif
            #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
            FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
            #endif
        };
        struct SurfaceDescriptionInputs
        {
            float4 uv0;
            float3 TimeParameters;
        };
        struct VertexDescriptionInputs
        {
            float3 ObjectSpaceNormal;
            float3 ObjectSpaceTangent;
            float3 ObjectSpacePosition;
        };
        struct PackedVaryings
        {
            float4 positionCS : SV_POSITION;
            float4 interp0 : TEXCOORD0;
            float4 interp1 : TEXCOORD1;
            #if UNITY_ANY_INSTANCING_ENABLED
            uint instanceID : CUSTOM_INSTANCE_ID;
            #endif
            #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
            uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
            #endif
            #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
            uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
            #endif
            #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
            FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
            #endif
        };
            PackedVaryings PackVaryings (Varyings input)
        {
            PackedVaryings output;
            output.positionCS = input.positionCS;
            output.interp0.xyzw =  input.texCoord0;
            output.interp1.xyzw =  input.color;
            #if UNITY_ANY_INSTANCING_ENABLED
            output.instanceID = input.instanceID;
            #endif
            #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
            output.stereoTargetEyeIndexAsBlendIdx0 = input.stereoTargetEyeIndexAsBlendIdx0;
            #endif
            #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
            output.stereoTargetEyeIndexAsRTArrayIdx = input.stereoTargetEyeIndexAsRTArrayIdx;
            #endif
            #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
            output.cullFace = input.cullFace;
            #endif
            return output;
        }
        Varyings UnpackVaryings (PackedVaryings input)
        {
            Varyings output;
            output.positionCS = input.positionCS;
            output.texCoord0 = input.interp0.xyzw;
            output.color = input.interp1.xyzw;
            #if UNITY_ANY_INSTANCING_ENABLED
            output.instanceID = input.instanceID;
            #endif
            #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
            output.stereoTargetEyeIndexAsBlendIdx0 = input.stereoTargetEyeIndexAsBlendIdx0;
            #endif
            #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
            output.stereoTargetEyeIndexAsRTArrayIdx = input.stereoTargetEyeIndexAsRTArrayIdx;
            #endif
            #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
            output.cullFace = input.cullFace;
            #endif
            return output;
        }
            // --------------------------------------------------
            // Graph
            // Graph Properties
            CBUFFER_START(UnityPerMaterial)
        float4 Texture2D_40d3e1ffef7f43f6b3648f291bb5974d_TexelSize;
        float Vector1_3b055a08b82546ffbbe80087a02fe9cb;
        float Vector1_23db7fea7a93488a82f726fa778690e9;
        float4 Color_cfca9819e86340599cd882083808e8c0;
        CBUFFER_END
        // Object and Global properties
        SAMPLER(SamplerState_Linear_Repeat);
        TEXTURE2D(Texture2D_40d3e1ffef7f43f6b3648f291bb5974d);
        SAMPLER(samplerTexture2D_40d3e1ffef7f43f6b3648f291bb5974d);
            // Graph Functions
        float2 Unity_GradientNoise_Dir_float(float2 p)
        {
            // Permutation and hashing used in webgl-nosie goo.gl/pX7HtC
            p = p % 289;
            // need full precision, otherwise half overflows when p > 1
            float x = float(34 * p.x + 1) * p.x % 289 + p.y;
            x = (34 * x + 1) * x % 289;
            x = frac(x / 41) * 2 - 1;
            return normalize(float2(x - floor(x + 0.5), abs(x) - 0.5));
        }
        void Unity_GradientNoise_float(float2 UV, float Scale, out float Out)
        { 
            float2 p = UV * Scale;
            float2 ip = floor(p);
            float2 fp = frac(p);
            float d00 = dot(Unity_GradientNoise_Dir_float(ip), fp);
            float d01 = dot(Unity_GradientNoise_Dir_float(ip + float2(0, 1)), fp - float2(0, 1));
            float d10 = dot(Unity_GradientNoise_Dir_float(ip + float2(1, 0)), fp - float2(1, 0));
            float d11 = dot(Unity_GradientNoise_Dir_float(ip + float2(1, 1)), fp - float2(1, 1));
            fp = fp * fp * fp * (fp * (fp * 6 - 15) + 10);
            Out = lerp(lerp(d00, d01, fp.y), lerp(d10, d11, fp.y), fp.x) + 0.5;
        }
        void Unity_Multiply_float(float A, float B, out float Out)
        {
            Out = A * B;
        }
        void Unity_Add_float(float A, float B, out float Out)
        {
            Out = A + B;
        }
        inline float Unity_SimpleNoise_RandomValue_float (float2 uv)
        {
            return frac(sin(dot(uv, float2(12.9898, 78.233)))*43758.5453);
        }
        inline float Unity_SimpleNnoise_Interpolate_float (float a, float b, float t)
        {
            return (1.0-t)*a + (t*b);
        }
        inline float Unity_SimpleNoise_ValueNoise_float (float2 uv)
        {
            float2 i = floor(uv);
            float2 f = frac(uv);
            f = f * f * (3.0 - 2.0 * f);
            uv = abs(frac(uv) - 0.5);
            float2 c0 = i + float2(0.0, 0.0);
            float2 c1 = i + float2(1.0, 0.0);
            float2 c2 = i + float2(0.0, 1.0);
            float2 c3 = i + float2(1.0, 1.0);
            float r0 = Unity_SimpleNoise_RandomValue_float(c0);
            float r1 = Unity_SimpleNoise_RandomValue_float(c1);
            float r2 = Unity_SimpleNoise_RandomValue_float(c2);
            float r3 = Unity_SimpleNoise_RandomValue_float(c3);
            float bottomOfGrid = Unity_SimpleNnoise_Interpolate_float(r0, r1, f.x);
            float topOfGrid = Unity_SimpleNnoise_Interpolate_float(r2, r3, f.x);
            float t = Unity_SimpleNnoise_Interpolate_float(bottomOfGrid, topOfGrid, f.y);
            return t;
        }
        void Unity_SimpleNoise_float(float2 UV, float Scale, out float Out)
        {
            float t = 0.0;
            float freq = pow(2.0, float(0));
            float amp = pow(0.5, float(3-0));
            t += Unity_SimpleNoise_ValueNoise_float(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
            freq = pow(2.0, float(1));
            amp = pow(0.5, float(3-1));
            t += Unity_SimpleNoise_ValueNoise_float(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
            freq = pow(2.0, float(2));
            amp = pow(0.5, float(3-2));
            t += Unity_SimpleNoise_ValueNoise_float(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
            Out = t;
        }
        void Unity_TilingAndOffset_float(float2 UV, float2 Tiling, float2 Offset, out float2 Out)
        {
            Out = UV * Tiling + Offset;
        }
        void Unity_Multiply_float(float4 A, float4 B, out float4 Out)
        {
            Out = A * B;
        }
            // Graph Vertex
            struct VertexDescription
        {
            float3 Position;
            float3 Normal;
            float3 Tangent;
        };
        VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
        {
            VertexDescription description = (VertexDescription)0;
            description.Position = IN.ObjectSpacePosition;
            description.Normal = IN.ObjectSpaceNormal;
            description.Tangent = IN.ObjectSpaceTangent;
            return description;
        }
            // Graph Pixel
            struct SurfaceDescription
        {
            float3 BaseColor;
            float Alpha;
        };
        SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
        {
            SurfaceDescription surface = (SurfaceDescription)0;
            UnityTexture2D _Property_5f96fa6b31874c7c8f49a5ba4c802ea1_Out_0 = UnityBuildTexture2DStructNoScale(Texture2D_40d3e1ffef7f43f6b3648f291bb5974d);
            float _Property_e2b4dcb7085e4752ace7d623eaa848a5_Out_0 = Vector1_23db7fea7a93488a82f726fa778690e9;
            float _GradientNoise_0295ca2f6ca341b1ac796ec73bf2385e_Out_2;
            Unity_GradientNoise_float(IN.uv0.xy, 3, _GradientNoise_0295ca2f6ca341b1ac796ec73bf2385e_Out_2);
            float _Property_7166f06b49d84545891345939cacb632_Out_0 = Vector1_3b055a08b82546ffbbe80087a02fe9cb;
            float _Multiply_bbf027acfdbb41ccaa57e62650292da4_Out_2;
            Unity_Multiply_float(_Property_7166f06b49d84545891345939cacb632_Out_0, IN.TimeParameters.x, _Multiply_bbf027acfdbb41ccaa57e62650292da4_Out_2);
            float _Add_31381d66d83848d381412ee3af768cad_Out_2;
            Unity_Add_float(_GradientNoise_0295ca2f6ca341b1ac796ec73bf2385e_Out_2, _Multiply_bbf027acfdbb41ccaa57e62650292da4_Out_2, _Add_31381d66d83848d381412ee3af768cad_Out_2);
            float _SimpleNoise_634cb24c606344d28b5e7c670c09ba7a_Out_2;
            Unity_SimpleNoise_float((_Add_31381d66d83848d381412ee3af768cad_Out_2.xx), 50, _SimpleNoise_634cb24c606344d28b5e7c670c09ba7a_Out_2);
            float _Multiply_8c1af9eb25a14ad7910d7c5737106dba_Out_2;
            Unity_Multiply_float(_Property_e2b4dcb7085e4752ace7d623eaa848a5_Out_0, _SimpleNoise_634cb24c606344d28b5e7c670c09ba7a_Out_2, _Multiply_8c1af9eb25a14ad7910d7c5737106dba_Out_2);
            float2 _Vector2_6686572d44b148c3bd43ea00a7ee71d6_Out_0 = float2(_Multiply_8c1af9eb25a14ad7910d7c5737106dba_Out_2, 1);
            float2 _TilingAndOffset_80aee777cdc84f93b09a9f58f7cd8a21_Out_3;
            Unity_TilingAndOffset_float(IN.uv0.xy, float2 (1, -1), _Vector2_6686572d44b148c3bd43ea00a7ee71d6_Out_0, _TilingAndOffset_80aee777cdc84f93b09a9f58f7cd8a21_Out_3);
            float4 _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_RGBA_0 = SAMPLE_TEXTURE2D(_Property_5f96fa6b31874c7c8f49a5ba4c802ea1_Out_0.tex, _Property_5f96fa6b31874c7c8f49a5ba4c802ea1_Out_0.samplerstate, _TilingAndOffset_80aee777cdc84f93b09a9f58f7cd8a21_Out_3);
            float _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_R_4 = _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_RGBA_0.r;
            float _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_G_5 = _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_RGBA_0.g;
            float _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_B_6 = _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_RGBA_0.b;
            float _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_A_7 = _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_RGBA_0.a;
            float4 _Property_cc5ba6d85d044fb894405bde6f11b58c_Out_0 = Color_cfca9819e86340599cd882083808e8c0;
            float4 _Multiply_a29ff5ef4d7049d2bb4da2beabad978e_Out_2;
            Unity_Multiply_float(_SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_RGBA_0, _Property_cc5ba6d85d044fb894405bde6f11b58c_Out_0, _Multiply_a29ff5ef4d7049d2bb4da2beabad978e_Out_2);
            surface.BaseColor = (_Multiply_a29ff5ef4d7049d2bb4da2beabad978e_Out_2.xyz);
            surface.Alpha = 1;
            return surface;
        }
            // --------------------------------------------------
            // Build Graph Inputs
            VertexDescriptionInputs BuildVertexDescriptionInputs(Attributes input)
        {
            VertexDescriptionInputs output;
            ZERO_INITIALIZE(VertexDescriptionInputs, output);
            output.ObjectSpaceNormal =           input.normalOS;
            output.ObjectSpaceTangent =          input.tangentOS.xyz;
            output.ObjectSpacePosition =         input.positionOS;
            return output;
        }
            SurfaceDescriptionInputs BuildSurfaceDescriptionInputs(Varyings input)
        {
            SurfaceDescriptionInputs output;
            ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
            output.uv0 =                         input.texCoord0;
            output.TimeParameters =              _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value
        #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
        #define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN output.FaceSign =                    IS_FRONT_VFACE(input.cullFace, true, false);
        #else
        #define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
        #endif
        #undef BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
            return output;
        }
            // --------------------------------------------------
            // Main
            #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/Varyings.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteUnlitPass.hlsl"
            ENDHLSL
        }
        Pass
        {
            Name "Sprite Unlit"
            Tags
            {
                "LightMode" = "UniversalForward"
            }
            // Render State
            Cull Off
        Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
        ZTest LEqual
        ZWrite Off
            // Debug
            // <None>
            // --------------------------------------------------
            // Pass
            HLSLPROGRAM
            // Pragmas
            #pragma target 2.0
        #pragma exclude_renderers d3d11_9x
        #pragma vertex vert
        #pragma fragment frag
            // DotsInstancingOptions: <None>
            // HybridV1InjectedBuiltinProperties: <None>
            // Keywords
            // PassKeywords: <None>
            // GraphKeywords: <None>
            // Defines
            #define _SURFACE_TYPE_TRANSPARENT 1
            #define ATTRIBUTES_NEED_NORMAL
            #define ATTRIBUTES_NEED_TANGENT
            #define ATTRIBUTES_NEED_TEXCOORD0
            #define ATTRIBUTES_NEED_COLOR
            #define VARYINGS_NEED_TEXCOORD0
            #define VARYINGS_NEED_COLOR
            #define FEATURES_GRAPH_VERTEX
            /* WARNING: $splice Could not find named fragment 'PassInstancing' */
            #define SHADERPASS SHADERPASS_SPRITEFORWARD
            /* WARNING: $splice Could not find named fragment 'DotsInstancingVars' */
            // Includes
            #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
        #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
        #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
            // --------------------------------------------------
            // Structs and Packing
            struct Attributes
        {
            float3 positionOS : POSITION;
            float3 normalOS : NORMAL;
            float4 tangentOS : TANGENT;
            float4 uv0 : TEXCOORD0;
            float4 color : COLOR;
            #if UNITY_ANY_INSTANCING_ENABLED
            uint instanceID : INSTANCEID_SEMANTIC;
            #endif
        };
        struct Varyings
        {
            float4 positionCS : SV_POSITION;
            float4 texCoord0;
            float4 color;
            #if UNITY_ANY_INSTANCING_ENABLED
            uint instanceID : CUSTOM_INSTANCE_ID;
            #endif
            #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
            uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
            #endif
            #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
            uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
            #endif
            #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
            FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
            #endif
        };
        struct SurfaceDescriptionInputs
        {
            float4 uv0;
            float3 TimeParameters;
        };
        struct VertexDescriptionInputs
        {
            float3 ObjectSpaceNormal;
            float3 ObjectSpaceTangent;
            float3 ObjectSpacePosition;
        };
        struct PackedVaryings
        {
            float4 positionCS : SV_POSITION;
            float4 interp0 : TEXCOORD0;
            float4 interp1 : TEXCOORD1;
            #if UNITY_ANY_INSTANCING_ENABLED
            uint instanceID : CUSTOM_INSTANCE_ID;
            #endif
            #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
            uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
            #endif
            #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
            uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
            #endif
            #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
            FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
            #endif
        };
            PackedVaryings PackVaryings (Varyings input)
        {
            PackedVaryings output;
            output.positionCS = input.positionCS;
            output.interp0.xyzw =  input.texCoord0;
            output.interp1.xyzw =  input.color;
            #if UNITY_ANY_INSTANCING_ENABLED
            output.instanceID = input.instanceID;
            #endif
            #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
            output.stereoTargetEyeIndexAsBlendIdx0 = input.stereoTargetEyeIndexAsBlendIdx0;
            #endif
            #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
            output.stereoTargetEyeIndexAsRTArrayIdx = input.stereoTargetEyeIndexAsRTArrayIdx;
            #endif
            #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
            output.cullFace = input.cullFace;
            #endif
            return output;
        }
        Varyings UnpackVaryings (PackedVaryings input)
        {
            Varyings output;
            output.positionCS = input.positionCS;
            output.texCoord0 = input.interp0.xyzw;
            output.color = input.interp1.xyzw;
            #if UNITY_ANY_INSTANCING_ENABLED
            output.instanceID = input.instanceID;
            #endif
            #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
            output.stereoTargetEyeIndexAsBlendIdx0 = input.stereoTargetEyeIndexAsBlendIdx0;
            #endif
            #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
            output.stereoTargetEyeIndexAsRTArrayIdx = input.stereoTargetEyeIndexAsRTArrayIdx;
            #endif
            #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
            output.cullFace = input.cullFace;
            #endif
            return output;
        }
            // --------------------------------------------------
            // Graph
            // Graph Properties
            CBUFFER_START(UnityPerMaterial)
        float4 Texture2D_40d3e1ffef7f43f6b3648f291bb5974d_TexelSize;
        float Vector1_3b055a08b82546ffbbe80087a02fe9cb;
        float Vector1_23db7fea7a93488a82f726fa778690e9;
        float4 Color_cfca9819e86340599cd882083808e8c0;
        CBUFFER_END
        // Object and Global properties
        SAMPLER(SamplerState_Linear_Repeat);
        TEXTURE2D(Texture2D_40d3e1ffef7f43f6b3648f291bb5974d);
        SAMPLER(samplerTexture2D_40d3e1ffef7f43f6b3648f291bb5974d);
            // Graph Functions
        float2 Unity_GradientNoise_Dir_float(float2 p)
        {
            // Permutation and hashing used in webgl-nosie goo.gl/pX7HtC
            p = p % 289;
            // need full precision, otherwise half overflows when p > 1
            float x = float(34 * p.x + 1) * p.x % 289 + p.y;
            x = (34 * x + 1) * x % 289;
            x = frac(x / 41) * 2 - 1;
            return normalize(float2(x - floor(x + 0.5), abs(x) - 0.5));
        }
        void Unity_GradientNoise_float(float2 UV, float Scale, out float Out)
        { 
            float2 p = UV * Scale;
            float2 ip = floor(p);
            float2 fp = frac(p);
            float d00 = dot(Unity_GradientNoise_Dir_float(ip), fp);
            float d01 = dot(Unity_GradientNoise_Dir_float(ip + float2(0, 1)), fp - float2(0, 1));
            float d10 = dot(Unity_GradientNoise_Dir_float(ip + float2(1, 0)), fp - float2(1, 0));
            float d11 = dot(Unity_GradientNoise_Dir_float(ip + float2(1, 1)), fp - float2(1, 1));
            fp = fp * fp * fp * (fp * (fp * 6 - 15) + 10);
            Out = lerp(lerp(d00, d01, fp.y), lerp(d10, d11, fp.y), fp.x) + 0.5;
        }
        void Unity_Multiply_float(float A, float B, out float Out)
        {
            Out = A * B;
        }
        void Unity_Add_float(float A, float B, out float Out)
        {
            Out = A + B;
        }
        inline float Unity_SimpleNoise_RandomValue_float (float2 uv)
        {
            return frac(sin(dot(uv, float2(12.9898, 78.233)))*43758.5453);
        }
        inline float Unity_SimpleNnoise_Interpolate_float (float a, float b, float t)
        {
            return (1.0-t)*a + (t*b);
        }
        inline float Unity_SimpleNoise_ValueNoise_float (float2 uv)
        {
            float2 i = floor(uv);
            float2 f = frac(uv);
            f = f * f * (3.0 - 2.0 * f);
            uv = abs(frac(uv) - 0.5);
            float2 c0 = i + float2(0.0, 0.0);
            float2 c1 = i + float2(1.0, 0.0);
            float2 c2 = i + float2(0.0, 1.0);
            float2 c3 = i + float2(1.0, 1.0);
            float r0 = Unity_SimpleNoise_RandomValue_float(c0);
            float r1 = Unity_SimpleNoise_RandomValue_float(c1);
            float r2 = Unity_SimpleNoise_RandomValue_float(c2);
            float r3 = Unity_SimpleNoise_RandomValue_float(c3);
            float bottomOfGrid = Unity_SimpleNnoise_Interpolate_float(r0, r1, f.x);
            float topOfGrid = Unity_SimpleNnoise_Interpolate_float(r2, r3, f.x);
            float t = Unity_SimpleNnoise_Interpolate_float(bottomOfGrid, topOfGrid, f.y);
            return t;
        }
        void Unity_SimpleNoise_float(float2 UV, float Scale, out float Out)
        {
            float t = 0.0;
            float freq = pow(2.0, float(0));
            float amp = pow(0.5, float(3-0));
            t += Unity_SimpleNoise_ValueNoise_float(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
            freq = pow(2.0, float(1));
            amp = pow(0.5, float(3-1));
            t += Unity_SimpleNoise_ValueNoise_float(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
            freq = pow(2.0, float(2));
            amp = pow(0.5, float(3-2));
            t += Unity_SimpleNoise_ValueNoise_float(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
            Out = t;
        }
        void Unity_TilingAndOffset_float(float2 UV, float2 Tiling, float2 Offset, out float2 Out)
        {
            Out = UV * Tiling + Offset;
        }
        void Unity_Multiply_float(float4 A, float4 B, out float4 Out)
        {
            Out = A * B;
        }
            // Graph Vertex
            struct VertexDescription
        {
            float3 Position;
            float3 Normal;
            float3 Tangent;
        };
        VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
        {
            VertexDescription description = (VertexDescription)0;
            description.Position = IN.ObjectSpacePosition;
            description.Normal = IN.ObjectSpaceNormal;
            description.Tangent = IN.ObjectSpaceTangent;
            return description;
        }
            // Graph Pixel
            struct SurfaceDescription
        {
            float3 BaseColor;
            float Alpha;
        };
        SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
        {
            SurfaceDescription surface = (SurfaceDescription)0;
            UnityTexture2D _Property_5f96fa6b31874c7c8f49a5ba4c802ea1_Out_0 = UnityBuildTexture2DStructNoScale(Texture2D_40d3e1ffef7f43f6b3648f291bb5974d);
            float _Property_e2b4dcb7085e4752ace7d623eaa848a5_Out_0 = Vector1_23db7fea7a93488a82f726fa778690e9;
            float _GradientNoise_0295ca2f6ca341b1ac796ec73bf2385e_Out_2;
            Unity_GradientNoise_float(IN.uv0.xy, 3, _GradientNoise_0295ca2f6ca341b1ac796ec73bf2385e_Out_2);
            float _Property_7166f06b49d84545891345939cacb632_Out_0 = Vector1_3b055a08b82546ffbbe80087a02fe9cb;
            float _Multiply_bbf027acfdbb41ccaa57e62650292da4_Out_2;
            Unity_Multiply_float(_Property_7166f06b49d84545891345939cacb632_Out_0, IN.TimeParameters.x, _Multiply_bbf027acfdbb41ccaa57e62650292da4_Out_2);
            float _Add_31381d66d83848d381412ee3af768cad_Out_2;
            Unity_Add_float(_GradientNoise_0295ca2f6ca341b1ac796ec73bf2385e_Out_2, _Multiply_bbf027acfdbb41ccaa57e62650292da4_Out_2, _Add_31381d66d83848d381412ee3af768cad_Out_2);
            float _SimpleNoise_634cb24c606344d28b5e7c670c09ba7a_Out_2;
            Unity_SimpleNoise_float((_Add_31381d66d83848d381412ee3af768cad_Out_2.xx), 50, _SimpleNoise_634cb24c606344d28b5e7c670c09ba7a_Out_2);
            float _Multiply_8c1af9eb25a14ad7910d7c5737106dba_Out_2;
            Unity_Multiply_float(_Property_e2b4dcb7085e4752ace7d623eaa848a5_Out_0, _SimpleNoise_634cb24c606344d28b5e7c670c09ba7a_Out_2, _Multiply_8c1af9eb25a14ad7910d7c5737106dba_Out_2);
            float2 _Vector2_6686572d44b148c3bd43ea00a7ee71d6_Out_0 = float2(_Multiply_8c1af9eb25a14ad7910d7c5737106dba_Out_2, 1);
            float2 _TilingAndOffset_80aee777cdc84f93b09a9f58f7cd8a21_Out_3;
            Unity_TilingAndOffset_float(IN.uv0.xy, float2 (1, -1), _Vector2_6686572d44b148c3bd43ea00a7ee71d6_Out_0, _TilingAndOffset_80aee777cdc84f93b09a9f58f7cd8a21_Out_3);
            float4 _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_RGBA_0 = SAMPLE_TEXTURE2D(_Property_5f96fa6b31874c7c8f49a5ba4c802ea1_Out_0.tex, _Property_5f96fa6b31874c7c8f49a5ba4c802ea1_Out_0.samplerstate, _TilingAndOffset_80aee777cdc84f93b09a9f58f7cd8a21_Out_3);
            float _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_R_4 = _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_RGBA_0.r;
            float _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_G_5 = _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_RGBA_0.g;
            float _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_B_6 = _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_RGBA_0.b;
            float _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_A_7 = _SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_RGBA_0.a;
            float4 _Property_cc5ba6d85d044fb894405bde6f11b58c_Out_0 = Color_cfca9819e86340599cd882083808e8c0;
            float4 _Multiply_a29ff5ef4d7049d2bb4da2beabad978e_Out_2;
            Unity_Multiply_float(_SampleTexture2D_a940191ef9bb4c11a83d593387dc04f9_RGBA_0, _Property_cc5ba6d85d044fb894405bde6f11b58c_Out_0, _Multiply_a29ff5ef4d7049d2bb4da2beabad978e_Out_2);
            surface.BaseColor = (_Multiply_a29ff5ef4d7049d2bb4da2beabad978e_Out_2.xyz);
            surface.Alpha = 1;
            return surface;
        }
            // --------------------------------------------------
            // Build Graph Inputs
            VertexDescriptionInputs BuildVertexDescriptionInputs(Attributes input)
        {
            VertexDescriptionInputs output;
            ZERO_INITIALIZE(VertexDescriptionInputs, output);
            output.ObjectSpaceNormal =           input.normalOS;
            output.ObjectSpaceTangent =          input.tangentOS.xyz;
            output.ObjectSpacePosition =         input.positionOS;
            return output;
        }
            SurfaceDescriptionInputs BuildSurfaceDescriptionInputs(Varyings input)
        {
            SurfaceDescriptionInputs output;
            ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
            output.uv0 =                         input.texCoord0;
            output.TimeParameters =              _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value
        #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
        #define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN output.FaceSign =                    IS_FRONT_VFACE(input.cullFace, true, false);
        #else
        #define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
        #endif
        #undef BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
            return output;
        }
            // --------------------------------------------------
            // Main
            #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/Varyings.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteUnlitPass.hlsl"
            ENDHLSL
        }
    }
    FallBack "Hidden/Shader Graph/FallbackError"
}
复制代码

源码下载地址:Unity技术-ShaderGraph-水面倒影Shader.zip-Unity3D文档类资源-CSDN下载

👉其他

📢作者:小空和小芝中的小空

📢这位道友请留步☁️,我观你气度不凡,谈吐间隐隐有王者霸气💚,日后定有一番大作为📝!!!旁边有点赞👍收藏🌟今日传你,点了吧,未来你成功☀️,我分文不取,若不成功⚡️,也好回来找我。


相关文章
|
6月前
|
编解码 算法 程序员
老程序员分享:OpenGL学习进程(10)第七课:四边形绘制与动画基础
老程序员分享:OpenGL学习进程(10)第七课:四边形绘制与动画基础
|
7月前
|
缓存 数据库 数据安全/隐私保护
我绘制文章插图的三个神级工具
我绘制文章插图的三个神级工具
115 0
|
Python
通过游戏学Python系列之小兔要上天---手把手教你使用Pygame开发平台跳跃类游戏02之物体运动
通过游戏学Python系列之小兔要上天---手把手教你使用Pygame开发平台跳跃类游戏02之物体运动
131 0
|
Python
通过游戏学Python系列之小兔要上天---手把手教你使用Pygame开发平台跳跃类游戏03之重力及碰撞检测
通过游戏学Python系列之小兔要上天---手把手教你使用Pygame开发平台跳跃类游戏03之重力及碰撞检测
191 0
|
Java
手把手一步一步教你使用Java开发一个大型街机动作闯关类游戏21之enemy行走和死亡动画效果
手把手一步一步教你使用Java开发一个大型街机动作闯关类游戏21之enemy行走和死亡动画效果
183 0
|
Java
手把手一步一步教你使用Java开发一个大型街机动作闯关类游戏05图像仿射变换(平移和缩放操作)
手把手一步一步教你使用Java开发一个大型街机动作闯关类游戏05图像仿射变换(平移和缩放操作)
167 0
|
前端开发 JavaScript
2023跨年烟花(浪漫烟花+美妙音乐+雪花飘飘)含前端源码直接下载---系列最终篇
2023跨年烟花(浪漫烟花+美妙音乐+雪花飘飘)含前端源码直接下载---系列最终篇
539 0
2023跨年烟花(浪漫烟花+美妙音乐+雪花飘飘)含前端源码直接下载---系列最终篇
|
算法 C++
【硬核教程】,如何摆脱黑白框编程,1小时学会用c++做一个飞机大战
【硬核教程】,如何摆脱黑白框编程,1小时学会用c++做一个飞机大战
|
前端开发 Python
学习笔记 | Python程序基本格式及trutle绘图函数库(奥运五环、太阳花、五角星、运动时钟、玫瑰花实例附源码)
学习笔记 | Python程序基本格式及trutle绘图函数库(奥运五环、太阳花、五角星、运动时钟、玫瑰花实例附源码)
学习笔记 | Python程序基本格式及trutle绘图函数库(奥运五环、太阳花、五角星、运动时钟、玫瑰花实例附源码)
|
存储 前端开发 uml
史上最强画图工具推荐
史上最强画图工具推荐
791 0
史上最强画图工具推荐