Pass { $splice(PassName) Tags { $splice(LightMode) } // Render State $splice(RenderState) // Debug $splice(Debug) // -------------------------------------------------- // Pass HLSLPROGRAM // Pragmas $splice(PassPragmas) // Keywords $splice(PassKeywords) $splice(GraphKeywords) // For custom interpolators to inject a substruct definition before FragInputs definition, // allowing for FragInputs to capture CI's intended for ShaderGraph's SDI. $splice(CustomInterpolatorPreInclude) #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/FragInputs.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 #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit_Splatmap_Includes.hlsl" // Required by terrain // -------------------------------------------------- // Defines // Attribute $AttributesMesh.normalOS: #define ATTRIBUTES_NEED_NORMAL $AttributesMesh.uv0: #define ATTRIBUTES_NEED_TEXCOORD0 $AttributesMesh.color: #define ATTRIBUTES_NEED_COLOR $AttributesMesh.vertexID: #define ATTRIBUTES_NEED_VERTEXID $VaryingsMeshToPS.positionRWS: #define VARYINGS_NEED_POSITION_WS $VaryingsMeshToPS.positionPredisplacementRWS: #define VARYINGS_NEED_POSITIONPREDISPLACEMENT_WS $VaryingsMeshToPS.normalWS: #define VARYINGS_NEED_TANGENT_TO_WORLD $VaryingsMeshToPS.texCoord0: #define VARYINGS_NEED_TEXCOORD0 $VaryingsMeshToPS.color: #define VARYINGS_NEED_COLOR $VaryingsMeshToPS.elementToWorld0: #define VARYINGS_NEED_ELEMENT_TO_WORLD $VaryingsMeshToPS.worldToElement0: #define VARYINGS_NEED_WORLD_TO_ELEMENT $features.graphVertex: #define HAVE_MESH_MODIFICATION $SurfaceDescriptionInputs.FaceSign: // Define when IsFontFaceNode is included in ShaderGraph $SurfaceDescriptionInputs.FaceSign: #define VARYINGS_NEED_CULLFACE $VertexDescription.CustomVelocity: #define _ADD_CUSTOM_VELOCITY $splice(GraphDefines) $features.graphTessellation: #ifdef TESSELLATION_ON $features.graphTessellation: // World and normal are always available $features.graphTessellation: $VaryingsMeshToDS.positionPredisplacementRWS: #define VARYINGS_DS_NEED_POSITIONPREDISPLACEMENT $features.graphTessellation: $VaryingsMeshToDS.tangentWS: #define VARYINGS_DS_NEED_TANGENT $features.graphTessellation: $VaryingsMeshToDS.texCoord0: #define VARYINGS_DS_NEED_TEXCOORD0 $features.graphTessellation: $VaryingsMeshToDS.texCoord1: #define VARYINGS_DS_NEED_TEXCOORD1 $features.graphTessellation: $VaryingsMeshToDS.texCoord2: #define VARYINGS_DS_NEED_TEXCOORD2 $features.graphTessellation: $VaryingsMeshToDS.texCoord3: #define VARYINGS_DS_NEED_TEXCOORD3 $features.graphTessellation: $VaryingsMeshToDS.color: #define VARYINGS_DS_NEED_COLOR $features.graphTessellation: #endif // 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 #ifndef HD_TERRAIN_ENABLED #ifndef UNITY_TERRAIN_CB_VARS #define UNITY_TERRAIN_CB_VARS #endif #ifndef UNITY_TERRAIN_CB_DEBUG_VARS #define UNITY_TERRAIN_CB_DEBUG_VARS #endif #endif // Caution: we can use the define SHADER_UNLIT onlit after the above Material include as it is the Unlit template who define it #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 // -- Graph Properties $splice(GraphProperties) // -- Property used by ScenePickingPass #ifdef SCENEPICKINGPASS float4 _SelectionID; #endif // -- Properties used by SceneSelectionPass #ifdef SCENESELECTIONPASS int _ObjectId; int _PassValue; #endif // -- Properties used by TerrainPass #if HD_TERRAIN_ENABLED CBUFFER_START(UnityTerrain) UNITY_TERRAIN_CB_VARS #ifdef UNITY_INSTANCING_ENABLED float4 _TerrainHeightmapRecipSize; // float4(1.0f/width, 1.0f/height, 1.0f/(width-1), 1.0f/(height-1)) float4 _TerrainHeightmapScale; // float4(hmScale.x, hmScale.y / (float)(kMaxHeight), hmScale.z, 0.0f) TEXTURE2D(_TerrainHeightmapTexture); TEXTURE2D(_TerrainNormalmapTexture); SAMPLER(sampler_TerrainNormalmapTexture); #endif // UNITY_INSTANCING_ENABLED #ifdef DEBUG_DISPLAY UNITY_TERRAIN_CB_DEBUG_VARS #endif CBUFFER_END #endif // HD_TERRAIN_ENABLED // Includes $splice(PreGraphIncludes) $splice(GraphIncludes) // Specific Material Define $include("ShaderPassDefine.template.hlsl") // -------------------------------------------------- // Structs and Packing $splice(PassStructs) $splice(InterpolatorPack) // -------------------------------------------------- // Graph // Graph Functions $splice(GraphFunctions) // Graph Vertex $splice(GraphVertex) // Graph Pixel $splice(GraphPixel) // -------------------------------------------------- // Build Graph Inputs $features.graphVertex: $include("Vertex.template.hlsl") $features.graphTessellation: $include("Tessellation.template.hlsl") $features.graphPixel: $include("Pixel.template.hlsl") // -------------------------------------------------- // Build Surface Data (Specific Material) $include("ShaderPass.template.hlsl") // -------------------------------------------------- // Get Surface And BuiltinData void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) { #ifdef ENABLE_TERRAIN_PERPIXEL_NORMAL float2 terrainNormalMapUV = (fragInputs.texCoord0.xy + 0.5f) * _TerrainHeightmapRecipSize.xy; float3 normalOS = SAMPLE_TEXTURE2D(_TerrainNormalmapTexture, sampler_TerrainNormalmapTexture, terrainNormalMapUV).rgb * 2.0 - 1.0; float3 normalWS = TransformObjectToWorldNormal(normalOS); float4 tangentOS = ConstructTerrainTangent(normalOS, float3(0.0, 0.0, 1.0)); float4 tangentWS = float4(TransformObjectToWorldNormal(tangentOS.xyz), 0.0); fragInputs.tangentToWorld = BuildTangentToWorld(tangentWS, normalWS); fragInputs.texCoord0.xy *= _TerrainHeightmapRecipSize.zw; #endif // terrain lightmap uvs are always taken from uv0 fragInputs.texCoord1 = fragInputs.texCoord2 = fragInputs.texCoord0; SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); #ifdef _TERRAIN_SG_ALPHA_CLIP half alpha = surfaceDescription.Alpha; clip(alpha - surfaceDescription.AlphaClipThreshold); #endif #if !defined(SHADER_STAGE_RAY_TRACING) && _DEPTHOFFSET_ON ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); #endif float3 bentNormalWS; BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS); // Builtin Data // For back lighting we use the oposite vertex normal InitBuiltinData(posInput, 1.0, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData); // override sampleBakedGI - not used by Unlit $LightingGI: builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI; $BackLightingGI: builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI; $SurfaceDescription.Emission: 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 $SurfaceDescription.VTPackedFeedback: builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback; #endif #if _DEPTHOFFSET_ON builtinData.depthOffset = surfaceDescription.DepthOffset; #endif // PostInitBuiltinData call ApplyDebugToBuiltinData PostInitBuiltinData(V, posInput, surfaceData, builtinData); RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS } // -------------------------------------------------- // Main $splice(PostGraphIncludes) ENDHLSL }