Skip to content

Commit 5758b53

Browse files
committed
Add slang shader for descriptor sets sample
1 parent 2c6f3bf commit 5758b53

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Copyright (c) 2025, Sascha Willems
2+
*
3+
* SPDX-License-Identifier: MIT
4+
*
5+
*/
6+
7+
struct VSInput
8+
{
9+
float3 Pos;
10+
float3 Normal;
11+
float2 UV;
12+
float3 Color;
13+
};
14+
15+
struct VSOutput
16+
{
17+
float4 Pos : SV_POSITION;
18+
float3 Normal;
19+
float3 Color;
20+
float2 UV;
21+
};
22+
23+
// Slang auto generates bindings by order of descriptors
24+
// So the UBO is bound to slot 0, the sampler to slot 1
25+
// due to their order in the shader
26+
27+
struct UBOMatrices {
28+
float4x4 projection;
29+
float4x4 view;
30+
float4x4 model;
31+
};
32+
ConstantBuffer<UBOMatrices> uboMatrices;
33+
34+
Sampler2D samplerColorMap;
35+
36+
[shader("vertex")]
37+
VSOutput vertexMain(VSInput input)
38+
{
39+
VSOutput output;
40+
output.Normal = input.Normal;
41+
output.Color = input.Color;
42+
output.UV = input.UV;
43+
output.Pos = mul(uboMatrices.projection, mul(uboMatrices.view, mul(uboMatrices.model, float4(input.Pos.xyz, 1.0))));
44+
return output;
45+
}
46+
47+
[shader("fragment")]
48+
float4 fragmentMain(VSOutput input)
49+
{
50+
return samplerColorMap.Sample(input.UV) * float4(input.Color, 1.0);
51+
}

0 commit comments

Comments
 (0)