Files
Seele/res/shaders/DepthCullingTask.slang
T

62 lines
2.3 KiB
Plaintext
Raw Normal View History

2024-05-16 19:47:35 +02:00
import Common;
import Scene;
groupshared MeshPayload p;
groupshared uint head;
2024-06-07 09:19:47 +02:00
groupshared MeshData mesh;
groupshared InstanceData instance;
groupshared Frustum viewFrustum;
ParameterBlock<Texture2D> pDepthAttachment;
2024-05-16 19:47:35 +02:00
[numthreads(TASK_GROUP_SIZE, 1, 1)]
[shader("amplification")]
void taskMain(
2024-06-07 09:19:47 +02:00
uint threadID: SV_GroupThreadID,
uint groupID: SV_GroupID, )
{
if (threadID == 0)
{
head = 0;
instance = pScene.instances[pOffsets.instanceOffset + groupID];
2024-06-07 09:19:47 +02:00
mesh = pScene.meshData[pOffsets.instanceOffset + groupID];
p.instanceId = pOffsets.instanceOffset + groupID;
p.meshletOffset = mesh.meshletOffset;
p.cullingOffset = pScene.cullingOffsets[p.instanceId];
float3 origin = viewToModel(instance.inverseTransformMatrix, float4(0, 0, 0, 1)).xyz;
const float offset = 0.0f;
float3 corners[4] = {
screenToModel(instance.inverseTransformMatrix, float4(offset, offset, -1.0f, 1.0f)).xyz,
screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions.x - offset, offset, -1.0f, 1.0f)).xyz,
screenToModel(instance.inverseTransformMatrix, float4(offset, pViewParams.screenDimensions.y - offset, -1.0f, 1.0f)).xyz,
screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions - float2(offset, offset), -1.0f, 1.0f)).xyz
};
viewFrustum.sides[0] = computePlane(origin, corners[2], corners[0]);
viewFrustum.sides[1] = computePlane(origin, corners[1], corners[3]);
viewFrustum.sides[2] = computePlane(origin, corners[0], corners[1]);
viewFrustum.sides[3] = computePlane(origin, corners[3], corners[2]);
}
GroupMemoryBarrierWithGroupSync();
for (uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE)
{
uint m = p.meshletOffset + i;
uint cull = p.cullingOffset + i;
MeshletDescription meshlet = pScene.meshletInfos[m];
2024-06-07 09:19:47 +02:00
MeshletCullingInfo culling = pScene.cullingInfos[cull];
// if any triangle was visible last frame, it was drawn by the cached pass already
if(!culling.anyVisible())
{
#ifdef VIEW_CULLING
if(meshlet.bounding.insideFrustum(viewFrustum))
#endif
{
uint index;
InterlockedAdd(head, 1, index);
p.culledMeshlets[index] = i;
}
}
}
GroupMemoryBarrierWithGroupSync();
DispatchMesh(head, 1, 1, p);
2024-05-30 16:56:22 +02:00
}