84 lines
3.0 KiB
Plaintext
84 lines
3.0 KiB
Plaintext
|
#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/PostProcessing/Shaders/PostProcessDefines.hlsl"
|
||
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/DepthOfFieldCommon.hlsl"
|
||
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingSampling.hlsl"
|
||
|
|
||
|
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
|
||
|
|
||
|
#pragma kernel KMain
|
||
|
|
||
|
#pragma multi_compile _ ENABLE_ALPHA
|
||
|
#pragma multi_compile _ FORCE_POINT_SAMPLING
|
||
|
|
||
|
#define GROUP_RES 8u
|
||
|
#define GROUP_SIZE (GROUP_RES * GROUP_RES)
|
||
|
|
||
|
CBUFFER_START(cb0)
|
||
|
float4 _Params;
|
||
|
float4 _Params2;
|
||
|
CBUFFER_END
|
||
|
|
||
|
#define NumRings _Params.x
|
||
|
#define MaxCoCRadius _Params.y
|
||
|
#define Anamorphism _Params.z
|
||
|
|
||
|
// Out-of-focus areas, computed at lower res
|
||
|
TEXTURE2D_X(_InputNearTexture);
|
||
|
|
||
|
// Here we write the final output
|
||
|
RW_TEXTURE2D_X(CTYPE, _OutputTexture);
|
||
|
|
||
|
#define ResScale 1.0f
|
||
|
#define OneOverResScale 1.0f
|
||
|
#define MaxColorMip 0.0f
|
||
|
#define AdaptiveSamplingWeights _Params2.xy
|
||
|
#define BlurResolution _Params2.z
|
||
|
#define InvBlurResolution _Params2.w
|
||
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/DoFGatherUtils.hlsl"
|
||
|
|
||
|
[numthreads(GROUP_RES, GROUP_RES, 1)]
|
||
|
void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||
|
{
|
||
|
UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z);
|
||
|
|
||
|
PositionInputs posInputs = GetPositionInput(float2(dispatchThreadId.xy), _PostProcessScreenSize.zw, uint2(GROUP_RES, GROUP_RES));
|
||
|
|
||
|
CTYPE output = 0;
|
||
|
|
||
|
int tileClass = GetTileClass(posInputs.positionSS);
|
||
|
|
||
|
if (tileClass == SLOW_INFOCUS_TILE)
|
||
|
{
|
||
|
SampleData centerSample;
|
||
|
centerSample.color = GetColorSample(posInputs.positionSS, 0);
|
||
|
centerSample.CoC = GetCoCRadius(posInputs.positionSS);
|
||
|
|
||
|
DoFTile tileData;
|
||
|
LoadTileData(posInputs.positionSS, centerSample, NumRings, tileData);
|
||
|
|
||
|
float4 outColor;
|
||
|
float outAlpha;
|
||
|
DoFGatherRings(posInputs, tileData, centerSample, outColor, outAlpha);
|
||
|
output.xyz = outColor.xyz;
|
||
|
#ifdef ENABLE_ALPHA
|
||
|
ComposeAlpha(output, centerSample.color.xyz, outAlpha);
|
||
|
#endif
|
||
|
}
|
||
|
else if (tileClass == FAST_DEFOCUS_TILE)
|
||
|
{
|
||
|
float2 uv = (posInputs.positionSS + 0.5) * _PostProcessScreenSize.zw;
|
||
|
uv = ClampAndScaleUV(uv, _PostProcessScreenSize.zw * BlurResolution, 0.5f, _RTHandlePostProcessScale.xy);
|
||
|
output = SAMPLE_TEXTURE2D_X_LOD(_InputNearTexture, s_linear_clamp_sampler, uv, 0.0).CTYPE_SWIZZLE;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
output = GetColorSample(posInputs.positionSS, 0);
|
||
|
}
|
||
|
|
||
|
// Helper function to visualize tile types in case it is needed for debugging
|
||
|
//DebugTiles(posInputs.positionSS, output.xyz);
|
||
|
|
||
|
_OutputTexture[COORD_TEXTURE2D_X(posInputs.positionSS)] = (CTYPE)output;
|
||
|
}
|