hdr-canvas 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,18 +2,18 @@
2
2
 
3
3
  # Introduction
4
4
 
5
- Since the last release many areas of handling HDR contet in the browser have evolved.
6
- Most notably is certainly the introduction of the `Float16Array` in the `ImageData` construtor:
5
+ Since the last release many areas of handling HDR content in the browser have evolved.
6
+ Most notably is certainly the introduction of the `Float16Array` in the `ImageData` constructor:
7
7
 
8
- - The [WhatWG spec](https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#imagedataarray), [MDN](https://developer.mozilla.org/en-US/docs/Web/API/ImageData/ImageData#syntax) and [BCD]([new ImageData(new Float16Array(4), 1, 1, {pixelFormat:"rgba-float16"})](https://github.com/mdn/browser-compat-data/issues/27547)) have been updated accordingly. You can test your own browser using `new ImageData(new Float16Array(4), 1, 1, {pixelFormat:"rgba-float16"})`.
8
+ - The [WhatWG spec](https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#imagedataarray), [MDN](https://developer.mozilla.org/en-US/docs/Web/API/ImageData/ImageData#syntax) and [BCD](https://github.com/mdn/browser-compat-data/issues/27547)) have been updated accordingly. You can test your own browser using `new ImageData(new Float16Array(4), 1, 1, {pixelFormat:"rgba-float16"})`.
9
9
  - Still open in [Firefox](https://bugzil.la/1958830)
10
10
  - Hidden behind flag in [Safari](https://webkit.org/b/291196)
11
- - Chromium has implemented it starting with [137](https://source.chromium.org/chromium/chromium/src/+/refs/tags/137.0.7104.0:third_party/blink/renderer/core/html/canvas/image_data.idl): \*\*The `ImageData` constructor only acceppts `Float16Array` instead of `Uint16Array`. This makes older versions of this modue obsolute, since they targeted the chromium specific solution.
11
+ - Chromium has implemented it starting with [137](https://source.chromium.org/chromium/chromium/src/+/refs/tags/137.0.7104.0:third_party/blink/renderer/core/html/canvas/image_data.idl): \*\*The `ImageData` constructor only accepts `Float16Array` instead of `Uint16Array`. This makes older versions of this module obsolete, since they targeted the chromium specific solution.
12
12
  - If Safari enables it by default it will be also in the [Typescript DOM types](https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/2107)
13
13
 
14
14
  As [@reitowo](https://github.com/reitowo) pointed out, there has been a change to the `getContext("2d")` method. The key `pixelFormat` has been replaced by `colorType`.
15
15
 
16
- In parallel threre have been changes to the UltraHDR image format, especially te encoding of gain map matadata. While this used to be don in XMP it's now done according to ISO 21496-1. This ihas been adopted by Google and Apple in newer OS versions like Android 15 and iOS 18 to avoid cross-platform fragmentation. The [UltraHDR Library](https://github.com/google/libultrahdr) has already changed to ussin the [ISO format as default](https://github.com/google/libultrahdr/blob/main/docs/building.md).
16
+ In parallel there have been changes to the UltraHDR image format, especially the encoding of gain map metadata. While this used to be don in XMP it's now done according to ISO 21496-1. This has been adopted by Google and Apple in newer OS versions like Android 15 and iOS 18 to avoid cross-platform fragmentation. The [UltraHDR Library](https://github.com/google/libultrahdr) has already changed to using the [ISO format as default](https://github.com/google/libultrahdr/blob/main/docs/building.md).
17
17
 
18
18
  Currently the ThreeJS UHDR loader doesn't know how to handle this change, see [mrdoob/three.js#32293](https://github.com/mrdoob/three.js/issues/32293).
19
19
 
@@ -29,7 +29,7 @@ The documentation have been greatly improved, there is now also a [site](https:/
29
29
 
30
30
  ## Examples
31
31
 
32
- The examples fro the blog are now part of this repository:
32
+ The examples from the blog are now part of this repository:
33
33
 
34
34
  - [`tests/site/assets/ts/hdr-three.js.ts`](tests/site/assets/ts/hdr-three.js.ts) - Three JS with HDR texture
35
35
  - [`tests/site/assets/ts/image-slider.ts`](tests/site/assets/ts/image-slider.ts) - Generated HDR content
@@ -0,0 +1,19 @@
1
+ # `hdr-canvas` 0.1.1
2
+
3
+ # Introduction
4
+
5
+ Since the last release many areas of handling HDR content in the browser have evolved. This also applies for WebGPU renderings using ThreeJS
6
+
7
+ The changes in initializing a `canvas for a Rendere are described in the [explainer](https://github.com/ccameron-chromium/webgpu-hdr/blob/main/EXPLAINER.md).
8
+
9
+ The important change is the renaming from `colorMetadata` to:
10
+
11
+ ```
12
+ toneMapping: { mode: "extended" }
13
+ ```
14
+
15
+ This is also reflected by the ThreeJS API so a custom HDR WebGPU Renderer and Backend aren't strictly needed anymore. They will be removed soon.
16
+
17
+ # Key Changes & New Features
18
+
19
+ - Fix ThreeJS HDR Renderer and Backend
@@ -0,0 +1,13 @@
1
+ # How to release a new version
2
+
3
+ # Create a tag
4
+
5
+ ```
6
+ git tag 0.1.0
7
+ ```
8
+
9
+ # Create a release on GitHub
10
+
11
+ - https://github.com/cmahnke/hdr-canvas/releases/new
12
+ - Add Title and notes
13
+ - Check "Set as the latest release"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdr-canvas",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "HDR capable HTML canvas",
5
5
  "main": "dist/hdr-canvas.cjs",
6
6
  "module": "dist/hdr-canvas.js",
@@ -77,11 +77,11 @@
77
77
  "@rollup/plugin-node-resolve": "^16.0.3",
78
78
  "@rollup/plugin-terser": "^0.4.4",
79
79
  "@rollup/plugin-typescript": "^12.3.0",
80
- "@napi-rs/canvas": "^0.1.82",
80
+ "@napi-rs/canvas": "^0.1.83",
81
81
  "@types/jsdom": "^27.0.0",
82
82
  "@types/semver": "^7.7.1",
83
83
  "@types/three": "^0.181.0",
84
- "@typescript-eslint/parser": "^8.46.4",
84
+ "@typescript-eslint/parser": "^8.48.0",
85
85
  "@typescript/lib-dom": "npm:@types/web@^0.0.294",
86
86
  "better-docs": "^2.7.3",
87
87
  "eslint": "^9.39.1",
@@ -89,22 +89,22 @@
89
89
  "globals": "^16.5.0",
90
90
  "jsdoc": "^4.0.5",
91
91
  "jsdom": "^27.2.0",
92
- "knip": "^5.69.1",
92
+ "knip": "^5.70.2",
93
93
  "pkg-types": "^2.3.0",
94
- "prettier": "^3.6.2",
95
- "rimraf": "^6.1.0",
96
- "rollup": "^4.53.2",
97
- "rollup-plugin-dts": "^6.2.3",
98
- "sass": "^1.94.0",
94
+ "prettier": "^3.7.1",
95
+ "rimraf": "^6.1.2",
96
+ "rollup": "^4.53.3",
97
+ "rollup-plugin-dts": "^6.3.0",
98
+ "sass": "^1.94.2",
99
99
  "semver": "^7.7.3",
100
- "stylelint": "^16.25.0",
100
+ "stylelint": "^16.26.1",
101
101
  "stylelint-config-standard-scss": "^16.0.0",
102
- "three": "^0.181.1",
102
+ "three": "^0.181.2",
103
103
  "tslib": "^2.8.1",
104
104
  "typescript": "^5.9.3",
105
- "typescript-eslint": "^8.46.4",
106
- "vite": "^7.2.2",
107
- "vitest": "^4.0.9"
105
+ "typescript-eslint": "^8.48.0",
106
+ "vite": "^7.2.4",
107
+ "vitest": "^4.0.14"
108
108
  },
109
109
  "dependencies": {
110
110
  "colorjs.io": "^0.5.2"
@@ -1,5 +1,5 @@
1
1
  import WebGPUBackend from 'three/src/renderers/webgpu/WebGPUBackend.js';
2
- import { GPUFeatureName, GPUTextureFormat } from 'three/src/renderers/webgpu/utils/WebGPUConstants.js';
2
+ import { REVISION, HalfFloatType } from 'three/src/constants.js';
3
3
 
4
4
  /**
5
5
  * An HDR-enabled WebGPU backend for three.js, extending the standard `WebGPUBackend`.
@@ -13,96 +13,58 @@ import { GPUFeatureName, GPUTextureFormat } from 'three/src/renderers/webgpu/uti
13
13
 
14
14
  class HDRWebGPUBackend extends WebGPUBackend {
15
15
 
16
- /**
17
- * Initializes the backend, including requesting a WebGPU device and configuring the context.
18
- * This method overrides the parent `init` to set a specific HDR color space.
19
- *
20
- * @param {WebGLRenderer} renderer - The three.js renderer instance.
21
- * @returns {Promise<void>} A promise that resolves when the initialization is complete.
22
- */
23
- // See https://github.com/mrdoob/three.js/blob/master/examples/jsm/renderers/webgpu/WebGPUBackend.js#L123
24
- async init( renderer ) {
16
+ get context() {
25
17
 
26
- await super.init( renderer );
18
+ const canvasTarget = this.renderer.getCanvasTarget();
19
+ const canvasData = this.get( canvasTarget );
27
20
 
28
- //
21
+ let context = canvasData.context;
29
22
 
30
- const parameters = this.parameters;
23
+ if ( context === undefined ) {
31
24
 
32
- // create the device if it is not passed with parameters
25
+ const parameters = this.parameters;
33
26
 
34
- let device;
27
+ if ( canvasTarget.isDefaultCanvasTarget === true && parameters.context !== undefined ) {
35
28
 
36
- if ( parameters.device === undefined ) {
29
+ context = parameters.context;
37
30
 
38
- const adapterOptions = {
39
- powerPreference: parameters.powerPreference
40
- };
31
+ } else {
41
32
 
42
- const adapter = await navigator.gpu.requestAdapter( adapterOptions );
33
+ context = canvasTarget.domElement.getContext( 'webgpu' );
43
34
 
44
- if ( adapter === null ) {
35
+ }
45
36
 
46
- throw new Error( 'WebGPUBackend: Unable to create WebGPU adapter.' );
37
+ // OffscreenCanvas does not have setAttribute, see #22811
38
+ if ( 'setAttribute' in canvasTarget.domElement ) canvasTarget.domElement.setAttribute( 'data-engine', `three.js r${ REVISION } webgpu` );
47
39
 
48
- }
40
+ const alphaMode = parameters.alpha ? 'premultiplied' : 'opaque';
49
41
 
50
- // feature support
42
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
43
+ const toneMappingMode = parameters.outputType === HalfFloatType ? 'extended' : 'standard';
51
44
 
52
- const features = Object.values( GPUFeatureName );
45
+ // See https://github.com/ccameron-chromium/webgpu-hdr/blob/main/EXPLAINER.md#example-use
46
+ /**
47
+ * Configures the WebGPU context with HDR settings.
48
+ * The `colorSpace` is set to `rec2100-hlg` for High Dynamic Range support.
49
+ * @see {@link https://github.com/ccameron-chromium/webgpu-hdr/blob/main/EXPLAINER.md#example-use | WebGPU HDR Explainer}
50
+ */
53
51
 
54
- const supportedFeatures = [];
52
+ context.configure( {
53
+ device: this.device,
54
+ format: this.utils.getPreferredCanvasFormat(),
55
+ usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
56
+ alphaMode: alphaMode,
57
+ colorSpace: "rec2100-hlg",
58
+ toneMapping: { mode: "extended" }
59
+ } );
55
60
 
56
- for ( const name of features ) {
61
+ canvasData.context = context;
57
62
 
58
- if ( adapter.features.has( name ) ) {
63
+ }
59
64
 
60
- supportedFeatures.push( name );
65
+ return context;
61
66
 
62
- }
63
-
64
- }
65
-
66
- const deviceDescriptor = {
67
- requiredFeatures: supportedFeatures,
68
- requiredLimits: parameters.requiredLimits
69
- };
70
-
71
- device = await adapter.requestDevice( deviceDescriptor );
72
-
73
- } else {
74
-
75
- device = parameters.device;
76
-
77
- }
78
-
79
- const context = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgpu' );
80
-
81
- this.device = device;
82
- this.context = context;
83
-
84
- const alphaMode = parameters.alpha ? 'premultiplied' : 'opaque';
85
-
86
- // See https://github.com/ccameron-chromium/webgpu-hdr/blob/main/EXPLAINER.md#example-use
87
- /**
88
- * Configures the WebGPU context with HDR settings.
89
- * The `colorSpace` is set to `rec2100-hlg` for High Dynamic Range support.
90
- * @see {@link https://github.com/ccameron-chromium/webgpu-hdr/blob/main/EXPLAINER.md#example-use | WebGPU HDR Explainer}
91
- */
92
- this.context.configure( {
93
- device: this.device,
94
- format: GPUTextureFormat.BGRA8Unorm,
95
- //format: GPUTextureFormat.RGBA16Float,
96
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
97
- alphaMode: alphaMode,
98
- //colorSpace: "display-p3",
99
- colorSpace: "rec2100-hlg",
100
- colorMetadata: { mode:"extended" }
101
- } );
102
-
103
- this.updateSize();
104
-
105
- }
67
+ }
106
68
 
107
69
  }
108
70