Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

HDRP See object only trough another

Discussion in 'Shaders' started by alexanderkudryavy, Oct 15, 2021.

  1. alexanderkudryavy

    alexanderkudryavy

    Joined:
    Sep 20, 2019
    Posts:
    13
    Hi guys, please can you tell me how I can do that trick with HDRPLit?
     
  2. rob11

    rob11

    Joined:
    Mar 7, 2017
    Posts:
    57
  3. alexanderkudryavy

    alexanderkudryavy

    Joined:
    Sep 20, 2019
    Posts:
    13
    Thank you, well I have some progress, it's work if I create in shader graph node with 2d texture, then copy code from it and use it like shader, but how I can get same result with hdrp lit?
     
  4. alexanderkudryavy

    alexanderkudryavy

    Joined:
    Sep 20, 2019
    Posts:
    13
    Code (CSharp):
    1. Shader "Custom/Portal"
    2. {
    3.     SubShader
    4.     {
    5.         Tags
    6.         {
    7.             // RenderPipeline: <None>
    8.             "RenderType"="Opaque"
    9.             "Queue"="Geometry-1"
    10.         }
    11.         ZWrite off
    12.         ColorMask 0
    13.         Cull off
    14.        
    15.         Stencil
    16.         {
    17.             Ref 255
    18.             Comp always
    19.             Pass replace
    20.         }
    21.        
    22.         Pass {
    23.         }
    24.     }
    25. }
    26.  
    and

    Code (CSharp):
    1. Shader "Inside"
    2. {
    3.     Properties
    4.     {
    5.         [NoScaleOffset]_Texture2D("Texture2D", 2D) = "white" {}
    6.     }
    7.     SubShader
    8.     {
    9.         Tags
    10.         {
    11.             // RenderPipeline: <None>
    12.             "RenderType"="Opaque"
    13.             "Queue"="Geometry+255"
    14.         }
    15.        
    16.         Stencil
    17.         {
    18.             Ref 255
    19.             Comp Equal
    20.             Pass Replace
    21.         }
    22.        
    23.         Pass
    24.         {
    25.             // Name: <None>
    26.             Tags
    27.             {
    28.                 // LightMode: <None>
    29.             }
    30.  
    31.             // Render State
    32.             // RenderState: <None>
    33.  
    34.             // Debug
    35.             // <None>
    36.  
    37.             // --------------------------------------------------
    38.             // Pass
    39.  
    40.             HLSLPROGRAM
    41.  
    42.             // Pragmas
    43.             #pragma vertex vert
    44.         #pragma fragment frag
    45.  
    46.             // DotsInstancingOptions: <None>
    47.             // HybridV1InjectedBuiltinProperties: <None>
    48.  
    49.             // Keywords
    50.             // PassKeywords: <None>
    51.             // GraphKeywords: <None>
    52.  
    53.             // Defines
    54.             #define ATTRIBUTES_NEED_TEXCOORD0
    55.             #define VARYINGS_NEED_TEXCOORD0
    56.             /* WARNING: $splice Could not find named fragment 'PassInstancing' */
    57.             #define SHADERPASS SHADERPASS_PREVIEW
    58.         #define SHADERGRAPH_PREVIEW
    59.             /* WARNING: $splice Could not find named fragment 'DotsInstancingVars' */
    60.  
    61.             // Includes
    62.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    63.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl"
    64.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
    65.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
    66.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
    67.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    68.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
    69.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
    70.         #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariables.hlsl"
    71.         #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl"
    72.         #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"
    73.  
    74.             // --------------------------------------------------
    75.             // Structs and Packing
    76.  
    77.             struct Attributes
    78.         {
    79.             float3 positionOS : POSITION;
    80.             float4 uv0 : TEXCOORD0;
    81.             #if UNITY_ANY_INSTANCING_ENABLED
    82.             uint instanceID : INSTANCEID_SEMANTIC;
    83.             #endif
    84.         };
    85.         struct Varyings
    86.         {
    87.             float4 positionCS : SV_POSITION;
    88.             float4 texCoord0;
    89.             #if UNITY_ANY_INSTANCING_ENABLED
    90.             uint instanceID : CUSTOM_INSTANCE_ID;
    91.             #endif
    92.             #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
    93.             FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
    94.             #endif
    95.         };
    96.         struct SurfaceDescriptionInputs
    97.         {
    98.             float4 uv0;
    99.         };
    100.         struct VertexDescriptionInputs
    101.         {
    102.         };
    103.         struct PackedVaryings
    104.         {
    105.             float4 positionCS : SV_POSITION;
    106.             float4 interp0 : TEXCOORD0;
    107.             #if UNITY_ANY_INSTANCING_ENABLED
    108.             uint instanceID : CUSTOM_INSTANCE_ID;
    109.             #endif
    110.             #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
    111.             FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
    112.             #endif
    113.         };
    114.  
    115.             PackedVaryings PackVaryings (Varyings input)
    116.         {
    117.             PackedVaryings output;
    118.             output.positionCS = input.positionCS;
    119.             output.interp0.xyzw =  input.texCoord0;
    120.             #if UNITY_ANY_INSTANCING_ENABLED
    121.             output.instanceID = input.instanceID;
    122.             #endif
    123.             #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
    124.             output.cullFace = input.cullFace;
    125.             #endif
    126.             return output;
    127.         }
    128.         Varyings UnpackVaryings (PackedVaryings input)
    129.         {
    130.             Varyings output;
    131.             output.positionCS = input.positionCS;
    132.             output.texCoord0 = input.interp0.xyzw;
    133.             #if UNITY_ANY_INSTANCING_ENABLED
    134.             output.instanceID = input.instanceID;
    135.             #endif
    136.             #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
    137.             output.cullFace = input.cullFace;
    138.             #endif
    139.             return output;
    140.         }
    141.  
    142.             // --------------------------------------------------
    143.             // Graph
    144.  
    145.             // Graph Properties
    146.             CBUFFER_START(UnityPerMaterial)
    147.         float4 _Texture2D_TexelSize;
    148.         CBUFFER_END
    149.  
    150.         // Object and Global properties
    151.         SAMPLER(SamplerState_Linear_Repeat);
    152.         TEXTURE2D(_Texture2D);
    153.         SAMPLER(sampler_Texture2D);
    154.  
    155.             // Graph Functions
    156.             // GraphFunctions: <None>
    157.  
    158.             // Graph Vertex
    159.             // GraphVertex: <None>
    160.  
    161.             // Graph Pixel
    162.             struct SurfaceDescription
    163.         {
    164.             float4 Out;
    165.         };
    166.  
    167.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    168.         {
    169.             SurfaceDescription surface = (SurfaceDescription)0;
    170.             UnityTexture2D _Property_9a62c2e30e09409e94b1b84543821489_Out_0 = UnityBuildTexture2DStructNoScale(_Texture2D);
    171.             float4 _SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_RGBA_0 = SAMPLE_TEXTURE2D(_Property_9a62c2e30e09409e94b1b84543821489_Out_0.tex, _Property_9a62c2e30e09409e94b1b84543821489_Out_0.samplerstate, IN.uv0.xy);
    172.             float _SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_R_4 = _SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_RGBA_0.r;
    173.             float _SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_G_5 = _SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_RGBA_0.g;
    174.             float _SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_B_6 = _SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_RGBA_0.b;
    175.             float _SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_A_7 = _SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_RGBA_0.a;
    176.             surface.Out = all(isfinite(_SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_RGBA_0)) ? half4(_SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_RGBA_0.x, _SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_RGBA_0.y, _SampleTexture2D_3e8dbfc295154b9fb7c06d6f25abe9b8_RGBA_0.z, 1.0) : float4(1.0f, 0.0f, 1.0f, 1.0f);
    177.             return surface;
    178.         }
    179.  
    180.             // --------------------------------------------------
    181.             // Build Graph Inputs
    182.  
    183.             SurfaceDescriptionInputs BuildSurfaceDescriptionInputs(Varyings input)
    184.         {
    185.             SurfaceDescriptionInputs output;
    186.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    187.  
    188.  
    189.  
    190.  
    191.  
    192.             output.uv0 =                         input.texCoord0;
    193.         #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
    194.         #define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN output.FaceSign =                    IS_FRONT_VFACE(input.cullFace, true, false);
    195.         #else
    196.         #define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
    197.         #endif
    198.         #undef BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
    199.  
    200.             return output;
    201.         }
    202.  
    203.             // --------------------------------------------------
    204.             // Main
    205.  
    206.             #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/PreviewVaryings.hlsl"
    207.         #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/PreviewPass.hlsl"
    208.  
    209.             ENDHLSL
    210.         }
    211.     }
    212.     FallBack "Hidden/Shader Graph/FallbackError"
    213. }
     
  5. alexanderkudryavy

    alexanderkudryavy

    Joined:
    Sep 20, 2019
    Posts:
    13
    Where I need past Stencil in hdrp lit shader?

    Code (CSharp):
    1. Shader "Inside2"
    2. {
    3.     Properties
    4.     {
    5.         [HideInInspector]_EmissionColor("Color", Color) = (1, 1, 1, 1)
    6.         [HideInInspector]_RenderQueueType("Float", Float) = 1
    7.         [HideInInspector][ToggleUI]_AddPrecomputedVelocity("Boolean", Float) = 0
    8.         [HideInInspector][ToggleUI]_DepthOffsetEnable("Boolean", Float) = 0
    9.         [HideInInspector][ToggleUI]_TransparentWritingMotionVec("Boolean", Float) = 0
    10.         [HideInInspector][ToggleUI]_AlphaCutoffEnable("Boolean", Float) = 0
    11.         [HideInInspector]_TransparentSortPriority("_TransparentSortPriority", Float) = 0
    12.         [HideInInspector][ToggleUI]_UseShadowThreshold("Boolean", Float) = 0
    13.         [HideInInspector][ToggleUI]_DoubleSidedEnable("Boolean", Float) = 0
    14.         [HideInInspector][Enum(Flip, 0, Mirror, 1, None, 2)]_DoubleSidedNormalMode("Float", Float) = 2
    15.         [HideInInspector]_DoubleSidedConstants("Vector4", Vector) = (1, 1, -1, 0)
    16.         [HideInInspector][ToggleUI]_TransparentDepthPrepassEnable("Boolean", Float) = 0
    17.         [HideInInspector][ToggleUI]_TransparentDepthPostpassEnable("Boolean", Float) = 0
    18.         [HideInInspector]_SurfaceType("Float", Float) = 0
    19.         [HideInInspector]_BlendMode("Float", Float) = 0
    20.         [HideInInspector]_SrcBlend("Float", Float) = 1
    21.         [HideInInspector]_DstBlend("Float", Float) = 0
    22.         [HideInInspector]_AlphaSrcBlend("Float", Float) = 1
    23.         [HideInInspector]_AlphaDstBlend("Float", Float) = 0
    24.         [HideInInspector][ToggleUI]_AlphaToMask("Boolean", Float) = 0
    25.         [HideInInspector][ToggleUI]_AlphaToMaskInspectorValue("Boolean", Float) = 0
    26.         [HideInInspector][ToggleUI]_ZWrite("Boolean", Float) = 1
    27.         [HideInInspector][ToggleUI]_TransparentZWrite("Boolean", Float) = 0
    28.         [HideInInspector]_CullMode("Float", Float) = 2
    29.         [HideInInspector][ToggleUI]_EnableFogOnTransparent("Boolean", Float) = 1
    30.         [HideInInspector]_CullModeForward("Float", Float) = 2
    31.         [HideInInspector][Enum(Front, 1, Back, 2)]_TransparentCullMode("Float", Float) = 2
    32.         [HideInInspector][Enum(UnityEditor.Rendering.HighDefinition.OpaqueCullMode)]_OpaqueCullMode("Float", Float) = 2
    33.         [HideInInspector]_ZTestDepthEqualForOpaque("Float", Int) = 4
    34.         [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestTransparent("Float", Float) = 4
    35.         [HideInInspector][ToggleUI]_TransparentBackfaceEnable("Boolean", Float) = 0
    36.         [HideInInspector][ToggleUI]_RequireSplitLighting("Boolean", Float) = 0
    37.         [HideInInspector][ToggleUI]_ReceivesSSR("Boolean", Float) = 1
    38.         [HideInInspector][ToggleUI]_ReceivesSSRTransparent("Boolean", Float) = 0
    39.         [HideInInspector][ToggleUI]_EnableBlendModePreserveSpecularLighting("Boolean", Float) = 1
    40.         [HideInInspector][ToggleUI]_SupportDecals("Boolean", Float) = 1
    41.         [HideInInspector]_StencilRef("Float", Int) = 0
    42.         [HideInInspector]_StencilWriteMask("Float", Int) = 6
    43.         [HideInInspector]_StencilRefDepth("Float", Int) = 8
    44.         [HideInInspector]_StencilWriteMaskDepth("Float", Int) = 8
    45.         [HideInInspector]_StencilRefMV("Float", Int) = 40
    46.         [HideInInspector]_StencilWriteMaskMV("Float", Int) = 40
    47.         [HideInInspector]_StencilRefDistortionVec("Float", Int) = 4
    48.         [HideInInspector]_StencilWriteMaskDistortionVec("Float", Int) = 4
    49.         [HideInInspector]_StencilWriteMaskGBuffer("Float", Int) = 14
    50.         [HideInInspector]_StencilRefGBuffer("Float", Int) = 10
    51.         [HideInInspector]_ZTestGBuffer("Float", Int) = 4
    52.         [HideInInspector][ToggleUI]_RayTracing("Boolean", Float) = 0
    53.         [HideInInspector][Enum(None, 0, Box, 1, Sphere, 2, Thin, 3)]_RefractionModel("Float", Float) = 0
    54.         [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
    55.         [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
    56.         [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
    57.     }
    58.     SubShader
    59.     {
    60.         Tags
    61.         {
    62.             "RenderPipeline"="HDRenderPipeline"
    63.             "RenderType"="HDLitShader"
    64.             "Queue"="Geometry+225"
    65.         }
    66.        
    67.         Pass
    68.         {
    69.             Name "ShadowCaster"
    70.             Tags
    71.             {
    72.                 "LightMode" = "ShadowCaster"
    73.             }
    74.  
    75.             // Render State
    76.             Cull [_CullMode]
    77.         ZWrite On
    78.         ColorMask 0
    79.         ZClip [_ZClip]
    80.             // Debug
    81.             // <None>
    82.  
    83.             // --------------------------------------------------
    84.             // Pass
    85.  
    86.             HLSLPROGRAM
    87.  
    88.             // Pragmas
    89.             #pragma target 4.5
    90.         #pragma vertex Vert
    91.         #pragma fragment Frag
    92.         #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
    93.         #pragma multi_compile_instancing
    94.         #pragma instancing_options renderinglayer
    95.  
    96.             // Keywords
    97.             #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    98.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    99.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    100.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    101.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    102.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    103.         #pragma shader_feature_local _ _DISABLE_DECALS
    104.         #pragma shader_feature_local _ _DISABLE_SSR
    105.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    106.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    107.             // GraphKeywords: <None>
    108.  
    109.             // Early Instancing Defines
    110.             // DotsInstancingOptions: <None>
    111.  
    112.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    113.             // HybridV1InjectedBuiltinProperties: <None>
    114.  
    115.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    116.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    117.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    118.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    119.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    120.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    121.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    122.  
    123.             // --------------------------------------------------
    124.             // Defines
    125.  
    126.             // Attribute
    127.             #define ATTRIBUTES_NEED_NORMAL
    128.             #define ATTRIBUTES_NEED_TANGENT
    129.  
    130.             #define HAVE_MESH_MODIFICATION
    131.  
    132.  
    133.             #define SHADERPASS SHADERPASS_SHADOWS
    134.  
    135.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    136.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    137.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    138.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    139.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    140.             #define RAYTRACING_SHADER_GRAPH_HIGH
    141.             #endif
    142.  
    143.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    144.             #define RAYTRACING_SHADER_GRAPH_LOW
    145.             #endif
    146.             // end
    147.  
    148.             #ifndef SHADER_UNLIT
    149.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    150.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    151.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    152.                 #define VARYINGS_NEED_CULLFACE
    153.             #endif
    154.             #endif
    155.  
    156.             // Specific Material Define
    157.         #define _ENERGY_CONSERVING_SPECULAR 1
    158.  
    159.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    160.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    161.             #define OUTPUT_SPLIT_LIGHTING
    162.         #endif
    163.  
    164.         // This shader support recursive rendering for raytracing
    165.         #define HAVE_RECURSIVE_RENDERING
    166.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    167.  
    168.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    169.             // we should have a code like this:
    170.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    171.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    172.             // endif
    173.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    174.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    175.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    176.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    177.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    178.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    179.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    180.                 #define WRITE_NORMAL_BUFFER
    181.             #endif
    182.             #endif
    183.  
    184.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    185.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    186.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    187.             // the constant buffer. A bug is filed and is being looked at.
    188.             #if defined(SHADER_API_VULKAN)
    189.             #define DISABLE_UNLIT_DEEXPOSURE
    190.             #endif
    191.  
    192.             #ifndef DEBUG_DISPLAY
    193.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    194.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    195.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    196.                     #if SHADERPASS == SHADERPASS_FORWARD
    197.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    198.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    199.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    200.                     #endif
    201.                 #endif
    202.             #endif
    203.  
    204.             // Translate transparent motion vector define
    205.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    206.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    207.             #endif
    208.  
    209.             // -- Graph Properties
    210.             CBUFFER_START(UnityPerMaterial)
    211.         float4 _EmissionColor;
    212.         float _UseShadowThreshold;
    213.         float4 _DoubleSidedConstants;
    214.         float _BlendMode;
    215.         float _EnableBlendModePreserveSpecularLighting;
    216.         float _RayTracing;
    217.         float _RefractionModel;
    218.         CBUFFER_END
    219.  
    220.         // Object and Global properties
    221.  
    222.             // -- Property used by ScenePickingPass
    223.             #ifdef SCENEPICKINGPASS
    224.             float4 _SelectionID;
    225.             #endif
    226.  
    227.             // -- Properties used by SceneSelectionPass
    228.             #ifdef SCENESELECTIONPASS
    229.             int _ObjectId;
    230.             int _PassValue;
    231.             #endif
    232.  
    233.             // Includes
    234.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
    235.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    236.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
    237.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    238.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    239.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    240.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
    241.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"
    242.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    243.  
    244.             // --------------------------------------------------
    245.             // Structs and Packing
    246.  
    247.             struct AttributesMesh
    248.         {
    249.             float3 positionOS : POSITION;
    250.             float3 normalOS : NORMAL;
    251.             float4 tangentOS : TANGENT;
    252.             #if UNITY_ANY_INSTANCING_ENABLED
    253.             uint instanceID : INSTANCEID_SEMANTIC;
    254.             #endif
    255.         };
    256.         struct VaryingsMeshToPS
    257.         {
    258.             float4 positionCS : SV_POSITION;
    259.             #if UNITY_ANY_INSTANCING_ENABLED
    260.             uint instanceID : CUSTOM_INSTANCE_ID;
    261.             #endif
    262.         };
    263.         struct SurfaceDescriptionInputs
    264.         {
    265.         };
    266.         struct VertexDescriptionInputs
    267.         {
    268.             float3 ObjectSpaceNormal;
    269.             float3 ObjectSpaceTangent;
    270.             float3 ObjectSpacePosition;
    271.         };
    272.         struct PackedVaryingsMeshToPS
    273.         {
    274.             float4 positionCS : SV_POSITION;
    275.             #if UNITY_ANY_INSTANCING_ENABLED
    276.             uint instanceID : CUSTOM_INSTANCE_ID;
    277.             #endif
    278.         };
    279.  
    280.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    281.         {
    282.             PackedVaryingsMeshToPS output;
    283.             output.positionCS = input.positionCS;
    284.             #if UNITY_ANY_INSTANCING_ENABLED
    285.             output.instanceID = input.instanceID;
    286.             #endif
    287.             return output;
    288.         }
    289.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    290.         {
    291.             VaryingsMeshToPS output;
    292.             output.positionCS = input.positionCS;
    293.             #if UNITY_ANY_INSTANCING_ENABLED
    294.             output.instanceID = input.instanceID;
    295.             #endif
    296.             return output;
    297.         }
    298.  
    299.             // --------------------------------------------------
    300.             // Graph
    301.  
    302.  
    303.             // Graph Functions
    304.             // GraphFunctions: <None>
    305.  
    306.             // Graph Vertex
    307.             struct VertexDescription
    308.         {
    309.             float3 Position;
    310.             float3 Normal;
    311.             float3 Tangent;
    312.         };
    313.  
    314.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    315.         {
    316.             VertexDescription description = (VertexDescription)0;
    317.             description.Position = IN.ObjectSpacePosition;
    318.             description.Normal = IN.ObjectSpaceNormal;
    319.             description.Tangent = IN.ObjectSpaceTangent;
    320.             return description;
    321.         }
    322.  
    323.             // Graph Pixel
    324.             struct SurfaceDescription
    325.         {
    326.             float Alpha;
    327.         };
    328.  
    329.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    330.         {
    331.             SurfaceDescription surface = (SurfaceDescription)0;
    332.             surface.Alpha = 1;
    333.             return surface;
    334.         }
    335.  
    336.             // --------------------------------------------------
    337.             // Build Graph Inputs
    338.  
    339.            
    340.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    341.         {
    342.             VertexDescriptionInputs output;
    343.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    344.  
    345.             output.ObjectSpaceNormal =           input.normalOS;
    346.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    347.             output.ObjectSpacePosition =         input.positionOS;
    348.  
    349.             return output;
    350.         }
    351.  
    352.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    353.         {
    354.             // build graph inputs
    355.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    356.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    357.  
    358.             // evaluate vertex graph
    359.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    360.  
    361.             // copy graph output to the results
    362.             input.positionOS = vertexDescription.Position;
    363.             input.normalOS = vertexDescription.Normal;
    364.             input.tangentOS.xyz = vertexDescription.Tangent;
    365.  
    366.             return input;
    367.         }
    368.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    369.         {
    370.             FragInputs output;
    371.             ZERO_INITIALIZE(FragInputs, output);
    372.  
    373.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    374.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    375.             // to compute normals which are then passed on elsewhere to compute other values...
    376.             output.tangentToWorld = k_identity3x3;
    377.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    378.  
    379.  
    380.             return output;
    381.         }
    382.  
    383.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    384.         {
    385.             SurfaceDescriptionInputs output;
    386.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    387.  
    388.             #if defined(SHADER_STAGE_RAY_TRACING)
    389.             #else
    390.             #endif
    391.  
    392.             return output;
    393.         }
    394.  
    395.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    396.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    397.         {
    398.             UNITY_SETUP_INSTANCE_ID(input);
    399.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    400.             return BuildFragInputs(unpacked);
    401.         }
    402.  
    403.             // --------------------------------------------------
    404.             // Build Surface Data (Specific Material)
    405.  
    406.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    407.         {
    408.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    409.  
    410.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    411.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    412.             surfaceData.specularOcclusion = 1.0;
    413.  
    414.  
    415.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    416.                 if (_EnableSSRefraction)
    417.                 {
    418.  
    419.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    420.                     surfaceDescription.Alpha = 1.0;
    421.                 }
    422.                 else
    423.                 {
    424.                     surfaceData.ior = 1.0;
    425.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    426.                     surfaceData.atDistance = 1.0;
    427.                     surfaceData.transmittanceMask = 0.0;
    428.                     surfaceDescription.Alpha = 1.0;
    429.                 }
    430.             #else
    431.                 surfaceData.ior = 1.0;
    432.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    433.                 surfaceData.atDistance = 1.0;
    434.                 surfaceData.transmittanceMask = 0.0;
    435.             #endif
    436.  
    437.             // These static material feature allow compile time optimization
    438.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    439.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    440.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    441.             #endif
    442.  
    443.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    444.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    445.             #endif
    446.  
    447.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    448.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    449.             #endif
    450.  
    451.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    452.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    453.             #endif
    454.  
    455.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    456.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    457.             #endif
    458.  
    459.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    460.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    461.             #endif
    462.  
    463.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    464.                 // Require to have setup baseColor
    465.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    466.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    467.             #endif
    468.  
    469.             #ifdef _DOUBLESIDED_ON
    470.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    471.             #else
    472.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    473.             #endif
    474.  
    475.             // normal delivered to master node
    476.  
    477.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    478.  
    479.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    480.  
    481.  
    482.             #if HAVE_DECALS
    483.                 if (_EnableDecals)
    484.                 {
    485.                     float alpha = 1.0;
    486.                     alpha = surfaceDescription.Alpha;
    487.  
    488.                     // Both uses and modifies 'surfaceData.normalWS'.
    489.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    490.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    491.                 }
    492.             #endif
    493.  
    494.             bentNormalWS = surfaceData.normalWS;
    495.  
    496.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    497.  
    498.             #ifdef DEBUG_DISPLAY
    499.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    500.                 {
    501.                     // TODO: need to update mip info
    502.                     surfaceData.metallic = 0;
    503.                 }
    504.  
    505.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    506.                 // as it can modify attribute use for static lighting
    507.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    508.             #endif
    509.  
    510.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    511.             // If user provide bent normal then we process a better term
    512.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    513.                 // Just use the value passed through via the slot (not active otherwise)
    514.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    515.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    516.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    517.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    518.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    519.             #endif
    520.  
    521.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    522.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    523.             #endif
    524.         }
    525.  
    526.             // --------------------------------------------------
    527.             // Get Surface And BuiltinData
    528.  
    529.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    530.             {
    531.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    532.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    533.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    534.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    535.                 #endif
    536.                 #endif
    537.  
    538.                 #ifndef SHADER_UNLIT
    539.                 #ifdef _DOUBLESIDED_ON
    540.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    541.                 #else
    542.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    543.                 #endif
    544.  
    545.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    546.                 #endif // SHADER_UNLIT
    547.  
    548.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    549.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    550.  
    551.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    552.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    553.                 #ifdef _ALPHATEST_ON
    554.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    555.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    556.                     // The TransparentDepthPrepass is also used with SSR transparent.
    557.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    558.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    559.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    560.                     // DepthPostpass always use its own alpha threshold
    561.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    562.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    563.                     // If use shadow threshold isn't enable we don't allow any test
    564.                     #endif
    565.  
    566.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    567.                 #endif
    568.  
    569.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    570.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    571.                 #endif
    572.  
    573.                 #ifndef SHADER_UNLIT
    574.                 float3 bentNormalWS;
    575.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    576.  
    577.                 // Builtin Data
    578.                 // For back lighting we use the oposite vertex normal
    579.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    580.  
    581.                 #else
    582.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    583.  
    584.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    585.                 builtinData.opacity = surfaceDescription.Alpha;
    586.  
    587.                 #if defined(DEBUG_DISPLAY)
    588.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    589.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    590.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    591.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    592.                 #endif
    593.  
    594.                 #endif // SHADER_UNLIT
    595.  
    596.                 #ifdef _ALPHATEST_ON
    597.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    598.                     builtinData.alphaClipTreshold = alphaCutoff;
    599.                 #endif
    600.  
    601.                 // override sampleBakedGI - not used by Unlit
    602.  
    603.  
    604.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    605.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    606.                 // This is a limitation of the current MRT approach.
    607.  
    608.                 #if _DEPTHOFFSET_ON
    609.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    610.                 #endif
    611.  
    612.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    613.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    614.                 builtinData.distortion = surfaceDescription.Distortion;
    615.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    616.                 #endif
    617.  
    618.                 #ifndef SHADER_UNLIT
    619.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    620.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    621.                 #else
    622.                 ApplyDebugToBuiltinData(builtinData);
    623.                 #endif
    624.  
    625.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    626.             }
    627.  
    628.             // --------------------------------------------------
    629.             // Main
    630.  
    631.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"
    632.  
    633.             ENDHLSL
    634.         }
    635.         Pass
    636.         {
    637.             Name "META"
    638.             Tags
    639.             {
    640.                 "LightMode" = "META"
    641.             }
    642.  
    643.             // Render State
    644.             Cull Off
    645.  
    646.             // Debug
    647.             // <None>
    648.  
    649.             // --------------------------------------------------
    650.             // Pass
    651.  
    652.             HLSLPROGRAM
    653.  
    654.             // Pragmas
    655.             #pragma target 4.5
    656.         #pragma vertex Vert
    657.         #pragma fragment Frag
    658.         #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
    659.         #pragma multi_compile_instancing
    660.         #pragma instancing_options renderinglayer
    661.  
    662.             // Keywords
    663.             #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    664.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    665.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    666.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    667.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    668.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    669.         #pragma shader_feature_local _ _DISABLE_DECALS
    670.         #pragma shader_feature_local _ _DISABLE_SSR
    671.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    672.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    673.             // GraphKeywords: <None>
    674.  
    675.             // Early Instancing Defines
    676.             // DotsInstancingOptions: <None>
    677.  
    678.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    679.             // HybridV1InjectedBuiltinProperties: <None>
    680.  
    681.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    682.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    683.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    684.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    685.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    686.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    687.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    688.  
    689.             // --------------------------------------------------
    690.             // Defines
    691.  
    692.             // Attribute
    693.             #define ATTRIBUTES_NEED_NORMAL
    694.             #define ATTRIBUTES_NEED_TANGENT
    695.             #define ATTRIBUTES_NEED_TEXCOORD0
    696.             #define ATTRIBUTES_NEED_TEXCOORD1
    697.             #define ATTRIBUTES_NEED_TEXCOORD2
    698.             #define ATTRIBUTES_NEED_COLOR
    699.  
    700.             #define HAVE_MESH_MODIFICATION
    701.  
    702.  
    703.             #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT
    704.         #define RAYTRACING_SHADER_GRAPH_DEFAULT
    705.  
    706.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    707.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    708.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    709.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    710.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    711.             #define RAYTRACING_SHADER_GRAPH_HIGH
    712.             #endif
    713.  
    714.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    715.             #define RAYTRACING_SHADER_GRAPH_LOW
    716.             #endif
    717.             // end
    718.  
    719.             #ifndef SHADER_UNLIT
    720.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    721.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    722.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    723.                 #define VARYINGS_NEED_CULLFACE
    724.             #endif
    725.             #endif
    726.  
    727.             // Specific Material Define
    728.         #define _ENERGY_CONSERVING_SPECULAR 1
    729.  
    730.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    731.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    732.             #define OUTPUT_SPLIT_LIGHTING
    733.         #endif
    734.  
    735.         // This shader support recursive rendering for raytracing
    736.         #define HAVE_RECURSIVE_RENDERING
    737.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    738.  
    739.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    740.             // we should have a code like this:
    741.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    742.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    743.             // endif
    744.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    745.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    746.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    747.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    748.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    749.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    750.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    751.                 #define WRITE_NORMAL_BUFFER
    752.             #endif
    753.             #endif
    754.  
    755.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    756.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    757.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    758.             // the constant buffer. A bug is filed and is being looked at.
    759.             #if defined(SHADER_API_VULKAN)
    760.             #define DISABLE_UNLIT_DEEXPOSURE
    761.             #endif
    762.  
    763.             #ifndef DEBUG_DISPLAY
    764.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    765.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    766.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    767.                     #if SHADERPASS == SHADERPASS_FORWARD
    768.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    769.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    770.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    771.                     #endif
    772.                 #endif
    773.             #endif
    774.  
    775.             // Translate transparent motion vector define
    776.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    777.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    778.             #endif
    779.  
    780.             // -- Graph Properties
    781.             CBUFFER_START(UnityPerMaterial)
    782.         float4 _EmissionColor;
    783.         float _UseShadowThreshold;
    784.         float4 _DoubleSidedConstants;
    785.         float _BlendMode;
    786.         float _EnableBlendModePreserveSpecularLighting;
    787.         float _RayTracing;
    788.         float _RefractionModel;
    789.         CBUFFER_END
    790.  
    791.         // Object and Global properties
    792.  
    793.             // -- Property used by ScenePickingPass
    794.             #ifdef SCENEPICKINGPASS
    795.             float4 _SelectionID;
    796.             #endif
    797.  
    798.             // -- Properties used by SceneSelectionPass
    799.             #ifdef SCENESELECTIONPASS
    800.             int _ObjectId;
    801.             int _PassValue;
    802.             #endif
    803.  
    804.             // Includes
    805.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
    806.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    807.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
    808.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    809.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    810.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    811.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
    812.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"
    813.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    814.  
    815.             // --------------------------------------------------
    816.             // Structs and Packing
    817.  
    818.             struct AttributesMesh
    819.         {
    820.             float3 positionOS : POSITION;
    821.             float3 normalOS : NORMAL;
    822.             float4 tangentOS : TANGENT;
    823.             float4 uv0 : TEXCOORD0;
    824.             float4 uv1 : TEXCOORD1;
    825.             float4 uv2 : TEXCOORD2;
    826.             float4 color : COLOR;
    827.             #if UNITY_ANY_INSTANCING_ENABLED
    828.             uint instanceID : INSTANCEID_SEMANTIC;
    829.             #endif
    830.         };
    831.         struct VaryingsMeshToPS
    832.         {
    833.             float4 positionCS : SV_POSITION;
    834.             #if UNITY_ANY_INSTANCING_ENABLED
    835.             uint instanceID : CUSTOM_INSTANCE_ID;
    836.             #endif
    837.         };
    838.         struct SurfaceDescriptionInputs
    839.         {
    840.             float3 TangentSpaceNormal;
    841.         };
    842.         struct VertexDescriptionInputs
    843.         {
    844.         };
    845.         struct PackedVaryingsMeshToPS
    846.         {
    847.             float4 positionCS : SV_POSITION;
    848.             #if UNITY_ANY_INSTANCING_ENABLED
    849.             uint instanceID : CUSTOM_INSTANCE_ID;
    850.             #endif
    851.         };
    852.  
    853.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    854.         {
    855.             PackedVaryingsMeshToPS output;
    856.             output.positionCS = input.positionCS;
    857.             #if UNITY_ANY_INSTANCING_ENABLED
    858.             output.instanceID = input.instanceID;
    859.             #endif
    860.             return output;
    861.         }
    862.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    863.         {
    864.             VaryingsMeshToPS output;
    865.             output.positionCS = input.positionCS;
    866.             #if UNITY_ANY_INSTANCING_ENABLED
    867.             output.instanceID = input.instanceID;
    868.             #endif
    869.             return output;
    870.         }
    871.  
    872.             // --------------------------------------------------
    873.             // Graph
    874.  
    875.  
    876.             // Graph Functions
    877.             // GraphFunctions: <None>
    878.  
    879.             // Graph Vertex
    880.             struct VertexDescription
    881.         {
    882.         };
    883.  
    884.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    885.         {
    886.             VertexDescription description = (VertexDescription)0;
    887.             return description;
    888.         }
    889.  
    890.             // Graph Pixel
    891.             struct SurfaceDescription
    892.         {
    893.             float3 BaseColor;
    894.             float3 Emission;
    895.             float Alpha;
    896.             float3 BentNormal;
    897.             float Smoothness;
    898.             float Occlusion;
    899.             float3 NormalTS;
    900.             float Metallic;
    901.         };
    902.  
    903.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    904.         {
    905.             SurfaceDescription surface = (SurfaceDescription)0;
    906.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    907.             surface.Emission = float3(0, 0, 0);
    908.             surface.Alpha = 1;
    909.             surface.BentNormal = IN.TangentSpaceNormal;
    910.             surface.Smoothness = 0.5;
    911.             surface.Occlusion = 1;
    912.             surface.NormalTS = IN.TangentSpaceNormal;
    913.             surface.Metallic = 0;
    914.             return surface;
    915.         }
    916.  
    917.             // --------------------------------------------------
    918.             // Build Graph Inputs
    919.  
    920.            
    921.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    922.         {
    923.             VertexDescriptionInputs output;
    924.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    925.  
    926.  
    927.             return output;
    928.         }
    929.  
    930.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    931.         {
    932.             // build graph inputs
    933.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    934.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    935.  
    936.             // evaluate vertex graph
    937.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    938.  
    939.             // copy graph output to the results
    940.  
    941.             return input;
    942.         }
    943.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    944.         {
    945.             FragInputs output;
    946.             ZERO_INITIALIZE(FragInputs, output);
    947.  
    948.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    949.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    950.             // to compute normals which are then passed on elsewhere to compute other values...
    951.             output.tangentToWorld = k_identity3x3;
    952.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    953.  
    954.  
    955.             return output;
    956.         }
    957.  
    958.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    959.         {
    960.             SurfaceDescriptionInputs output;
    961.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    962.  
    963.             #if defined(SHADER_STAGE_RAY_TRACING)
    964.             #else
    965.             #endif
    966.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    967.  
    968.             return output;
    969.         }
    970.  
    971.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    972.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    973.         {
    974.             UNITY_SETUP_INSTANCE_ID(input);
    975.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    976.             return BuildFragInputs(unpacked);
    977.         }
    978.  
    979.             // --------------------------------------------------
    980.             // Build Surface Data (Specific Material)
    981.  
    982.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    983.         {
    984.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    985.  
    986.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    987.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    988.             surfaceData.specularOcclusion = 1.0;
    989.  
    990.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    991.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    992.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    993.             surfaceData.metallic =                  surfaceDescription.Metallic;
    994.  
    995.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    996.                 if (_EnableSSRefraction)
    997.                 {
    998.  
    999.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    1000.                     surfaceDescription.Alpha = 1.0;
    1001.                 }
    1002.                 else
    1003.                 {
    1004.                     surfaceData.ior = 1.0;
    1005.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    1006.                     surfaceData.atDistance = 1.0;
    1007.                     surfaceData.transmittanceMask = 0.0;
    1008.                     surfaceDescription.Alpha = 1.0;
    1009.                 }
    1010.             #else
    1011.                 surfaceData.ior = 1.0;
    1012.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    1013.                 surfaceData.atDistance = 1.0;
    1014.                 surfaceData.transmittanceMask = 0.0;
    1015.             #endif
    1016.  
    1017.             // These static material feature allow compile time optimization
    1018.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    1019.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    1020.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    1021.             #endif
    1022.  
    1023.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    1024.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    1025.             #endif
    1026.  
    1027.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    1028.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    1029.             #endif
    1030.  
    1031.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    1032.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    1033.             #endif
    1034.  
    1035.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    1036.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    1037.             #endif
    1038.  
    1039.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    1040.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    1041.             #endif
    1042.  
    1043.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    1044.                 // Require to have setup baseColor
    1045.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    1046.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    1047.             #endif
    1048.  
    1049.             #ifdef _DOUBLESIDED_ON
    1050.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    1051.             #else
    1052.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    1053.             #endif
    1054.  
    1055.             // normal delivered to master node
    1056.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    1057.  
    1058.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    1059.  
    1060.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    1061.  
    1062.  
    1063.             #if HAVE_DECALS
    1064.                 if (_EnableDecals)
    1065.                 {
    1066.                     float alpha = 1.0;
    1067.                     alpha = surfaceDescription.Alpha;
    1068.  
    1069.                     // Both uses and modifies 'surfaceData.normalWS'.
    1070.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    1071.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    1072.                 }
    1073.             #endif
    1074.  
    1075.             bentNormalWS = surfaceData.normalWS;
    1076.  
    1077.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    1078.  
    1079.             #ifdef DEBUG_DISPLAY
    1080.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    1081.                 {
    1082.                     // TODO: need to update mip info
    1083.                     surfaceData.metallic = 0;
    1084.                 }
    1085.  
    1086.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    1087.                 // as it can modify attribute use for static lighting
    1088.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    1089.             #endif
    1090.  
    1091.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    1092.             // If user provide bent normal then we process a better term
    1093.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    1094.                 // Just use the value passed through via the slot (not active otherwise)
    1095.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    1096.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    1097.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    1098.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    1099.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    1100.             #endif
    1101.  
    1102.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    1103.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    1104.             #endif
    1105.         }
    1106.  
    1107.             // --------------------------------------------------
    1108.             // Get Surface And BuiltinData
    1109.  
    1110.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    1111.             {
    1112.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    1113.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    1114.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    1115.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    1116.                 #endif
    1117.                 #endif
    1118.  
    1119.                 #ifndef SHADER_UNLIT
    1120.                 #ifdef _DOUBLESIDED_ON
    1121.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    1122.                 #else
    1123.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    1124.                 #endif
    1125.  
    1126.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    1127.                 #endif // SHADER_UNLIT
    1128.  
    1129.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    1130.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    1131.  
    1132.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    1133.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    1134.                 #ifdef _ALPHATEST_ON
    1135.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    1136.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    1137.                     // The TransparentDepthPrepass is also used with SSR transparent.
    1138.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    1139.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    1140.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    1141.                     // DepthPostpass always use its own alpha threshold
    1142.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    1143.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    1144.                     // If use shadow threshold isn't enable we don't allow any test
    1145.                     #endif
    1146.  
    1147.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    1148.                 #endif
    1149.  
    1150.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    1151.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    1152.                 #endif
    1153.  
    1154.                 #ifndef SHADER_UNLIT
    1155.                 float3 bentNormalWS;
    1156.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    1157.  
    1158.                 // Builtin Data
    1159.                 // For back lighting we use the oposite vertex normal
    1160.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    1161.  
    1162.                 #else
    1163.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    1164.  
    1165.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    1166.                 builtinData.opacity = surfaceDescription.Alpha;
    1167.  
    1168.                 #if defined(DEBUG_DISPLAY)
    1169.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    1170.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    1171.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    1172.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    1173.                 #endif
    1174.  
    1175.                 #endif // SHADER_UNLIT
    1176.  
    1177.                 #ifdef _ALPHATEST_ON
    1178.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    1179.                     builtinData.alphaClipTreshold = alphaCutoff;
    1180.                 #endif
    1181.  
    1182.                 // override sampleBakedGI - not used by Unlit
    1183.  
    1184.                 builtinData.emissiveColor = surfaceDescription.Emission;
    1185.  
    1186.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    1187.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    1188.                 // This is a limitation of the current MRT approach.
    1189.  
    1190.                 #if _DEPTHOFFSET_ON
    1191.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    1192.                 #endif
    1193.  
    1194.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    1195.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    1196.                 builtinData.distortion = surfaceDescription.Distortion;
    1197.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    1198.                 #endif
    1199.  
    1200.                 #ifndef SHADER_UNLIT
    1201.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    1202.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    1203.                 #else
    1204.                 ApplyDebugToBuiltinData(builtinData);
    1205.                 #endif
    1206.  
    1207.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    1208.             }
    1209.  
    1210.             // --------------------------------------------------
    1211.             // Main
    1212.  
    1213.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl"
    1214.  
    1215.             ENDHLSL
    1216.         }
    1217.         Pass
    1218.         {
    1219.             Name "ScenePickingPass"
    1220.             Tags
    1221.             {
    1222.                 "LightMode" = "Picking"
    1223.             }
    1224.  
    1225.             // Render State
    1226.             Cull [_CullMode]
    1227.  
    1228.             // Debug
    1229.             // <None>
    1230.  
    1231.             // --------------------------------------------------
    1232.             // Pass
    1233.  
    1234.             HLSLPROGRAM
    1235.  
    1236.             // Pragmas
    1237.             #pragma target 4.5
    1238.         #pragma vertex Vert
    1239.         #pragma fragment Frag
    1240.         #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
    1241.         #pragma multi_compile_instancing
    1242.         #pragma editor_sync_compilation
    1243.         #pragma instancing_options renderinglayer
    1244.  
    1245.             // Keywords
    1246.             #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    1247.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    1248.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    1249.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    1250.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    1251.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    1252.         #pragma shader_feature_local _ _DISABLE_DECALS
    1253.         #pragma shader_feature_local _ _DISABLE_SSR
    1254.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    1255.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    1256.             // GraphKeywords: <None>
    1257.  
    1258.             // Early Instancing Defines
    1259.             // DotsInstancingOptions: <None>
    1260.  
    1261.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    1262.             // HybridV1InjectedBuiltinProperties: <None>
    1263.  
    1264.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    1265.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    1266.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    1267.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    1268.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    1269.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    1270.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    1271.  
    1272.             // --------------------------------------------------
    1273.             // Defines
    1274.  
    1275.             // Attribute
    1276.             #define ATTRIBUTES_NEED_NORMAL
    1277.             #define ATTRIBUTES_NEED_TANGENT
    1278.  
    1279.             #define HAVE_MESH_MODIFICATION
    1280.  
    1281.  
    1282.             #define SHADERPASS SHADERPASS_DEPTH_ONLY
    1283.         #define SCENEPICKINGPASS
    1284.  
    1285.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    1286.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    1287.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    1288.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    1289.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    1290.             #define RAYTRACING_SHADER_GRAPH_HIGH
    1291.             #endif
    1292.  
    1293.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    1294.             #define RAYTRACING_SHADER_GRAPH_LOW
    1295.             #endif
    1296.             // end
    1297.  
    1298.             #ifndef SHADER_UNLIT
    1299.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    1300.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    1301.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    1302.                 #define VARYINGS_NEED_CULLFACE
    1303.             #endif
    1304.             #endif
    1305.  
    1306.             // Specific Material Define
    1307.         #define _ENERGY_CONSERVING_SPECULAR 1
    1308.  
    1309.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    1310.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    1311.             #define OUTPUT_SPLIT_LIGHTING
    1312.         #endif
    1313.  
    1314.         // This shader support recursive rendering for raytracing
    1315.         #define HAVE_RECURSIVE_RENDERING
    1316.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    1317.  
    1318.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    1319.             // we should have a code like this:
    1320.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    1321.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    1322.             // endif
    1323.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    1324.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    1325.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    1326.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    1327.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    1328.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    1329.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    1330.                 #define WRITE_NORMAL_BUFFER
    1331.             #endif
    1332.             #endif
    1333.  
    1334.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    1335.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    1336.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    1337.             // the constant buffer. A bug is filed and is being looked at.
    1338.             #if defined(SHADER_API_VULKAN)
    1339.             #define DISABLE_UNLIT_DEEXPOSURE
    1340.             #endif
    1341.  
    1342.             #ifndef DEBUG_DISPLAY
    1343.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    1344.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    1345.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    1346.                     #if SHADERPASS == SHADERPASS_FORWARD
    1347.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    1348.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    1349.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    1350.                     #endif
    1351.                 #endif
    1352.             #endif
    1353.  
    1354.             // Translate transparent motion vector define
    1355.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    1356.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    1357.             #endif
    1358.  
    1359.             // -- Graph Properties
    1360.             CBUFFER_START(UnityPerMaterial)
    1361.         float4 _EmissionColor;
    1362.         float _UseShadowThreshold;
    1363.         float4 _DoubleSidedConstants;
    1364.         float _BlendMode;
    1365.         float _EnableBlendModePreserveSpecularLighting;
    1366.         float _RayTracing;
    1367.         float _RefractionModel;
    1368.         CBUFFER_END
    1369.  
    1370.         // Object and Global properties
    1371.  
    1372.             // -- Property used by ScenePickingPass
    1373.             #ifdef SCENEPICKINGPASS
    1374.             float4 _SelectionID;
    1375.             #endif
    1376.  
    1377.             // -- Properties used by SceneSelectionPass
    1378.             #ifdef SCENESELECTIONPASS
    1379.             int _ObjectId;
    1380.             int _PassValue;
    1381.             #endif
    1382.  
    1383.             // Includes
    1384.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl"
    1385.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
    1386.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    1387.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    1388.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    1389.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    1390.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    1391.  
    1392.             // --------------------------------------------------
    1393.             // Structs and Packing
    1394.  
    1395.             struct AttributesMesh
    1396.         {
    1397.             float3 positionOS : POSITION;
    1398.             float3 normalOS : NORMAL;
    1399.             float4 tangentOS : TANGENT;
    1400.             #if UNITY_ANY_INSTANCING_ENABLED
    1401.             uint instanceID : INSTANCEID_SEMANTIC;
    1402.             #endif
    1403.         };
    1404.         struct VaryingsMeshToPS
    1405.         {
    1406.             float4 positionCS : SV_POSITION;
    1407.             #if UNITY_ANY_INSTANCING_ENABLED
    1408.             uint instanceID : CUSTOM_INSTANCE_ID;
    1409.             #endif
    1410.         };
    1411.         struct SurfaceDescriptionInputs
    1412.         {
    1413.             float3 TangentSpaceNormal;
    1414.         };
    1415.         struct VertexDescriptionInputs
    1416.         {
    1417.             float3 ObjectSpaceNormal;
    1418.             float3 ObjectSpaceTangent;
    1419.             float3 ObjectSpacePosition;
    1420.         };
    1421.         struct PackedVaryingsMeshToPS
    1422.         {
    1423.             float4 positionCS : SV_POSITION;
    1424.             #if UNITY_ANY_INSTANCING_ENABLED
    1425.             uint instanceID : CUSTOM_INSTANCE_ID;
    1426.             #endif
    1427.         };
    1428.  
    1429.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    1430.         {
    1431.             PackedVaryingsMeshToPS output;
    1432.             output.positionCS = input.positionCS;
    1433.             #if UNITY_ANY_INSTANCING_ENABLED
    1434.             output.instanceID = input.instanceID;
    1435.             #endif
    1436.             return output;
    1437.         }
    1438.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    1439.         {
    1440.             VaryingsMeshToPS output;
    1441.             output.positionCS = input.positionCS;
    1442.             #if UNITY_ANY_INSTANCING_ENABLED
    1443.             output.instanceID = input.instanceID;
    1444.             #endif
    1445.             return output;
    1446.         }
    1447.  
    1448.             // --------------------------------------------------
    1449.             // Graph
    1450.  
    1451.  
    1452.             // Graph Functions
    1453.             // GraphFunctions: <None>
    1454.  
    1455.             // Graph Vertex
    1456.             struct VertexDescription
    1457.         {
    1458.             float3 Position;
    1459.             float3 Normal;
    1460.             float3 Tangent;
    1461.         };
    1462.  
    1463.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    1464.         {
    1465.             VertexDescription description = (VertexDescription)0;
    1466.             description.Position = IN.ObjectSpacePosition;
    1467.             description.Normal = IN.ObjectSpaceNormal;
    1468.             description.Tangent = IN.ObjectSpaceTangent;
    1469.             return description;
    1470.         }
    1471.  
    1472.             // Graph Pixel
    1473.             struct SurfaceDescription
    1474.         {
    1475.             float3 BaseColor;
    1476.             float3 Emission;
    1477.             float Alpha;
    1478.             float3 BentNormal;
    1479.             float Smoothness;
    1480.             float Occlusion;
    1481.             float3 NormalTS;
    1482.             float Metallic;
    1483.         };
    1484.  
    1485.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    1486.         {
    1487.             SurfaceDescription surface = (SurfaceDescription)0;
    1488.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    1489.             surface.Emission = float3(0, 0, 0);
    1490.             surface.Alpha = 1;
    1491.             surface.BentNormal = IN.TangentSpaceNormal;
    1492.             surface.Smoothness = 0.5;
    1493.             surface.Occlusion = 1;
    1494.             surface.NormalTS = IN.TangentSpaceNormal;
    1495.             surface.Metallic = 0;
    1496.             return surface;
    1497.         }
    1498.  
    1499.             // --------------------------------------------------
    1500.             // Build Graph Inputs
    1501.  
    1502.            
    1503.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    1504.         {
    1505.             VertexDescriptionInputs output;
    1506.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    1507.  
    1508.             output.ObjectSpaceNormal =           input.normalOS;
    1509.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    1510.             output.ObjectSpacePosition =         input.positionOS;
    1511.  
    1512.             return output;
    1513.         }
    1514.  
    1515.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    1516.         {
    1517.             // build graph inputs
    1518.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    1519.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    1520.  
    1521.             // evaluate vertex graph
    1522.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    1523.  
    1524.             // copy graph output to the results
    1525.             input.positionOS = vertexDescription.Position;
    1526.             input.normalOS = vertexDescription.Normal;
    1527.             input.tangentOS.xyz = vertexDescription.Tangent;
    1528.  
    1529.             return input;
    1530.         }
    1531.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    1532.         {
    1533.             FragInputs output;
    1534.             ZERO_INITIALIZE(FragInputs, output);
    1535.  
    1536.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    1537.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    1538.             // to compute normals which are then passed on elsewhere to compute other values...
    1539.             output.tangentToWorld = k_identity3x3;
    1540.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    1541.  
    1542.  
    1543.             return output;
    1544.         }
    1545.  
    1546.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    1547.         {
    1548.             SurfaceDescriptionInputs output;
    1549.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    1550.  
    1551.             #if defined(SHADER_STAGE_RAY_TRACING)
    1552.             #else
    1553.             #endif
    1554.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    1555.  
    1556.             return output;
    1557.         }
    1558.  
    1559.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    1560.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    1561.         {
    1562.             UNITY_SETUP_INSTANCE_ID(input);
    1563.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    1564.             return BuildFragInputs(unpacked);
    1565.         }
    1566.  
    1567.             // --------------------------------------------------
    1568.             // Build Surface Data (Specific Material)
    1569.  
    1570.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    1571.         {
    1572.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    1573.  
    1574.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    1575.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    1576.             surfaceData.specularOcclusion = 1.0;
    1577.  
    1578.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    1579.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    1580.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    1581.             surfaceData.metallic =                  surfaceDescription.Metallic;
    1582.  
    1583.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    1584.                 if (_EnableSSRefraction)
    1585.                 {
    1586.  
    1587.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    1588.                     surfaceDescription.Alpha = 1.0;
    1589.                 }
    1590.                 else
    1591.                 {
    1592.                     surfaceData.ior = 1.0;
    1593.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    1594.                     surfaceData.atDistance = 1.0;
    1595.                     surfaceData.transmittanceMask = 0.0;
    1596.                     surfaceDescription.Alpha = 1.0;
    1597.                 }
    1598.             #else
    1599.                 surfaceData.ior = 1.0;
    1600.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    1601.                 surfaceData.atDistance = 1.0;
    1602.                 surfaceData.transmittanceMask = 0.0;
    1603.             #endif
    1604.  
    1605.             // These static material feature allow compile time optimization
    1606.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    1607.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    1608.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    1609.             #endif
    1610.  
    1611.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    1612.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    1613.             #endif
    1614.  
    1615.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    1616.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    1617.             #endif
    1618.  
    1619.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    1620.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    1621.             #endif
    1622.  
    1623.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    1624.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    1625.             #endif
    1626.  
    1627.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    1628.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    1629.             #endif
    1630.  
    1631.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    1632.                 // Require to have setup baseColor
    1633.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    1634.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    1635.             #endif
    1636.  
    1637.             #ifdef _DOUBLESIDED_ON
    1638.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    1639.             #else
    1640.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    1641.             #endif
    1642.  
    1643.             // normal delivered to master node
    1644.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    1645.  
    1646.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    1647.  
    1648.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    1649.  
    1650.  
    1651.             #if HAVE_DECALS
    1652.                 if (_EnableDecals)
    1653.                 {
    1654.                     float alpha = 1.0;
    1655.                     alpha = surfaceDescription.Alpha;
    1656.  
    1657.                     // Both uses and modifies 'surfaceData.normalWS'.
    1658.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    1659.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    1660.                 }
    1661.             #endif
    1662.  
    1663.             bentNormalWS = surfaceData.normalWS;
    1664.  
    1665.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    1666.  
    1667.             #ifdef DEBUG_DISPLAY
    1668.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    1669.                 {
    1670.                     // TODO: need to update mip info
    1671.                     surfaceData.metallic = 0;
    1672.                 }
    1673.  
    1674.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    1675.                 // as it can modify attribute use for static lighting
    1676.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    1677.             #endif
    1678.  
    1679.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    1680.             // If user provide bent normal then we process a better term
    1681.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    1682.                 // Just use the value passed through via the slot (not active otherwise)
    1683.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    1684.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    1685.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    1686.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    1687.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    1688.             #endif
    1689.  
    1690.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    1691.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    1692.             #endif
    1693.         }
    1694.  
    1695.             // --------------------------------------------------
    1696.             // Get Surface And BuiltinData
    1697.  
    1698.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    1699.             {
    1700.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    1701.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    1702.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    1703.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    1704.                 #endif
    1705.                 #endif
    1706.  
    1707.                 #ifndef SHADER_UNLIT
    1708.                 #ifdef _DOUBLESIDED_ON
    1709.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    1710.                 #else
    1711.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    1712.                 #endif
    1713.  
    1714.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    1715.                 #endif // SHADER_UNLIT
    1716.  
    1717.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    1718.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    1719.  
    1720.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    1721.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    1722.                 #ifdef _ALPHATEST_ON
    1723.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    1724.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    1725.                     // The TransparentDepthPrepass is also used with SSR transparent.
    1726.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    1727.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    1728.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    1729.                     // DepthPostpass always use its own alpha threshold
    1730.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    1731.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    1732.                     // If use shadow threshold isn't enable we don't allow any test
    1733.                     #endif
    1734.  
    1735.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    1736.                 #endif
    1737.  
    1738.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    1739.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    1740.                 #endif
    1741.  
    1742.                 #ifndef SHADER_UNLIT
    1743.                 float3 bentNormalWS;
    1744.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    1745.  
    1746.                 // Builtin Data
    1747.                 // For back lighting we use the oposite vertex normal
    1748.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    1749.  
    1750.                 #else
    1751.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    1752.  
    1753.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    1754.                 builtinData.opacity = surfaceDescription.Alpha;
    1755.  
    1756.                 #if defined(DEBUG_DISPLAY)
    1757.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    1758.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    1759.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    1760.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    1761.                 #endif
    1762.  
    1763.                 #endif // SHADER_UNLIT
    1764.  
    1765.                 #ifdef _ALPHATEST_ON
    1766.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    1767.                     builtinData.alphaClipTreshold = alphaCutoff;
    1768.                 #endif
    1769.  
    1770.                 // override sampleBakedGI - not used by Unlit
    1771.  
    1772.                 builtinData.emissiveColor = surfaceDescription.Emission;
    1773.  
    1774.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    1775.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    1776.                 // This is a limitation of the current MRT approach.
    1777.  
    1778.                 #if _DEPTHOFFSET_ON
    1779.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    1780.                 #endif
    1781.  
    1782.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    1783.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    1784.                 builtinData.distortion = surfaceDescription.Distortion;
    1785.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    1786.                 #endif
    1787.  
    1788.                 #ifndef SHADER_UNLIT
    1789.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    1790.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    1791.                 #else
    1792.                 ApplyDebugToBuiltinData(builtinData);
    1793.                 #endif
    1794.  
    1795.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    1796.             }
    1797.  
    1798.             // --------------------------------------------------
    1799.             // Main
    1800.  
    1801.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"
    1802.  
    1803.             ENDHLSL
    1804.         }
    1805.         Pass
    1806.         {
    1807.             Name "SceneSelectionPass"
    1808.             Tags
    1809.             {
    1810.                 "LightMode" = "SceneSelectionPass"
    1811.             }
    1812.  
    1813.             // Render State
    1814.             Cull Off
    1815.  
    1816.             // Debug
    1817.             // <None>
    1818.  
    1819.             // --------------------------------------------------
    1820.             // Pass
    1821.  
    1822.             HLSLPROGRAM
    1823.  
    1824.             // Pragmas
    1825.             #pragma target 4.5
    1826.         #pragma vertex Vert
    1827.         #pragma fragment Frag
    1828.         #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
    1829.         #pragma multi_compile_instancing
    1830.         #pragma editor_sync_compilation
    1831.         #pragma instancing_options renderinglayer
    1832.  
    1833.             // Keywords
    1834.             #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    1835.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    1836.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    1837.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    1838.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    1839.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    1840.         #pragma shader_feature_local _ _DISABLE_DECALS
    1841.         #pragma shader_feature_local _ _DISABLE_SSR
    1842.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    1843.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    1844.             // GraphKeywords: <None>
    1845.  
    1846.             // Early Instancing Defines
    1847.             // DotsInstancingOptions: <None>
    1848.  
    1849.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    1850.             // HybridV1InjectedBuiltinProperties: <None>
    1851.  
    1852.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    1853.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    1854.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    1855.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    1856.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    1857.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    1858.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    1859.  
    1860.             // --------------------------------------------------
    1861.             // Defines
    1862.  
    1863.             // Attribute
    1864.             #define ATTRIBUTES_NEED_NORMAL
    1865.             #define ATTRIBUTES_NEED_TANGENT
    1866.  
    1867.             #define HAVE_MESH_MODIFICATION
    1868.  
    1869.  
    1870.             #define SHADERPASS SHADERPASS_DEPTH_ONLY
    1871.         #define RAYTRACING_SHADER_GRAPH_DEFAULT
    1872.         #define SCENESELECTIONPASS
    1873.  
    1874.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    1875.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    1876.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    1877.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    1878.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    1879.             #define RAYTRACING_SHADER_GRAPH_HIGH
    1880.             #endif
    1881.  
    1882.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    1883.             #define RAYTRACING_SHADER_GRAPH_LOW
    1884.             #endif
    1885.             // end
    1886.  
    1887.             #ifndef SHADER_UNLIT
    1888.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    1889.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    1890.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    1891.                 #define VARYINGS_NEED_CULLFACE
    1892.             #endif
    1893.             #endif
    1894.  
    1895.             // Specific Material Define
    1896.         #define _ENERGY_CONSERVING_SPECULAR 1
    1897.  
    1898.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    1899.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    1900.             #define OUTPUT_SPLIT_LIGHTING
    1901.         #endif
    1902.  
    1903.         // This shader support recursive rendering for raytracing
    1904.         #define HAVE_RECURSIVE_RENDERING
    1905.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    1906.  
    1907.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    1908.             // we should have a code like this:
    1909.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    1910.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    1911.             // endif
    1912.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    1913.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    1914.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    1915.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    1916.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    1917.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    1918.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    1919.                 #define WRITE_NORMAL_BUFFER
    1920.             #endif
    1921.             #endif
    1922.  
    1923.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    1924.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    1925.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    1926.             // the constant buffer. A bug is filed and is being looked at.
    1927.             #if defined(SHADER_API_VULKAN)
    1928.             #define DISABLE_UNLIT_DEEXPOSURE
    1929.             #endif
    1930.  
    1931.             #ifndef DEBUG_DISPLAY
    1932.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    1933.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    1934.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    1935.                     #if SHADERPASS == SHADERPASS_FORWARD
    1936.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    1937.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    1938.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    1939.                     #endif
    1940.                 #endif
    1941.             #endif
    1942.  
    1943.             // Translate transparent motion vector define
    1944.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    1945.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    1946.             #endif
    1947.  
    1948.             // -- Graph Properties
    1949.             CBUFFER_START(UnityPerMaterial)
    1950.         float4 _EmissionColor;
    1951.         float _UseShadowThreshold;
    1952.         float4 _DoubleSidedConstants;
    1953.         float _BlendMode;
    1954.         float _EnableBlendModePreserveSpecularLighting;
    1955.         float _RayTracing;
    1956.         float _RefractionModel;
    1957.         CBUFFER_END
    1958.  
    1959.         // Object and Global properties
    1960.  
    1961.             // -- Property used by ScenePickingPass
    1962.             #ifdef SCENEPICKINGPASS
    1963.             float4 _SelectionID;
    1964.             #endif
    1965.  
    1966.             // -- Properties used by SceneSelectionPass
    1967.             #ifdef SCENESELECTIONPASS
    1968.             int _ObjectId;
    1969.             int _PassValue;
    1970.             #endif
    1971.  
    1972.             // Includes
    1973.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
    1974.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    1975.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
    1976.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    1977.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    1978.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    1979.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
    1980.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"
    1981.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    1982.  
    1983.             // --------------------------------------------------
    1984.             // Structs and Packing
    1985.  
    1986.             struct AttributesMesh
    1987.         {
    1988.             float3 positionOS : POSITION;
    1989.             float3 normalOS : NORMAL;
    1990.             float4 tangentOS : TANGENT;
    1991.             #if UNITY_ANY_INSTANCING_ENABLED
    1992.             uint instanceID : INSTANCEID_SEMANTIC;
    1993.             #endif
    1994.         };
    1995.         struct VaryingsMeshToPS
    1996.         {
    1997.             float4 positionCS : SV_POSITION;
    1998.             #if UNITY_ANY_INSTANCING_ENABLED
    1999.             uint instanceID : CUSTOM_INSTANCE_ID;
    2000.             #endif
    2001.         };
    2002.         struct SurfaceDescriptionInputs
    2003.         {
    2004.             float3 TangentSpaceNormal;
    2005.         };
    2006.         struct VertexDescriptionInputs
    2007.         {
    2008.             float3 ObjectSpaceNormal;
    2009.             float3 ObjectSpaceTangent;
    2010.             float3 ObjectSpacePosition;
    2011.         };
    2012.         struct PackedVaryingsMeshToPS
    2013.         {
    2014.             float4 positionCS : SV_POSITION;
    2015.             #if UNITY_ANY_INSTANCING_ENABLED
    2016.             uint instanceID : CUSTOM_INSTANCE_ID;
    2017.             #endif
    2018.         };
    2019.  
    2020.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    2021.         {
    2022.             PackedVaryingsMeshToPS output;
    2023.             output.positionCS = input.positionCS;
    2024.             #if UNITY_ANY_INSTANCING_ENABLED
    2025.             output.instanceID = input.instanceID;
    2026.             #endif
    2027.             return output;
    2028.         }
    2029.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    2030.         {
    2031.             VaryingsMeshToPS output;
    2032.             output.positionCS = input.positionCS;
    2033.             #if UNITY_ANY_INSTANCING_ENABLED
    2034.             output.instanceID = input.instanceID;
    2035.             #endif
    2036.             return output;
    2037.         }
    2038.  
    2039.             // --------------------------------------------------
    2040.             // Graph
    2041.  
    2042.  
    2043.             // Graph Functions
    2044.             // GraphFunctions: <None>
    2045.  
    2046.             // Graph Vertex
    2047.             struct VertexDescription
    2048.         {
    2049.             float3 Position;
    2050.             float3 Normal;
    2051.             float3 Tangent;
    2052.         };
    2053.  
    2054.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    2055.         {
    2056.             VertexDescription description = (VertexDescription)0;
    2057.             description.Position = IN.ObjectSpacePosition;
    2058.             description.Normal = IN.ObjectSpaceNormal;
    2059.             description.Tangent = IN.ObjectSpaceTangent;
    2060.             return description;
    2061.         }
    2062.  
    2063.             // Graph Pixel
    2064.             struct SurfaceDescription
    2065.         {
    2066.             float3 BaseColor;
    2067.             float3 Emission;
    2068.             float Alpha;
    2069.             float3 BentNormal;
    2070.             float Smoothness;
    2071.             float Occlusion;
    2072.             float3 NormalTS;
    2073.             float Metallic;
    2074.         };
    2075.  
    2076.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    2077.         {
    2078.             SurfaceDescription surface = (SurfaceDescription)0;
    2079.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    2080.             surface.Emission = float3(0, 0, 0);
    2081.             surface.Alpha = 1;
    2082.             surface.BentNormal = IN.TangentSpaceNormal;
    2083.             surface.Smoothness = 0.5;
    2084.             surface.Occlusion = 1;
    2085.             surface.NormalTS = IN.TangentSpaceNormal;
    2086.             surface.Metallic = 0;
    2087.             return surface;
    2088.         }
    2089.  
    2090.             // --------------------------------------------------
    2091.             // Build Graph Inputs
    2092.  
    2093.            
    2094.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    2095.         {
    2096.             VertexDescriptionInputs output;
    2097.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    2098.  
    2099.             output.ObjectSpaceNormal =           input.normalOS;
    2100.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    2101.             output.ObjectSpacePosition =         input.positionOS;
    2102.  
    2103.             return output;
    2104.         }
    2105.  
    2106.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    2107.         {
    2108.             // build graph inputs
    2109.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    2110.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    2111.  
    2112.             // evaluate vertex graph
    2113.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    2114.  
    2115.             // copy graph output to the results
    2116.             input.positionOS = vertexDescription.Position;
    2117.             input.normalOS = vertexDescription.Normal;
    2118.             input.tangentOS.xyz = vertexDescription.Tangent;
    2119.  
    2120.             return input;
    2121.         }
    2122.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    2123.         {
    2124.             FragInputs output;
    2125.             ZERO_INITIALIZE(FragInputs, output);
    2126.  
    2127.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    2128.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    2129.             // to compute normals which are then passed on elsewhere to compute other values...
    2130.             output.tangentToWorld = k_identity3x3;
    2131.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    2132.  
    2133.  
    2134.             return output;
    2135.         }
    2136.  
    2137.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    2138.         {
    2139.             SurfaceDescriptionInputs output;
    2140.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    2141.  
    2142.             #if defined(SHADER_STAGE_RAY_TRACING)
    2143.             #else
    2144.             #endif
    2145.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    2146.  
    2147.             return output;
    2148.         }
    2149.  
    2150.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    2151.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    2152.         {
    2153.             UNITY_SETUP_INSTANCE_ID(input);
    2154.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    2155.             return BuildFragInputs(unpacked);
    2156.         }
    2157.  
    2158.             // --------------------------------------------------
    2159.             // Build Surface Data (Specific Material)
    2160.  
    2161.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    2162.         {
    2163.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    2164.  
    2165.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    2166.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    2167.             surfaceData.specularOcclusion = 1.0;
    2168.  
    2169.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    2170.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    2171.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    2172.             surfaceData.metallic =                  surfaceDescription.Metallic;
    2173.  
    2174.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    2175.                 if (_EnableSSRefraction)
    2176.                 {
    2177.  
    2178.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    2179.                     surfaceDescription.Alpha = 1.0;
    2180.                 }
    2181.                 else
    2182.                 {
    2183.                     surfaceData.ior = 1.0;
    2184.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    2185.                     surfaceData.atDistance = 1.0;
    2186.                     surfaceData.transmittanceMask = 0.0;
    2187.                     surfaceDescription.Alpha = 1.0;
    2188.                 }
    2189.             #else
    2190.                 surfaceData.ior = 1.0;
    2191.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    2192.                 surfaceData.atDistance = 1.0;
    2193.                 surfaceData.transmittanceMask = 0.0;
    2194.             #endif
    2195.  
    2196.             // These static material feature allow compile time optimization
    2197.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    2198.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    2199.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    2200.             #endif
    2201.  
    2202.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    2203.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    2204.             #endif
    2205.  
    2206.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    2207.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    2208.             #endif
    2209.  
    2210.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    2211.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    2212.             #endif
    2213.  
    2214.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    2215.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    2216.             #endif
    2217.  
    2218.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    2219.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    2220.             #endif
    2221.  
    2222.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    2223.                 // Require to have setup baseColor
    2224.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    2225.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    2226.             #endif
    2227.  
    2228.             #ifdef _DOUBLESIDED_ON
    2229.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    2230.             #else
    2231.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    2232.             #endif
    2233.  
    2234.             // normal delivered to master node
    2235.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    2236.  
    2237.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    2238.  
    2239.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    2240.  
    2241.  
    2242.             #if HAVE_DECALS
    2243.                 if (_EnableDecals)
    2244.                 {
    2245.                     float alpha = 1.0;
    2246.                     alpha = surfaceDescription.Alpha;
    2247.  
    2248.                     // Both uses and modifies 'surfaceData.normalWS'.
    2249.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    2250.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    2251.                 }
    2252.             #endif
    2253.  
    2254.             bentNormalWS = surfaceData.normalWS;
    2255.  
    2256.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    2257.  
    2258.             #ifdef DEBUG_DISPLAY
    2259.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    2260.                 {
    2261.                     // TODO: need to update mip info
    2262.                     surfaceData.metallic = 0;
    2263.                 }
    2264.  
    2265.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    2266.                 // as it can modify attribute use for static lighting
    2267.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    2268.             #endif
    2269.  
    2270.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    2271.             // If user provide bent normal then we process a better term
    2272.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    2273.                 // Just use the value passed through via the slot (not active otherwise)
    2274.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    2275.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    2276.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    2277.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    2278.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    2279.             #endif
    2280.  
    2281.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    2282.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    2283.             #endif
    2284.         }
    2285.  
    2286.             // --------------------------------------------------
    2287.             // Get Surface And BuiltinData
    2288.  
    2289.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    2290.             {
    2291.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    2292.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    2293.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    2294.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    2295.                 #endif
    2296.                 #endif
    2297.  
    2298.                 #ifndef SHADER_UNLIT
    2299.                 #ifdef _DOUBLESIDED_ON
    2300.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    2301.                 #else
    2302.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    2303.                 #endif
    2304.  
    2305.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    2306.                 #endif // SHADER_UNLIT
    2307.  
    2308.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    2309.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    2310.  
    2311.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    2312.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    2313.                 #ifdef _ALPHATEST_ON
    2314.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    2315.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    2316.                     // The TransparentDepthPrepass is also used with SSR transparent.
    2317.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    2318.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    2319.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    2320.                     // DepthPostpass always use its own alpha threshold
    2321.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    2322.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    2323.                     // If use shadow threshold isn't enable we don't allow any test
    2324.                     #endif
    2325.  
    2326.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    2327.                 #endif
    2328.  
    2329.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    2330.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    2331.                 #endif
    2332.  
    2333.                 #ifndef SHADER_UNLIT
    2334.                 float3 bentNormalWS;
    2335.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    2336.  
    2337.                 // Builtin Data
    2338.                 // For back lighting we use the oposite vertex normal
    2339.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    2340.  
    2341.                 #else
    2342.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    2343.  
    2344.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    2345.                 builtinData.opacity = surfaceDescription.Alpha;
    2346.  
    2347.                 #if defined(DEBUG_DISPLAY)
    2348.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    2349.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    2350.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    2351.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    2352.                 #endif
    2353.  
    2354.                 #endif // SHADER_UNLIT
    2355.  
    2356.                 #ifdef _ALPHATEST_ON
    2357.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    2358.                     builtinData.alphaClipTreshold = alphaCutoff;
    2359.                 #endif
    2360.  
    2361.                 // override sampleBakedGI - not used by Unlit
    2362.  
    2363.                 builtinData.emissiveColor = surfaceDescription.Emission;
    2364.  
    2365.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    2366.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    2367.                 // This is a limitation of the current MRT approach.
    2368.  
    2369.                 #if _DEPTHOFFSET_ON
    2370.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    2371.                 #endif
    2372.  
    2373.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    2374.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    2375.                 builtinData.distortion = surfaceDescription.Distortion;
    2376.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    2377.                 #endif
    2378.  
    2379.                 #ifndef SHADER_UNLIT
    2380.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    2381.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    2382.                 #else
    2383.                 ApplyDebugToBuiltinData(builtinData);
    2384.                 #endif
    2385.  
    2386.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    2387.             }
    2388.  
    2389.             // --------------------------------------------------
    2390.             // Main
    2391.  
    2392.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"
    2393.  
    2394.             ENDHLSL
    2395.         }
    2396.         Pass
    2397.         {
    2398.             Name "MotionVectors"
    2399.             Tags
    2400.             {
    2401.                 "LightMode" = "MotionVectors"
    2402.             }
    2403.  
    2404.             // Render State
    2405.             Cull [_CullMode]
    2406.         ZWrite On
    2407.         Stencil
    2408.         {
    2409.             WriteMask [_StencilWriteMaskMV]
    2410.             Ref [_StencilRefMV]
    2411.             CompFront Always
    2412.             PassFront Replace
    2413.             CompBack Always
    2414.             PassBack Replace
    2415.         }
    2416.  
    2417.             // Debug
    2418.             // <None>
    2419.  
    2420.             // --------------------------------------------------
    2421.             // Pass
    2422.  
    2423.             HLSLPROGRAM
    2424.  
    2425.             // Pragmas
    2426.             #pragma target 4.5
    2427.         #pragma vertex Vert
    2428.         #pragma fragment Frag
    2429.         #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
    2430.         #pragma multi_compile_instancing
    2431.         #pragma instancing_options renderinglayer
    2432.  
    2433.             // Keywords
    2434.             #pragma multi_compile _ WRITE_MSAA_DEPTH
    2435.         #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    2436.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    2437.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    2438.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    2439.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    2440.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    2441.         #pragma multi_compile _ WRITE_NORMAL_BUFFER
    2442.         #pragma shader_feature_local _ _DISABLE_DECALS
    2443.         #pragma shader_feature_local _ _DISABLE_SSR
    2444.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    2445.         #pragma multi_compile _ WRITE_DECAL_BUFFER
    2446.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    2447.             // GraphKeywords: <None>
    2448.  
    2449.             // Early Instancing Defines
    2450.             // DotsInstancingOptions: <None>
    2451.  
    2452.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    2453.             // HybridV1InjectedBuiltinProperties: <None>
    2454.  
    2455.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    2456.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    2457.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    2458.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    2459.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    2460.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    2461.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    2462.  
    2463.             // --------------------------------------------------
    2464.             // Defines
    2465.  
    2466.             // Attribute
    2467.             #define ATTRIBUTES_NEED_NORMAL
    2468.             #define ATTRIBUTES_NEED_TANGENT
    2469.             #define ATTRIBUTES_NEED_TEXCOORD0
    2470.             #define ATTRIBUTES_NEED_TEXCOORD1
    2471.             #define ATTRIBUTES_NEED_TEXCOORD2
    2472.             #define ATTRIBUTES_NEED_TEXCOORD3
    2473.             #define ATTRIBUTES_NEED_COLOR
    2474.             #define VARYINGS_NEED_POSITION_WS
    2475.             #define VARYINGS_NEED_TANGENT_TO_WORLD
    2476.             #define VARYINGS_NEED_TEXCOORD1
    2477.             #define VARYINGS_NEED_TEXCOORD2
    2478.             #define VARYINGS_NEED_TEXCOORD3
    2479.             #define VARYINGS_NEED_COLOR
    2480.  
    2481.             #define HAVE_MESH_MODIFICATION
    2482.  
    2483.  
    2484.             #define SHADERPASS SHADERPASS_MOTION_VECTORS
    2485.         #define RAYTRACING_SHADER_GRAPH_DEFAULT
    2486.  
    2487.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    2488.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    2489.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    2490.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    2491.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    2492.             #define RAYTRACING_SHADER_GRAPH_HIGH
    2493.             #endif
    2494.  
    2495.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    2496.             #define RAYTRACING_SHADER_GRAPH_LOW
    2497.             #endif
    2498.             // end
    2499.  
    2500.             #ifndef SHADER_UNLIT
    2501.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    2502.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    2503.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    2504.                 #define VARYINGS_NEED_CULLFACE
    2505.             #endif
    2506.             #endif
    2507.  
    2508.             // Specific Material Define
    2509.         #define _ENERGY_CONSERVING_SPECULAR 1
    2510.  
    2511.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    2512.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    2513.             #define OUTPUT_SPLIT_LIGHTING
    2514.         #endif
    2515.  
    2516.         // This shader support recursive rendering for raytracing
    2517.         #define HAVE_RECURSIVE_RENDERING
    2518.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    2519.  
    2520.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    2521.             // we should have a code like this:
    2522.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    2523.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    2524.             // endif
    2525.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    2526.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    2527.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    2528.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    2529.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    2530.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    2531.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    2532.                 #define WRITE_NORMAL_BUFFER
    2533.             #endif
    2534.             #endif
    2535.  
    2536.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    2537.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    2538.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    2539.             // the constant buffer. A bug is filed and is being looked at.
    2540.             #if defined(SHADER_API_VULKAN)
    2541.             #define DISABLE_UNLIT_DEEXPOSURE
    2542.             #endif
    2543.  
    2544.             #ifndef DEBUG_DISPLAY
    2545.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    2546.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    2547.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    2548.                     #if SHADERPASS == SHADERPASS_FORWARD
    2549.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    2550.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    2551.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    2552.                     #endif
    2553.                 #endif
    2554.             #endif
    2555.  
    2556.             // Translate transparent motion vector define
    2557.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    2558.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    2559.             #endif
    2560.  
    2561.             // -- Graph Properties
    2562.             CBUFFER_START(UnityPerMaterial)
    2563.         float4 _EmissionColor;
    2564.         float _UseShadowThreshold;
    2565.         float4 _DoubleSidedConstants;
    2566.         float _BlendMode;
    2567.         float _EnableBlendModePreserveSpecularLighting;
    2568.         float _RayTracing;
    2569.         float _RefractionModel;
    2570.         CBUFFER_END
    2571.  
    2572.         // Object and Global properties
    2573.  
    2574.             // -- Property used by ScenePickingPass
    2575.             #ifdef SCENEPICKINGPASS
    2576.             float4 _SelectionID;
    2577.             #endif
    2578.  
    2579.             // -- Properties used by SceneSelectionPass
    2580.             #ifdef SCENESELECTIONPASS
    2581.             int _ObjectId;
    2582.             int _PassValue;
    2583.             #endif
    2584.  
    2585.             // Includes
    2586.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
    2587.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    2588.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
    2589.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    2590.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    2591.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    2592.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
    2593.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"
    2594.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    2595.  
    2596.             // --------------------------------------------------
    2597.             // Structs and Packing
    2598.  
    2599.             struct AttributesMesh
    2600.         {
    2601.             float3 positionOS : POSITION;
    2602.             float3 normalOS : NORMAL;
    2603.             float4 tangentOS : TANGENT;
    2604.             float4 uv0 : TEXCOORD0;
    2605.             float4 uv1 : TEXCOORD1;
    2606.             float4 uv2 : TEXCOORD2;
    2607.             float4 uv3 : TEXCOORD3;
    2608.             float4 color : COLOR;
    2609.             #if UNITY_ANY_INSTANCING_ENABLED
    2610.             uint instanceID : INSTANCEID_SEMANTIC;
    2611.             #endif
    2612.         };
    2613.         struct VaryingsMeshToPS
    2614.         {
    2615.             float4 positionCS : SV_POSITION;
    2616.             float3 positionRWS;
    2617.             float3 normalWS;
    2618.             float4 tangentWS;
    2619.             float4 texCoord1;
    2620.             float4 texCoord2;
    2621.             float4 texCoord3;
    2622.             float4 color;
    2623.             #if UNITY_ANY_INSTANCING_ENABLED
    2624.             uint instanceID : CUSTOM_INSTANCE_ID;
    2625.             #endif
    2626.         };
    2627.         struct SurfaceDescriptionInputs
    2628.         {
    2629.             float3 TangentSpaceNormal;
    2630.         };
    2631.         struct VertexDescriptionInputs
    2632.         {
    2633.             float3 ObjectSpaceNormal;
    2634.             float3 ObjectSpaceTangent;
    2635.             float3 ObjectSpacePosition;
    2636.         };
    2637.         struct PackedVaryingsMeshToPS
    2638.         {
    2639.             float4 positionCS : SV_POSITION;
    2640.             float3 interp0 : TEXCOORD0;
    2641.             float3 interp1 : TEXCOORD1;
    2642.             float4 interp2 : TEXCOORD2;
    2643.             float4 interp3 : TEXCOORD3;
    2644.             float4 interp4 : TEXCOORD4;
    2645.             float4 interp5 : TEXCOORD5;
    2646.             float4 interp6 : TEXCOORD6;
    2647.             #if UNITY_ANY_INSTANCING_ENABLED
    2648.             uint instanceID : CUSTOM_INSTANCE_ID;
    2649.             #endif
    2650.         };
    2651.  
    2652.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    2653.         {
    2654.             PackedVaryingsMeshToPS output;
    2655.             output.positionCS = input.positionCS;
    2656.             output.interp0.xyz =  input.positionRWS;
    2657.             output.interp1.xyz =  input.normalWS;
    2658.             output.interp2.xyzw =  input.tangentWS;
    2659.             output.interp3.xyzw =  input.texCoord1;
    2660.             output.interp4.xyzw =  input.texCoord2;
    2661.             output.interp5.xyzw =  input.texCoord3;
    2662.             output.interp6.xyzw =  input.color;
    2663.             #if UNITY_ANY_INSTANCING_ENABLED
    2664.             output.instanceID = input.instanceID;
    2665.             #endif
    2666.             return output;
    2667.         }
    2668.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    2669.         {
    2670.             VaryingsMeshToPS output;
    2671.             output.positionCS = input.positionCS;
    2672.             output.positionRWS = input.interp0.xyz;
    2673.             output.normalWS = input.interp1.xyz;
    2674.             output.tangentWS = input.interp2.xyzw;
    2675.             output.texCoord1 = input.interp3.xyzw;
    2676.             output.texCoord2 = input.interp4.xyzw;
    2677.             output.texCoord3 = input.interp5.xyzw;
    2678.             output.color = input.interp6.xyzw;
    2679.             #if UNITY_ANY_INSTANCING_ENABLED
    2680.             output.instanceID = input.instanceID;
    2681.             #endif
    2682.             return output;
    2683.         }
    2684.  
    2685.             // --------------------------------------------------
    2686.             // Graph
    2687.  
    2688.  
    2689.             // Graph Functions
    2690.             // GraphFunctions: <None>
    2691.  
    2692.             // Graph Vertex
    2693.             struct VertexDescription
    2694.         {
    2695.             float3 Position;
    2696.             float3 Normal;
    2697.             float3 Tangent;
    2698.         };
    2699.  
    2700.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    2701.         {
    2702.             VertexDescription description = (VertexDescription)0;
    2703.             description.Position = IN.ObjectSpacePosition;
    2704.             description.Normal = IN.ObjectSpaceNormal;
    2705.             description.Tangent = IN.ObjectSpaceTangent;
    2706.             return description;
    2707.         }
    2708.  
    2709.             // Graph Pixel
    2710.             struct SurfaceDescription
    2711.         {
    2712.             float3 BaseColor;
    2713.             float3 Emission;
    2714.             float Alpha;
    2715.             float3 BentNormal;
    2716.             float Smoothness;
    2717.             float Occlusion;
    2718.             float3 NormalTS;
    2719.             float Metallic;
    2720.         };
    2721.  
    2722.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    2723.         {
    2724.             SurfaceDescription surface = (SurfaceDescription)0;
    2725.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    2726.             surface.Emission = float3(0, 0, 0);
    2727.             surface.Alpha = 1;
    2728.             surface.BentNormal = IN.TangentSpaceNormal;
    2729.             surface.Smoothness = 0.5;
    2730.             surface.Occlusion = 1;
    2731.             surface.NormalTS = IN.TangentSpaceNormal;
    2732.             surface.Metallic = 0;
    2733.             return surface;
    2734.         }
    2735.  
    2736.             // --------------------------------------------------
    2737.             // Build Graph Inputs
    2738.  
    2739.            
    2740.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    2741.         {
    2742.             VertexDescriptionInputs output;
    2743.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    2744.  
    2745.             output.ObjectSpaceNormal =           input.normalOS;
    2746.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    2747.             output.ObjectSpacePosition =         input.positionOS;
    2748.  
    2749.             return output;
    2750.         }
    2751.  
    2752.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    2753.         {
    2754.             // build graph inputs
    2755.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    2756.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    2757.  
    2758.             // evaluate vertex graph
    2759.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    2760.  
    2761.             // copy graph output to the results
    2762.             input.positionOS = vertexDescription.Position;
    2763.             input.normalOS = vertexDescription.Normal;
    2764.             input.tangentOS.xyz = vertexDescription.Tangent;
    2765.  
    2766.             return input;
    2767.         }
    2768.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    2769.         {
    2770.             FragInputs output;
    2771.             ZERO_INITIALIZE(FragInputs, output);
    2772.  
    2773.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    2774.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    2775.             // to compute normals which are then passed on elsewhere to compute other values...
    2776.             output.tangentToWorld = k_identity3x3;
    2777.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    2778.  
    2779.             output.positionRWS = input.positionRWS;
    2780.             output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS);
    2781.             output.texCoord1 = input.texCoord1;
    2782.             output.texCoord2 = input.texCoord2;
    2783.             output.texCoord3 = input.texCoord3;
    2784.             output.color = input.color;
    2785.  
    2786.             return output;
    2787.         }
    2788.  
    2789.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    2790.         {
    2791.             SurfaceDescriptionInputs output;
    2792.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    2793.  
    2794.             #if defined(SHADER_STAGE_RAY_TRACING)
    2795.             #else
    2796.             #endif
    2797.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    2798.  
    2799.             return output;
    2800.         }
    2801.  
    2802.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    2803.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    2804.         {
    2805.             UNITY_SETUP_INSTANCE_ID(input);
    2806.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    2807.             return BuildFragInputs(unpacked);
    2808.         }
    2809.  
    2810.             // --------------------------------------------------
    2811.             // Build Surface Data (Specific Material)
    2812.  
    2813.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    2814.         {
    2815.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    2816.  
    2817.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    2818.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    2819.             surfaceData.specularOcclusion = 1.0;
    2820.  
    2821.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    2822.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    2823.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    2824.             surfaceData.metallic =                  surfaceDescription.Metallic;
    2825.  
    2826.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    2827.                 if (_EnableSSRefraction)
    2828.                 {
    2829.  
    2830.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    2831.                     surfaceDescription.Alpha = 1.0;
    2832.                 }
    2833.                 else
    2834.                 {
    2835.                     surfaceData.ior = 1.0;
    2836.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    2837.                     surfaceData.atDistance = 1.0;
    2838.                     surfaceData.transmittanceMask = 0.0;
    2839.                     surfaceDescription.Alpha = 1.0;
    2840.                 }
    2841.             #else
    2842.                 surfaceData.ior = 1.0;
    2843.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    2844.                 surfaceData.atDistance = 1.0;
    2845.                 surfaceData.transmittanceMask = 0.0;
    2846.             #endif
    2847.  
    2848.             // These static material feature allow compile time optimization
    2849.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    2850.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    2851.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    2852.             #endif
    2853.  
    2854.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    2855.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    2856.             #endif
    2857.  
    2858.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    2859.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    2860.             #endif
    2861.  
    2862.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    2863.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    2864.             #endif
    2865.  
    2866.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    2867.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    2868.             #endif
    2869.  
    2870.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    2871.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    2872.             #endif
    2873.  
    2874.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    2875.                 // Require to have setup baseColor
    2876.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    2877.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    2878.             #endif
    2879.  
    2880.             #ifdef _DOUBLESIDED_ON
    2881.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    2882.             #else
    2883.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    2884.             #endif
    2885.  
    2886.             // normal delivered to master node
    2887.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    2888.  
    2889.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    2890.  
    2891.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    2892.  
    2893.  
    2894.             #if HAVE_DECALS
    2895.                 if (_EnableDecals)
    2896.                 {
    2897.                     float alpha = 1.0;
    2898.                     alpha = surfaceDescription.Alpha;
    2899.  
    2900.                     // Both uses and modifies 'surfaceData.normalWS'.
    2901.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    2902.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    2903.                 }
    2904.             #endif
    2905.  
    2906.             bentNormalWS = surfaceData.normalWS;
    2907.  
    2908.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    2909.  
    2910.             #ifdef DEBUG_DISPLAY
    2911.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    2912.                 {
    2913.                     // TODO: need to update mip info
    2914.                     surfaceData.metallic = 0;
    2915.                 }
    2916.  
    2917.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    2918.                 // as it can modify attribute use for static lighting
    2919.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    2920.             #endif
    2921.  
    2922.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    2923.             // If user provide bent normal then we process a better term
    2924.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    2925.                 // Just use the value passed through via the slot (not active otherwise)
    2926.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    2927.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    2928.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    2929.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    2930.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    2931.             #endif
    2932.  
    2933.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    2934.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    2935.             #endif
    2936.         }
    2937.  
    2938.             // --------------------------------------------------
    2939.             // Get Surface And BuiltinData
    2940.  
    2941.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    2942.             {
    2943.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    2944.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    2945.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    2946.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    2947.                 #endif
    2948.                 #endif
    2949.  
    2950.                 #ifndef SHADER_UNLIT
    2951.                 #ifdef _DOUBLESIDED_ON
    2952.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    2953.                 #else
    2954.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    2955.                 #endif
    2956.  
    2957.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    2958.                 #endif // SHADER_UNLIT
    2959.  
    2960.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    2961.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    2962.  
    2963.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    2964.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    2965.                 #ifdef _ALPHATEST_ON
    2966.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    2967.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    2968.                     // The TransparentDepthPrepass is also used with SSR transparent.
    2969.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    2970.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    2971.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    2972.                     // DepthPostpass always use its own alpha threshold
    2973.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    2974.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    2975.                     // If use shadow threshold isn't enable we don't allow any test
    2976.                     #endif
    2977.  
    2978.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    2979.                 #endif
    2980.  
    2981.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    2982.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    2983.                 #endif
    2984.  
    2985.                 #ifndef SHADER_UNLIT
    2986.                 float3 bentNormalWS;
    2987.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    2988.  
    2989.                 // Builtin Data
    2990.                 // For back lighting we use the oposite vertex normal
    2991.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    2992.  
    2993.                 #else
    2994.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    2995.  
    2996.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    2997.                 builtinData.opacity = surfaceDescription.Alpha;
    2998.  
    2999.                 #if defined(DEBUG_DISPLAY)
    3000.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    3001.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    3002.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    3003.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    3004.                 #endif
    3005.  
    3006.                 #endif // SHADER_UNLIT
    3007.  
    3008.                 #ifdef _ALPHATEST_ON
    3009.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    3010.                     builtinData.alphaClipTreshold = alphaCutoff;
    3011.                 #endif
    3012.  
    3013.                 // override sampleBakedGI - not used by Unlit
    3014.  
    3015.                 builtinData.emissiveColor = surfaceDescription.Emission;
    3016.  
    3017.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    3018.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    3019.                 // This is a limitation of the current MRT approach.
    3020.  
    3021.                 #if _DEPTHOFFSET_ON
    3022.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    3023.                 #endif
    3024.  
    3025.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    3026.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    3027.                 builtinData.distortion = surfaceDescription.Distortion;
    3028.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    3029.                 #endif
    3030.  
    3031.                 #ifndef SHADER_UNLIT
    3032.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    3033.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    3034.                 #else
    3035.                 ApplyDebugToBuiltinData(builtinData);
    3036.                 #endif
    3037.  
    3038.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    3039.             }
    3040.  
    3041.             // --------------------------------------------------
    3042.             // Main
    3043.  
    3044.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassMotionVectors.hlsl"
    3045.  
    3046.             ENDHLSL
    3047.         }
    3048.         Pass
    3049.         {
    3050.             Name "TransparentDepthPrepass"
    3051.             Tags
    3052.             {
    3053.                 "LightMode" = "TransparentDepthPrepass"
    3054.             }
    3055.  
    3056.             // Render State
    3057.             Cull [_CullMode]
    3058.         Blend One Zero
    3059.         ZWrite On
    3060.         Stencil
    3061.         {
    3062.             WriteMask [_StencilWriteMaskDepth]
    3063.             Ref [_StencilRefDepth]
    3064.             CompFront Always
    3065.             PassFront Replace
    3066.             CompBack Always
    3067.             PassBack Replace
    3068.         }
    3069.  
    3070.             // Debug
    3071.             // <None>
    3072.  
    3073.             // --------------------------------------------------
    3074.             // Pass
    3075.  
    3076.             HLSLPROGRAM
    3077.  
    3078.             // Pragmas
    3079.             #pragma target 4.5
    3080.         #pragma vertex Vert
    3081.         #pragma fragment Frag
    3082.         #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
    3083.         #pragma multi_compile_instancing
    3084.         #pragma instancing_options renderinglayer
    3085.  
    3086.             // Keywords
    3087.             #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    3088.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    3089.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    3090.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    3091.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    3092.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    3093.         #pragma shader_feature_local _ _DISABLE_DECALS
    3094.         #pragma shader_feature_local _ _DISABLE_SSR
    3095.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    3096.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    3097.             // GraphKeywords: <None>
    3098.  
    3099.             // Early Instancing Defines
    3100.             // DotsInstancingOptions: <None>
    3101.  
    3102.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    3103.             // HybridV1InjectedBuiltinProperties: <None>
    3104.  
    3105.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    3106.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    3107.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    3108.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    3109.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    3110.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    3111.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    3112.  
    3113.             // --------------------------------------------------
    3114.             // Defines
    3115.  
    3116.             // Attribute
    3117.             #define ATTRIBUTES_NEED_NORMAL
    3118.             #define ATTRIBUTES_NEED_TANGENT
    3119.             #define ATTRIBUTES_NEED_TEXCOORD0
    3120.             #define ATTRIBUTES_NEED_TEXCOORD1
    3121.             #define ATTRIBUTES_NEED_TEXCOORD2
    3122.             #define ATTRIBUTES_NEED_TEXCOORD3
    3123.             #define ATTRIBUTES_NEED_COLOR
    3124.             #define VARYINGS_NEED_POSITION_WS
    3125.             #define VARYINGS_NEED_TANGENT_TO_WORLD
    3126.             #define VARYINGS_NEED_TEXCOORD1
    3127.             #define VARYINGS_NEED_TEXCOORD2
    3128.             #define VARYINGS_NEED_TEXCOORD3
    3129.             #define VARYINGS_NEED_COLOR
    3130.  
    3131.             #define HAVE_MESH_MODIFICATION
    3132.  
    3133.  
    3134.             #define SHADERPASS SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    3135.         #define RAYTRACING_SHADER_GRAPH_DEFAULT
    3136.  
    3137.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    3138.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    3139.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    3140.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    3141.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    3142.             #define RAYTRACING_SHADER_GRAPH_HIGH
    3143.             #endif
    3144.  
    3145.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    3146.             #define RAYTRACING_SHADER_GRAPH_LOW
    3147.             #endif
    3148.             // end
    3149.  
    3150.             #ifndef SHADER_UNLIT
    3151.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    3152.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    3153.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    3154.                 #define VARYINGS_NEED_CULLFACE
    3155.             #endif
    3156.             #endif
    3157.  
    3158.             // Specific Material Define
    3159.         #define _ENERGY_CONSERVING_SPECULAR 1
    3160.  
    3161.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    3162.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    3163.             #define OUTPUT_SPLIT_LIGHTING
    3164.         #endif
    3165.  
    3166.         // This shader support recursive rendering for raytracing
    3167.         #define HAVE_RECURSIVE_RENDERING
    3168.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    3169.  
    3170.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    3171.             // we should have a code like this:
    3172.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    3173.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    3174.             // endif
    3175.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    3176.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    3177.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    3178.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    3179.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    3180.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    3181.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    3182.                 #define WRITE_NORMAL_BUFFER
    3183.             #endif
    3184.             #endif
    3185.  
    3186.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    3187.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    3188.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    3189.             // the constant buffer. A bug is filed and is being looked at.
    3190.             #if defined(SHADER_API_VULKAN)
    3191.             #define DISABLE_UNLIT_DEEXPOSURE
    3192.             #endif
    3193.  
    3194.             #ifndef DEBUG_DISPLAY
    3195.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    3196.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    3197.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    3198.                     #if SHADERPASS == SHADERPASS_FORWARD
    3199.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    3200.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    3201.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    3202.                     #endif
    3203.                 #endif
    3204.             #endif
    3205.  
    3206.             // Translate transparent motion vector define
    3207.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    3208.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    3209.             #endif
    3210.  
    3211.             // -- Graph Properties
    3212.             CBUFFER_START(UnityPerMaterial)
    3213.         float4 _EmissionColor;
    3214.         float _UseShadowThreshold;
    3215.         float4 _DoubleSidedConstants;
    3216.         float _BlendMode;
    3217.         float _EnableBlendModePreserveSpecularLighting;
    3218.         float _RayTracing;
    3219.         float _RefractionModel;
    3220.         CBUFFER_END
    3221.  
    3222.         // Object and Global properties
    3223.  
    3224.             // -- Property used by ScenePickingPass
    3225.             #ifdef SCENEPICKINGPASS
    3226.             float4 _SelectionID;
    3227.             #endif
    3228.  
    3229.             // -- Properties used by SceneSelectionPass
    3230.             #ifdef SCENESELECTIONPASS
    3231.             int _ObjectId;
    3232.             int _PassValue;
    3233.             #endif
    3234.  
    3235.             // Includes
    3236.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
    3237.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    3238.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
    3239.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    3240.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    3241.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    3242.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
    3243.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"
    3244.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    3245.  
    3246.             // --------------------------------------------------
    3247.             // Structs and Packing
    3248.  
    3249.             struct AttributesMesh
    3250.         {
    3251.             float3 positionOS : POSITION;
    3252.             float3 normalOS : NORMAL;
    3253.             float4 tangentOS : TANGENT;
    3254.             float4 uv0 : TEXCOORD0;
    3255.             float4 uv1 : TEXCOORD1;
    3256.             float4 uv2 : TEXCOORD2;
    3257.             float4 uv3 : TEXCOORD3;
    3258.             float4 color : COLOR;
    3259.             #if UNITY_ANY_INSTANCING_ENABLED
    3260.             uint instanceID : INSTANCEID_SEMANTIC;
    3261.             #endif
    3262.         };
    3263.         struct VaryingsMeshToPS
    3264.         {
    3265.             float4 positionCS : SV_POSITION;
    3266.             float3 positionRWS;
    3267.             float3 normalWS;
    3268.             float4 tangentWS;
    3269.             float4 texCoord1;
    3270.             float4 texCoord2;
    3271.             float4 texCoord3;
    3272.             float4 color;
    3273.             #if UNITY_ANY_INSTANCING_ENABLED
    3274.             uint instanceID : CUSTOM_INSTANCE_ID;
    3275.             #endif
    3276.         };
    3277.         struct SurfaceDescriptionInputs
    3278.         {
    3279.             float3 TangentSpaceNormal;
    3280.         };
    3281.         struct VertexDescriptionInputs
    3282.         {
    3283.             float3 ObjectSpaceNormal;
    3284.             float3 ObjectSpaceTangent;
    3285.             float3 ObjectSpacePosition;
    3286.         };
    3287.         struct PackedVaryingsMeshToPS
    3288.         {
    3289.             float4 positionCS : SV_POSITION;
    3290.             float3 interp0 : TEXCOORD0;
    3291.             float3 interp1 : TEXCOORD1;
    3292.             float4 interp2 : TEXCOORD2;
    3293.             float4 interp3 : TEXCOORD3;
    3294.             float4 interp4 : TEXCOORD4;
    3295.             float4 interp5 : TEXCOORD5;
    3296.             float4 interp6 : TEXCOORD6;
    3297.             #if UNITY_ANY_INSTANCING_ENABLED
    3298.             uint instanceID : CUSTOM_INSTANCE_ID;
    3299.             #endif
    3300.         };
    3301.  
    3302.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    3303.         {
    3304.             PackedVaryingsMeshToPS output;
    3305.             output.positionCS = input.positionCS;
    3306.             output.interp0.xyz =  input.positionRWS;
    3307.             output.interp1.xyz =  input.normalWS;
    3308.             output.interp2.xyzw =  input.tangentWS;
    3309.             output.interp3.xyzw =  input.texCoord1;
    3310.             output.interp4.xyzw =  input.texCoord2;
    3311.             output.interp5.xyzw =  input.texCoord3;
    3312.             output.interp6.xyzw =  input.color;
    3313.             #if UNITY_ANY_INSTANCING_ENABLED
    3314.             output.instanceID = input.instanceID;
    3315.             #endif
    3316.             return output;
    3317.         }
    3318.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    3319.         {
    3320.             VaryingsMeshToPS output;
    3321.             output.positionCS = input.positionCS;
    3322.             output.positionRWS = input.interp0.xyz;
    3323.             output.normalWS = input.interp1.xyz;
    3324.             output.tangentWS = input.interp2.xyzw;
    3325.             output.texCoord1 = input.interp3.xyzw;
    3326.             output.texCoord2 = input.interp4.xyzw;
    3327.             output.texCoord3 = input.interp5.xyzw;
    3328.             output.color = input.interp6.xyzw;
    3329.             #if UNITY_ANY_INSTANCING_ENABLED
    3330.             output.instanceID = input.instanceID;
    3331.             #endif
    3332.             return output;
    3333.         }
    3334.  
    3335.             // --------------------------------------------------
    3336.             // Graph
    3337.  
    3338.  
    3339.             // Graph Functions
    3340.             // GraphFunctions: <None>
    3341.  
    3342.             // Graph Vertex
    3343.             struct VertexDescription
    3344.         {
    3345.             float3 Position;
    3346.             float3 Normal;
    3347.             float3 Tangent;
    3348.         };
    3349.  
    3350.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    3351.         {
    3352.             VertexDescription description = (VertexDescription)0;
    3353.             description.Position = IN.ObjectSpacePosition;
    3354.             description.Normal = IN.ObjectSpaceNormal;
    3355.             description.Tangent = IN.ObjectSpaceTangent;
    3356.             return description;
    3357.         }
    3358.  
    3359.             // Graph Pixel
    3360.             struct SurfaceDescription
    3361.         {
    3362.             float Alpha;
    3363.             float3 NormalTS;
    3364.             float Smoothness;
    3365.         };
    3366.  
    3367.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    3368.         {
    3369.             SurfaceDescription surface = (SurfaceDescription)0;
    3370.             surface.Alpha = 1;
    3371.             surface.NormalTS = IN.TangentSpaceNormal;
    3372.             surface.Smoothness = 0.5;
    3373.             return surface;
    3374.         }
    3375.  
    3376.             // --------------------------------------------------
    3377.             // Build Graph Inputs
    3378.  
    3379.            
    3380.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    3381.         {
    3382.             VertexDescriptionInputs output;
    3383.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    3384.  
    3385.             output.ObjectSpaceNormal =           input.normalOS;
    3386.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    3387.             output.ObjectSpacePosition =         input.positionOS;
    3388.  
    3389.             return output;
    3390.         }
    3391.  
    3392.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    3393.         {
    3394.             // build graph inputs
    3395.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    3396.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    3397.  
    3398.             // evaluate vertex graph
    3399.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    3400.  
    3401.             // copy graph output to the results
    3402.             input.positionOS = vertexDescription.Position;
    3403.             input.normalOS = vertexDescription.Normal;
    3404.             input.tangentOS.xyz = vertexDescription.Tangent;
    3405.  
    3406.             return input;
    3407.         }
    3408.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    3409.         {
    3410.             FragInputs output;
    3411.             ZERO_INITIALIZE(FragInputs, output);
    3412.  
    3413.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    3414.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    3415.             // to compute normals which are then passed on elsewhere to compute other values...
    3416.             output.tangentToWorld = k_identity3x3;
    3417.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    3418.  
    3419.             output.positionRWS = input.positionRWS;
    3420.             output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS);
    3421.             output.texCoord1 = input.texCoord1;
    3422.             output.texCoord2 = input.texCoord2;
    3423.             output.texCoord3 = input.texCoord3;
    3424.             output.color = input.color;
    3425.  
    3426.             return output;
    3427.         }
    3428.  
    3429.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    3430.         {
    3431.             SurfaceDescriptionInputs output;
    3432.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    3433.  
    3434.             #if defined(SHADER_STAGE_RAY_TRACING)
    3435.             #else
    3436.             #endif
    3437.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    3438.  
    3439.             return output;
    3440.         }
    3441.  
    3442.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    3443.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    3444.         {
    3445.             UNITY_SETUP_INSTANCE_ID(input);
    3446.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    3447.             return BuildFragInputs(unpacked);
    3448.         }
    3449.  
    3450.             // --------------------------------------------------
    3451.             // Build Surface Data (Specific Material)
    3452.  
    3453.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    3454.         {
    3455.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    3456.  
    3457.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    3458.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    3459.             surfaceData.specularOcclusion = 1.0;
    3460.  
    3461.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    3462.  
    3463.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    3464.                 if (_EnableSSRefraction)
    3465.                 {
    3466.  
    3467.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    3468.                     surfaceDescription.Alpha = 1.0;
    3469.                 }
    3470.                 else
    3471.                 {
    3472.                     surfaceData.ior = 1.0;
    3473.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    3474.                     surfaceData.atDistance = 1.0;
    3475.                     surfaceData.transmittanceMask = 0.0;
    3476.                     surfaceDescription.Alpha = 1.0;
    3477.                 }
    3478.             #else
    3479.                 surfaceData.ior = 1.0;
    3480.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    3481.                 surfaceData.atDistance = 1.0;
    3482.                 surfaceData.transmittanceMask = 0.0;
    3483.             #endif
    3484.  
    3485.             // These static material feature allow compile time optimization
    3486.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    3487.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    3488.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    3489.             #endif
    3490.  
    3491.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    3492.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    3493.             #endif
    3494.  
    3495.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    3496.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    3497.             #endif
    3498.  
    3499.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    3500.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    3501.             #endif
    3502.  
    3503.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    3504.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    3505.             #endif
    3506.  
    3507.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    3508.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    3509.             #endif
    3510.  
    3511.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    3512.                 // Require to have setup baseColor
    3513.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    3514.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    3515.             #endif
    3516.  
    3517.             #ifdef _DOUBLESIDED_ON
    3518.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    3519.             #else
    3520.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    3521.             #endif
    3522.  
    3523.             // normal delivered to master node
    3524.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    3525.  
    3526.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    3527.  
    3528.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    3529.  
    3530.  
    3531.             #if HAVE_DECALS
    3532.                 if (_EnableDecals)
    3533.                 {
    3534.                     float alpha = 1.0;
    3535.                     alpha = surfaceDescription.Alpha;
    3536.  
    3537.                     // Both uses and modifies 'surfaceData.normalWS'.
    3538.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    3539.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    3540.                 }
    3541.             #endif
    3542.  
    3543.             bentNormalWS = surfaceData.normalWS;
    3544.  
    3545.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    3546.  
    3547.             #ifdef DEBUG_DISPLAY
    3548.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    3549.                 {
    3550.                     // TODO: need to update mip info
    3551.                     surfaceData.metallic = 0;
    3552.                 }
    3553.  
    3554.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    3555.                 // as it can modify attribute use for static lighting
    3556.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    3557.             #endif
    3558.  
    3559.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    3560.             // If user provide bent normal then we process a better term
    3561.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    3562.                 // Just use the value passed through via the slot (not active otherwise)
    3563.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    3564.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    3565.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    3566.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    3567.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    3568.             #endif
    3569.  
    3570.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    3571.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    3572.             #endif
    3573.         }
    3574.  
    3575.             // --------------------------------------------------
    3576.             // Get Surface And BuiltinData
    3577.  
    3578.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    3579.             {
    3580.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    3581.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    3582.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    3583.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    3584.                 #endif
    3585.                 #endif
    3586.  
    3587.                 #ifndef SHADER_UNLIT
    3588.                 #ifdef _DOUBLESIDED_ON
    3589.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    3590.                 #else
    3591.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    3592.                 #endif
    3593.  
    3594.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    3595.                 #endif // SHADER_UNLIT
    3596.  
    3597.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    3598.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    3599.  
    3600.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    3601.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    3602.                 #ifdef _ALPHATEST_ON
    3603.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    3604.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    3605.                     // The TransparentDepthPrepass is also used with SSR transparent.
    3606.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    3607.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    3608.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    3609.                     // DepthPostpass always use its own alpha threshold
    3610.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    3611.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    3612.                     // If use shadow threshold isn't enable we don't allow any test
    3613.                     #endif
    3614.  
    3615.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    3616.                 #endif
    3617.  
    3618.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    3619.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    3620.                 #endif
    3621.  
    3622.                 #ifndef SHADER_UNLIT
    3623.                 float3 bentNormalWS;
    3624.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    3625.  
    3626.                 // Builtin Data
    3627.                 // For back lighting we use the oposite vertex normal
    3628.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    3629.  
    3630.                 #else
    3631.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    3632.  
    3633.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    3634.                 builtinData.opacity = surfaceDescription.Alpha;
    3635.  
    3636.                 #if defined(DEBUG_DISPLAY)
    3637.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    3638.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    3639.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    3640.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    3641.                 #endif
    3642.  
    3643.                 #endif // SHADER_UNLIT
    3644.  
    3645.                 #ifdef _ALPHATEST_ON
    3646.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    3647.                     builtinData.alphaClipTreshold = alphaCutoff;
    3648.                 #endif
    3649.  
    3650.                 // override sampleBakedGI - not used by Unlit
    3651.  
    3652.  
    3653.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    3654.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    3655.                 // This is a limitation of the current MRT approach.
    3656.  
    3657.                 #if _DEPTHOFFSET_ON
    3658.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    3659.                 #endif
    3660.  
    3661.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    3662.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    3663.                 builtinData.distortion = surfaceDescription.Distortion;
    3664.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    3665.                 #endif
    3666.  
    3667.                 #ifndef SHADER_UNLIT
    3668.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    3669.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    3670.                 #else
    3671.                 ApplyDebugToBuiltinData(builtinData);
    3672.                 #endif
    3673.  
    3674.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    3675.             }
    3676.  
    3677.             // --------------------------------------------------
    3678.             // Main
    3679.  
    3680.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"
    3681.  
    3682.             ENDHLSL
    3683.         }
    3684.         Pass
    3685.         {
    3686.             Name "FullScreenDebug"
    3687.             Tags
    3688.             {
    3689.                 "LightMode" = "FullScreenDebug"
    3690.             }
    3691.  
    3692.             // Render State
    3693.             Cull [_CullMode]
    3694.         ZTest LEqual
    3695.         ZWrite Off
    3696.  
    3697.             // Debug
    3698.             // <None>
    3699.  
    3700.             // --------------------------------------------------
    3701.             // Pass
    3702.  
    3703.             HLSLPROGRAM
    3704.  
    3705.             // Pragmas
    3706.             #pragma target 4.5
    3707.         #pragma vertex Vert
    3708.         #pragma fragment Frag
    3709.         #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
    3710.  
    3711.             // Keywords
    3712.             #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    3713.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    3714.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    3715.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    3716.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    3717.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    3718.         #pragma shader_feature_local _ _DISABLE_DECALS
    3719.         #pragma shader_feature_local _ _DISABLE_SSR
    3720.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    3721.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    3722.             // GraphKeywords: <None>
    3723.  
    3724.             // Early Instancing Defines
    3725.             // DotsInstancingOptions: <None>
    3726.  
    3727.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    3728.             // HybridV1InjectedBuiltinProperties: <None>
    3729.  
    3730.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    3731.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    3732.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    3733.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    3734.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    3735.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    3736.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    3737.  
    3738.             // --------------------------------------------------
    3739.             // Defines
    3740.  
    3741.             // Attribute
    3742.             #define ATTRIBUTES_NEED_NORMAL
    3743.             #define ATTRIBUTES_NEED_TANGENT
    3744.  
    3745.             #define HAVE_MESH_MODIFICATION
    3746.  
    3747.  
    3748.             #define SHADERPASS SHADERPASS_FULL_SCREEN_DEBUG
    3749.  
    3750.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    3751.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    3752.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    3753.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    3754.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    3755.             #define RAYTRACING_SHADER_GRAPH_HIGH
    3756.             #endif
    3757.  
    3758.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    3759.             #define RAYTRACING_SHADER_GRAPH_LOW
    3760.             #endif
    3761.             // end
    3762.  
    3763.             #ifndef SHADER_UNLIT
    3764.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    3765.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    3766.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    3767.                 #define VARYINGS_NEED_CULLFACE
    3768.             #endif
    3769.             #endif
    3770.  
    3771.             // Specific Material Define
    3772.         #define _ENERGY_CONSERVING_SPECULAR 1
    3773.  
    3774.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    3775.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    3776.             #define OUTPUT_SPLIT_LIGHTING
    3777.         #endif
    3778.  
    3779.         // This shader support recursive rendering for raytracing
    3780.         #define HAVE_RECURSIVE_RENDERING
    3781.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    3782.  
    3783.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    3784.             // we should have a code like this:
    3785.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    3786.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    3787.             // endif
    3788.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    3789.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    3790.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    3791.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    3792.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    3793.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    3794.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    3795.                 #define WRITE_NORMAL_BUFFER
    3796.             #endif
    3797.             #endif
    3798.  
    3799.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    3800.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    3801.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    3802.             // the constant buffer. A bug is filed and is being looked at.
    3803.             #if defined(SHADER_API_VULKAN)
    3804.             #define DISABLE_UNLIT_DEEXPOSURE
    3805.             #endif
    3806.  
    3807.             #ifndef DEBUG_DISPLAY
    3808.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    3809.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    3810.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    3811.                     #if SHADERPASS == SHADERPASS_FORWARD
    3812.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    3813.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    3814.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    3815.                     #endif
    3816.                 #endif
    3817.             #endif
    3818.  
    3819.             // Translate transparent motion vector define
    3820.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    3821.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    3822.             #endif
    3823.  
    3824.             // -- Graph Properties
    3825.             CBUFFER_START(UnityPerMaterial)
    3826.         float4 _EmissionColor;
    3827.         float _UseShadowThreshold;
    3828.         float4 _DoubleSidedConstants;
    3829.         float _BlendMode;
    3830.         float _EnableBlendModePreserveSpecularLighting;
    3831.         float _RayTracing;
    3832.         float _RefractionModel;
    3833.         CBUFFER_END
    3834.  
    3835.         // Object and Global properties
    3836.  
    3837.             // -- Property used by ScenePickingPass
    3838.             #ifdef SCENEPICKINGPASS
    3839.             float4 _SelectionID;
    3840.             #endif
    3841.  
    3842.             // -- Properties used by SceneSelectionPass
    3843.             #ifdef SCENESELECTIONPASS
    3844.             int _ObjectId;
    3845.             int _PassValue;
    3846.             #endif
    3847.  
    3848.             // Includes
    3849.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
    3850.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    3851.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
    3852.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    3853.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    3854.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    3855.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    3856.  
    3857.             // --------------------------------------------------
    3858.             // Structs and Packing
    3859.  
    3860.             struct AttributesMesh
    3861.         {
    3862.             float3 positionOS : POSITION;
    3863.             float3 normalOS : NORMAL;
    3864.             float4 tangentOS : TANGENT;
    3865.             #if UNITY_ANY_INSTANCING_ENABLED
    3866.             uint instanceID : INSTANCEID_SEMANTIC;
    3867.             #endif
    3868.         };
    3869.         struct VaryingsMeshToPS
    3870.         {
    3871.             float4 positionCS : SV_POSITION;
    3872.             #if UNITY_ANY_INSTANCING_ENABLED
    3873.             uint instanceID : CUSTOM_INSTANCE_ID;
    3874.             #endif
    3875.         };
    3876.         struct SurfaceDescriptionInputs
    3877.         {
    3878.             float3 TangentSpaceNormal;
    3879.         };
    3880.         struct VertexDescriptionInputs
    3881.         {
    3882.             float3 ObjectSpaceNormal;
    3883.             float3 ObjectSpaceTangent;
    3884.             float3 ObjectSpacePosition;
    3885.         };
    3886.         struct PackedVaryingsMeshToPS
    3887.         {
    3888.             float4 positionCS : SV_POSITION;
    3889.             #if UNITY_ANY_INSTANCING_ENABLED
    3890.             uint instanceID : CUSTOM_INSTANCE_ID;
    3891.             #endif
    3892.         };
    3893.  
    3894.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    3895.         {
    3896.             PackedVaryingsMeshToPS output;
    3897.             output.positionCS = input.positionCS;
    3898.             #if UNITY_ANY_INSTANCING_ENABLED
    3899.             output.instanceID = input.instanceID;
    3900.             #endif
    3901.             return output;
    3902.         }
    3903.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    3904.         {
    3905.             VaryingsMeshToPS output;
    3906.             output.positionCS = input.positionCS;
    3907.             #if UNITY_ANY_INSTANCING_ENABLED
    3908.             output.instanceID = input.instanceID;
    3909.             #endif
    3910.             return output;
    3911.         }
    3912.  
    3913.             // --------------------------------------------------
    3914.             // Graph
    3915.  
    3916.  
    3917.             // Graph Functions
    3918.             // GraphFunctions: <None>
    3919.  
    3920.             // Graph Vertex
    3921.             struct VertexDescription
    3922.         {
    3923.             float3 Position;
    3924.             float3 Normal;
    3925.             float3 Tangent;
    3926.         };
    3927.  
    3928.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    3929.         {
    3930.             VertexDescription description = (VertexDescription)0;
    3931.             description.Position = IN.ObjectSpacePosition;
    3932.             description.Normal = IN.ObjectSpaceNormal;
    3933.             description.Tangent = IN.ObjectSpaceTangent;
    3934.             return description;
    3935.         }
    3936.  
    3937.             // Graph Pixel
    3938.             struct SurfaceDescription
    3939.         {
    3940.             float3 BaseColor;
    3941.             float3 Emission;
    3942.             float Alpha;
    3943.             float3 BentNormal;
    3944.             float Smoothness;
    3945.             float Occlusion;
    3946.             float3 NormalTS;
    3947.             float Metallic;
    3948.         };
    3949.  
    3950.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    3951.         {
    3952.             SurfaceDescription surface = (SurfaceDescription)0;
    3953.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    3954.             surface.Emission = float3(0, 0, 0);
    3955.             surface.Alpha = 1;
    3956.             surface.BentNormal = IN.TangentSpaceNormal;
    3957.             surface.Smoothness = 0.5;
    3958.             surface.Occlusion = 1;
    3959.             surface.NormalTS = IN.TangentSpaceNormal;
    3960.             surface.Metallic = 0;
    3961.             return surface;
    3962.         }
    3963.  
    3964.             // --------------------------------------------------
    3965.             // Build Graph Inputs
    3966.  
    3967.            
    3968.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    3969.         {
    3970.             VertexDescriptionInputs output;
    3971.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    3972.  
    3973.             output.ObjectSpaceNormal =           input.normalOS;
    3974.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    3975.             output.ObjectSpacePosition =         input.positionOS;
    3976.  
    3977.             return output;
    3978.         }
    3979.  
    3980.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    3981.         {
    3982.             // build graph inputs
    3983.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    3984.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    3985.  
    3986.             // evaluate vertex graph
    3987.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    3988.  
    3989.             // copy graph output to the results
    3990.             input.positionOS = vertexDescription.Position;
    3991.             input.normalOS = vertexDescription.Normal;
    3992.             input.tangentOS.xyz = vertexDescription.Tangent;
    3993.  
    3994.             return input;
    3995.         }
    3996.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    3997.         {
    3998.             FragInputs output;
    3999.             ZERO_INITIALIZE(FragInputs, output);
    4000.  
    4001.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    4002.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    4003.             // to compute normals which are then passed on elsewhere to compute other values...
    4004.             output.tangentToWorld = k_identity3x3;
    4005.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    4006.  
    4007.  
    4008.             return output;
    4009.         }
    4010.  
    4011.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    4012.         {
    4013.             SurfaceDescriptionInputs output;
    4014.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    4015.  
    4016.             #if defined(SHADER_STAGE_RAY_TRACING)
    4017.             #else
    4018.             #endif
    4019.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    4020.  
    4021.             return output;
    4022.         }
    4023.  
    4024.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    4025.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    4026.         {
    4027.             UNITY_SETUP_INSTANCE_ID(input);
    4028.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    4029.             return BuildFragInputs(unpacked);
    4030.         }
    4031.  
    4032.             // --------------------------------------------------
    4033.             // Build Surface Data (Specific Material)
    4034.  
    4035.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    4036.         {
    4037.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    4038.  
    4039.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    4040.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    4041.             surfaceData.specularOcclusion = 1.0;
    4042.  
    4043.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    4044.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    4045.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    4046.             surfaceData.metallic =                  surfaceDescription.Metallic;
    4047.  
    4048.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    4049.                 if (_EnableSSRefraction)
    4050.                 {
    4051.  
    4052.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    4053.                     surfaceDescription.Alpha = 1.0;
    4054.                 }
    4055.                 else
    4056.                 {
    4057.                     surfaceData.ior = 1.0;
    4058.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    4059.                     surfaceData.atDistance = 1.0;
    4060.                     surfaceData.transmittanceMask = 0.0;
    4061.                     surfaceDescription.Alpha = 1.0;
    4062.                 }
    4063.             #else
    4064.                 surfaceData.ior = 1.0;
    4065.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    4066.                 surfaceData.atDistance = 1.0;
    4067.                 surfaceData.transmittanceMask = 0.0;
    4068.             #endif
    4069.  
    4070.             // These static material feature allow compile time optimization
    4071.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    4072.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    4073.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    4074.             #endif
    4075.  
    4076.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    4077.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    4078.             #endif
    4079.  
    4080.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    4081.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    4082.             #endif
    4083.  
    4084.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    4085.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    4086.             #endif
    4087.  
    4088.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    4089.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    4090.             #endif
    4091.  
    4092.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    4093.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    4094.             #endif
    4095.  
    4096.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    4097.                 // Require to have setup baseColor
    4098.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    4099.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    4100.             #endif
    4101.  
    4102.             #ifdef _DOUBLESIDED_ON
    4103.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    4104.             #else
    4105.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    4106.             #endif
    4107.  
    4108.             // normal delivered to master node
    4109.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    4110.  
    4111.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    4112.  
    4113.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    4114.  
    4115.  
    4116.             #if HAVE_DECALS
    4117.                 if (_EnableDecals)
    4118.                 {
    4119.                     float alpha = 1.0;
    4120.                     alpha = surfaceDescription.Alpha;
    4121.  
    4122.                     // Both uses and modifies 'surfaceData.normalWS'.
    4123.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    4124.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    4125.                 }
    4126.             #endif
    4127.  
    4128.             bentNormalWS = surfaceData.normalWS;
    4129.  
    4130.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    4131.  
    4132.             #ifdef DEBUG_DISPLAY
    4133.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    4134.                 {
    4135.                     // TODO: need to update mip info
    4136.                     surfaceData.metallic = 0;
    4137.                 }
    4138.  
    4139.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    4140.                 // as it can modify attribute use for static lighting
    4141.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    4142.             #endif
    4143.  
    4144.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    4145.             // If user provide bent normal then we process a better term
    4146.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    4147.                 // Just use the value passed through via the slot (not active otherwise)
    4148.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    4149.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    4150.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    4151.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    4152.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    4153.             #endif
    4154.  
    4155.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    4156.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    4157.             #endif
    4158.         }
    4159.  
    4160.             // --------------------------------------------------
    4161.             // Get Surface And BuiltinData
    4162.  
    4163.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    4164.             {
    4165.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    4166.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    4167.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    4168.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    4169.                 #endif
    4170.                 #endif
    4171.  
    4172.                 #ifndef SHADER_UNLIT
    4173.                 #ifdef _DOUBLESIDED_ON
    4174.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    4175.                 #else
    4176.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    4177.                 #endif
    4178.  
    4179.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    4180.                 #endif // SHADER_UNLIT
    4181.  
    4182.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    4183.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    4184.  
    4185.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    4186.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    4187.                 #ifdef _ALPHATEST_ON
    4188.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    4189.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    4190.                     // The TransparentDepthPrepass is also used with SSR transparent.
    4191.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    4192.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    4193.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    4194.                     // DepthPostpass always use its own alpha threshold
    4195.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    4196.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    4197.                     // If use shadow threshold isn't enable we don't allow any test
    4198.                     #endif
    4199.  
    4200.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    4201.                 #endif
    4202.  
    4203.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    4204.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    4205.                 #endif
    4206.  
    4207.                 #ifndef SHADER_UNLIT
    4208.                 float3 bentNormalWS;
    4209.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    4210.  
    4211.                 // Builtin Data
    4212.                 // For back lighting we use the oposite vertex normal
    4213.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    4214.  
    4215.                 #else
    4216.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    4217.  
    4218.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    4219.                 builtinData.opacity = surfaceDescription.Alpha;
    4220.  
    4221.                 #if defined(DEBUG_DISPLAY)
    4222.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    4223.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    4224.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    4225.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    4226.                 #endif
    4227.  
    4228.                 #endif // SHADER_UNLIT
    4229.  
    4230.                 #ifdef _ALPHATEST_ON
    4231.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    4232.                     builtinData.alphaClipTreshold = alphaCutoff;
    4233.                 #endif
    4234.  
    4235.                 // override sampleBakedGI - not used by Unlit
    4236.  
    4237.                 builtinData.emissiveColor = surfaceDescription.Emission;
    4238.  
    4239.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    4240.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    4241.                 // This is a limitation of the current MRT approach.
    4242.  
    4243.                 #if _DEPTHOFFSET_ON
    4244.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    4245.                 #endif
    4246.  
    4247.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    4248.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    4249.                 builtinData.distortion = surfaceDescription.Distortion;
    4250.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    4251.                 #endif
    4252.  
    4253.                 #ifndef SHADER_UNLIT
    4254.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    4255.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    4256.                 #else
    4257.                 ApplyDebugToBuiltinData(builtinData);
    4258.                 #endif
    4259.  
    4260.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    4261.             }
    4262.  
    4263.             // --------------------------------------------------
    4264.             // Main
    4265.  
    4266.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassFullScreenDebug.hlsl"
    4267.  
    4268.             ENDHLSL
    4269.         }
    4270.         Pass
    4271.         {
    4272.             Name "DepthOnly"
    4273.             Tags
    4274.             {
    4275.                 "LightMode" = "DepthOnly"
    4276.             }
    4277.  
    4278.             // Render State
    4279.             Cull [_CullMode]
    4280.         ZWrite On
    4281.         Stencil
    4282.         {
    4283.             WriteMask [_StencilWriteMaskDepth]
    4284.             Ref [_StencilRefDepth]
    4285.             CompFront Always
    4286.             PassFront Replace
    4287.             CompBack Always
    4288.             PassBack Replace
    4289.         }
    4290.  
    4291.             // Debug
    4292.             // <None>
    4293.  
    4294.             // --------------------------------------------------
    4295.             // Pass
    4296.  
    4297.             HLSLPROGRAM
    4298.  
    4299.             // Pragmas
    4300.             #pragma target 4.5
    4301.         #pragma vertex Vert
    4302.         #pragma fragment Frag
    4303.         #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
    4304.         #pragma multi_compile_instancing
    4305.         #pragma instancing_options renderinglayer
    4306.  
    4307.             // Keywords
    4308.             #pragma multi_compile _ WRITE_NORMAL_BUFFER
    4309.         #pragma multi_compile _ WRITE_MSAA_DEPTH
    4310.         #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    4311.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    4312.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    4313.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    4314.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    4315.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    4316.         #pragma shader_feature_local _ _DISABLE_DECALS
    4317.         #pragma shader_feature_local _ _DISABLE_SSR
    4318.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    4319.         #pragma multi_compile _ WRITE_DECAL_BUFFER
    4320.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    4321.             // GraphKeywords: <None>
    4322.  
    4323.             // Early Instancing Defines
    4324.             // DotsInstancingOptions: <None>
    4325.  
    4326.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    4327.             // HybridV1InjectedBuiltinProperties: <None>
    4328.  
    4329.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    4330.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    4331.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    4332.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    4333.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    4334.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    4335.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    4336.  
    4337.             // --------------------------------------------------
    4338.             // Defines
    4339.  
    4340.             // Attribute
    4341.             #define ATTRIBUTES_NEED_NORMAL
    4342.             #define ATTRIBUTES_NEED_TANGENT
    4343.             #define ATTRIBUTES_NEED_TEXCOORD0
    4344.             #define ATTRIBUTES_NEED_TEXCOORD1
    4345.             #define ATTRIBUTES_NEED_TEXCOORD2
    4346.             #define ATTRIBUTES_NEED_TEXCOORD3
    4347.             #define ATTRIBUTES_NEED_COLOR
    4348.             #define VARYINGS_NEED_POSITION_WS
    4349.             #define VARYINGS_NEED_TANGENT_TO_WORLD
    4350.             #define VARYINGS_NEED_TEXCOORD1
    4351.             #define VARYINGS_NEED_TEXCOORD2
    4352.             #define VARYINGS_NEED_TEXCOORD3
    4353.             #define VARYINGS_NEED_COLOR
    4354.  
    4355.             #define HAVE_MESH_MODIFICATION
    4356.  
    4357.  
    4358.             #define SHADERPASS SHADERPASS_DEPTH_ONLY
    4359.         #define RAYTRACING_SHADER_GRAPH_DEFAULT
    4360.  
    4361.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    4362.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    4363.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    4364.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    4365.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    4366.             #define RAYTRACING_SHADER_GRAPH_HIGH
    4367.             #endif
    4368.  
    4369.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    4370.             #define RAYTRACING_SHADER_GRAPH_LOW
    4371.             #endif
    4372.             // end
    4373.  
    4374.             #ifndef SHADER_UNLIT
    4375.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    4376.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    4377.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    4378.                 #define VARYINGS_NEED_CULLFACE
    4379.             #endif
    4380.             #endif
    4381.  
    4382.             // Specific Material Define
    4383.         #define _ENERGY_CONSERVING_SPECULAR 1
    4384.  
    4385.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    4386.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    4387.             #define OUTPUT_SPLIT_LIGHTING
    4388.         #endif
    4389.  
    4390.         // This shader support recursive rendering for raytracing
    4391.         #define HAVE_RECURSIVE_RENDERING
    4392.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    4393.  
    4394.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    4395.             // we should have a code like this:
    4396.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    4397.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    4398.             // endif
    4399.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    4400.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    4401.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    4402.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    4403.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    4404.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    4405.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    4406.                 #define WRITE_NORMAL_BUFFER
    4407.             #endif
    4408.             #endif
    4409.  
    4410.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    4411.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    4412.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    4413.             // the constant buffer. A bug is filed and is being looked at.
    4414.             #if defined(SHADER_API_VULKAN)
    4415.             #define DISABLE_UNLIT_DEEXPOSURE
    4416.             #endif
    4417.  
    4418.             #ifndef DEBUG_DISPLAY
    4419.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    4420.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    4421.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    4422.                     #if SHADERPASS == SHADERPASS_FORWARD
    4423.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    4424.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    4425.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    4426.                     #endif
    4427.                 #endif
    4428.             #endif
    4429.  
    4430.             // Translate transparent motion vector define
    4431.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    4432.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    4433.             #endif
    4434.  
    4435.             // -- Graph Properties
    4436.             CBUFFER_START(UnityPerMaterial)
    4437.         float4 _EmissionColor;
    4438.         float _UseShadowThreshold;
    4439.         float4 _DoubleSidedConstants;
    4440.         float _BlendMode;
    4441.         float _EnableBlendModePreserveSpecularLighting;
    4442.         float _RayTracing;
    4443.         float _RefractionModel;
    4444.         CBUFFER_END
    4445.  
    4446.         // Object and Global properties
    4447.  
    4448.             // -- Property used by ScenePickingPass
    4449.             #ifdef SCENEPICKINGPASS
    4450.             float4 _SelectionID;
    4451.             #endif
    4452.  
    4453.             // -- Properties used by SceneSelectionPass
    4454.             #ifdef SCENESELECTIONPASS
    4455.             int _ObjectId;
    4456.             int _PassValue;
    4457.             #endif
    4458.  
    4459.             // Includes
    4460.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
    4461.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    4462.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
    4463.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    4464.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    4465.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    4466.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
    4467.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"
    4468.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    4469.  
    4470.             // --------------------------------------------------
    4471.             // Structs and Packing
    4472.  
    4473.             struct AttributesMesh
    4474.         {
    4475.             float3 positionOS : POSITION;
    4476.             float3 normalOS : NORMAL;
    4477.             float4 tangentOS : TANGENT;
    4478.             float4 uv0 : TEXCOORD0;
    4479.             float4 uv1 : TEXCOORD1;
    4480.             float4 uv2 : TEXCOORD2;
    4481.             float4 uv3 : TEXCOORD3;
    4482.             float4 color : COLOR;
    4483.             #if UNITY_ANY_INSTANCING_ENABLED
    4484.             uint instanceID : INSTANCEID_SEMANTIC;
    4485.             #endif
    4486.         };
    4487.         struct VaryingsMeshToPS
    4488.         {
    4489.             float4 positionCS : SV_POSITION;
    4490.             float3 positionRWS;
    4491.             float3 normalWS;
    4492.             float4 tangentWS;
    4493.             float4 texCoord1;
    4494.             float4 texCoord2;
    4495.             float4 texCoord3;
    4496.             float4 color;
    4497.             #if UNITY_ANY_INSTANCING_ENABLED
    4498.             uint instanceID : CUSTOM_INSTANCE_ID;
    4499.             #endif
    4500.         };
    4501.         struct SurfaceDescriptionInputs
    4502.         {
    4503.             float3 TangentSpaceNormal;
    4504.         };
    4505.         struct VertexDescriptionInputs
    4506.         {
    4507.             float3 ObjectSpaceNormal;
    4508.             float3 ObjectSpaceTangent;
    4509.             float3 ObjectSpacePosition;
    4510.         };
    4511.         struct PackedVaryingsMeshToPS
    4512.         {
    4513.             float4 positionCS : SV_POSITION;
    4514.             float3 interp0 : TEXCOORD0;
    4515.             float3 interp1 : TEXCOORD1;
    4516.             float4 interp2 : TEXCOORD2;
    4517.             float4 interp3 : TEXCOORD3;
    4518.             float4 interp4 : TEXCOORD4;
    4519.             float4 interp5 : TEXCOORD5;
    4520.             float4 interp6 : TEXCOORD6;
    4521.             #if UNITY_ANY_INSTANCING_ENABLED
    4522.             uint instanceID : CUSTOM_INSTANCE_ID;
    4523.             #endif
    4524.         };
    4525.  
    4526.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    4527.         {
    4528.             PackedVaryingsMeshToPS output;
    4529.             output.positionCS = input.positionCS;
    4530.             output.interp0.xyz =  input.positionRWS;
    4531.             output.interp1.xyz =  input.normalWS;
    4532.             output.interp2.xyzw =  input.tangentWS;
    4533.             output.interp3.xyzw =  input.texCoord1;
    4534.             output.interp4.xyzw =  input.texCoord2;
    4535.             output.interp5.xyzw =  input.texCoord3;
    4536.             output.interp6.xyzw =  input.color;
    4537.             #if UNITY_ANY_INSTANCING_ENABLED
    4538.             output.instanceID = input.instanceID;
    4539.             #endif
    4540.             return output;
    4541.         }
    4542.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    4543.         {
    4544.             VaryingsMeshToPS output;
    4545.             output.positionCS = input.positionCS;
    4546.             output.positionRWS = input.interp0.xyz;
    4547.             output.normalWS = input.interp1.xyz;
    4548.             output.tangentWS = input.interp2.xyzw;
    4549.             output.texCoord1 = input.interp3.xyzw;
    4550.             output.texCoord2 = input.interp4.xyzw;
    4551.             output.texCoord3 = input.interp5.xyzw;
    4552.             output.color = input.interp6.xyzw;
    4553.             #if UNITY_ANY_INSTANCING_ENABLED
    4554.             output.instanceID = input.instanceID;
    4555.             #endif
    4556.             return output;
    4557.         }
    4558.  
    4559.             // --------------------------------------------------
    4560.             // Graph
    4561.  
    4562.  
    4563.             // Graph Functions
    4564.             // GraphFunctions: <None>
    4565.  
    4566.             // Graph Vertex
    4567.             struct VertexDescription
    4568.         {
    4569.             float3 Position;
    4570.             float3 Normal;
    4571.             float3 Tangent;
    4572.         };
    4573.  
    4574.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    4575.         {
    4576.             VertexDescription description = (VertexDescription)0;
    4577.             description.Position = IN.ObjectSpacePosition;
    4578.             description.Normal = IN.ObjectSpaceNormal;
    4579.             description.Tangent = IN.ObjectSpaceTangent;
    4580.             return description;
    4581.         }
    4582.  
    4583.             // Graph Pixel
    4584.             struct SurfaceDescription
    4585.         {
    4586.             float3 BaseColor;
    4587.             float3 Emission;
    4588.             float Alpha;
    4589.             float3 BentNormal;
    4590.             float Smoothness;
    4591.             float Occlusion;
    4592.             float3 NormalTS;
    4593.             float Metallic;
    4594.         };
    4595.  
    4596.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    4597.         {
    4598.             SurfaceDescription surface = (SurfaceDescription)0;
    4599.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    4600.             surface.Emission = float3(0, 0, 0);
    4601.             surface.Alpha = 1;
    4602.             surface.BentNormal = IN.TangentSpaceNormal;
    4603.             surface.Smoothness = 0.5;
    4604.             surface.Occlusion = 1;
    4605.             surface.NormalTS = IN.TangentSpaceNormal;
    4606.             surface.Metallic = 0;
    4607.             return surface;
    4608.         }
    4609.  
    4610.             // --------------------------------------------------
    4611.             // Build Graph Inputs
    4612.  
    4613.            
    4614.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    4615.         {
    4616.             VertexDescriptionInputs output;
    4617.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    4618.  
    4619.             output.ObjectSpaceNormal =           input.normalOS;
    4620.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    4621.             output.ObjectSpacePosition =         input.positionOS;
    4622.  
    4623.             return output;
    4624.         }
    4625.  
    4626.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    4627.         {
    4628.             // build graph inputs
    4629.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    4630.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    4631.  
    4632.             // evaluate vertex graph
    4633.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    4634.  
    4635.             // copy graph output to the results
    4636.             input.positionOS = vertexDescription.Position;
    4637.             input.normalOS = vertexDescription.Normal;
    4638.             input.tangentOS.xyz = vertexDescription.Tangent;
    4639.  
    4640.             return input;
    4641.         }
    4642.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    4643.         {
    4644.             FragInputs output;
    4645.             ZERO_INITIALIZE(FragInputs, output);
    4646.  
    4647.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    4648.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    4649.             // to compute normals which are then passed on elsewhere to compute other values...
    4650.             output.tangentToWorld = k_identity3x3;
    4651.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    4652.  
    4653.             output.positionRWS = input.positionRWS;
    4654.             output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS);
    4655.             output.texCoord1 = input.texCoord1;
    4656.             output.texCoord2 = input.texCoord2;
    4657.             output.texCoord3 = input.texCoord3;
    4658.             output.color = input.color;
    4659.  
    4660.             return output;
    4661.         }
    4662.  
    4663.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    4664.         {
    4665.             SurfaceDescriptionInputs output;
    4666.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    4667.  
    4668.             #if defined(SHADER_STAGE_RAY_TRACING)
    4669.             #else
    4670.             #endif
    4671.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    4672.  
    4673.             return output;
    4674.         }
    4675.  
    4676.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    4677.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    4678.         {
    4679.             UNITY_SETUP_INSTANCE_ID(input);
    4680.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    4681.             return BuildFragInputs(unpacked);
    4682.         }
    4683.  
    4684.             // --------------------------------------------------
    4685.             // Build Surface Data (Specific Material)
    4686.  
    4687.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    4688.         {
    4689.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    4690.  
    4691.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    4692.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    4693.             surfaceData.specularOcclusion = 1.0;
    4694.  
    4695.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    4696.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    4697.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    4698.             surfaceData.metallic =                  surfaceDescription.Metallic;
    4699.  
    4700.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    4701.                 if (_EnableSSRefraction)
    4702.                 {
    4703.  
    4704.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    4705.                     surfaceDescription.Alpha = 1.0;
    4706.                 }
    4707.                 else
    4708.                 {
    4709.                     surfaceData.ior = 1.0;
    4710.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    4711.                     surfaceData.atDistance = 1.0;
    4712.                     surfaceData.transmittanceMask = 0.0;
    4713.                     surfaceDescription.Alpha = 1.0;
    4714.                 }
    4715.             #else
    4716.                 surfaceData.ior = 1.0;
    4717.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    4718.                 surfaceData.atDistance = 1.0;
    4719.                 surfaceData.transmittanceMask = 0.0;
    4720.             #endif
    4721.  
    4722.             // These static material feature allow compile time optimization
    4723.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    4724.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    4725.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    4726.             #endif
    4727.  
    4728.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    4729.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    4730.             #endif
    4731.  
    4732.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    4733.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    4734.             #endif
    4735.  
    4736.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    4737.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    4738.             #endif
    4739.  
    4740.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    4741.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    4742.             #endif
    4743.  
    4744.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    4745.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    4746.             #endif
    4747.  
    4748.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    4749.                 // Require to have setup baseColor
    4750.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    4751.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    4752.             #endif
    4753.  
    4754.             #ifdef _DOUBLESIDED_ON
    4755.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    4756.             #else
    4757.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    4758.             #endif
    4759.  
    4760.             // normal delivered to master node
    4761.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    4762.  
    4763.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    4764.  
    4765.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    4766.  
    4767.  
    4768.             #if HAVE_DECALS
    4769.                 if (_EnableDecals)
    4770.                 {
    4771.                     float alpha = 1.0;
    4772.                     alpha = surfaceDescription.Alpha;
    4773.  
    4774.                     // Both uses and modifies 'surfaceData.normalWS'.
    4775.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    4776.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    4777.                 }
    4778.             #endif
    4779.  
    4780.             bentNormalWS = surfaceData.normalWS;
    4781.  
    4782.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    4783.  
    4784.             #ifdef DEBUG_DISPLAY
    4785.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    4786.                 {
    4787.                     // TODO: need to update mip info
    4788.                     surfaceData.metallic = 0;
    4789.                 }
    4790.  
    4791.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    4792.                 // as it can modify attribute use for static lighting
    4793.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    4794.             #endif
    4795.  
    4796.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    4797.             // If user provide bent normal then we process a better term
    4798.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    4799.                 // Just use the value passed through via the slot (not active otherwise)
    4800.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    4801.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    4802.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    4803.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    4804.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    4805.             #endif
    4806.  
    4807.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    4808.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    4809.             #endif
    4810.         }
    4811.  
    4812.             // --------------------------------------------------
    4813.             // Get Surface And BuiltinData
    4814.  
    4815.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    4816.             {
    4817.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    4818.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    4819.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    4820.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    4821.                 #endif
    4822.                 #endif
    4823.  
    4824.                 #ifndef SHADER_UNLIT
    4825.                 #ifdef _DOUBLESIDED_ON
    4826.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    4827.                 #else
    4828.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    4829.                 #endif
    4830.  
    4831.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    4832.                 #endif // SHADER_UNLIT
    4833.  
    4834.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    4835.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    4836.  
    4837.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    4838.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    4839.                 #ifdef _ALPHATEST_ON
    4840.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    4841.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    4842.                     // The TransparentDepthPrepass is also used with SSR transparent.
    4843.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    4844.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    4845.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    4846.                     // DepthPostpass always use its own alpha threshold
    4847.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    4848.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    4849.                     // If use shadow threshold isn't enable we don't allow any test
    4850.                     #endif
    4851.  
    4852.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    4853.                 #endif
    4854.  
    4855.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    4856.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    4857.                 #endif
    4858.  
    4859.                 #ifndef SHADER_UNLIT
    4860.                 float3 bentNormalWS;
    4861.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    4862.  
    4863.                 // Builtin Data
    4864.                 // For back lighting we use the oposite vertex normal
    4865.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    4866.  
    4867.                 #else
    4868.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    4869.  
    4870.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    4871.                 builtinData.opacity = surfaceDescription.Alpha;
    4872.  
    4873.                 #if defined(DEBUG_DISPLAY)
    4874.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    4875.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    4876.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    4877.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    4878.                 #endif
    4879.  
    4880.                 #endif // SHADER_UNLIT
    4881.  
    4882.                 #ifdef _ALPHATEST_ON
    4883.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    4884.                     builtinData.alphaClipTreshold = alphaCutoff;
    4885.                 #endif
    4886.  
    4887.                 // override sampleBakedGI - not used by Unlit
    4888.  
    4889.                 builtinData.emissiveColor = surfaceDescription.Emission;
    4890.  
    4891.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    4892.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    4893.                 // This is a limitation of the current MRT approach.
    4894.  
    4895.                 #if _DEPTHOFFSET_ON
    4896.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    4897.                 #endif
    4898.  
    4899.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    4900.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    4901.                 builtinData.distortion = surfaceDescription.Distortion;
    4902.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    4903.                 #endif
    4904.  
    4905.                 #ifndef SHADER_UNLIT
    4906.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    4907.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    4908.                 #else
    4909.                 ApplyDebugToBuiltinData(builtinData);
    4910.                 #endif
    4911.  
    4912.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    4913.             }
    4914.  
    4915.             // --------------------------------------------------
    4916.             // Main
    4917.  
    4918.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"
    4919.  
    4920.             ENDHLSL
    4921.         }
    4922.         Pass
    4923.         {
    4924.             Name "GBuffer"
    4925.             Tags
    4926.             {
    4927.                 "LightMode" = "GBuffer"
    4928.             }
    4929.  
    4930.             // Render State
    4931.             Cull [_CullMode]
    4932.         ZTest [_ZTestGBuffer]
    4933.         Stencil
    4934.         {
    4935.             WriteMask [_StencilWriteMaskGBuffer]
    4936.             Ref [_StencilRefGBuffer]
    4937.             CompFront Always
    4938.             PassFront Replace
    4939.             CompBack Always
    4940.             PassBack Replace
    4941.         }
    4942.  
    4943.             // Debug
    4944.             // <None>
    4945.  
    4946.             // --------------------------------------------------
    4947.             // Pass
    4948.  
    4949.             HLSLPROGRAM
    4950.  
    4951.             // Pragmas
    4952.             #pragma target 4.5
    4953.         #pragma vertex Vert
    4954.         #pragma fragment Frag
    4955.         #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
    4956.         #pragma multi_compile_instancing
    4957.         #pragma instancing_options renderinglayer
    4958.  
    4959.             // Keywords
    4960.             #pragma multi_compile _ LIGHT_LAYERS
    4961.         #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    4962.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    4963.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    4964.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    4965.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    4966.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    4967.         #pragma multi_compile _ DEBUG_DISPLAY
    4968.         #pragma shader_feature_local _ _DISABLE_DECALS
    4969.         #pragma shader_feature_local _ _DISABLE_SSR
    4970.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    4971.         #pragma multi_compile _ LIGHTMAP_ON
    4972.         #pragma multi_compile _ DIRLIGHTMAP_COMBINED
    4973.         #pragma multi_compile _ DYNAMICLIGHTMAP_ON
    4974.         #pragma multi_compile _ SHADOWS_SHADOWMASK
    4975.         #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
    4976.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    4977.             // GraphKeywords: <None>
    4978.  
    4979.             // Early Instancing Defines
    4980.             // DotsInstancingOptions: <None>
    4981.  
    4982.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    4983.             // HybridV1InjectedBuiltinProperties: <None>
    4984.  
    4985.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    4986.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    4987.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    4988.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    4989.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    4990.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    4991.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    4992.  
    4993.             // --------------------------------------------------
    4994.             // Defines
    4995.  
    4996.             // Attribute
    4997.             #define ATTRIBUTES_NEED_NORMAL
    4998.             #define ATTRIBUTES_NEED_TANGENT
    4999.             #define ATTRIBUTES_NEED_TEXCOORD1
    5000.             #define ATTRIBUTES_NEED_TEXCOORD2
    5001.             #define VARYINGS_NEED_POSITION_WS
    5002.             #define VARYINGS_NEED_TANGENT_TO_WORLD
    5003.             #define VARYINGS_NEED_TEXCOORD1
    5004.             #define VARYINGS_NEED_TEXCOORD2
    5005.  
    5006.             #define HAVE_MESH_MODIFICATION
    5007.  
    5008.  
    5009.             #define SHADERPASS SHADERPASS_GBUFFER
    5010.         #define RAYTRACING_SHADER_GRAPH_DEFAULT
    5011.  
    5012.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    5013.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    5014.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    5015.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    5016.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    5017.             #define RAYTRACING_SHADER_GRAPH_HIGH
    5018.             #endif
    5019.  
    5020.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    5021.             #define RAYTRACING_SHADER_GRAPH_LOW
    5022.             #endif
    5023.             // end
    5024.  
    5025.             #ifndef SHADER_UNLIT
    5026.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    5027.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    5028.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    5029.                 #define VARYINGS_NEED_CULLFACE
    5030.             #endif
    5031.             #endif
    5032.  
    5033.             // Specific Material Define
    5034.         #define _ENERGY_CONSERVING_SPECULAR 1
    5035.  
    5036.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    5037.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    5038.             #define OUTPUT_SPLIT_LIGHTING
    5039.         #endif
    5040.  
    5041.         // This shader support recursive rendering for raytracing
    5042.         #define HAVE_RECURSIVE_RENDERING
    5043.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    5044.  
    5045.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    5046.             // we should have a code like this:
    5047.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    5048.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    5049.             // endif
    5050.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    5051.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    5052.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    5053.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    5054.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    5055.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    5056.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    5057.                 #define WRITE_NORMAL_BUFFER
    5058.             #endif
    5059.             #endif
    5060.  
    5061.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    5062.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    5063.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    5064.             // the constant buffer. A bug is filed and is being looked at.
    5065.             #if defined(SHADER_API_VULKAN)
    5066.             #define DISABLE_UNLIT_DEEXPOSURE
    5067.             #endif
    5068.  
    5069.             #ifndef DEBUG_DISPLAY
    5070.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    5071.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    5072.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    5073.                     #if SHADERPASS == SHADERPASS_FORWARD
    5074.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    5075.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    5076.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    5077.                     #endif
    5078.                 #endif
    5079.             #endif
    5080.  
    5081.             // Translate transparent motion vector define
    5082.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    5083.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    5084.             #endif
    5085.  
    5086.             // -- Graph Properties
    5087.             CBUFFER_START(UnityPerMaterial)
    5088.         float4 _EmissionColor;
    5089.         float _UseShadowThreshold;
    5090.         float4 _DoubleSidedConstants;
    5091.         float _BlendMode;
    5092.         float _EnableBlendModePreserveSpecularLighting;
    5093.         float _RayTracing;
    5094.         float _RefractionModel;
    5095.         CBUFFER_END
    5096.  
    5097.         // Object and Global properties
    5098.  
    5099.             // -- Property used by ScenePickingPass
    5100.             #ifdef SCENEPICKINGPASS
    5101.             float4 _SelectionID;
    5102.             #endif
    5103.  
    5104.             // -- Properties used by SceneSelectionPass
    5105.             #ifdef SCENESELECTIONPASS
    5106.             int _ObjectId;
    5107.             int _PassValue;
    5108.             #endif
    5109.  
    5110.             // Includes
    5111.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
    5112.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    5113.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
    5114.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    5115.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    5116.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    5117.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
    5118.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"
    5119.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    5120.  
    5121.             // --------------------------------------------------
    5122.             // Structs and Packing
    5123.  
    5124.             struct AttributesMesh
    5125.         {
    5126.             float3 positionOS : POSITION;
    5127.             float3 normalOS : NORMAL;
    5128.             float4 tangentOS : TANGENT;
    5129.             float4 uv1 : TEXCOORD1;
    5130.             float4 uv2 : TEXCOORD2;
    5131.             #if UNITY_ANY_INSTANCING_ENABLED
    5132.             uint instanceID : INSTANCEID_SEMANTIC;
    5133.             #endif
    5134.         };
    5135.         struct VaryingsMeshToPS
    5136.         {
    5137.             float4 positionCS : SV_POSITION;
    5138.             float3 positionRWS;
    5139.             float3 normalWS;
    5140.             float4 tangentWS;
    5141.             float4 texCoord1;
    5142.             float4 texCoord2;
    5143.             #if UNITY_ANY_INSTANCING_ENABLED
    5144.             uint instanceID : CUSTOM_INSTANCE_ID;
    5145.             #endif
    5146.         };
    5147.         struct SurfaceDescriptionInputs
    5148.         {
    5149.             float3 TangentSpaceNormal;
    5150.         };
    5151.         struct VertexDescriptionInputs
    5152.         {
    5153.             float3 ObjectSpaceNormal;
    5154.             float3 ObjectSpaceTangent;
    5155.             float3 ObjectSpacePosition;
    5156.         };
    5157.         struct PackedVaryingsMeshToPS
    5158.         {
    5159.             float4 positionCS : SV_POSITION;
    5160.             float3 interp0 : TEXCOORD0;
    5161.             float3 interp1 : TEXCOORD1;
    5162.             float4 interp2 : TEXCOORD2;
    5163.             float4 interp3 : TEXCOORD3;
    5164.             float4 interp4 : TEXCOORD4;
    5165.             #if UNITY_ANY_INSTANCING_ENABLED
    5166.             uint instanceID : CUSTOM_INSTANCE_ID;
    5167.             #endif
    5168.         };
    5169.  
    5170.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    5171.         {
    5172.             PackedVaryingsMeshToPS output;
    5173.             output.positionCS = input.positionCS;
    5174.             output.interp0.xyz =  input.positionRWS;
    5175.             output.interp1.xyz =  input.normalWS;
    5176.             output.interp2.xyzw =  input.tangentWS;
    5177.             output.interp3.xyzw =  input.texCoord1;
    5178.             output.interp4.xyzw =  input.texCoord2;
    5179.             #if UNITY_ANY_INSTANCING_ENABLED
    5180.             output.instanceID = input.instanceID;
    5181.             #endif
    5182.             return output;
    5183.         }
    5184.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    5185.         {
    5186.             VaryingsMeshToPS output;
    5187.             output.positionCS = input.positionCS;
    5188.             output.positionRWS = input.interp0.xyz;
    5189.             output.normalWS = input.interp1.xyz;
    5190.             output.tangentWS = input.interp2.xyzw;
    5191.             output.texCoord1 = input.interp3.xyzw;
    5192.             output.texCoord2 = input.interp4.xyzw;
    5193.             #if UNITY_ANY_INSTANCING_ENABLED
    5194.             output.instanceID = input.instanceID;
    5195.             #endif
    5196.             return output;
    5197.         }
    5198.  
    5199.             // --------------------------------------------------
    5200.             // Graph
    5201.  
    5202.  
    5203.             // Graph Functions
    5204.             // GraphFunctions: <None>
    5205.  
    5206.             // Graph Vertex
    5207.             struct VertexDescription
    5208.         {
    5209.             float3 Position;
    5210.             float3 Normal;
    5211.             float3 Tangent;
    5212.         };
    5213.  
    5214.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    5215.         {
    5216.             VertexDescription description = (VertexDescription)0;
    5217.             description.Position = IN.ObjectSpacePosition;
    5218.             description.Normal = IN.ObjectSpaceNormal;
    5219.             description.Tangent = IN.ObjectSpaceTangent;
    5220.             return description;
    5221.         }
    5222.  
    5223.             // Graph Pixel
    5224.             struct SurfaceDescription
    5225.         {
    5226.             float3 BaseColor;
    5227.             float3 Emission;
    5228.             float Alpha;
    5229.             float3 BentNormal;
    5230.             float Smoothness;
    5231.             float Occlusion;
    5232.             float3 NormalTS;
    5233.             float Metallic;
    5234.             float4 VTPackedFeedback;
    5235.         };
    5236.  
    5237.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    5238.         {
    5239.             SurfaceDescription surface = (SurfaceDescription)0;
    5240.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    5241.             surface.Emission = float3(0, 0, 0);
    5242.             surface.Alpha = 1;
    5243.             surface.BentNormal = IN.TangentSpaceNormal;
    5244.             surface.Smoothness = 0.5;
    5245.             surface.Occlusion = 1;
    5246.             surface.NormalTS = IN.TangentSpaceNormal;
    5247.             surface.Metallic = 0;
    5248.             {
    5249.                 surface.VTPackedFeedback = float4(1.0f,1.0f,1.0f,.0f);
    5250.             }
    5251.             return surface;
    5252.         }
    5253.  
    5254.             // --------------------------------------------------
    5255.             // Build Graph Inputs
    5256.  
    5257.            
    5258.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    5259.         {
    5260.             VertexDescriptionInputs output;
    5261.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    5262.  
    5263.             output.ObjectSpaceNormal =           input.normalOS;
    5264.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    5265.             output.ObjectSpacePosition =         input.positionOS;
    5266.  
    5267.             return output;
    5268.         }
    5269.  
    5270.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    5271.         {
    5272.             // build graph inputs
    5273.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    5274.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    5275.  
    5276.             // evaluate vertex graph
    5277.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    5278.  
    5279.             // copy graph output to the results
    5280.             input.positionOS = vertexDescription.Position;
    5281.             input.normalOS = vertexDescription.Normal;
    5282.             input.tangentOS.xyz = vertexDescription.Tangent;
    5283.  
    5284.             return input;
    5285.         }
    5286.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    5287.         {
    5288.             FragInputs output;
    5289.             ZERO_INITIALIZE(FragInputs, output);
    5290.  
    5291.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    5292.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    5293.             // to compute normals which are then passed on elsewhere to compute other values...
    5294.             output.tangentToWorld = k_identity3x3;
    5295.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    5296.  
    5297.             output.positionRWS = input.positionRWS;
    5298.             output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS);
    5299.             output.texCoord1 = input.texCoord1;
    5300.             output.texCoord2 = input.texCoord2;
    5301.  
    5302.             return output;
    5303.         }
    5304.  
    5305.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    5306.         {
    5307.             SurfaceDescriptionInputs output;
    5308.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    5309.  
    5310.             #if defined(SHADER_STAGE_RAY_TRACING)
    5311.             #else
    5312.             #endif
    5313.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    5314.  
    5315.             return output;
    5316.         }
    5317.  
    5318.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    5319.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    5320.         {
    5321.             UNITY_SETUP_INSTANCE_ID(input);
    5322.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    5323.             return BuildFragInputs(unpacked);
    5324.         }
    5325.  
    5326.             // --------------------------------------------------
    5327.             // Build Surface Data (Specific Material)
    5328.  
    5329.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    5330.         {
    5331.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    5332.  
    5333.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    5334.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    5335.             surfaceData.specularOcclusion = 1.0;
    5336.  
    5337.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    5338.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    5339.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    5340.             surfaceData.metallic =                  surfaceDescription.Metallic;
    5341.  
    5342.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    5343.                 if (_EnableSSRefraction)
    5344.                 {
    5345.  
    5346.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    5347.                     surfaceDescription.Alpha = 1.0;
    5348.                 }
    5349.                 else
    5350.                 {
    5351.                     surfaceData.ior = 1.0;
    5352.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    5353.                     surfaceData.atDistance = 1.0;
    5354.                     surfaceData.transmittanceMask = 0.0;
    5355.                     surfaceDescription.Alpha = 1.0;
    5356.                 }
    5357.             #else
    5358.                 surfaceData.ior = 1.0;
    5359.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    5360.                 surfaceData.atDistance = 1.0;
    5361.                 surfaceData.transmittanceMask = 0.0;
    5362.             #endif
    5363.  
    5364.             // These static material feature allow compile time optimization
    5365.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    5366.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    5367.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    5368.             #endif
    5369.  
    5370.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    5371.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    5372.             #endif
    5373.  
    5374.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    5375.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    5376.             #endif
    5377.  
    5378.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    5379.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    5380.             #endif
    5381.  
    5382.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    5383.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    5384.             #endif
    5385.  
    5386.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    5387.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    5388.             #endif
    5389.  
    5390.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    5391.                 // Require to have setup baseColor
    5392.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    5393.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    5394.             #endif
    5395.  
    5396.             #ifdef _DOUBLESIDED_ON
    5397.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    5398.             #else
    5399.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    5400.             #endif
    5401.  
    5402.             // normal delivered to master node
    5403.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    5404.  
    5405.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    5406.  
    5407.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    5408.  
    5409.  
    5410.             #if HAVE_DECALS
    5411.                 if (_EnableDecals)
    5412.                 {
    5413.                     float alpha = 1.0;
    5414.                     alpha = surfaceDescription.Alpha;
    5415.  
    5416.                     // Both uses and modifies 'surfaceData.normalWS'.
    5417.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    5418.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    5419.                 }
    5420.             #endif
    5421.  
    5422.             bentNormalWS = surfaceData.normalWS;
    5423.  
    5424.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    5425.  
    5426.             #ifdef DEBUG_DISPLAY
    5427.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    5428.                 {
    5429.                     // TODO: need to update mip info
    5430.                     surfaceData.metallic = 0;
    5431.                 }
    5432.  
    5433.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    5434.                 // as it can modify attribute use for static lighting
    5435.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    5436.             #endif
    5437.  
    5438.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    5439.             // If user provide bent normal then we process a better term
    5440.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    5441.                 // Just use the value passed through via the slot (not active otherwise)
    5442.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    5443.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    5444.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    5445.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    5446.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    5447.             #endif
    5448.  
    5449.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    5450.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    5451.             #endif
    5452.         }
    5453.  
    5454.             // --------------------------------------------------
    5455.             // Get Surface And BuiltinData
    5456.  
    5457.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    5458.             {
    5459.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    5460.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    5461.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    5462.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    5463.                 #endif
    5464.                 #endif
    5465.  
    5466.                 #ifndef SHADER_UNLIT
    5467.                 #ifdef _DOUBLESIDED_ON
    5468.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    5469.                 #else
    5470.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    5471.                 #endif
    5472.  
    5473.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    5474.                 #endif // SHADER_UNLIT
    5475.  
    5476.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    5477.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    5478.  
    5479.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    5480.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    5481.                 #ifdef _ALPHATEST_ON
    5482.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    5483.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    5484.                     // The TransparentDepthPrepass is also used with SSR transparent.
    5485.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    5486.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    5487.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    5488.                     // DepthPostpass always use its own alpha threshold
    5489.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    5490.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    5491.                     // If use shadow threshold isn't enable we don't allow any test
    5492.                     #endif
    5493.  
    5494.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    5495.                 #endif
    5496.  
    5497.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    5498.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    5499.                 #endif
    5500.  
    5501.                 #ifndef SHADER_UNLIT
    5502.                 float3 bentNormalWS;
    5503.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    5504.  
    5505.                 // Builtin Data
    5506.                 // For back lighting we use the oposite vertex normal
    5507.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    5508.  
    5509.                 #else
    5510.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    5511.  
    5512.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    5513.                 builtinData.opacity = surfaceDescription.Alpha;
    5514.  
    5515.                 #if defined(DEBUG_DISPLAY)
    5516.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    5517.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    5518.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    5519.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    5520.                 #endif
    5521.  
    5522.                 #endif // SHADER_UNLIT
    5523.  
    5524.                 #ifdef _ALPHATEST_ON
    5525.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    5526.                     builtinData.alphaClipTreshold = alphaCutoff;
    5527.                 #endif
    5528.  
    5529.                 // override sampleBakedGI - not used by Unlit
    5530.  
    5531.                 builtinData.emissiveColor = surfaceDescription.Emission;
    5532.  
    5533.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    5534.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    5535.                 // This is a limitation of the current MRT approach.
    5536.                 builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback;
    5537.  
    5538.                 #if _DEPTHOFFSET_ON
    5539.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    5540.                 #endif
    5541.  
    5542.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    5543.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    5544.                 builtinData.distortion = surfaceDescription.Distortion;
    5545.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    5546.                 #endif
    5547.  
    5548.                 #ifndef SHADER_UNLIT
    5549.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    5550.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    5551.                 #else
    5552.                 ApplyDebugToBuiltinData(builtinData);
    5553.                 #endif
    5554.  
    5555.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    5556.             }
    5557.  
    5558.             // --------------------------------------------------
    5559.             // Main
    5560.  
    5561.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"
    5562.  
    5563.             ENDHLSL
    5564.         }
    5565.         Pass
    5566.         {
    5567.             Name "Forward"
    5568.             Tags
    5569.             {
    5570.                 "LightMode" = "Forward"
    5571.             }
    5572.  
    5573.             // Render State
    5574.             Cull [_CullModeForward]
    5575.         Blend [_SrcBlend] [_DstBlend], [_AlphaSrcBlend] [_AlphaDstBlend]
    5576.         ZTest [_ZTestDepthEqualForOpaque]
    5577.         ZWrite [_ZWrite]
    5578.         ColorMask [_ColorMaskTransparentVel] 1
    5579.         Stencil
    5580.         {
    5581.             WriteMask [_StencilWriteMask]
    5582.             Ref [_StencilRef]
    5583.             CompFront Always
    5584.             PassFront Replace
    5585.             CompBack Always
    5586.             PassBack Replace
    5587.         }
    5588.  
    5589.             // Debug
    5590.             // <None>
    5591.  
    5592.             // --------------------------------------------------
    5593.             // Pass
    5594.  
    5595.             HLSLPROGRAM
    5596.  
    5597.             // Pragmas
    5598.             #pragma target 4.5
    5599.         #pragma vertex Vert
    5600.         #pragma fragment Frag
    5601.         #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
    5602.         #pragma multi_compile_instancing
    5603.         #pragma instancing_options renderinglayer
    5604.  
    5605.             // Keywords
    5606.             #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    5607.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    5608.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    5609.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    5610.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    5611.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    5612.         #pragma multi_compile _ DEBUG_DISPLAY
    5613.         #pragma shader_feature_local _ _DISABLE_DECALS
    5614.         #pragma shader_feature_local _ _DISABLE_SSR
    5615.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    5616.         #pragma multi_compile _ LIGHTMAP_ON
    5617.         #pragma multi_compile _ DIRLIGHTMAP_COMBINED
    5618.         #pragma multi_compile _ DYNAMICLIGHTMAP_ON
    5619.         #pragma multi_compile _ SHADOWS_SHADOWMASK
    5620.         #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
    5621.         #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH
    5622.         #pragma multi_compile SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON
    5623.         #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
    5624.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    5625.             // GraphKeywords: <None>
    5626.  
    5627.             // Early Instancing Defines
    5628.             // DotsInstancingOptions: <None>
    5629.  
    5630.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    5631.             // HybridV1InjectedBuiltinProperties: <None>
    5632.  
    5633.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    5634.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    5635.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    5636.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    5637.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    5638.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    5639.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    5640.  
    5641.             // --------------------------------------------------
    5642.             // Defines
    5643.  
    5644.             // Attribute
    5645.             #define ATTRIBUTES_NEED_NORMAL
    5646.             #define ATTRIBUTES_NEED_TANGENT
    5647.             #define ATTRIBUTES_NEED_TEXCOORD1
    5648.             #define ATTRIBUTES_NEED_TEXCOORD2
    5649.             #define VARYINGS_NEED_POSITION_WS
    5650.             #define VARYINGS_NEED_TANGENT_TO_WORLD
    5651.             #define VARYINGS_NEED_TEXCOORD1
    5652.             #define VARYINGS_NEED_TEXCOORD2
    5653.  
    5654.             #define HAVE_MESH_MODIFICATION
    5655.  
    5656.  
    5657.             #define SHADERPASS SHADERPASS_FORWARD
    5658.         #define SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING
    5659.         #define HAS_LIGHTLOOP
    5660.         #define RAYTRACING_SHADER_GRAPH_DEFAULT
    5661.  
    5662.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    5663.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    5664.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    5665.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    5666.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    5667.             #define RAYTRACING_SHADER_GRAPH_HIGH
    5668.             #endif
    5669.  
    5670.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    5671.             #define RAYTRACING_SHADER_GRAPH_LOW
    5672.             #endif
    5673.             // end
    5674.  
    5675.             #ifndef SHADER_UNLIT
    5676.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    5677.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    5678.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    5679.                 #define VARYINGS_NEED_CULLFACE
    5680.             #endif
    5681.             #endif
    5682.  
    5683.             // Specific Material Define
    5684.         #define _ENERGY_CONSERVING_SPECULAR 1
    5685.  
    5686.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    5687.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    5688.             #define OUTPUT_SPLIT_LIGHTING
    5689.         #endif
    5690.  
    5691.         // This shader support recursive rendering for raytracing
    5692.         #define HAVE_RECURSIVE_RENDERING
    5693.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    5694.  
    5695.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    5696.             // we should have a code like this:
    5697.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    5698.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    5699.             // endif
    5700.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    5701.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    5702.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    5703.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    5704.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    5705.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    5706.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    5707.                 #define WRITE_NORMAL_BUFFER
    5708.             #endif
    5709.             #endif
    5710.  
    5711.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    5712.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    5713.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    5714.             // the constant buffer. A bug is filed and is being looked at.
    5715.             #if defined(SHADER_API_VULKAN)
    5716.             #define DISABLE_UNLIT_DEEXPOSURE
    5717.             #endif
    5718.  
    5719.             #ifndef DEBUG_DISPLAY
    5720.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    5721.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    5722.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    5723.                     #if SHADERPASS == SHADERPASS_FORWARD
    5724.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    5725.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    5726.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    5727.                     #endif
    5728.                 #endif
    5729.             #endif
    5730.  
    5731.             // Translate transparent motion vector define
    5732.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    5733.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    5734.             #endif
    5735.  
    5736.             // -- Graph Properties
    5737.             CBUFFER_START(UnityPerMaterial)
    5738.         float4 _EmissionColor;
    5739.         float _UseShadowThreshold;
    5740.         float4 _DoubleSidedConstants;
    5741.         float _BlendMode;
    5742.         float _EnableBlendModePreserveSpecularLighting;
    5743.         float _RayTracing;
    5744.         float _RefractionModel;
    5745.         CBUFFER_END
    5746.  
    5747.         // Object and Global properties
    5748.  
    5749.             // -- Property used by ScenePickingPass
    5750.             #ifdef SCENEPICKINGPASS
    5751.             float4 _SelectionID;
    5752.             #endif
    5753.  
    5754.             // -- Properties used by SceneSelectionPass
    5755.             #ifdef SCENESELECTIONPASS
    5756.             int _ObjectId;
    5757.             int _PassValue;
    5758.             #endif
    5759.  
    5760.             // Includes
    5761.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
    5762.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    5763.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
    5764.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"
    5765.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl"
    5766.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    5767.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl"
    5768.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    5769.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    5770.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
    5771.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"
    5772.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    5773.  
    5774.             // --------------------------------------------------
    5775.             // Structs and Packing
    5776.  
    5777.             struct AttributesMesh
    5778.         {
    5779.             float3 positionOS : POSITION;
    5780.             float3 normalOS : NORMAL;
    5781.             float4 tangentOS : TANGENT;
    5782.             float4 uv1 : TEXCOORD1;
    5783.             float4 uv2 : TEXCOORD2;
    5784.             #if UNITY_ANY_INSTANCING_ENABLED
    5785.             uint instanceID : INSTANCEID_SEMANTIC;
    5786.             #endif
    5787.         };
    5788.         struct VaryingsMeshToPS
    5789.         {
    5790.             float4 positionCS : SV_POSITION;
    5791.             float3 positionRWS;
    5792.             float3 normalWS;
    5793.             float4 tangentWS;
    5794.             float4 texCoord1;
    5795.             float4 texCoord2;
    5796.             #if UNITY_ANY_INSTANCING_ENABLED
    5797.             uint instanceID : CUSTOM_INSTANCE_ID;
    5798.             #endif
    5799.         };
    5800.         struct SurfaceDescriptionInputs
    5801.         {
    5802.             float3 TangentSpaceNormal;
    5803.         };
    5804.         struct VertexDescriptionInputs
    5805.         {
    5806.             float3 ObjectSpaceNormal;
    5807.             float3 ObjectSpaceTangent;
    5808.             float3 ObjectSpacePosition;
    5809.         };
    5810.         struct PackedVaryingsMeshToPS
    5811.         {
    5812.             float4 positionCS : SV_POSITION;
    5813.             float3 interp0 : TEXCOORD0;
    5814.             float3 interp1 : TEXCOORD1;
    5815.             float4 interp2 : TEXCOORD2;
    5816.             float4 interp3 : TEXCOORD3;
    5817.             float4 interp4 : TEXCOORD4;
    5818.             #if UNITY_ANY_INSTANCING_ENABLED
    5819.             uint instanceID : CUSTOM_INSTANCE_ID;
    5820.             #endif
    5821.         };
    5822.  
    5823.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    5824.         {
    5825.             PackedVaryingsMeshToPS output;
    5826.             output.positionCS = input.positionCS;
    5827.             output.interp0.xyz =  input.positionRWS;
    5828.             output.interp1.xyz =  input.normalWS;
    5829.             output.interp2.xyzw =  input.tangentWS;
    5830.             output.interp3.xyzw =  input.texCoord1;
    5831.             output.interp4.xyzw =  input.texCoord2;
    5832.             #if UNITY_ANY_INSTANCING_ENABLED
    5833.             output.instanceID = input.instanceID;
    5834.             #endif
    5835.             return output;
    5836.         }
    5837.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    5838.         {
    5839.             VaryingsMeshToPS output;
    5840.             output.positionCS = input.positionCS;
    5841.             output.positionRWS = input.interp0.xyz;
    5842.             output.normalWS = input.interp1.xyz;
    5843.             output.tangentWS = input.interp2.xyzw;
    5844.             output.texCoord1 = input.interp3.xyzw;
    5845.             output.texCoord2 = input.interp4.xyzw;
    5846.             #if UNITY_ANY_INSTANCING_ENABLED
    5847.             output.instanceID = input.instanceID;
    5848.             #endif
    5849.             return output;
    5850.         }
    5851.  
    5852.             // --------------------------------------------------
    5853.             // Graph
    5854.  
    5855.  
    5856.             // Graph Functions
    5857.             // GraphFunctions: <None>
    5858.  
    5859.             // Graph Vertex
    5860.             struct VertexDescription
    5861.         {
    5862.             float3 Position;
    5863.             float3 Normal;
    5864.             float3 Tangent;
    5865.         };
    5866.  
    5867.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    5868.         {
    5869.             VertexDescription description = (VertexDescription)0;
    5870.             description.Position = IN.ObjectSpacePosition;
    5871.             description.Normal = IN.ObjectSpaceNormal;
    5872.             description.Tangent = IN.ObjectSpaceTangent;
    5873.             return description;
    5874.         }
    5875.  
    5876.             // Graph Pixel
    5877.             struct SurfaceDescription
    5878.         {
    5879.             float3 BaseColor;
    5880.             float3 Emission;
    5881.             float Alpha;
    5882.             float3 BentNormal;
    5883.             float Smoothness;
    5884.             float Occlusion;
    5885.             float3 NormalTS;
    5886.             float Metallic;
    5887.             float4 VTPackedFeedback;
    5888.         };
    5889.  
    5890.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    5891.         {
    5892.             SurfaceDescription surface = (SurfaceDescription)0;
    5893.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    5894.             surface.Emission = float3(0, 0, 0);
    5895.             surface.Alpha = 1;
    5896.             surface.BentNormal = IN.TangentSpaceNormal;
    5897.             surface.Smoothness = 0.5;
    5898.             surface.Occlusion = 1;
    5899.             surface.NormalTS = IN.TangentSpaceNormal;
    5900.             surface.Metallic = 0;
    5901.             {
    5902.                 surface.VTPackedFeedback = float4(1.0f,1.0f,1.0f,.0f);
    5903.             }
    5904.             return surface;
    5905.         }
    5906.  
    5907.             // --------------------------------------------------
    5908.             // Build Graph Inputs
    5909.  
    5910.            
    5911.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    5912.         {
    5913.             VertexDescriptionInputs output;
    5914.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    5915.  
    5916.             output.ObjectSpaceNormal =           input.normalOS;
    5917.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    5918.             output.ObjectSpacePosition =         input.positionOS;
    5919.  
    5920.             return output;
    5921.         }
    5922.  
    5923.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    5924.         {
    5925.             // build graph inputs
    5926.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    5927.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    5928.  
    5929.             // evaluate vertex graph
    5930.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    5931.  
    5932.             // copy graph output to the results
    5933.             input.positionOS = vertexDescription.Position;
    5934.             input.normalOS = vertexDescription.Normal;
    5935.             input.tangentOS.xyz = vertexDescription.Tangent;
    5936.  
    5937.             return input;
    5938.         }
    5939.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    5940.         {
    5941.             FragInputs output;
    5942.             ZERO_INITIALIZE(FragInputs, output);
    5943.  
    5944.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    5945.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    5946.             // to compute normals which are then passed on elsewhere to compute other values...
    5947.             output.tangentToWorld = k_identity3x3;
    5948.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    5949.  
    5950.             output.positionRWS = input.positionRWS;
    5951.             output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS);
    5952.             output.texCoord1 = input.texCoord1;
    5953.             output.texCoord2 = input.texCoord2;
    5954.  
    5955.             return output;
    5956.         }
    5957.  
    5958.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    5959.         {
    5960.             SurfaceDescriptionInputs output;
    5961.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    5962.  
    5963.             #if defined(SHADER_STAGE_RAY_TRACING)
    5964.             #else
    5965.             #endif
    5966.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    5967.  
    5968.             return output;
    5969.         }
    5970.  
    5971.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    5972.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    5973.         {
    5974.             UNITY_SETUP_INSTANCE_ID(input);
    5975.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    5976.             return BuildFragInputs(unpacked);
    5977.         }
    5978.  
    5979.             // --------------------------------------------------
    5980.             // Build Surface Data (Specific Material)
    5981.  
    5982.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    5983.         {
    5984.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    5985.  
    5986.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    5987.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    5988.             surfaceData.specularOcclusion = 1.0;
    5989.  
    5990.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    5991.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    5992.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    5993.             surfaceData.metallic =                  surfaceDescription.Metallic;
    5994.  
    5995.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    5996.                 if (_EnableSSRefraction)
    5997.                 {
    5998.  
    5999.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    6000.                     surfaceDescription.Alpha = 1.0;
    6001.                 }
    6002.                 else
    6003.                 {
    6004.                     surfaceData.ior = 1.0;
    6005.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    6006.                     surfaceData.atDistance = 1.0;
    6007.                     surfaceData.transmittanceMask = 0.0;
    6008.                     surfaceDescription.Alpha = 1.0;
    6009.                 }
    6010.             #else
    6011.                 surfaceData.ior = 1.0;
    6012.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    6013.                 surfaceData.atDistance = 1.0;
    6014.                 surfaceData.transmittanceMask = 0.0;
    6015.             #endif
    6016.  
    6017.             // These static material feature allow compile time optimization
    6018.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    6019.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    6020.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    6021.             #endif
    6022.  
    6023.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    6024.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    6025.             #endif
    6026.  
    6027.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    6028.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    6029.             #endif
    6030.  
    6031.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    6032.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    6033.             #endif
    6034.  
    6035.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    6036.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    6037.             #endif
    6038.  
    6039.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    6040.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    6041.             #endif
    6042.  
    6043.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    6044.                 // Require to have setup baseColor
    6045.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    6046.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    6047.             #endif
    6048.  
    6049.             #ifdef _DOUBLESIDED_ON
    6050.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    6051.             #else
    6052.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    6053.             #endif
    6054.  
    6055.             // normal delivered to master node
    6056.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    6057.  
    6058.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    6059.  
    6060.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    6061.  
    6062.  
    6063.             #if HAVE_DECALS
    6064.                 if (_EnableDecals)
    6065.                 {
    6066.                     float alpha = 1.0;
    6067.                     alpha = surfaceDescription.Alpha;
    6068.  
    6069.                     // Both uses and modifies 'surfaceData.normalWS'.
    6070.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    6071.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    6072.                 }
    6073.             #endif
    6074.  
    6075.             bentNormalWS = surfaceData.normalWS;
    6076.  
    6077.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    6078.  
    6079.             #ifdef DEBUG_DISPLAY
    6080.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    6081.                 {
    6082.                     // TODO: need to update mip info
    6083.                     surfaceData.metallic = 0;
    6084.                 }
    6085.  
    6086.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    6087.                 // as it can modify attribute use for static lighting
    6088.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    6089.             #endif
    6090.  
    6091.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    6092.             // If user provide bent normal then we process a better term
    6093.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    6094.                 // Just use the value passed through via the slot (not active otherwise)
    6095.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    6096.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    6097.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    6098.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    6099.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    6100.             #endif
    6101.  
    6102.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    6103.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    6104.             #endif
    6105.         }
    6106.  
    6107.             // --------------------------------------------------
    6108.             // Get Surface And BuiltinData
    6109.  
    6110.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    6111.             {
    6112.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    6113.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    6114.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    6115.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    6116.                 #endif
    6117.                 #endif
    6118.  
    6119.                 #ifndef SHADER_UNLIT
    6120.                 #ifdef _DOUBLESIDED_ON
    6121.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    6122.                 #else
    6123.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    6124.                 #endif
    6125.  
    6126.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    6127.                 #endif // SHADER_UNLIT
    6128.  
    6129.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    6130.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    6131.  
    6132.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    6133.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    6134.                 #ifdef _ALPHATEST_ON
    6135.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    6136.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    6137.                     // The TransparentDepthPrepass is also used with SSR transparent.
    6138.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    6139.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    6140.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    6141.                     // DepthPostpass always use its own alpha threshold
    6142.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    6143.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    6144.                     // If use shadow threshold isn't enable we don't allow any test
    6145.                     #endif
    6146.  
    6147.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    6148.                 #endif
    6149.  
    6150.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    6151.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    6152.                 #endif
    6153.  
    6154.                 #ifndef SHADER_UNLIT
    6155.                 float3 bentNormalWS;
    6156.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    6157.  
    6158.                 // Builtin Data
    6159.                 // For back lighting we use the oposite vertex normal
    6160.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    6161.  
    6162.                 #else
    6163.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    6164.  
    6165.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    6166.                 builtinData.opacity = surfaceDescription.Alpha;
    6167.  
    6168.                 #if defined(DEBUG_DISPLAY)
    6169.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    6170.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    6171.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    6172.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    6173.                 #endif
    6174.  
    6175.                 #endif // SHADER_UNLIT
    6176.  
    6177.                 #ifdef _ALPHATEST_ON
    6178.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    6179.                     builtinData.alphaClipTreshold = alphaCutoff;
    6180.                 #endif
    6181.  
    6182.                 // override sampleBakedGI - not used by Unlit
    6183.  
    6184.                 builtinData.emissiveColor = surfaceDescription.Emission;
    6185.  
    6186.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    6187.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    6188.                 // This is a limitation of the current MRT approach.
    6189.                 builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback;
    6190.  
    6191.                 #if _DEPTHOFFSET_ON
    6192.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    6193.                 #endif
    6194.  
    6195.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    6196.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    6197.                 builtinData.distortion = surfaceDescription.Distortion;
    6198.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    6199.                 #endif
    6200.  
    6201.                 #ifndef SHADER_UNLIT
    6202.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    6203.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    6204.                 #else
    6205.                 ApplyDebugToBuiltinData(builtinData);
    6206.                 #endif
    6207.  
    6208.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    6209.             }
    6210.  
    6211.             // --------------------------------------------------
    6212.             // Main
    6213.  
    6214.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl"
    6215.  
    6216.             ENDHLSL
    6217.         }
    6218.         Pass
    6219.         {
    6220.             Name "RayTracingPrepass"
    6221.             Tags
    6222.             {
    6223.                 "LightMode" = "RayTracingPrepass"
    6224.             }
    6225.  
    6226.             // Render State
    6227.             Cull [_CullMode]
    6228.         Blend One Zero
    6229.         ZWrite On
    6230.  
    6231.             // Debug
    6232.             // <None>
    6233.  
    6234.             // --------------------------------------------------
    6235.             // Pass
    6236.  
    6237.             HLSLPROGRAM
    6238.  
    6239.             // Pragmas
    6240.             #pragma target 4.5
    6241.         #pragma vertex Vert
    6242.         #pragma fragment Frag
    6243.         #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
    6244.  
    6245.             // Keywords
    6246.             #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    6247.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    6248.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    6249.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    6250.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    6251.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    6252.         #pragma shader_feature_local _ _DISABLE_DECALS
    6253.         #pragma shader_feature_local _ _DISABLE_SSR
    6254.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    6255.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    6256.             // GraphKeywords: <None>
    6257.  
    6258.             // Early Instancing Defines
    6259.             // DotsInstancingOptions: <None>
    6260.  
    6261.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    6262.             // HybridV1InjectedBuiltinProperties: <None>
    6263.  
    6264.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    6265.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    6266.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    6267.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    6268.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    6269.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    6270.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    6271.  
    6272.             // --------------------------------------------------
    6273.             // Defines
    6274.  
    6275.             // Attribute
    6276.             #define ATTRIBUTES_NEED_NORMAL
    6277.             #define ATTRIBUTES_NEED_TANGENT
    6278.  
    6279.             #define HAVE_MESH_MODIFICATION
    6280.  
    6281.  
    6282.             #define SHADERPASS SHADERPASS_CONSTANT
    6283.         #define RAYTRACING_SHADER_GRAPH_DEFAULT
    6284.  
    6285.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    6286.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    6287.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    6288.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    6289.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    6290.             #define RAYTRACING_SHADER_GRAPH_HIGH
    6291.             #endif
    6292.  
    6293.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    6294.             #define RAYTRACING_SHADER_GRAPH_LOW
    6295.             #endif
    6296.             // end
    6297.  
    6298.             #ifndef SHADER_UNLIT
    6299.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    6300.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    6301.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    6302.                 #define VARYINGS_NEED_CULLFACE
    6303.             #endif
    6304.             #endif
    6305.  
    6306.             // Specific Material Define
    6307.         #define _ENERGY_CONSERVING_SPECULAR 1
    6308.  
    6309.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    6310.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    6311.             #define OUTPUT_SPLIT_LIGHTING
    6312.         #endif
    6313.  
    6314.         // This shader support recursive rendering for raytracing
    6315.         #define HAVE_RECURSIVE_RENDERING
    6316.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    6317.  
    6318.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    6319.             // we should have a code like this:
    6320.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    6321.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    6322.             // endif
    6323.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    6324.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    6325.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    6326.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    6327.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    6328.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    6329.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    6330.                 #define WRITE_NORMAL_BUFFER
    6331.             #endif
    6332.             #endif
    6333.  
    6334.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    6335.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    6336.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    6337.             // the constant buffer. A bug is filed and is being looked at.
    6338.             #if defined(SHADER_API_VULKAN)
    6339.             #define DISABLE_UNLIT_DEEXPOSURE
    6340.             #endif
    6341.  
    6342.             #ifndef DEBUG_DISPLAY
    6343.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    6344.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    6345.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    6346.                     #if SHADERPASS == SHADERPASS_FORWARD
    6347.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    6348.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    6349.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    6350.                     #endif
    6351.                 #endif
    6352.             #endif
    6353.  
    6354.             // Translate transparent motion vector define
    6355.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    6356.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    6357.             #endif
    6358.  
    6359.             // -- Graph Properties
    6360.             CBUFFER_START(UnityPerMaterial)
    6361.         float4 _EmissionColor;
    6362.         float _UseShadowThreshold;
    6363.         float4 _DoubleSidedConstants;
    6364.         float _BlendMode;
    6365.         float _EnableBlendModePreserveSpecularLighting;
    6366.         float _RayTracing;
    6367.         float _RefractionModel;
    6368.         CBUFFER_END
    6369.  
    6370.         // Object and Global properties
    6371.  
    6372.             // -- Property used by ScenePickingPass
    6373.             #ifdef SCENEPICKINGPASS
    6374.             float4 _SelectionID;
    6375.             #endif
    6376.  
    6377.             // -- Properties used by SceneSelectionPass
    6378.             #ifdef SCENESELECTIONPASS
    6379.             int _ObjectId;
    6380.             int _PassValue;
    6381.             #endif
    6382.  
    6383.             // Includes
    6384.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
    6385.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    6386.         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
    6387.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    6388.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    6389.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    6390.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
    6391.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"
    6392.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    6393.  
    6394.             // --------------------------------------------------
    6395.             // Structs and Packing
    6396.  
    6397.             struct AttributesMesh
    6398.         {
    6399.             float3 positionOS : POSITION;
    6400.             float3 normalOS : NORMAL;
    6401.             float4 tangentOS : TANGENT;
    6402.             #if UNITY_ANY_INSTANCING_ENABLED
    6403.             uint instanceID : INSTANCEID_SEMANTIC;
    6404.             #endif
    6405.         };
    6406.         struct VaryingsMeshToPS
    6407.         {
    6408.             float4 positionCS : SV_POSITION;
    6409.             #if UNITY_ANY_INSTANCING_ENABLED
    6410.             uint instanceID : CUSTOM_INSTANCE_ID;
    6411.             #endif
    6412.         };
    6413.         struct SurfaceDescriptionInputs
    6414.         {
    6415.             float3 TangentSpaceNormal;
    6416.         };
    6417.         struct VertexDescriptionInputs
    6418.         {
    6419.             float3 ObjectSpaceNormal;
    6420.             float3 ObjectSpaceTangent;
    6421.             float3 ObjectSpacePosition;
    6422.         };
    6423.         struct PackedVaryingsMeshToPS
    6424.         {
    6425.             float4 positionCS : SV_POSITION;
    6426.             #if UNITY_ANY_INSTANCING_ENABLED
    6427.             uint instanceID : CUSTOM_INSTANCE_ID;
    6428.             #endif
    6429.         };
    6430.  
    6431.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    6432.         {
    6433.             PackedVaryingsMeshToPS output;
    6434.             output.positionCS = input.positionCS;
    6435.             #if UNITY_ANY_INSTANCING_ENABLED
    6436.             output.instanceID = input.instanceID;
    6437.             #endif
    6438.             return output;
    6439.         }
    6440.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    6441.         {
    6442.             VaryingsMeshToPS output;
    6443.             output.positionCS = input.positionCS;
    6444.             #if UNITY_ANY_INSTANCING_ENABLED
    6445.             output.instanceID = input.instanceID;
    6446.             #endif
    6447.             return output;
    6448.         }
    6449.  
    6450.             // --------------------------------------------------
    6451.             // Graph
    6452.  
    6453.  
    6454.             // Graph Functions
    6455.             // GraphFunctions: <None>
    6456.  
    6457.             // Graph Vertex
    6458.             struct VertexDescription
    6459.         {
    6460.             float3 Position;
    6461.             float3 Normal;
    6462.             float3 Tangent;
    6463.         };
    6464.  
    6465.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    6466.         {
    6467.             VertexDescription description = (VertexDescription)0;
    6468.             description.Position = IN.ObjectSpacePosition;
    6469.             description.Normal = IN.ObjectSpaceNormal;
    6470.             description.Tangent = IN.ObjectSpaceTangent;
    6471.             return description;
    6472.         }
    6473.  
    6474.             // Graph Pixel
    6475.             struct SurfaceDescription
    6476.         {
    6477.             float3 BaseColor;
    6478.             float3 Emission;
    6479.             float Alpha;
    6480.             float3 BentNormal;
    6481.             float Smoothness;
    6482.             float Occlusion;
    6483.             float3 NormalTS;
    6484.             float Metallic;
    6485.         };
    6486.  
    6487.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    6488.         {
    6489.             SurfaceDescription surface = (SurfaceDescription)0;
    6490.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    6491.             surface.Emission = float3(0, 0, 0);
    6492.             surface.Alpha = 1;
    6493.             surface.BentNormal = IN.TangentSpaceNormal;
    6494.             surface.Smoothness = 0.5;
    6495.             surface.Occlusion = 1;
    6496.             surface.NormalTS = IN.TangentSpaceNormal;
    6497.             surface.Metallic = 0;
    6498.             return surface;
    6499.         }
    6500.  
    6501.             // --------------------------------------------------
    6502.             // Build Graph Inputs
    6503.  
    6504.            
    6505.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    6506.         {
    6507.             VertexDescriptionInputs output;
    6508.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    6509.  
    6510.             output.ObjectSpaceNormal =           input.normalOS;
    6511.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    6512.             output.ObjectSpacePosition =         input.positionOS;
    6513.  
    6514.             return output;
    6515.         }
    6516.  
    6517.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    6518.         {
    6519.             // build graph inputs
    6520.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    6521.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    6522.  
    6523.             // evaluate vertex graph
    6524.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    6525.  
    6526.             // copy graph output to the results
    6527.             input.positionOS = vertexDescription.Position;
    6528.             input.normalOS = vertexDescription.Normal;
    6529.             input.tangentOS.xyz = vertexDescription.Tangent;
    6530.  
    6531.             return input;
    6532.         }
    6533.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    6534.         {
    6535.             FragInputs output;
    6536.             ZERO_INITIALIZE(FragInputs, output);
    6537.  
    6538.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    6539.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    6540.             // to compute normals which are then passed on elsewhere to compute other values...
    6541.             output.tangentToWorld = k_identity3x3;
    6542.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    6543.  
    6544.  
    6545.             return output;
    6546.         }
    6547.  
    6548.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    6549.         {
    6550.             SurfaceDescriptionInputs output;
    6551.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    6552.  
    6553.             #if defined(SHADER_STAGE_RAY_TRACING)
    6554.             #else
    6555.             #endif
    6556.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    6557.  
    6558.             return output;
    6559.         }
    6560.  
    6561.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    6562.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    6563.         {
    6564.             UNITY_SETUP_INSTANCE_ID(input);
    6565.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    6566.             return BuildFragInputs(unpacked);
    6567.         }
    6568.  
    6569.             // --------------------------------------------------
    6570.             // Build Surface Data (Specific Material)
    6571.  
    6572.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    6573.         {
    6574.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    6575.  
    6576.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    6577.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    6578.             surfaceData.specularOcclusion = 1.0;
    6579.  
    6580.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    6581.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    6582.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    6583.             surfaceData.metallic =                  surfaceDescription.Metallic;
    6584.  
    6585.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    6586.                 if (_EnableSSRefraction)
    6587.                 {
    6588.  
    6589.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    6590.                     surfaceDescription.Alpha = 1.0;
    6591.                 }
    6592.                 else
    6593.                 {
    6594.                     surfaceData.ior = 1.0;
    6595.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    6596.                     surfaceData.atDistance = 1.0;
    6597.                     surfaceData.transmittanceMask = 0.0;
    6598.                     surfaceDescription.Alpha = 1.0;
    6599.                 }
    6600.             #else
    6601.                 surfaceData.ior = 1.0;
    6602.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    6603.                 surfaceData.atDistance = 1.0;
    6604.                 surfaceData.transmittanceMask = 0.0;
    6605.             #endif
    6606.  
    6607.             // These static material feature allow compile time optimization
    6608.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    6609.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    6610.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    6611.             #endif
    6612.  
    6613.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    6614.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    6615.             #endif
    6616.  
    6617.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    6618.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    6619.             #endif
    6620.  
    6621.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    6622.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    6623.             #endif
    6624.  
    6625.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    6626.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    6627.             #endif
    6628.  
    6629.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    6630.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    6631.             #endif
    6632.  
    6633.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    6634.                 // Require to have setup baseColor
    6635.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    6636.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    6637.             #endif
    6638.  
    6639.             #ifdef _DOUBLESIDED_ON
    6640.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    6641.             #else
    6642.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    6643.             #endif
    6644.  
    6645.             // normal delivered to master node
    6646.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    6647.  
    6648.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    6649.  
    6650.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    6651.  
    6652.  
    6653.             #if HAVE_DECALS
    6654.                 if (_EnableDecals)
    6655.                 {
    6656.                     float alpha = 1.0;
    6657.                     alpha = surfaceDescription.Alpha;
    6658.  
    6659.                     // Both uses and modifies 'surfaceData.normalWS'.
    6660.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    6661.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    6662.                 }
    6663.             #endif
    6664.  
    6665.             bentNormalWS = surfaceData.normalWS;
    6666.  
    6667.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    6668.  
    6669.             #ifdef DEBUG_DISPLAY
    6670.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    6671.                 {
    6672.                     // TODO: need to update mip info
    6673.                     surfaceData.metallic = 0;
    6674.                 }
    6675.  
    6676.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    6677.                 // as it can modify attribute use for static lighting
    6678.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    6679.             #endif
    6680.  
    6681.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    6682.             // If user provide bent normal then we process a better term
    6683.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    6684.                 // Just use the value passed through via the slot (not active otherwise)
    6685.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    6686.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    6687.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    6688.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    6689.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    6690.             #endif
    6691.  
    6692.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    6693.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    6694.             #endif
    6695.         }
    6696.  
    6697.             // --------------------------------------------------
    6698.             // Get Surface And BuiltinData
    6699.  
    6700.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    6701.             {
    6702.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    6703.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    6704.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    6705.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    6706.                 #endif
    6707.                 #endif
    6708.  
    6709.                 #ifndef SHADER_UNLIT
    6710.                 #ifdef _DOUBLESIDED_ON
    6711.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    6712.                 #else
    6713.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    6714.                 #endif
    6715.  
    6716.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    6717.                 #endif // SHADER_UNLIT
    6718.  
    6719.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    6720.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    6721.  
    6722.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    6723.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    6724.                 #ifdef _ALPHATEST_ON
    6725.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    6726.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    6727.                     // The TransparentDepthPrepass is also used with SSR transparent.
    6728.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    6729.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    6730.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    6731.                     // DepthPostpass always use its own alpha threshold
    6732.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    6733.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    6734.                     // If use shadow threshold isn't enable we don't allow any test
    6735.                     #endif
    6736.  
    6737.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    6738.                 #endif
    6739.  
    6740.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    6741.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    6742.                 #endif
    6743.  
    6744.                 #ifndef SHADER_UNLIT
    6745.                 float3 bentNormalWS;
    6746.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    6747.  
    6748.                 // Builtin Data
    6749.                 // For back lighting we use the oposite vertex normal
    6750.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    6751.  
    6752.                 #else
    6753.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    6754.  
    6755.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    6756.                 builtinData.opacity = surfaceDescription.Alpha;
    6757.  
    6758.                 #if defined(DEBUG_DISPLAY)
    6759.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    6760.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    6761.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    6762.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    6763.                 #endif
    6764.  
    6765.                 #endif // SHADER_UNLIT
    6766.  
    6767.                 #ifdef _ALPHATEST_ON
    6768.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    6769.                     builtinData.alphaClipTreshold = alphaCutoff;
    6770.                 #endif
    6771.  
    6772.                 // override sampleBakedGI - not used by Unlit
    6773.  
    6774.                 builtinData.emissiveColor = surfaceDescription.Emission;
    6775.  
    6776.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    6777.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    6778.                 // This is a limitation of the current MRT approach.
    6779.  
    6780.                 #if _DEPTHOFFSET_ON
    6781.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    6782.                 #endif
    6783.  
    6784.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    6785.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    6786.                 builtinData.distortion = surfaceDescription.Distortion;
    6787.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    6788.                 #endif
    6789.  
    6790.                 #ifndef SHADER_UNLIT
    6791.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    6792.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    6793.                 #else
    6794.                 ApplyDebugToBuiltinData(builtinData);
    6795.                 #endif
    6796.  
    6797.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    6798.             }
    6799.  
    6800.             // --------------------------------------------------
    6801.             // Main
    6802.  
    6803.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassConstant.hlsl"
    6804.  
    6805.             ENDHLSL
    6806.         }
    6807.     }
    6808.     SubShader
    6809.     {
    6810.         Tags
    6811.         {
    6812.             "RenderPipeline"="HDRenderPipeline"
    6813.             "RenderType"="HDLitShader"
    6814.             "Queue"="Geometry+225"
    6815.         }
    6816.        
    6817.         Pass
    6818.         {
    6819.             Name "IndirectDXR"
    6820.             Tags
    6821.             {
    6822.                 "LightMode" = "IndirectDXR"
    6823.             }
    6824.  
    6825.             // Render State
    6826.             // RenderState: <None>
    6827.  
    6828.             // Debug
    6829.             // <None>
    6830.  
    6831.             // --------------------------------------------------
    6832.             // Pass
    6833.  
    6834.             HLSLPROGRAM
    6835.  
    6836.             // Pragmas
    6837.             #pragma target 5.0
    6838.         #pragma raytracing surface_shader
    6839.         #pragma only_renderers d3d11
    6840.  
    6841.             // Keywords
    6842.             #pragma multi_compile _ MULTI_BOUNCE_INDIRECT
    6843.         #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    6844.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    6845.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    6846.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    6847.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    6848.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    6849.         #pragma multi_compile _ DEBUG_DISPLAY
    6850.         #pragma shader_feature_local _ _DISABLE_DECALS
    6851.         #pragma shader_feature_local _ _DISABLE_SSR
    6852.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    6853.         #pragma multi_compile _ LIGHTMAP_ON
    6854.         #pragma multi_compile _ DIRLIGHTMAP_COMBINED
    6855.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    6856.             // GraphKeywords: <None>
    6857.  
    6858.             // Early Instancing Defines
    6859.             // DotsInstancingOptions: <None>
    6860.  
    6861.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    6862.             // HybridV1InjectedBuiltinProperties: <None>
    6863.  
    6864.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    6865.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    6866.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    6867.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    6868.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    6869.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    6870.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    6871.  
    6872.             // --------------------------------------------------
    6873.             // Defines
    6874.  
    6875.             // Attribute
    6876.             #define ATTRIBUTES_NEED_NORMAL
    6877.             #define ATTRIBUTES_NEED_TANGENT
    6878.             #define ATTRIBUTES_NEED_TEXCOORD1
    6879.             #define ATTRIBUTES_NEED_TEXCOORD2
    6880.             #define VARYINGS_NEED_POSITION_WS
    6881.             #define VARYINGS_NEED_TANGENT_TO_WORLD
    6882.             #define VARYINGS_NEED_TEXCOORD1
    6883.             #define VARYINGS_NEED_TEXCOORD2
    6884.  
    6885.             #define HAVE_MESH_MODIFICATION
    6886.  
    6887.  
    6888.             #define SHADERPASS SHADERPASS_RAYTRACING_INDIRECT
    6889.         #define SHADOW_LOW
    6890.         #define RAYTRACING_SHADER_GRAPH_RAYTRACED
    6891.         #define HAS_LIGHTLOOP
    6892.  
    6893.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    6894.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    6895.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    6896.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    6897.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    6898.             #define RAYTRACING_SHADER_GRAPH_HIGH
    6899.             #endif
    6900.  
    6901.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    6902.             #define RAYTRACING_SHADER_GRAPH_LOW
    6903.             #endif
    6904.             // end
    6905.  
    6906.             #ifndef SHADER_UNLIT
    6907.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    6908.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    6909.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    6910.                 #define VARYINGS_NEED_CULLFACE
    6911.             #endif
    6912.             #endif
    6913.  
    6914.             // Specific Material Define
    6915.         #define _ENERGY_CONSERVING_SPECULAR 1
    6916.  
    6917.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    6918.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    6919.             #define OUTPUT_SPLIT_LIGHTING
    6920.         #endif
    6921.  
    6922.         // This shader support recursive rendering for raytracing
    6923.         #define HAVE_RECURSIVE_RENDERING
    6924.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    6925.  
    6926.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    6927.             // we should have a code like this:
    6928.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    6929.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    6930.             // endif
    6931.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    6932.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    6933.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    6934.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    6935.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    6936.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    6937.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    6938.                 #define WRITE_NORMAL_BUFFER
    6939.             #endif
    6940.             #endif
    6941.  
    6942.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    6943.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    6944.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    6945.             // the constant buffer. A bug is filed and is being looked at.
    6946.             #if defined(SHADER_API_VULKAN)
    6947.             #define DISABLE_UNLIT_DEEXPOSURE
    6948.             #endif
    6949.  
    6950.             #ifndef DEBUG_DISPLAY
    6951.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    6952.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    6953.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    6954.                     #if SHADERPASS == SHADERPASS_FORWARD
    6955.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    6956.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    6957.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    6958.                     #endif
    6959.                 #endif
    6960.             #endif
    6961.  
    6962.             // Translate transparent motion vector define
    6963.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    6964.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    6965.             #endif
    6966.  
    6967.             // -- Graph Properties
    6968.             CBUFFER_START(UnityPerMaterial)
    6969.         float4 _EmissionColor;
    6970.         float _UseShadowThreshold;
    6971.         float4 _DoubleSidedConstants;
    6972.         float _BlendMode;
    6973.         float _EnableBlendModePreserveSpecularLighting;
    6974.         float _RayTracing;
    6975.         float _RefractionModel;
    6976.         CBUFFER_END
    6977.  
    6978.         // Object and Global properties
    6979.  
    6980.             // -- Property used by ScenePickingPass
    6981.             #ifdef SCENEPICKINGPASS
    6982.             float4 _SelectionID;
    6983.             #endif
    6984.  
    6985.             // -- Properties used by SceneSelectionPass
    6986.             #ifdef SCENESELECTIONPASS
    6987.             int _ObjectId;
    6988.             int _PassValue;
    6989.             #endif
    6990.  
    6991.             // Includes
    6992.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl"
    6993.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    6994.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl"
    6995.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl"
    6996.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl"
    6997.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"
    6998.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl"
    6999.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    7000.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRaytracing.hlsl"
    7001.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl"
    7002.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    7003.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    7004.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingCommon.hlsl"
    7005.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    7006.  
    7007.             // --------------------------------------------------
    7008.             // Structs and Packing
    7009.  
    7010.             struct AttributesMesh
    7011.         {
    7012.             float3 positionOS : POSITION;
    7013.             float3 normalOS : NORMAL;
    7014.             float4 tangentOS : TANGENT;
    7015.             float4 uv1 : TEXCOORD1;
    7016.             float4 uv2 : TEXCOORD2;
    7017.             #if UNITY_ANY_INSTANCING_ENABLED
    7018.             uint instanceID : INSTANCEID_SEMANTIC;
    7019.             #endif
    7020.         };
    7021.         struct VaryingsMeshToPS
    7022.         {
    7023.             float4 positionCS : SV_POSITION;
    7024.             float3 positionRWS;
    7025.             float3 normalWS;
    7026.             float4 tangentWS;
    7027.             float4 texCoord1;
    7028.             float4 texCoord2;
    7029.             #if UNITY_ANY_INSTANCING_ENABLED
    7030.             uint instanceID : CUSTOM_INSTANCE_ID;
    7031.             #endif
    7032.         };
    7033.         struct SurfaceDescriptionInputs
    7034.         {
    7035.             float3 TangentSpaceNormal;
    7036.         };
    7037.         struct VertexDescriptionInputs
    7038.         {
    7039.             float3 ObjectSpaceNormal;
    7040.             float3 ObjectSpaceTangent;
    7041.             float3 ObjectSpacePosition;
    7042.         };
    7043.         struct PackedVaryingsMeshToPS
    7044.         {
    7045.             float4 positionCS : SV_POSITION;
    7046.             float3 interp0 : TEXCOORD0;
    7047.             float3 interp1 : TEXCOORD1;
    7048.             float4 interp2 : TEXCOORD2;
    7049.             float4 interp3 : TEXCOORD3;
    7050.             float4 interp4 : TEXCOORD4;
    7051.             #if UNITY_ANY_INSTANCING_ENABLED
    7052.             uint instanceID : CUSTOM_INSTANCE_ID;
    7053.             #endif
    7054.         };
    7055.  
    7056.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    7057.         {
    7058.             PackedVaryingsMeshToPS output;
    7059.             output.positionCS = input.positionCS;
    7060.             output.interp0.xyz =  input.positionRWS;
    7061.             output.interp1.xyz =  input.normalWS;
    7062.             output.interp2.xyzw =  input.tangentWS;
    7063.             output.interp3.xyzw =  input.texCoord1;
    7064.             output.interp4.xyzw =  input.texCoord2;
    7065.             #if UNITY_ANY_INSTANCING_ENABLED
    7066.             output.instanceID = input.instanceID;
    7067.             #endif
    7068.             return output;
    7069.         }
    7070.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    7071.         {
    7072.             VaryingsMeshToPS output;
    7073.             output.positionCS = input.positionCS;
    7074.             output.positionRWS = input.interp0.xyz;
    7075.             output.normalWS = input.interp1.xyz;
    7076.             output.tangentWS = input.interp2.xyzw;
    7077.             output.texCoord1 = input.interp3.xyzw;
    7078.             output.texCoord2 = input.interp4.xyzw;
    7079.             #if UNITY_ANY_INSTANCING_ENABLED
    7080.             output.instanceID = input.instanceID;
    7081.             #endif
    7082.             return output;
    7083.         }
    7084.  
    7085.             // --------------------------------------------------
    7086.             // Graph
    7087.  
    7088.  
    7089.             // Graph Functions
    7090.             // GraphFunctions: <None>
    7091.  
    7092.             // Graph Vertex
    7093.             struct VertexDescription
    7094.         {
    7095.             float3 Position;
    7096.             float3 Normal;
    7097.             float3 Tangent;
    7098.         };
    7099.  
    7100.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    7101.         {
    7102.             VertexDescription description = (VertexDescription)0;
    7103.             description.Position = IN.ObjectSpacePosition;
    7104.             description.Normal = IN.ObjectSpaceNormal;
    7105.             description.Tangent = IN.ObjectSpaceTangent;
    7106.             return description;
    7107.         }
    7108.  
    7109.             // Graph Pixel
    7110.             struct SurfaceDescription
    7111.         {
    7112.             float3 BaseColor;
    7113.             float3 Emission;
    7114.             float Alpha;
    7115.             float3 BentNormal;
    7116.             float Smoothness;
    7117.             float Occlusion;
    7118.             float3 NormalTS;
    7119.             float Metallic;
    7120.         };
    7121.  
    7122.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    7123.         {
    7124.             SurfaceDescription surface = (SurfaceDescription)0;
    7125.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    7126.             surface.Emission = float3(0, 0, 0);
    7127.             surface.Alpha = 1;
    7128.             surface.BentNormal = IN.TangentSpaceNormal;
    7129.             surface.Smoothness = 0.5;
    7130.             surface.Occlusion = 1;
    7131.             surface.NormalTS = IN.TangentSpaceNormal;
    7132.             surface.Metallic = 0;
    7133.             return surface;
    7134.         }
    7135.  
    7136.             // --------------------------------------------------
    7137.             // Build Graph Inputs
    7138.  
    7139.            
    7140.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    7141.         {
    7142.             VertexDescriptionInputs output;
    7143.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    7144.  
    7145.             output.ObjectSpaceNormal =           input.normalOS;
    7146.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    7147.             output.ObjectSpacePosition =         input.positionOS;
    7148.  
    7149.             return output;
    7150.         }
    7151.  
    7152.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    7153.         {
    7154.             // build graph inputs
    7155.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    7156.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    7157.  
    7158.             // evaluate vertex graph
    7159.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    7160.  
    7161.             // copy graph output to the results
    7162.             input.positionOS = vertexDescription.Position;
    7163.             input.normalOS = vertexDescription.Normal;
    7164.             input.tangentOS.xyz = vertexDescription.Tangent;
    7165.  
    7166.             return input;
    7167.         }
    7168.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    7169.         {
    7170.             FragInputs output;
    7171.             ZERO_INITIALIZE(FragInputs, output);
    7172.  
    7173.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    7174.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    7175.             // to compute normals which are then passed on elsewhere to compute other values...
    7176.             output.tangentToWorld = k_identity3x3;
    7177.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    7178.  
    7179.             output.positionRWS = input.positionRWS;
    7180.             output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS);
    7181.             output.texCoord1 = input.texCoord1;
    7182.             output.texCoord2 = input.texCoord2;
    7183.  
    7184.             return output;
    7185.         }
    7186.  
    7187.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    7188.         {
    7189.             SurfaceDescriptionInputs output;
    7190.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    7191.  
    7192.             #if defined(SHADER_STAGE_RAY_TRACING)
    7193.             #else
    7194.             #endif
    7195.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    7196.  
    7197.             return output;
    7198.         }
    7199.  
    7200.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    7201.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    7202.         {
    7203.             UNITY_SETUP_INSTANCE_ID(input);
    7204.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    7205.             return BuildFragInputs(unpacked);
    7206.         }
    7207.  
    7208.             // --------------------------------------------------
    7209.             // Build Surface Data (Specific Material)
    7210.  
    7211.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    7212.         {
    7213.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    7214.  
    7215.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    7216.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    7217.             surfaceData.specularOcclusion = 1.0;
    7218.  
    7219.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    7220.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    7221.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    7222.             surfaceData.metallic =                  surfaceDescription.Metallic;
    7223.  
    7224.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    7225.                 if (_EnableSSRefraction)
    7226.                 {
    7227.  
    7228.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    7229.                     surfaceDescription.Alpha = 1.0;
    7230.                 }
    7231.                 else
    7232.                 {
    7233.                     surfaceData.ior = 1.0;
    7234.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    7235.                     surfaceData.atDistance = 1.0;
    7236.                     surfaceData.transmittanceMask = 0.0;
    7237.                     surfaceDescription.Alpha = 1.0;
    7238.                 }
    7239.             #else
    7240.                 surfaceData.ior = 1.0;
    7241.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    7242.                 surfaceData.atDistance = 1.0;
    7243.                 surfaceData.transmittanceMask = 0.0;
    7244.             #endif
    7245.  
    7246.             // These static material feature allow compile time optimization
    7247.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    7248.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    7249.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    7250.             #endif
    7251.  
    7252.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    7253.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    7254.             #endif
    7255.  
    7256.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    7257.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    7258.             #endif
    7259.  
    7260.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    7261.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    7262.             #endif
    7263.  
    7264.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    7265.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    7266.             #endif
    7267.  
    7268.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    7269.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    7270.             #endif
    7271.  
    7272.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    7273.                 // Require to have setup baseColor
    7274.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    7275.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    7276.             #endif
    7277.  
    7278.             #ifdef _DOUBLESIDED_ON
    7279.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    7280.             #else
    7281.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    7282.             #endif
    7283.  
    7284.             // normal delivered to master node
    7285.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    7286.  
    7287.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    7288.  
    7289.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    7290.  
    7291.  
    7292.             #if HAVE_DECALS
    7293.                 if (_EnableDecals)
    7294.                 {
    7295.                     float alpha = 1.0;
    7296.                     alpha = surfaceDescription.Alpha;
    7297.  
    7298.                     // Both uses and modifies 'surfaceData.normalWS'.
    7299.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    7300.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    7301.                 }
    7302.             #endif
    7303.  
    7304.             bentNormalWS = surfaceData.normalWS;
    7305.  
    7306.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    7307.  
    7308.             #ifdef DEBUG_DISPLAY
    7309.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    7310.                 {
    7311.                     // TODO: need to update mip info
    7312.                     surfaceData.metallic = 0;
    7313.                 }
    7314.  
    7315.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    7316.                 // as it can modify attribute use for static lighting
    7317.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    7318.             #endif
    7319.  
    7320.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    7321.             // If user provide bent normal then we process a better term
    7322.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    7323.                 // Just use the value passed through via the slot (not active otherwise)
    7324.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    7325.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    7326.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    7327.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    7328.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    7329.             #endif
    7330.  
    7331.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    7332.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    7333.             #endif
    7334.         }
    7335.  
    7336.             // --------------------------------------------------
    7337.             // Get Surface And BuiltinData
    7338.  
    7339.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    7340.             {
    7341.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    7342.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    7343.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    7344.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    7345.                 #endif
    7346.                 #endif
    7347.  
    7348.                 #ifndef SHADER_UNLIT
    7349.                 #ifdef _DOUBLESIDED_ON
    7350.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    7351.                 #else
    7352.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    7353.                 #endif
    7354.  
    7355.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    7356.                 #endif // SHADER_UNLIT
    7357.  
    7358.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    7359.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    7360.  
    7361.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    7362.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    7363.                 #ifdef _ALPHATEST_ON
    7364.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    7365.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    7366.                     // The TransparentDepthPrepass is also used with SSR transparent.
    7367.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    7368.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    7369.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    7370.                     // DepthPostpass always use its own alpha threshold
    7371.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    7372.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    7373.                     // If use shadow threshold isn't enable we don't allow any test
    7374.                     #endif
    7375.  
    7376.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    7377.                 #endif
    7378.  
    7379.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    7380.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    7381.                 #endif
    7382.  
    7383.                 #ifndef SHADER_UNLIT
    7384.                 float3 bentNormalWS;
    7385.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    7386.  
    7387.                 // Builtin Data
    7388.                 // For back lighting we use the oposite vertex normal
    7389.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    7390.  
    7391.                 #else
    7392.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    7393.  
    7394.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    7395.                 builtinData.opacity = surfaceDescription.Alpha;
    7396.  
    7397.                 #if defined(DEBUG_DISPLAY)
    7398.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    7399.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    7400.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    7401.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    7402.                 #endif
    7403.  
    7404.                 #endif // SHADER_UNLIT
    7405.  
    7406.                 #ifdef _ALPHATEST_ON
    7407.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    7408.                     builtinData.alphaClipTreshold = alphaCutoff;
    7409.                 #endif
    7410.  
    7411.                 // override sampleBakedGI - not used by Unlit
    7412.  
    7413.                 builtinData.emissiveColor = surfaceDescription.Emission;
    7414.  
    7415.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    7416.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    7417.                 // This is a limitation of the current MRT approach.
    7418.  
    7419.                 #if _DEPTHOFFSET_ON
    7420.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    7421.                 #endif
    7422.  
    7423.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    7424.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    7425.                 builtinData.distortion = surfaceDescription.Distortion;
    7426.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    7427.                 #endif
    7428.  
    7429.                 #ifndef SHADER_UNLIT
    7430.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    7431.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    7432.                 #else
    7433.                 ApplyDebugToBuiltinData(builtinData);
    7434.                 #endif
    7435.  
    7436.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    7437.             }
    7438.  
    7439.             // --------------------------------------------------
    7440.             // Main
    7441.  
    7442.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingIndirect.hlsl"
    7443.  
    7444.             ENDHLSL
    7445.         }
    7446.         Pass
    7447.         {
    7448.             Name "VisibilityDXR"
    7449.             Tags
    7450.             {
    7451.                 "LightMode" = "VisibilityDXR"
    7452.             }
    7453.  
    7454.             // Render State
    7455.             // RenderState: <None>
    7456.  
    7457.             // Debug
    7458.             // <None>
    7459.  
    7460.             // --------------------------------------------------
    7461.             // Pass
    7462.  
    7463.             HLSLPROGRAM
    7464.  
    7465.             // Pragmas
    7466.             #pragma target 5.0
    7467.         #pragma raytracing surface_shader
    7468.         #pragma only_renderers d3d11
    7469.  
    7470.             // Keywords
    7471.             #pragma multi_compile _ TRANSPARENT_COLOR_SHADOW
    7472.         #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    7473.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    7474.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    7475.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    7476.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    7477.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    7478.         #pragma shader_feature_local _ _DISABLE_DECALS
    7479.         #pragma shader_feature_local _ _DISABLE_SSR
    7480.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    7481.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    7482.             // GraphKeywords: <None>
    7483.  
    7484.             // Early Instancing Defines
    7485.             // DotsInstancingOptions: <None>
    7486.  
    7487.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    7488.             // HybridV1InjectedBuiltinProperties: <None>
    7489.  
    7490.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    7491.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    7492.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    7493.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    7494.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    7495.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    7496.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    7497.  
    7498.             // --------------------------------------------------
    7499.             // Defines
    7500.  
    7501.             // Attribute
    7502.             #define ATTRIBUTES_NEED_NORMAL
    7503.             #define ATTRIBUTES_NEED_TANGENT
    7504.  
    7505.             #define HAVE_MESH_MODIFICATION
    7506.  
    7507.  
    7508.             #define SHADERPASS SHADERPASS_RAYTRACING_VISIBILITY
    7509.         #define RAYTRACING_SHADER_GRAPH_RAYTRACED
    7510.  
    7511.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    7512.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    7513.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    7514.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    7515.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    7516.             #define RAYTRACING_SHADER_GRAPH_HIGH
    7517.             #endif
    7518.  
    7519.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    7520.             #define RAYTRACING_SHADER_GRAPH_LOW
    7521.             #endif
    7522.             // end
    7523.  
    7524.             #ifndef SHADER_UNLIT
    7525.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    7526.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    7527.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    7528.                 #define VARYINGS_NEED_CULLFACE
    7529.             #endif
    7530.             #endif
    7531.  
    7532.             // Specific Material Define
    7533.         #define _ENERGY_CONSERVING_SPECULAR 1
    7534.  
    7535.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    7536.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    7537.             #define OUTPUT_SPLIT_LIGHTING
    7538.         #endif
    7539.  
    7540.         // This shader support recursive rendering for raytracing
    7541.         #define HAVE_RECURSIVE_RENDERING
    7542.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    7543.  
    7544.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    7545.             // we should have a code like this:
    7546.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    7547.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    7548.             // endif
    7549.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    7550.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    7551.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    7552.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    7553.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    7554.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    7555.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    7556.                 #define WRITE_NORMAL_BUFFER
    7557.             #endif
    7558.             #endif
    7559.  
    7560.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    7561.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    7562.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    7563.             // the constant buffer. A bug is filed and is being looked at.
    7564.             #if defined(SHADER_API_VULKAN)
    7565.             #define DISABLE_UNLIT_DEEXPOSURE
    7566.             #endif
    7567.  
    7568.             #ifndef DEBUG_DISPLAY
    7569.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    7570.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    7571.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    7572.                     #if SHADERPASS == SHADERPASS_FORWARD
    7573.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    7574.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    7575.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    7576.                     #endif
    7577.                 #endif
    7578.             #endif
    7579.  
    7580.             // Translate transparent motion vector define
    7581.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    7582.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    7583.             #endif
    7584.  
    7585.             // -- Graph Properties
    7586.             CBUFFER_START(UnityPerMaterial)
    7587.         float4 _EmissionColor;
    7588.         float _UseShadowThreshold;
    7589.         float4 _DoubleSidedConstants;
    7590.         float _BlendMode;
    7591.         float _EnableBlendModePreserveSpecularLighting;
    7592.         float _RayTracing;
    7593.         float _RefractionModel;
    7594.         CBUFFER_END
    7595.  
    7596.         // Object and Global properties
    7597.  
    7598.             // -- Property used by ScenePickingPass
    7599.             #ifdef SCENEPICKINGPASS
    7600.             float4 _SelectionID;
    7601.             #endif
    7602.  
    7603.             // -- Properties used by SceneSelectionPass
    7604.             #ifdef SCENESELECTIONPASS
    7605.             int _ObjectId;
    7606.             int _PassValue;
    7607.             #endif
    7608.  
    7609.             // Includes
    7610.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl"
    7611.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    7612.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl"
    7613.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl"
    7614.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl"
    7615.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    7616.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRaytracing.hlsl"
    7617.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    7618.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    7619.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingCommon.hlsl"
    7620.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    7621.  
    7622.             // --------------------------------------------------
    7623.             // Structs and Packing
    7624.  
    7625.             struct AttributesMesh
    7626.         {
    7627.             float3 positionOS : POSITION;
    7628.             float3 normalOS : NORMAL;
    7629.             float4 tangentOS : TANGENT;
    7630.             #if UNITY_ANY_INSTANCING_ENABLED
    7631.             uint instanceID : INSTANCEID_SEMANTIC;
    7632.             #endif
    7633.         };
    7634.         struct VaryingsMeshToPS
    7635.         {
    7636.             float4 positionCS : SV_POSITION;
    7637.             #if UNITY_ANY_INSTANCING_ENABLED
    7638.             uint instanceID : CUSTOM_INSTANCE_ID;
    7639.             #endif
    7640.         };
    7641.         struct SurfaceDescriptionInputs
    7642.         {
    7643.             float3 TangentSpaceNormal;
    7644.         };
    7645.         struct VertexDescriptionInputs
    7646.         {
    7647.             float3 ObjectSpaceNormal;
    7648.             float3 ObjectSpaceTangent;
    7649.             float3 ObjectSpacePosition;
    7650.         };
    7651.         struct PackedVaryingsMeshToPS
    7652.         {
    7653.             float4 positionCS : SV_POSITION;
    7654.             #if UNITY_ANY_INSTANCING_ENABLED
    7655.             uint instanceID : CUSTOM_INSTANCE_ID;
    7656.             #endif
    7657.         };
    7658.  
    7659.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    7660.         {
    7661.             PackedVaryingsMeshToPS output;
    7662.             output.positionCS = input.positionCS;
    7663.             #if UNITY_ANY_INSTANCING_ENABLED
    7664.             output.instanceID = input.instanceID;
    7665.             #endif
    7666.             return output;
    7667.         }
    7668.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    7669.         {
    7670.             VaryingsMeshToPS output;
    7671.             output.positionCS = input.positionCS;
    7672.             #if UNITY_ANY_INSTANCING_ENABLED
    7673.             output.instanceID = input.instanceID;
    7674.             #endif
    7675.             return output;
    7676.         }
    7677.  
    7678.             // --------------------------------------------------
    7679.             // Graph
    7680.  
    7681.  
    7682.             // Graph Functions
    7683.             // GraphFunctions: <None>
    7684.  
    7685.             // Graph Vertex
    7686.             struct VertexDescription
    7687.         {
    7688.             float3 Position;
    7689.             float3 Normal;
    7690.             float3 Tangent;
    7691.         };
    7692.  
    7693.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    7694.         {
    7695.             VertexDescription description = (VertexDescription)0;
    7696.             description.Position = IN.ObjectSpacePosition;
    7697.             description.Normal = IN.ObjectSpaceNormal;
    7698.             description.Tangent = IN.ObjectSpaceTangent;
    7699.             return description;
    7700.         }
    7701.  
    7702.             // Graph Pixel
    7703.             struct SurfaceDescription
    7704.         {
    7705.             float3 BaseColor;
    7706.             float3 Emission;
    7707.             float Alpha;
    7708.             float3 BentNormal;
    7709.             float Smoothness;
    7710.             float Occlusion;
    7711.             float3 NormalTS;
    7712.             float Metallic;
    7713.         };
    7714.  
    7715.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    7716.         {
    7717.             SurfaceDescription surface = (SurfaceDescription)0;
    7718.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    7719.             surface.Emission = float3(0, 0, 0);
    7720.             surface.Alpha = 1;
    7721.             surface.BentNormal = IN.TangentSpaceNormal;
    7722.             surface.Smoothness = 0.5;
    7723.             surface.Occlusion = 1;
    7724.             surface.NormalTS = IN.TangentSpaceNormal;
    7725.             surface.Metallic = 0;
    7726.             return surface;
    7727.         }
    7728.  
    7729.             // --------------------------------------------------
    7730.             // Build Graph Inputs
    7731.  
    7732.            
    7733.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    7734.         {
    7735.             VertexDescriptionInputs output;
    7736.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    7737.  
    7738.             output.ObjectSpaceNormal =           input.normalOS;
    7739.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    7740.             output.ObjectSpacePosition =         input.positionOS;
    7741.  
    7742.             return output;
    7743.         }
    7744.  
    7745.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    7746.         {
    7747.             // build graph inputs
    7748.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    7749.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    7750.  
    7751.             // evaluate vertex graph
    7752.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    7753.  
    7754.             // copy graph output to the results
    7755.             input.positionOS = vertexDescription.Position;
    7756.             input.normalOS = vertexDescription.Normal;
    7757.             input.tangentOS.xyz = vertexDescription.Tangent;
    7758.  
    7759.             return input;
    7760.         }
    7761.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    7762.         {
    7763.             FragInputs output;
    7764.             ZERO_INITIALIZE(FragInputs, output);
    7765.  
    7766.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    7767.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    7768.             // to compute normals which are then passed on elsewhere to compute other values...
    7769.             output.tangentToWorld = k_identity3x3;
    7770.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    7771.  
    7772.  
    7773.             return output;
    7774.         }
    7775.  
    7776.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    7777.         {
    7778.             SurfaceDescriptionInputs output;
    7779.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    7780.  
    7781.             #if defined(SHADER_STAGE_RAY_TRACING)
    7782.             #else
    7783.             #endif
    7784.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    7785.  
    7786.             return output;
    7787.         }
    7788.  
    7789.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    7790.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    7791.         {
    7792.             UNITY_SETUP_INSTANCE_ID(input);
    7793.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    7794.             return BuildFragInputs(unpacked);
    7795.         }
    7796.  
    7797.             // --------------------------------------------------
    7798.             // Build Surface Data (Specific Material)
    7799.  
    7800.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    7801.         {
    7802.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    7803.  
    7804.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    7805.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    7806.             surfaceData.specularOcclusion = 1.0;
    7807.  
    7808.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    7809.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    7810.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    7811.             surfaceData.metallic =                  surfaceDescription.Metallic;
    7812.  
    7813.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    7814.                 if (_EnableSSRefraction)
    7815.                 {
    7816.  
    7817.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    7818.                     surfaceDescription.Alpha = 1.0;
    7819.                 }
    7820.                 else
    7821.                 {
    7822.                     surfaceData.ior = 1.0;
    7823.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    7824.                     surfaceData.atDistance = 1.0;
    7825.                     surfaceData.transmittanceMask = 0.0;
    7826.                     surfaceDescription.Alpha = 1.0;
    7827.                 }
    7828.             #else
    7829.                 surfaceData.ior = 1.0;
    7830.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    7831.                 surfaceData.atDistance = 1.0;
    7832.                 surfaceData.transmittanceMask = 0.0;
    7833.             #endif
    7834.  
    7835.             // These static material feature allow compile time optimization
    7836.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    7837.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    7838.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    7839.             #endif
    7840.  
    7841.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    7842.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    7843.             #endif
    7844.  
    7845.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    7846.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    7847.             #endif
    7848.  
    7849.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    7850.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    7851.             #endif
    7852.  
    7853.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    7854.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    7855.             #endif
    7856.  
    7857.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    7858.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    7859.             #endif
    7860.  
    7861.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    7862.                 // Require to have setup baseColor
    7863.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    7864.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    7865.             #endif
    7866.  
    7867.             #ifdef _DOUBLESIDED_ON
    7868.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    7869.             #else
    7870.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    7871.             #endif
    7872.  
    7873.             // normal delivered to master node
    7874.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    7875.  
    7876.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    7877.  
    7878.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    7879.  
    7880.  
    7881.             #if HAVE_DECALS
    7882.                 if (_EnableDecals)
    7883.                 {
    7884.                     float alpha = 1.0;
    7885.                     alpha = surfaceDescription.Alpha;
    7886.  
    7887.                     // Both uses and modifies 'surfaceData.normalWS'.
    7888.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    7889.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    7890.                 }
    7891.             #endif
    7892.  
    7893.             bentNormalWS = surfaceData.normalWS;
    7894.  
    7895.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    7896.  
    7897.             #ifdef DEBUG_DISPLAY
    7898.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    7899.                 {
    7900.                     // TODO: need to update mip info
    7901.                     surfaceData.metallic = 0;
    7902.                 }
    7903.  
    7904.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    7905.                 // as it can modify attribute use for static lighting
    7906.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    7907.             #endif
    7908.  
    7909.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    7910.             // If user provide bent normal then we process a better term
    7911.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    7912.                 // Just use the value passed through via the slot (not active otherwise)
    7913.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    7914.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    7915.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    7916.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    7917.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    7918.             #endif
    7919.  
    7920.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    7921.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    7922.             #endif
    7923.         }
    7924.  
    7925.             // --------------------------------------------------
    7926.             // Get Surface And BuiltinData
    7927.  
    7928.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    7929.             {
    7930.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    7931.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    7932.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    7933.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    7934.                 #endif
    7935.                 #endif
    7936.  
    7937.                 #ifndef SHADER_UNLIT
    7938.                 #ifdef _DOUBLESIDED_ON
    7939.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    7940.                 #else
    7941.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    7942.                 #endif
    7943.  
    7944.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    7945.                 #endif // SHADER_UNLIT
    7946.  
    7947.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    7948.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    7949.  
    7950.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    7951.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    7952.                 #ifdef _ALPHATEST_ON
    7953.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    7954.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    7955.                     // The TransparentDepthPrepass is also used with SSR transparent.
    7956.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    7957.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    7958.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    7959.                     // DepthPostpass always use its own alpha threshold
    7960.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    7961.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    7962.                     // If use shadow threshold isn't enable we don't allow any test
    7963.                     #endif
    7964.  
    7965.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    7966.                 #endif
    7967.  
    7968.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    7969.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    7970.                 #endif
    7971.  
    7972.                 #ifndef SHADER_UNLIT
    7973.                 float3 bentNormalWS;
    7974.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    7975.  
    7976.                 // Builtin Data
    7977.                 // For back lighting we use the oposite vertex normal
    7978.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    7979.  
    7980.                 #else
    7981.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    7982.  
    7983.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    7984.                 builtinData.opacity = surfaceDescription.Alpha;
    7985.  
    7986.                 #if defined(DEBUG_DISPLAY)
    7987.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    7988.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    7989.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    7990.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    7991.                 #endif
    7992.  
    7993.                 #endif // SHADER_UNLIT
    7994.  
    7995.                 #ifdef _ALPHATEST_ON
    7996.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    7997.                     builtinData.alphaClipTreshold = alphaCutoff;
    7998.                 #endif
    7999.  
    8000.                 // override sampleBakedGI - not used by Unlit
    8001.  
    8002.                 builtinData.emissiveColor = surfaceDescription.Emission;
    8003.  
    8004.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    8005.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    8006.                 // This is a limitation of the current MRT approach.
    8007.  
    8008.                 #if _DEPTHOFFSET_ON
    8009.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    8010.                 #endif
    8011.  
    8012.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    8013.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    8014.                 builtinData.distortion = surfaceDescription.Distortion;
    8015.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    8016.                 #endif
    8017.  
    8018.                 #ifndef SHADER_UNLIT
    8019.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    8020.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    8021.                 #else
    8022.                 ApplyDebugToBuiltinData(builtinData);
    8023.                 #endif
    8024.  
    8025.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    8026.             }
    8027.  
    8028.             // --------------------------------------------------
    8029.             // Main
    8030.  
    8031.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingVisibility.hlsl"
    8032.  
    8033.             ENDHLSL
    8034.         }
    8035.         Pass
    8036.         {
    8037.             Name "ForwardDXR"
    8038.             Tags
    8039.             {
    8040.                 "LightMode" = "ForwardDXR"
    8041.             }
    8042.  
    8043.             // Render State
    8044.             // RenderState: <None>
    8045.  
    8046.             // Debug
    8047.             // <None>
    8048.  
    8049.             // --------------------------------------------------
    8050.             // Pass
    8051.  
    8052.             HLSLPROGRAM
    8053.  
    8054.             // Pragmas
    8055.             #pragma target 5.0
    8056.         #pragma raytracing surface_shader
    8057.         #pragma only_renderers d3d11
    8058.  
    8059.             // Keywords
    8060.             #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    8061.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    8062.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    8063.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    8064.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    8065.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    8066.         #pragma multi_compile _ DEBUG_DISPLAY
    8067.         #pragma shader_feature_local _ _DISABLE_DECALS
    8068.         #pragma shader_feature_local _ _DISABLE_SSR
    8069.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    8070.         #pragma multi_compile _ LIGHTMAP_ON
    8071.         #pragma multi_compile _ DIRLIGHTMAP_COMBINED
    8072.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    8073.             // GraphKeywords: <None>
    8074.  
    8075.             // Early Instancing Defines
    8076.             // DotsInstancingOptions: <None>
    8077.  
    8078.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    8079.             // HybridV1InjectedBuiltinProperties: <None>
    8080.  
    8081.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    8082.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    8083.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    8084.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    8085.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    8086.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    8087.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    8088.  
    8089.             // --------------------------------------------------
    8090.             // Defines
    8091.  
    8092.             // Attribute
    8093.             #define ATTRIBUTES_NEED_NORMAL
    8094.             #define ATTRIBUTES_NEED_TANGENT
    8095.             #define ATTRIBUTES_NEED_TEXCOORD1
    8096.             #define ATTRIBUTES_NEED_TEXCOORD2
    8097.             #define VARYINGS_NEED_POSITION_WS
    8098.             #define VARYINGS_NEED_TANGENT_TO_WORLD
    8099.             #define VARYINGS_NEED_TEXCOORD1
    8100.             #define VARYINGS_NEED_TEXCOORD2
    8101.  
    8102.             #define HAVE_MESH_MODIFICATION
    8103.  
    8104.  
    8105.             #define SHADERPASS SHADERPASS_RAYTRACING_FORWARD
    8106.         #define SHADOW_LOW
    8107.         #define RAYTRACING_SHADER_GRAPH_RAYTRACED
    8108.         #define HAS_LIGHTLOOP
    8109.  
    8110.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    8111.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    8112.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    8113.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    8114.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    8115.             #define RAYTRACING_SHADER_GRAPH_HIGH
    8116.             #endif
    8117.  
    8118.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    8119.             #define RAYTRACING_SHADER_GRAPH_LOW
    8120.             #endif
    8121.             // end
    8122.  
    8123.             #ifndef SHADER_UNLIT
    8124.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    8125.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    8126.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    8127.                 #define VARYINGS_NEED_CULLFACE
    8128.             #endif
    8129.             #endif
    8130.  
    8131.             // Specific Material Define
    8132.         #define _ENERGY_CONSERVING_SPECULAR 1
    8133.  
    8134.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    8135.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    8136.             #define OUTPUT_SPLIT_LIGHTING
    8137.         #endif
    8138.  
    8139.         // This shader support recursive rendering for raytracing
    8140.         #define HAVE_RECURSIVE_RENDERING
    8141.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    8142.  
    8143.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    8144.             // we should have a code like this:
    8145.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    8146.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    8147.             // endif
    8148.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    8149.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    8150.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    8151.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    8152.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    8153.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    8154.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    8155.                 #define WRITE_NORMAL_BUFFER
    8156.             #endif
    8157.             #endif
    8158.  
    8159.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    8160.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    8161.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    8162.             // the constant buffer. A bug is filed and is being looked at.
    8163.             #if defined(SHADER_API_VULKAN)
    8164.             #define DISABLE_UNLIT_DEEXPOSURE
    8165.             #endif
    8166.  
    8167.             #ifndef DEBUG_DISPLAY
    8168.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    8169.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    8170.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    8171.                     #if SHADERPASS == SHADERPASS_FORWARD
    8172.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    8173.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    8174.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    8175.                     #endif
    8176.                 #endif
    8177.             #endif
    8178.  
    8179.             // Translate transparent motion vector define
    8180.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    8181.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    8182.             #endif
    8183.  
    8184.             // -- Graph Properties
    8185.             CBUFFER_START(UnityPerMaterial)
    8186.         float4 _EmissionColor;
    8187.         float _UseShadowThreshold;
    8188.         float4 _DoubleSidedConstants;
    8189.         float _BlendMode;
    8190.         float _EnableBlendModePreserveSpecularLighting;
    8191.         float _RayTracing;
    8192.         float _RefractionModel;
    8193.         CBUFFER_END
    8194.  
    8195.         // Object and Global properties
    8196.  
    8197.             // -- Property used by ScenePickingPass
    8198.             #ifdef SCENEPICKINGPASS
    8199.             float4 _SelectionID;
    8200.             #endif
    8201.  
    8202.             // -- Properties used by SceneSelectionPass
    8203.             #ifdef SCENESELECTIONPASS
    8204.             int _ObjectId;
    8205.             int _PassValue;
    8206.             #endif
    8207.  
    8208.             // Includes
    8209.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl"
    8210.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    8211.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl"
    8212.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl"
    8213.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl"
    8214.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"
    8215.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl"
    8216.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    8217.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRaytracing.hlsl"
    8218.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl"
    8219.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    8220.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    8221.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingCommon.hlsl"
    8222.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    8223.  
    8224.             // --------------------------------------------------
    8225.             // Structs and Packing
    8226.  
    8227.             struct AttributesMesh
    8228.         {
    8229.             float3 positionOS : POSITION;
    8230.             float3 normalOS : NORMAL;
    8231.             float4 tangentOS : TANGENT;
    8232.             float4 uv1 : TEXCOORD1;
    8233.             float4 uv2 : TEXCOORD2;
    8234.             #if UNITY_ANY_INSTANCING_ENABLED
    8235.             uint instanceID : INSTANCEID_SEMANTIC;
    8236.             #endif
    8237.         };
    8238.         struct VaryingsMeshToPS
    8239.         {
    8240.             float4 positionCS : SV_POSITION;
    8241.             float3 positionRWS;
    8242.             float3 normalWS;
    8243.             float4 tangentWS;
    8244.             float4 texCoord1;
    8245.             float4 texCoord2;
    8246.             #if UNITY_ANY_INSTANCING_ENABLED
    8247.             uint instanceID : CUSTOM_INSTANCE_ID;
    8248.             #endif
    8249.         };
    8250.         struct SurfaceDescriptionInputs
    8251.         {
    8252.             float3 TangentSpaceNormal;
    8253.         };
    8254.         struct VertexDescriptionInputs
    8255.         {
    8256.             float3 ObjectSpaceNormal;
    8257.             float3 ObjectSpaceTangent;
    8258.             float3 ObjectSpacePosition;
    8259.         };
    8260.         struct PackedVaryingsMeshToPS
    8261.         {
    8262.             float4 positionCS : SV_POSITION;
    8263.             float3 interp0 : TEXCOORD0;
    8264.             float3 interp1 : TEXCOORD1;
    8265.             float4 interp2 : TEXCOORD2;
    8266.             float4 interp3 : TEXCOORD3;
    8267.             float4 interp4 : TEXCOORD4;
    8268.             #if UNITY_ANY_INSTANCING_ENABLED
    8269.             uint instanceID : CUSTOM_INSTANCE_ID;
    8270.             #endif
    8271.         };
    8272.  
    8273.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    8274.         {
    8275.             PackedVaryingsMeshToPS output;
    8276.             output.positionCS = input.positionCS;
    8277.             output.interp0.xyz =  input.positionRWS;
    8278.             output.interp1.xyz =  input.normalWS;
    8279.             output.interp2.xyzw =  input.tangentWS;
    8280.             output.interp3.xyzw =  input.texCoord1;
    8281.             output.interp4.xyzw =  input.texCoord2;
    8282.             #if UNITY_ANY_INSTANCING_ENABLED
    8283.             output.instanceID = input.instanceID;
    8284.             #endif
    8285.             return output;
    8286.         }
    8287.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    8288.         {
    8289.             VaryingsMeshToPS output;
    8290.             output.positionCS = input.positionCS;
    8291.             output.positionRWS = input.interp0.xyz;
    8292.             output.normalWS = input.interp1.xyz;
    8293.             output.tangentWS = input.interp2.xyzw;
    8294.             output.texCoord1 = input.interp3.xyzw;
    8295.             output.texCoord2 = input.interp4.xyzw;
    8296.             #if UNITY_ANY_INSTANCING_ENABLED
    8297.             output.instanceID = input.instanceID;
    8298.             #endif
    8299.             return output;
    8300.         }
    8301.  
    8302.             // --------------------------------------------------
    8303.             // Graph
    8304.  
    8305.  
    8306.             // Graph Functions
    8307.             // GraphFunctions: <None>
    8308.  
    8309.             // Graph Vertex
    8310.             struct VertexDescription
    8311.         {
    8312.             float3 Position;
    8313.             float3 Normal;
    8314.             float3 Tangent;
    8315.         };
    8316.  
    8317.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    8318.         {
    8319.             VertexDescription description = (VertexDescription)0;
    8320.             description.Position = IN.ObjectSpacePosition;
    8321.             description.Normal = IN.ObjectSpaceNormal;
    8322.             description.Tangent = IN.ObjectSpaceTangent;
    8323.             return description;
    8324.         }
    8325.  
    8326.             // Graph Pixel
    8327.             struct SurfaceDescription
    8328.         {
    8329.             float3 BaseColor;
    8330.             float3 Emission;
    8331.             float Alpha;
    8332.             float3 BentNormal;
    8333.             float Smoothness;
    8334.             float Occlusion;
    8335.             float3 NormalTS;
    8336.             float Metallic;
    8337.         };
    8338.  
    8339.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    8340.         {
    8341.             SurfaceDescription surface = (SurfaceDescription)0;
    8342.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    8343.             surface.Emission = float3(0, 0, 0);
    8344.             surface.Alpha = 1;
    8345.             surface.BentNormal = IN.TangentSpaceNormal;
    8346.             surface.Smoothness = 0.5;
    8347.             surface.Occlusion = 1;
    8348.             surface.NormalTS = IN.TangentSpaceNormal;
    8349.             surface.Metallic = 0;
    8350.             return surface;
    8351.         }
    8352.  
    8353.             // --------------------------------------------------
    8354.             // Build Graph Inputs
    8355.  
    8356.            
    8357.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    8358.         {
    8359.             VertexDescriptionInputs output;
    8360.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    8361.  
    8362.             output.ObjectSpaceNormal =           input.normalOS;
    8363.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    8364.             output.ObjectSpacePosition =         input.positionOS;
    8365.  
    8366.             return output;
    8367.         }
    8368.  
    8369.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    8370.         {
    8371.             // build graph inputs
    8372.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    8373.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    8374.  
    8375.             // evaluate vertex graph
    8376.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    8377.  
    8378.             // copy graph output to the results
    8379.             input.positionOS = vertexDescription.Position;
    8380.             input.normalOS = vertexDescription.Normal;
    8381.             input.tangentOS.xyz = vertexDescription.Tangent;
    8382.  
    8383.             return input;
    8384.         }
    8385.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    8386.         {
    8387.             FragInputs output;
    8388.             ZERO_INITIALIZE(FragInputs, output);
    8389.  
    8390.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    8391.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    8392.             // to compute normals which are then passed on elsewhere to compute other values...
    8393.             output.tangentToWorld = k_identity3x3;
    8394.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    8395.  
    8396.             output.positionRWS = input.positionRWS;
    8397.             output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS);
    8398.             output.texCoord1 = input.texCoord1;
    8399.             output.texCoord2 = input.texCoord2;
    8400.  
    8401.             return output;
    8402.         }
    8403.  
    8404.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    8405.         {
    8406.             SurfaceDescriptionInputs output;
    8407.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    8408.  
    8409.             #if defined(SHADER_STAGE_RAY_TRACING)
    8410.             #else
    8411.             #endif
    8412.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    8413.  
    8414.             return output;
    8415.         }
    8416.  
    8417.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    8418.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    8419.         {
    8420.             UNITY_SETUP_INSTANCE_ID(input);
    8421.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    8422.             return BuildFragInputs(unpacked);
    8423.         }
    8424.  
    8425.             // --------------------------------------------------
    8426.             // Build Surface Data (Specific Material)
    8427.  
    8428.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    8429.         {
    8430.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    8431.  
    8432.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    8433.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    8434.             surfaceData.specularOcclusion = 1.0;
    8435.  
    8436.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    8437.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    8438.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    8439.             surfaceData.metallic =                  surfaceDescription.Metallic;
    8440.  
    8441.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    8442.                 if (_EnableSSRefraction)
    8443.                 {
    8444.  
    8445.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    8446.                     surfaceDescription.Alpha = 1.0;
    8447.                 }
    8448.                 else
    8449.                 {
    8450.                     surfaceData.ior = 1.0;
    8451.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    8452.                     surfaceData.atDistance = 1.0;
    8453.                     surfaceData.transmittanceMask = 0.0;
    8454.                     surfaceDescription.Alpha = 1.0;
    8455.                 }
    8456.             #else
    8457.                 surfaceData.ior = 1.0;
    8458.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    8459.                 surfaceData.atDistance = 1.0;
    8460.                 surfaceData.transmittanceMask = 0.0;
    8461.             #endif
    8462.  
    8463.             // These static material feature allow compile time optimization
    8464.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    8465.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    8466.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    8467.             #endif
    8468.  
    8469.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    8470.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    8471.             #endif
    8472.  
    8473.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    8474.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    8475.             #endif
    8476.  
    8477.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    8478.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    8479.             #endif
    8480.  
    8481.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    8482.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    8483.             #endif
    8484.  
    8485.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    8486.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    8487.             #endif
    8488.  
    8489.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    8490.                 // Require to have setup baseColor
    8491.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    8492.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    8493.             #endif
    8494.  
    8495.             #ifdef _DOUBLESIDED_ON
    8496.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    8497.             #else
    8498.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    8499.             #endif
    8500.  
    8501.             // normal delivered to master node
    8502.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    8503.  
    8504.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    8505.  
    8506.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    8507.  
    8508.  
    8509.             #if HAVE_DECALS
    8510.                 if (_EnableDecals)
    8511.                 {
    8512.                     float alpha = 1.0;
    8513.                     alpha = surfaceDescription.Alpha;
    8514.  
    8515.                     // Both uses and modifies 'surfaceData.normalWS'.
    8516.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    8517.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    8518.                 }
    8519.             #endif
    8520.  
    8521.             bentNormalWS = surfaceData.normalWS;
    8522.  
    8523.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    8524.  
    8525.             #ifdef DEBUG_DISPLAY
    8526.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    8527.                 {
    8528.                     // TODO: need to update mip info
    8529.                     surfaceData.metallic = 0;
    8530.                 }
    8531.  
    8532.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    8533.                 // as it can modify attribute use for static lighting
    8534.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    8535.             #endif
    8536.  
    8537.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    8538.             // If user provide bent normal then we process a better term
    8539.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    8540.                 // Just use the value passed through via the slot (not active otherwise)
    8541.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    8542.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    8543.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    8544.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    8545.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    8546.             #endif
    8547.  
    8548.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    8549.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    8550.             #endif
    8551.         }
    8552.  
    8553.             // --------------------------------------------------
    8554.             // Get Surface And BuiltinData
    8555.  
    8556.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    8557.             {
    8558.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    8559.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    8560.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    8561.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    8562.                 #endif
    8563.                 #endif
    8564.  
    8565.                 #ifndef SHADER_UNLIT
    8566.                 #ifdef _DOUBLESIDED_ON
    8567.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    8568.                 #else
    8569.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    8570.                 #endif
    8571.  
    8572.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    8573.                 #endif // SHADER_UNLIT
    8574.  
    8575.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    8576.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    8577.  
    8578.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    8579.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    8580.                 #ifdef _ALPHATEST_ON
    8581.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    8582.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    8583.                     // The TransparentDepthPrepass is also used with SSR transparent.
    8584.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    8585.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    8586.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    8587.                     // DepthPostpass always use its own alpha threshold
    8588.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    8589.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    8590.                     // If use shadow threshold isn't enable we don't allow any test
    8591.                     #endif
    8592.  
    8593.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    8594.                 #endif
    8595.  
    8596.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    8597.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    8598.                 #endif
    8599.  
    8600.                 #ifndef SHADER_UNLIT
    8601.                 float3 bentNormalWS;
    8602.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    8603.  
    8604.                 // Builtin Data
    8605.                 // For back lighting we use the oposite vertex normal
    8606.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    8607.  
    8608.                 #else
    8609.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    8610.  
    8611.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    8612.                 builtinData.opacity = surfaceDescription.Alpha;
    8613.  
    8614.                 #if defined(DEBUG_DISPLAY)
    8615.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    8616.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    8617.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    8618.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    8619.                 #endif
    8620.  
    8621.                 #endif // SHADER_UNLIT
    8622.  
    8623.                 #ifdef _ALPHATEST_ON
    8624.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    8625.                     builtinData.alphaClipTreshold = alphaCutoff;
    8626.                 #endif
    8627.  
    8628.                 // override sampleBakedGI - not used by Unlit
    8629.  
    8630.                 builtinData.emissiveColor = surfaceDescription.Emission;
    8631.  
    8632.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    8633.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    8634.                 // This is a limitation of the current MRT approach.
    8635.  
    8636.                 #if _DEPTHOFFSET_ON
    8637.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    8638.                 #endif
    8639.  
    8640.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    8641.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    8642.                 builtinData.distortion = surfaceDescription.Distortion;
    8643.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    8644.                 #endif
    8645.  
    8646.                 #ifndef SHADER_UNLIT
    8647.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    8648.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    8649.                 #else
    8650.                 ApplyDebugToBuiltinData(builtinData);
    8651.                 #endif
    8652.  
    8653.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    8654.             }
    8655.  
    8656.             // --------------------------------------------------
    8657.             // Main
    8658.  
    8659.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingForward.hlsl"
    8660.  
    8661.             ENDHLSL
    8662.         }
    8663.         Pass
    8664.         {
    8665.             Name "GBufferDXR"
    8666.             Tags
    8667.             {
    8668.                 "LightMode" = "GBufferDXR"
    8669.             }
    8670.  
    8671.             // Render State
    8672.             // RenderState: <None>
    8673.  
    8674.             // Debug
    8675.             // <None>
    8676.  
    8677.             // --------------------------------------------------
    8678.             // Pass
    8679.  
    8680.             HLSLPROGRAM
    8681.  
    8682.             // Pragmas
    8683.             #pragma target 5.0
    8684.         #pragma raytracing surface_shader
    8685.         #pragma only_renderers d3d11
    8686.  
    8687.             // Keywords
    8688.             #pragma multi_compile _ MINIMAL_GBUFFER
    8689.         #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    8690.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    8691.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    8692.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    8693.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    8694.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    8695.         #pragma multi_compile _ DEBUG_DISPLAY
    8696.         #pragma shader_feature_local _ _DISABLE_DECALS
    8697.         #pragma shader_feature_local _ _DISABLE_SSR
    8698.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    8699.         #pragma multi_compile _ LIGHTMAP_ON
    8700.         #pragma multi_compile _ DIRLIGHTMAP_COMBINED
    8701.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    8702.             // GraphKeywords: <None>
    8703.  
    8704.             // Early Instancing Defines
    8705.             // DotsInstancingOptions: <None>
    8706.  
    8707.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    8708.             // HybridV1InjectedBuiltinProperties: <None>
    8709.  
    8710.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    8711.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    8712.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    8713.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    8714.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    8715.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    8716.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    8717.  
    8718.             // --------------------------------------------------
    8719.             // Defines
    8720.  
    8721.             // Attribute
    8722.             #define ATTRIBUTES_NEED_NORMAL
    8723.             #define ATTRIBUTES_NEED_TANGENT
    8724.             #define ATTRIBUTES_NEED_TEXCOORD1
    8725.             #define ATTRIBUTES_NEED_TEXCOORD2
    8726.             #define VARYINGS_NEED_POSITION_WS
    8727.             #define VARYINGS_NEED_TANGENT_TO_WORLD
    8728.             #define VARYINGS_NEED_TEXCOORD1
    8729.             #define VARYINGS_NEED_TEXCOORD2
    8730.  
    8731.             #define HAVE_MESH_MODIFICATION
    8732.  
    8733.  
    8734.             #define SHADERPASS SHADERPASS_RAYTRACING_GBUFFER
    8735.         #define SHADOW_LOW
    8736.         #define RAYTRACING_SHADER_GRAPH_RAYTRACED
    8737.  
    8738.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    8739.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    8740.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    8741.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    8742.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    8743.             #define RAYTRACING_SHADER_GRAPH_HIGH
    8744.             #endif
    8745.  
    8746.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    8747.             #define RAYTRACING_SHADER_GRAPH_LOW
    8748.             #endif
    8749.             // end
    8750.  
    8751.             #ifndef SHADER_UNLIT
    8752.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    8753.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    8754.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    8755.                 #define VARYINGS_NEED_CULLFACE
    8756.             #endif
    8757.             #endif
    8758.  
    8759.             // Specific Material Define
    8760.         #define _ENERGY_CONSERVING_SPECULAR 1
    8761.  
    8762.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    8763.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    8764.             #define OUTPUT_SPLIT_LIGHTING
    8765.         #endif
    8766.  
    8767.         // This shader support recursive rendering for raytracing
    8768.         #define HAVE_RECURSIVE_RENDERING
    8769.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    8770.  
    8771.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    8772.             // we should have a code like this:
    8773.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    8774.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    8775.             // endif
    8776.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    8777.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    8778.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    8779.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    8780.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    8781.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    8782.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    8783.                 #define WRITE_NORMAL_BUFFER
    8784.             #endif
    8785.             #endif
    8786.  
    8787.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    8788.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    8789.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    8790.             // the constant buffer. A bug is filed and is being looked at.
    8791.             #if defined(SHADER_API_VULKAN)
    8792.             #define DISABLE_UNLIT_DEEXPOSURE
    8793.             #endif
    8794.  
    8795.             #ifndef DEBUG_DISPLAY
    8796.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    8797.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    8798.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    8799.                     #if SHADERPASS == SHADERPASS_FORWARD
    8800.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    8801.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    8802.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    8803.                     #endif
    8804.                 #endif
    8805.             #endif
    8806.  
    8807.             // Translate transparent motion vector define
    8808.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    8809.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    8810.             #endif
    8811.  
    8812.             // -- Graph Properties
    8813.             CBUFFER_START(UnityPerMaterial)
    8814.         float4 _EmissionColor;
    8815.         float _UseShadowThreshold;
    8816.         float4 _DoubleSidedConstants;
    8817.         float _BlendMode;
    8818.         float _EnableBlendModePreserveSpecularLighting;
    8819.         float _RayTracing;
    8820.         float _RefractionModel;
    8821.         CBUFFER_END
    8822.  
    8823.         // Object and Global properties
    8824.  
    8825.             // -- Property used by ScenePickingPass
    8826.             #ifdef SCENEPICKINGPASS
    8827.             float4 _SelectionID;
    8828.             #endif
    8829.  
    8830.             // -- Properties used by SceneSelectionPass
    8831.             #ifdef SCENESELECTIONPASS
    8832.             int _ObjectId;
    8833.             int _PassValue;
    8834.             #endif
    8835.  
    8836.             // Includes
    8837.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl"
    8838.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    8839.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl"
    8840.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl"
    8841.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingIntersectonGBuffer.hlsl"
    8842.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    8843.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.hlsl"
    8844.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRaytracing.hlsl"
    8845.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    8846.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    8847.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingCommon.hlsl"
    8848.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    8849.  
    8850.             // --------------------------------------------------
    8851.             // Structs and Packing
    8852.  
    8853.             struct AttributesMesh
    8854.         {
    8855.             float3 positionOS : POSITION;
    8856.             float3 normalOS : NORMAL;
    8857.             float4 tangentOS : TANGENT;
    8858.             float4 uv1 : TEXCOORD1;
    8859.             float4 uv2 : TEXCOORD2;
    8860.             #if UNITY_ANY_INSTANCING_ENABLED
    8861.             uint instanceID : INSTANCEID_SEMANTIC;
    8862.             #endif
    8863.         };
    8864.         struct VaryingsMeshToPS
    8865.         {
    8866.             float4 positionCS : SV_POSITION;
    8867.             float3 positionRWS;
    8868.             float3 normalWS;
    8869.             float4 tangentWS;
    8870.             float4 texCoord1;
    8871.             float4 texCoord2;
    8872.             #if UNITY_ANY_INSTANCING_ENABLED
    8873.             uint instanceID : CUSTOM_INSTANCE_ID;
    8874.             #endif
    8875.         };
    8876.         struct SurfaceDescriptionInputs
    8877.         {
    8878.             float3 TangentSpaceNormal;
    8879.         };
    8880.         struct VertexDescriptionInputs
    8881.         {
    8882.             float3 ObjectSpaceNormal;
    8883.             float3 ObjectSpaceTangent;
    8884.             float3 ObjectSpacePosition;
    8885.         };
    8886.         struct PackedVaryingsMeshToPS
    8887.         {
    8888.             float4 positionCS : SV_POSITION;
    8889.             float3 interp0 : TEXCOORD0;
    8890.             float3 interp1 : TEXCOORD1;
    8891.             float4 interp2 : TEXCOORD2;
    8892.             float4 interp3 : TEXCOORD3;
    8893.             float4 interp4 : TEXCOORD4;
    8894.             #if UNITY_ANY_INSTANCING_ENABLED
    8895.             uint instanceID : CUSTOM_INSTANCE_ID;
    8896.             #endif
    8897.         };
    8898.  
    8899.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    8900.         {
    8901.             PackedVaryingsMeshToPS output;
    8902.             output.positionCS = input.positionCS;
    8903.             output.interp0.xyz =  input.positionRWS;
    8904.             output.interp1.xyz =  input.normalWS;
    8905.             output.interp2.xyzw =  input.tangentWS;
    8906.             output.interp3.xyzw =  input.texCoord1;
    8907.             output.interp4.xyzw =  input.texCoord2;
    8908.             #if UNITY_ANY_INSTANCING_ENABLED
    8909.             output.instanceID = input.instanceID;
    8910.             #endif
    8911.             return output;
    8912.         }
    8913.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    8914.         {
    8915.             VaryingsMeshToPS output;
    8916.             output.positionCS = input.positionCS;
    8917.             output.positionRWS = input.interp0.xyz;
    8918.             output.normalWS = input.interp1.xyz;
    8919.             output.tangentWS = input.interp2.xyzw;
    8920.             output.texCoord1 = input.interp3.xyzw;
    8921.             output.texCoord2 = input.interp4.xyzw;
    8922.             #if UNITY_ANY_INSTANCING_ENABLED
    8923.             output.instanceID = input.instanceID;
    8924.             #endif
    8925.             return output;
    8926.         }
    8927.  
    8928.             // --------------------------------------------------
    8929.             // Graph
    8930.  
    8931.  
    8932.             // Graph Functions
    8933.             // GraphFunctions: <None>
    8934.  
    8935.             // Graph Vertex
    8936.             struct VertexDescription
    8937.         {
    8938.             float3 Position;
    8939.             float3 Normal;
    8940.             float3 Tangent;
    8941.         };
    8942.  
    8943.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    8944.         {
    8945.             VertexDescription description = (VertexDescription)0;
    8946.             description.Position = IN.ObjectSpacePosition;
    8947.             description.Normal = IN.ObjectSpaceNormal;
    8948.             description.Tangent = IN.ObjectSpaceTangent;
    8949.             return description;
    8950.         }
    8951.  
    8952.             // Graph Pixel
    8953.             struct SurfaceDescription
    8954.         {
    8955.             float3 BaseColor;
    8956.             float3 Emission;
    8957.             float Alpha;
    8958.             float3 BentNormal;
    8959.             float Smoothness;
    8960.             float Occlusion;
    8961.             float3 NormalTS;
    8962.             float Metallic;
    8963.         };
    8964.  
    8965.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    8966.         {
    8967.             SurfaceDescription surface = (SurfaceDescription)0;
    8968.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    8969.             surface.Emission = float3(0, 0, 0);
    8970.             surface.Alpha = 1;
    8971.             surface.BentNormal = IN.TangentSpaceNormal;
    8972.             surface.Smoothness = 0.5;
    8973.             surface.Occlusion = 1;
    8974.             surface.NormalTS = IN.TangentSpaceNormal;
    8975.             surface.Metallic = 0;
    8976.             return surface;
    8977.         }
    8978.  
    8979.             // --------------------------------------------------
    8980.             // Build Graph Inputs
    8981.  
    8982.            
    8983.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    8984.         {
    8985.             VertexDescriptionInputs output;
    8986.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    8987.  
    8988.             output.ObjectSpaceNormal =           input.normalOS;
    8989.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    8990.             output.ObjectSpacePosition =         input.positionOS;
    8991.  
    8992.             return output;
    8993.         }
    8994.  
    8995.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    8996.         {
    8997.             // build graph inputs
    8998.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    8999.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    9000.  
    9001.             // evaluate vertex graph
    9002.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    9003.  
    9004.             // copy graph output to the results
    9005.             input.positionOS = vertexDescription.Position;
    9006.             input.normalOS = vertexDescription.Normal;
    9007.             input.tangentOS.xyz = vertexDescription.Tangent;
    9008.  
    9009.             return input;
    9010.         }
    9011.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    9012.         {
    9013.             FragInputs output;
    9014.             ZERO_INITIALIZE(FragInputs, output);
    9015.  
    9016.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    9017.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    9018.             // to compute normals which are then passed on elsewhere to compute other values...
    9019.             output.tangentToWorld = k_identity3x3;
    9020.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    9021.  
    9022.             output.positionRWS = input.positionRWS;
    9023.             output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS);
    9024.             output.texCoord1 = input.texCoord1;
    9025.             output.texCoord2 = input.texCoord2;
    9026.  
    9027.             return output;
    9028.         }
    9029.  
    9030.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    9031.         {
    9032.             SurfaceDescriptionInputs output;
    9033.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    9034.  
    9035.             #if defined(SHADER_STAGE_RAY_TRACING)
    9036.             #else
    9037.             #endif
    9038.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    9039.  
    9040.             return output;
    9041.         }
    9042.  
    9043.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    9044.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    9045.         {
    9046.             UNITY_SETUP_INSTANCE_ID(input);
    9047.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    9048.             return BuildFragInputs(unpacked);
    9049.         }
    9050.  
    9051.             // --------------------------------------------------
    9052.             // Build Surface Data (Specific Material)
    9053.  
    9054.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    9055.         {
    9056.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    9057.  
    9058.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    9059.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    9060.             surfaceData.specularOcclusion = 1.0;
    9061.  
    9062.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    9063.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    9064.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    9065.             surfaceData.metallic =                  surfaceDescription.Metallic;
    9066.  
    9067.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    9068.                 if (_EnableSSRefraction)
    9069.                 {
    9070.  
    9071.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    9072.                     surfaceDescription.Alpha = 1.0;
    9073.                 }
    9074.                 else
    9075.                 {
    9076.                     surfaceData.ior = 1.0;
    9077.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    9078.                     surfaceData.atDistance = 1.0;
    9079.                     surfaceData.transmittanceMask = 0.0;
    9080.                     surfaceDescription.Alpha = 1.0;
    9081.                 }
    9082.             #else
    9083.                 surfaceData.ior = 1.0;
    9084.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    9085.                 surfaceData.atDistance = 1.0;
    9086.                 surfaceData.transmittanceMask = 0.0;
    9087.             #endif
    9088.  
    9089.             // These static material feature allow compile time optimization
    9090.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    9091.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    9092.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    9093.             #endif
    9094.  
    9095.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    9096.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    9097.             #endif
    9098.  
    9099.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    9100.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    9101.             #endif
    9102.  
    9103.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    9104.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    9105.             #endif
    9106.  
    9107.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    9108.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    9109.             #endif
    9110.  
    9111.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    9112.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    9113.             #endif
    9114.  
    9115.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    9116.                 // Require to have setup baseColor
    9117.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    9118.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    9119.             #endif
    9120.  
    9121.             #ifdef _DOUBLESIDED_ON
    9122.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    9123.             #else
    9124.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    9125.             #endif
    9126.  
    9127.             // normal delivered to master node
    9128.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    9129.  
    9130.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    9131.  
    9132.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    9133.  
    9134.  
    9135.             #if HAVE_DECALS
    9136.                 if (_EnableDecals)
    9137.                 {
    9138.                     float alpha = 1.0;
    9139.                     alpha = surfaceDescription.Alpha;
    9140.  
    9141.                     // Both uses and modifies 'surfaceData.normalWS'.
    9142.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    9143.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    9144.                 }
    9145.             #endif
    9146.  
    9147.             bentNormalWS = surfaceData.normalWS;
    9148.  
    9149.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    9150.  
    9151.             #ifdef DEBUG_DISPLAY
    9152.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    9153.                 {
    9154.                     // TODO: need to update mip info
    9155.                     surfaceData.metallic = 0;
    9156.                 }
    9157.  
    9158.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    9159.                 // as it can modify attribute use for static lighting
    9160.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    9161.             #endif
    9162.  
    9163.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    9164.             // If user provide bent normal then we process a better term
    9165.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    9166.                 // Just use the value passed through via the slot (not active otherwise)
    9167.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    9168.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    9169.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    9170.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    9171.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    9172.             #endif
    9173.  
    9174.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    9175.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    9176.             #endif
    9177.         }
    9178.  
    9179.             // --------------------------------------------------
    9180.             // Get Surface And BuiltinData
    9181.  
    9182.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    9183.             {
    9184.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    9185.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    9186.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    9187.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    9188.                 #endif
    9189.                 #endif
    9190.  
    9191.                 #ifndef SHADER_UNLIT
    9192.                 #ifdef _DOUBLESIDED_ON
    9193.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    9194.                 #else
    9195.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    9196.                 #endif
    9197.  
    9198.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    9199.                 #endif // SHADER_UNLIT
    9200.  
    9201.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    9202.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    9203.  
    9204.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    9205.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    9206.                 #ifdef _ALPHATEST_ON
    9207.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    9208.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    9209.                     // The TransparentDepthPrepass is also used with SSR transparent.
    9210.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    9211.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    9212.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    9213.                     // DepthPostpass always use its own alpha threshold
    9214.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    9215.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    9216.                     // If use shadow threshold isn't enable we don't allow any test
    9217.                     #endif
    9218.  
    9219.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    9220.                 #endif
    9221.  
    9222.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    9223.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    9224.                 #endif
    9225.  
    9226.                 #ifndef SHADER_UNLIT
    9227.                 float3 bentNormalWS;
    9228.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    9229.  
    9230.                 // Builtin Data
    9231.                 // For back lighting we use the oposite vertex normal
    9232.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    9233.  
    9234.                 #else
    9235.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    9236.  
    9237.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    9238.                 builtinData.opacity = surfaceDescription.Alpha;
    9239.  
    9240.                 #if defined(DEBUG_DISPLAY)
    9241.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    9242.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    9243.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    9244.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    9245.                 #endif
    9246.  
    9247.                 #endif // SHADER_UNLIT
    9248.  
    9249.                 #ifdef _ALPHATEST_ON
    9250.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    9251.                     builtinData.alphaClipTreshold = alphaCutoff;
    9252.                 #endif
    9253.  
    9254.                 // override sampleBakedGI - not used by Unlit
    9255.  
    9256.                 builtinData.emissiveColor = surfaceDescription.Emission;
    9257.  
    9258.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    9259.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    9260.                 // This is a limitation of the current MRT approach.
    9261.  
    9262.                 #if _DEPTHOFFSET_ON
    9263.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    9264.                 #endif
    9265.  
    9266.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    9267.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    9268.                 builtinData.distortion = surfaceDescription.Distortion;
    9269.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    9270.                 #endif
    9271.  
    9272.                 #ifndef SHADER_UNLIT
    9273.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    9274.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    9275.                 #else
    9276.                 ApplyDebugToBuiltinData(builtinData);
    9277.                 #endif
    9278.  
    9279.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    9280.             }
    9281.  
    9282.             // --------------------------------------------------
    9283.             // Main
    9284.  
    9285.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderpassRaytracingGBuffer.hlsl"
    9286.  
    9287.             ENDHLSL
    9288.         }
    9289.         Pass
    9290.         {
    9291.             Name "PathTracingDXR"
    9292.             Tags
    9293.             {
    9294.                 "LightMode" = "PathTracingDXR"
    9295.             }
    9296.  
    9297.             // Render State
    9298.             // RenderState: <None>
    9299.  
    9300.             // Debug
    9301.             // <None>
    9302.  
    9303.             // --------------------------------------------------
    9304.             // Pass
    9305.  
    9306.             HLSLPROGRAM
    9307.  
    9308.             // Pragmas
    9309.             #pragma target 5.0
    9310.         #pragma raytracing surface_shader
    9311.         #pragma only_renderers d3d11
    9312.  
    9313.             // Keywords
    9314.             #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
    9315.         #pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY
    9316.         #pragma shader_feature_local _ _DOUBLESIDED_ON
    9317.         #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
    9318.         #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC
    9319.         #pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT
    9320.         #pragma shader_feature_local _ _DISABLE_DECALS
    9321.         #pragma shader_feature_local _ _DISABLE_SSR
    9322.         #pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT
    9323.         #pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN
    9324.             // GraphKeywords: <None>
    9325.  
    9326.             // Early Instancing Defines
    9327.             // DotsInstancingOptions: <None>
    9328.  
    9329.             // Injected Instanced Properties (must be included before UnityInstancing.hlsl)
    9330.             // HybridV1InjectedBuiltinProperties: <None>
    9331.  
    9332.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    9333.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
    9334.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    9335.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    9336.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    9337.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB
    9338.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition
    9339.  
    9340.             // --------------------------------------------------
    9341.             // Defines
    9342.  
    9343.             // Attribute
    9344.             #define ATTRIBUTES_NEED_NORMAL
    9345.             #define ATTRIBUTES_NEED_TANGENT
    9346.  
    9347.             #define HAVE_MESH_MODIFICATION
    9348.  
    9349.  
    9350.             #define SHADERPASS SHADERPASS_PATH_TRACING
    9351.         #define SHADOW_LOW
    9352.         #define RAYTRACING_SHADER_GRAPH_DEFAULT
    9353.         #define HAS_LIGHTLOOP
    9354.  
    9355.             // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode
    9356.             // The ShaderGraph don't support correctly migration of this node as it serialize all the node data
    9357.             // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here
    9358.             // to still allow us to rename the field and keyword of this node without breaking existing code.
    9359.             #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
    9360.             #define RAYTRACING_SHADER_GRAPH_HIGH
    9361.             #endif
    9362.  
    9363.             #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
    9364.             #define RAYTRACING_SHADER_GRAPH_LOW
    9365.             #endif
    9366.             // end
    9367.  
    9368.             #ifndef SHADER_UNLIT
    9369.             // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode
    9370.             // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph.
    9371.             #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
    9372.                 #define VARYINGS_NEED_CULLFACE
    9373.             #endif
    9374.             #endif
    9375.  
    9376.             // Specific Material Define
    9377.         #define _ENERGY_CONSERVING_SPECULAR 1
    9378.  
    9379.         // If we use subsurface scattering, enable output split lighting (for forward pass)
    9380.         #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT)
    9381.             #define OUTPUT_SPLIT_LIGHTING
    9382.         #endif
    9383.  
    9384.         // This shader support recursive rendering for raytracing
    9385.         #define HAVE_RECURSIVE_RENDERING
    9386.             // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it
    9387.  
    9388.             // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings
    9389.             // we should have a code like this:
    9390.             // if !defined(_DISABLE_SSR_TRANSPARENT)
    9391.             // pragma multi_compile _ WRITE_NORMAL_BUFFER
    9392.             // endif
    9393.             // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive
    9394.             // it based on if SSR transparent in frame settings and not (and stripper can strip it).
    9395.             // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define
    9396.             // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled.
    9397.             // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now.
    9398.             #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    9399.             #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
    9400.                 #define WRITE_NORMAL_BUFFER
    9401.             #endif
    9402.             #endif
    9403.  
    9404.             // NOTE: disabling de exposure usage on unlit shader graphs (caused by virtual texture constant buffer binding).
    9405.             // If we turn this on, in vulkan, virtual texture offsets are corrupted. It is likely caused by the stack
    9406.             // textures constant buffers, which utilize arrays. Something is happening to the reflection data of vulkan which completely displaces
    9407.             // the constant buffer. A bug is filed and is being looked at.
    9408.             #if defined(SHADER_API_VULKAN)
    9409.             #define DISABLE_UNLIT_DEEXPOSURE
    9410.             #endif
    9411.  
    9412.             #ifndef DEBUG_DISPLAY
    9413.                 // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
    9414.                 // Don't do it with debug display mode as it is possible there is no depth prepass in this case
    9415.                 #if !defined(_SURFACE_TYPE_TRANSPARENT)
    9416.                     #if SHADERPASS == SHADERPASS_FORWARD
    9417.                     #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
    9418.                     #elif SHADERPASS == SHADERPASS_GBUFFER
    9419.                     #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
    9420.                     #endif
    9421.                 #endif
    9422.             #endif
    9423.  
    9424.             // Translate transparent motion vector define
    9425.             #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT)
    9426.                 #define _WRITE_TRANSPARENT_MOTION_VECTOR
    9427.             #endif
    9428.  
    9429.             // -- Graph Properties
    9430.             CBUFFER_START(UnityPerMaterial)
    9431.         float4 _EmissionColor;
    9432.         float _UseShadowThreshold;
    9433.         float4 _DoubleSidedConstants;
    9434.         float _BlendMode;
    9435.         float _EnableBlendModePreserveSpecularLighting;
    9436.         float _RayTracing;
    9437.         float _RefractionModel;
    9438.         CBUFFER_END
    9439.  
    9440.         // Object and Global properties
    9441.  
    9442.             // -- Property used by ScenePickingPass
    9443.             #ifdef SCENEPICKINGPASS
    9444.             float4 _SelectionID;
    9445.             #endif
    9446.  
    9447.             // -- Properties used by SceneSelectionPass
    9448.             #ifdef SCENESELECTIONPASS
    9449.             int _ObjectId;
    9450.             int _PassValue;
    9451.             #endif
    9452.  
    9453.             // Includes
    9454.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl"
    9455.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
    9456.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl"
    9457.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl"
    9458.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl"
    9459.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"
    9460.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl"
    9461.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
    9462.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl"
    9463.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
    9464.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
    9465.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingCommon.hlsl"
    9466.         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
    9467.  
    9468.             // --------------------------------------------------
    9469.             // Structs and Packing
    9470.  
    9471.             struct AttributesMesh
    9472.         {
    9473.             float3 positionOS : POSITION;
    9474.             float3 normalOS : NORMAL;
    9475.             float4 tangentOS : TANGENT;
    9476.             #if UNITY_ANY_INSTANCING_ENABLED
    9477.             uint instanceID : INSTANCEID_SEMANTIC;
    9478.             #endif
    9479.         };
    9480.         struct VaryingsMeshToPS
    9481.         {
    9482.             float4 positionCS : SV_POSITION;
    9483.             #if UNITY_ANY_INSTANCING_ENABLED
    9484.             uint instanceID : CUSTOM_INSTANCE_ID;
    9485.             #endif
    9486.         };
    9487.         struct SurfaceDescriptionInputs
    9488.         {
    9489.             float3 TangentSpaceNormal;
    9490.         };
    9491.         struct VertexDescriptionInputs
    9492.         {
    9493.             float3 ObjectSpaceNormal;
    9494.             float3 ObjectSpaceTangent;
    9495.             float3 ObjectSpacePosition;
    9496.         };
    9497.         struct PackedVaryingsMeshToPS
    9498.         {
    9499.             float4 positionCS : SV_POSITION;
    9500.             #if UNITY_ANY_INSTANCING_ENABLED
    9501.             uint instanceID : CUSTOM_INSTANCE_ID;
    9502.             #endif
    9503.         };
    9504.  
    9505.             PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input)
    9506.         {
    9507.             PackedVaryingsMeshToPS output;
    9508.             output.positionCS = input.positionCS;
    9509.             #if UNITY_ANY_INSTANCING_ENABLED
    9510.             output.instanceID = input.instanceID;
    9511.             #endif
    9512.             return output;
    9513.         }
    9514.         VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input)
    9515.         {
    9516.             VaryingsMeshToPS output;
    9517.             output.positionCS = input.positionCS;
    9518.             #if UNITY_ANY_INSTANCING_ENABLED
    9519.             output.instanceID = input.instanceID;
    9520.             #endif
    9521.             return output;
    9522.         }
    9523.  
    9524.             // --------------------------------------------------
    9525.             // Graph
    9526.  
    9527.  
    9528.             // Graph Functions
    9529.             // GraphFunctions: <None>
    9530.  
    9531.             // Graph Vertex
    9532.             struct VertexDescription
    9533.         {
    9534.             float3 Position;
    9535.             float3 Normal;
    9536.             float3 Tangent;
    9537.         };
    9538.  
    9539.         VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
    9540.         {
    9541.             VertexDescription description = (VertexDescription)0;
    9542.             description.Position = IN.ObjectSpacePosition;
    9543.             description.Normal = IN.ObjectSpaceNormal;
    9544.             description.Tangent = IN.ObjectSpaceTangent;
    9545.             return description;
    9546.         }
    9547.  
    9548.             // Graph Pixel
    9549.             struct SurfaceDescription
    9550.         {
    9551.             float3 BaseColor;
    9552.             float3 Emission;
    9553.             float Alpha;
    9554.             float3 BentNormal;
    9555.             float Smoothness;
    9556.             float Occlusion;
    9557.             float3 NormalTS;
    9558.             float Metallic;
    9559.         };
    9560.  
    9561.         SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
    9562.         {
    9563.             SurfaceDescription surface = (SurfaceDescription)0;
    9564.             surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
    9565.             surface.Emission = float3(0, 0, 0);
    9566.             surface.Alpha = 1;
    9567.             surface.BentNormal = IN.TangentSpaceNormal;
    9568.             surface.Smoothness = 0.5;
    9569.             surface.Occlusion = 1;
    9570.             surface.NormalTS = IN.TangentSpaceNormal;
    9571.             surface.Metallic = 0;
    9572.             return surface;
    9573.         }
    9574.  
    9575.             // --------------------------------------------------
    9576.             // Build Graph Inputs
    9577.  
    9578.            
    9579.         VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input)
    9580.         {
    9581.             VertexDescriptionInputs output;
    9582.             ZERO_INITIALIZE(VertexDescriptionInputs, output);
    9583.  
    9584.             output.ObjectSpaceNormal =           input.normalOS;
    9585.             output.ObjectSpaceTangent =          input.tangentOS.xyz;
    9586.             output.ObjectSpacePosition =         input.positionOS;
    9587.  
    9588.             return output;
    9589.         }
    9590.  
    9591.         AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters)
    9592.         {
    9593.             // build graph inputs
    9594.             VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input);
    9595.             // Override time paramters with used one (This is required to correctly handle motion vector for vertex animation based on time)
    9596.  
    9597.             // evaluate vertex graph
    9598.             VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs);
    9599.  
    9600.             // copy graph output to the results
    9601.             input.positionOS = vertexDescription.Position;
    9602.             input.normalOS = vertexDescription.Normal;
    9603.             input.tangentOS.xyz = vertexDescription.Tangent;
    9604.  
    9605.             return input;
    9606.         }
    9607.             FragInputs BuildFragInputs(VaryingsMeshToPS input)
    9608.         {
    9609.             FragInputs output;
    9610.             ZERO_INITIALIZE(FragInputs, output);
    9611.  
    9612.             // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used).
    9613.             // TODO: this is a really poor workaround, but the variable is used in a bunch of places
    9614.             // to compute normals which are then passed on elsewhere to compute other values...
    9615.             output.tangentToWorld = k_identity3x3;
    9616.             output.positionSS = input.positionCS;       // input.positionCS is SV_Position
    9617.  
    9618.  
    9619.             return output;
    9620.         }
    9621.  
    9622.         SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS)
    9623.         {
    9624.             SurfaceDescriptionInputs output;
    9625.             ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
    9626.  
    9627.             #if defined(SHADER_STAGE_RAY_TRACING)
    9628.             #else
    9629.             #endif
    9630.             output.TangentSpaceNormal =          float3(0.0f, 0.0f, 1.0f);
    9631.  
    9632.             return output;
    9633.         }
    9634.  
    9635.         // existing HDRP code uses the combined function to go directly from packed to frag inputs
    9636.         FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
    9637.         {
    9638.             UNITY_SETUP_INSTANCE_ID(input);
    9639.             VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input);
    9640.             return BuildFragInputs(unpacked);
    9641.         }
    9642.  
    9643.             // --------------------------------------------------
    9644.             // Build Surface Data (Specific Material)
    9645.  
    9646.         void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
    9647.         {
    9648.             ZERO_INITIALIZE(SurfaceData, surfaceData);
    9649.  
    9650.             // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct
    9651.             // however specularOcclusion can come from the graph, so need to be init here so it can be override.
    9652.             surfaceData.specularOcclusion = 1.0;
    9653.  
    9654.             surfaceData.baseColor =                 surfaceDescription.BaseColor;
    9655.             surfaceData.perceptualSmoothness =      surfaceDescription.Smoothness;
    9656.             surfaceData.ambientOcclusion =          surfaceDescription.Occlusion;
    9657.             surfaceData.metallic =                  surfaceDescription.Metallic;
    9658.  
    9659.             #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN)
    9660.                 if (_EnableSSRefraction)
    9661.                 {
    9662.  
    9663.                     surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha);
    9664.                     surfaceDescription.Alpha = 1.0;
    9665.                 }
    9666.                 else
    9667.                 {
    9668.                     surfaceData.ior = 1.0;
    9669.                     surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    9670.                     surfaceData.atDistance = 1.0;
    9671.                     surfaceData.transmittanceMask = 0.0;
    9672.                     surfaceDescription.Alpha = 1.0;
    9673.                 }
    9674.             #else
    9675.                 surfaceData.ior = 1.0;
    9676.                 surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
    9677.                 surfaceData.atDistance = 1.0;
    9678.                 surfaceData.transmittanceMask = 0.0;
    9679.             #endif
    9680.  
    9681.             // These static material feature allow compile time optimization
    9682.             surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
    9683.             #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
    9684.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
    9685.             #endif
    9686.  
    9687.             #ifdef _MATERIAL_FEATURE_TRANSMISSION
    9688.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
    9689.             #endif
    9690.  
    9691.             #ifdef _MATERIAL_FEATURE_ANISOTROPY
    9692.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
    9693.             #endif
    9694.  
    9695.             #ifdef _MATERIAL_FEATURE_IRIDESCENCE
    9696.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
    9697.             #endif
    9698.  
    9699.             #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
    9700.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
    9701.             #endif
    9702.  
    9703.             #ifdef _MATERIAL_FEATURE_CLEAR_COAT
    9704.                 surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
    9705.             #endif
    9706.  
    9707.             #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR)
    9708.                 // Require to have setup baseColor
    9709.                 // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
    9710.                 surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b));
    9711.             #endif
    9712.  
    9713.             #ifdef _DOUBLESIDED_ON
    9714.                 float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    9715.             #else
    9716.                 float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    9717.             #endif
    9718.  
    9719.             // normal delivered to master node
    9720.             GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants);
    9721.  
    9722.             surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
    9723.  
    9724.             surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz);    // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
    9725.  
    9726.  
    9727.             #if HAVE_DECALS
    9728.                 if (_EnableDecals)
    9729.                 {
    9730.                     float alpha = 1.0;
    9731.                     alpha = surfaceDescription.Alpha;
    9732.  
    9733.                     // Both uses and modifies 'surfaceData.normalWS'.
    9734.                     DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
    9735.                     ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData);
    9736.                 }
    9737.             #endif
    9738.  
    9739.             bentNormalWS = surfaceData.normalWS;
    9740.  
    9741.             surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
    9742.  
    9743.             #ifdef DEBUG_DISPLAY
    9744.                 if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
    9745.                 {
    9746.                     // TODO: need to update mip info
    9747.                     surfaceData.metallic = 0;
    9748.                 }
    9749.  
    9750.                 // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData
    9751.                 // as it can modify attribute use for static lighting
    9752.                 ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
    9753.             #endif
    9754.  
    9755.             // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
    9756.             // If user provide bent normal then we process a better term
    9757.             #if defined(_SPECULAR_OCCLUSION_CUSTOM)
    9758.                 // Just use the value passed through via the slot (not active otherwise)
    9759.             #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
    9760.                 // If we have bent normal and ambient occlusion, process a specular occlusion
    9761.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
    9762.             #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
    9763.                 surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
    9764.             #endif
    9765.  
    9766.             #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
    9767.                 surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
    9768.             #endif
    9769.         }
    9770.  
    9771.             // --------------------------------------------------
    9772.             // Get Surface And BuiltinData
    9773.  
    9774.             void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
    9775.             {
    9776.                 // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
    9777.                 #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
    9778.                 #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
    9779.                 LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
    9780.                 #endif
    9781.                 #endif
    9782.  
    9783.                 #ifndef SHADER_UNLIT
    9784.                 #ifdef _DOUBLESIDED_ON
    9785.                     float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
    9786.                 #else
    9787.                     float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
    9788.                 #endif
    9789.  
    9790.                 ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal
    9791.                 #endif // SHADER_UNLIT
    9792.  
    9793.                 SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V);
    9794.                 SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
    9795.  
    9796.                 // Perform alpha test very early to save performance (a killed pixel will not sample textures)
    9797.                 // TODO: split graph evaluation to grab just alpha dependencies first? tricky..
    9798.                 #ifdef _ALPHATEST_ON
    9799.                     float alphaCutoff = surfaceDescription.AlphaClipThreshold;
    9800.                     #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
    9801.                     // The TransparentDepthPrepass is also used with SSR transparent.
    9802.                     // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold
    9803.                     // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass
    9804.                     #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
    9805.                     // DepthPostpass always use its own alpha threshold
    9806.                     alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass;
    9807.                     #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
    9808.                     // If use shadow threshold isn't enable we don't allow any test
    9809.                     #endif
    9810.  
    9811.                     GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff);
    9812.                 #endif
    9813.  
    9814.                 #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON
    9815.                 ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
    9816.                 #endif
    9817.  
    9818.                 #ifndef SHADER_UNLIT
    9819.                 float3 bentNormalWS;
    9820.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
    9821.  
    9822.                 // Builtin Data
    9823.                 // For back lighting we use the oposite vertex normal
    9824.                 InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
    9825.  
    9826.                 #else
    9827.                 BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData);
    9828.  
    9829.                 ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting
    9830.                 builtinData.opacity = surfaceDescription.Alpha;
    9831.  
    9832.                 #if defined(DEBUG_DISPLAY)
    9833.                     // Light Layers are currently not used for the Unlit shader (because it is not lit)
    9834.                     // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to
    9835.                     // display in the light layers visualization mode, therefore we need the renderingLayers
    9836.                     builtinData.renderingLayers = GetMeshRenderingLightLayer();
    9837.                 #endif
    9838.  
    9839.                 #endif // SHADER_UNLIT
    9840.  
    9841.                 #ifdef _ALPHATEST_ON
    9842.                     // Used for sharpening by alpha to mask - Alpha to covertage is only used with depth only and forward pass (no shadow pass, no transparent pass)
    9843.                     builtinData.alphaClipTreshold = alphaCutoff;
    9844.                 #endif
    9845.  
    9846.                 // override sampleBakedGI - not used by Unlit
    9847.  
    9848.                 builtinData.emissiveColor = surfaceDescription.Emission;
    9849.  
    9850.                 // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define)
    9851.                 // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved
    9852.                 // This is a limitation of the current MRT approach.
    9853.  
    9854.                 #if _DEPTHOFFSET_ON
    9855.                 builtinData.depthOffset = surfaceDescription.DepthOffset;
    9856.                 #endif
    9857.  
    9858.                 // TODO: We should generate distortion / distortionBlur for non distortion pass
    9859.                 #if (SHADERPASS == SHADERPASS_DISTORTION)
    9860.                 builtinData.distortion = surfaceDescription.Distortion;
    9861.                 builtinData.distortionBlur = surfaceDescription.DistortionBlur;
    9862.                 #endif
    9863.  
    9864.                 #ifndef SHADER_UNLIT
    9865.                 // PostInitBuiltinData call ApplyDebugToBuiltinData
    9866.                 PostInitBuiltinData(V, posInput, surfaceData, builtinData);
    9867.                 #else
    9868.                 ApplyDebugToBuiltinData(builtinData);
    9869.                 #endif
    9870.  
    9871.                 RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
    9872.             }
    9873.  
    9874.             // --------------------------------------------------
    9875.             // Main
    9876.  
    9877.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl"
    9878.  
    9879.             ENDHLSL
    9880.         }
    9881.     }
    9882.     CustomEditorForRenderPipeline "Rendering.HighDefinition.LitShaderGraphGUI" "UnityEngine.Rendering.HighDefinition.HDRenderPipelineAsset"
    9883.     FallBack "Hidden/Shader Graph/FallbackError"
    9884. }
     
  6. alexanderkudryavy

    alexanderkudryavy

    Joined:
    Sep 20, 2019
    Posts:
    13
    I wanna use light on stencil object but i cant....