Skip to content

Commit

Permalink
Warn when HDR canvas is not supported (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois authored Oct 1, 2024
1 parent 268c290 commit 6556fee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
11 changes: 6 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/showdown": "^2.0.6",
"@types/stats.js": "^0.17.3",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@webgpu/types": "^0.1.44",
"@webgpu/types": "^0.1.47",
"chokidar": "^3.6.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.10.0",
Expand Down
24 changes: 18 additions & 6 deletions sample/particles/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function configureContext() {
toneMapping: { mode: simulationParams.toneMappingMode },
alphaMode: 'premultiplied',
});
hdrFolder.name = getHdrFolderName();
}

const particlesBuffer = device.createBuffer({
Expand Down Expand Up @@ -346,13 +347,24 @@ hdrFolder
hdrFolder.add(simulationParams, 'brightnessFactor', 0, 4, 0.1);
hdrFolder.open();
const hdrMediaQuery = window.matchMedia('(dynamic-range: high)');
function updateHdrFolderName() {
hdrFolder.name = `HDR settings ${
hdrMediaQuery.matches ? '' : '⚠️ Your display is not compatible'
}`;
function getHdrFolderName() {
if (!hdrMediaQuery.matches) {
return "HDR settings ⚠️ Display isn't compatible";
}
if (!('getConfiguration' in GPUCanvasContext.prototype)) {
return 'HDR settings';
}
if (
simulationParams.toneMappingMode === 'extended' &&
context.getConfiguration().toneMapping?.mode !== 'extended'
) {
return "HDR settings ⚠️ Browser doesn't support HDR canvas";
}
return 'HDR settings';
}
updateHdrFolderName();
hdrMediaQuery.onchange = updateHdrFolderName;
hdrMediaQuery.onchange = () => {
hdrFolder.name = getHdrFolderName();
};

const computePipeline = device.createComputePipeline({
layout: 'auto',
Expand Down

0 comments on commit 6556fee

Please sign in to comment.