Files
Seele/res/shaders/DepthMipGen.slang
T

56 lines
1.6 KiB
Plaintext
Raw Normal View History

2024-06-17 16:21:41 +02:00
import Common;
2024-08-29 11:23:55 +02:00
import DepthCommon;
2024-06-17 16:21:41 +02:00
ParameterBlock<DepthData> pDepthAttachment;
struct MipParam
{
2024-09-07 11:15:47 +02:00
uint sourceOffset;
uint destOffset;
uint2 sourceDim;
uint2 destDim;
2024-06-17 16:21:41 +02:00
}
2024-06-20 21:57:26 +02:00
layout(push_constant)
2024-06-17 16:21:41 +02:00
ConstantBuffer<MipParam> pMipParam;
2024-09-07 11:15:47 +02:00
float readBuffer(uint2 pos)
2024-06-17 16:21:41 +02:00
{
2024-09-07 11:15:47 +02:00
if(pos.x >= pMipParam.sourceDim.x || pos.y >= pMipParam.sourceDim.y)
{
return 1.0f;
}
return pDepthAttachment.buffer[pMipParam.sourceOffset + pos.x + (pos.y * pMipParam.sourceDim.x)];
2024-06-17 16:21:41 +02:00
}
[shader("compute")]
2024-09-07 11:15:47 +02:00
[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)]
2024-06-17 16:21:41 +02:00
void reduceLevel(
2024-09-07 11:15:47 +02:00
uint2 dispatchID: SV_DispatchThreadID,
) {
if(dispatchID.x >= pMipParam.destDim.x || dispatchID.y >= pMipParam.destDim.y)
2024-06-17 16:21:41 +02:00
{
return;
}
2024-09-07 11:15:47 +02:00
uint2 readOffset = dispatchID * 2;
float d0 = readBuffer(readOffset + uint2(0, 0));
float d1 = readBuffer(readOffset + uint2(0, 1));
float d2 = readBuffer(readOffset + uint2(1, 0));
float d3 = readBuffer(readOffset + uint2(1, 1));
pDepthAttachment.buffer[pMipParam.destOffset + dispatchID.x + (dispatchID.y * pMipParam.destDim.x)] = min(min(d0, d1), min(d2, d3));
2024-06-17 16:21:41 +02:00
}
2024-09-07 11:15:47 +02:00
// each thread reduces the a pixel indivdually
// used for mip levels where the read size is smaller than
// the group dimensions
2024-06-17 16:21:41 +02:00
[shader("compute")]
2024-09-07 11:15:47 +02:00
[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)]
void sourceCopy(
uint2 dispatchID: SV_DispatchThreadID
2024-06-17 16:21:41 +02:00
) {
2024-09-07 11:15:47 +02:00
if(dispatchID.x >= pViewParams.screenDimensions.x || dispatchID.y >= pViewParams.screenDimensions.y)
{
return;
}
pDepthAttachment.buffer[dispatchID.x + (dispatchID.y * uint(pViewParams.screenDimensions.x))] = pDepthAttachment.texture[uint2(dispatchID)];
2024-06-17 16:21:41 +02:00
}