Skip to content

Commit cb1f443

Browse files
committed
Add slang shaders for screenshot sample
1 parent 04ab171 commit cb1f443

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
float3 Color;
12+
};
13+
14+
struct VSOutput
15+
{
16+
float4 Pos : SV_POSITION;
17+
float3 Color;
18+
float3 Normal;
19+
float3 ViewVec;
20+
float3 LightVec;
21+
};
22+
23+
struct UBO
24+
{
25+
float4x4 projection;
26+
float4x4 view;
27+
float4x4 model;
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.Color = input.Color;
37+
38+
output.Pos = mul(ubo.projection, mul(ubo.view, mul(ubo.model, float4(input.Pos.xyz, 1.0))));
39+
40+
output.Normal = mul((float3x3)ubo.model, input.Normal);
41+
float4 pos = mul(ubo.model, float4(input.Pos, 1.0));
42+
43+
const float3 lightPos = float3(1.0, -1.0, 1.0);
44+
output.LightVec = lightPos.xyz - pos.xyz;
45+
output.ViewVec = -pos.xyz;
46+
return output;
47+
}
48+
49+
[shader("fragment")]
50+
float4 fragmentMain(VSOutput input)
51+
{
52+
const float ambient = 0.1;
53+
float3 N = normalize(input.Normal);
54+
float3 L = normalize(input.LightVec);
55+
float3 V = normalize(input.ViewVec);
56+
float3 R = reflect(-L, N);
57+
float3 diffuse = max(dot(N, L), 0.0).rrr;
58+
float3 specular = pow(max(dot(R, V), 0.0), 32.0);
59+
return float4((ambient + diffuse) * input.Color.rgb + specular, 1.0);
60+
}

0 commit comments

Comments
 (0)