72 lines
2.4 KiB
Plaintext
72 lines
2.4 KiB
Plaintext
// Each #kernel tells which function to compile; you can have many kernels
|
|
#pragma kernel KMain
|
|
#pragma kernel KMainMSAA
|
|
|
|
#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/Material/Builtin/BuiltinData.hlsl"
|
|
|
|
RW_TEXTURE2D(float4, _OutputTexture);
|
|
TEXTURE2D_X(_InputTexture);
|
|
TEXTURE2D_X_MSAA(float4, _InputTextureMSAA);
|
|
|
|
CBUFFER_START(cb0)
|
|
float4 _Params;
|
|
float4 _Params1;
|
|
CBUFFER_END
|
|
|
|
#define Scale _Params.x
|
|
#define startOffsetX _Params.y
|
|
#define startOffsetY _Params.z
|
|
#define srcWidth _Params1.x
|
|
#define srcHeight _Params1.y
|
|
#define dstWidth _Params1.z
|
|
#define dstHeight _Params1.w
|
|
|
|
|
|
static const uint TGSize = 8;
|
|
|
|
[numthreads(TGSize, TGSize, 1)]
|
|
void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
|
|
{
|
|
const uint2 samplePos = dispatchThreadId.xy;
|
|
const uint2 startOffset = uint2(startOffsetX, startOffsetY);
|
|
const uint2 offset = (startOffset + samplePos) % Scale;// startOffset jitters the offset per frame, mixing in samplePos jitters within the macroblocks in a frame
|
|
|
|
// At the edges we have a few threads due to round-up which are immediately terminated
|
|
if (samplePos.x >= (uint)dstWidth || samplePos.y >= (uint)dstHeight)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Clamp to source rect
|
|
uint2 srcPos = samplePos * Scale + offset;
|
|
srcPos.x = min(srcPos.x, (uint)srcWidth - 1);
|
|
srcPos.y = min(srcPos.y, (uint)srcHeight - 1);
|
|
|
|
float4 value = LOAD_TEXTURE2D_X(_InputTexture, srcPos);
|
|
_OutputTexture[samplePos] = value;
|
|
}
|
|
|
|
[numthreads(TGSize, TGSize, 1)]
|
|
void KMainMSAA(uint3 dispatchThreadId : SV_DispatchThreadID)
|
|
{
|
|
const uint2 samplePos = dispatchThreadId.xy;
|
|
const uint2 startOffset = uint2(startOffsetX, startOffsetY);
|
|
const uint2 offset = (startOffset + samplePos) % Scale;
|
|
|
|
// At the edges we have a few threads due to round-up which are immediately terminated
|
|
if (samplePos.x >= (uint)dstWidth || samplePos.y >= (uint)dstHeight)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Clamp to source rect
|
|
uint2 srcPos = samplePos * Scale + offset;
|
|
srcPos.x = min(srcPos.x, (uint)srcWidth - 1);
|
|
srcPos.y = min(srcPos.y, (uint)srcHeight - 1);
|
|
|
|
float4 value = LOAD_TEXTURE2D_X_MSAA(_InputTextureMSAA, srcPos, 0);
|
|
_OutputTexture[samplePos] = value;
|
|
}
|