File tree Expand file tree Collapse file tree
shaders/slang/distancefieldfonts Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /* Copyright (c) 2025, Sascha Willems
2+ *
3+ * SPDX-License-Identifier: MIT
4+ *
5+ */
6+
7+ struct VSInput
8+ {
9+ float3 Pos;
10+ float2 UV;
11+ };
12+
13+ struct VSOutput
14+ {
15+ float4 Pos : SV_POSITION;
16+ float2 UV;
17+ };
18+
19+ struct UBO
20+ {
21+ float4x4 projection;
22+ float4x4 model;
23+ };
24+ ConstantBuffer < UBO> ubo;
25+ Sampler2D samplerColor;
26+
27+ [shader(" vertex" )]
28+ VSOutput vertexMain(VSInput input)
29+ {
30+ VSOutput output;
31+ output .UV = input .UV ;
32+ output .Pos = mul(ubo .projection , mul(ubo .model , float4(input .Pos .xyz , 1 . 0 )));
33+ return output;
34+ }
35+
36+ [shader(" fragment" )]
37+ float4 fragmentMain(VSOutput input)
38+ {
39+ return samplerColor .Sample (input .UV ).aaaa ;
40+ }
Original file line number Diff line number Diff line change 1+ /* Copyright (c) 2025, Sascha Willems
2+ *
3+ * SPDX-License-Identifier: MIT
4+ *
5+ */
6+
7+ struct VSInput
8+ {
9+ float3 Pos;
10+ float2 UV;
11+ };
12+
13+
14+ struct VSOutput
15+ {
16+ float4 Pos : SV_POSITION;
17+ float2 UV;
18+ };
19+
20+ struct UBO
21+ {
22+ float4x4 projection;
23+ float4x4 model;
24+ float4 outlineColor;
25+ float outlineWidth;
26+ float outline;
27+ };
28+ ConstantBuffer < UBO> ubo;
29+ Sampler2D samplerColor;
30+
31+ [shader(" vertex" )]
32+ VSOutput vertexMain(VSInput input)
33+ {
34+ VSOutput output;
35+ output .UV = input .UV ;
36+ output .Pos = mul(ubo .projection , mul(ubo .model , float4(input .Pos .xyz , 1 . 0 )));
37+ return output;
38+ }
39+
40+ [shader(" fragment" )]
41+ float4 fragmentMain(VSOutput input)
42+ {
43+ float dist = samplerColor .Sample (input .UV ).a ;
44+ float smoothWidth = fwidth(dist);
45+ float alpha = smoothstep(0 . 5 - smoothWidth, 0 . 5 + smoothWidth, dist);
46+ float3 rgb = alpha .xxx ;
47+
48+ if (ubo .outline > 0 . 0 )
49+ {
50+ float w = 1 . 0 - ubo .outlineWidth ;
51+ alpha = smoothstep(w - smoothWidth, w + smoothWidth, dist);
52+ rgb += lerp(alpha .xxx , ubo .outlineColor .rgb , alpha);
53+ }
54+
55+ return float4(rgb, alpha);
56+ }
You can’t perform that action at this time.
0 commit comments