Skip to content

Commit db2258a

Browse files
committed
Add multisampling
1 parent f48bd7b commit db2258a

File tree

2 files changed

+44
-8
lines changed
  • apps/typegpu-docs/src/examples/geometry

2 files changed

+44
-8
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ context.configure({
3232
alphaMode: 'premultiplied',
3333
});
3434

35-
// Textures
3635
let msaaTexture: GPUTexture;
3736
let msaaTextureView: GPUTextureView;
3837

apps/typegpu-docs/src/examples/geometry/lines-combinations/index.ts

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ context.configure({
6666
alphaMode: 'premultiplied',
6767
});
6868

69+
let msaaTexture: GPUTexture;
70+
let msaaTextureView: GPUTextureView;
71+
72+
const createDepthAndMsaaTextures = () => {
73+
if (msaaTexture) {
74+
msaaTexture.destroy();
75+
}
76+
msaaTexture = device.createTexture({
77+
size: [canvas.width, canvas.height, 1],
78+
format: presentationFormat,
79+
sampleCount: 4,
80+
usage: GPUTextureUsage.RENDER_ATTACHMENT,
81+
});
82+
msaaTextureView = msaaTexture.createView();
83+
};
84+
85+
createDepthAndMsaaTextures();
86+
const resizeObserver = new ResizeObserver(createDepthAndMsaaTextures);
87+
resizeObserver.observe(canvas);
88+
6989
const Uniforms = struct({
7090
time: f32,
7191
fillType: u32,
@@ -336,6 +356,7 @@ function createPipelines() {
336356
.withPrimitive({
337357
// cullMode: 'back',
338358
})
359+
.withMultisample({ count: multisample ? 4 : 1 })
339360
.createPipeline()
340361
.withIndexBuffer(oneSided ? indexBufferLeft : indexBuffer);
341362

@@ -352,6 +373,7 @@ function createPipelines() {
352373
.withPrimitive({
353374
topology: 'line-list',
354375
})
376+
.withMultisample({ count: multisample ? 4 : 1 })
355377
.createPipeline()
356378
.withIndexBuffer(outlineIndexBuffer);
357379

@@ -365,6 +387,7 @@ function createPipelines() {
365387
.withPrimitive({
366388
topology: 'line-strip',
367389
})
390+
.withMultisample({ count: multisample ? 4 : 1 })
368391
.createPipeline();
369392

370393
const circles = root['~unstable']
@@ -377,6 +400,7 @@ function createPipelines() {
377400
.withPrimitive({
378401
topology: 'line-list',
379402
})
403+
.withMultisample({ count: multisample ? 4 : 1 })
380404
.createPipeline();
381405

382406
return {
@@ -387,8 +411,9 @@ function createPipelines() {
387411
};
388412
}
389413

414+
let multisample = true;
390415
let showRadii = false;
391-
let wireframe = true;
416+
let wireframe = false;
392417
let oneSided = false;
393418
let fillType = 1;
394419
let animationSpeed = 1;
@@ -401,7 +426,12 @@ const draw = (timeMs: number) => {
401426
time: timeMs * 1e-3,
402427
});
403428
const colorAttachment: ColorAttachment = {
404-
view: context.getCurrentTexture().createView(),
429+
view: multisample
430+
? msaaTextureView
431+
: context.getCurrentTexture().createView(),
432+
resolveTarget: multisample
433+
? context.getCurrentTexture().createView()
434+
: undefined,
405435
clearValue: [1, 1, 1, 1],
406436
loadOp: 'load',
407437
storeOp: 'store',
@@ -460,6 +490,13 @@ const fillOptions = {
460490
};
461491

462492
export const controls = {
493+
'MSAA x4': {
494+
initial: multisample,
495+
onToggleChange: (value: boolean) => {
496+
multisample = value;
497+
pipelines = createPipelines();
498+
},
499+
},
463500
'Test Case': {
464501
initial: Object.keys(testCases)[0],
465502
options: Object.keys(testCases),
@@ -501,26 +538,26 @@ export const controls = {
501538
},
502539
},
503540
Wireframe: {
504-
initial: true,
541+
initial: wireframe,
505542
onToggleChange: (value: boolean) => {
506543
wireframe = value;
507544
},
508545
},
509546
'One sided': {
510-
initial: false,
547+
initial: oneSided,
511548
onToggleChange: (value: boolean) => {
512549
oneSided = value;
513550
pipelines = createPipelines();
514551
},
515552
},
516553
'Radius and centerline': {
517-
initial: false,
554+
initial: showRadii,
518555
onToggleChange: (value: boolean) => {
519556
showRadii = value;
520557
},
521558
},
522559
'Animation speed': {
523-
initial: 1,
560+
initial: animationSpeed,
524561
min: 0,
525562
step: 0.001,
526563
max: 5,
@@ -529,7 +566,7 @@ export const controls = {
529566
},
530567
},
531568
Reverse: {
532-
initial: false,
569+
initial: reverse,
533570
onToggleChange: (value: boolean) => {
534571
reverse = value;
535572
},

0 commit comments

Comments
 (0)