Added HLSL shaders for mesh shading sample

This commit is contained in:
Sascha Willems 2023-06-08 16:50:12 +02:00
parent 8a686e0380
commit 18012268ed
6 changed files with 84 additions and 0 deletions

View file

@ -0,0 +1,15 @@
/* Copyright (c) 2023, Sascha Willems
*
* SPDX-License-Identifier: MIT
*
*/
struct VSOutput
{
[[vk::location(0)]] float4 color : COLOR0;
};
float4 main(VSOutput input) : SV_TARGET
{
return float4(input.color);
}

Binary file not shown.

View file

@ -0,0 +1,50 @@
/* Copyright (c) 2023, Sascha Willems
*
* SPDX-License-Identifier: MIT
*
*/
struct UBO
{
float4x4 projection;
float4x4 model;
float4x4 view;
};
cbuffer ubo : register(b0) { UBO ubo; }
struct VertexOutput
{
float4 position: SV_Position;
float4 color: COLOR0;
};
static const float4 positions[3] = {
float4( 0.0, -1.0, 0.0, 1.0),
float4(-1.0, 1.0, 0.0, 1.0),
float4( 1.0, 1.0, 0.0, 1.0)
};
static const float4 colors[3] = {
float4(0.0, 1.0, 0.0, 1.0),
float4(0.0, 0.0, 1.0, 1.0),
float4(1.0, 0.0, 0.0, 1.0)
};
[outputtopology("triangle")]
[numthreads(1, 1, 1)]
void main(out indices uint3 triangles[1], out vertices VertexOutput vertices[3], uint3 DispatchThreadID : SV_DispatchThreadID)
{
float4x4 mvp = mul(ubo.projection, mul(ubo.view, ubo.model));
float4 offset = float4(0.0, 0.0, (float)DispatchThreadID, 0.0);
SetMeshOutputCounts(3, 1);
for (uint i = 0; i < 3; i++) {
vertices[i].position = mul(mvp, positions[i] + offset);
vertices[i].color = colors[i];
}
SetMeshOutputCounts(3, 1);
triangles[0] = uint3(0, 1, 2);
}

Binary file not shown.

View file

@ -0,0 +1,19 @@
/* Copyright (c) 2023, Sascha Willems
*
* SPDX-License-Identifier: MIT
*
*/
struct DummyPayLoad
{
uint dummyData;
};
// We don't use pay loads in this sample, but the fn call requires one
groupshared DummyPayLoad dummyPayLoad;
[numthreads(1,1,1)]
void main()
{
DispatchMesh(3, 1, 1, dummyPayLoad);
}

Binary file not shown.