react-native-shine 0.6.0 → 0.7.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.
Files changed (80) hide show
  1. package/lib/module/components/Content.js +79 -41
  2. package/lib/module/components/Content.js.map +1 -1
  3. package/lib/module/components/Shine.js +10 -0
  4. package/lib/module/components/Shine.js.map +1 -1
  5. package/lib/module/components/ShineGroup.js +16 -8
  6. package/lib/module/components/ShineGroup.js.map +1 -1
  7. package/lib/module/enums/colorHighlightPresets.js +24 -0
  8. package/lib/module/enums/colorHighlightPresets.js.map +1 -0
  9. package/lib/module/enums/effectPresets.js +16 -0
  10. package/lib/module/enums/effectPresets.js.map +1 -0
  11. package/lib/module/index.js +2 -0
  12. package/lib/module/index.js.map +1 -1
  13. package/lib/module/shaders/bindGroupLayouts.js +24 -15
  14. package/lib/module/shaders/bindGroupLayouts.js.map +1 -1
  15. package/lib/module/shaders/bindGroupUtils.js +16 -7
  16. package/lib/module/shaders/bindGroupUtils.js.map +1 -1
  17. package/lib/module/shaders/computeShaders/precomputeColorMask.js +34 -0
  18. package/lib/module/shaders/computeShaders/precomputeColorMask.js.map +1 -0
  19. package/lib/module/shaders/fragmentShaders/colorMaskFragment.js +53 -41
  20. package/lib/module/shaders/fragmentShaders/colorMaskFragment.js.map +1 -1
  21. package/lib/module/shaders/fragmentShaders/glareFragment.js +11 -8
  22. package/lib/module/shaders/fragmentShaders/glareFragment.js.map +1 -1
  23. package/lib/module/shaders/fragmentShaders/holoFragment.js +6 -5
  24. package/lib/module/shaders/fragmentShaders/holoFragment.js.map +1 -1
  25. package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js +12 -8
  26. package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js.map +1 -1
  27. package/lib/module/shaders/pipelineSetups.js +3 -1
  28. package/lib/module/shaders/pipelineSetups.js.map +1 -1
  29. package/lib/module/shaders/resourceManagement/bufferManager.js.map +1 -1
  30. package/lib/module/types/size.js +2 -0
  31. package/lib/module/types/typeUtils.js +120 -75
  32. package/lib/module/types/typeUtils.js.map +1 -1
  33. package/lib/module/types/vector.js +2 -0
  34. package/lib/module/utils/vector.js +6 -6
  35. package/lib/typescript/src/components/Content.d.ts +11 -8
  36. package/lib/typescript/src/components/Content.d.ts.map +1 -1
  37. package/lib/typescript/src/components/Shine.d.ts.map +1 -1
  38. package/lib/typescript/src/components/ShineGroup.d.ts +1 -1
  39. package/lib/typescript/src/components/ShineGroup.d.ts.map +1 -1
  40. package/lib/typescript/src/enums/colorHighlightPresets.d.ts +12 -0
  41. package/lib/typescript/src/enums/colorHighlightPresets.d.ts.map +1 -0
  42. package/lib/typescript/src/enums/effectPresets.d.ts +14 -0
  43. package/lib/typescript/src/enums/effectPresets.d.ts.map +1 -0
  44. package/lib/typescript/src/index.d.ts +2 -0
  45. package/lib/typescript/src/index.d.ts.map +1 -1
  46. package/lib/typescript/src/shaders/bindGroupLayouts.d.ts +98 -49
  47. package/lib/typescript/src/shaders/bindGroupLayouts.d.ts.map +1 -1
  48. package/lib/typescript/src/shaders/bindGroupUtils.d.ts +41 -48
  49. package/lib/typescript/src/shaders/bindGroupUtils.d.ts.map +1 -1
  50. package/lib/typescript/src/shaders/computeShaders/precomputeColorMask.d.ts +5 -0
  51. package/lib/typescript/src/shaders/computeShaders/precomputeColorMask.d.ts.map +1 -0
  52. package/lib/typescript/src/shaders/fragmentShaders/colorMaskFragment.d.ts.map +1 -1
  53. package/lib/typescript/src/shaders/fragmentShaders/glareFragment.d.ts.map +1 -1
  54. package/lib/typescript/src/shaders/fragmentShaders/reverseHoloFragment.d.ts.map +1 -1
  55. package/lib/typescript/src/shaders/pipelineSetups.d.ts +3 -4
  56. package/lib/typescript/src/shaders/pipelineSetups.d.ts.map +1 -1
  57. package/lib/typescript/src/shaders/resourceManagement/bufferManager.d.ts +5 -3
  58. package/lib/typescript/src/shaders/resourceManagement/bufferManager.d.ts.map +1 -1
  59. package/lib/typescript/src/types/typeUtils.d.ts +43 -10
  60. package/lib/typescript/src/types/typeUtils.d.ts.map +1 -1
  61. package/lib/typescript/src/types/types.d.ts +31 -4
  62. package/lib/typescript/src/types/types.d.ts.map +1 -1
  63. package/package.json +2 -1
  64. package/src/components/Content.tsx +98 -39
  65. package/src/components/Shine.tsx +8 -0
  66. package/src/components/ShineGroup.tsx +16 -8
  67. package/src/enums/colorHighlightPresets.ts +33 -0
  68. package/src/enums/effectPresets.ts +11 -0
  69. package/src/index.tsx +2 -0
  70. package/src/shaders/bindGroupLayouts.ts +34 -11
  71. package/src/shaders/bindGroupUtils.ts +19 -26
  72. package/src/shaders/computeShaders/precomputeColorMask.ts +29 -0
  73. package/src/shaders/fragmentShaders/colorMaskFragment.ts +64 -45
  74. package/src/shaders/fragmentShaders/glareFragment.ts +10 -6
  75. package/src/shaders/fragmentShaders/holoFragment.ts +5 -5
  76. package/src/shaders/fragmentShaders/reverseHoloFragment.ts +12 -7
  77. package/src/shaders/pipelineSetups.ts +15 -6
  78. package/src/shaders/resourceManagement/bufferManager.ts +8 -3
  79. package/src/types/typeUtils.ts +134 -82
  80. package/src/types/types.ts +36 -4
@@ -6,11 +6,13 @@ export type vec4 = [number, number, number, number];
6
6
  export type quaternion = vec4;
7
7
  export type GlareOptions = {
8
8
  glowPower: number;
9
- hueShiftAngleMax: number;
10
- hueShiftAngleMin: number;
11
- hueBlendPower: number;
12
9
  lightIntensity: number;
13
10
  glareIntensity: number;
11
+ glareColor: {
12
+ hueBlendPower: number;
13
+ hueShiftAngleMax: number;
14
+ hueShiftAngleMin: number;
15
+ };
14
16
  };
15
17
  export type ColorMask = {
16
18
  baseColor: vec3;
@@ -20,8 +22,8 @@ export type ColorMask = {
20
22
  lower: number;
21
23
  };
22
24
  brightnessTolerance?: number;
23
- lowBrightnessThreshold?: number;
24
25
  saturationTolerance?: number;
26
+ lowBrightnessThreshold?: number;
25
27
  lowSaturationThreshold?: number;
26
28
  rgbToleranceRange: {
27
29
  upper: vec3;
@@ -29,6 +31,31 @@ export type ColorMask = {
29
31
  };
30
32
  debugMode?: boolean;
31
33
  };
34
+ export type ColorMaskArrayShaderAssert = [
35
+ any,
36
+ any,
37
+ any,
38
+ any,
39
+ any,
40
+ any,
41
+ any,
42
+ any,
43
+ any,
44
+ any,
45
+ any,
46
+ any,
47
+ any,
48
+ any,
49
+ any,
50
+ any
51
+ ];
52
+ export type Effect = {
53
+ name: 'reverseHolo';
54
+ options: Partial<ReverseHoloDetectionChannelFlags>;
55
+ } | {
56
+ name: 'holo';
57
+ options?: HoloOptions;
58
+ };
32
59
  export type ReverseHoloDetectionChannelFlags = {
33
60
  redChannel: number;
34
61
  greenChannel: number;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACpC,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAC5C,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC;AAE9B,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB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C9B,CAAC;AAGF,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI;KACnD,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACf,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAExB,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,GACN,MAAM,GACN,IAAI,GACJ,SAAS,CAAC;AAId,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,SAAS,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC3E,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAC5E,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE1B,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,mBAAmB,CAAC;IAC5B,KAAK,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,UAAU,CACtC,kBAAkB,CAAC,qBAAqB,CAAC,CAC1C,CAAC,CAAC,CAAC,CAAC;AAEL,MAAM,MAAM,sBAAsB,GAAG,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-shine",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Fast and efficient way of adding interactive effects that are run entirely on shaders using typeGPU.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -62,6 +62,7 @@
62
62
  "registry": "https://registry.npmjs.org/"
63
63
  },
64
64
  "devDependencies": {
65
+ "@babel/plugin-transform-typescript": "^7.28.5",
65
66
  "@commitlint/config-conventional": "^19.6.0",
66
67
  "@eslint/compat": "^1.2.7",
67
68
  "@eslint/eslintrc": "^3.3.0",
@@ -16,6 +16,7 @@ import {
16
16
  import * as d from 'typegpu/data';
17
17
  import type {
18
18
  TextureProps,
19
+ // TgpuComputePipeline,
19
20
  TgpuRenderPipeline,
20
21
  TgpuRoot,
21
22
  TgpuTexture,
@@ -23,6 +24,7 @@ import type {
23
24
  import {
24
25
  bufferData,
25
26
  type BufferData,
27
+ // precomputeColorMaskBindGroupLayout,
26
28
  textureBindGroupLayout,
27
29
  } from '../shaders/bindGroupLayouts';
28
30
  import useAnimationFrame from '../hooks/useAnimationFrame';
@@ -49,13 +51,13 @@ import type {
49
51
  ColorAttachment,
50
52
  ColorMask,
51
53
  DeepPartiallyOptional,
54
+ Effect,
52
55
  GlareOptions,
53
56
  PipelineAttachmentPair,
54
- ReverseHoloDetectionChannelFlags,
55
57
  } from '../types/types';
56
58
  import {
57
- colorMaskToTyped,
58
- createColorMask,
59
+ colorMasksToTyped,
60
+ createColorMasks,
59
61
  createGlareOptions,
60
62
  createReverseHoloDetectionChannelFlags,
61
63
  } from '../types/typeUtils';
@@ -75,19 +77,28 @@ import {
75
77
  zeroV3d,
76
78
  } from '../utils/vector';
77
79
  import { baseTextureFragment } from '../shaders/fragmentShaders/baseTextureFragment';
80
+ // import { precomputeColorMask } from '../shaders/computeShaders/precomputeColorMask';
78
81
 
79
82
  export interface SharedProps {
80
83
  width: number;
81
84
  height: number;
82
85
  glareOptions?: Partial<GlareOptions>;
83
- colorMaskOptions?: DeepPartiallyOptional<ColorMask, 'baseColor'>;
84
- touchPosition?: SharedValue<V2d>;
85
- addReverseHolo?: boolean;
86
- reverseHoloDetectionChannelOptions?: Partial<ReverseHoloDetectionChannelFlags>;
87
- addHolo?: boolean;
88
- translateViewIn3d?: boolean;
86
+ enableGlare?: boolean;
87
+ highlightColors?: DeepPartiallyOptional<ColorMask, 'baseColor'>[];
88
+ isHighlightInclusive?: boolean;
89
+ lightPosition?: SharedValue<V2d>;
90
+ // addReverseHolo?: boolean;
91
+ // reverseHoloDetectionChannelOptions?: Partial<ReverseHoloDetectionChannelFlags>;
92
+ // addHolo?: boolean;
93
+ translateViewIn3d?:
94
+ | boolean
95
+ | {
96
+ perspective?: number;
97
+ intensity?: number;
98
+ };
89
99
  style?: ViewStyle;
90
100
  containerStyle?: ViewStyle;
101
+ effects?: Effect[];
91
102
  }
92
103
 
93
104
  interface ContentProps extends SharedProps {
@@ -103,19 +114,23 @@ interface PipelineMap {
103
114
  mask: TgpuRenderPipeline | void;
104
115
  reverseHolo: TgpuRenderPipeline | void;
105
116
  holo: TgpuRenderPipeline | void;
117
+ // precomputeColorMaskPipeline: TgpuComputePipeline | void;
106
118
  }
107
119
 
108
120
  export default function Content({
109
- addHolo,
110
- addReverseHolo,
111
- reverseHoloDetectionChannelOptions,
112
- colorMaskOptions,
121
+ // addHolo,
122
+ // addReverseHolo,
123
+ // reverseHoloDetectionChannelOptions,
124
+ effects,
125
+ highlightColors,
126
+ isHighlightInclusive = true,
113
127
  glareOptions,
128
+ enableGlare = true,
114
129
  height,
115
130
  imageTexture,
116
131
  maskTexture,
117
132
  root,
118
- touchPosition,
133
+ lightPosition,
119
134
  width,
120
135
  translateViewIn3d = false,
121
136
  style,
@@ -157,12 +172,19 @@ export default function Content({
157
172
  );
158
173
 
159
174
  const animatedStyle = useAnimatedStyle(() => {
160
- const rotX = rotation.value.x * 10;
161
- const rotY = rotation.value.y * 10;
175
+ let perspective: number = 300;
176
+ let intensity: number = 10;
177
+ if (typeof translateViewIn3d === 'object') {
178
+ perspective = translateViewIn3d.perspective ?? perspective;
179
+ intensity = translateViewIn3d.intensity ?? intensity;
180
+ }
181
+
182
+ const rotX = rotation.value.x * intensity;
183
+ const rotY = rotation.value.y * intensity;
162
184
 
163
185
  return {
164
186
  transform: [
165
- { perspective: 300 },
187
+ { perspective: perspective },
166
188
  { rotateX: `${-rotY}deg` },
167
189
  { rotateY: `${rotX}deg` },
168
190
  ],
@@ -182,9 +204,9 @@ export default function Content({
182
204
  useDerivedValue(() => {
183
205
  'worklet';
184
206
 
185
- if (touchPosition) {
186
- rotation.value = touchPosition
187
- ? { x: touchPosition.value.x, y: touchPosition.value.y, z: 0 }
207
+ if (lightPosition) {
208
+ rotation.value = lightPosition
209
+ ? { x: lightPosition.value.x, y: lightPosition.value.y, z: 0 }
188
210
  : zeroV3d;
189
211
 
190
212
  return;
@@ -288,18 +310,24 @@ export default function Content({
288
310
  const colorMaskBuffer = bufferMap.addBuffer(
289
311
  root,
290
312
  'colorMask',
291
- colorMaskToTyped(
292
- createColorMask(
293
- colorMaskOptions ?? { baseColor: [-20, -20, -20], useHSV: false }
294
- )
313
+ colorMasksToTyped(
314
+ createColorMasks(
315
+ highlightColors ?? [{ baseColor: [-20, -20, -20], useHSV: false }]
316
+ ),
317
+ highlightColors && highlightColors.length
318
+ ? isHighlightInclusive
319
+ : !isHighlightInclusive
295
320
  )
296
321
  );
297
322
  const colorMaskBindGroup = createColorMaskBindGroup(root, colorMaskBuffer);
298
323
 
324
+ const reverseHoloEffect = effects
325
+ ? effects.find((e) => e.name === 'reverseHolo')
326
+ : undefined;
299
327
  const reverseHoloDetectionChannelFlagsBuffer = bufferMap.addBuffer(
300
328
  root,
301
329
  'reverseHoloDetectionChannelFlags',
302
- createReverseHoloDetectionChannelFlags(reverseHoloDetectionChannelOptions)
330
+ createReverseHoloDetectionChannelFlags(reverseHoloEffect?.options)
303
331
  );
304
332
  const reverseHoloDetectionChannelFlagsBindGroup =
305
333
  createReverseHoloDetectionChannelFlagsBindGroup(
@@ -308,6 +336,17 @@ export default function Content({
308
336
  glareBuffer
309
337
  );
310
338
 
339
+ const holoEffect = effects
340
+ ? effects.find((e) => e.name === 'holo')
341
+ : undefined;
342
+
343
+ // const precomputeColorMaskBindGroup = root.createBindGroup(
344
+ // precomputeColorMaskBindGroupLayout,
345
+ // {
346
+ // colorMaskTextureDst: colorMaskStorageTexture,
347
+ // }
348
+ // );
349
+
311
350
  const pipelineMap: PipelineMap = {
312
351
  baseTexture: attachBindGroups(
313
352
  root['~unstable']
@@ -366,6 +405,14 @@ export default function Content({
366
405
  sampler,
367
406
  presentationFormat
368
407
  ),
408
+ // precomputeColorMaskPipeline: attachBindGroups(
409
+ // root['~unstable'].withCompute(precomputeColorMask).createPipeline(),
410
+ // [
411
+ // imageTextureBindGroup,
412
+ // colorMaskBindGroup,
413
+ // precomputeColorMaskBindGroup,
414
+ // ]
415
+ // ),
369
416
  };
370
417
 
371
418
  const modifyBuffers = () => {
@@ -387,20 +434,30 @@ export default function Content({
387
434
  storeOp: 'store',
388
435
  };
389
436
 
390
- const { baseTexture, glare, mask, colorMask, holo, reverseHolo } =
391
- pipelineMap;
437
+ const {
438
+ baseTexture,
439
+ glare,
440
+ mask,
441
+ colorMask,
442
+ holo,
443
+ reverseHolo,
444
+ // precomputeColorMaskPipeline,
445
+ } = pipelineMap;
446
+
447
+ //TODO: delete this from here after testing
448
+ // precomputeColorMaskPipeline!.dispatchWorkgroups(8, 8);
392
449
 
393
450
  const pairs: PipelineAttachmentPair[] = [
394
451
  [baseTexture, initialAttachment],
395
452
  ];
396
453
 
397
- if (glareOptions && glare) {
454
+ if ((glareOptions || enableGlare) && glare) {
398
455
  pairs.push([glare, loadingAttachment]);
399
456
  }
400
457
  if (mask) pairs.push([mask, loadingAttachment]);
401
- if (addReverseHolo && reverseHolo)
458
+ if (reverseHoloEffect && reverseHolo)
402
459
  pairs.push([reverseHolo, loadingAttachment]);
403
- if (addHolo && holo) pairs.push([holo, loadingAttachment]);
460
+ if (holoEffect && holo) pairs.push([holo, loadingAttachment]);
404
461
  if (colorMask) pairs.push([colorMask, loadingAttachment]);
405
462
 
406
463
  pairs.forEach(([pipeline, attachment]) =>
@@ -428,11 +485,11 @@ export default function Content({
428
485
  rotation,
429
486
  bufferMap,
430
487
  glareOptions,
431
- colorMaskOptions,
432
- addHolo,
433
- addReverseHolo,
434
- reverseHoloDetectionChannelOptions,
488
+ enableGlare,
489
+ highlightColors,
435
490
  pixelSize,
491
+ effects,
492
+ isHighlightInclusive,
436
493
  ]);
437
494
 
438
495
  useAnimationFrame(() => renderRef.current?.());
@@ -440,11 +497,13 @@ export default function Content({
440
497
  return (
441
498
  <View
442
499
  style={{
443
- transform: [
444
- {
445
- matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 50, 1],
446
- },
447
- ],
500
+ transform: translateViewIn3d
501
+ ? [
502
+ {
503
+ matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 50, 1],
504
+ },
505
+ ]
506
+ : [],
448
507
  ...containerStyle,
449
508
  }}
450
509
  >
@@ -15,6 +15,9 @@ export function Shine({ imageURI, maskURI, ...props }: ShineProps) {
15
15
  const root = device && getOrInitRoot(device);
16
16
  const [imageTexture, setImageTexture] = useState<TgpuTexture>();
17
17
  const [maskTexture, setMaskTexture] = useState<TgpuTexture>();
18
+ // const [colorMaskStorageTexture, colorMaskStorageTexture] =
19
+ // useState<TgpuTexture>();
20
+ //TODO: complete the work with the compute shader, try out the shader
18
21
 
19
22
  useEffect(() => {
20
23
  if (root) loadBitmap(root, imageURI, setImageTexture);
@@ -24,6 +27,11 @@ export function Shine({ imageURI, maskURI, ...props }: ShineProps) {
24
27
  if (root && maskURI) loadBitmap(root, maskURI, setMaskTexture);
25
28
  }, [root, imageURI, maskURI]);
26
29
 
30
+ // useEffect(() => {
31
+ // //TODO: write the logic for allocating the storage texture for the precomputed colorMask
32
+ // if (root)
33
+ // }, [root, imageURI]);
34
+
27
35
  return (
28
36
  root &&
29
37
  imageTexture && (
@@ -16,11 +16,15 @@ type ShineGroupProps = PropsWithChildren<Partial<ShineProps>>;
16
16
  export function ShineGroup({
17
17
  children,
18
18
  glareOptions,
19
- colorMaskOptions,
19
+ highlightColors,
20
20
  maskURI,
21
- touchPosition,
22
- addHolo = false,
23
- addReverseHolo = false,
21
+ lightPosition: touchPosition,
22
+ effects,
23
+ enableGlare = true,
24
+ isHighlightInclusive = true,
25
+ translateViewIn3d = false,
26
+ containerStyle,
27
+ style,
24
28
  }: ShineGroupProps) {
25
29
  const viewShotRef = useRef<ViewShot>(null);
26
30
  const [capturedURI, setCapturedURI] = useState<string | null>(null);
@@ -76,11 +80,15 @@ export function ShineGroup({
76
80
  {...sizeFromV2d(size)}
77
81
  imageURI={capturedURI}
78
82
  glareOptions={glareOptions}
79
- colorMaskOptions={colorMaskOptions}
83
+ highlightColors={highlightColors}
80
84
  maskURI={maskURI}
81
- touchPosition={touchPosition}
82
- addReverseHolo={addReverseHolo}
83
- addHolo={addHolo}
85
+ lightPosition={touchPosition}
86
+ effects={effects}
87
+ translateViewIn3d={translateViewIn3d}
88
+ enableGlare={enableGlare}
89
+ containerStyle={containerStyle}
90
+ isHighlightInclusive={isHighlightInclusive}
91
+ style={style}
84
92
  />
85
93
  )}
86
94
  </View>
@@ -0,0 +1,33 @@
1
+ import { ColorPresets } from './colorPresets';
2
+ import { type ColorMask, type vec3 } from '../types/types';
3
+
4
+ type ColorHighlightPresetMap = {
5
+ readonly [K in keyof typeof ColorPresets]: ColorMask;
6
+ };
7
+
8
+ export const ColorHighlightPresets = Object.fromEntries(
9
+ (Object.entries(ColorPresets) as [keyof typeof ColorPresets, vec3][]).map(
10
+ ([key, color]) => {
11
+ return [
12
+ key,
13
+ {
14
+ baseColor: color,
15
+ useHSV: true,
16
+ hueToleranceRange: { upper: 15, lower: 15 },
17
+ } as ColorMask,
18
+ ];
19
+ }
20
+ )
21
+ ) as ColorHighlightPresetMap;
22
+
23
+ export const createHighlightColor = (
24
+ rgb: vec3,
25
+ useHSV: boolean = true,
26
+ hueToleranceRange: { upper: number; lower: number } = { upper: 15, lower: 15 }
27
+ ) => {
28
+ return {
29
+ baseColor: rgb,
30
+ useHSV,
31
+ hueToleranceRange,
32
+ } as ColorMask;
33
+ };
@@ -0,0 +1,11 @@
1
+ import type { Effect } from '../types/types';
2
+
3
+ export const Effects = {
4
+ REVERSE_HOLO: {
5
+ name: 'reverseHolo',
6
+ options: { redChannel: 1.0, greenChannel: 0.0, blueChannel: 0.0 },
7
+ },
8
+ HOLO: {
9
+ name: 'holo',
10
+ },
11
+ } as const satisfies Record<string, Effect>;
package/src/index.tsx CHANGED
@@ -17,3 +17,5 @@ export type { ShineProps } from './components/Shine';
17
17
  export * from './utils/vector';
18
18
  export type { V2d, V3d } from './types/vector';
19
19
  export * from './enums/colorPresets';
20
+ export * from './enums/effectPresets';
21
+ export * from './enums/colorHighlightPresets';
@@ -3,14 +3,12 @@ import * as d from 'typegpu/data';
3
3
  import type { BufferUsageType } from './resourceManagement/bufferManager';
4
4
 
5
5
  export const textureBindGroupLayout = tgpu.bindGroupLayout({
6
- // texture: { texture: d.texture2d(d.f32) } //TODO: revert this change after bumping typegpu version (currently there is a bug with texture formats)
7
- texture: { texture: 'float', dimension: '2d', sampleType: 'float' },
6
+ texture: { texture: d.texture2d(d.f32) },
8
7
  sampler: { sampler: 'filtering' },
9
8
  });
10
9
 
11
10
  export const maskTextureBindGroupLayout = tgpu.bindGroupLayout({
12
- // texture: { texture: d.texture2d(d.f32) }, //TODO: same as above
13
- texture: { texture: 'float', dimension: '2d', sampleType: 'float' },
11
+ texture: { texture: d.texture2d(d.f32) },
14
12
  sampler: { sampler: 'filtering' },
15
13
  });
16
14
 
@@ -19,10 +17,12 @@ export const rotationBindGroupLayout = tgpu.bindGroupLayout({
19
17
  });
20
18
 
21
19
  export const glareSchema = d.struct({
22
- glowPower: d.f32,
23
- hueShiftAngleMax: d.f32,
24
- hueShiftAngleMin: d.f32,
25
- hueBlendPower: d.f32,
20
+ glareColor: d.struct({
21
+ hueShiftAngleMax: d.f32,
22
+ hueShiftAngleMin: d.f32,
23
+ hueBlendPower: d.f32,
24
+ }),
25
+ glowPower: d.align(16, d.f32),
26
26
  lightIntensity: d.f32,
27
27
  glareIntensity: d.f32,
28
28
  });
@@ -33,6 +33,7 @@ export const glareBindGroupLayout = tgpu.bindGroupLayout({
33
33
  glareOptions: { uniform: glareSchema },
34
34
  });
35
35
 
36
+ //TODO: change the buffer so it reserves memory for an array of colorMaskSchemas
36
37
  export const colorMaskSchema = d.struct({
37
38
  baseColor: d.vec3f,
38
39
  rgbToleranceRange: d.struct({
@@ -53,8 +54,18 @@ export const colorMaskSchema = d.struct({
53
54
 
54
55
  export type ColorMaskSchema = typeof colorMaskSchema;
55
56
 
57
+ export const COLOR_MASK_MAX_COUNT = 16;
58
+
59
+ export const colorMaskArraySchema = d.struct({
60
+ masks: d.arrayOf(colorMaskSchema, COLOR_MASK_MAX_COUNT),
61
+ usedMaskCount: d.i32,
62
+ reverseHighlight: d.i32,
63
+ });
64
+
65
+ export type ColorMaskArraySchema = typeof colorMaskArraySchema;
66
+
56
67
  export const colorMaskBindGroupLayout = tgpu.bindGroupLayout({
57
- mask: { uniform: colorMaskSchema },
68
+ colorMasks: { uniform: colorMaskArraySchema },
58
69
  });
59
70
 
60
71
  export const reverseHoloDetectionChannelFlagsSchema = d.struct({
@@ -75,6 +86,18 @@ export const reverseHoloDetectionChannelFlagsBindGroupLayout =
75
86
  glareOptions: { uniform: glareSchema },
76
87
  });
77
88
 
89
+ export const precomputeColorMaskBindGroupLayout = tgpu.bindGroupLayout({
90
+ colorMaskTextureDst: {
91
+ storageTexture: d.textureStorage2d('rgba8unorm', 'read-write'),
92
+ },
93
+ });
94
+
95
+ export type BufferSchemas =
96
+ | d.Vec3f
97
+ | ReverseHoloDetectionChannelFlagsSchema
98
+ | ColorMaskArraySchema
99
+ | GlareSchema;
100
+
78
101
  export const bufferData = {
79
102
  rotation: {
80
103
  schema: d.vec3f,
@@ -85,7 +108,7 @@ export const bufferData = {
85
108
  usage: 'uniform',
86
109
  },
87
110
  colorMask: {
88
- schema: colorMaskSchema,
111
+ schema: colorMaskArraySchema,
89
112
  usage: 'uniform',
90
113
  },
91
114
  reverseHoloDetectionChannelFlags: {
@@ -94,7 +117,7 @@ export const bufferData = {
94
117
  },
95
118
  } as const satisfies Record<
96
119
  string,
97
- { schema: ValidateBufferSchema<any>; usage: BufferUsageType }
120
+ { schema: ValidateBufferSchema<BufferSchemas>; usage: BufferUsageType }
98
121
  >;
99
122
 
100
123
  export type BufferData = typeof bufferData;
@@ -4,24 +4,14 @@ import {
4
4
  glareBindGroupLayout,
5
5
  glareSchema,
6
6
  colorMaskBindGroupLayout,
7
- type ColorMaskSchema,
8
7
  rotationBindGroupLayout,
9
8
  type GlareSchema,
10
- colorMaskSchema,
11
9
  type ReverseHoloDetectionChannelFlagsSchema,
12
10
  reverseHoloDetectionChannelFlagsBindGroupLayout,
11
+ type ColorMaskArraySchema,
13
12
  } from './bindGroupLayouts';
14
- import type {
15
- GlareOptions,
16
- ColorMask,
17
- PartiallyOptional,
18
- } from '../types/types';
19
- import {
20
- colorMaskToTyped,
21
- createGlareOptions,
22
- createColorMask,
23
- mapToF32,
24
- } from '../types/typeUtils';
13
+ import type { GlareOptions } from '../types/types';
14
+ import { createGlareOptions, glareOptionsToTyped } from '../types/typeUtils';
25
15
  import { componentsFromV3d, zeroV3d } from '../utils/vector';
26
16
 
27
17
  export const createRotationBuffer = (root: TgpuRoot, initValues = zeroV3d) =>
@@ -42,7 +32,10 @@ export const createGlareOptionsBuffer = (
42
32
  initValues?: Partial<GlareOptions>
43
33
  ) =>
44
34
  root
45
- .createBuffer(glareSchema, mapToF32(createGlareOptions({ ...initValues })))
35
+ .createBuffer(
36
+ glareSchema,
37
+ glareOptionsToTyped(createGlareOptions({ ...initValues }))
38
+ )
46
39
  .$usage('uniform');
47
40
 
48
41
  export const createGlareBindGroup = (
@@ -53,23 +46,23 @@ export const createGlareBindGroup = (
53
46
  glareOptions: buffer,
54
47
  });
55
48
 
56
- export const createColorMaskBuffer = (
57
- root: TgpuRoot,
58
- initValues: PartiallyOptional<ColorMask, 'baseColor'>
59
- ) =>
60
- root
61
- .createBuffer(
62
- colorMaskSchema,
63
- colorMaskToTyped(createColorMask({ ...initValues }))
64
- )
65
- .$usage('uniform');
49
+ // export const createColorMaskBuffer = (
50
+ // root: TgpuRoot,
51
+ // initValues: PartiallyOptional<ColorMask, 'baseColor'>[]
52
+ // ) =>
53
+ // root
54
+ // .createBuffer(
55
+ // colorMaskSchema,
56
+ // colorMasksToTyped(createColorMasks(initValues))
57
+ // )
58
+ // .$usage('uniform');
66
59
 
67
60
  export const createColorMaskBindGroup = (
68
61
  root: TgpuRoot,
69
- buffer: TgpuBuffer<ColorMaskSchema> & UniformFlag
62
+ buffer: TgpuBuffer<ColorMaskArraySchema> & UniformFlag
70
63
  ) =>
71
64
  root.createBindGroup(colorMaskBindGroupLayout, {
72
- mask: buffer,
65
+ colorMasks: buffer,
73
66
  });
74
67
 
75
68
  export const createReverseHoloDetectionChannelFlagsBindGroup = (
@@ -0,0 +1,29 @@
1
+ import tgpu from 'typegpu';
2
+ import * as d from 'typegpu/data';
3
+ import * as std from 'typegpu/std';
4
+ import {
5
+ precomputeColorMaskBindGroupLayout,
6
+ textureBindGroupLayout,
7
+ } from './../bindGroupLayouts';
8
+
9
+ export const precomputeColorMask = tgpu['~unstable'].computeFn({
10
+ in: { gid: d.builtin.globalInvocationId },
11
+ workgroupSize: [8, 8, 1],
12
+ })((input) => {
13
+ const x = input.gid.x;
14
+ const y = input.gid.y;
15
+ const colorMaskStorageTexture =
16
+ precomputeColorMaskBindGroupLayout.$.colorMaskTextureDst;
17
+ const size = std.textureDimensions(colorMaskStorageTexture);
18
+
19
+ if (x >= size.x || y >= size.y) return;
20
+ const uv = d.vec2f(d.f32(x) / d.f32(size.x), d.f32(y) / d.f32(size.y));
21
+
22
+ const colorSampled = std.textureSample(
23
+ textureBindGroupLayout.$.texture,
24
+ textureBindGroupLayout.$.sampler,
25
+ uv
26
+ );
27
+
28
+ std.textureStore(colorMaskStorageTexture, d.vec2u(x, y), colorSampled);
29
+ });