48 lines
1.8 KiB
Plaintext
48 lines
1.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
|
|
|
|
TEXTURE2D_X(_InputLowTexture);
|
|
TEXTURE2D_X(_InputHighTexture);
|
|
|
|
RW_TEXTURE2D_X(float3, _OutputTexture);
|
|
|
|
CBUFFER_START(cb0)
|
|
float4 _Params; // x: scatter, yzw: unused
|
|
float4 _BloomBicubicParams; // xy: low src size, zw: low src texel size
|
|
float4 _TexelSize; // xy; high src size, zw: high src texel size
|
|
CBUFFER_END
|
|
|
|
#define Scatter _Params.x
|
|
|
|
#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), _TexelSize.zw, uint2(GROUP_SIZE, GROUP_SIZE));
|
|
float2 uv = ClampAndScaleUV(posInputs.positionNDC, _BloomBicubicParams.zw, 1.0f);
|
|
float3 highRes = LOAD_TEXTURE2D_X(_InputHighTexture, clamp(posInputs.positionSS, 0, _TexelSize.xy - 1)).xyz;
|
|
|
|
#if LOW_QUALITY
|
|
float3 lowRes = SAMPLE_TEXTURE2D_X_LOD(_InputLowTexture, s_linear_clamp_sampler, uv, 0.0).xyz;
|
|
#else // HIGH_QUALITY
|
|
float2 maxCoord = (1.0f - _TexelSize.zw) * _RTHandleScale.xy;
|
|
float3 lowRes = SampleTexture2DBicubic(TEXTURE2D_X_ARGS(_InputLowTexture, s_linear_clamp_sampler), uv, _BloomBicubicParams, maxCoord, unity_StereoEyeIndex).xyz;
|
|
#endif
|
|
|
|
float3 output = lerp(highRes, lowRes, Scatter);
|
|
|
|
// Guard bands
|
|
output *= all(dispatchThreadId.xy <= uint2(_TexelSize.xy));
|
|
|
|
_OutputTexture[COORD_TEXTURE2D_X(dispatchThreadId.xy)] = output;
|
|
}
|