1+ /* Copyright (c) 2025, Sascha Willems
2+ *
3+ * SPDX-License-Identifier: MIT
4+ *
5+ */
6+
7+ struct VSInput
8+ {
9+ float4 Pos;
10+ float2 UV;
11+ float3 Color;
12+ float3 Normal;
13+ };
14+
15+ struct VSOutput
16+ {
17+ float4 Pos : SV_POSITION;
18+ float3 Normal;
19+ float2 UV;
20+ float3 Color;
21+ float3 ViewVec;
22+ float3 LightVec;
23+ };
24+
25+ struct UBO
26+ {
27+ float4x4 projection;
28+ float4x4 view;
29+ float4x4 model;
30+ };
31+ ConstantBuffer < UBO> ubo;
32+
33+ Sampler2D colorMapSampler;
34+
35+ [shader(" vertex" )]
36+ VSOutput vertexMain(VSInput input)
37+ {
38+ VSOutput output;
39+ output .Normal = input .Normal ;
40+ output .Color = input .Color ;
41+ output .UV = input .UV ;
42+ output .Pos = mul(ubo .projection , mul(ubo .view , mul(ubo .model , input .Pos )));
43+
44+ float3 lightPos = float3(- 5 . 0 , - 5 . 0 , 0 . 0 );
45+ float4 pos = mul(ubo .view , mul(ubo .model , input .Pos ));
46+ output .Normal = mul((float4x3 )mul(ubo .view , ubo .model ), input .Normal ).xyz ;
47+ output .LightVec = lightPos - pos .xyz ;
48+ output .ViewVec = - pos .xyz ;
49+ return output;
50+ }
51+
52+ [shader(" fragment" )]
53+ float4 fragmentMain(VSOutput input)
54+ {
55+ float3 ambient = float3(0 . 0 f , 0 . 0 f , 0 . 0 f );
56+
57+ // Adjust light calculations for glow color
58+ if ((input .Color .r >= 0 . 9 ) || (input .Color .g >= 0 . 9 ) || (input .Color .b >= 0 . 9 ))
59+ {
60+ ambient = input .Color * 0 . 25 ;
61+ }
62+
63+ float3 N = normalize(input .Normal );
64+ float3 L = normalize(input .LightVec );
65+ float3 V = normalize(input .ViewVec );
66+ float3 R = reflect(- L, N);
67+ float3 diffuse = max(dot(N, L), 0 . 0 ) * input .Color ;
68+ float3 specular = pow(max(dot(R, V), 0 . 0 ), 8 . 0 ) * float3(0 . 75 f , 0 . 75 f , 0 . 75 f );
69+ return float4(ambient + diffuse + specular, 1 . 0 );
70+ }
0 commit comments