Skip to content

Commit

Permalink
Make all canvas alphaModes premultiplied
Browse files Browse the repository at this point in the history
Also, fix helloTriangle not considering devicePixelRatio
  • Loading branch information
austinEng committed Apr 5, 2023
1 parent 0bd0e6b commit e485401
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/sample/animometer/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
});

Expand Down
2 changes: 1 addition & 1 deletion src/sample/computeBoids/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

const spriteShaderModule = device.createShaderModule({ code: spriteWGSL });
Expand Down
2 changes: 1 addition & 1 deletion src/sample/cubemap/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

// Create a vertex buffer from the cube data.
Expand Down
2 changes: 1 addition & 1 deletion src/sample/deferredRendering/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

// Create the model vertex buffer.
Expand Down
2 changes: 1 addition & 1 deletion src/sample/fractalCube/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
// Specify we want both RENDER_ATTACHMENT and COPY_SRC since we
// will copy out of the swapchain texture.
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

// Create a vertex buffer from the cube data.
Expand Down
6 changes: 5 additions & 1 deletion src/sample/helloTriangle/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ const init: SampleInit = async ({ canvas, pageState }) => {
if (!pageState.active) return;
const context = canvas.getContext('webgpu') as GPUCanvasContext;

const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = canvas.clientWidth * devicePixelRatio;
canvas.height = canvas.clientHeight * devicePixelRatio;
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();

context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

const pipeline = device.createRenderPipeline({
Expand Down
2 changes: 1 addition & 1 deletion src/sample/helloTriangleMSAA/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

const sampleCount = 4;
Expand Down
2 changes: 1 addition & 1 deletion src/sample/imageBlur/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

const blurPipeline = device.createComputePipeline({
Expand Down
2 changes: 1 addition & 1 deletion src/sample/instancedCube/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

// Create a vertex buffer from the cube data.
Expand Down
2 changes: 1 addition & 1 deletion src/sample/particles/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

const particlesBuffer = device.createBuffer({
Expand Down
2 changes: 1 addition & 1 deletion src/sample/resizeCanvas/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

const sampleCount = 4;
Expand Down
2 changes: 1 addition & 1 deletion src/sample/reversedZ/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

const verticesBuffer = device.createBuffer({
Expand Down
2 changes: 1 addition & 1 deletion src/sample/rotatingCube/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

// Create a vertex buffer from the cube data.
Expand Down
2 changes: 1 addition & 1 deletion src/sample/shadowMapping/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

// Create the model vertex buffer.
Expand Down
2 changes: 1 addition & 1 deletion src/sample/texturedCube/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

// Create a vertex buffer from the cube data.
Expand Down
2 changes: 1 addition & 1 deletion src/sample/twoCubes/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

// Create a vertex buffer from the cube data.
Expand Down
2 changes: 1 addition & 1 deletion src/sample/videoUploading/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const init: SampleInit = async ({ canvas, pageState }) => {
context.configure({
device,
format: presentationFormat,
alphaMode: 'opaque',
alphaMode: 'premultiplied',
});

const pipeline = device.createRenderPipeline({
Expand Down

0 comments on commit e485401

Please sign in to comment.