2021-09-09 20:42:29 -04:00

134 lines
4.5 KiB
Plaintext

${VFXBegin:VFXPassDepth}"DepthForwardOnly"${VFXEnd}
${VFXBegin:VFXPassForward}"ForwardOnly"${VFXEnd}
${VFXBegin:VFXPassShadow}"ShadowCaster"${VFXEnd}
${VFXBegin:VFXPassVelocity}"MotionVectors"${VFXEnd}
${VFXBegin:VFXPassDepthDefine}#define SHADERPASS SHADERPASS_DEPTH_ONLY${VFXEnd}
${VFXBegin:VFXPassForwardDefine}#define SHADERPASS SHADERPASS_FORWARD_UNLIT${VFXEnd}
${VFXBegin:VFXPassShadowDefine}#define SHADERPASS SHADERPASS_SHADOWS${VFXEnd}
${VFXBegin:VFXPassVelocityDefine}#define SHADERPASS SHADERPASS_MOTION_VECTORS${VFXEnd}
${VFXBegin:VFXPassDepthAdditionalPragma}#pragma multi_compile _ WRITE_MSAA_DEPTH${VFXEnd}
${VFXBegin:VFXPassForwardAdditionalPragma}#pragma multi_compile _ DEBUG_DISPLAY${VFXEnd}
${VFXBegin:VFXPassVelocityAdditionalPragma}#pragma multi_compile _ WRITE_MSAA_DEPTH${VFXEnd}
${VFXBegin:VFXShaderGraphFunctionsInclude}
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinGIUtilities.hlsl"
#ifndef SHADERPASS
#error Shaderpass should be defined at this stage.
#endif
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
${VFXEnd}
${VFXBegin:VFXPassDepthCommonFragmentLit}
#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR
${VFXPassVelocityDefine}
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_SHADOW
${VFXPassShadowDefine}
#else
${VFXPassDepthDefine}
#endif
${VFXIncludeRP("VFXLit.template")}
${SHADERGRAPH_PIXEL_CODE_DEPTHONLY}
#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION
int _ObjectId;
int _PassValue;
#endif
#pragma fragment frag
void frag(ps_input i
#if USE_DOUBLE_SIDED
, bool frontFace : SV_IsFrontFace
#endif
#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR
#ifdef WRITE_MSAA_DEPTH
// We need the depth color as SV_Target0 for alpha to coverage
, out float4 outDepthColor : SV_Target0
, out float4 outMotionVector : SV_Target1
#ifdef WRITE_NORMAL_BUFFER
, out float4 outNormalBuffer : SV_Target2
#endif
#else
// When no MSAA, the motion vector is always the first buffer
, out float4 outMotionVector : SV_Target0
#ifdef WRITE_NORMAL_BUFFER
, out float4 outNormalBuffer : SV_Target1
#endif
#endif
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL
#ifdef WRITE_MSAA_DEPTH
// We need the depth color as SV_Target0 for alpha to coverage
, out float4 outDepthColor : SV_Target0
#ifdef WRITE_NORMAL_BUFFER
, out float4 outNormalBuffer : SV_Target1
#endif
#elif defined(WRITE_NORMAL_BUFFER)
, out float4 outNormalBuffer : SV_Target0
#endif
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION
, out float4 outColor : SV_Target0
#endif
)
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
VFXTransformPSInputs(i);
${VFXComputeNormalWS}
#ifdef VFX_SHADERGRAPH
${VFXAdditionalInterpolantsPreparation}
${SHADERGRAPH_PIXEL_CALL_DEPTHONLY}
float alpha = OUTSG.${SHADERGRAPH_PARAM_ALPHA};
#else
float alpha = VFXGetFragmentColor(i).a;
#if HDRP_USE_BASE_COLOR_MAP_ALPHA
alpha *= VFXGetTextureColor(VFX_SAMPLER(baseColorMap),i).a;
#endif
#endif
VFXClipFragmentColor(alpha,i);
#ifdef WRITE_NORMAL_BUFFER
#ifndef VFX_SHADERGRAPH
VFXComputePixelOutputToNormalBuffer(i,normalWS,uvData,outNormalBuffer);
#else
#if HAS_SHADERGRAPH_PARAM_NORMAL
float3 n = OUTSG.Normal_8;
normalWS = mul(n,tbn);
#endif
SurfaceData surface = (SurfaceData)0;
surface.normalWS = normalWS;
EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surface), outNormalBuffer);
#endif
#endif
#ifdef WRITE_MSAA_DEPTH
outDepthColor = i.VFX_VARYING_POSCS.z;
#if VFX_USE_ALPHA_TO_MASK
outDepthColor.a = alpha;
#endif
#endif
#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR
${VFXComputeOutputMotionVector}
outMotionVector = encodedMotionVector;
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION
// We use depth prepass for scene selection in the editor, this code allow to output the outline correctly
outColor = float4(_ObjectId, _PassValue, 1.0, 1.0);
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL
//void
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_SHADOW
//void
#else
#error VFX_PASSDEPTH undefined
#endif
}
${VFXEnd}