@luma.gl/engine 9.1.0-alpha.9 → 9.1.0-beta.11
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/dist/animation/key-frames.js +1 -0
- package/dist/animation/key-frames.js.map +1 -0
- package/dist/animation/timeline.js +1 -0
- package/dist/animation/timeline.js.map +1 -0
- package/dist/animation-loop/animation-loop-template.js +1 -0
- package/dist/animation-loop/animation-loop-template.js.map +1 -0
- package/dist/animation-loop/animation-loop.d.ts +2 -0
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +24 -6
- package/dist/animation-loop/animation-loop.js.map +1 -0
- package/dist/animation-loop/animation-props.js +1 -0
- package/dist/animation-loop/animation-props.js.map +1 -0
- package/dist/animation-loop/make-animation-loop.d.ts +5 -1
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +3 -1
- package/dist/animation-loop/make-animation-loop.js.map +1 -0
- package/dist/animation-loop/request-animation-frame.d.ts +4 -2
- package/dist/animation-loop/request-animation-frame.d.ts.map +1 -1
- package/dist/animation-loop/request-animation-frame.js +5 -3
- package/dist/animation-loop/request-animation-frame.js.map +1 -0
- package/dist/application-utils/load-file.d.ts +1 -1
- package/dist/application-utils/load-file.d.ts.map +1 -1
- package/dist/application-utils/load-file.js +2 -2
- package/dist/application-utils/load-file.js.map +1 -0
- package/dist/application-utils/random.js +1 -0
- package/dist/application-utils/random.js.map +1 -0
- package/dist/async-texture/async-texture.d.ts +14 -2
- package/dist/async-texture/async-texture.d.ts.map +1 -1
- package/dist/async-texture/async-texture.js +31 -0
- package/dist/async-texture/async-texture.js.map +1 -0
- package/dist/compute/buffer-transform.d.ts +41 -0
- package/dist/compute/buffer-transform.d.ts.map +1 -0
- package/dist/{transform → compute}/buffer-transform.js +19 -12
- package/dist/compute/buffer-transform.js.map +1 -0
- package/dist/{computation.d.ts → compute/computation.d.ts} +3 -3
- package/dist/compute/computation.d.ts.map +1 -0
- package/dist/{computation.js → compute/computation.js} +7 -8
- package/dist/compute/computation.js.map +1 -0
- package/dist/compute/swap.d.ts +48 -0
- package/dist/compute/swap.d.ts.map +1 -0
- package/dist/compute/swap.js +91 -0
- package/dist/compute/swap.js.map +1 -0
- package/dist/{transform → compute}/texture-transform.d.ts +0 -6
- package/dist/compute/texture-transform.d.ts.map +1 -0
- package/dist/{transform → compute}/texture-transform.js +7 -13
- package/dist/compute/texture-transform.js.map +1 -0
- package/dist/debug/copy-texture-to-image.js +1 -0
- package/dist/debug/copy-texture-to-image.js.map +1 -0
- package/dist/debug/debug-framebuffer.js +2 -1
- package/dist/debug/debug-framebuffer.js.map +1 -0
- package/dist/debug/debug-shader-layout.js +2 -1
- package/dist/debug/debug-shader-layout.js.map +1 -0
- package/dist/debug/pixel-data-utils.js +1 -0
- package/dist/debug/pixel-data-utils.js.map +1 -0
- package/dist/dist.dev.js +2588 -5862
- package/dist/dist.min.js +420 -103
- package/dist/factories/pipeline-factory.d.ts.map +1 -0
- package/dist/{lib → factories}/pipeline-factory.js +1 -0
- package/dist/factories/pipeline-factory.js.map +1 -0
- package/dist/factories/shader-factory.d.ts.map +1 -0
- package/dist/{lib → factories}/shader-factory.js +1 -0
- package/dist/factories/shader-factory.js.map +1 -0
- package/dist/geometries/cone-geometry.js +1 -0
- package/dist/geometries/cone-geometry.js.map +1 -0
- package/dist/geometries/cube-geometry.js +1 -0
- package/dist/geometries/cube-geometry.js.map +1 -0
- package/dist/geometries/cylinder-geometry.js +1 -0
- package/dist/geometries/cylinder-geometry.js.map +1 -0
- package/dist/geometries/ico-sphere-geometry.js +1 -0
- package/dist/geometries/ico-sphere-geometry.js.map +1 -0
- package/dist/geometries/plane-geometry.js +1 -0
- package/dist/geometries/plane-geometry.js.map +1 -0
- package/dist/geometries/sphere-geometry.js +1 -0
- package/dist/geometries/sphere-geometry.js.map +1 -0
- package/dist/geometries/truncated-cone-geometry.js +1 -0
- package/dist/geometries/truncated-cone-geometry.js.map +1 -0
- package/dist/geometry/geometry-table.js +1 -0
- package/dist/geometry/geometry-table.js.map +1 -0
- package/dist/geometry/geometry-utils.js +1 -0
- package/dist/geometry/geometry-utils.js.map +1 -0
- package/dist/geometry/geometry.js +1 -0
- package/dist/geometry/geometry.js.map +1 -0
- package/dist/geometry/gpu-geometry.js +1 -0
- package/dist/geometry/gpu-geometry.js.map +1 -0
- package/dist/geometry/gpu-table.js +1 -0
- package/dist/geometry/gpu-table.js.map +1 -0
- package/dist/index.cjs +1268 -173
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +23 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -9
- package/dist/index.js.map +1 -0
- package/dist/model/model.d.ts +11 -10
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +77 -58
- package/dist/model/model.js.map +1 -0
- package/dist/model/split-uniforms-and-bindings.d.ts +1 -1
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js +2 -1
- package/dist/model/split-uniforms-and-bindings.js.map +1 -0
- package/dist/models/billboard-texture-model.d.ts +23 -0
- package/dist/models/billboard-texture-model.d.ts.map +1 -0
- package/dist/models/billboard-texture-model.js +78 -0
- package/dist/models/billboard-texture-model.js.map +1 -0
- package/dist/models/billboard-texture-module.d.ts +10 -0
- package/dist/models/billboard-texture-module.d.ts.map +1 -0
- package/dist/models/billboard-texture-module.js +37 -0
- package/dist/models/billboard-texture-module.js.map +1 -0
- package/dist/{lib → models}/clip-space.d.ts +3 -1
- package/dist/models/clip-space.d.ts.map +1 -0
- package/dist/models/clip-space.js +77 -0
- package/dist/models/clip-space.js.map +1 -0
- package/dist/modules/picking/color-picking.d.ts +28 -0
- package/dist/modules/picking/color-picking.d.ts.map +1 -0
- package/dist/modules/picking/color-picking.js +177 -0
- package/dist/modules/picking/color-picking.js.map +1 -0
- package/dist/modules/picking/index-picking.d.ts +32 -0
- package/dist/modules/picking/index-picking.d.ts.map +1 -0
- package/dist/modules/picking/index-picking.js +148 -0
- package/dist/modules/picking/index-picking.js.map +1 -0
- package/dist/modules/picking/legacy-picking-manager.d.ts +27 -0
- package/dist/modules/picking/legacy-picking-manager.d.ts.map +1 -0
- package/dist/modules/picking/legacy-picking-manager.js +76 -0
- package/dist/modules/picking/legacy-picking-manager.js.map +1 -0
- package/dist/modules/picking/picking-manager.d.ts +45 -0
- package/dist/modules/picking/picking-manager.d.ts.map +1 -0
- package/dist/modules/picking/picking-manager.js +101 -0
- package/dist/modules/picking/picking-manager.js.map +1 -0
- package/dist/modules/picking/picking-uniforms.d.ts +79 -0
- package/dist/modules/picking/picking-uniforms.d.ts.map +1 -0
- package/dist/modules/picking/picking-uniforms.js +109 -0
- package/dist/modules/picking/picking-uniforms.js.map +1 -0
- package/dist/passes/get-fragment-shader.d.ts +12 -0
- package/dist/passes/get-fragment-shader.d.ts.map +1 -0
- package/dist/passes/get-fragment-shader.js +117 -0
- package/dist/passes/get-fragment-shader.js.map +1 -0
- package/dist/passes/shader-pass-renderer.d.ts +63 -0
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -0
- package/dist/passes/shader-pass-renderer.js +197 -0
- package/dist/passes/shader-pass-renderer.js.map +1 -0
- package/dist/scenegraph/group-node.js +1 -0
- package/dist/scenegraph/group-node.js.map +1 -0
- package/dist/scenegraph/model-node.js +1 -0
- package/dist/scenegraph/model-node.js.map +1 -0
- package/dist/scenegraph/scenegraph-node.js +1 -0
- package/dist/scenegraph/scenegraph-node.js.map +1 -0
- package/dist/shader-inputs.d.ts +8 -21
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +15 -11
- package/dist/shader-inputs.js.map +1 -0
- package/dist/utils/deep-equal.js +1 -0
- package/dist/utils/deep-equal.js.map +1 -0
- package/dist/utils/uid.js +1 -0
- package/dist/utils/uid.js.map +1 -0
- package/package.json +6 -6
- package/src/animation-loop/animation-loop.ts +27 -6
- package/src/animation-loop/make-animation-loop.ts +8 -3
- package/src/animation-loop/request-animation-frame.ts +4 -3
- package/src/application-utils/load-file.ts +2 -4
- package/src/async-texture/async-texture.ts +39 -7
- package/src/{transform → compute}/buffer-transform.ts +30 -14
- package/src/{computation.ts → compute/computation.ts} +14 -8
- package/src/compute/swap.ts +116 -0
- package/src/{transform → compute}/texture-transform.ts +6 -16
- package/src/debug/debug-framebuffer.ts +1 -1
- package/src/debug/debug-shader-layout.ts +1 -1
- package/src/index.ts +35 -16
- package/src/model/model.ts +116 -66
- package/src/model/split-uniforms-and-bindings.ts +4 -4
- package/src/models/billboard-texture-model.ts +98 -0
- package/src/models/billboard-texture-module.ts +49 -0
- package/src/models/clip-space.ts +88 -0
- package/src/modules/picking/README.md +88 -0
- package/src/modules/picking/color-picking.ts +190 -0
- package/src/modules/picking/index-picking.ts +156 -0
- package/src/modules/picking/legacy-picking-manager.ts +99 -0
- package/src/modules/picking/picking-manager.ts +137 -0
- package/src/modules/picking/picking-uniforms.ts +179 -0
- package/src/passes/get-fragment-shader.ts +129 -0
- package/src/passes/shader-pass-renderer.ts +252 -0
- package/src/shader-inputs.ts +27 -48
- package/dist/computation.d.ts.map +0 -1
- package/dist/lib/clip-space.d.ts.map +0 -1
- package/dist/lib/clip-space.js +0 -46
- package/dist/lib/pipeline-factory.d.ts.map +0 -1
- package/dist/lib/shader-factory.d.ts.map +0 -1
- package/dist/transform/buffer-transform.d.ts +0 -35
- package/dist/transform/buffer-transform.d.ts.map +0 -1
- package/dist/transform/texture-transform.d.ts.map +0 -1
- package/src/lib/clip-space.ts +0 -53
- /package/dist/{lib → factories}/pipeline-factory.d.ts +0 -0
- /package/dist/{lib → factories}/shader-factory.d.ts +0 -0
- /package/src/{lib → factories}/pipeline-factory.ts +0 -0
- /package/src/{lib → factories}/shader-factory.ts +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Device, Framebuffer } from '@luma.gl/core';
|
|
2
|
+
import { picking } from '@luma.gl/shadertools';
|
|
3
|
+
import { ShaderInputs } from "../../shader-inputs.js";
|
|
4
|
+
/**
|
|
5
|
+
* Helper class for using the legacy picking module
|
|
6
|
+
*/
|
|
7
|
+
export declare class LegacyPickingManager {
|
|
8
|
+
device: Device;
|
|
9
|
+
framebuffer: Framebuffer | null;
|
|
10
|
+
shaderInputs: ShaderInputs<{
|
|
11
|
+
picking: typeof picking.props;
|
|
12
|
+
}>;
|
|
13
|
+
constructor(device: Device, shaderInputs: ShaderInputs);
|
|
14
|
+
destroy(): void;
|
|
15
|
+
getFramebuffer(): Framebuffer;
|
|
16
|
+
/** Clear highlighted / picked object */
|
|
17
|
+
clearPickState(): void;
|
|
18
|
+
/** Prepare for rendering picking colors */
|
|
19
|
+
beginRenderPass(): import("@luma.gl/core").RenderPass;
|
|
20
|
+
updatePickState(mousePosition: [number, number]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Get pick position in device pixel range
|
|
23
|
+
* use the center pixel location in device pixel range
|
|
24
|
+
*/
|
|
25
|
+
getPickPosition(mousePosition: number[]): [number, number];
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=legacy-picking-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-picking-manager.d.ts","sourceRoot":"","sources":["../../../src/modules/picking/legacy-picking-manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAC,YAAY,EAAC,+BAA4B;AAGjD;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,WAAW,GAAG,IAAI,CAAQ;IACvC,YAAY,EAAE,YAAY,CAAC;QAAC,OAAO,EAAE,OAAO,OAAO,CAAC,KAAK,CAAA;KAAC,CAAC,CAAC;gBAEhD,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY;IAKtD,OAAO;IAIP,cAAc;IAUd,wCAAwC;IACxC,cAAc;IAId,2CAA2C;IAC3C,eAAe;IAef,eAAe,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IA+B/C;;;OAGG;IACH,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;CAM3D"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* Helper class for using the legacy picking module
|
|
6
|
+
*/
|
|
7
|
+
export class LegacyPickingManager {
|
|
8
|
+
device;
|
|
9
|
+
framebuffer = null;
|
|
10
|
+
shaderInputs;
|
|
11
|
+
constructor(device, shaderInputs) {
|
|
12
|
+
this.device = device;
|
|
13
|
+
this.shaderInputs = shaderInputs;
|
|
14
|
+
}
|
|
15
|
+
destroy() {
|
|
16
|
+
this.framebuffer?.destroy();
|
|
17
|
+
}
|
|
18
|
+
getFramebuffer() {
|
|
19
|
+
if (!this.framebuffer) {
|
|
20
|
+
this.framebuffer = this.device.createFramebuffer({
|
|
21
|
+
colorAttachments: ['rgba8unorm'],
|
|
22
|
+
depthStencilAttachment: 'depth24plus'
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return this.framebuffer;
|
|
26
|
+
}
|
|
27
|
+
/** Clear highlighted / picked object */
|
|
28
|
+
clearPickState() {
|
|
29
|
+
this.shaderInputs.setProps({ picking: { highlightedObjectColor: null } });
|
|
30
|
+
}
|
|
31
|
+
/** Prepare for rendering picking colors */
|
|
32
|
+
beginRenderPass() {
|
|
33
|
+
const framebuffer = this.getFramebuffer();
|
|
34
|
+
framebuffer.resize(this.device.getCanvasContext().getPixelSize());
|
|
35
|
+
this.shaderInputs.setProps({ picking: { isActive: true } });
|
|
36
|
+
const pickingPass = this.device.beginRenderPass({
|
|
37
|
+
framebuffer,
|
|
38
|
+
clearColor: [0, 0, 0, 0],
|
|
39
|
+
clearDepth: 1
|
|
40
|
+
});
|
|
41
|
+
return pickingPass;
|
|
42
|
+
}
|
|
43
|
+
updatePickState(mousePosition) {
|
|
44
|
+
const framebuffer = this.getFramebuffer();
|
|
45
|
+
// use the center pixel location in device pixel range
|
|
46
|
+
const [pickX, pickY] = this.getPickPosition(mousePosition);
|
|
47
|
+
// Read back
|
|
48
|
+
const color255 = this.device.readPixelsToArrayWebGL(framebuffer, {
|
|
49
|
+
sourceX: pickX,
|
|
50
|
+
sourceY: pickY,
|
|
51
|
+
sourceWidth: 1,
|
|
52
|
+
sourceHeight: 1
|
|
53
|
+
});
|
|
54
|
+
// console.log(color255);
|
|
55
|
+
// Check if we have
|
|
56
|
+
let highlightedObjectColor = [...color255].map(x => x / 255);
|
|
57
|
+
const isHighlightActive = highlightedObjectColor[0] + highlightedObjectColor[1] + highlightedObjectColor[2] > 0;
|
|
58
|
+
if (!isHighlightActive) {
|
|
59
|
+
highlightedObjectColor = null;
|
|
60
|
+
}
|
|
61
|
+
this.shaderInputs.setProps({
|
|
62
|
+
picking: { isActive: false, highlightedObjectColor }
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get pick position in device pixel range
|
|
67
|
+
* use the center pixel location in device pixel range
|
|
68
|
+
*/
|
|
69
|
+
getPickPosition(mousePosition) {
|
|
70
|
+
const devicePixels = this.device.getCanvasContext().cssToDevicePixels(mousePosition);
|
|
71
|
+
const pickX = devicePixels.x + Math.floor(devicePixels.width / 2);
|
|
72
|
+
const pickY = devicePixels.y + Math.floor(devicePixels.height / 2);
|
|
73
|
+
return [pickX, pickY];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=legacy-picking-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-picking-manager.js","sourceRoot":"","sources":["../../../src/modules/picking/legacy-picking-manager.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GAAG,YAAY,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACnE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Device, Framebuffer } from '@luma.gl/core';
|
|
2
|
+
import { ShaderInputs } from "../../shader-inputs.js";
|
|
3
|
+
import { pickingUniforms } from "./picking-uniforms.js";
|
|
4
|
+
/** Information about picked object */
|
|
5
|
+
export type PickInfo = {
|
|
6
|
+
batchIndex: number | null;
|
|
7
|
+
objectIndex: number | null;
|
|
8
|
+
};
|
|
9
|
+
export type PickingManagerProps = {
|
|
10
|
+
/** Shader Inputs from models to pick */
|
|
11
|
+
shaderInputs?: ShaderInputs<{
|
|
12
|
+
picking: typeof pickingUniforms.props;
|
|
13
|
+
}>;
|
|
14
|
+
/** Callback */
|
|
15
|
+
onObjectPicked?: (info: PickInfo) => void;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Helper class for using the new picking module
|
|
19
|
+
* @todo Port to WebGPU
|
|
20
|
+
* @todo Support multiple models
|
|
21
|
+
* @todo Switching picking module
|
|
22
|
+
*/
|
|
23
|
+
export declare class PickingManager {
|
|
24
|
+
device: Device;
|
|
25
|
+
props: Required<PickingManagerProps>;
|
|
26
|
+
/** Info from latest pick operation */
|
|
27
|
+
pickInfo: PickInfo;
|
|
28
|
+
/** Framebuffer used for picking */
|
|
29
|
+
framebuffer: Framebuffer | null;
|
|
30
|
+
static defaultProps: Required<PickingManagerProps>;
|
|
31
|
+
constructor(device: Device, props: PickingManagerProps);
|
|
32
|
+
destroy(): void;
|
|
33
|
+
getFramebuffer(): Framebuffer;
|
|
34
|
+
/** Clear highlighted / picked object */
|
|
35
|
+
clearPickState(): void;
|
|
36
|
+
/** Prepare for rendering picking colors */
|
|
37
|
+
beginRenderPass(): import("@luma.gl/core").RenderPass;
|
|
38
|
+
getPickInfo(mousePosition: [number, number]): PickInfo | null;
|
|
39
|
+
/**
|
|
40
|
+
* Get pick position in device pixel range
|
|
41
|
+
* use the center pixel location in device pixel range
|
|
42
|
+
*/
|
|
43
|
+
getPickPosition(mousePosition: number[]): [number, number];
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=picking-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"picking-manager.d.ts","sourceRoot":"","sources":["../../../src/modules/picking/picking-manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,EAAC,YAAY,EAAC,+BAA4B;AACjD,OAAO,EAAC,eAAe,EAAgB,8BAA2B;AAGlE,sCAAsC;AACtC,MAAM,MAAM,QAAQ,GAAG;IACrB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,wCAAwC;IACxC,YAAY,CAAC,EAAE,YAAY,CAAC;QAAC,OAAO,EAAE,OAAO,eAAe,CAAC,KAAK,CAAA;KAAC,CAAC,CAAC;IACrE,eAAe;IACf,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IACrC,sCAAsC;IACtC,QAAQ,EAAE,QAAQ,CAAyC;IAC3D,mCAAmC;IACnC,WAAW,EAAE,WAAW,GAAG,IAAI,CAAQ;IAEvC,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAGhD;gBAEU,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB;IAKtD,OAAO;IAKP,cAAc;IAUd,wCAAwC;IACxC,cAAc;IAId,2CAA2C;IAC3C,eAAe;IAef,WAAW,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,QAAQ,GAAG,IAAI;IA4C7D;;;OAGG;IACH,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;CAM3D"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { INVALID_INDEX } from "./picking-uniforms.js";
|
|
5
|
+
/**
|
|
6
|
+
* Helper class for using the new picking module
|
|
7
|
+
* @todo Port to WebGPU
|
|
8
|
+
* @todo Support multiple models
|
|
9
|
+
* @todo Switching picking module
|
|
10
|
+
*/
|
|
11
|
+
export class PickingManager {
|
|
12
|
+
device;
|
|
13
|
+
props;
|
|
14
|
+
/** Info from latest pick operation */
|
|
15
|
+
pickInfo = { batchIndex: null, objectIndex: null };
|
|
16
|
+
/** Framebuffer used for picking */
|
|
17
|
+
framebuffer = null;
|
|
18
|
+
static defaultProps = {
|
|
19
|
+
shaderInputs: undefined,
|
|
20
|
+
onObjectPicked: () => { }
|
|
21
|
+
};
|
|
22
|
+
constructor(device, props) {
|
|
23
|
+
this.device = device;
|
|
24
|
+
this.props = { ...PickingManager.defaultProps, ...props };
|
|
25
|
+
}
|
|
26
|
+
destroy() {
|
|
27
|
+
this.framebuffer?.destroy();
|
|
28
|
+
}
|
|
29
|
+
// TODO - Ask for a cached framebuffer? a Framebuffer factory?
|
|
30
|
+
getFramebuffer() {
|
|
31
|
+
if (!this.framebuffer) {
|
|
32
|
+
this.framebuffer = this.device.createFramebuffer({
|
|
33
|
+
colorAttachments: ['rgba8unorm', 'rg32sint'],
|
|
34
|
+
depthStencilAttachment: 'depth24plus'
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return this.framebuffer;
|
|
38
|
+
}
|
|
39
|
+
/** Clear highlighted / picked object */
|
|
40
|
+
clearPickState() {
|
|
41
|
+
this.props.shaderInputs.setProps({ picking: { highlightedObjectIndex: null } });
|
|
42
|
+
}
|
|
43
|
+
/** Prepare for rendering picking colors */
|
|
44
|
+
beginRenderPass() {
|
|
45
|
+
const framebuffer = this.getFramebuffer();
|
|
46
|
+
framebuffer.resize(this.device.getDefaultCanvasContext().getPixelSize());
|
|
47
|
+
this.props.shaderInputs?.setProps({ picking: { isActive: true } });
|
|
48
|
+
const pickingPass = this.device.beginRenderPass({
|
|
49
|
+
framebuffer,
|
|
50
|
+
clearColors: [new Float32Array([0, 0, 0, 0]), new Int32Array([-1, -1, 0, 0])],
|
|
51
|
+
clearDepth: 1
|
|
52
|
+
});
|
|
53
|
+
return pickingPass;
|
|
54
|
+
}
|
|
55
|
+
getPickInfo(mousePosition) {
|
|
56
|
+
const framebuffer = this.getFramebuffer();
|
|
57
|
+
// use the center pixel location in device pixel range
|
|
58
|
+
const [pickX, pickY] = this.getPickPosition(mousePosition);
|
|
59
|
+
// Read back
|
|
60
|
+
const pixelData = this.device.readPixelsToArrayWebGL(framebuffer, {
|
|
61
|
+
sourceX: pickX,
|
|
62
|
+
sourceY: pickY,
|
|
63
|
+
sourceWidth: 1,
|
|
64
|
+
sourceHeight: 1,
|
|
65
|
+
sourceAttachment: 1
|
|
66
|
+
});
|
|
67
|
+
if (!pixelData) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const pickInfo = {
|
|
71
|
+
objectIndex: pixelData[0] === INVALID_INDEX ? null : pixelData[0],
|
|
72
|
+
batchIndex: pixelData[1] === INVALID_INDEX ? null : pixelData[1]
|
|
73
|
+
};
|
|
74
|
+
// Call callback if picked object has changed
|
|
75
|
+
if (pickInfo.objectIndex !== this.pickInfo.objectIndex ||
|
|
76
|
+
pickInfo.batchIndex !== this.pickInfo.batchIndex) {
|
|
77
|
+
this.pickInfo = pickInfo;
|
|
78
|
+
this.props.onObjectPicked(pickInfo);
|
|
79
|
+
// console.log(`Object ${pickInfo.objectIndex} in batch ${pickInfo.batchIndex} was picked`)
|
|
80
|
+
}
|
|
81
|
+
this.props.shaderInputs?.setProps({
|
|
82
|
+
picking: {
|
|
83
|
+
isActive: false,
|
|
84
|
+
highlightedBatchIndex: pickInfo.batchIndex,
|
|
85
|
+
highlightedObjectIndex: pickInfo.objectIndex
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return this.pickInfo;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get pick position in device pixel range
|
|
92
|
+
* use the center pixel location in device pixel range
|
|
93
|
+
*/
|
|
94
|
+
getPickPosition(mousePosition) {
|
|
95
|
+
const devicePixels = this.device.getDefaultCanvasContext().cssToDevicePixels(mousePosition);
|
|
96
|
+
const pickX = devicePixels.x + Math.floor(devicePixels.width / 2);
|
|
97
|
+
const pickY = devicePixels.y + Math.floor(devicePixels.height / 2);
|
|
98
|
+
return [pickX, pickY];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=picking-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"picking-manager.js","sourceRoot":"","sources":["../../../src/modules/picking/picking-manager.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAkB,aAAa,EAAC,8BAA2B;AAgBlE;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IACzB,MAAM,CAAS;IACf,KAAK,CAAgC;IACrC,sCAAsC;IACtC,QAAQ,GAAa,EAAC,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;IAC3D,mCAAmC;IACnC,WAAW,GAAuB,IAAI,CAAC;IAEvC,MAAM,CAAC,YAAY,GAAkC;QACnD,YAAY,EAAE,SAAU;QACxB,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;KACzB,CAAC;IAEF,YAAY,MAAc,E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AE;gBACP,QAAQ,EAAE,KAAK;gBACf,qBAAqB,EAAE,QAAQ,CAAC,UAAU;gBAC1C,sBAAsB,EAAE,QAAQ,CAAC,WAAW;aAC7C;SACF,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,aAAuB;QACrC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,uBAAuB,EAAE,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;QAC5F,MAAM,KAAK,GAAG,YAAY,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAClE,MAAM,KAAK,GAAG,YAAY,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACnE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { NumberArray4 } from '@math.gl/types';
|
|
2
|
+
export declare const INVALID_INDEX = -1;
|
|
3
|
+
/**
|
|
4
|
+
* Props for the picking module, which depending on mode renders picking colors or highlighted item.
|
|
5
|
+
* When active, renders picking colors, assumed to be rendered to off-screen "picking" buffer.
|
|
6
|
+
* When inactive, renders normal colors, with the exception of selected object which is rendered with highlight
|
|
7
|
+
* can distinguish between 2^32 different objects in each of 2^32 different batches.
|
|
8
|
+
*/
|
|
9
|
+
export type PickingProps = {
|
|
10
|
+
/** Are we picking? I.e. rendering picking colors? */
|
|
11
|
+
isActive?: boolean;
|
|
12
|
+
/** Whether to use instance_index (built-in) or a custom application supplied index (usually from an attribute) */
|
|
13
|
+
indexMode?: 'instance' | 'custom';
|
|
14
|
+
/** Batch index (used when rendering multiple models to identify which model was picked), defaults to 0 */
|
|
15
|
+
batchIndex?: number;
|
|
16
|
+
/** Index of the highlighted batch, defaults to 0 */
|
|
17
|
+
highlightedBatchIndex?: number | null;
|
|
18
|
+
/** Set an index to highlight that item, or `null` to explicitly clear **/
|
|
19
|
+
highlightedObjectIndex?: number | null;
|
|
20
|
+
/** Color of visual highlight of "selected" item () */
|
|
21
|
+
highlightColor?: NumberArray4;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Uniforms for the picking module, which renders picking colors and highlighted item.
|
|
25
|
+
* When active, renders picking colors, assumed to be rendered to off-screen "picking" buffer.
|
|
26
|
+
* When inactive, renders normal colors, with the exception of selected object which is rendered with highlight
|
|
27
|
+
*/
|
|
28
|
+
export type PickingUniforms = {
|
|
29
|
+
/**
|
|
30
|
+
* When true, renders picking colors. Set when rendering to off-screen "picking" buffer.
|
|
31
|
+
* When false, renders normal colors, with the exception of selected object which is rendered with highlight
|
|
32
|
+
*/
|
|
33
|
+
isActive: boolean;
|
|
34
|
+
/** Set to true when picking an attribute value instead of object index */
|
|
35
|
+
indexMode: 0 | 1;
|
|
36
|
+
/** Index of batch currently being rendered */
|
|
37
|
+
batchIndex: number;
|
|
38
|
+
/** Do we have a highlighted item? */
|
|
39
|
+
isHighlightActive: boolean;
|
|
40
|
+
/** Color of visual highlight of "selected" item. Note: RGBA components must in the range 0-1 */
|
|
41
|
+
highlightColor: NumberArray4;
|
|
42
|
+
/** Indicates which batch to visually highlight an item in (defaults to 0) */
|
|
43
|
+
highlightedBatchIndex: number;
|
|
44
|
+
/** Indicates which index in the batch to highlight an item in */
|
|
45
|
+
highlightedObjectIndex: number;
|
|
46
|
+
};
|
|
47
|
+
export type PickingBindings = {};
|
|
48
|
+
export declare const GLSL_UNIFORMS = "precision highp float;\nprecision highp int;\n\nuniform pickingUniforms {\n int isActive;\n int indexMode;\n int batchIndex;\n\n int isHighlightActive;\n int highlightedBatchIndex;\n int highlightedObjectIndex;\n vec4 highlightColor;\n} picking;\n";
|
|
49
|
+
export declare const WGSL_UNIFORMS = "struct pickingUniforms {\n isActive: int32;\n indexMode: int32;\n batchIndex: int32;\n\n isHighlightActive: int32;\n highlightedBatchIndex: int32;\n highlightedObjectIndex: int32;\n highlightColor: vec4<f32>;\n} picking;\n";
|
|
50
|
+
declare function getUniforms(props?: PickingProps, prevUniforms?: PickingUniforms): PickingUniforms;
|
|
51
|
+
/**
|
|
52
|
+
* Provides support for color-based picking and highlighting.
|
|
53
|
+
*
|
|
54
|
+
* In particular, supports picking a specific instance in an instanced
|
|
55
|
+
* draw call and highlighting an instance based on its picking color,
|
|
56
|
+
* and correspondingly, supports picking and highlighting groups of
|
|
57
|
+
* primitives with the same picking color in non-instanced draw-calls
|
|
58
|
+
*
|
|
59
|
+
* @note Color based picking has the significant advantage in that it can be added to any
|
|
60
|
+
* existing shader without requiring any additional picking logic.
|
|
61
|
+
*/
|
|
62
|
+
export declare const pickingUniforms: {
|
|
63
|
+
readonly props: PickingProps;
|
|
64
|
+
readonly uniforms: PickingUniforms;
|
|
65
|
+
readonly name: "picking";
|
|
66
|
+
readonly uniformTypes: Required<import("modules/shadertools/dist/lib/utils/uniform-types").UniformTypes<PickingUniforms>>;
|
|
67
|
+
readonly defaultUniforms: {
|
|
68
|
+
readonly isActive: false;
|
|
69
|
+
readonly indexMode: 0;
|
|
70
|
+
readonly batchIndex: 0;
|
|
71
|
+
readonly isHighlightActive: true;
|
|
72
|
+
readonly highlightedBatchIndex: -1;
|
|
73
|
+
readonly highlightedObjectIndex: -1;
|
|
74
|
+
readonly highlightColor: NumberArray4;
|
|
75
|
+
};
|
|
76
|
+
readonly getUniforms: typeof getUniforms;
|
|
77
|
+
};
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=picking-uniforms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"picking-uniforms.d.ts","sourceRoot":"","sources":["../../../src/modules/picking/picking-uniforms.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAMjD,eAAO,MAAM,aAAa,KAAK,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l contributors
|
|
4
|
+
/** Default color for auto highlight, a cyan color */
|
|
5
|
+
const DEFAULT_HIGHLIGHT_COLOR = [0, 1, 1, 1];
|
|
6
|
+
export const INVALID_INDEX = -1;
|
|
7
|
+
// GLSL_UNIFORMS
|
|
8
|
+
const uniformTypes = {
|
|
9
|
+
isActive: 'i32',
|
|
10
|
+
indexMode: 'i32',
|
|
11
|
+
batchIndex: 'i32',
|
|
12
|
+
isHighlightActive: 'i32',
|
|
13
|
+
highlightedBatchIndex: 'i32',
|
|
14
|
+
highlightedObjectIndex: 'i32',
|
|
15
|
+
highlightColor: 'vec4<f32>'
|
|
16
|
+
};
|
|
17
|
+
export const GLSL_UNIFORMS = /* glsl */ `\
|
|
18
|
+
precision highp float;
|
|
19
|
+
precision highp int;
|
|
20
|
+
|
|
21
|
+
uniform pickingUniforms {
|
|
22
|
+
int isActive;
|
|
23
|
+
int indexMode;
|
|
24
|
+
int batchIndex;
|
|
25
|
+
|
|
26
|
+
int isHighlightActive;
|
|
27
|
+
int highlightedBatchIndex;
|
|
28
|
+
int highlightedObjectIndex;
|
|
29
|
+
vec4 highlightColor;
|
|
30
|
+
} picking;
|
|
31
|
+
`;
|
|
32
|
+
export const WGSL_UNIFORMS = /* wgsl */ `\
|
|
33
|
+
struct pickingUniforms {
|
|
34
|
+
isActive: int32;
|
|
35
|
+
indexMode: int32;
|
|
36
|
+
batchIndex: int32;
|
|
37
|
+
|
|
38
|
+
isHighlightActive: int32;
|
|
39
|
+
highlightedBatchIndex: int32;
|
|
40
|
+
highlightedObjectIndex: int32;
|
|
41
|
+
highlightColor: vec4<f32>;
|
|
42
|
+
} picking;
|
|
43
|
+
`;
|
|
44
|
+
function getUniforms(props = {}, prevUniforms) {
|
|
45
|
+
const uniforms = { ...prevUniforms };
|
|
46
|
+
// picking
|
|
47
|
+
if (props.isActive !== undefined) {
|
|
48
|
+
uniforms.isActive = Boolean(props.isActive);
|
|
49
|
+
}
|
|
50
|
+
switch (props.indexMode) {
|
|
51
|
+
case 'instance':
|
|
52
|
+
uniforms.indexMode = 0;
|
|
53
|
+
break;
|
|
54
|
+
case 'custom':
|
|
55
|
+
uniforms.indexMode = 1;
|
|
56
|
+
break;
|
|
57
|
+
case undefined:
|
|
58
|
+
// no change
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
switch (props.highlightedObjectIndex) {
|
|
62
|
+
case undefined:
|
|
63
|
+
// Unless highlightedObjectColor explicitly null or set, do not update state
|
|
64
|
+
break;
|
|
65
|
+
case null:
|
|
66
|
+
// Clear highlight
|
|
67
|
+
uniforms.isHighlightActive = false;
|
|
68
|
+
uniforms.highlightedObjectIndex = INVALID_INDEX;
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
uniforms.isHighlightActive = true;
|
|
72
|
+
uniforms.highlightedObjectIndex = props.highlightedObjectIndex;
|
|
73
|
+
}
|
|
74
|
+
if (typeof props.highlightedBatchIndex === 'number') {
|
|
75
|
+
uniforms.highlightedBatchIndex = props.highlightedBatchIndex;
|
|
76
|
+
}
|
|
77
|
+
if (props.highlightColor) {
|
|
78
|
+
uniforms.highlightColor = props.highlightColor;
|
|
79
|
+
}
|
|
80
|
+
return uniforms;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Provides support for color-based picking and highlighting.
|
|
84
|
+
*
|
|
85
|
+
* In particular, supports picking a specific instance in an instanced
|
|
86
|
+
* draw call and highlighting an instance based on its picking color,
|
|
87
|
+
* and correspondingly, supports picking and highlighting groups of
|
|
88
|
+
* primitives with the same picking color in non-instanced draw-calls
|
|
89
|
+
*
|
|
90
|
+
* @note Color based picking has the significant advantage in that it can be added to any
|
|
91
|
+
* existing shader without requiring any additional picking logic.
|
|
92
|
+
*/
|
|
93
|
+
export const pickingUniforms = {
|
|
94
|
+
props: {},
|
|
95
|
+
uniforms: {},
|
|
96
|
+
name: 'picking',
|
|
97
|
+
uniformTypes,
|
|
98
|
+
defaultUniforms: {
|
|
99
|
+
isActive: false,
|
|
100
|
+
indexMode: 0,
|
|
101
|
+
batchIndex: 0,
|
|
102
|
+
isHighlightActive: true,
|
|
103
|
+
highlightedBatchIndex: INVALID_INDEX,
|
|
104
|
+
highlightedObjectIndex: INVALID_INDEX,
|
|
105
|
+
highlightColor: DEFAULT_HIGHLIGHT_COLOR
|
|
106
|
+
},
|
|
107
|
+
getUniforms
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=picking-uniforms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"picking-uniforms.js","sourceRoot":"","sources":["../../../src/modules/picking/picking-uniforms.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAKpC,qDAAqD;AACrD,MAAM,uBAAuB,GAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAE3D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,CAAC;AAoDhC,gBAAgB;AAEhB,MAAM,YAAY,GAA0E;IAC1F,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,KAAK;IAChB,UAAU,EAAE,KAAK;IAEjB,iBAAiB,EAAE,KAAK;IACxB,qBAAqB,EAAE,KAAK;IAC5B,sBAAsB,EAAE,KAAK;IAC7B,cAAc,EAAE,WAAW;CAC5B,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;;;;;;;;;;;;;;CAcvC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;;;;;;;;;;;CAWvC,CAAC;AAEF,SAAS,WAAW,CAAC,QAAsB,EAAE,EAAE,YAA8B;IAC3E,MAAM,QAAQ,GAAG,EAAC,GAAG,YAAY,EAAoB,CAAC;IAEtD,UAAU;IACV,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACjC,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;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W;CACoE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ShaderPass } from '@luma.gl/shadertools';
|
|
2
|
+
/**
|
|
3
|
+
* Gets fragment shader source for a shader pass sub pass
|
|
4
|
+
* @param options
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function getFragmentShaderForRenderPass(options: {
|
|
8
|
+
shaderPass: ShaderPass;
|
|
9
|
+
action: 'filter' | 'sample';
|
|
10
|
+
shadingLanguage: 'wgsl' | 'glsl';
|
|
11
|
+
}): string;
|
|
12
|
+
//# sourceMappingURL=get-fragment-shader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-fragment-shader.d.ts","sourceRoot":"","sources":["../../src/passes/get-fragment-shader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,OAAO,EAAE;IACtD,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC5B,eAAe,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC,GAAG,MAAM,CAkBT"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* Gets fragment shader source for a shader pass sub pass
|
|
6
|
+
* @param options
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export function getFragmentShaderForRenderPass(options) {
|
|
10
|
+
const { shaderPass, action, shadingLanguage } = options;
|
|
11
|
+
switch (action) {
|
|
12
|
+
case 'filter':
|
|
13
|
+
const filterFunc = `${shaderPass.name}_filterColor_ext`;
|
|
14
|
+
return shadingLanguage === 'wgsl'
|
|
15
|
+
? getFilterShaderWGSL(filterFunc)
|
|
16
|
+
: getFilterShaderGLSL(filterFunc);
|
|
17
|
+
case 'sample':
|
|
18
|
+
const samplerFunc = `${shaderPass.name}_sampleColor`;
|
|
19
|
+
return shadingLanguage === 'wgsl'
|
|
20
|
+
? getSamplerShaderWGSL(samplerFunc)
|
|
21
|
+
: getSamplerShaderGLSL(samplerFunc);
|
|
22
|
+
default:
|
|
23
|
+
throw new Error(`${shaderPass.name} no fragment shader generated for shader pass`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Get a filtering WGSL fragment shader */
|
|
27
|
+
function getFilterShaderWGSL(func) {
|
|
28
|
+
return /* wgsl */ `\
|
|
29
|
+
// Binding 0:1 is reserved for shader passes
|
|
30
|
+
@group(0) @binding(0) var<uniform> brightnessContrast : brightnessContrastUniforms;
|
|
31
|
+
@group(0) @binding(1) var texture: texture_2d<f32>;
|
|
32
|
+
@group(0) @binding(2) var sampler: sampler;
|
|
33
|
+
|
|
34
|
+
struct FragmentInputs = {
|
|
35
|
+
@location(0) fragUV: vec2f,
|
|
36
|
+
@location(1) fragPosition: vec4f,
|
|
37
|
+
@location(2) fragCoordinate: vec4f
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
@fragment
|
|
41
|
+
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
42
|
+
let texSize = textureDimensions(texture, 0);
|
|
43
|
+
var fragColor = textureSample(texture, sampler, fragUV);
|
|
44
|
+
fragColor = ${func}(gl_FragColor, texSize, texCoord);
|
|
45
|
+
return fragColor;
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
/** Get a sampling WGSL fragment shader */
|
|
50
|
+
function getSamplerShaderWGSL(func) {
|
|
51
|
+
return /* wgsl */ `\
|
|
52
|
+
// Binding 0:1 is reserved for shader passes
|
|
53
|
+
@group(0) @binding(0) var<uniform> brightnessContrast : brightnessContrastUniforms;
|
|
54
|
+
@group(0) @binding(1) var texture: texture_2d<f32>;
|
|
55
|
+
@group(0) @binding(2) var sampler: sampler;
|
|
56
|
+
|
|
57
|
+
struct FragmentInputs = {
|
|
58
|
+
@location(0) fragUV: vec2f,
|
|
59
|
+
@location(1) fragPosition: vec4f,
|
|
60
|
+
@location(2) fragCoordinate: vec4f
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
@fragment
|
|
64
|
+
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
65
|
+
let texSize = textureDimensions(texture, 0);
|
|
66
|
+
var fragColor = textureSample(texture, sampler, fragUV);
|
|
67
|
+
fragColor = ${func}(gl_FragColor, texSize, texCoord);
|
|
68
|
+
return fragColor;
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
/** Get a filtering GLSL fragment shader */
|
|
73
|
+
function getFilterShaderGLSL(func) {
|
|
74
|
+
return /* glsl */ `\
|
|
75
|
+
#version 300 es
|
|
76
|
+
|
|
77
|
+
uniform sampler2D sourceTexture;
|
|
78
|
+
|
|
79
|
+
in vec2 position;
|
|
80
|
+
in vec2 coordinate;
|
|
81
|
+
in vec2 uv;
|
|
82
|
+
|
|
83
|
+
out vec4 fragColor;
|
|
84
|
+
|
|
85
|
+
void main() {
|
|
86
|
+
vec2 texCoord = coordinate;
|
|
87
|
+
ivec2 iTexSize = textureSize(sourceTexture, 0);
|
|
88
|
+
vec2 texSize = vec2(float(iTexSize.x), float(iTexSize.y));
|
|
89
|
+
|
|
90
|
+
fragColor = texture(sourceTexture, texCoord);
|
|
91
|
+
fragColor = ${func}(fragColor, texSize, texCoord);
|
|
92
|
+
}
|
|
93
|
+
`;
|
|
94
|
+
}
|
|
95
|
+
/** Get a sampling GLSL fragment shader */
|
|
96
|
+
function getSamplerShaderGLSL(func) {
|
|
97
|
+
return /* glsl */ `\
|
|
98
|
+
#version 300 es
|
|
99
|
+
|
|
100
|
+
uniform sampler2D sourceTexture;
|
|
101
|
+
|
|
102
|
+
in vec2 position;
|
|
103
|
+
in vec2 coordinate;
|
|
104
|
+
in vec2 uv;
|
|
105
|
+
|
|
106
|
+
out vec4 fragColor;
|
|
107
|
+
|
|
108
|
+
void main() {
|
|
109
|
+
vec2 texCoord = coordinate;
|
|
110
|
+
ivec2 iTexSize = textureSize(sourceTexture, 0);
|
|
111
|
+
vec2 texSize = vec2(float(iTexSize.x), float(iTexSize.y));
|
|
112
|
+
|
|
113
|
+
fragColor = ${func}(sourceTexture, texSize, texCoord);
|
|
114
|
+
}
|
|
115
|
+
`;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=get-fragment-shader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-fragment-shader.js","sourceRoot":"","sources":["../../src/passes/get-fragment-shader.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC;;;;GAIG;AACH,MAAM,UAAU,8BAA8B,CAAC,OAI9C;IACC,MAAM,EAAC,UAAU,EAAE,MAAM,EAAE,eAAe,EAAC,GAAG,OAAO,CAAC;IACtD,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,QAAQ;YACX,MAAM,UAAU,GAAG,GAAG,UAAU,CAAC,IAAI,kBAAkB,CAAC;YACxD,OAAO,eAAe,KAAK,MAAM;gBAC/B,CAAC,CAAC,mBAAmB,CAAC,UAAU,CAAC;gBACjC,CAAC,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;QAEtC,KAAK,QAAQ;YACX,MAAM,WAAW,GAAG,GAAG,UAAU,CAAC,IAAI,cAAc,CAAC;YACrD,OAAO,eAAe,KAAK,MAAM;gBAC/B,CAAC,CAAC,oBAAoB,CAAC,WAAW,CAAC;gBACnC,CAAC,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;QAExC;YACE,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,+CAA+C,CAAC,CAAC;IACvF,CAAC;AACH,CAAC;AAED,2CAA2C;AAC3C,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO,UAAU,C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