Added HLSL shaders for mesh shading sample
This commit is contained in:
parent
8a686e0380
commit
18012268ed
6 changed files with 84 additions and 0 deletions
15
shaders/hlsl/meshshader/meshshader.frag
Normal file
15
shaders/hlsl/meshshader/meshshader.frag
Normal 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);
|
||||
}
|
||||
BIN
shaders/hlsl/meshshader/meshshader.frag.spv
Normal file
BIN
shaders/hlsl/meshshader/meshshader.frag.spv
Normal file
Binary file not shown.
50
shaders/hlsl/meshshader/meshshader.mesh
Normal file
50
shaders/hlsl/meshshader/meshshader.mesh
Normal 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);
|
||||
}
|
||||
BIN
shaders/hlsl/meshshader/meshshader.mesh.spv
Normal file
BIN
shaders/hlsl/meshshader/meshshader.mesh.spv
Normal file
Binary file not shown.
19
shaders/hlsl/meshshader/meshshader.task
Normal file
19
shaders/hlsl/meshshader/meshshader.task
Normal 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);
|
||||
}
|
||||
BIN
shaders/hlsl/meshshader/meshshader.task.spv
Normal file
BIN
shaders/hlsl/meshshader/meshshader.task.spv
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue