From 44a04330120cb16b331fd3ebd6089f261f9af7fa Mon Sep 17 00:00:00 2001 From: LiRuoChen <571244399@qq.com> Date: Sat, 9 Dec 2023 15:38:24 +0800 Subject: [PATCH] backup --- .../.idea/vcs.xml | 1 - .../.idea/workspace.xml | 39 +- .../effect2d/Decal_CircleWave_SD.shader | 16247 ---------------- .../effect2d/Decal_CircleWave_SD.shader.meta | 9 - Assets/Scenes/PrefabEditingSceneOld.unity | 25 +- Packages/manifest.json | 1 + Packages/packages-lock.json | 21 + 7 files changed, 61 insertions(+), 16282 deletions(-) delete mode 100644 Assets/LRC/Material/HDRP_Shader/effect2d/Decal_CircleWave_SD.shader delete mode 100644 Assets/LRC/Material/HDRP_Shader/effect2d/Decal_CircleWave_SD.shader.meta diff --git a/.idea/.idea.TowerCraneVisualization_HDRP_master/.idea/vcs.xml b/.idea/.idea.TowerCraneVisualization_HDRP_master/.idea/vcs.xml index b7c6f1f..adc21a6 100644 --- a/.idea/.idea.TowerCraneVisualization_HDRP_master/.idea/vcs.xml +++ b/.idea/.idea.TowerCraneVisualization_HDRP_master/.idea/vcs.xml @@ -1,7 +1,6 @@ - diff --git a/.idea/.idea.TowerCraneVisualization_HDRP_master/.idea/workspace.xml b/.idea/.idea.TowerCraneVisualization_HDRP_master/.idea/workspace.xml index 30f3856..75c8b36 100644 --- a/.idea/.idea.TowerCraneVisualization_HDRP_master/.idea/workspace.xml +++ b/.idea/.idea.TowerCraneVisualization_HDRP_master/.idea/workspace.xml @@ -5,20 +5,16 @@ - - - - - - - - - - - - - + + + + + + + + + - + + + + - - + diff --git a/Assets/LRC/Material/HDRP_Shader/effect2d/Decal_CircleWave_SD.shader b/Assets/LRC/Material/HDRP_Shader/effect2d/Decal_CircleWave_SD.shader deleted file mode 100644 index f479f3e..0000000 --- a/Assets/LRC/Material/HDRP_Shader/effect2d/Decal_CircleWave_SD.shader +++ /dev/null @@ -1,16247 +0,0 @@ -Shader "Shader Graphs/Decal_CircleWave_SG" -{ - Properties - { - _BaseColor("BaseColor", Color) = (1, 1, 1, 0) - _AlphaPower("AlphaPower", Float) = 0.5 - _TransColor("TransColor", Color) = (1, 1, 1, 0) - _FresPower("FresPower", Float) = 2 - _Emission("Emission", Float) = 0 - _CircleDest("CircleDest", Float) = 1 - _WaveScale("WaveScale", Float) = 1 - _WaveStrength("WaveStrength", Float) = 0.01 - _TimeScale("TimeScale", Float) = 1 - [HideInInspector]_DiffusionProfileHash("Float", Float) = 0 - [HideInInspector]_DiffusionProfileAsset("Vector4", Vector) = (0, 0, 0, 0) - [HideInInspector]_EmissionColor("Color", Color) = (1, 1, 1, 1) - [HideInInspector]_RenderQueueType("Float", Float) = 4 - [HideInInspector][ToggleUI]_AddPrecomputedVelocity("Boolean", Float) = 0 - [HideInInspector][ToggleUI]_DepthOffsetEnable("Boolean", Float) = 0 - [HideInInspector][ToggleUI]_ConservativeDepthOffsetEnable("Boolean", Float) = 0 - [HideInInspector][ToggleUI]_TransparentWritingMotionVec("Boolean", Float) = 0 - [HideInInspector][ToggleUI]_AlphaCutoffEnable("Boolean", Float) = 0 - [HideInInspector]_TransparentSortPriority("_TransparentSortPriority", Float) = 0 - [HideInInspector][ToggleUI]_UseShadowThreshold("Boolean", Float) = 0 - [HideInInspector][ToggleUI]_DoubleSidedEnable("Boolean", Float) = 0 - [HideInInspector][Enum(Flip, 0, Mirror, 1, None, 2)]_DoubleSidedNormalMode("Float", Float) = 2 - [HideInInspector]_DoubleSidedConstants("Vector4", Vector) = (1, 1, -1, 0) - [HideInInspector][Enum(Auto, 0, On, 1, Off, 2)]_DoubleSidedGIMode("Float", Float) = 0 - [HideInInspector][ToggleUI]_TransparentDepthPrepassEnable("Boolean", Float) = 0 - [HideInInspector][ToggleUI]_TransparentDepthPostpassEnable("Boolean", Float) = 0 - [HideInInspector]_SurfaceType("Float", Float) = 1 - [HideInInspector]_BlendMode("Float", Float) = 0 - [HideInInspector]_SrcBlend("Float", Float) = 1 - [HideInInspector]_DstBlend("Float", Float) = 0 - [HideInInspector]_AlphaSrcBlend("Float", Float) = 1 - [HideInInspector]_AlphaDstBlend("Float", Float) = 0 - [HideInInspector][ToggleUI]_ZWrite("Boolean", Float) = 0 - [HideInInspector][ToggleUI]_TransparentZWrite("Boolean", Float) = 0 - [HideInInspector]_CullMode("Float", Float) = 2 - [HideInInspector][ToggleUI]_EnableFogOnTransparent("Boolean", Float) = 1 - [HideInInspector]_CullModeForward("Float", Float) = 2 - [HideInInspector][Enum(Front, 1, Back, 2)]_TransparentCullMode("Float", Float) = 2 - [HideInInspector][Enum(UnityEditor.Rendering.HighDefinition.OpaqueCullMode)]_OpaqueCullMode("Float", Float) = 2 - [HideInInspector]_ZTestDepthEqualForOpaque("Float", Int) = 4 - [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestTransparent("Float", Float) = 4 - [HideInInspector][ToggleUI]_TransparentBackfaceEnable("Boolean", Float) = 0 - [HideInInspector][ToggleUI]_RequireSplitLighting("Boolean", Float) = 0 - [HideInInspector][ToggleUI]_ReceivesSSR("Boolean", Float) = 0 - [HideInInspector][ToggleUI]_ReceivesSSRTransparent("Boolean", Float) = 0 - [HideInInspector][ToggleUI]_EnableBlendModePreserveSpecularLighting("Boolean", Float) = 0 - [HideInInspector][ToggleUI]_SupportDecals("Boolean", Float) = 0 - [HideInInspector]_StencilRef("Float", Int) = 0 - [HideInInspector]_StencilWriteMask("Float", Int) = 6 - [HideInInspector]_StencilRefDepth("Float", Int) = 0 - [HideInInspector]_StencilWriteMaskDepth("Float", Int) = 9 - [HideInInspector]_StencilRefMV("Float", Int) = 32 - [HideInInspector]_StencilWriteMaskMV("Float", Int) = 41 - [HideInInspector]_StencilRefDistortionVec("Float", Int) = 4 - [HideInInspector]_StencilWriteMaskDistortionVec("Float", Int) = 4 - [HideInInspector]_StencilWriteMaskGBuffer("Float", Int) = 15 - [HideInInspector]_StencilRefGBuffer("Float", Int) = 2 - [HideInInspector]_ZTestGBuffer("Float", Int) = 4 - [HideInInspector][ToggleUI]_RayTracing("Boolean", Float) = 1 - [HideInInspector][Enum(None, 0, Planar, 1, Sphere, 2, Thin, 3)]_RefractionModel("Float", Float) = 1 - [HideInInspector][Enum(Translucent, 5)]_MaterialID("_MaterialID", Float) = 5 - [HideInInspector]_MaterialTypeMask("_MaterialTypeMask", Float) = 32 - [HideInInspector][ToggleUI]_TransmissionEnable("Boolean", Float) = 1 - [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} - [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} - [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} - } - SubShader - { - Tags - { - "RenderPipeline"="HDRenderPipeline" - "RenderType"="HDLitShader" - "Queue"="Transparent+0" - "DisableBatching"="False" - "ShaderGraphShader"="true" - "ShaderGraphTargetId"="HDLitSubTarget" - } - Pass - { - Name "ShadowCaster" - Tags - { - "LightMode" = "ShadowCaster" - } - - // Render State - Cull [_CullMode] - ZWrite On - ColorMask 0 - ZClip [_ZClip] - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma multi_compile _ DOTS_INSTANCING_ON - #pragma instancing_options renderinglayer - #pragma target 4.5 - #pragma vertex Vert - #pragma fragment Frag - #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch - #pragma multi_compile_instancing - - // Keywords - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - struct CustomInterpolators - { - }; - #define USE_CUSTOMINTERP_SUBSTRUCT - - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - - #define HAVE_MESH_MODIFICATION - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_SHADOWS - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - // GraphIncludes: - - // -------------------------------------------------- - // Structs and Packing - - struct AttributesMesh - { - float3 positionOS : POSITION; - float3 normalOS : NORMAL; - float4 tangentOS : TANGENT; - float4 uv0 : TEXCOORD0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : INSTANCEID_SEMANTIC; - #endif - }; - struct VaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float3 positionRWS; - float3 normalWS; - float4 tangentWS; - float4 texCoord0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - struct VertexDescriptionInputs - { - float3 ObjectSpaceNormal; - float3 ObjectSpaceTangent; - float3 ObjectSpacePosition; - }; - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - struct PackedVaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float4 tangentWS : INTERP0; - float4 texCoord0 : INTERP1; - float3 positionRWS : INTERP2; - float3 normalWS : INTERP3; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - - PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input) - { - PackedVaryingsMeshToPS output; - ZERO_INITIALIZE(PackedVaryingsMeshToPS, output); - output.positionCS = input.positionCS; - output.tangentWS.xyzw = input.tangentWS; - output.texCoord0.xyzw = input.texCoord0; - output.positionRWS.xyz = input.positionRWS; - output.normalWS.xyz = input.normalWS; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input) - { - VaryingsMeshToPS output; - output.positionCS = input.positionCS; - output.tangentWS = input.tangentWS.xyzw; - output.texCoord0 = input.texCoord0.xyzw; - output.positionRWS = input.positionRWS.xyz; - output.normalWS = input.normalWS.xyz; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - // Graph Vertex - struct VertexDescription - { - float3 Position; - float3 Normal; - float3 Tangent; - }; - - VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN) - { - VertexDescription description = (VertexDescription)0; - description.Position = IN.ObjectSpacePosition; - description.Normal = IN.ObjectSpaceNormal; - description.Tangent = IN.ObjectSpaceTangent; - return description; - } - - // Graph Pixel - struct SurfaceDescription - { - float Alpha; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - - VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input) - { - VertexDescriptionInputs output; - ZERO_INITIALIZE(VertexDescriptionInputs, output); - - output.ObjectSpaceNormal = input.normalOS; - output.ObjectSpaceTangent = input.tangentOS.xyz; - output.ObjectSpacePosition = input.positionOS; - - return output; - } - - VertexDescription GetVertexDescription(AttributesMesh input, float3 timeParameters - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - // build graph inputs - VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input); - // Override time parameters with used one (This is required to correctly handle motion vectors for vertex animation based on time) - - // evaluate vertex graph - #ifdef HAVE_VFX_MODIFICATION - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - // Fetch the vertex graph properties for the particle instance. - GetElementVertexProperties(element, properties); - - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs, properties); - #else - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); - #endif - return vertexDescription; - - } - - AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters - #ifdef USE_CUSTOMINTERP_SUBSTRUCT - #ifdef TESSELLATION_ON - , inout VaryingsMeshToDS varyings - #else - , inout VaryingsMeshToPS varyings - #endif - #endif - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, timeParameters - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - - // copy graph output to the results - input.positionOS = vertexDescription.Position; - input.normalOS = vertexDescription.Normal; - input.tangentOS.xyz = vertexDescription.Tangent; - - - - return input; - } - - #if defined(_ADD_CUSTOM_VELOCITY) // For shader graph custom velocity - // Return precomputed Velocity in object space - float3 GetCustomVelocity(AttributesMesh input - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, _TimeParameters.xyz - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - return vertexDescription.CustomVelocity; - } - #endif - - FragInputs BuildFragInputs(VaryingsMeshToPS input) - { - FragInputs output; - ZERO_INITIALIZE(FragInputs, output); - - // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). - // TODO: this is a really poor workaround, but the variable is used in a bunch of places - // to compute normals which are then passed on elsewhere to compute other values... - output.tangentToWorld = k_identity3x3; - output.positionSS = input.positionCS; // input.positionCS is SV_Position - - output.positionRWS = input.positionRWS; - output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS); - output.texCoord0 = input.texCoord0; - - #ifdef HAVE_VFX_MODIFICATION - // FragInputs from VFX come from two places: Interpolator or CBuffer. - #if VFX_USE_GRAPH_VALUES - uint instanceActiveIndex = asuint(UNITY_ACCESS_INSTANCED_PROP(PerInstance, _InstanceActiveIndex)); - /* WARNING: $splice Could not find named fragment 'VFXLoadGraphValues' */ - #endif - - /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */ - - #endif - - // splice point to copy custom interpolator fields from varyings to frag inputs - - - return output; - } - - // existing HDRP code uses the combined function to go directly from packed to frag inputs - FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) - { - UNITY_SETUP_INSTANCE_ID(input); - #if defined(HAVE_VFX_MODIFICATION) && defined(UNITY_INSTANCING_ENABLED) - unity_InstanceID = input.instanceID; - #endif - VaryingsMeshToPS unpacked = UnpackVaryingsMeshToPS(input); - return BuildFragInputs(unpacked); - } - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "META" - Tags - { - "LightMode" = "META" - } - - // Render State - Cull Off - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma multi_compile _ DOTS_INSTANCING_ON - #pragma instancing_options renderinglayer - #pragma target 4.5 - #pragma vertex Vert - #pragma fragment Frag - #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch - #pragma multi_compile_instancing - - // Keywords - #pragma shader_feature _ EDITOR_VISUALIZATION - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorPreInclude' */ - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define ATTRIBUTES_NEED_TEXCOORD1 - #define ATTRIBUTES_NEED_TEXCOORD2 - #define ATTRIBUTES_NEED_TEXCOORD3 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_POSITIONPREDISPLACEMENT_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - #define VARYINGS_NEED_TEXCOORD1 - #define VARYINGS_NEED_TEXCOORD2 - #define VARYINGS_NEED_TEXCOORD3 - - #define HAVE_MESH_MODIFICATION - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - #define FRAG_INPUTS_USE_TEXCOORD1 - #define FRAG_INPUTS_USE_TEXCOORD2 - #define FRAG_INPUTS_USE_TEXCOORD3 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT - #define RAYTRACING_SHADER_GRAPH_DEFAULT - #define SCENEPICKINGPASS 1 - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct AttributesMesh - { - float3 positionOS : POSITION; - float3 normalOS : NORMAL; - float4 tangentOS : TANGENT; - float4 uv0 : TEXCOORD0; - float4 uv1 : TEXCOORD1; - float4 uv2 : TEXCOORD2; - float4 uv3 : TEXCOORD3; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : INSTANCEID_SEMANTIC; - #endif - }; - struct VaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float3 positionRWS; - float3 positionPredisplacementRWS; - float3 normalWS; - float4 tangentWS; - float4 texCoord0; - float4 texCoord1; - float4 texCoord2; - float4 texCoord3; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - struct VertexDescriptionInputs - { - }; - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - struct PackedVaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float4 tangentWS : INTERP0; - float4 texCoord0 : INTERP1; - float4 texCoord1 : INTERP2; - float4 texCoord2 : INTERP3; - float4 texCoord3 : INTERP4; - float3 positionRWS : INTERP5; - float3 positionPredisplacementRWS : INTERP6; - float3 normalWS : INTERP7; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - - PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input) - { - PackedVaryingsMeshToPS output; - ZERO_INITIALIZE(PackedVaryingsMeshToPS, output); - output.positionCS = input.positionCS; - output.tangentWS.xyzw = input.tangentWS; - output.texCoord0.xyzw = input.texCoord0; - output.texCoord1.xyzw = input.texCoord1; - output.texCoord2.xyzw = input.texCoord2; - output.texCoord3.xyzw = input.texCoord3; - output.positionRWS.xyz = input.positionRWS; - output.positionPredisplacementRWS.xyz = input.positionPredisplacementRWS; - output.normalWS.xyz = input.normalWS; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input) - { - VaryingsMeshToPS output; - output.positionCS = input.positionCS; - output.tangentWS = input.tangentWS.xyzw; - output.texCoord0 = input.texCoord0.xyzw; - output.texCoord1 = input.texCoord1.xyzw; - output.texCoord2 = input.texCoord2.xyzw; - output.texCoord3 = input.texCoord3.xyzw; - output.positionRWS = input.positionRWS.xyz; - output.positionPredisplacementRWS = input.positionPredisplacementRWS.xyz; - output.normalWS = input.normalWS.xyz; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - struct VertexDescription - { - }; - - VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN) - { - VertexDescription description = (VertexDescription)0; - return description; - } - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - - VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input) - { - VertexDescriptionInputs output; - ZERO_INITIALIZE(VertexDescriptionInputs, output); - - - return output; - } - - VertexDescription GetVertexDescription(AttributesMesh input, float3 timeParameters - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - // build graph inputs - VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input); - // Override time parameters with used one (This is required to correctly handle motion vectors for vertex animation based on time) - - // evaluate vertex graph - #ifdef HAVE_VFX_MODIFICATION - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - // Fetch the vertex graph properties for the particle instance. - GetElementVertexProperties(element, properties); - - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs, properties); - #else - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); - #endif - return vertexDescription; - - } - - AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters - #ifdef USE_CUSTOMINTERP_SUBSTRUCT - #ifdef TESSELLATION_ON - , inout VaryingsMeshToDS varyings - #else - , inout VaryingsMeshToPS varyings - #endif - #endif - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, timeParameters - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - - // copy graph output to the results - - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorVertMeshCustomInterpolation' */ - - return input; - } - - #if defined(_ADD_CUSTOM_VELOCITY) // For shader graph custom velocity - // Return precomputed Velocity in object space - float3 GetCustomVelocity(AttributesMesh input - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, _TimeParameters.xyz - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - return vertexDescription.CustomVelocity; - } - #endif - - FragInputs BuildFragInputs(VaryingsMeshToPS input) - { - FragInputs output; - ZERO_INITIALIZE(FragInputs, output); - - // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). - // TODO: this is a really poor workaround, but the variable is used in a bunch of places - // to compute normals which are then passed on elsewhere to compute other values... - output.tangentToWorld = k_identity3x3; - output.positionSS = input.positionCS; // input.positionCS is SV_Position - - output.positionRWS = input.positionRWS; - output.positionPredisplacementRWS = input.positionPredisplacementRWS; - output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS); - output.texCoord0 = input.texCoord0; - output.texCoord1 = input.texCoord1; - output.texCoord2 = input.texCoord2; - output.texCoord3 = input.texCoord3; - - #ifdef HAVE_VFX_MODIFICATION - // FragInputs from VFX come from two places: Interpolator or CBuffer. - #if VFX_USE_GRAPH_VALUES - uint instanceActiveIndex = asuint(UNITY_ACCESS_INSTANCED_PROP(PerInstance, _InstanceActiveIndex)); - /* WARNING: $splice Could not find named fragment 'VFXLoadGraphValues' */ - #endif - - /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */ - - #endif - - // splice point to copy custom interpolator fields from varyings to frag inputs - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorVaryingsToFragInputs' */ - - return output; - } - - // existing HDRP code uses the combined function to go directly from packed to frag inputs - FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) - { - UNITY_SETUP_INSTANCE_ID(input); - #if defined(HAVE_VFX_MODIFICATION) && defined(UNITY_INSTANCING_ENABLED) - unity_InstanceID = input.instanceID; - #endif - VaryingsMeshToPS unpacked = UnpackVaryingsMeshToPS(input); - return BuildFragInputs(unpacked); - } - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorCopyToSDI' */ - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "ScenePickingPass" - Tags - { - "LightMode" = "Picking" - } - - // Render State - Cull [_CullMode] - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma multi_compile _ DOTS_INSTANCING_ON - #pragma editor_sync_compilation - #pragma instancing_options renderinglayer - #pragma target 4.5 - #pragma vertex Vert - #pragma fragment Frag - #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch - #pragma multi_compile_instancing - - // Keywords - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - struct CustomInterpolators - { - }; - #define USE_CUSTOMINTERP_SUBSTRUCT - - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - - #define HAVE_MESH_MODIFICATION - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_DEPTH_ONLY - #define SCENEPICKINGPASS 1 - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct AttributesMesh - { - float3 positionOS : POSITION; - float3 normalOS : NORMAL; - float4 tangentOS : TANGENT; - float4 uv0 : TEXCOORD0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : INSTANCEID_SEMANTIC; - #endif - }; - struct VaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float3 positionRWS; - float3 normalWS; - float4 tangentWS; - float4 texCoord0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - struct VertexDescriptionInputs - { - float3 ObjectSpaceNormal; - float3 ObjectSpaceTangent; - float3 ObjectSpacePosition; - }; - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - struct PackedVaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float4 tangentWS : INTERP0; - float4 texCoord0 : INTERP1; - float3 positionRWS : INTERP2; - float3 normalWS : INTERP3; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - - PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input) - { - PackedVaryingsMeshToPS output; - ZERO_INITIALIZE(PackedVaryingsMeshToPS, output); - output.positionCS = input.positionCS; - output.tangentWS.xyzw = input.tangentWS; - output.texCoord0.xyzw = input.texCoord0; - output.positionRWS.xyz = input.positionRWS; - output.normalWS.xyz = input.normalWS; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input) - { - VaryingsMeshToPS output; - output.positionCS = input.positionCS; - output.tangentWS = input.tangentWS.xyzw; - output.texCoord0 = input.texCoord0.xyzw; - output.positionRWS = input.positionRWS.xyz; - output.normalWS = input.normalWS.xyz; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - struct VertexDescription - { - float3 Position; - float3 Normal; - float3 Tangent; - }; - - VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN) - { - VertexDescription description = (VertexDescription)0; - description.Position = IN.ObjectSpacePosition; - description.Normal = IN.ObjectSpaceNormal; - description.Tangent = IN.ObjectSpaceTangent; - return description; - } - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - - VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input) - { - VertexDescriptionInputs output; - ZERO_INITIALIZE(VertexDescriptionInputs, output); - - output.ObjectSpaceNormal = input.normalOS; - output.ObjectSpaceTangent = input.tangentOS.xyz; - output.ObjectSpacePosition = input.positionOS; - - return output; - } - - VertexDescription GetVertexDescription(AttributesMesh input, float3 timeParameters - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - // build graph inputs - VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input); - // Override time parameters with used one (This is required to correctly handle motion vectors for vertex animation based on time) - - // evaluate vertex graph - #ifdef HAVE_VFX_MODIFICATION - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - // Fetch the vertex graph properties for the particle instance. - GetElementVertexProperties(element, properties); - - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs, properties); - #else - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); - #endif - return vertexDescription; - - } - - AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters - #ifdef USE_CUSTOMINTERP_SUBSTRUCT - #ifdef TESSELLATION_ON - , inout VaryingsMeshToDS varyings - #else - , inout VaryingsMeshToPS varyings - #endif - #endif - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, timeParameters - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - - // copy graph output to the results - input.positionOS = vertexDescription.Position; - input.normalOS = vertexDescription.Normal; - input.tangentOS.xyz = vertexDescription.Tangent; - - - - return input; - } - - #if defined(_ADD_CUSTOM_VELOCITY) // For shader graph custom velocity - // Return precomputed Velocity in object space - float3 GetCustomVelocity(AttributesMesh input - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, _TimeParameters.xyz - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - return vertexDescription.CustomVelocity; - } - #endif - - FragInputs BuildFragInputs(VaryingsMeshToPS input) - { - FragInputs output; - ZERO_INITIALIZE(FragInputs, output); - - // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). - // TODO: this is a really poor workaround, but the variable is used in a bunch of places - // to compute normals which are then passed on elsewhere to compute other values... - output.tangentToWorld = k_identity3x3; - output.positionSS = input.positionCS; // input.positionCS is SV_Position - - output.positionRWS = input.positionRWS; - output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS); - output.texCoord0 = input.texCoord0; - - #ifdef HAVE_VFX_MODIFICATION - // FragInputs from VFX come from two places: Interpolator or CBuffer. - #if VFX_USE_GRAPH_VALUES - uint instanceActiveIndex = asuint(UNITY_ACCESS_INSTANCED_PROP(PerInstance, _InstanceActiveIndex)); - /* WARNING: $splice Could not find named fragment 'VFXLoadGraphValues' */ - #endif - - /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */ - - #endif - - // splice point to copy custom interpolator fields from varyings to frag inputs - - - return output; - } - - // existing HDRP code uses the combined function to go directly from packed to frag inputs - FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) - { - UNITY_SETUP_INSTANCE_ID(input); - #if defined(HAVE_VFX_MODIFICATION) && defined(UNITY_INSTANCING_ENABLED) - unity_InstanceID = input.instanceID; - #endif - VaryingsMeshToPS unpacked = UnpackVaryingsMeshToPS(input); - return BuildFragInputs(unpacked); - } - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "SceneSelectionPass" - Tags - { - "LightMode" = "SceneSelectionPass" - } - - // Render State - Cull Off - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma multi_compile _ DOTS_INSTANCING_ON - #pragma editor_sync_compilation - #pragma instancing_options renderinglayer - #pragma target 4.5 - #pragma vertex Vert - #pragma fragment Frag - #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch - #pragma multi_compile_instancing - - // Keywords - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - struct CustomInterpolators - { - }; - #define USE_CUSTOMINTERP_SUBSTRUCT - - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - - #define HAVE_MESH_MODIFICATION - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_DEPTH_ONLY - #define RAYTRACING_SHADER_GRAPH_DEFAULT - #define SCENESELECTIONPASS 1 - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct AttributesMesh - { - float3 positionOS : POSITION; - float3 normalOS : NORMAL; - float4 tangentOS : TANGENT; - float4 uv0 : TEXCOORD0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : INSTANCEID_SEMANTIC; - #endif - }; - struct VaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float3 positionRWS; - float3 normalWS; - float4 tangentWS; - float4 texCoord0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - struct VertexDescriptionInputs - { - float3 ObjectSpaceNormal; - float3 ObjectSpaceTangent; - float3 ObjectSpacePosition; - }; - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - struct PackedVaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float4 tangentWS : INTERP0; - float4 texCoord0 : INTERP1; - float3 positionRWS : INTERP2; - float3 normalWS : INTERP3; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - - PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input) - { - PackedVaryingsMeshToPS output; - ZERO_INITIALIZE(PackedVaryingsMeshToPS, output); - output.positionCS = input.positionCS; - output.tangentWS.xyzw = input.tangentWS; - output.texCoord0.xyzw = input.texCoord0; - output.positionRWS.xyz = input.positionRWS; - output.normalWS.xyz = input.normalWS; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input) - { - VaryingsMeshToPS output; - output.positionCS = input.positionCS; - output.tangentWS = input.tangentWS.xyzw; - output.texCoord0 = input.texCoord0.xyzw; - output.positionRWS = input.positionRWS.xyz; - output.normalWS = input.normalWS.xyz; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - struct VertexDescription - { - float3 Position; - float3 Normal; - float3 Tangent; - }; - - VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN) - { - VertexDescription description = (VertexDescription)0; - description.Position = IN.ObjectSpacePosition; - description.Normal = IN.ObjectSpaceNormal; - description.Tangent = IN.ObjectSpaceTangent; - return description; - } - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - - VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input) - { - VertexDescriptionInputs output; - ZERO_INITIALIZE(VertexDescriptionInputs, output); - - output.ObjectSpaceNormal = input.normalOS; - output.ObjectSpaceTangent = input.tangentOS.xyz; - output.ObjectSpacePosition = input.positionOS; - - return output; - } - - VertexDescription GetVertexDescription(AttributesMesh input, float3 timeParameters - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - // build graph inputs - VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input); - // Override time parameters with used one (This is required to correctly handle motion vectors for vertex animation based on time) - - // evaluate vertex graph - #ifdef HAVE_VFX_MODIFICATION - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - // Fetch the vertex graph properties for the particle instance. - GetElementVertexProperties(element, properties); - - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs, properties); - #else - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); - #endif - return vertexDescription; - - } - - AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters - #ifdef USE_CUSTOMINTERP_SUBSTRUCT - #ifdef TESSELLATION_ON - , inout VaryingsMeshToDS varyings - #else - , inout VaryingsMeshToPS varyings - #endif - #endif - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, timeParameters - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - - // copy graph output to the results - input.positionOS = vertexDescription.Position; - input.normalOS = vertexDescription.Normal; - input.tangentOS.xyz = vertexDescription.Tangent; - - - - return input; - } - - #if defined(_ADD_CUSTOM_VELOCITY) // For shader graph custom velocity - // Return precomputed Velocity in object space - float3 GetCustomVelocity(AttributesMesh input - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, _TimeParameters.xyz - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - return vertexDescription.CustomVelocity; - } - #endif - - FragInputs BuildFragInputs(VaryingsMeshToPS input) - { - FragInputs output; - ZERO_INITIALIZE(FragInputs, output); - - // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). - // TODO: this is a really poor workaround, but the variable is used in a bunch of places - // to compute normals which are then passed on elsewhere to compute other values... - output.tangentToWorld = k_identity3x3; - output.positionSS = input.positionCS; // input.positionCS is SV_Position - - output.positionRWS = input.positionRWS; - output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS); - output.texCoord0 = input.texCoord0; - - #ifdef HAVE_VFX_MODIFICATION - // FragInputs from VFX come from two places: Interpolator or CBuffer. - #if VFX_USE_GRAPH_VALUES - uint instanceActiveIndex = asuint(UNITY_ACCESS_INSTANCED_PROP(PerInstance, _InstanceActiveIndex)); - /* WARNING: $splice Could not find named fragment 'VFXLoadGraphValues' */ - #endif - - /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */ - - #endif - - // splice point to copy custom interpolator fields from varyings to frag inputs - - - return output; - } - - // existing HDRP code uses the combined function to go directly from packed to frag inputs - FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) - { - UNITY_SETUP_INSTANCE_ID(input); - #if defined(HAVE_VFX_MODIFICATION) && defined(UNITY_INSTANCING_ENABLED) - unity_InstanceID = input.instanceID; - #endif - VaryingsMeshToPS unpacked = UnpackVaryingsMeshToPS(input); - return BuildFragInputs(unpacked); - } - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "MotionVectors" - Tags - { - "LightMode" = "MotionVectors" - } - - // Render State - Cull [_CullMode] - ZWrite On - Stencil - { - WriteMask [_StencilWriteMaskMV] - Ref [_StencilRefMV] - CompFront Always - PassFront Replace - CompBack Always - PassBack Replace - } - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma multi_compile _ DOTS_INSTANCING_ON - #pragma instancing_options renderinglayer - #pragma target 4.5 - #pragma vertex Vert - #pragma fragment Frag - #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch - #pragma multi_compile_instancing - - // Keywords - #pragma multi_compile_fragment _ WRITE_MSAA_DEPTH - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma multi_compile _ WRITE_NORMAL_BUFFER - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma multi_compile_fragment _ WRITE_DECAL_BUFFER_AND_RENDERING_LAYER - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - struct CustomInterpolators - { - }; - #define USE_CUSTOMINTERP_SUBSTRUCT - - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - - #define HAVE_MESH_MODIFICATION - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_MOTION_VECTORS - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct AttributesMesh - { - float3 positionOS : POSITION; - float3 normalOS : NORMAL; - float4 tangentOS : TANGENT; - float4 uv0 : TEXCOORD0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : INSTANCEID_SEMANTIC; - #endif - }; - struct VaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float3 positionRWS; - float3 normalWS; - float4 tangentWS; - float4 texCoord0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - struct VertexDescriptionInputs - { - float3 ObjectSpaceNormal; - float3 ObjectSpaceTangent; - float3 ObjectSpacePosition; - }; - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - struct PackedVaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float4 tangentWS : INTERP0; - float4 texCoord0 : INTERP1; - float3 positionRWS : INTERP2; - float3 normalWS : INTERP3; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - - PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input) - { - PackedVaryingsMeshToPS output; - ZERO_INITIALIZE(PackedVaryingsMeshToPS, output); - output.positionCS = input.positionCS; - output.tangentWS.xyzw = input.tangentWS; - output.texCoord0.xyzw = input.texCoord0; - output.positionRWS.xyz = input.positionRWS; - output.normalWS.xyz = input.normalWS; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input) - { - VaryingsMeshToPS output; - output.positionCS = input.positionCS; - output.tangentWS = input.tangentWS.xyzw; - output.texCoord0 = input.texCoord0.xyzw; - output.positionRWS = input.positionRWS.xyz; - output.normalWS = input.normalWS.xyz; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - struct VertexDescription - { - float3 Position; - float3 Normal; - float3 Tangent; - }; - - VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN) - { - VertexDescription description = (VertexDescription)0; - description.Position = IN.ObjectSpacePosition; - description.Normal = IN.ObjectSpaceNormal; - description.Tangent = IN.ObjectSpaceTangent; - return description; - } - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - - VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input) - { - VertexDescriptionInputs output; - ZERO_INITIALIZE(VertexDescriptionInputs, output); - - output.ObjectSpaceNormal = input.normalOS; - output.ObjectSpaceTangent = input.tangentOS.xyz; - output.ObjectSpacePosition = input.positionOS; - - return output; - } - - VertexDescription GetVertexDescription(AttributesMesh input, float3 timeParameters - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - // build graph inputs - VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input); - // Override time parameters with used one (This is required to correctly handle motion vectors for vertex animation based on time) - - // evaluate vertex graph - #ifdef HAVE_VFX_MODIFICATION - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - // Fetch the vertex graph properties for the particle instance. - GetElementVertexProperties(element, properties); - - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs, properties); - #else - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); - #endif - return vertexDescription; - - } - - AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters - #ifdef USE_CUSTOMINTERP_SUBSTRUCT - #ifdef TESSELLATION_ON - , inout VaryingsMeshToDS varyings - #else - , inout VaryingsMeshToPS varyings - #endif - #endif - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, timeParameters - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - - // copy graph output to the results - input.positionOS = vertexDescription.Position; - input.normalOS = vertexDescription.Normal; - input.tangentOS.xyz = vertexDescription.Tangent; - - - - return input; - } - - #if defined(_ADD_CUSTOM_VELOCITY) // For shader graph custom velocity - // Return precomputed Velocity in object space - float3 GetCustomVelocity(AttributesMesh input - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, _TimeParameters.xyz - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - return vertexDescription.CustomVelocity; - } - #endif - - FragInputs BuildFragInputs(VaryingsMeshToPS input) - { - FragInputs output; - ZERO_INITIALIZE(FragInputs, output); - - // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). - // TODO: this is a really poor workaround, but the variable is used in a bunch of places - // to compute normals which are then passed on elsewhere to compute other values... - output.tangentToWorld = k_identity3x3; - output.positionSS = input.positionCS; // input.positionCS is SV_Position - - output.positionRWS = input.positionRWS; - output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS); - output.texCoord0 = input.texCoord0; - - #ifdef HAVE_VFX_MODIFICATION - // FragInputs from VFX come from two places: Interpolator or CBuffer. - #if VFX_USE_GRAPH_VALUES - uint instanceActiveIndex = asuint(UNITY_ACCESS_INSTANCED_PROP(PerInstance, _InstanceActiveIndex)); - /* WARNING: $splice Could not find named fragment 'VFXLoadGraphValues' */ - #endif - - /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */ - - #endif - - // splice point to copy custom interpolator fields from varyings to frag inputs - - - return output; - } - - // existing HDRP code uses the combined function to go directly from packed to frag inputs - FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) - { - UNITY_SETUP_INSTANCE_ID(input); - #if defined(HAVE_VFX_MODIFICATION) && defined(UNITY_INSTANCING_ENABLED) - unity_InstanceID = input.instanceID; - #endif - VaryingsMeshToPS unpacked = UnpackVaryingsMeshToPS(input); - return BuildFragInputs(unpacked); - } - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassMotionVectors.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "TransparentDepthPrepass" - Tags - { - "LightMode" = "TransparentDepthPrepass" - } - - // Render State - Cull [_CullMode] - Blend One Zero - ZWrite On - Stencil - { - WriteMask [_StencilWriteMaskDepth] - Ref [_StencilRefDepth] - CompFront Always - PassFront Replace - CompBack Always - PassBack Replace - } - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma multi_compile _ DOTS_INSTANCING_ON - #pragma instancing_options renderinglayer - #pragma target 4.5 - #pragma vertex Vert - #pragma fragment Frag - #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch - #pragma multi_compile_instancing - - // Keywords - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - struct CustomInterpolators - { - }; - #define USE_CUSTOMINTERP_SUBSTRUCT - - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - - #define HAVE_MESH_MODIFICATION - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #define RAYTRACING_SHADER_GRAPH_DEFAULT - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - // GraphIncludes: - - // -------------------------------------------------- - // Structs and Packing - - struct AttributesMesh - { - float3 positionOS : POSITION; - float3 normalOS : NORMAL; - float4 tangentOS : TANGENT; - float4 uv0 : TEXCOORD0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : INSTANCEID_SEMANTIC; - #endif - }; - struct VaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float3 positionRWS; - float3 normalWS; - float4 tangentWS; - float4 texCoord0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - struct VertexDescriptionInputs - { - float3 ObjectSpaceNormal; - float3 ObjectSpaceTangent; - float3 ObjectSpacePosition; - }; - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - struct PackedVaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float4 tangentWS : INTERP0; - float4 texCoord0 : INTERP1; - float3 positionRWS : INTERP2; - float3 normalWS : INTERP3; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - - PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input) - { - PackedVaryingsMeshToPS output; - ZERO_INITIALIZE(PackedVaryingsMeshToPS, output); - output.positionCS = input.positionCS; - output.tangentWS.xyzw = input.tangentWS; - output.texCoord0.xyzw = input.texCoord0; - output.positionRWS.xyz = input.positionRWS; - output.normalWS.xyz = input.normalWS; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input) - { - VaryingsMeshToPS output; - output.positionCS = input.positionCS; - output.tangentWS = input.tangentWS.xyzw; - output.texCoord0 = input.texCoord0.xyzw; - output.positionRWS = input.positionRWS.xyz; - output.normalWS = input.normalWS.xyz; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - struct VertexDescription - { - float3 Position; - float3 Normal; - float3 Tangent; - }; - - VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN) - { - VertexDescription description = (VertexDescription)0; - description.Position = IN.ObjectSpacePosition; - description.Normal = IN.ObjectSpaceNormal; - description.Tangent = IN.ObjectSpaceTangent; - return description; - } - - // Graph Pixel - struct SurfaceDescription - { - float Alpha; - float3 NormalTS; - float Smoothness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.Smoothness = 0.5; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - - VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input) - { - VertexDescriptionInputs output; - ZERO_INITIALIZE(VertexDescriptionInputs, output); - - output.ObjectSpaceNormal = input.normalOS; - output.ObjectSpaceTangent = input.tangentOS.xyz; - output.ObjectSpacePosition = input.positionOS; - - return output; - } - - VertexDescription GetVertexDescription(AttributesMesh input, float3 timeParameters - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - // build graph inputs - VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input); - // Override time parameters with used one (This is required to correctly handle motion vectors for vertex animation based on time) - - // evaluate vertex graph - #ifdef HAVE_VFX_MODIFICATION - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - // Fetch the vertex graph properties for the particle instance. - GetElementVertexProperties(element, properties); - - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs, properties); - #else - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); - #endif - return vertexDescription; - - } - - AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters - #ifdef USE_CUSTOMINTERP_SUBSTRUCT - #ifdef TESSELLATION_ON - , inout VaryingsMeshToDS varyings - #else - , inout VaryingsMeshToPS varyings - #endif - #endif - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, timeParameters - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - - // copy graph output to the results - input.positionOS = vertexDescription.Position; - input.normalOS = vertexDescription.Normal; - input.tangentOS.xyz = vertexDescription.Tangent; - - - - return input; - } - - #if defined(_ADD_CUSTOM_VELOCITY) // For shader graph custom velocity - // Return precomputed Velocity in object space - float3 GetCustomVelocity(AttributesMesh input - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, _TimeParameters.xyz - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - return vertexDescription.CustomVelocity; - } - #endif - - FragInputs BuildFragInputs(VaryingsMeshToPS input) - { - FragInputs output; - ZERO_INITIALIZE(FragInputs, output); - - // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). - // TODO: this is a really poor workaround, but the variable is used in a bunch of places - // to compute normals which are then passed on elsewhere to compute other values... - output.tangentToWorld = k_identity3x3; - output.positionSS = input.positionCS; // input.positionCS is SV_Position - - output.positionRWS = input.positionRWS; - output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS); - output.texCoord0 = input.texCoord0; - - #ifdef HAVE_VFX_MODIFICATION - // FragInputs from VFX come from two places: Interpolator or CBuffer. - #if VFX_USE_GRAPH_VALUES - uint instanceActiveIndex = asuint(UNITY_ACCESS_INSTANCED_PROP(PerInstance, _InstanceActiveIndex)); - /* WARNING: $splice Could not find named fragment 'VFXLoadGraphValues' */ - #endif - - /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */ - - #endif - - // splice point to copy custom interpolator fields from varyings to frag inputs - - - return output; - } - - // existing HDRP code uses the combined function to go directly from packed to frag inputs - FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) - { - UNITY_SETUP_INSTANCE_ID(input); - #if defined(HAVE_VFX_MODIFICATION) && defined(UNITY_INSTANCING_ENABLED) - unity_InstanceID = input.instanceID; - #endif - VaryingsMeshToPS unpacked = UnpackVaryingsMeshToPS(input); - return BuildFragInputs(unpacked); - } - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "FullScreenDebug" - Tags - { - "LightMode" = "FullScreenDebug" - } - - // Render State - Cull [_CullMode] - ZTest LEqual - ZWrite Off - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma multi_compile _ DOTS_INSTANCING_ON - #pragma instancing_options renderinglayer - #pragma target 4.5 - #pragma vertex Vert - #pragma fragment Frag - #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch - #pragma multi_compile_instancing - - // Keywords - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - struct CustomInterpolators - { - }; - #define USE_CUSTOMINTERP_SUBSTRUCT - - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - - #define HAVE_MESH_MODIFICATION - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_FULL_SCREEN_DEBUG - #define RAYTRACING_SHADER_GRAPH_DEFAULT - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct AttributesMesh - { - float3 positionOS : POSITION; - float3 normalOS : NORMAL; - float4 tangentOS : TANGENT; - float4 uv0 : TEXCOORD0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : INSTANCEID_SEMANTIC; - #endif - }; - struct VaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float3 positionRWS; - float3 normalWS; - float4 tangentWS; - float4 texCoord0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - struct VertexDescriptionInputs - { - float3 ObjectSpaceNormal; - float3 ObjectSpaceTangent; - float3 ObjectSpacePosition; - }; - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - struct PackedVaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float4 tangentWS : INTERP0; - float4 texCoord0 : INTERP1; - float3 positionRWS : INTERP2; - float3 normalWS : INTERP3; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - - PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input) - { - PackedVaryingsMeshToPS output; - ZERO_INITIALIZE(PackedVaryingsMeshToPS, output); - output.positionCS = input.positionCS; - output.tangentWS.xyzw = input.tangentWS; - output.texCoord0.xyzw = input.texCoord0; - output.positionRWS.xyz = input.positionRWS; - output.normalWS.xyz = input.normalWS; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input) - { - VaryingsMeshToPS output; - output.positionCS = input.positionCS; - output.tangentWS = input.tangentWS.xyzw; - output.texCoord0 = input.texCoord0.xyzw; - output.positionRWS = input.positionRWS.xyz; - output.normalWS = input.normalWS.xyz; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - struct VertexDescription - { - float3 Position; - float3 Normal; - float3 Tangent; - }; - - VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN) - { - VertexDescription description = (VertexDescription)0; - description.Position = IN.ObjectSpacePosition; - description.Normal = IN.ObjectSpaceNormal; - description.Tangent = IN.ObjectSpaceTangent; - return description; - } - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - - VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input) - { - VertexDescriptionInputs output; - ZERO_INITIALIZE(VertexDescriptionInputs, output); - - output.ObjectSpaceNormal = input.normalOS; - output.ObjectSpaceTangent = input.tangentOS.xyz; - output.ObjectSpacePosition = input.positionOS; - - return output; - } - - VertexDescription GetVertexDescription(AttributesMesh input, float3 timeParameters - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - // build graph inputs - VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input); - // Override time parameters with used one (This is required to correctly handle motion vectors for vertex animation based on time) - - // evaluate vertex graph - #ifdef HAVE_VFX_MODIFICATION - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - // Fetch the vertex graph properties for the particle instance. - GetElementVertexProperties(element, properties); - - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs, properties); - #else - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); - #endif - return vertexDescription; - - } - - AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters - #ifdef USE_CUSTOMINTERP_SUBSTRUCT - #ifdef TESSELLATION_ON - , inout VaryingsMeshToDS varyings - #else - , inout VaryingsMeshToPS varyings - #endif - #endif - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, timeParameters - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - - // copy graph output to the results - input.positionOS = vertexDescription.Position; - input.normalOS = vertexDescription.Normal; - input.tangentOS.xyz = vertexDescription.Tangent; - - - - return input; - } - - #if defined(_ADD_CUSTOM_VELOCITY) // For shader graph custom velocity - // Return precomputed Velocity in object space - float3 GetCustomVelocity(AttributesMesh input - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, _TimeParameters.xyz - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - return vertexDescription.CustomVelocity; - } - #endif - - FragInputs BuildFragInputs(VaryingsMeshToPS input) - { - FragInputs output; - ZERO_INITIALIZE(FragInputs, output); - - // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). - // TODO: this is a really poor workaround, but the variable is used in a bunch of places - // to compute normals which are then passed on elsewhere to compute other values... - output.tangentToWorld = k_identity3x3; - output.positionSS = input.positionCS; // input.positionCS is SV_Position - - output.positionRWS = input.positionRWS; - output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS); - output.texCoord0 = input.texCoord0; - - #ifdef HAVE_VFX_MODIFICATION - // FragInputs from VFX come from two places: Interpolator or CBuffer. - #if VFX_USE_GRAPH_VALUES - uint instanceActiveIndex = asuint(UNITY_ACCESS_INSTANCED_PROP(PerInstance, _InstanceActiveIndex)); - /* WARNING: $splice Could not find named fragment 'VFXLoadGraphValues' */ - #endif - - /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */ - - #endif - - // splice point to copy custom interpolator fields from varyings to frag inputs - - - return output; - } - - // existing HDRP code uses the combined function to go directly from packed to frag inputs - FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) - { - UNITY_SETUP_INSTANCE_ID(input); - #if defined(HAVE_VFX_MODIFICATION) && defined(UNITY_INSTANCING_ENABLED) - unity_InstanceID = input.instanceID; - #endif - VaryingsMeshToPS unpacked = UnpackVaryingsMeshToPS(input); - return BuildFragInputs(unpacked); - } - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassFullScreenDebug.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "DepthOnly" - Tags - { - "LightMode" = "DepthOnly" - } - - // Render State - Cull [_CullMode] - ZWrite On - Stencil - { - WriteMask [_StencilWriteMaskDepth] - Ref [_StencilRefDepth] - CompFront Always - PassFront Replace - CompBack Always - PassBack Replace - } - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma multi_compile _ DOTS_INSTANCING_ON - #pragma instancing_options renderinglayer - #pragma target 4.5 - #pragma vertex Vert - #pragma fragment Frag - #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch - #pragma multi_compile_instancing - - // Keywords - #pragma multi_compile _ WRITE_NORMAL_BUFFER - #pragma multi_compile_fragment _ WRITE_MSAA_DEPTH - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma multi_compile_fragment _ WRITE_DECAL_BUFFER WRITE_RENDERING_LAYER - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - struct CustomInterpolators - { - }; - #define USE_CUSTOMINTERP_SUBSTRUCT - - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - - #define HAVE_MESH_MODIFICATION - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_DEPTH_ONLY - #define RAYTRACING_SHADER_GRAPH_DEFAULT - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct AttributesMesh - { - float3 positionOS : POSITION; - float3 normalOS : NORMAL; - float4 tangentOS : TANGENT; - float4 uv0 : TEXCOORD0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : INSTANCEID_SEMANTIC; - #endif - }; - struct VaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float3 positionRWS; - float3 normalWS; - float4 tangentWS; - float4 texCoord0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - struct VertexDescriptionInputs - { - float3 ObjectSpaceNormal; - float3 ObjectSpaceTangent; - float3 ObjectSpacePosition; - }; - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - struct PackedVaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float4 tangentWS : INTERP0; - float4 texCoord0 : INTERP1; - float3 positionRWS : INTERP2; - float3 normalWS : INTERP3; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - - PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input) - { - PackedVaryingsMeshToPS output; - ZERO_INITIALIZE(PackedVaryingsMeshToPS, output); - output.positionCS = input.positionCS; - output.tangentWS.xyzw = input.tangentWS; - output.texCoord0.xyzw = input.texCoord0; - output.positionRWS.xyz = input.positionRWS; - output.normalWS.xyz = input.normalWS; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input) - { - VaryingsMeshToPS output; - output.positionCS = input.positionCS; - output.tangentWS = input.tangentWS.xyzw; - output.texCoord0 = input.texCoord0.xyzw; - output.positionRWS = input.positionRWS.xyz; - output.normalWS = input.normalWS.xyz; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - struct VertexDescription - { - float3 Position; - float3 Normal; - float3 Tangent; - }; - - VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN) - { - VertexDescription description = (VertexDescription)0; - description.Position = IN.ObjectSpacePosition; - description.Normal = IN.ObjectSpaceNormal; - description.Tangent = IN.ObjectSpaceTangent; - return description; - } - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - - VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input) - { - VertexDescriptionInputs output; - ZERO_INITIALIZE(VertexDescriptionInputs, output); - - output.ObjectSpaceNormal = input.normalOS; - output.ObjectSpaceTangent = input.tangentOS.xyz; - output.ObjectSpacePosition = input.positionOS; - - return output; - } - - VertexDescription GetVertexDescription(AttributesMesh input, float3 timeParameters - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - // build graph inputs - VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input); - // Override time parameters with used one (This is required to correctly handle motion vectors for vertex animation based on time) - - // evaluate vertex graph - #ifdef HAVE_VFX_MODIFICATION - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - // Fetch the vertex graph properties for the particle instance. - GetElementVertexProperties(element, properties); - - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs, properties); - #else - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); - #endif - return vertexDescription; - - } - - AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters - #ifdef USE_CUSTOMINTERP_SUBSTRUCT - #ifdef TESSELLATION_ON - , inout VaryingsMeshToDS varyings - #else - , inout VaryingsMeshToPS varyings - #endif - #endif - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, timeParameters - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - - // copy graph output to the results - input.positionOS = vertexDescription.Position; - input.normalOS = vertexDescription.Normal; - input.tangentOS.xyz = vertexDescription.Tangent; - - - - return input; - } - - #if defined(_ADD_CUSTOM_VELOCITY) // For shader graph custom velocity - // Return precomputed Velocity in object space - float3 GetCustomVelocity(AttributesMesh input - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, _TimeParameters.xyz - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - return vertexDescription.CustomVelocity; - } - #endif - - FragInputs BuildFragInputs(VaryingsMeshToPS input) - { - FragInputs output; - ZERO_INITIALIZE(FragInputs, output); - - // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). - // TODO: this is a really poor workaround, but the variable is used in a bunch of places - // to compute normals which are then passed on elsewhere to compute other values... - output.tangentToWorld = k_identity3x3; - output.positionSS = input.positionCS; // input.positionCS is SV_Position - - output.positionRWS = input.positionRWS; - output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS); - output.texCoord0 = input.texCoord0; - - #ifdef HAVE_VFX_MODIFICATION - // FragInputs from VFX come from two places: Interpolator or CBuffer. - #if VFX_USE_GRAPH_VALUES - uint instanceActiveIndex = asuint(UNITY_ACCESS_INSTANCED_PROP(PerInstance, _InstanceActiveIndex)); - /* WARNING: $splice Could not find named fragment 'VFXLoadGraphValues' */ - #endif - - /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */ - - #endif - - // splice point to copy custom interpolator fields from varyings to frag inputs - - - return output; - } - - // existing HDRP code uses the combined function to go directly from packed to frag inputs - FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) - { - UNITY_SETUP_INSTANCE_ID(input); - #if defined(HAVE_VFX_MODIFICATION) && defined(UNITY_INSTANCING_ENABLED) - unity_InstanceID = input.instanceID; - #endif - VaryingsMeshToPS unpacked = UnpackVaryingsMeshToPS(input); - return BuildFragInputs(unpacked); - } - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "GBuffer" - Tags - { - "LightMode" = "GBuffer" - } - - // Render State - Cull [_CullMode] - ZTest [_ZTestGBuffer] - Stencil - { - WriteMask [_StencilWriteMaskGBuffer] - Ref [_StencilRefGBuffer] - CompFront Always - PassFront Replace - CompBack Always - PassBack Replace - } - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma multi_compile _ DOTS_INSTANCING_ON - #pragma instancing_options renderinglayer - #pragma target 4.5 - #pragma vertex Vert - #pragma fragment Frag - #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch - #pragma multi_compile_instancing - - // Keywords - #pragma multi_compile_fragment _ RENDERING_LAYERS - #pragma multi_compile_raytracing _ RENDERING_LAYERS - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma multi_compile _ DEBUG_DISPLAY - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma multi_compile _ LIGHTMAP_ON - #pragma multi_compile _ DIRLIGHTMAP_COMBINED - #pragma multi_compile_fragment _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 - #pragma multi_compile_raytracing _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 - #pragma multi_compile _ DYNAMICLIGHTMAP_ON - #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK - #pragma multi_compile_raytracing _ SHADOWS_SHADOWMASK - #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT - #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - struct CustomInterpolators - { - }; - #define USE_CUSTOMINTERP_SUBSTRUCT - - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define ATTRIBUTES_NEED_TEXCOORD1 - #define ATTRIBUTES_NEED_TEXCOORD2 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - #define VARYINGS_NEED_TEXCOORD1 - #define VARYINGS_NEED_TEXCOORD2 - - #define HAVE_MESH_MODIFICATION - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - #define FRAG_INPUTS_USE_TEXCOORD1 - #define FRAG_INPUTS_USE_TEXCOORD2 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_GBUFFER - #define RAYTRACING_SHADER_GRAPH_DEFAULT - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct AttributesMesh - { - float3 positionOS : POSITION; - float3 normalOS : NORMAL; - float4 tangentOS : TANGENT; - float4 uv0 : TEXCOORD0; - float4 uv1 : TEXCOORD1; - float4 uv2 : TEXCOORD2; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : INSTANCEID_SEMANTIC; - #endif - }; - struct VaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float3 positionRWS; - float3 normalWS; - float4 tangentWS; - float4 texCoord0; - float4 texCoord1; - float4 texCoord2; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - struct VertexDescriptionInputs - { - float3 ObjectSpaceNormal; - float3 ObjectSpaceTangent; - float3 ObjectSpacePosition; - }; - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - struct PackedVaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float4 tangentWS : INTERP0; - float4 texCoord0 : INTERP1; - float4 texCoord1 : INTERP2; - float4 texCoord2 : INTERP3; - float3 positionRWS : INTERP4; - float3 normalWS : INTERP5; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - - PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input) - { - PackedVaryingsMeshToPS output; - ZERO_INITIALIZE(PackedVaryingsMeshToPS, output); - output.positionCS = input.positionCS; - output.tangentWS.xyzw = input.tangentWS; - output.texCoord0.xyzw = input.texCoord0; - output.texCoord1.xyzw = input.texCoord1; - output.texCoord2.xyzw = input.texCoord2; - output.positionRWS.xyz = input.positionRWS; - output.normalWS.xyz = input.normalWS; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input) - { - VaryingsMeshToPS output; - output.positionCS = input.positionCS; - output.tangentWS = input.tangentWS.xyzw; - output.texCoord0 = input.texCoord0.xyzw; - output.texCoord1 = input.texCoord1.xyzw; - output.texCoord2 = input.texCoord2.xyzw; - output.positionRWS = input.positionRWS.xyz; - output.normalWS = input.normalWS.xyz; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - struct VertexDescription - { - float3 Position; - float3 Normal; - float3 Tangent; - }; - - VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN) - { - VertexDescription description = (VertexDescription)0; - description.Position = IN.ObjectSpacePosition; - description.Normal = IN.ObjectSpaceNormal; - description.Tangent = IN.ObjectSpaceTangent; - return description; - } - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - float4 VTPackedFeedback; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - { - surface.VTPackedFeedback = float4(1.0f,1.0f,1.0f,1.0f); - } - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - - VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input) - { - VertexDescriptionInputs output; - ZERO_INITIALIZE(VertexDescriptionInputs, output); - - output.ObjectSpaceNormal = input.normalOS; - output.ObjectSpaceTangent = input.tangentOS.xyz; - output.ObjectSpacePosition = input.positionOS; - - return output; - } - - VertexDescription GetVertexDescription(AttributesMesh input, float3 timeParameters - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - // build graph inputs - VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input); - // Override time parameters with used one (This is required to correctly handle motion vectors for vertex animation based on time) - - // evaluate vertex graph - #ifdef HAVE_VFX_MODIFICATION - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - // Fetch the vertex graph properties for the particle instance. - GetElementVertexProperties(element, properties); - - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs, properties); - #else - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); - #endif - return vertexDescription; - - } - - AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters - #ifdef USE_CUSTOMINTERP_SUBSTRUCT - #ifdef TESSELLATION_ON - , inout VaryingsMeshToDS varyings - #else - , inout VaryingsMeshToPS varyings - #endif - #endif - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, timeParameters - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - - // copy graph output to the results - input.positionOS = vertexDescription.Position; - input.normalOS = vertexDescription.Normal; - input.tangentOS.xyz = vertexDescription.Tangent; - - - - return input; - } - - #if defined(_ADD_CUSTOM_VELOCITY) // For shader graph custom velocity - // Return precomputed Velocity in object space - float3 GetCustomVelocity(AttributesMesh input - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, _TimeParameters.xyz - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - return vertexDescription.CustomVelocity; - } - #endif - - FragInputs BuildFragInputs(VaryingsMeshToPS input) - { - FragInputs output; - ZERO_INITIALIZE(FragInputs, output); - - // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). - // TODO: this is a really poor workaround, but the variable is used in a bunch of places - // to compute normals which are then passed on elsewhere to compute other values... - output.tangentToWorld = k_identity3x3; - output.positionSS = input.positionCS; // input.positionCS is SV_Position - - output.positionRWS = input.positionRWS; - output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS); - output.texCoord0 = input.texCoord0; - output.texCoord1 = input.texCoord1; - output.texCoord2 = input.texCoord2; - - #ifdef HAVE_VFX_MODIFICATION - // FragInputs from VFX come from two places: Interpolator or CBuffer. - #if VFX_USE_GRAPH_VALUES - uint instanceActiveIndex = asuint(UNITY_ACCESS_INSTANCED_PROP(PerInstance, _InstanceActiveIndex)); - /* WARNING: $splice Could not find named fragment 'VFXLoadGraphValues' */ - #endif - - /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */ - - #endif - - // splice point to copy custom interpolator fields from varyings to frag inputs - - - return output; - } - - // existing HDRP code uses the combined function to go directly from packed to frag inputs - FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) - { - UNITY_SETUP_INSTANCE_ID(input); - #if defined(HAVE_VFX_MODIFICATION) && defined(UNITY_INSTANCING_ENABLED) - unity_InstanceID = input.instanceID; - #endif - VaryingsMeshToPS unpacked = UnpackVaryingsMeshToPS(input); - return BuildFragInputs(unpacked); - } - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback; - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "Forward" - Tags - { - "LightMode" = "Forward" - } - - // Render State - Cull [_CullModeForward] - Blend [_SrcBlend] [_DstBlend], [_AlphaSrcBlend] [_AlphaDstBlend] - Blend 1 SrcAlpha OneMinusSrcAlpha - ZTest [_ZTestDepthEqualForOpaque] - ZWrite [_ZWrite] - ColorMask [_ColorMaskTransparentVelOne] 1 - ColorMask [_ColorMaskTransparentVelTwo] 2 - Stencil - { - WriteMask [_StencilWriteMask] - Ref [_StencilRef] - CompFront Always - PassFront Replace - CompBack Always - PassBack Replace - } - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma multi_compile _ DOTS_INSTANCING_ON - #pragma instancing_options renderinglayer - #pragma target 4.5 - #pragma vertex Vert - #pragma fragment Frag - #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch - #pragma multi_compile_instancing - - // Keywords - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma multi_compile _ DEBUG_DISPLAY - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma multi_compile _ LIGHTMAP_ON - #pragma multi_compile _ DIRLIGHTMAP_COMBINED - #pragma multi_compile_fragment _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 - #pragma multi_compile_raytracing _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 - #pragma multi_compile _ DYNAMICLIGHTMAP_ON - #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK - #pragma multi_compile_raytracing _ SHADOWS_SHADOWMASK - #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT - #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH - #pragma multi_compile_fragment AREA_SHADOW_MEDIUM AREA_SHADOW_HIGH - #pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON - #pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - struct CustomInterpolators - { - }; - #define USE_CUSTOMINTERP_SUBSTRUCT - - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define ATTRIBUTES_NEED_TEXCOORD1 - #define ATTRIBUTES_NEED_TEXCOORD2 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - #define VARYINGS_NEED_TEXCOORD1 - #define VARYINGS_NEED_TEXCOORD2 - - #define HAVE_MESH_MODIFICATION - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - #define FRAG_INPUTS_USE_TEXCOORD1 - #define FRAG_INPUTS_USE_TEXCOORD2 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_FORWARD - #define SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 - #define HAS_LIGHTLOOP 1 - #define RAYTRACING_SHADER_GRAPH_DEFAULT - #define SHADER_LIT 1 - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct AttributesMesh - { - float3 positionOS : POSITION; - float3 normalOS : NORMAL; - float4 tangentOS : TANGENT; - float4 uv0 : TEXCOORD0; - float4 uv1 : TEXCOORD1; - float4 uv2 : TEXCOORD2; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : INSTANCEID_SEMANTIC; - #endif - }; - struct VaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float3 positionRWS; - float3 normalWS; - float4 tangentWS; - float4 texCoord0; - float4 texCoord1; - float4 texCoord2; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - struct VertexDescriptionInputs - { - float3 ObjectSpaceNormal; - float3 ObjectSpaceTangent; - float3 ObjectSpacePosition; - }; - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - struct PackedVaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float4 tangentWS : INTERP0; - float4 texCoord0 : INTERP1; - float4 texCoord1 : INTERP2; - float4 texCoord2 : INTERP3; - float3 positionRWS : INTERP4; - float3 normalWS : INTERP5; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - - PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input) - { - PackedVaryingsMeshToPS output; - ZERO_INITIALIZE(PackedVaryingsMeshToPS, output); - output.positionCS = input.positionCS; - output.tangentWS.xyzw = input.tangentWS; - output.texCoord0.xyzw = input.texCoord0; - output.texCoord1.xyzw = input.texCoord1; - output.texCoord2.xyzw = input.texCoord2; - output.positionRWS.xyz = input.positionRWS; - output.normalWS.xyz = input.normalWS; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input) - { - VaryingsMeshToPS output; - output.positionCS = input.positionCS; - output.tangentWS = input.tangentWS.xyzw; - output.texCoord0 = input.texCoord0.xyzw; - output.texCoord1 = input.texCoord1.xyzw; - output.texCoord2 = input.texCoord2.xyzw; - output.positionRWS = input.positionRWS.xyz; - output.normalWS = input.normalWS.xyz; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - struct VertexDescription - { - float3 Position; - float3 Normal; - float3 Tangent; - }; - - VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN) - { - VertexDescription description = (VertexDescription)0; - description.Position = IN.ObjectSpacePosition; - description.Normal = IN.ObjectSpaceNormal; - description.Tangent = IN.ObjectSpaceTangent; - return description; - } - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - float4 VTPackedFeedback; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - { - surface.VTPackedFeedback = float4(1.0f,1.0f,1.0f,1.0f); - } - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - - VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input) - { - VertexDescriptionInputs output; - ZERO_INITIALIZE(VertexDescriptionInputs, output); - - output.ObjectSpaceNormal = input.normalOS; - output.ObjectSpaceTangent = input.tangentOS.xyz; - output.ObjectSpacePosition = input.positionOS; - - return output; - } - - VertexDescription GetVertexDescription(AttributesMesh input, float3 timeParameters - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - // build graph inputs - VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input); - // Override time parameters with used one (This is required to correctly handle motion vectors for vertex animation based on time) - - // evaluate vertex graph - #ifdef HAVE_VFX_MODIFICATION - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - // Fetch the vertex graph properties for the particle instance. - GetElementVertexProperties(element, properties); - - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs, properties); - #else - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); - #endif - return vertexDescription; - - } - - AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters - #ifdef USE_CUSTOMINTERP_SUBSTRUCT - #ifdef TESSELLATION_ON - , inout VaryingsMeshToDS varyings - #else - , inout VaryingsMeshToPS varyings - #endif - #endif - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, timeParameters - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - - // copy graph output to the results - input.positionOS = vertexDescription.Position; - input.normalOS = vertexDescription.Normal; - input.tangentOS.xyz = vertexDescription.Tangent; - - - - return input; - } - - #if defined(_ADD_CUSTOM_VELOCITY) // For shader graph custom velocity - // Return precomputed Velocity in object space - float3 GetCustomVelocity(AttributesMesh input - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, _TimeParameters.xyz - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - return vertexDescription.CustomVelocity; - } - #endif - - FragInputs BuildFragInputs(VaryingsMeshToPS input) - { - FragInputs output; - ZERO_INITIALIZE(FragInputs, output); - - // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). - // TODO: this is a really poor workaround, but the variable is used in a bunch of places - // to compute normals which are then passed on elsewhere to compute other values... - output.tangentToWorld = k_identity3x3; - output.positionSS = input.positionCS; // input.positionCS is SV_Position - - output.positionRWS = input.positionRWS; - output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS); - output.texCoord0 = input.texCoord0; - output.texCoord1 = input.texCoord1; - output.texCoord2 = input.texCoord2; - - #ifdef HAVE_VFX_MODIFICATION - // FragInputs from VFX come from two places: Interpolator or CBuffer. - #if VFX_USE_GRAPH_VALUES - uint instanceActiveIndex = asuint(UNITY_ACCESS_INSTANCED_PROP(PerInstance, _InstanceActiveIndex)); - /* WARNING: $splice Could not find named fragment 'VFXLoadGraphValues' */ - #endif - - /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */ - - #endif - - // splice point to copy custom interpolator fields from varyings to frag inputs - - - return output; - } - - // existing HDRP code uses the combined function to go directly from packed to frag inputs - FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) - { - UNITY_SETUP_INSTANCE_ID(input); - #if defined(HAVE_VFX_MODIFICATION) && defined(UNITY_INSTANCING_ENABLED) - unity_InstanceID = input.instanceID; - #endif - VaryingsMeshToPS unpacked = UnpackVaryingsMeshToPS(input); - return BuildFragInputs(unpacked); - } - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback; - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "RayTracingPrepass" - Tags - { - "LightMode" = "RayTracingPrepass" - } - - // Render State - Cull [_CullMode] - Blend One Zero - ZWrite On - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma target 4.5 - #pragma vertex Vert - #pragma fragment Frag - #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch - #pragma multi_compile_instancing - - // Keywords - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - struct CustomInterpolators - { - }; - #define USE_CUSTOMINTERP_SUBSTRUCT - - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - - #define HAVE_MESH_MODIFICATION - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_CONSTANT - #define RAYTRACING_SHADER_GRAPH_DEFAULT - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct AttributesMesh - { - float3 positionOS : POSITION; - float3 normalOS : NORMAL; - float4 tangentOS : TANGENT; - float4 uv0 : TEXCOORD0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : INSTANCEID_SEMANTIC; - #endif - }; - struct VaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float3 positionRWS; - float3 normalWS; - float4 tangentWS; - float4 texCoord0; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - struct VertexDescriptionInputs - { - float3 ObjectSpaceNormal; - float3 ObjectSpaceTangent; - float3 ObjectSpacePosition; - }; - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - struct PackedVaryingsMeshToPS - { - SV_POSITION_QUALIFIERS float4 positionCS : SV_POSITION; - float4 tangentWS : INTERP0; - float4 texCoord0 : INTERP1; - float3 positionRWS : INTERP2; - float3 normalWS : INTERP3; - #if UNITY_ANY_INSTANCING_ENABLED - uint instanceID : CUSTOM_INSTANCE_ID; - #endif - }; - - PackedVaryingsMeshToPS PackVaryingsMeshToPS (VaryingsMeshToPS input) - { - PackedVaryingsMeshToPS output; - ZERO_INITIALIZE(PackedVaryingsMeshToPS, output); - output.positionCS = input.positionCS; - output.tangentWS.xyzw = input.tangentWS; - output.texCoord0.xyzw = input.texCoord0; - output.positionRWS.xyz = input.positionRWS; - output.normalWS.xyz = input.normalWS; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - VaryingsMeshToPS UnpackVaryingsMeshToPS (PackedVaryingsMeshToPS input) - { - VaryingsMeshToPS output; - output.positionCS = input.positionCS; - output.tangentWS = input.tangentWS.xyzw; - output.texCoord0 = input.texCoord0.xyzw; - output.positionRWS = input.positionRWS.xyz; - output.normalWS = input.normalWS.xyz; - #if UNITY_ANY_INSTANCING_ENABLED - output.instanceID = input.instanceID; - #endif - return output; - } - - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - struct VertexDescription - { - float3 Position; - float3 Normal; - float3 Tangent; - }; - - VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN) - { - VertexDescription description = (VertexDescription)0; - description.Position = IN.ObjectSpacePosition; - description.Normal = IN.ObjectSpaceNormal; - description.Tangent = IN.ObjectSpaceTangent; - return description; - } - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - - VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input) - { - VertexDescriptionInputs output; - ZERO_INITIALIZE(VertexDescriptionInputs, output); - - output.ObjectSpaceNormal = input.normalOS; - output.ObjectSpaceTangent = input.tangentOS.xyz; - output.ObjectSpacePosition = input.positionOS; - - return output; - } - - VertexDescription GetVertexDescription(AttributesMesh input, float3 timeParameters - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - // build graph inputs - VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input); - // Override time parameters with used one (This is required to correctly handle motion vectors for vertex animation based on time) - - // evaluate vertex graph - #ifdef HAVE_VFX_MODIFICATION - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - // Fetch the vertex graph properties for the particle instance. - GetElementVertexProperties(element, properties); - - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs, properties); - #else - VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); - #endif - return vertexDescription; - - } - - AttributesMesh ApplyMeshModification(AttributesMesh input, float3 timeParameters - #ifdef USE_CUSTOMINTERP_SUBSTRUCT - #ifdef TESSELLATION_ON - , inout VaryingsMeshToDS varyings - #else - , inout VaryingsMeshToPS varyings - #endif - #endif - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, timeParameters - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - - // copy graph output to the results - input.positionOS = vertexDescription.Position; - input.normalOS = vertexDescription.Normal; - input.tangentOS.xyz = vertexDescription.Tangent; - - - - return input; - } - - #if defined(_ADD_CUSTOM_VELOCITY) // For shader graph custom velocity - // Return precomputed Velocity in object space - float3 GetCustomVelocity(AttributesMesh input - #ifdef HAVE_VFX_MODIFICATION - , AttributesElement element - #endif - ) - { - VertexDescription vertexDescription = GetVertexDescription(input, _TimeParameters.xyz - #ifdef HAVE_VFX_MODIFICATION - , element - #endif - ); - return vertexDescription.CustomVelocity; - } - #endif - - FragInputs BuildFragInputs(VaryingsMeshToPS input) - { - FragInputs output; - ZERO_INITIALIZE(FragInputs, output); - - // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). - // TODO: this is a really poor workaround, but the variable is used in a bunch of places - // to compute normals which are then passed on elsewhere to compute other values... - output.tangentToWorld = k_identity3x3; - output.positionSS = input.positionCS; // input.positionCS is SV_Position - - output.positionRWS = input.positionRWS; - output.tangentToWorld = BuildTangentToWorld(input.tangentWS, input.normalWS); - output.texCoord0 = input.texCoord0; - - #ifdef HAVE_VFX_MODIFICATION - // FragInputs from VFX come from two places: Interpolator or CBuffer. - #if VFX_USE_GRAPH_VALUES - uint instanceActiveIndex = asuint(UNITY_ACCESS_INSTANCED_PROP(PerInstance, _InstanceActiveIndex)); - /* WARNING: $splice Could not find named fragment 'VFXLoadGraphValues' */ - #endif - - /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */ - - #endif - - // splice point to copy custom interpolator fields from varyings to frag inputs - - - return output; - } - - // existing HDRP code uses the combined function to go directly from packed to frag inputs - FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) - { - UNITY_SETUP_INSTANCE_ID(input); - #if defined(HAVE_VFX_MODIFICATION) && defined(UNITY_INSTANCING_ENABLED) - unity_InstanceID = input.instanceID; - #endif - VaryingsMeshToPS unpacked = UnpackVaryingsMeshToPS(input); - return BuildFragInputs(unpacked); - } - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassConstant.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - } - SubShader - { - Tags - { - "RenderPipeline"="HDRenderPipeline" - "RenderType"="HDLitShader" - "Queue"="Transparent+0" - "DisableBatching"="False" - "ShaderGraphShader"="true" - "ShaderGraphTargetId"="HDLitSubTarget" - } - Pass - { - Name "IndirectDXR" - Tags - { - "LightMode" = "IndirectDXR" - } - - // Render State - // RenderState: - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma target 5.0 - #pragma raytracing surface_shader - #pragma only_renderers d3d11 xboxseries ps5 - - // Keywords - #pragma multi_compile _ MULTI_BOUNCE_INDIRECT - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma multi_compile _ DEBUG_DISPLAY - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma multi_compile _ LIGHTMAP_ON - #pragma multi_compile _ DIRLIGHTMAP_COMBINED - #pragma multi_compile_fragment _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 - #pragma multi_compile_raytracing _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 - #pragma multi_compile _ DYNAMICLIGHTMAP_ON - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorPreInclude' */ - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define ATTRIBUTES_NEED_TEXCOORD1 - #define ATTRIBUTES_NEED_TEXCOORD2 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - #define VARYINGS_NEED_TEXCOORD1 - #define VARYINGS_NEED_TEXCOORD2 - - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - #define FRAG_INPUTS_USE_TEXCOORD1 - #define FRAG_INPUTS_USE_TEXCOORD2 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_RAYTRACING_INDIRECT - #define SHADOW_LOW - #define RAYTRACING_SHADER_GRAPH_RAYTRACED - #define HAS_LIGHTLOOP 1 - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRayTracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - - //Interpolator Packs: - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - // GraphVertex: - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorCopyToSDI' */ - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingIndirect.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "VisibilityDXR" - Tags - { - "LightMode" = "VisibilityDXR" - } - - // Render State - // RenderState: - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma target 5.0 - #pragma raytracing surface_shader - #pragma only_renderers d3d11 xboxseries ps5 - - // Keywords - #pragma multi_compile _ TRANSPARENT_COLOR_SHADOW - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorPreInclude' */ - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_RAYTRACING_VISIBILITY - #define RAYTRACING_SHADER_GRAPH_RAYTRACED - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRayTracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - - //Interpolator Packs: - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - // GraphVertex: - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorCopyToSDI' */ - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingVisibility.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "ForwardDXR" - Tags - { - "LightMode" = "ForwardDXR" - } - - // Render State - // RenderState: - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma target 5.0 - #pragma raytracing surface_shader - #pragma only_renderers d3d11 xboxseries ps5 - - // Keywords - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma multi_compile _ DEBUG_DISPLAY - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma multi_compile _ LIGHTMAP_ON - #pragma multi_compile _ DIRLIGHTMAP_COMBINED - #pragma multi_compile_fragment _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 - #pragma multi_compile_raytracing _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 - #pragma multi_compile _ DYNAMICLIGHTMAP_ON - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorPreInclude' */ - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define ATTRIBUTES_NEED_TEXCOORD1 - #define ATTRIBUTES_NEED_TEXCOORD2 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - #define VARYINGS_NEED_TEXCOORD1 - #define VARYINGS_NEED_TEXCOORD2 - - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - #define FRAG_INPUTS_USE_TEXCOORD1 - #define FRAG_INPUTS_USE_TEXCOORD2 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_RAYTRACING_FORWARD - #define SHADOW_LOW - #define RAYTRACING_SHADER_GRAPH_RAYTRACED - #define HAS_LIGHTLOOP 1 - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRayTracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - - //Interpolator Packs: - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - // GraphVertex: - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorCopyToSDI' */ - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingForward.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "GBufferDXR" - Tags - { - "LightMode" = "GBufferDXR" - } - - // Render State - // RenderState: - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma target 5.0 - #pragma raytracing surface_shader - #pragma only_renderers d3d11 xboxseries ps5 - - // Keywords - #pragma multi_compile _ MINIMAL_GBUFFER - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma multi_compile _ DEBUG_DISPLAY - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma multi_compile _ LIGHTMAP_ON - #pragma multi_compile _ DIRLIGHTMAP_COMBINED - #pragma multi_compile_fragment _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 - #pragma multi_compile_raytracing _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 - #pragma multi_compile _ DYNAMICLIGHTMAP_ON - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorPreInclude' */ - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define ATTRIBUTES_NEED_TEXCOORD1 - #define ATTRIBUTES_NEED_TEXCOORD2 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - #define VARYINGS_NEED_TEXCOORD1 - #define VARYINGS_NEED_TEXCOORD2 - - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - #define FRAG_INPUTS_USE_TEXCOORD1 - #define FRAG_INPUTS_USE_TEXCOORD2 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_RAYTRACING_GBUFFER - #define SHADOW_LOW - #define RAYTRACING_SHADER_GRAPH_RAYTRACED - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingIntersectonGBuffer.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRayTracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - - //Interpolator Packs: - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - // GraphVertex: - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorCopyToSDI' */ - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingGBuffer.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - Pass - { - Name "DebugDXR" - Tags - { - "LightMode" = "DebugDXR" - } - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma target 5.0 - #pragma raytracing surface_shader - #pragma only_renderers d3d11 xboxseries ps5 - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRayTracingDebug.hlsl" - - ENDHLSL - } - Pass - { - Name "PathTracingDXR" - Tags - { - "LightMode" = "PathTracingDXR" - } - - // Render State - // RenderState: - - // Debug - // - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - #pragma target 5.0 - #pragma raytracing surface_shader - #pragma only_renderers d3d11 xboxseries ps5 - - // Keywords - #pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT - #pragma shader_feature_local _ _DOUBLESIDED_ON - #pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY - #pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC - #pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT - #pragma shader_feature_local_fragment _ _DISABLE_DECALS - #pragma shader_feature_local_raytracing _ _DISABLE_DECALS - #pragma shader_feature_local_fragment _ _DISABLE_SSR - #pragma shader_feature_local_raytracing _ _DISABLE_SSR - #pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT - #pragma shader_feature_local _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_TRANSMISSION - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_ANISOTROPY - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_IRIDESCENCE - #pragma shader_feature_local_fragment _MATERIAL_FEATURE_SPECULAR_COLOR - #pragma shader_feature_local_raytracing _MATERIAL_FEATURE_SPECULAR_COLOR - // GraphKeywords: - - // For custom interpolators to inject a substruct definition before FragInputs definition, - // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorPreInclude' */ - - - // TODO: Merge FragInputsVFX substruct with CustomInterpolators. - #ifdef HAVE_VFX_MODIFICATION - struct FragInputsVFX - { - /* WARNING: $splice Could not find named fragment 'FragInputsVFX' */ - }; - #endif - - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB - // Always include Shader Graph version - // Always include last to avoid double macros - #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition - - // -------------------------------------------------- - // Defines - - // Attribute - #define ATTRIBUTES_NEED_NORMAL - #define ATTRIBUTES_NEED_TANGENT - #define ATTRIBUTES_NEED_TEXCOORD0 - #define ATTRIBUTES_NEED_TEXCOORD1 - #define ATTRIBUTES_NEED_TEXCOORD2 - #define VARYINGS_NEED_POSITION_WS - #define VARYINGS_NEED_TANGENT_TO_WORLD - #define VARYINGS_NEED_TEXCOORD0 - #define VARYINGS_NEED_TEXCOORD1 - #define VARYINGS_NEED_TEXCOORD2 - - - //Strip down the FragInputs.hlsl (on graphics), so we can only optimize the interpolators we use. - //if by accident something requests contents of FragInputs.hlsl, it will be caught as a compiler error - //Frag inputs stripping is only enabled when FRAG_INPUTS_ENABLE_STRIPPING is set - #if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG - #define FRAG_INPUTS_ENABLE_STRIPPING - #endif - #define FRAG_INPUTS_USE_TEXCOORD0 - #define FRAG_INPUTS_USE_TEXCOORD1 - #define FRAG_INPUTS_USE_TEXCOORD2 - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" - - - - #define SHADERPASS SHADERPASS_PATH_TRACING - #define SHADOW_LOW - #define RAYTRACING_SHADER_GRAPH_DEFAULT - #define HAS_LIGHTLOOP 1 - - - // Following two define are a workaround introduce in 10.1.x for RaytracingQualityNode - // The ShaderGraph don't support correctly migration of this node as it serialize all the node data - // in the json file making it impossible to uprgrade. Until we get a fix, we do a workaround here - // to still allow us to rename the field and keyword of this node without breaking existing code. - #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT - #define RAYTRACING_SHADER_GRAPH_HIGH - #endif - - #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED - #define RAYTRACING_SHADER_GRAPH_LOW - #endif - // end - - #ifndef SHADER_UNLIT - // We need isFrontFace when using double sided - it is not required for unlit as in case of unlit double sided only drive the cullmode - // VARYINGS_NEED_CULLFACE can be define by VaryingsMeshToPS.FaceSign input if a IsFrontFace Node is included in the shader graph. - #if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE) - #define VARYINGS_NEED_CULLFACE - #endif - #endif - - // Specific Material Define - #define _MATERIAL_FEATURE_CLEAR_COAT - #define _AMBIENT_OCCLUSION 1 - #define _SPECULAR_OCCLUSION_FROM_AO 1 - #define _ENERGY_CONSERVING_SPECULAR 1 - - // If we use subsurface scattering, enable output split lighting (for forward pass) - #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define OUTPUT_SPLIT_LIGHTING - #endif - - // This shader support recursive rendering for raytracing - #define HAVE_RECURSIVE_RENDERING - - // In Path Tracing, For all single-sided, refractive materials, we want to force a thin refraction model - #if (SHADERPASS == SHADERPASS_PATH_TRACING) && !defined(_DOUBLESIDED_ON) && (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) - #undef _REFRACTION_PLANE - #undef _REFRACTION_SPHERE - #define _REFRACTION_THIN - #endif - // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it - - // To handle SSR on transparent correctly with a possibility to enable/disable it per framesettings - // we should have a code like this: - // if !defined(_DISABLE_SSR_TRANSPARENT) - // pragma multi_compile _ WRITE_NORMAL_BUFFER - // endif - // i.e we enable the multicompile only if we can receive SSR or not, and then C# code drive - // it based on if SSR transparent in frame settings and not (and stripper can strip it). - // this is currently not possible with our current preprocessor as _DISABLE_SSR_TRANSPARENT is a keyword not a define - // so instead we used this and chose to pay the extra cost of normal write even if SSR transaprent is disabled. - // Ideally the shader graph generator should handle it but condition below can't be handle correctly for now. - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) - #define WRITE_NORMAL_BUFFER - #endif - #endif - - // See Lit.shader - #if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER) - #define WRITE_DECAL_BUFFER - #endif - - #ifndef DEBUG_DISPLAY - // 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) - // Don't do it with debug display mode as it is possible there is no depth prepass in this case - #if !defined(_SURFACE_TYPE_TRANSPARENT) - #if SHADERPASS == SHADERPASS_FORWARD - #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST - #elif SHADERPASS == SHADERPASS_GBUFFER - #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST - #endif - #endif - #endif - - // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass - #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) - #define _DEFERRED_CAPABLE_MATERIAL - #endif - - // Translate transparent motion vector define - #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) - #define _WRITE_TRANSPARENT_MOTION_VECTOR - #endif - - // -- Graph Properties - CBUFFER_START(UnityPerMaterial) - float4 _DiffusionProfileAsset; - float _DiffusionProfileHash; - float _WaveScale; - float4 _BaseColor; - float _WaveStrength; - float _TimeScale; - float _AlphaPower; - float4 _TransColor; - float _FresPower; - float _CircleDest; - float _Emission; - float4 _EmissionColor; - float _UseShadowThreshold; - float4 _DoubleSidedConstants; - float _BlendMode; - float _EnableBlendModePreserveSpecularLighting; - float _RayTracing; - float _RefractionModel; - float _MaterialID; - float _MaterialTypeMask; - CBUFFER_END - - - // Object and Global properties - - // -- Property used by ScenePickingPass - #ifdef SCENEPICKINGPASS - float4 _SelectionID; - #endif - - // -- Properties used by SceneSelectionPass - #ifdef SCENESELECTIONPASS - int _ObjectId; - int _PassValue; - #endif - - // Includes - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" - - // -------------------------------------------------- - // Structs and Packing - - struct SurfaceDescriptionInputs - { - float3 WorldSpaceNormal; - float3 TangentSpaceNormal; - float3 WorldSpaceTangent; - float3 WorldSpaceBiTangent; - float3 WorldSpaceViewDirection; - float3 WorldSpacePosition; - float4 uv0; - float3 TimeParameters; - }; - - //Interpolator Packs: - - // -------------------------------------------------- - // Graph - - - // Graph Functions - - void Unity_Multiply_float_float(float A, float B, out float Out) - { - Out = A * B; - } - - void Unity_Subtract_float2(float2 A, float2 B, out float2 Out) - { - Out = A - B; - } - - void Unity_Multiply_float2_float2(float2 A, float2 B, out float2 Out) - { - Out = A * B; - } - - void Unity_Length_float2(float2 In, out float Out) - { - Out = length(In); - } - - void Unity_Add_float(float A, float B, out float Out) - { - Out = A + B; - } - - void Unity_Sine_float(float In, out float Out) - { - Out = sin(In); - } - - void Unity_Divide_float(float A, float B, out float Out) - { - Out = A / B; - } - - void Unity_Lerp_float(float A, float B, float T, out float Out) - { - Out = lerp(A, B, T); - } - - void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - } - - void Unity_FresnelEffect_float(float3 Normal, float3 ViewDir, float Power, out float Out) - { - Out = pow((1.0 - saturate(dot(normalize(Normal), normalize(ViewDir)))), Power); - } - - void Unity_Multiply_float4_float4(float4 A, float4 B, out float4 Out) - { - Out = A * B; - } - - float3 Unity_HDRP_GetEmissionHDRColor_float(float3 ldrColor, float luminanceIntensity, float exposureWeight) - { - float3 hdrColor = ldrColor * luminanceIntensity; - - #ifdef SHADERGRAPH_PREVIEW - float inverseExposureMultiplier = 1.0; - #else - float inverseExposureMultiplier = GetInverseCurrentExposureMultiplier(); - #endif - - // Inverse pre-expose using _EmissiveExposureWeight weight - hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight); - return hdrColor; - } - - void Unity_Subtract_float(float A, float B, out float Out) - { - Out = A - B; - } - - void Unity_Maximum_float(float A, float B, out float Out) - { - Out = max(A, B); - } - - void Unity_Power_float(float A, float B, out float Out) - { - Out = pow(A, B); - } - - void Unity_Minimum_float(float A, float B, out float Out) - { - Out = min(A, B); - }; - - void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out) - { - - #if defined(SHADER_STAGE_RAY_TRACING) && defined(RAYTRACING_SHADER_GRAPH_DEFAULT) - #error 'Normal From Height' node is not supported in ray tracing, please provide an alternate implementation, relying for instance on the 'Raytracing Quality' keyword - #endif - float3 worldDerivativeX = ddx(Position); - float3 worldDerivativeY = ddy(Position); - - float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX); - float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz); - float d = dot(worldDerivativeX, crossY); - float sgn = d < 0.0 ? (-1.0f) : 1.0f; - float surface = sgn / max(0.000000000000001192093f, abs(d)); - - float dHdx = ddx(In); - float dHdy = ddy(In); - float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX); - Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad)); - Out = TransformWorldToTangent(Out, TangentMatrix); - } - - void Unity_Lerp_float3(float3 A, float3 B, float3 T, out float3 Out) - { - Out = lerp(A, B, T); - } - - // Graph Vertex - // GraphVertex: - - // Graph Pixel - struct SurfaceDescription - { - float3 BaseColor; - float3 Emission; - float Alpha; - float3 BentNormal; - float Smoothness; - float Occlusion; - float3 NormalTS; - float CoatMask; - float RefractionIndex; - float3 RefractionColor; - float RefractionDistance; - float TransmissionMask; - float Thickness; - float DiffusionProfileHash; - }; - - SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) - { - SurfaceDescription surface = (SurfaceDescription)0; - float4 _Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4 = _BaseColor; - float _Property_871232bf27004c7ab598189ddb755023_Out_0_Float = _TimeScale; - float _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float; - Unity_Multiply_float_float(IN.TimeParameters.x, _Property_871232bf27004c7ab598189ddb755023_Out_0_Float, _Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float); - float4 _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4 = IN.uv0; - float2 _Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2 = _UV_94db754685bb4032b9e27ccd686c593e_Out_0_Vector4.xy; - float2 _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2; - Unity_Subtract_float2(_Swizzle_86888d2752a446eebf28546e6e9b42c4_Out_1_Vector2, float2(0.5, 0.5), _Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2); - float _Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float = _WaveScale; - float2 _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2; - Unity_Multiply_float2_float2(_Subtract_012016a55709404b91da1777f6a9d7d4_Out_2_Vector2, (_Property_57b1cc2025bd410aab4db9fe07558a2e_Out_0_Float.xx), _Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2); - float2 _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2; - Unity_Multiply_float2_float2(_Multiply_3c495cf8a17a4f34b7ea8b9eada699b9_Out_2_Vector2, float2(2, 2), _Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2); - float _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float; - Unity_Length_float2(_Multiply_652d7baffd1c462fadecf340f33bd238_Out_2_Vector2, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float); - float _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float; - Unity_Add_float(_Multiply_3405bff6a7a3496eb4713243c90d616d_Out_2_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float); - float _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float; - Unity_Multiply_float_float(_Add_e87c1a0c194a45f38f054f3820e29b4a_Out_2_Float, 3.1415, _Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float); - float _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float; - Unity_Sine_float(_Multiply_baa6e28297fe49fdad9dab17ec258a8f_Out_2_Float, _Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float); - float _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float; - Unity_Add_float(_Sine_164d6728f4884fffa4459e444f7e5aff_Out_1_Float, 1, _Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float); - float _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float; - Unity_Divide_float(_Add_915ca48427c241539ece1b6f1ee87348_Out_2_Float, 2, _Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float); - float _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float; - Unity_Lerp_float(_Divide_ddc0b1b2021b44a4a7162192dc275208_Out_2_Float, 1, 0, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float); - float _Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3; - float3x3 _NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_943e679438594e14bf445a387d221ded_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_World_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_ef28928f1bd149fc981786d78214e6e6_Out_0_Float,_NormalFromHeight_943e679438594e14bf445a387d221ded_Position,_NormalFromHeight_943e679438594e14bf445a387d221ded_TangentMatrix, _NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3); - float _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float = _FresPower; - float _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float; - Unity_FresnelEffect_float(_NormalFromHeight_943e679438594e14bf445a387d221ded_Out_1_Vector3, IN.WorldSpaceViewDirection, _Property_e933a9f07f9347c997f5ce7e1ffde3dc_Out_0_Float, _FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float); - float4 _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4 = _BaseColor; - float4 _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4; - Unity_Multiply_float4_float4((_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float.xxxx), _Property_76898573631d42088d9c47eaa89b29c4_Out_0_Vector4, _Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4); - float _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float = _Emission; - float3 _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3 = Unity_HDRP_GetEmissionHDRColor_float((_Multiply_f9ece64e1f0e415eb4453524b81ba0c8_Out_2_Vector4.xyz).xyz, _Property_3665978c6c284ed9b969ca3bc3484ab3_Out_0_Float, 0); - float _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float = _CircleDest; - float _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float; - Unity_Subtract_float(_Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Length_b306b51a99aa40f28b11236ee6e50884_Out_1_Float, _Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float); - float _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float; - Unity_Maximum_float(_Subtract_eccb605d27bf4663ae0353e68d48ef23_Out_2_Float, 0, _Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float); - float _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float = _AlphaPower; - float _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float; - Unity_Power_float(_Maximum_560dee48b4f64745a97e1e9ebdbd46bf_Out_2_Float, _Property_539d5478d3094f1a82d1cd36f6d7c16a_Out_0_Float, _Power_a9d794f81b8d470689a50d0395965527_Out_2_Float); - float _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float; - Unity_Divide_float(_Power_a9d794f81b8d470689a50d0395965527_Out_2_Float, _Property_263d3431656e44dca057c9d787a74a48_Out_0_Float, _Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float); - float _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - Unity_Minimum_float(_Divide_0e797532dded4ea6a86b9951b47acb7c_Out_2_Float, 1, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float); - float _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - Unity_Multiply_float_float(_FresnelEffect_31640da69ec943aa9635bab33e06388e_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float); - float _Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float = _WaveStrength; - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3; - float3x3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); - float3 _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position = IN.WorldSpacePosition; - Unity_NormalFromHeight_Tangent_float(_Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float,_Property_07b33af0954b4a51bbafa04d162b1746_Out_0_Float,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Position,_NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_TangentMatrix, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3); - float3 _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - Unity_Lerp_float3(IN.TangentSpaceNormal, _NormalFromHeight_efcae9a0a31d4eeea0dbe6f73555f888_Out_1_Vector3, (_Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float.xxx), _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3); - float _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - Unity_Lerp_float(1, _Lerp_9fde70626aad4e64a52d1e8eb8f5c426_Out_3_Float, _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float, _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float); - float4 _Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4 = _TransColor; - surface.BaseColor = (_Property_56f24318697640b68de76d54ad04d1d2_Out_0_Vector4.xyz); - surface.Emission = _EmissionNode_efd86573d730465a8de23041525b39a4_Output_0_Vector3; - surface.Alpha = _Multiply_cbd910d7693647cf9b8d579a1355e661_Out_2_Float; - surface.BentNormal = IN.TangentSpaceNormal; - surface.Smoothness = 0.5; - surface.Occlusion = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.NormalTS = _Lerp_d1add7e31c734b038b5be09f978f8e45_Out_3_Vector3; - surface.CoatMask = _Minimum_8acd3b0d973b47ce8753c57ea9142269_Out_2_Float; - surface.RefractionIndex = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.RefractionColor = (_Property_3eda75bbf4854474ba7572025fcea7a6_Out_0_Vector4.xyz); - surface.RefractionDistance = _Lerp_06dc11b13bbe43328e6e896ccc539971_Out_3_Float; - surface.TransmissionMask = 0; - surface.Thickness = 0; - surface.DiffusionProfileHash = ((asuint(_DiffusionProfileHash) != 0) ? _DiffusionProfileHash : asfloat(uint(1082089202))); - return surface; - } - - // -------------------------------------------------- - // Build Graph Inputs - #ifdef HAVE_VFX_MODIFICATION - #define VFX_SRP_ATTRIBUTES AttributesMesh - #define VaryingsMeshType VaryingsMeshToPS - #define VFX_SRP_VARYINGS VaryingsMeshType - #define VFX_SRP_SURFACE_INPUTS FragInputs - #endif - SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) - { - SurfaceDescriptionInputs output; - ZERO_INITIALIZE(SurfaceDescriptionInputs, output); - - output.WorldSpaceNormal = normalize(input.tangentToWorld[2].xyz); - #if defined(SHADER_STAGE_RAY_TRACING) - #else - #endif - output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); - output.WorldSpaceTangent = input.tangentToWorld[0].xyz; - output.WorldSpaceBiTangent = input.tangentToWorld[1].xyz; - output.WorldSpaceViewDirection = normalize(viewWS); - output.WorldSpacePosition = input.positionRWS; - - #if UNITY_UV_STARTS_AT_TOP - #else - #endif - - - output.uv0 = input.texCoord0; - output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value - - // splice point to copy frag inputs custom interpolator pack into the SDI - /* WARNING: $splice Could not find named fragment 'CustomInterpolatorCopyToSDI' */ - - return output; - } - - // -------------------------------------------------- - // Build Surface Data (Specific Material) - - void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData); - - void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, SurfaceDescription surfaceDescription, - inout SurfaceData surfaceData) - { - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - #ifdef DECAL_NORMAL_BLENDING - // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert - // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space - float3 normalTS; - - normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(surfaceDescription.NormalTS, - fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); - - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - - GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); - #else - // normal delivered to master node - GetNormalWS(fragInputs, surfaceDescription.NormalTS, surfaceData.normalWS, doubleSidedConstants); - - #if HAVE_DECALS - if (_EnableDecals) - { - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); - ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); - ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); - } - #endif - #endif - } - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) - { - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct - // however specularOcclusion can come from the graph, so need to be init here so it can be override. - surfaceData.specularOcclusion = 1.0; - - surfaceData.baseColor = surfaceDescription.BaseColor; - surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; - surfaceData.ambientOcclusion = surfaceDescription.Occlusion; - surfaceData.transmissionMask = surfaceDescription.TransmissionMask; - surfaceData.thickness = surfaceDescription.Thickness; - surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); - surfaceData.coatMask = surfaceDescription.CoatMask; - - #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) - if (_EnableSSRefraction) - { - surfaceData.ior = surfaceDescription.RefractionIndex; - surfaceData.transmittanceColor = surfaceDescription.RefractionColor; - surfaceData.atDistance = surfaceDescription.RefractionDistance; - - surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); - surfaceDescription.Alpha = 1.0; - } - else - { - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - surfaceDescription.Alpha = 1.0; - } - #else - surfaceData.ior = 1.0; - surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); - surfaceData.atDistance = 1.0; - surfaceData.transmittanceMask = 0.0; - #endif - - // These static material feature allow compile time optimization - surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; - #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; - #endif - - #ifdef _MATERIAL_FEATURE_TRANSMISSION - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; - #endif - - #ifdef _MATERIAL_FEATURE_ANISOTROPY - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; - - // Initialize the normal to something non-zero to avoid a div-zero warning for anisotropy. - surfaceData.normalWS = float3(0, 1, 0); - #endif - - #ifdef _MATERIAL_FEATURE_IRIDESCENCE - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; - #endif - - #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; - #endif - - #ifdef _MATERIAL_FEATURE_CLEAR_COAT - surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; - #endif - - #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) - // Require to have setup baseColor - // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it - surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); - #endif - - float3 doubleSidedConstants = GetDoubleSidedConstants(); - - ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, surfaceData); - - surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; - - 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 - - - bentNormalWS = surfaceData.normalWS; - - surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); - - #ifdef DEBUG_DISPLAY - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO: need to update mip info - surfaceData.metallic = 0; - } - - // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData - // as it can modify attribute use for static lighting - ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); - #endif - - // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. - // If user provide bent normal then we process a better term - #if defined(_SPECULAR_OCCLUSION_CUSTOM) - // Just use the value passed through via the slot (not active otherwise) - #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) - // If we have bent normal and ambient occlusion, process a specular occlusion - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) - surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif - - #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) - surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); - #endif - } - - // -------------------------------------------------- - // Get Surface And BuiltinData - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - // Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD) - #if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) - #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group - LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); - #endif - #endif - - #ifndef SHADER_UNLIT - #ifdef _DOUBLESIDED_ON - float3 doubleSidedConstants = _DoubleSidedConstants.xyz; - #else - float3 doubleSidedConstants = float3(1.0, 1.0, 1.0); - #endif - - ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants); // Apply double sided flip on the vertex normal - #endif // SHADER_UNLIT - - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - - #if defined(HAVE_VFX_MODIFICATION) - GraphProperties properties; - ZERO_INITIALIZE(GraphProperties, properties); - - GetElementPixelProperties(fragInputs, properties); - - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs, properties); - #else - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - #endif - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - #ifdef _ALPHATEST_ON - float alphaCutoff = surfaceDescription.AlphaClipThreshold; - #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS - // The TransparentDepthPrepass is also used with SSR transparent. - // If an artists enable transaprent SSR but not the TransparentDepthPrepass itself, then we use AlphaClipThreshold - // otherwise if TransparentDepthPrepass is enabled we use AlphaClipThresholdDepthPrepass - #elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS - // DepthPostpass always use its own alpha threshold - alphaCutoff = surfaceDescription.AlphaClipThresholdDepthPostpass; - #elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY) - // If use shadow threshold isn't enable we don't allow any test - #endif - - GENERIC_ALPHA_TEST(surfaceDescription.Alpha, alphaCutoff); - #endif - - #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON - ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); - #endif - - #ifndef SHADER_UNLIT - float3 bentNormalWS; - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); - - #ifdef FRAG_INPUTS_USE_TEXCOORD1 - float4 lightmapTexCoord1 = fragInputs.texCoord1; - #else - float4 lightmapTexCoord1 = float4(0,0,0,0); - #endif - - #ifdef FRAG_INPUTS_USE_TEXCOORD2 - float4 lightmapTexCoord2 = fragInputs.texCoord2; - #else - float4 lightmapTexCoord2 = float4(0,0,0,0); - #endif - - float alpha = 1.0; - alpha = surfaceDescription.Alpha; - - // Builtin Data - // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], lightmapTexCoord1, lightmapTexCoord2, builtinData); - - #else - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - ZERO_BUILTIN_INITIALIZE(builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - - #if defined(DEBUG_DISPLAY) - // Light Layers are currently not used for the Unlit shader (because it is not lit) - // But Unlit objects do cast shadows according to their rendering layer mask, which is what we want to - // display in the light layers visualization mode, therefore we need the renderingLayers - builtinData.renderingLayers = GetMeshRenderingLayerMask(); - #endif - - #endif // SHADER_UNLIT - - #ifdef _ALPHATEST_ON - // 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) - builtinData.alphaClipTreshold = alphaCutoff; - #endif - - // override sampleBakedGI - not used by Unlit - // When overriding GI, we need to force the isLightmap flag to make sure we don't add APV (sampled in the lightloop) on top of the overridden value (set at GBuffer stage) - - builtinData.emissiveColor = surfaceDescription.Emission; - - // Note this will not fully work on transparent surfaces (can check with _SURFACE_TYPE_TRANSPARENT define) - // We will always overwrite vt feeback with the nearest. So behind transparent surfaces vt will not be resolved - // This is a limitation of the current MRT approach. - #ifdef UNITY_VIRTUAL_TEXTURING - #endif - - #ifdef LINE_RENDERING_OFFSCREEN_SHADING - #endif - - #if _DEPTHOFFSET_ON - builtinData.depthOffset = surfaceDescription.DepthOffset; - #endif - - // TODO: We should generate distortion / distortionBlur for non distortion pass - #if (SHADERPASS == SHADERPASS_DISTORTION) - builtinData.distortion = surfaceDescription.Distortion; - builtinData.distortionBlur = surfaceDescription.DistortionBlur; - #endif - - #ifndef SHADER_UNLIT - // PostInitBuiltinData call ApplyDebugToBuiltinData - PostInitBuiltinData(V, posInput, surfaceData, builtinData); - #else - ApplyDebugToBuiltinData(builtinData); - #endif - - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl" - - // -------------------------------------------------- - // Visual Effect Vertex Invocations - - #ifdef HAVE_VFX_MODIFICATION - #if !defined(SHADER_STAGE_RAY_TRACING) - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl" - #else - #endif - #endif - - ENDHLSL - } - } - CustomEditor "UnityEditor.ShaderGraph.GenericShaderGraphMaterialGUI" - CustomEditorForRenderPipeline "Rendering.HighDefinition.LitShaderGraphGUI" "UnityEngine.Rendering.HighDefinition.HDRenderPipelineAsset" - FallBack "Hidden/Shader Graph/FallbackError" -} \ No newline at end of file diff --git a/Assets/LRC/Material/HDRP_Shader/effect2d/Decal_CircleWave_SD.shader.meta b/Assets/LRC/Material/HDRP_Shader/effect2d/Decal_CircleWave_SD.shader.meta deleted file mode 100644 index 20c3351..0000000 --- a/Assets/LRC/Material/HDRP_Shader/effect2d/Decal_CircleWave_SD.shader.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 1e66c07de2a0cfe42a2e16acdeaf746f -ShaderImporter: - externalObjects: {} - defaultTextures: [] - nonModifiableTextures: [] - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scenes/PrefabEditingSceneOld.unity b/Assets/Scenes/PrefabEditingSceneOld.unity index 3c19739..02b954d 100644 --- a/Assets/Scenes/PrefabEditingSceneOld.unity +++ b/Assets/Scenes/PrefabEditingSceneOld.unity @@ -15438,6 +15438,7 @@ GameObject: - component: {fileID: 1688701447} - component: {fileID: 1688701446} - component: {fileID: 1688701445} + - component: {fileID: 1688701449} m_Layer: 5 m_Name: ScreenUI m_TagString: Untagged @@ -15476,7 +15477,7 @@ MonoBehaviour: m_EditorClassIdentifier: m_UiScaleMode: 0 m_ReferencePixelsPerUnit: 100 - m_ScaleFactor: 1 + m_ScaleFactor: 1.3335 m_ReferenceResolution: {x: 800, y: 600} m_ScreenMatchMode: 0 m_MatchWidthOrHeight: 0 @@ -15532,6 +15533,18 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 0} +--- !u!114 &1688701449 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1688701444} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5e5e480bc8648214891d46b029219a27, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1698402854 GameObject: m_ObjectHideFlags: 0 @@ -15659,10 +15672,10 @@ RectTransform: m_Father: {fileID: 1688701448} m_RootOrder: -1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 100, y: 100} + m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &1735197394 GameObject: @@ -20716,11 +20729,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8776649617763594622, guid: 3b24ed8660d71c94aa2c7b0633e2dedc, type: 3} propertyPath: m_SizeDelta.x - value: 1820 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8776649617763594622, guid: 3b24ed8660d71c94aa2c7b0633e2dedc, type: 3} propertyPath: m_SizeDelta.y - value: 980 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8776649617763594622, guid: 3b24ed8660d71c94aa2c7b0633e2dedc, type: 3} propertyPath: m_LocalPosition.x diff --git a/Packages/manifest.json b/Packages/manifest.json index ad08c14..96fb637 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -2,6 +2,7 @@ "dependencies": { "com.lrss3.debugdimensiondrawindicator": "file:F:/AllProject/QTZProject/QTZTool/com.lrss3.debugdimensiondrawindicator-0.1.110-1/com.lrss3.debugdimensiondrawindicator-0.1.110/package", "com.lrss3.xericlibrary": "file:F:/AllProject/QTZProject/QTZTool/com.lrss3.xericlibrary-0.2.414/package", + "com.unity.addressables": "1.20.5", "com.unity.cinemachine": "2.9.5", "com.unity.collab-proxy": "2.1.0", "com.unity.feature.development": "1.0.1", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 2ea6d81..e44cce6 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -12,6 +12,20 @@ "source": "embedded", "dependencies": {} }, + "com.unity.addressables": { + "version": "1.20.5", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.scriptablebuildpipeline": "1.20.2", + "com.unity.modules.assetbundle": "1.0.0", + "com.unity.modules.imageconversion": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.unitywebrequestassetbundle": "1.0.0" + }, + "url": "https://packages.unity.com" + }, "com.unity.burst": { "version": "1.7.4", "depth": 1, @@ -158,6 +172,13 @@ "com.unity.render-pipelines.core": "13.1.9" } }, + "com.unity.scriptablebuildpipeline": { + "version": "1.20.2", + "depth": 1, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.com" + }, "com.unity.searcher": { "version": "4.9.2", "depth": 2,