102 lines
3.8 KiB
Plaintext
102 lines
3.8 KiB
Plaintext
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Filtering.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
|
|
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
|
|
|
|
#pragma kernel KMain
|
|
|
|
#pragma multi_compile LOW_QUALITY HIGH_QUALITY FULL_RES
|
|
#pragma multi_compile _ FAR
|
|
#pragma multi_compile _ NEAR
|
|
#pragma multi_compile _ ENABLE_ALPHA
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/PostProcessDefines.hlsl"
|
|
|
|
TEXTURE2D_X(_InputTexture);
|
|
TEXTURE2D_X(_InputNearTexture);
|
|
TEXTURE2D_X(_InputNearAlphaTexture);
|
|
TEXTURE2D_X(_InputFarTexture);
|
|
TEXTURE2D_X(_InputCoCTexture);
|
|
|
|
RW_TEXTURE2D_X(CTYPE, _OutputTexture);
|
|
|
|
SAMPLER(sampler_LinearClamp);
|
|
|
|
CBUFFER_START(cb0)
|
|
float4 _TargetScale;
|
|
CBUFFER_END
|
|
|
|
#define GROUP_SIZE 8
|
|
|
|
[numthreads(GROUP_SIZE, GROUP_SIZE, 1)]
|
|
void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
|
|
{
|
|
UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z);
|
|
|
|
PositionInputs posInputs = GetPositionInput(float2(dispatchThreadId.xy), _ScreenSize.zw, uint2(GROUP_SIZE, GROUP_SIZE));
|
|
float2 uv = posInputs.positionNDC * _RTHandleScale.xy;
|
|
|
|
CTYPE outColor = LOAD_TEXTURE2D_X(_InputTexture, posInputs.positionSS).CTYPE_SWIZZLE;
|
|
CTYPE originalColor = outColor;
|
|
|
|
float4 bicubicWnd = float4(_ScreenSize.xy * _TargetScale.y * rcp(_RTHandleScale.xy), 1.0 / (_ScreenSize.xy * _TargetScale.y* rcp(_RTHandleScale.xy)));
|
|
|
|
// Avoid bleeding with the RTHandle autosize system
|
|
float2 maxCoord = (_RTHandleScale.xy - bicubicWnd.zw);
|
|
uv = min(uv, maxCoord);
|
|
// Blend the far layer first
|
|
|
|
#if FAR
|
|
{
|
|
CTYPE dstColor = 0.0;
|
|
float dstAlpha = 1.0;
|
|
|
|
// Fullscreen CoC
|
|
float coc = LOAD_TEXTURE2D_X(_InputCoCTexture, posInputs.positionSS).x;
|
|
|
|
if (coc > 0.0)
|
|
{
|
|
#if FULL_RES
|
|
CTYPE farColor = LOAD_TEXTURE2D_X(_InputFarTexture, posInputs.positionSS).CTYPE_SWIZZLE;
|
|
#elif HIGH_QUALITY
|
|
CTYPE farColor = SampleTexture2DBicubic(TEXTURE2D_X_ARGS(_InputFarTexture, sampler_LinearClamp), uv, bicubicWnd, maxCoord, unity_StereoEyeIndex).CTYPE_SWIZZLE;
|
|
#else
|
|
CTYPE farColor = SAMPLE_TEXTURE2D_X_LOD(_InputFarTexture, sampler_LinearClamp, uv, 0.0).CTYPE_SWIZZLE;
|
|
#endif
|
|
|
|
// Non-linear blend
|
|
// "CryEngine 3 Graphics Gems" [Sousa13]
|
|
float blend = sqrt(coc * FOUR_PI);
|
|
dstColor = farColor * saturate(blend);
|
|
dstAlpha = saturate(1.0 - blend);
|
|
}
|
|
outColor = outColor * dstAlpha + dstColor;
|
|
}
|
|
#endif
|
|
|
|
// Then the near layer
|
|
#if NEAR
|
|
{
|
|
#if FULL_RES
|
|
CTYPE nearColor = LOAD_TEXTURE2D_X(_InputNearTexture, posInputs.positionSS).CTYPE_SWIZZLE;
|
|
float alpha = LOAD_TEXTURE2D_X(_InputNearAlphaTexture, posInputs.positionSS).x;
|
|
#elif HIGH_QUALITY
|
|
CTYPE nearColor = SampleTexture2DBicubic(TEXTURE2D_X_ARGS(_InputNearTexture, sampler_LinearClamp), uv, bicubicWnd, maxCoord, unity_StereoEyeIndex).CTYPE_SWIZZLE;
|
|
float alpha = SampleTexture2DBicubic(TEXTURE2D_X_ARGS(_InputNearAlphaTexture, sampler_LinearClamp), uv, bicubicWnd, maxCoord, unity_StereoEyeIndex).x;
|
|
#else
|
|
CTYPE nearColor = SAMPLE_TEXTURE2D_X_LOD(_InputNearTexture, sampler_LinearClamp, uv, 0.0).CTYPE_SWIZZLE;
|
|
float alpha = SAMPLE_TEXTURE2D_X_LOD(_InputNearAlphaTexture, sampler_LinearClamp, uv, 0.0).x;
|
|
#endif
|
|
|
|
outColor = lerp(outColor, nearColor, alpha);
|
|
}
|
|
#endif
|
|
|
|
#ifdef ENABLE_ALPHA
|
|
// Preserve the original value of the pixels with zero alpha
|
|
outColor.xyz = outColor.a > 0 ? outColor.xyz : originalColor.xyz;
|
|
#endif
|
|
_OutputTexture[COORD_TEXTURE2D_X(posInputs.positionSS)] = outColor;
|
|
}
|