Skip to content

Commit ec8ad58

Browse files
Samples: cleaned up Slang shaders
1 parent 4582986 commit ec8ad58

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

samples/001_HelloTriangle.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,22 @@ static const float3 col[3] = float3[3](
2222
float3(0.0, 0.0, 1.0)
2323
);
2424
25-
struct OutVertex {
26-
float3 color;
27-
};
28-
29-
struct Fragment {
30-
float4 color;
31-
};
32-
3325
struct VertexStageOutput {
34-
OutVertex vertex : OutVertex;
35-
float4 sv_position : SV_Position;
26+
float4 sv_Position : SV_Position;
27+
float3 color : COLOR0;
3628
};
3729
3830
[shader("vertex")]
3931
VertexStageOutput vertexMain(uint vertexID : SV_VertexID) {
40-
VertexStageOutput output;
41-
42-
output.vertex.color = col[vertexID];
43-
output.sv_position = float4(pos[vertexID], 0.0, 1.0);
44-
45-
return output;
32+
return {
33+
float4(pos[vertexID], 0.0, 1.0),
34+
col[vertexID],
35+
};
4636
}
4737
4838
[shader("fragment")]
49-
float4 fragmentMain(OutVertex vertex : OutVertex) : SV_Target {
50-
return float4(vertex.color, 1.0);
39+
float4 fragmentMain(float3 color : COLOR0) : SV_Target {
40+
return float4(color, 1.0);
5141
}
5242
)";
5343

samples/009_TriplanarMapping.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,28 @@ struct PushConstants {
4747
[[vk::push_constant]] PushConstants pc;
4848
4949
struct VertexStageOutput {
50-
float4 position : SV_Position;
50+
float4 sv_Position : SV_Position;
5151
float3 color;
5252
float3 normal;
5353
};
5454
5555
[shader("vertex")]
56-
void vertexMain(uint vertexID : SV_VertexID,
57-
uint instanceID : SV_InstanceID,
58-
out VertexStageOutput output)
56+
VertexStageOutput vertexMain(uint vertexID : SV_VertexID,
57+
uint instanceID : SV_InstanceID)
5958
{
6059
float4x4 proj = pc.perFrame->proj;
6160
float4x4 view = pc.perFrame->view;
6261
float4x4 model = pc.perObject->model[instanceID];
6362
6463
Vertex v = pc.vb->vertices[vertexID];
6564
66-
output.position = mul(float4(v.x, v.y, v.z, 1.0), mul(model, mul(view, proj)));
67-
output.color = float3(v.r, v.g, v.b);
68-
output.normal = normalize(float3(v.x, v.y, v.z)); // object space normal
65+
VertexStageOutput out;
66+
67+
out.sv_Position = mul(float4(v.x, v.y, v.z, 1.0), mul(model, mul(view, proj)));
68+
out.color = float3(v.r, v.g, v.b);
69+
out.normal = normalize(float3(v.x, v.y, v.z)); // object space normal
70+
71+
return out;
6972
}
7073
7174
float4 triplanar(uint tex, float3 worldPos, float3 normal) {
@@ -86,9 +89,7 @@ float4 triplanar(uint tex, float3 worldPos, float3 normal) {
8689
}
8790
8891
[shader("fragment")]
89-
float4 fragmentMain(
90-
VertexStageOutput input,
91-
float4 position : SV_Position) : SV_Target
92+
float4 fragmentMain(VertexStageOutput input) : SV_Target
9293
{
9394
// triplanar mapping in object-space; for our icosahedron, object-space position and normal vectors are the same
9495
float4 t0 = triplanar(pc.perFrame->texture0, input.normal, input.normal);

0 commit comments

Comments
 (0)