@monogrid/gainmap-js 2.0.7 → 3.0.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.
- package/CHANGELOG.md +25 -0
- package/README.md +14 -12
- package/dist/{QuadRenderer-QXcVmgNm.js → QuadRenderer-pEe6Kzcn.js} +45 -38
- package/dist/{_commonjsHelpers-ftl_lJMx.js → _commonjsHelpers-Gkwpb-h5.js} +1 -1
- package/dist/{compress-MvOX-rlz.js → compress-6L6-d1aM.js} +1 -1
- package/dist/core/QuadRenderer.d.ts +34 -2
- package/dist/core/types.d.ts +14 -0
- package/dist/decode/index.d.ts +2 -0
- package/dist/decode/loaders/GainMapLoader.d.ts +7 -7
- package/dist/decode/loaders/HDRJPGLoader.d.ts +7 -7
- package/dist/decode/loaders/LoaderBase.d.ts +9 -1
- package/dist/decode/types.d.ts +5 -1
- package/dist/decode.js +73 -23
- package/dist/decode.umd.js +116 -57
- package/dist/encode/get-sdr-rendition.d.ts +3 -1
- package/dist/encode/types.d.ts +5 -0
- package/dist/encode.js +42 -13
- package/dist/encode.umd.js +84 -48
- package/dist/libultrahdr.js +1 -1
- package/dist/libultrahdr.umd.js +1 -1
- package/dist/worker-interface.js +2 -2
- package/dist/worker-interface.umd.js +1 -1
- package/dist/worker.js +3 -3
- package/dist/worker.umd.js +1 -1
- package/package.json +25 -24
- /package/dist/decode/utils/{extract-metadata-from-jpeg.d.ts → extractXMP.d.ts} +0 -0
package/dist/decode.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js
|
|
2
|
+
* @monogrid/gainmap-js v3.0.1
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -48,23 +48,13 @@
|
|
|
48
48
|
* @param type
|
|
49
49
|
* @param renderer
|
|
50
50
|
* @param camera
|
|
51
|
+
* @param renderTargetOptions
|
|
51
52
|
* @returns
|
|
52
53
|
*/
|
|
53
|
-
const canReadPixels = (type, renderer, camera) => {
|
|
54
|
+
const canReadPixels = (type, renderer, camera, renderTargetOptions) => {
|
|
54
55
|
if (_canReadPixelsResult !== undefined)
|
|
55
56
|
return _canReadPixelsResult;
|
|
56
|
-
const testRT = new three.WebGLRenderTarget(1, 1,
|
|
57
|
-
type,
|
|
58
|
-
colorSpace: three.LinearSRGBColorSpace,
|
|
59
|
-
format: three.RGBAFormat,
|
|
60
|
-
magFilter: three.LinearFilter,
|
|
61
|
-
minFilter: three.LinearFilter,
|
|
62
|
-
wrapS: three.RepeatWrapping,
|
|
63
|
-
wrapT: three.RepeatWrapping,
|
|
64
|
-
depthBuffer: false,
|
|
65
|
-
stencilBuffer: false,
|
|
66
|
-
generateMipmaps: true
|
|
67
|
-
});
|
|
57
|
+
const testRT = new three.WebGLRenderTarget(1, 1, renderTargetOptions);
|
|
68
58
|
renderer.setRenderTarget(testRT);
|
|
69
59
|
const mesh = new three.Mesh(new three.PlaneGeometry(), new three.MeshBasicMaterial({ color: 0xffffff }));
|
|
70
60
|
renderer.render(mesh, camera);
|
|
@@ -89,7 +79,8 @@
|
|
|
89
79
|
* @param sourceTexture
|
|
90
80
|
* @param renderer
|
|
91
81
|
*/
|
|
92
|
-
constructor(
|
|
82
|
+
constructor(options) {
|
|
83
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
93
84
|
this._rendererIsDisposable = false;
|
|
94
85
|
this._supportsReadPixels = true;
|
|
95
86
|
/**
|
|
@@ -106,13 +97,29 @@
|
|
|
106
97
|
}
|
|
107
98
|
this._renderer.setRenderTarget(null);
|
|
108
99
|
};
|
|
109
|
-
this._width = width;
|
|
110
|
-
this._height = height;
|
|
111
|
-
this._type = type;
|
|
112
|
-
this._colorSpace = colorSpace;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
100
|
+
this._width = options.width;
|
|
101
|
+
this._height = options.height;
|
|
102
|
+
this._type = options.type;
|
|
103
|
+
this._colorSpace = options.colorSpace;
|
|
104
|
+
const rtOptions = {
|
|
105
|
+
// fixed options
|
|
106
|
+
format: three.RGBAFormat,
|
|
107
|
+
depthBuffer: false,
|
|
108
|
+
stencilBuffer: false,
|
|
109
|
+
// user options
|
|
110
|
+
type: this._type, // set in class property
|
|
111
|
+
colorSpace: this._colorSpace, // set in class property
|
|
112
|
+
anisotropy: ((_a = options.renderTargetOptions) === null || _a === void 0 ? void 0 : _a.anisotropy) !== undefined ? (_b = options.renderTargetOptions) === null || _b === void 0 ? void 0 : _b.anisotropy : 1,
|
|
113
|
+
generateMipmaps: ((_c = options.renderTargetOptions) === null || _c === void 0 ? void 0 : _c.generateMipmaps) !== undefined ? (_d = options.renderTargetOptions) === null || _d === void 0 ? void 0 : _d.generateMipmaps : false,
|
|
114
|
+
magFilter: ((_e = options.renderTargetOptions) === null || _e === void 0 ? void 0 : _e.magFilter) !== undefined ? (_f = options.renderTargetOptions) === null || _f === void 0 ? void 0 : _f.magFilter : three.LinearFilter,
|
|
115
|
+
minFilter: ((_g = options.renderTargetOptions) === null || _g === void 0 ? void 0 : _g.minFilter) !== undefined ? (_h = options.renderTargetOptions) === null || _h === void 0 ? void 0 : _h.minFilter : three.LinearFilter,
|
|
116
|
+
samples: ((_j = options.renderTargetOptions) === null || _j === void 0 ? void 0 : _j.samples) !== undefined ? (_k = options.renderTargetOptions) === null || _k === void 0 ? void 0 : _k.samples : undefined,
|
|
117
|
+
wrapS: ((_l = options.renderTargetOptions) === null || _l === void 0 ? void 0 : _l.wrapS) !== undefined ? (_m = options.renderTargetOptions) === null || _m === void 0 ? void 0 : _m.wrapS : three.ClampToEdgeWrapping,
|
|
118
|
+
wrapT: ((_o = options.renderTargetOptions) === null || _o === void 0 ? void 0 : _o.wrapT) !== undefined ? (_p = options.renderTargetOptions) === null || _p === void 0 ? void 0 : _p.wrapT : three.ClampToEdgeWrapping
|
|
119
|
+
};
|
|
120
|
+
this._material = options.material;
|
|
121
|
+
if (options.renderer) {
|
|
122
|
+
this._renderer = options.renderer;
|
|
116
123
|
}
|
|
117
124
|
else {
|
|
118
125
|
this._renderer = QuadRenderer.instantiateRenderer();
|
|
@@ -126,7 +133,7 @@
|
|
|
126
133
|
this._camera.top = 0.5;
|
|
127
134
|
this._camera.bottom = -0.5;
|
|
128
135
|
this._camera.updateProjectionMatrix();
|
|
129
|
-
if (!canReadPixels(this._type, this._renderer, this._camera)) {
|
|
136
|
+
if (!canReadPixels(this._type, this._renderer, this._camera, rtOptions)) {
|
|
130
137
|
let alternativeType;
|
|
131
138
|
switch (this._type) {
|
|
132
139
|
case three.HalfFloatType:
|
|
@@ -145,18 +152,8 @@
|
|
|
145
152
|
this._quad = new three.Mesh(new three.PlaneGeometry(), this._material);
|
|
146
153
|
this._quad.geometry.computeBoundingBox();
|
|
147
154
|
this._scene.add(this._quad);
|
|
148
|
-
this._renderTarget = new three.WebGLRenderTarget(width, height,
|
|
149
|
-
|
|
150
|
-
colorSpace,
|
|
151
|
-
format: three.RGBAFormat,
|
|
152
|
-
magFilter: three.LinearFilter,
|
|
153
|
-
minFilter: three.LinearMipMapLinearFilter,
|
|
154
|
-
wrapS: three.RepeatWrapping,
|
|
155
|
-
wrapT: three.RepeatWrapping,
|
|
156
|
-
depthBuffer: false,
|
|
157
|
-
stencilBuffer: false,
|
|
158
|
-
generateMipmaps: true
|
|
159
|
-
});
|
|
155
|
+
this._renderTarget = new three.WebGLRenderTarget(this.width, this.height, rtOptions);
|
|
156
|
+
this._renderTarget.texture.mapping = ((_q = options.renderTargetOptions) === null || _q === void 0 ? void 0 : _q.mapping) !== undefined ? (_r = options.renderTargetOptions) === null || _r === void 0 ? void 0 : _r.mapping : three.UVMapping;
|
|
160
157
|
}
|
|
161
158
|
/**
|
|
162
159
|
* Instantiates a temporary renderer
|
|
@@ -189,10 +186,20 @@
|
|
|
189
186
|
* Performs a readPixel operation in the renderTarget
|
|
190
187
|
* and returns a DataTexture containing the read data
|
|
191
188
|
*
|
|
189
|
+
* @params options
|
|
192
190
|
* @returns
|
|
193
191
|
*/
|
|
194
|
-
toDataTexture() {
|
|
195
|
-
|
|
192
|
+
toDataTexture(options) {
|
|
193
|
+
const returnValue = new three.DataTexture(
|
|
194
|
+
// fixed values
|
|
195
|
+
this.toArray(), this.width, this.height, three.RGBAFormat, this._type,
|
|
196
|
+
// user values
|
|
197
|
+
(options === null || options === void 0 ? void 0 : options.mapping) || three.UVMapping, (options === null || options === void 0 ? void 0 : options.wrapS) || three.ClampToEdgeWrapping, (options === null || options === void 0 ? void 0 : options.wrapT) || three.ClampToEdgeWrapping, (options === null || options === void 0 ? void 0 : options.magFilter) || three.LinearFilter, (options === null || options === void 0 ? void 0 : options.minFilter) || three.LinearFilter, (options === null || options === void 0 ? void 0 : options.anisotropy) || 1,
|
|
198
|
+
// fixed value
|
|
199
|
+
three.LinearSRGBColorSpace);
|
|
200
|
+
// set this afterwards, we can't set it in constructor
|
|
201
|
+
returnValue.generateMipmaps = (options === null || options === void 0 ? void 0 : options.generateMipmaps) !== undefined ? options === null || options === void 0 ? void 0 : options.generateMipmaps : false;
|
|
202
|
+
return returnValue;
|
|
196
203
|
}
|
|
197
204
|
/**
|
|
198
205
|
* If using a disposable renderer, it will dispose it.
|
|
@@ -510,9 +517,19 @@ void main() {
|
|
|
510
517
|
sdr,
|
|
511
518
|
gainMap
|
|
512
519
|
});
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
520
|
+
const quadRenderer = new QuadRenderer({
|
|
521
|
+
// TODO: three types are generic, eslint complains here, see how we can solve
|
|
522
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
523
|
+
width: sdr.image.width,
|
|
524
|
+
// TODO: three types are generic, eslint complains here, see how we can solve
|
|
525
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
526
|
+
height: sdr.image.height,
|
|
527
|
+
type: three.HalfFloatType,
|
|
528
|
+
colorSpace: three.LinearSRGBColorSpace,
|
|
529
|
+
material,
|
|
530
|
+
renderer,
|
|
531
|
+
renderTargetOptions: params.renderTargetOptions
|
|
532
|
+
});
|
|
516
533
|
try {
|
|
517
534
|
quadRenderer.render();
|
|
518
535
|
}
|
|
@@ -829,6 +846,16 @@ void main() {
|
|
|
829
846
|
this._renderer = renderer;
|
|
830
847
|
this._internalLoadingManager = new three.LoadingManager();
|
|
831
848
|
}
|
|
849
|
+
/**
|
|
850
|
+
* Specify the renderTarget options to use when rendering the gain map
|
|
851
|
+
*
|
|
852
|
+
* @param options
|
|
853
|
+
* @returns
|
|
854
|
+
*/
|
|
855
|
+
setRenderTargetOptions(options) {
|
|
856
|
+
this._renderTargetOptions = options;
|
|
857
|
+
return this;
|
|
858
|
+
}
|
|
832
859
|
/**
|
|
833
860
|
* @private
|
|
834
861
|
* @returns
|
|
@@ -847,7 +874,15 @@ void main() {
|
|
|
847
874
|
gainMap: new three.Texture(),
|
|
848
875
|
sdr: new three.Texture()
|
|
849
876
|
});
|
|
850
|
-
return new QuadRenderer(
|
|
877
|
+
return new QuadRenderer({
|
|
878
|
+
width: 16,
|
|
879
|
+
height: 16,
|
|
880
|
+
type: three.HalfFloatType,
|
|
881
|
+
colorSpace: three.LinearSRGBColorSpace,
|
|
882
|
+
material,
|
|
883
|
+
renderer: this._renderer,
|
|
884
|
+
renderTargetOptions: this._renderTargetOptions
|
|
885
|
+
});
|
|
851
886
|
}
|
|
852
887
|
/**
|
|
853
888
|
* @private
|
|
@@ -937,14 +972,14 @@ void main() {
|
|
|
937
972
|
* scene.add(mesh)
|
|
938
973
|
* renderer.render(scene, new PerspectiveCamera())
|
|
939
974
|
*
|
|
940
|
-
* //
|
|
941
|
-
* //
|
|
942
|
-
* //
|
|
943
|
-
* //
|
|
944
|
-
*
|
|
945
|
-
*
|
|
975
|
+
* // Starting from three.js r159
|
|
976
|
+
* // `result.renderTarget.texture` can
|
|
977
|
+
* // also be used as Equirectangular scene background
|
|
978
|
+
* //
|
|
979
|
+
* // it was previously needed to convert it
|
|
980
|
+
* // to a DataTexture with `result.toDataTexture()`
|
|
981
|
+
* scene.background = result.renderTarget.texture
|
|
946
982
|
* scene.background.mapping = EquirectangularReflectionMapping
|
|
947
|
-
* scene.background.minFilter = LinearFilter
|
|
948
983
|
*
|
|
949
984
|
* // result must be manually disposed
|
|
950
985
|
* // when you are done using it
|
|
@@ -973,7 +1008,19 @@ void main() {
|
|
|
973
1008
|
let metadata;
|
|
974
1009
|
const loadCheck = async () => {
|
|
975
1010
|
if (sdr && gainMap && metadata) {
|
|
976
|
-
|
|
1011
|
+
// solves #16
|
|
1012
|
+
try {
|
|
1013
|
+
await this.render(quadRenderer, metadata, sdr, gainMap);
|
|
1014
|
+
}
|
|
1015
|
+
catch (error) {
|
|
1016
|
+
this.manager.itemError(sdrUrl);
|
|
1017
|
+
this.manager.itemError(gainMapUrl);
|
|
1018
|
+
this.manager.itemError(metadataUrl);
|
|
1019
|
+
if (typeof onError === 'function')
|
|
1020
|
+
onError(error);
|
|
1021
|
+
quadRenderer.disposeOnDemandRenderer();
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
977
1024
|
if (typeof onLoad === 'function')
|
|
978
1025
|
onLoad(quadRenderer);
|
|
979
1026
|
this.manager.itemEnd(sdrUrl);
|
|
@@ -1102,14 +1149,14 @@ void main() {
|
|
|
1102
1149
|
* scene.add(mesh)
|
|
1103
1150
|
* renderer.render(scene, new PerspectiveCamera())
|
|
1104
1151
|
*
|
|
1105
|
-
* //
|
|
1106
|
-
* //
|
|
1107
|
-
* //
|
|
1108
|
-
* //
|
|
1109
|
-
*
|
|
1110
|
-
*
|
|
1152
|
+
* // Starting from three.js r159
|
|
1153
|
+
* // `result.renderTarget.texture` can
|
|
1154
|
+
* // also be used as Equirectangular scene background
|
|
1155
|
+
* //
|
|
1156
|
+
* // it was previously needed to convert it
|
|
1157
|
+
* // to a DataTexture with `result.toDataTexture()`
|
|
1158
|
+
* scene.background = result.renderTarget.texture
|
|
1111
1159
|
* scene.background.mapping = EquirectangularReflectionMapping
|
|
1112
|
-
* scene.background.minFilter = LinearFilter
|
|
1113
1160
|
*
|
|
1114
1161
|
* // result must be manually disposed
|
|
1115
1162
|
* // when you are done using it
|
|
@@ -1168,7 +1215,17 @@ void main() {
|
|
|
1168
1215
|
throw e;
|
|
1169
1216
|
}
|
|
1170
1217
|
}
|
|
1171
|
-
|
|
1218
|
+
// solves #16
|
|
1219
|
+
try {
|
|
1220
|
+
await this.render(quadRenderer, metadata, sdrJPEG, gainMapJPEG);
|
|
1221
|
+
}
|
|
1222
|
+
catch (error) {
|
|
1223
|
+
this.manager.itemError(url);
|
|
1224
|
+
if (typeof onError === 'function')
|
|
1225
|
+
onError(error);
|
|
1226
|
+
quadRenderer.disposeOnDemandRenderer();
|
|
1227
|
+
return;
|
|
1228
|
+
}
|
|
1172
1229
|
if (typeof onLoad === 'function')
|
|
1173
1230
|
onLoad(quadRenderer);
|
|
1174
1231
|
this.manager.itemEnd(url);
|
|
@@ -1186,8 +1243,10 @@ void main() {
|
|
|
1186
1243
|
exports.GainMapLoader = GainMapLoader;
|
|
1187
1244
|
exports.HDRJPGLoader = HDRJPGLoader;
|
|
1188
1245
|
exports.JPEGRLoader = HDRJPGLoader;
|
|
1246
|
+
exports.MPFExtractor = MPFExtractor;
|
|
1189
1247
|
exports.QuadRenderer = QuadRenderer;
|
|
1190
1248
|
exports.decode = decode;
|
|
1191
1249
|
exports.extractGainmapFromJPEG = extractGainmapFromJPEG;
|
|
1250
|
+
exports.extractXMP = extractXMP;
|
|
1192
1251
|
|
|
1193
1252
|
}));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DataTexture, ToneMapping, WebGLRenderer } from 'three';
|
|
2
2
|
import { QuadRenderer } from '../core/QuadRenderer';
|
|
3
|
+
import { QuadRendererTextureOptions } from '../decode';
|
|
3
4
|
import { SDRMaterial } from './materials/SDRMaterial';
|
|
4
5
|
/**
|
|
5
6
|
* Renders an SDR Representation of an HDR Image
|
|
@@ -10,6 +11,7 @@ import { SDRMaterial } from './materials/SDRMaterial';
|
|
|
10
11
|
* @param hdrTexture The HDR image to be rendered
|
|
11
12
|
* @param renderer (optional) WebGLRenderer to use during the rendering, a disposable renderer will be create and destroyed if this is not provided.
|
|
12
13
|
* @param toneMapping (optional) Tone mapping to be applied to the SDR Rendition
|
|
14
|
+
* @param renderTargetOptions (optional) Options to use when creating the output renderTarget
|
|
13
15
|
* @throws {Error} if the WebGLRenderer fails to render the SDR image
|
|
14
16
|
*/
|
|
15
|
-
export declare const getSDRRendition: (hdrTexture: DataTexture, renderer?: WebGLRenderer, toneMapping?: ToneMapping) => QuadRenderer<1009, SDRMaterial>;
|
|
17
|
+
export declare const getSDRRendition: (hdrTexture: DataTexture, renderer?: WebGLRenderer, toneMapping?: ToneMapping, renderTargetOptions?: QuadRendererTextureOptions) => QuadRenderer<1009, SDRMaterial>;
|
package/dist/encode/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type DataTexture, ToneMapping, WebGLRenderer } from 'three';
|
|
|
2
2
|
import { type EXR } from 'three/examples/jsm/loaders/EXRLoader';
|
|
3
3
|
import { type LogLuv } from 'three/examples/jsm/loaders/LogLuvLoader';
|
|
4
4
|
import { type RGBE } from 'three/examples/jsm/loaders/RGBELoader';
|
|
5
|
+
import { QuadRendererTextureOptions } from '../decode';
|
|
5
6
|
import { WorkerInterfaceImplementation } from '../worker-types';
|
|
6
7
|
/**
|
|
7
8
|
* Parameters used by content Creators in order to create a GainMap
|
|
@@ -82,6 +83,10 @@ export type EncodingParametersBase = GainmapEncodingParameters & {
|
|
|
82
83
|
* @defaultValue `ACESFilmicToneMapping`
|
|
83
84
|
*/
|
|
84
85
|
toneMapping?: ToneMapping;
|
|
86
|
+
/**
|
|
87
|
+
* Options to use when creating the output renderTarget
|
|
88
|
+
*/
|
|
89
|
+
renderTargetOptions?: QuadRendererTextureOptions;
|
|
85
90
|
};
|
|
86
91
|
/**
|
|
87
92
|
* This library can provide gainmap compressed in these mimeTypes
|
package/dist/encode.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js
|
|
2
|
+
* @monogrid/gainmap-js v3.0.1
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { c as compress } from './compress-
|
|
6
|
+
import { c as compress } from './compress-6L6-d1aM.js';
|
|
7
7
|
import { DataTexture, RGBAFormat, UVMapping, RepeatWrapping, LinearFilter, LinearSRGBColorSpace, ShaderMaterial, Vector3, NoBlending, UnsignedByteType, ACESFilmicToneMapping, LinearToneMapping, CineonToneMapping, ReinhardToneMapping, SRGBColorSpace, Vector2, WebGLRenderTarget, NearestFilter, ClampToEdgeWrapping, FloatType, DataUtils } from 'three';
|
|
8
|
-
import { Q as QuadRenderer } from './QuadRenderer-
|
|
8
|
+
import { Q as QuadRenderer } from './QuadRenderer-pEe6Kzcn.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Utility function to obtain a `DataTexture` from various input formats
|
|
@@ -177,7 +177,7 @@ class GainMapEncoderMaterial extends ShaderMaterial {
|
|
|
177
177
|
* @see {@link GainMapMetadata.hdrCapacityMax}
|
|
178
178
|
* @remarks Logarithmic space
|
|
179
179
|
*/
|
|
180
|
-
get hdrCapacityMax() { return Math.
|
|
180
|
+
get hdrCapacityMax() { return Math.max(Math.max(0, this.gainMapMax[0]), Math.max(0, this.gainMapMax[1]), Math.max(0, this.gainMapMax[2])); }
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
/**
|
|
@@ -195,7 +195,15 @@ const getGainMap = (params) => {
|
|
|
195
195
|
sdr: sdr.renderTarget.texture,
|
|
196
196
|
hdr: dataTexture
|
|
197
197
|
});
|
|
198
|
-
const quadRenderer = new QuadRenderer(
|
|
198
|
+
const quadRenderer = new QuadRenderer({
|
|
199
|
+
width: dataTexture.image.width,
|
|
200
|
+
height: dataTexture.image.height,
|
|
201
|
+
type: UnsignedByteType,
|
|
202
|
+
colorSpace: LinearSRGBColorSpace,
|
|
203
|
+
material,
|
|
204
|
+
renderer,
|
|
205
|
+
renderTargetOptions: params.renderTargetOptions
|
|
206
|
+
});
|
|
199
207
|
try {
|
|
200
208
|
quadRenderer.render();
|
|
201
209
|
}
|
|
@@ -418,11 +426,20 @@ class SDRMaterial extends ShaderMaterial {
|
|
|
418
426
|
* @param hdrTexture The HDR image to be rendered
|
|
419
427
|
* @param renderer (optional) WebGLRenderer to use during the rendering, a disposable renderer will be create and destroyed if this is not provided.
|
|
420
428
|
* @param toneMapping (optional) Tone mapping to be applied to the SDR Rendition
|
|
429
|
+
* @param renderTargetOptions (optional) Options to use when creating the output renderTarget
|
|
421
430
|
* @throws {Error} if the WebGLRenderer fails to render the SDR image
|
|
422
431
|
*/
|
|
423
|
-
const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
|
|
432
|
+
const getSDRRendition = (hdrTexture, renderer, toneMapping, renderTargetOptions) => {
|
|
424
433
|
hdrTexture.needsUpdate = true;
|
|
425
|
-
const quadRenderer = new QuadRenderer(
|
|
434
|
+
const quadRenderer = new QuadRenderer({
|
|
435
|
+
width: hdrTexture.image.width,
|
|
436
|
+
height: hdrTexture.image.height,
|
|
437
|
+
type: UnsignedByteType,
|
|
438
|
+
colorSpace: SRGBColorSpace,
|
|
439
|
+
material: new SDRMaterial({ map: hdrTexture, toneMapping }),
|
|
440
|
+
renderer,
|
|
441
|
+
renderTargetOptions
|
|
442
|
+
});
|
|
426
443
|
try {
|
|
427
444
|
quadRenderer.render();
|
|
428
445
|
}
|
|
@@ -489,7 +506,7 @@ const getSDRRendition = (hdrTexture, renderer, toneMapping) => {
|
|
|
489
506
|
const encode = (params) => {
|
|
490
507
|
const { image, renderer } = params;
|
|
491
508
|
const dataTexture = getDataTexture(image);
|
|
492
|
-
const sdr = getSDRRendition(dataTexture, renderer, params.toneMapping);
|
|
509
|
+
const sdr = getSDRRendition(dataTexture, renderer, params.toneMapping, params.renderTargetOptions);
|
|
493
510
|
const gainMapRenderer = getGainMap({
|
|
494
511
|
...params,
|
|
495
512
|
image: dataTexture,
|
|
@@ -501,7 +518,7 @@ const encode = (params) => {
|
|
|
501
518
|
gainMap: gainMapRenderer,
|
|
502
519
|
hdr: dataTexture,
|
|
503
520
|
getMetadata: () => {
|
|
504
|
-
|
|
521
|
+
return {
|
|
505
522
|
gainMapMax: gainMapRenderer.material.gainMapMax,
|
|
506
523
|
gainMapMin: gainMapRenderer.material.gainMapMin,
|
|
507
524
|
gamma: gainMapRenderer.material.gamma,
|
|
@@ -510,7 +527,6 @@ const encode = (params) => {
|
|
|
510
527
|
offsetHdr: gainMapRenderer.material.offsetHdr,
|
|
511
528
|
offsetSdr: gainMapRenderer.material.offsetSdr
|
|
512
529
|
};
|
|
513
|
-
return meta;
|
|
514
530
|
}
|
|
515
531
|
};
|
|
516
532
|
};
|
|
@@ -635,6 +651,10 @@ precision mediump float;
|
|
|
635
651
|
#define COMPARE_FUNCTION max
|
|
636
652
|
#endif
|
|
637
653
|
|
|
654
|
+
#ifndef INITIAL_VALUE
|
|
655
|
+
#define INITIAL_VALUE 0
|
|
656
|
+
#endif
|
|
657
|
+
|
|
638
658
|
uniform sampler2D map;
|
|
639
659
|
uniform vec2 u_srcResolution;
|
|
640
660
|
|
|
@@ -650,7 +670,8 @@ void main() {
|
|
|
650
670
|
// uv for first pixel in cell. +0.5 for center of pixel
|
|
651
671
|
vec2 uv = (srcPixel + 0.5) * onePixel;
|
|
652
672
|
|
|
653
|
-
vec4 resultColor = vec4(
|
|
673
|
+
vec4 resultColor = vec4(INITIAL_VALUE);
|
|
674
|
+
|
|
654
675
|
for (int y = 0; y < CELL_SIZE; ++y) {
|
|
655
676
|
for (int x = 0; x < CELL_SIZE; ++x) {
|
|
656
677
|
resultColor = COMPARE_FUNCTION(resultColor, texture2D(map, uv + vec2(x, y) * onePixel));
|
|
@@ -682,14 +703,22 @@ const findTextureMinMax = (image, mode = 'max', renderer) => {
|
|
|
682
703
|
},
|
|
683
704
|
defines: {
|
|
684
705
|
CELL_SIZE: cellSize,
|
|
685
|
-
COMPARE_FUNCTION: mode
|
|
706
|
+
COMPARE_FUNCTION: mode,
|
|
707
|
+
INITIAL_VALUE: mode === 'max' ? 0 : 65504 // max half float value
|
|
686
708
|
}
|
|
687
709
|
});
|
|
688
710
|
srcTex.needsUpdate = true;
|
|
689
711
|
mat.needsUpdate = true;
|
|
690
712
|
let w = srcTex.image.width;
|
|
691
713
|
let h = srcTex.image.height;
|
|
692
|
-
const quadRenderer = new QuadRenderer(
|
|
714
|
+
const quadRenderer = new QuadRenderer({
|
|
715
|
+
width: w,
|
|
716
|
+
height: h,
|
|
717
|
+
type: srcTex.type,
|
|
718
|
+
colorSpace: srcTex.colorSpace,
|
|
719
|
+
material: mat,
|
|
720
|
+
renderer
|
|
721
|
+
});
|
|
693
722
|
const frameBuffers = [];
|
|
694
723
|
while (w > 1 || h > 1) {
|
|
695
724
|
w = Math.max(1, (w + cellSize - 1) / cellSize | 0);
|