2023-10-09 17:20:30 +02:00
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
struct MeshPayload
|
2023-10-07 19:29:53 +02:00
|
|
|
{
|
2023-10-24 15:01:09 +02:00
|
|
|
int exponent;
|
2023-10-07 19:29:53 +02:00
|
|
|
};
|
|
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
groupshared MeshPayload payload;
|
2023-10-09 17:20:30 +02:00
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
[numthreads(1, 1, 1)]
|
|
|
|
|
[outputtopology("triangle")]
|
2023-10-09 17:20:30 +02:00
|
|
|
void taskMain(
|
|
|
|
|
uint3 threadID: SV_GroupIndex,
|
|
|
|
|
uint3 groupID: SV_GroupID
|
|
|
|
|
){
|
2023-10-24 15:01:09 +02:00
|
|
|
DispatchMesh(1,1,1,payload);
|
2023-10-09 17:20:30 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
const static float2 positions[3] = {
|
|
|
|
|
float2(0.0, -0.5),
|
|
|
|
|
float2(0.5, 0.5),
|
|
|
|
|
float2(-0.5, 0.5)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const static float3 colors[3] = {
|
|
|
|
|
float3(1.0, 1.0, 0.0),
|
|
|
|
|
float3(0.0, 1.0, 1.0),
|
|
|
|
|
float3(1.0, 0.0, 1.0)
|
|
|
|
|
};
|
|
|
|
|
struct Vertex
|
|
|
|
|
{
|
|
|
|
|
float4 pos : SV_Position;
|
|
|
|
|
float3 color : Color;
|
|
|
|
|
int index : Index;
|
|
|
|
|
int value : Value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const static uint MAX_VERTS = 12;
|
|
|
|
|
const static uint MAX_PRIMS = 4;
|
|
|
|
|
|
2023-10-09 17:20:30 +02:00
|
|
|
[outputtopology("triangle")]
|
|
|
|
|
[shader("mesh")]
|
2023-10-24 15:01:09 +02:00
|
|
|
[numthreads(12, 1, 1)]
|
2023-10-09 17:20:30 +02:00
|
|
|
void meshMain(
|
2023-10-24 15:01:09 +02:00
|
|
|
in uint tig : SV_GroupIndex,
|
|
|
|
|
in payload MeshPayload meshPayload,
|
|
|
|
|
out Vertices<Vertex, MAX_VERTS> verts,
|
|
|
|
|
out Indices<uint3, MAX_PRIMS> triangles)
|
|
|
|
|
{
|
|
|
|
|
const uint numVertices = 12;
|
|
|
|
|
const uint numPrimitives = 4;
|
|
|
|
|
SetMeshOutputCounts(numVertices, numPrimitives);
|
2023-10-09 17:20:30 +02:00
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
if(tig < numVertices)
|
|
|
|
|
{
|
|
|
|
|
const int tri = tig / 3;
|
|
|
|
|
verts[tig] = {float4(positions[tig % 3], 0, 1), colors[tig % 3], tri, int(pow(tri, meshPayload.exponent))};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(tig < numPrimitives)
|
|
|
|
|
triangles[tig] = tig * 3 + uint3(0,1,2);
|
2023-10-07 19:29:53 +02:00
|
|
|
}
|