Skip to content

Commit e485401

Browse files
committed
Make all canvas alphaModes premultiplied
Also, fix helloTriangle not considering devicePixelRatio
1 parent 0bd0e6b commit e485401

File tree

17 files changed

+21
-17
lines changed

17 files changed

+21
-17
lines changed

src/sample/animometer/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
3636
context.configure({
3737
device,
3838
format: presentationFormat,
39-
alphaMode: 'opaque',
39+
alphaMode: 'premultiplied',
4040
usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
4141
});
4242

src/sample/computeBoids/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
1717
context.configure({
1818
device,
1919
format: presentationFormat,
20-
alphaMode: 'opaque',
20+
alphaMode: 'premultiplied',
2121
});
2222

2323
const spriteShaderModule = device.createShaderModule({ code: spriteWGSL });

src/sample/cubemap/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
2727
context.configure({
2828
device,
2929
format: presentationFormat,
30-
alphaMode: 'opaque',
30+
alphaMode: 'premultiplied',
3131
});
3232

3333
// Create a vertex buffer from the cube data.

src/sample/deferredRendering/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
2828
context.configure({
2929
device,
3030
format: presentationFormat,
31-
alphaMode: 'opaque',
31+
alphaMode: 'premultiplied',
3232
});
3333

3434
// Create the model vertex buffer.

src/sample/fractalCube/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
3131
// Specify we want both RENDER_ATTACHMENT and COPY_SRC since we
3232
// will copy out of the swapchain texture.
3333
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
34-
alphaMode: 'opaque',
34+
alphaMode: 'premultiplied',
3535
});
3636

3737
// Create a vertex buffer from the cube data.

src/sample/helloTriangle/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ const init: SampleInit = async ({ canvas, pageState }) => {
1010
if (!pageState.active) return;
1111
const context = canvas.getContext('webgpu') as GPUCanvasContext;
1212

13+
const devicePixelRatio = window.devicePixelRatio || 1;
14+
canvas.width = canvas.clientWidth * devicePixelRatio;
15+
canvas.height = canvas.clientHeight * devicePixelRatio;
1316
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
17+
1418
context.configure({
1519
device,
1620
format: presentationFormat,
17-
alphaMode: 'opaque',
21+
alphaMode: 'premultiplied',
1822
});
1923

2024
const pipeline = device.createRenderPipeline({

src/sample/helloTriangleMSAA/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
1818
context.configure({
1919
device,
2020
format: presentationFormat,
21-
alphaMode: 'opaque',
21+
alphaMode: 'premultiplied',
2222
});
2323

2424
const sampleCount = 4;

src/sample/imageBlur/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
2222
context.configure({
2323
device,
2424
format: presentationFormat,
25-
alphaMode: 'opaque',
25+
alphaMode: 'premultiplied',
2626
});
2727

2828
const blurPipeline = device.createComputePipeline({

src/sample/instancedCube/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
2727
context.configure({
2828
device,
2929
format: presentationFormat,
30-
alphaMode: 'opaque',
30+
alphaMode: 'premultiplied',
3131
});
3232

3333
// Create a vertex buffer from the cube data.

src/sample/particles/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
3030
context.configure({
3131
device,
3232
format: presentationFormat,
33-
alphaMode: 'opaque',
33+
alphaMode: 'premultiplied',
3434
});
3535

3636
const particlesBuffer = device.createBuffer({

0 commit comments

Comments
 (0)