-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVBufferMS.hlsl
49 lines (40 loc) · 1.41 KB
/
VBufferMS.hlsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "ShaderCommon.hlsl"
struct PrimitiveAttributes
{
uint PackedOutput : COLOR0;
};
struct VertexAttributes
{
float4 Position : SV_Position;
};
[NumThreads(128, 1, 1)]
[OutputTopology("triangle")]
void main(
uint gtid : SV_GroupThreadID,
uint gid : SV_GroupID,
out indices uint3 tri[124],
out primitives PrimitiveAttributes prims[124],
out vertices VertexAttributes verts[64]
)
{
ByteAddressBuffer visibleInstances = ResourceDescriptorHeap[VISIBLE_INSTANCES_SRV];
ByteAddressBuffer visibleClusters = ResourceDescriptorHeap[VISIBLE_CLUSTERS_SRV];
uint packedClusterInstance = visibleClusters.Load(gid * 4);
uint clusterIndex = packedClusterInstance & 0x0000ffff;
uint visibleInstanceIndex = packedClusterInstance >> 16;
uint instanceIndex = visibleInstances.Load(visibleInstanceIndex * 4);
Cluster cluster = GetCluster(clusterIndex);
Instance instance = GetInstance(instanceIndex);
SetMeshOutputCounts(cluster.VertexCount, cluster.PrimitiveCount);
if (gtid < cluster.PrimitiveCount)
{
tri[gtid] = GetTri(cluster.PrimitiveStart + gtid);
prims[gtid].PackedOutput = (gid << 8) | (gtid & 0x000000FF);
}
if (gtid < cluster.VertexCount)
{
float3 vert = GetPosition(cluster.VertexStart + gtid);
float4 transformedVert = mul(instance.ModelMatrix, float4(vert, 1.0));
verts[gtid].Position = mul(constants.DrawingCamera.ViewProjectionMatrix, transformedVert);
}
}