react-native-shine 0.3.5 → 0.4.0
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/README.md +7 -6
- package/lib/module/components/Content.js +34 -28
- package/lib/module/components/Content.js.map +1 -1
- package/lib/module/components/ShineGroup.js +0 -2
- package/lib/module/components/ShineGroup.js.map +1 -1
- package/lib/module/shaders/bindGroupLayouts.js +20 -0
- package/lib/module/shaders/bindGroupLayouts.js.map +1 -1
- package/lib/module/shaders/bindGroupUtils.js +5 -1
- package/lib/module/shaders/bindGroupUtils.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/colorMaskFragment.js +2 -2
- package/lib/module/shaders/fragmentShaders/colorMaskFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/holoFragment.js +2 -2
- package/lib/module/shaders/fragmentShaders/holoFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js +28 -6
- package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js.map +1 -1
- package/lib/module/shaders/tgpuUtils.js +41 -0
- package/lib/module/shaders/tgpuUtils.js.map +1 -1
- package/lib/module/types/typeUtils.js +33 -0
- package/lib/module/types/typeUtils.js.map +1 -1
- package/lib/typescript/src/components/Content.d.ts +4 -3
- package/lib/typescript/src/components/Content.d.ts.map +1 -1
- package/lib/typescript/src/components/ShineGroup.d.ts +1 -1
- package/lib/typescript/src/components/ShineGroup.d.ts.map +1 -1
- package/lib/typescript/src/shaders/bindGroupLayouts.d.ts +42 -0
- package/lib/typescript/src/shaders/bindGroupLayouts.d.ts.map +1 -1
- package/lib/typescript/src/shaders/bindGroupUtils.d.ts +23 -1
- package/lib/typescript/src/shaders/bindGroupUtils.d.ts.map +1 -1
- package/lib/typescript/src/shaders/fragmentShaders/reverseHoloFragment.d.ts.map +1 -1
- package/lib/typescript/src/shaders/tgpuUtils.d.ts +2 -0
- package/lib/typescript/src/shaders/tgpuUtils.d.ts.map +1 -1
- package/lib/typescript/src/types/typeUtils.d.ts +9 -1
- package/lib/typescript/src/types/typeUtils.d.ts.map +1 -1
- package/lib/typescript/src/types/types.d.ts +8 -0
- package/lib/typescript/src/types/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Content.tsx +45 -24
- package/src/components/ShineGroup.tsx +0 -2
- package/src/shaders/bindGroupLayouts.ts +22 -0
- package/src/shaders/bindGroupUtils.ts +13 -0
- package/src/shaders/fragmentShaders/colorMaskFragment.ts +1 -1
- package/src/shaders/fragmentShaders/holoFragment.ts +1 -1
- package/src/shaders/fragmentShaders/reverseHoloFragment.ts +33 -4
- package/src/shaders/tgpuUtils.ts +40 -0
- package/src/types/typeUtils.ts +33 -0
- package/src/types/types.ts +9 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
-
import { PixelRatio,
|
|
2
|
+
import { PixelRatio, View } from 'react-native';
|
|
3
3
|
import Animated, {
|
|
4
4
|
SensorType,
|
|
5
5
|
type SharedValue,
|
|
@@ -26,6 +26,7 @@ import { TypedBufferMap } from '../shaders/resourceManagement/bufferManager';
|
|
|
26
26
|
import {
|
|
27
27
|
createColorMaskBindGroup,
|
|
28
28
|
createGlareBindGroup,
|
|
29
|
+
createReverseHoloDetectionChannelFlagsBindGroup,
|
|
29
30
|
createRotationValuesBindGroup,
|
|
30
31
|
} from '../shaders/bindGroupUtils';
|
|
31
32
|
import colorMaskFragment from '../shaders/fragmentShaders/colorMaskFragment';
|
|
@@ -46,11 +47,13 @@ import type {
|
|
|
46
47
|
DeepPartiallyOptional,
|
|
47
48
|
GlareOptions,
|
|
48
49
|
PipelineAttachmentPair,
|
|
50
|
+
ReverseHoloDetectionChannelFlags,
|
|
49
51
|
} from '../types/types';
|
|
50
52
|
import {
|
|
51
53
|
colorMaskToTyped,
|
|
52
54
|
createColorMask,
|
|
53
55
|
createGlareOptions,
|
|
56
|
+
createReverseHoloDetectionChannelFlags,
|
|
54
57
|
} from '../types/typeUtils';
|
|
55
58
|
import type { V2d, V3d } from '../types/vector';
|
|
56
59
|
import {
|
|
@@ -75,9 +78,10 @@ export interface SharedProps {
|
|
|
75
78
|
colorMaskOptions?: DeepPartiallyOptional<ColorMask, 'baseColor'>;
|
|
76
79
|
useTouchControl?: boolean;
|
|
77
80
|
touchPosition?: SharedValue<V2d>;
|
|
78
|
-
addTextureMask?: boolean;
|
|
79
81
|
addReverseHolo?: boolean;
|
|
82
|
+
reverseHoloDetectionChannelOptions?: Partial<ReverseHoloDetectionChannelFlags>;
|
|
80
83
|
addHolo?: boolean;
|
|
84
|
+
translateViewIn3d?: boolean;
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
interface ContentProps extends SharedProps {
|
|
@@ -97,7 +101,7 @@ interface PipelineMap {
|
|
|
97
101
|
export default function Content({
|
|
98
102
|
addHolo,
|
|
99
103
|
addReverseHolo,
|
|
100
|
-
|
|
104
|
+
reverseHoloDetectionChannelOptions,
|
|
101
105
|
colorMaskOptions,
|
|
102
106
|
glareOptions,
|
|
103
107
|
height,
|
|
@@ -107,6 +111,7 @@ export default function Content({
|
|
|
107
111
|
touchPosition,
|
|
108
112
|
useTouchControl,
|
|
109
113
|
width,
|
|
114
|
+
translateViewIn3d = false,
|
|
110
115
|
}: ContentProps) {
|
|
111
116
|
const { device } = root;
|
|
112
117
|
const { ref, context } = useGPUContext();
|
|
@@ -146,7 +151,6 @@ export default function Content({
|
|
|
146
151
|
{ perspective: 300 },
|
|
147
152
|
{ rotateX: `${-rotY}deg` },
|
|
148
153
|
{ rotateY: `${rotX}deg` },
|
|
149
|
-
// { rotateZ: `${rotX * 5}deg` },
|
|
150
154
|
],
|
|
151
155
|
};
|
|
152
156
|
});
|
|
@@ -275,6 +279,18 @@ export default function Content({
|
|
|
275
279
|
);
|
|
276
280
|
const colorMaskBindGroup = createColorMaskBindGroup(root, colorMaskBuffer);
|
|
277
281
|
|
|
282
|
+
const reverseHoloDetectionChannelFlagsBuffer = bufferMap.addBuffer(
|
|
283
|
+
root,
|
|
284
|
+
'reverseHoloDetectionChannelFlags',
|
|
285
|
+
createReverseHoloDetectionChannelFlags(reverseHoloDetectionChannelOptions)
|
|
286
|
+
);
|
|
287
|
+
const reverseHoloDetectionChannelFlagsBindGroup =
|
|
288
|
+
createReverseHoloDetectionChannelFlagsBindGroup(
|
|
289
|
+
root,
|
|
290
|
+
reverseHoloDetectionChannelFlagsBuffer,
|
|
291
|
+
glareBuffer
|
|
292
|
+
);
|
|
293
|
+
|
|
278
294
|
const pipelineMap: PipelineMap = {
|
|
279
295
|
glare: attachBindGroups(
|
|
280
296
|
root['~unstable']
|
|
@@ -308,7 +324,11 @@ export default function Content({
|
|
|
308
324
|
reverseHolo: createReverseHoloPipeline(
|
|
309
325
|
root,
|
|
310
326
|
maskTexture,
|
|
311
|
-
[
|
|
327
|
+
[
|
|
328
|
+
imageTextureBindGroup,
|
|
329
|
+
rotationBindGroup,
|
|
330
|
+
reverseHoloDetectionChannelFlagsBindGroup,
|
|
331
|
+
],
|
|
312
332
|
sampler,
|
|
313
333
|
presentationFormat
|
|
314
334
|
),
|
|
@@ -344,7 +364,7 @@ export default function Content({
|
|
|
344
364
|
|
|
345
365
|
const pairs: PipelineAttachmentPair[] = [[glare, initialAttachment]];
|
|
346
366
|
|
|
347
|
-
if (
|
|
367
|
+
if (mask) pairs.push([mask, loadingAttachment]);
|
|
348
368
|
if (addReverseHolo && reverseHolo)
|
|
349
369
|
pairs.push([reverseHolo, loadingAttachment]);
|
|
350
370
|
if (addHolo && holo) pairs.push([holo, loadingAttachment]);
|
|
@@ -362,6 +382,9 @@ export default function Content({
|
|
|
362
382
|
renderPipelines();
|
|
363
383
|
presentContext();
|
|
364
384
|
};
|
|
385
|
+
|
|
386
|
+
// const res = tgpu.resolve({ externals: { reverseHoloFragment } });
|
|
387
|
+
// console.log('reverseHoloFragment resolve:', res);
|
|
365
388
|
}, [
|
|
366
389
|
device,
|
|
367
390
|
context,
|
|
@@ -375,29 +398,27 @@ export default function Content({
|
|
|
375
398
|
colorMaskOptions,
|
|
376
399
|
addHolo,
|
|
377
400
|
addReverseHolo,
|
|
378
|
-
|
|
401
|
+
reverseHoloDetectionChannelOptions,
|
|
379
402
|
pixelSize,
|
|
380
403
|
]);
|
|
381
404
|
|
|
382
405
|
useAnimationFrame(() => renderRef.current?.());
|
|
383
406
|
|
|
384
407
|
return (
|
|
385
|
-
<
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
style={[{ width, height }]}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
</View>
|
|
401
|
-
</Animated.View>
|
|
408
|
+
<View
|
|
409
|
+
style={{
|
|
410
|
+
transform: [
|
|
411
|
+
{
|
|
412
|
+
matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 50, 1],
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
}}
|
|
416
|
+
>
|
|
417
|
+
<Animated.View style={[translateViewIn3d && animatedStyle]}>
|
|
418
|
+
<View>
|
|
419
|
+
<Canvas ref={ref} style={[{ width, height }]} transparent={true} />
|
|
420
|
+
</View>
|
|
421
|
+
</Animated.View>
|
|
422
|
+
</View>
|
|
402
423
|
);
|
|
403
424
|
}
|
|
@@ -20,7 +20,6 @@ export function ShineGroup({
|
|
|
20
20
|
maskURI,
|
|
21
21
|
touchPosition,
|
|
22
22
|
useTouchControl = false,
|
|
23
|
-
addTextureMask = false,
|
|
24
23
|
addHolo = false,
|
|
25
24
|
addReverseHolo = false,
|
|
26
25
|
}: ShineGroupProps) {
|
|
@@ -82,7 +81,6 @@ export function ShineGroup({
|
|
|
82
81
|
maskURI={maskURI}
|
|
83
82
|
touchPosition={touchPosition}
|
|
84
83
|
useTouchControl={useTouchControl}
|
|
85
|
-
addTextureMask={addTextureMask}
|
|
86
84
|
addReverseHolo={addReverseHolo}
|
|
87
85
|
addHolo={addHolo}
|
|
88
86
|
/>
|
|
@@ -47,6 +47,24 @@ export const colorMaskBindGroupLayout = tgpu.bindGroupLayout({
|
|
|
47
47
|
mask: { uniform: colorMaskSchema },
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
export const reverseHoloDetectionChannelFlagsSchema = d.struct({
|
|
51
|
+
redChannel: d.align(16, d.f32),
|
|
52
|
+
greenChannel: d.f32,
|
|
53
|
+
blueChannel: d.f32,
|
|
54
|
+
hue: d.f32,
|
|
55
|
+
saturation: d.f32,
|
|
56
|
+
value: d.f32,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export type ReverseHoloDetectionChannelFlagsSchema =
|
|
60
|
+
typeof reverseHoloDetectionChannelFlagsSchema;
|
|
61
|
+
|
|
62
|
+
export const reverseHoloDetectionChannelFlagsBindGroupLayout =
|
|
63
|
+
tgpu.bindGroupLayout({
|
|
64
|
+
channelFlags: { uniform: reverseHoloDetectionChannelFlagsSchema },
|
|
65
|
+
glareOptions: { uniform: glareSchema },
|
|
66
|
+
});
|
|
67
|
+
|
|
50
68
|
export const bufferData = {
|
|
51
69
|
rotation: {
|
|
52
70
|
schema: d.vec3f,
|
|
@@ -60,6 +78,10 @@ export const bufferData = {
|
|
|
60
78
|
schema: colorMaskSchema,
|
|
61
79
|
usage: 'uniform',
|
|
62
80
|
},
|
|
81
|
+
reverseHoloDetectionChannelFlags: {
|
|
82
|
+
schema: reverseHoloDetectionChannelFlagsSchema,
|
|
83
|
+
usage: 'uniform',
|
|
84
|
+
},
|
|
63
85
|
} as const satisfies Record<
|
|
64
86
|
string,
|
|
65
87
|
{ schema: ValidateBufferSchema<any>; usage: BufferUsageType }
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
rotationBindGroupLayout,
|
|
9
9
|
type GlareSchema,
|
|
10
10
|
colorMaskSchema,
|
|
11
|
+
type ReverseHoloDetectionChannelFlagsSchema,
|
|
12
|
+
reverseHoloDetectionChannelFlagsBindGroupLayout,
|
|
11
13
|
} from './bindGroupLayouts';
|
|
12
14
|
import type {
|
|
13
15
|
GlareOptions,
|
|
@@ -70,6 +72,17 @@ export const createColorMaskBindGroup = (
|
|
|
70
72
|
mask: buffer,
|
|
71
73
|
});
|
|
72
74
|
|
|
75
|
+
export const createReverseHoloDetectionChannelFlagsBindGroup = (
|
|
76
|
+
root: TgpuRoot,
|
|
77
|
+
detectionChannelBuffer: TgpuBuffer<ReverseHoloDetectionChannelFlagsSchema> &
|
|
78
|
+
UniformFlag,
|
|
79
|
+
glareOptionsBuffer: TgpuBuffer<GlareSchema> & UniformFlag
|
|
80
|
+
) =>
|
|
81
|
+
root.createBindGroup(reverseHoloDetectionChannelFlagsBindGroupLayout, {
|
|
82
|
+
channelFlags: detectionChannelBuffer,
|
|
83
|
+
glareOptions: glareOptionsBuffer,
|
|
84
|
+
});
|
|
85
|
+
|
|
73
86
|
// export const crateHoloBuffer = (
|
|
74
87
|
// root: TgpuRoot,
|
|
75
88
|
// initValues: Partial<HoloOptions>
|
|
@@ -31,5 +31,5 @@ export const holoFragment = tgpu['~unstable'].fragmentFn({
|
|
|
31
31
|
const rainbowColor = hueShift(d.vec3f(1.0, 1.0, 1.0), hueAngle);
|
|
32
32
|
const finalColor = std.mul(rainbowColor, 1.0);
|
|
33
33
|
|
|
34
|
-
return d.vec4f(finalColor, 0.
|
|
34
|
+
return d.vec4f(finalColor, 0.9 * textureColor.w);
|
|
35
35
|
});
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
textureBindGroupLayout,
|
|
6
6
|
maskTextureBindGroupLayout,
|
|
7
7
|
rotationBindGroupLayout,
|
|
8
|
-
|
|
8
|
+
reverseHoloDetectionChannelFlagsBindGroupLayout,
|
|
9
9
|
} from '../bindGroupLayouts';
|
|
10
|
-
import { hueShift } from '../tgpuUtils';
|
|
10
|
+
import { hueShift, rgbToHSV } from '../tgpuUtils';
|
|
11
11
|
|
|
12
12
|
export const reverseHoloFragment = tgpu['~unstable'].fragmentFn({
|
|
13
13
|
in: { uv: d.vec2f },
|
|
@@ -20,13 +20,26 @@ export const reverseHoloFragment = tgpu['~unstable'].fragmentFn({
|
|
|
20
20
|
const rot = rotationBindGroupLayout.$.vec;
|
|
21
21
|
const center = std.add(d.vec2f(0.0), d.vec2f(rot.x, rot.y)); // center from device orientation/touch
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
// glare options---------------------------------
|
|
24
|
+
const opts = reverseHoloDetectionChannelFlagsBindGroupLayout.$.glareOptions;
|
|
24
25
|
const glareIntensity = opts.glareIntensity;
|
|
25
26
|
const glowPower = opts.glowPower;
|
|
26
27
|
const hueBlendPower = opts.hueBlendPower;
|
|
27
28
|
const hueShiftAngleMin = opts.hueShiftAngleMin;
|
|
28
29
|
const hueShiftAngleMax = opts.hueShiftAngleMax;
|
|
29
30
|
const lightIntensity = opts.lightIntensity;
|
|
31
|
+
//-----------------------------------------------
|
|
32
|
+
|
|
33
|
+
// detection channel flags-----------------------
|
|
34
|
+
const detectionChannelFlags =
|
|
35
|
+
reverseHoloDetectionChannelFlagsBindGroupLayout.$.channelFlags;
|
|
36
|
+
const redChannelFlag = detectionChannelFlags.redChannel;
|
|
37
|
+
const greenChannelFlag = detectionChannelFlags.greenChannel;
|
|
38
|
+
const blueChannelFlag = detectionChannelFlags.blueChannel;
|
|
39
|
+
const hueFlag = detectionChannelFlags.hue;
|
|
40
|
+
const saturationFlag = detectionChannelFlags.saturation;
|
|
41
|
+
const valueFlag = detectionChannelFlags.value;
|
|
42
|
+
//------------------------------------------------
|
|
30
43
|
|
|
31
44
|
const cardColor = std.textureSample(
|
|
32
45
|
textureBindGroupLayout.$.texture,
|
|
@@ -49,9 +62,25 @@ export const reverseHoloFragment = tgpu['~unstable'].fragmentFn({
|
|
|
49
62
|
const influence = std.smoothstep(0.0, 1.0, scaledRadial);
|
|
50
63
|
const curvePower = std.clamp(glowPower, 0.05, 64.0);
|
|
51
64
|
const glowMask = std.pow(influence, std.div(1.0, curvePower));
|
|
65
|
+
const holoMaskColorHSV = rgbToHSV(holoMaskColor.xyz);
|
|
66
|
+
|
|
67
|
+
const rgbSelection = d.vec3f(
|
|
68
|
+
redChannelFlag,
|
|
69
|
+
greenChannelFlag,
|
|
70
|
+
blueChannelFlag
|
|
71
|
+
);
|
|
72
|
+
const channelFactor = std.dot(holoMaskColor.xyz, rgbSelection);
|
|
73
|
+
|
|
74
|
+
const hsvSelection = d.vec3f(hueFlag, saturationFlag, valueFlag);
|
|
75
|
+
const channelFactorHSV = std.dot(holoMaskColorHSV.xyz, hsvSelection);
|
|
76
|
+
//TODO: delete this combination to have separate RGB and HSV controls,
|
|
77
|
+
// maybe add weights later or choice of combination method
|
|
78
|
+
const channelFactorCombined = std.mix(channelFactor, channelFactorHSV, 0.0);
|
|
52
79
|
|
|
53
80
|
const holoFactor =
|
|
54
|
-
(1.0 -
|
|
81
|
+
(1.0 - channelFactorCombined) *
|
|
82
|
+
holoMaskColor.w *
|
|
83
|
+
std.pow(scaledRadial, 1.5);
|
|
55
84
|
|
|
56
85
|
const maskedGlow = std.mul(glowMask, holoFactor); // only affect masked areas
|
|
57
86
|
|
package/src/shaders/tgpuUtils.ts
CHANGED
|
@@ -33,6 +33,46 @@ export const hueShift = tgpu.fn(
|
|
|
33
33
|
return d.vec3f(r, g, b);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
+
export const rgbToHSV = tgpu.fn(
|
|
37
|
+
[d.vec3f],
|
|
38
|
+
d.vec3f
|
|
39
|
+
)((rgb) => {
|
|
40
|
+
const cMax = std.max(std.max(rgb.x, rgb.y), rgb.z);
|
|
41
|
+
const cMin = std.min(std.min(rgb.x, rgb.y), rgb.z);
|
|
42
|
+
const delta = std.sub(cMax, cMin);
|
|
43
|
+
|
|
44
|
+
const hueDeltaZero = d.f32(0.0);
|
|
45
|
+
const hueRmax = d.f32(60.0) * fmod((rgb.y - rgb.z) / delta, d.f32(6.0));
|
|
46
|
+
const hueGmax = d.f32(60.0) * ((rgb.z - rgb.x) / delta + d.f32(2.0));
|
|
47
|
+
const hueBmax = d.f32(60.0) * ((rgb.x - rgb.y) / delta + d.f32(4.0));
|
|
48
|
+
|
|
49
|
+
let hue = std.select(
|
|
50
|
+
hueDeltaZero,
|
|
51
|
+
hueRmax,
|
|
52
|
+
cMax === rgb.x && delta !== d.f32(0.0)
|
|
53
|
+
);
|
|
54
|
+
hue = std.select(hue, hueGmax, cMax === rgb.y && delta !== d.f32(0.0));
|
|
55
|
+
hue = std.select(hue, hueBmax, cMax === rgb.z && delta !== d.f32(0.0));
|
|
56
|
+
hue = std.select(hue, d.f32(0.0), delta === d.f32(0.0));
|
|
57
|
+
|
|
58
|
+
hue = std.mod(hue, d.f32(360.0));
|
|
59
|
+
const saturation = std.select(delta / cMax, d.f32(0.0), cMax === d.f32(0.0));
|
|
60
|
+
const value = cMax;
|
|
61
|
+
|
|
62
|
+
return d.vec3f(hue, saturation, value);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const fmod = tgpu.fn(
|
|
66
|
+
[d.f32, d.f32],
|
|
67
|
+
d.f32
|
|
68
|
+
)((number, md) => {
|
|
69
|
+
const dv = std.div(number, md);
|
|
70
|
+
const val = std.mul(md, std.floor(dv));
|
|
71
|
+
const c = std.sub(number, val);
|
|
72
|
+
|
|
73
|
+
return c;
|
|
74
|
+
});
|
|
75
|
+
|
|
36
76
|
export const glareColorShift = tgpu.fn(
|
|
37
77
|
[d.vec3f, d.f32],
|
|
38
78
|
d.vec3f
|
package/src/types/typeUtils.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { f32, vec2f, vec3f, vec4f } from 'typegpu/data';
|
|
2
|
+
import * as d from 'typegpu/data';
|
|
2
3
|
import type {
|
|
3
4
|
GlareOptions,
|
|
4
5
|
ColorMask,
|
|
5
6
|
DeepPartiallyOptional,
|
|
6
7
|
vec3,
|
|
7
8
|
HoloOptions,
|
|
9
|
+
ReverseHoloDetectionChannelFlags,
|
|
8
10
|
} from './types';
|
|
9
11
|
import { div } from 'typegpu/std';
|
|
10
12
|
import { WAVE_CALLBACKS } from '../enums/waveCallback';
|
|
@@ -87,6 +89,37 @@ export const createHoloOptions = (
|
|
|
87
89
|
return holoOpt;
|
|
88
90
|
};
|
|
89
91
|
|
|
92
|
+
export const createReverseHoloDetectionChannelFlags = (
|
|
93
|
+
options?: Partial<ReverseHoloDetectionChannelFlags>
|
|
94
|
+
) => {
|
|
95
|
+
let channelFlags;
|
|
96
|
+
if (options) {
|
|
97
|
+
const { redChannel, greenChannel, blueChannel, hue, saturation, value } =
|
|
98
|
+
options;
|
|
99
|
+
|
|
100
|
+
channelFlags = {
|
|
101
|
+
redChannel: redChannel ?? d.f32(0.0),
|
|
102
|
+
greenChannel: greenChannel ?? d.f32(0.0),
|
|
103
|
+
blueChannel: blueChannel ?? d.f32(0.0),
|
|
104
|
+
hue: hue ?? d.f32(0.0),
|
|
105
|
+
saturation: saturation ?? d.f32(0.0),
|
|
106
|
+
value: value ?? d.f32(0.0),
|
|
107
|
+
};
|
|
108
|
+
} else {
|
|
109
|
+
channelFlags = {
|
|
110
|
+
redChannel: d.f32(1.0),
|
|
111
|
+
greenChannel: d.f32(0.0),
|
|
112
|
+
blueChannel: d.f32(0.0),
|
|
113
|
+
hue: d.f32(0.0),
|
|
114
|
+
saturation: d.f32(0.0),
|
|
115
|
+
value: d.f32(0.0),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
console.log('createReverseHoloDetectionChannelFlags:', channelFlags);
|
|
120
|
+
return channelFlags;
|
|
121
|
+
};
|
|
122
|
+
|
|
90
123
|
export const numberArrToTyped = (vec: number[]) => {
|
|
91
124
|
let convFn: ((...args: number[]) => any) | null = null;
|
|
92
125
|
switch (vec.length) {
|
package/src/types/types.ts
CHANGED
|
@@ -27,6 +27,15 @@ export type ColorMask = {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
export type ReverseHoloDetectionChannelFlags = {
|
|
31
|
+
redChannel: number;
|
|
32
|
+
greenChannel: number;
|
|
33
|
+
blueChannel: number;
|
|
34
|
+
hue: number;
|
|
35
|
+
saturation: number;
|
|
36
|
+
value: number;
|
|
37
|
+
};
|
|
38
|
+
|
|
30
39
|
export type HoloOptions = {
|
|
31
40
|
intensity: number;
|
|
32
41
|
waveCallback: WaveCallbackFn;
|