UnityGame/Library/PackageCache/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UnlitGBufferPass.hlsl

77 lines
2.6 KiB
HLSL
Raw Normal View History

2024-10-27 10:53:47 +03:00
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unlit.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityGBuffer.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl"
void InitializeInputData(Varyings input, out InputData inputData)
{
inputData = (InputData)0;
// InputData is only used for DebugDisplay purposes in Unlit, so these are not initialized.
#if defined(DEBUG_DISPLAY)
inputData.positionWS = input.positionWS;
inputData.positionCS = input.positionCS;
inputData.normalWS = NormalizeNormalPerPixel(input.normalWS);
#else
inputData.positionWS = half3(0, 0, 0);
inputData.normalWS = NormalizeNormalPerPixel(input.normalWS);
inputData.viewDirectionWS = half3(0, 0, 1);
#endif
inputData.shadowCoord = 0;
inputData.fogCoord = 0;
inputData.vertexLighting = half3(0, 0, 0);
inputData.bakedGI = half3(0, 0, 0);
inputData.normalizedScreenSpaceUV = 0;
inputData.shadowMask = half4(1, 1, 1, 1);
}
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
output = BuildVaryings(input);
PackedVaryings packedOutput = PackVaryings(output);
return packedOutput;
}
FragmentOutput frag(PackedVaryings packedInput)
{
Varyings unpacked = UnpackVaryings(packedInput);
UNITY_SETUP_INSTANCE_ID(unpacked);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
SurfaceDescription surfaceDescription = BuildSurfaceDescription(unpacked);
SurfaceData surfaceData = (SurfaceData)0;
surfaceData.alpha = 1;
#if defined(_ALPHATEST_ON)
surfaceData.alpha = AlphaDiscard(surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold);
#endif
#if defined(LOD_FADE_CROSSFADE) && USE_UNITY_CROSSFADE
LODFadeCrossFade(unpacked.positionCS);
#endif
#if defined(_ALPHAMODULATE_ON)
surfaceData.albedo = AlphaModulate(surfaceDescription.BaseColor, surfaceData.alpha);
#else
surfaceData.albedo = surfaceDescription.BaseColor;
#endif
#if defined(_DBUFFER)
ApplyDecalToBaseColor(unpacked.positionCS, surfaceData.albedo);
#endif
InputData inputData;
InitializeInputData(unpacked, inputData);
#if defined(_SCREEN_SPACE_OCCLUSION) && !defined(_SURFACE_TYPE_TRANSPARENT)
float2 normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(unpacked.positionCS);
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(normalizedScreenSpaceUV);
surfaceData.albedo.rgb *= aoFactor.directAmbientOcclusion;
#else
surfaceData.occlusion = 1;
#endif
return SurfaceDataToGbuffer(surfaceData, inputData, float3(0,0,0), kLightingInvalid);
}