You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

402 lines
19 KiB

Pass
{
$splice(PassName)
Tags
{
$splice(LightMode)
}
// Render State
$splice(RenderState)
// Debug
$splice(Debug)
// --------------------------------------------------
// Pass
HLSLPROGRAM
// Pragmas
$splice(PassPragmas)
// Keywords
$splice(PassKeywords)
$splice(GraphKeywords)
// Defines
$splice(GraphDefines)
// 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)
$features.graphVFX: #define HAVE_VFX_MODIFICATION
// TODO: Merge FragInputsVFX substruct with CustomInterpolators.
#ifdef HAVE_VFX_MODIFICATION
struct FragInputsVFX
{
$splice(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
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS
// 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
$AttributesMesh.normalOS: #define ATTRIBUTES_NEED_NORMAL
$AttributesMesh.tangentOS: #define ATTRIBUTES_NEED_TANGENT
$AttributesMesh.uv0: #define ATTRIBUTES_NEED_TEXCOORD0
$AttributesMesh.uv1: #define ATTRIBUTES_NEED_TEXCOORD1
$AttributesMesh.uv2: #define ATTRIBUTES_NEED_TEXCOORD2
$AttributesMesh.uv3: #define ATTRIBUTES_NEED_TEXCOORD3
$AttributesMesh.color: #define ATTRIBUTES_NEED_COLOR
$AttributesMesh.vertexID: #define ATTRIBUTES_NEED_VERTEXID
$AttributesMesh.instanceID: #define ATTRIBUTES_NEED_INSTANCEID
$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.texCoord1: #define VARYINGS_NEED_TEXCOORD1
$VaryingsMeshToPS.texCoord2: #define VARYINGS_NEED_TEXCOORD2
$VaryingsMeshToPS.texCoord3: #define VARYINGS_NEED_TEXCOORD3
$VaryingsMeshToPS.color: #define VARYINGS_NEED_COLOR
$VaryingsMeshToPS.elementToWorld0: #define VARYINGS_NEED_ELEMENT_TO_WORLD
$VaryingsMeshToPS.worldToElement0: #define VARYINGS_NEED_WORLD_TO_ELEMENT
$VaryingsMeshToPS.instanceID: #define VARYINGS_NEED_INSTANCEID
$Varyings.diffuseGIData0: #define VARYINGS_NEED_SIX_WAY_DIFFUSE_GI_DATA
$features.graphVertex: #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
$FragInputs.texCoord0: #define FRAG_INPUTS_USE_TEXCOORD0
$FragInputs.texCoord1: #define FRAG_INPUTS_USE_TEXCOORD1
$FragInputs.texCoord2: #define FRAG_INPUTS_USE_TEXCOORD2
$FragInputs.texCoord3: #define FRAG_INPUTS_USE_TEXCOORD3
$FragInputs.instanceID: #define FRAG_INPUTS_USE_INSTANCEID
$FragInputs.diffuseGIData0: #define FRAG_INPUTS_USE_SIX_WAY_DIFFUSE_GI_DATA
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
$SurfaceDescriptionInputs.FaceSign: // Define when IsFontFaceNode is included in ShaderGraph
$SurfaceDescriptionInputs.FaceSign: #define VARYINGS_NEED_CULLFACE
$VertexDescription.CustomVelocity: #define _ADD_CUSTOM_VELOCITY
$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: $VaryingsMeshToDS.instanceID: #define VARYINGS_DS_NEED_INSTANCEID
$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
// Specific Material Define
$include("ShaderPassDefine.template.hlsl")
// 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(_TRANSPARENT_REFRACTIVE_SORT)) && defined(_SURFACE_TYPE_TRANSPARENT)
#define _WRITE_TRANSPARENT_MOTION_VECTOR
#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
// Includes
$splice(PreGraphIncludes)
$splice(GraphIncludes)
// --------------------------------------------------
// Structs and Packing
$splice(PassStructs)
$splice(InterpolatorPack)
// --------------------------------------------------
// Graph
// Graph Functions
$splice(GraphFunctions)
// Graph Vertex
$splice(GraphVertex)
// Graph Pixel
$splice(GraphPixel)
// --------------------------------------------------
// 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
$features.graphVFX: $include("VFXConfig.template.hlsl")
$features.graphVertex: $include("Vertex.template.hlsl")
$features.graphTessellation: $include("Tessellation.template.hlsl")
$features.graphPixel: $include("Pixel.template.hlsl")
// --------------------------------------------------
// Build Surface Data (Specific Material)
$include("DecalCommon.template.hlsl")
$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)
{
// 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
#ifdef DEBUG_DISPLAY
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
{
$SurfaceDescription.Alpha: surfaceDescription.Alpha = 1.0f;
}
#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
$DoAlphaTestPrepass: alphaCutoff = surfaceDescription.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
$DoAlphaTestShadow: alphaCutoff = _UseShadowThreshold ? surfaceDescription.AlphaClipThresholdShadow : alphaCutoff;
#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;
$SurfaceDescription.Alpha: 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)
$LightingGI: builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI; builtinData.isLightmap = 1;
$BackLightingGI: builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI; builtinData.isLightmap = 1;
$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
// 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
$splice(PostGraphIncludes)
// --------------------------------------------------
// 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
$features.graphVFX: $RaytracingVFX: $include("IntersectionShader.template.hlsl")
#endif
#endif
ENDHLSL
}