Skip to content

Commit 091d084

Browse files
committed
#19 imageblock experiment beginnings
1 parent ed9c404 commit 091d084

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Sources/vger/path.metal

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright © 2025 Audulus LLC. All rights reserved.
2+
3+
#include <metal_stdlib>
4+
using namespace metal;
5+
6+
// New experimental tile-buffer based path rendering.
7+
// Draw paths by flipping in/out using a triangle fan
8+
// then flipping using bezier regions.
9+
10+
struct GBufferData {
11+
12+
/// Inside or outside the path?
13+
bool sign [[raster_order_group(0)]];
14+
15+
/// Approx distance to path curve for AA.
16+
float distance [[raster_order_group(0)]];
17+
};
18+
19+
struct GBufferStore {
20+
GBufferData data [[imageblock_data]];
21+
};
22+
23+
struct VertexOut {
24+
float4 position [[ position ]];
25+
float2 uv;
26+
};
27+
28+
void flip(thread bool& b) {
29+
b = !b;
30+
}
31+
32+
fragment GBufferStore path_fragment(VertexOut in [[ stage_in ]],
33+
GBufferStore fragmentValues [[imageblock_data]]) {
34+
35+
GBufferStore result;
36+
result.data.sign = fragmentValues.data.sign;
37+
float u = in.uv.x;
38+
float v = in.uv.y;
39+
40+
if (isnan(u)) {
41+
// If we're rendering the triangle fan, flip the
42+
// whole triangle.
43+
flip(result.data.sign);
44+
} else {
45+
// Flip the sign only for the interior pixels.
46+
if(u*u - v < 0) {
47+
flip(result.data.sign);
48+
}
49+
}
50+
51+
return result;
52+
}

0 commit comments

Comments
 (0)