Skip to content

Commit e6f0e66

Browse files
authored
@typegpu/geometry Simplify variable width lines implementation (#1935)
1 parent 154df15 commit e6f0e66

35 files changed

Lines changed: 1607 additions & 1013 deletions

apps/typegpu-docs/src/examples/geometry/circles/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ if (!context) {
1414
}
1515

1616
const adapter = await navigator.gpu.requestAdapter();
17-
console.log(`Using ${adapter?.info.vendor} adapter`);
1817
const device = await adapter?.requestDevice({
1918
requiredFeatures: ['timestamp-query'],
2019
});
@@ -29,7 +28,6 @@ context.configure({
2928
alphaMode: 'premultiplied',
3029
});
3130

32-
// Textures
3331
let msaaTexture: GPUTexture;
3432
let msaaTextureView: GPUTextureView;
3533

@@ -99,9 +97,10 @@ const mainVertexMaxArea = tgpu.vertexFn({
9997
instanceIndex: d.interpolate('flat', d.u32),
10098
},
10199
})(({ vertexIndex, instanceIndex }) => {
100+
'use gpu';
102101
const C = bindGroupLayout.$.circles[instanceIndex];
103102
const unit = circle(vertexIndex);
104-
const pos = s.add(C.position, s.mul(unit, C.radius));
103+
const pos = C.position + unit * C.radius;
105104
return {
106105
outPos: d.vec4f(pos, 0.0, 1.0),
107106
uv: unit,
@@ -116,6 +115,7 @@ const mainFragment = tgpu.fragmentFn({
116115
},
117116
out: d.vec4f,
118117
})(({ uv, instanceIndex }) => {
118+
'use gpu';
119119
const color = d.vec3f(1, s.cos(d.f32(instanceIndex)), s.sin(5 * d.f32(instanceIndex)));
120120
const r = s.length(uv);
121121
return d.vec4f(s.mix(color, d.vec3f(), s.clamp((r - 0.9) * 20, 0, 0.5)), 1);
@@ -148,6 +148,10 @@ setTimeout(() => {
148148
.draw(circleVertexCount(4), circleCount);
149149
}, 100);
150150

151+
// #region Example controls & Cleanup
152+
151153
export function onCleanup() {
152154
root.destroy();
153155
}
156+
157+
// #endregion

0 commit comments

Comments
 (0)