Skip to content

Commit d6a1f6a

Browse files
committed
Add slang shaders for additional samples
1 parent 7e5a387 commit d6a1f6a

4 files changed

Lines changed: 198 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Copyright (c) 2025, Sascha Willems
2+
*
3+
* SPDX-License-Identifier: MIT
4+
*
5+
*/
6+
7+
struct VSInput
8+
{
9+
float4 Pos;
10+
float3 Color;
11+
float3 Normal;
12+
};
13+
14+
struct VSOutput
15+
{
16+
float4 Pos : SV_POSITION;
17+
}
18+
19+
struct UBO
20+
{
21+
float4x4 projection;
22+
float4x4 model;
23+
float4 lightPos;
24+
float outlineWidth;
25+
};
26+
ConstantBuffer<UBO> ubo;
27+
28+
[shader("vertex")]
29+
VSOutput vertexMain(VSInput input)
30+
{
31+
// Extrude along normal
32+
VSOutput output;
33+
float4 pos = float4(input.Pos.xyz + input.Normal * ubo.outlineWidth, input.Pos.w);
34+
output.Pos = mul(ubo.projection, mul(ubo.model, pos));
35+
return output;
36+
}
37+
38+
[shader("fragment")]
39+
float4 fragmentMain()
40+
{
41+
return float4(1.0, 1.0, 1.0, 1.0);
42+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* Copyright (c) 2025, Sascha Willems
2+
*
3+
* SPDX-License-Identifier: MIT
4+
*
5+
*/
6+
7+
struct VSInput
8+
{
9+
float3 Pos;
10+
float3 Color;
11+
float3 Normal;
12+
};
13+
14+
struct VSOutput
15+
{
16+
float4 Pos : SV_POSITION;
17+
float3 Normal;
18+
float3 Color;
19+
float3 LightVec;
20+
};
21+
22+
struct UBO
23+
{
24+
float4x4 projection;
25+
float4x4 model;
26+
float4 lightPos;
27+
};
28+
ConstantBuffer<UBO> ubo;
29+
30+
Sampler2D samplerColorMap;
31+
32+
[shader("vertex")]
33+
VSOutput vertexMain(VSInput input)
34+
{
35+
VSOutput output;
36+
output.Color = float3(1.0, 0.0, 0.0);
37+
output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos.xyz, 1.0)));
38+
output.Normal = mul((float3x3)ubo.model, input.Normal);
39+
float4 pos = mul(ubo.model, float4(input.Pos, 1.0));
40+
float3 lPos = mul((float3x3)ubo.model, ubo.lightPos.xyz);
41+
output.LightVec = lPos - pos.xyz;
42+
return output;
43+
}
44+
45+
[shader("fragment")]
46+
float4 fragmentMain(VSOutput input)
47+
{
48+
float3 color;
49+
float3 N = normalize(input.Normal);
50+
float3 L = normalize(input.LightVec);
51+
float intensity = dot(N,L);
52+
if (intensity > 0.98)
53+
color = input.Color * 1.5;
54+
else if (intensity > 0.9)
55+
color = input.Color * 1.0;
56+
else if (intensity > 0.5)
57+
color = input.Color * 0.6;
58+
else if (intensity > 0.25)
59+
color = input.Color * 0.4;
60+
else
61+
color = input.Color * 0.2;
62+
// Desaturate a bit
63+
color = lerp(color, dot(float3(0.2126,0.7152,0.0722), color).xxx, 0.1);
64+
return float4(color, 1);
65+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
};
13+
14+
struct VSOutput
15+
{
16+
float4 Pos : SV_POSITION;
17+
float3 Normal;
18+
float2 UV;
19+
float3 ViewVec;
20+
float3 LightVec;
21+
};
22+
23+
struct UBO
24+
{
25+
float4x4 projection;
26+
float4x4 model;
27+
float4 lightPos;
28+
};
29+
ConstantBuffer<UBO> ubo;
30+
31+
[shader("vertex")]
32+
VSOutput vertexMain(VSInput input)
33+
{
34+
VSOutput output;
35+
output.Normal = input.Normal;
36+
output.UV = input.UV;
37+
output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos.xyz, 1.0)));
38+
float4 pos = mul(ubo.model, float4(input.Pos, 1.0));
39+
output.Normal = mul((float3x3)ubo.model, normalize(input.Normal));
40+
float3 lPos = mul((float3x3)ubo.model, ubo.lightPos.xyz);
41+
output.LightVec = lPos - pos.xyz;
42+
output.ViewVec = -pos.xyz;
43+
return output;
44+
}
45+
46+
[shader("fragment")]
47+
float4 fragmentMain(VSOutput input)
48+
{
49+
float3 N = normalize(input.Normal);
50+
float3 L = normalize(input.LightVec);
51+
float3 V = normalize(input.ViewVec);
52+
float3 R = reflect(-L, N);
53+
float diffuse = max(dot(N, L), 0.0);
54+
float specular = pow(max(dot(R, V), 0.0), 1.0);
55+
return float4(((diffuse + specular) * 0.25).xxx, 1.0);
56+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* Copyright (c) 2025, Sascha Willems
2+
*
3+
* SPDX-License-Identifier: MIT
4+
*
5+
*/
6+
7+
struct VSInput
8+
{
9+
float2 Pos;
10+
float2 UV;
11+
};
12+
13+
struct VSOutput
14+
{
15+
float4 Pos : SV_POSITION;
16+
float2 UV;
17+
};
18+
19+
Sampler2D samplerFont;
20+
21+
[shader("vertex")]
22+
VSOutput vertexMain(VSInput input)
23+
{
24+
VSOutput output;
25+
output.Pos = float4(input.Pos, 0.0, 1.0);
26+
output.UV = input.UV;
27+
return output;
28+
}
29+
30+
[shader("fragment")]
31+
float4 fragmentMain(VSOutput input)
32+
{
33+
float color = samplerFont.Sample(input.UV).r;
34+
return color.xxxx;
35+
}

0 commit comments

Comments
 (0)