react-native-shine 0.6.0 → 0.7.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.
Files changed (62) hide show
  1. package/lib/module/components/Content.js +41 -27
  2. package/lib/module/components/Content.js.map +1 -1
  3. package/lib/module/components/ShineGroup.js +16 -8
  4. package/lib/module/components/ShineGroup.js.map +1 -1
  5. package/lib/module/enums/colorHighlightPresets.js +24 -0
  6. package/lib/module/enums/colorHighlightPresets.js.map +1 -0
  7. package/lib/module/enums/effectPresets.js +16 -0
  8. package/lib/module/enums/effectPresets.js.map +1 -0
  9. package/lib/module/index.js +2 -0
  10. package/lib/module/index.js.map +1 -1
  11. package/lib/module/shaders/bindGroupLayouts.js +19 -15
  12. package/lib/module/shaders/bindGroupLayouts.js.map +1 -1
  13. package/lib/module/shaders/bindGroupUtils.js +16 -7
  14. package/lib/module/shaders/bindGroupUtils.js.map +1 -1
  15. package/lib/module/shaders/fragmentShaders/colorMaskFragment.js +53 -41
  16. package/lib/module/shaders/fragmentShaders/colorMaskFragment.js.map +1 -1
  17. package/lib/module/shaders/fragmentShaders/glareFragment.js +11 -8
  18. package/lib/module/shaders/fragmentShaders/glareFragment.js.map +1 -1
  19. package/lib/module/shaders/fragmentShaders/holoFragment.js +6 -5
  20. package/lib/module/shaders/fragmentShaders/holoFragment.js.map +1 -1
  21. package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js +12 -8
  22. package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js.map +1 -1
  23. package/lib/module/types/size.js +2 -0
  24. package/lib/module/types/typeUtils.js +97 -51
  25. package/lib/module/types/typeUtils.js.map +1 -1
  26. package/lib/module/types/vector.js +2 -0
  27. package/lib/module/utils/vector.js +6 -6
  28. package/lib/typescript/src/components/Content.d.ts +11 -8
  29. package/lib/typescript/src/components/Content.d.ts.map +1 -1
  30. package/lib/typescript/src/components/ShineGroup.d.ts +1 -1
  31. package/lib/typescript/src/components/ShineGroup.d.ts.map +1 -1
  32. package/lib/typescript/src/enums/colorHighlightPresets.d.ts +12 -0
  33. package/lib/typescript/src/enums/colorHighlightPresets.d.ts.map +1 -0
  34. package/lib/typescript/src/enums/effectPresets.d.ts +14 -0
  35. package/lib/typescript/src/enums/effectPresets.d.ts.map +1 -0
  36. package/lib/typescript/src/index.d.ts +2 -0
  37. package/lib/typescript/src/index.d.ts.map +1 -1
  38. package/lib/typescript/src/shaders/bindGroupLayouts.d.ts +93 -49
  39. package/lib/typescript/src/shaders/bindGroupLayouts.d.ts.map +1 -1
  40. package/lib/typescript/src/shaders/bindGroupUtils.d.ts +41 -48
  41. package/lib/typescript/src/shaders/bindGroupUtils.d.ts.map +1 -1
  42. package/lib/typescript/src/shaders/fragmentShaders/colorMaskFragment.d.ts.map +1 -1
  43. package/lib/typescript/src/shaders/fragmentShaders/glareFragment.d.ts.map +1 -1
  44. package/lib/typescript/src/shaders/fragmentShaders/reverseHoloFragment.d.ts.map +1 -1
  45. package/lib/typescript/src/types/typeUtils.d.ts +32 -3
  46. package/lib/typescript/src/types/typeUtils.d.ts.map +1 -1
  47. package/lib/typescript/src/types/types.d.ts +31 -4
  48. package/lib/typescript/src/types/types.d.ts.map +1 -1
  49. package/package.json +2 -1
  50. package/src/components/Content.tsx +62 -34
  51. package/src/components/ShineGroup.tsx +16 -8
  52. package/src/enums/colorHighlightPresets.ts +33 -0
  53. package/src/enums/effectPresets.ts +11 -0
  54. package/src/index.tsx +2 -0
  55. package/src/shaders/bindGroupLayouts.ts +26 -10
  56. package/src/shaders/bindGroupUtils.ts +19 -26
  57. package/src/shaders/fragmentShaders/colorMaskFragment.ts +64 -45
  58. package/src/shaders/fragmentShaders/glareFragment.ts +10 -6
  59. package/src/shaders/fragmentShaders/holoFragment.ts +5 -5
  60. package/src/shaders/fragmentShaders/reverseHoloFragment.ts +12 -7
  61. package/src/types/typeUtils.ts +100 -57
  62. package/src/types/types.ts +36 -4
@@ -49,13 +49,13 @@ import type {
49
49
  ColorAttachment,
50
50
  ColorMask,
51
51
  DeepPartiallyOptional,
52
+ Effect,
52
53
  GlareOptions,
53
54
  PipelineAttachmentPair,
54
- ReverseHoloDetectionChannelFlags,
55
55
  } from '../types/types';
56
56
  import {
57
- colorMaskToTyped,
58
- createColorMask,
57
+ colorMasksToTyped,
58
+ createColorMasks,
59
59
  createGlareOptions,
60
60
  createReverseHoloDetectionChannelFlags,
61
61
  } from '../types/typeUtils';
@@ -80,14 +80,22 @@ export interface SharedProps {
80
80
  width: number;
81
81
  height: number;
82
82
  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;
83
+ enableGlare?: boolean;
84
+ highlightColors?: DeepPartiallyOptional<ColorMask, 'baseColor'>[];
85
+ isHighlightInclusive?: boolean;
86
+ lightPosition?: SharedValue<V2d>;
87
+ // addReverseHolo?: boolean;
88
+ // reverseHoloDetectionChannelOptions?: Partial<ReverseHoloDetectionChannelFlags>;
89
+ // addHolo?: boolean;
90
+ translateViewIn3d?:
91
+ | boolean
92
+ | {
93
+ perspective?: number;
94
+ intensity?: number;
95
+ };
89
96
  style?: ViewStyle;
90
97
  containerStyle?: ViewStyle;
98
+ effects?: Effect[];
91
99
  }
92
100
 
93
101
  interface ContentProps extends SharedProps {
@@ -106,16 +114,19 @@ interface PipelineMap {
106
114
  }
107
115
 
108
116
  export default function Content({
109
- addHolo,
110
- addReverseHolo,
111
- reverseHoloDetectionChannelOptions,
112
- colorMaskOptions,
117
+ // addHolo,
118
+ // addReverseHolo,
119
+ // reverseHoloDetectionChannelOptions,
120
+ effects,
121
+ highlightColors,
122
+ isHighlightInclusive = true,
113
123
  glareOptions,
124
+ enableGlare = true,
114
125
  height,
115
126
  imageTexture,
116
127
  maskTexture,
117
128
  root,
118
- touchPosition,
129
+ lightPosition: touchPosition,
119
130
  width,
120
131
  translateViewIn3d = false,
121
132
  style,
@@ -157,12 +168,19 @@ export default function Content({
157
168
  );
158
169
 
159
170
  const animatedStyle = useAnimatedStyle(() => {
160
- const rotX = rotation.value.x * 10;
161
- const rotY = rotation.value.y * 10;
171
+ let perspective: number = 300;
172
+ let intensity: number = 10;
173
+ if (typeof translateViewIn3d === 'object') {
174
+ perspective = translateViewIn3d.perspective ?? perspective;
175
+ intensity = translateViewIn3d.intensity ?? intensity;
176
+ }
177
+
178
+ const rotX = rotation.value.x * intensity;
179
+ const rotY = rotation.value.y * intensity;
162
180
 
163
181
  return {
164
182
  transform: [
165
- { perspective: 300 },
183
+ { perspective: perspective },
166
184
  { rotateX: `${-rotY}deg` },
167
185
  { rotateY: `${rotX}deg` },
168
186
  ],
@@ -288,18 +306,22 @@ export default function Content({
288
306
  const colorMaskBuffer = bufferMap.addBuffer(
289
307
  root,
290
308
  'colorMask',
291
- colorMaskToTyped(
292
- createColorMask(
293
- colorMaskOptions ?? { baseColor: [-20, -20, -20], useHSV: false }
294
- )
309
+ colorMasksToTyped(
310
+ createColorMasks(
311
+ highlightColors ?? [{ baseColor: [-20, -20, -20], useHSV: false }]
312
+ ),
313
+ isHighlightInclusive
295
314
  )
296
315
  );
297
316
  const colorMaskBindGroup = createColorMaskBindGroup(root, colorMaskBuffer);
298
317
 
318
+ const reverseHoloEffect = effects
319
+ ? effects.find((e) => e.name === 'reverseHolo')
320
+ : undefined;
299
321
  const reverseHoloDetectionChannelFlagsBuffer = bufferMap.addBuffer(
300
322
  root,
301
323
  'reverseHoloDetectionChannelFlags',
302
- createReverseHoloDetectionChannelFlags(reverseHoloDetectionChannelOptions)
324
+ createReverseHoloDetectionChannelFlags(reverseHoloEffect?.options)
303
325
  );
304
326
  const reverseHoloDetectionChannelFlagsBindGroup =
305
327
  createReverseHoloDetectionChannelFlagsBindGroup(
@@ -308,6 +330,10 @@ export default function Content({
308
330
  glareBuffer
309
331
  );
310
332
 
333
+ const holoEffect = effects
334
+ ? effects.find((e) => e.name === 'holo')
335
+ : undefined;
336
+
311
337
  const pipelineMap: PipelineMap = {
312
338
  baseTexture: attachBindGroups(
313
339
  root['~unstable']
@@ -394,13 +420,13 @@ export default function Content({
394
420
  [baseTexture, initialAttachment],
395
421
  ];
396
422
 
397
- if (glareOptions && glare) {
423
+ if ((glareOptions || !enableGlare) && glare) {
398
424
  pairs.push([glare, loadingAttachment]);
399
425
  }
400
426
  if (mask) pairs.push([mask, loadingAttachment]);
401
- if (addReverseHolo && reverseHolo)
427
+ if (reverseHoloEffect && reverseHolo)
402
428
  pairs.push([reverseHolo, loadingAttachment]);
403
- if (addHolo && holo) pairs.push([holo, loadingAttachment]);
429
+ if (holoEffect && holo) pairs.push([holo, loadingAttachment]);
404
430
  if (colorMask) pairs.push([colorMask, loadingAttachment]);
405
431
 
406
432
  pairs.forEach(([pipeline, attachment]) =>
@@ -428,11 +454,11 @@ export default function Content({
428
454
  rotation,
429
455
  bufferMap,
430
456
  glareOptions,
431
- colorMaskOptions,
432
- addHolo,
433
- addReverseHolo,
434
- reverseHoloDetectionChannelOptions,
457
+ enableGlare,
458
+ highlightColors,
435
459
  pixelSize,
460
+ effects,
461
+ isHighlightInclusive,
436
462
  ]);
437
463
 
438
464
  useAnimationFrame(() => renderRef.current?.());
@@ -440,11 +466,13 @@ export default function Content({
440
466
  return (
441
467
  <View
442
468
  style={{
443
- transform: [
444
- {
445
- matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 50, 1],
446
- },
447
- ],
469
+ transform: translateViewIn3d
470
+ ? [
471
+ {
472
+ matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 50, 1],
473
+ },
474
+ ]
475
+ : [],
448
476
  ...containerStyle,
449
477
  }}
450
478
  >
@@ -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,11 @@ export const reverseHoloDetectionChannelFlagsBindGroupLayout =
75
86
  glareOptions: { uniform: glareSchema },
76
87
  });
77
88
 
89
+ export type BufferSchemas =
90
+ | ReverseHoloDetectionChannelFlagsSchema
91
+ | ColorMaskSchema
92
+ | GlareSchema;
93
+
78
94
  export const bufferData = {
79
95
  rotation: {
80
96
  schema: d.vec3f,
@@ -85,7 +101,7 @@ export const bufferData = {
85
101
  usage: 'uniform',
86
102
  },
87
103
  colorMask: {
88
- schema: colorMaskSchema,
104
+ schema: colorMaskArraySchema,
89
105
  usage: 'uniform',
90
106
  },
91
107
  reverseHoloDetectionChannelFlags: {
@@ -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 = (
@@ -6,6 +6,7 @@ import {
6
6
  colorMaskBindGroupLayout,
7
7
  } from '../bindGroupLayouts';
8
8
  import { rgbToHSV } from '../tgpuUtils';
9
+ import type { ColorMaskArrayShaderAssert } from '../../types/types';
9
10
 
10
11
  const colorMaskFragment = tgpu['~unstable'].fragmentFn({
11
12
  in: { uv: d.vec2f },
@@ -13,72 +14,90 @@ const colorMaskFragment = tgpu['~unstable'].fragmentFn({
13
14
  })((input) => {
14
15
  const texcoord = d.vec2f(input.uv.x, 1.0 - input.uv.y);
15
16
 
16
- const mask = colorMaskBindGroupLayout.$.mask;
17
- const maskedColor = mask.baseColor;
18
- const rgbToleranceRange = mask.rgbToleranceRange;
19
- const useHSV = mask.useHSV;
20
-
21
- const hueToleranceRange = mask.hueToleranceRange;
22
- const hueUpper = hueToleranceRange.upper;
23
- const hueLower = hueToleranceRange.lower;
24
-
25
- const brightnessTolerance = mask.brightnessTolerance;
26
- const saturationTolerance = mask.saturationTolerance;
27
- const lowSaturationThreshold = mask.lowSaturationThreshold;
28
- const lowBrightnessThreshold = mask.lowBrightnessThreshold;
29
-
30
- const colorMaskDebug = mask.debugMode;
31
-
32
17
  let color = std.textureSample(
33
18
  textureBindGroupLayout.$.texture,
34
19
  textureBindGroupLayout.$.sampler,
35
20
  texcoord
36
21
  );
22
+ const masks = colorMaskBindGroupLayout.$.colorMasks
23
+ .masks as ColorMaskArrayShaderAssert;
24
+ const usedMaskCount = colorMaskBindGroupLayout.$.colorMasks.usedMaskCount;
25
+ const reverseHighlight =
26
+ colorMaskBindGroupLayout.$.colorMasks.reverseHighlight;
27
+
28
+ let colorMaskDebug = d.u32(0);
29
+ let cumulativeMaskCheck = d.u32(0);
30
+ const colorHSV = rgbToHSV(color.xyz);
37
31
 
38
- const maskedColorLower = std.sub(maskedColor, rgbToleranceRange.lower);
39
- const maskedColorUpper = std.add(maskedColor, rgbToleranceRange.upper);
40
- const upperCheck = std.all(std.le(color.xyz, maskedColorUpper));
41
- const lowerCheck = std.all(std.ge(color.xyz, maskedColorLower));
42
- const rgbCheck = upperCheck && lowerCheck;
32
+ //TODO: optimize this more
33
+ for (let i = 0; i < 16; i++) {
34
+ if (usedMaskCount <= i) break;
43
35
 
44
- const maskedHSV = rgbToHSV(maskedColor);
45
- const colorHSV = rgbToHSV(color.xyz);
36
+ const mask = masks[i];
37
+ const maskedColor = mask.baseColor;
38
+ const rgbToleranceRange = mask.rgbToleranceRange;
39
+ const useHSV = mask.useHSV;
40
+
41
+ const hueToleranceRange = mask.hueToleranceRange;
42
+ const hueUpper = hueToleranceRange.upper;
43
+ const hueLower = hueToleranceRange.lower;
44
+
45
+ const brightnessTolerance = mask.brightnessTolerance;
46
+ const saturationTolerance = mask.saturationTolerance;
47
+ const lowSaturationThreshold = mask.lowSaturationThreshold;
48
+ const lowBrightnessThreshold = mask.lowBrightnessThreshold;
46
49
 
47
- let hueDiff = std.sub(colorHSV.x, maskedHSV.x);
48
- hueDiff = std.select(hueDiff, std.sub(hueDiff, 1.0), hueDiff > d.f32(0.5));
49
- hueDiff = std.select(hueDiff, std.add(hueDiff, 1.0), hueDiff < d.f32(-0.5));
50
- const lowerHueCheck = hueDiff >= -hueLower;
51
- const upperHueCheck = hueDiff <= hueUpper;
52
- let hueCheck = lowerHueCheck && upperHueCheck;
50
+ const maskedColorLower = std.sub(maskedColor, rgbToleranceRange.lower);
51
+ const maskedColorUpper = std.add(maskedColor, rgbToleranceRange.upper);
52
+ const upperCheck = std.all(std.le(color.xyz, maskedColorUpper));
53
+ const lowerCheck = std.all(std.ge(color.xyz, maskedColorLower));
54
+ const rgbCheck = upperCheck && lowerCheck;
53
55
 
54
- const saturationDiff = std.abs(std.sub(colorHSV.y, maskedHSV.y));
55
- const saturationCheck = saturationDiff <= saturationTolerance;
56
+ const maskedHSV = rgbToHSV(maskedColor);
56
57
 
57
- const brightnessDiff = std.abs(std.sub(colorHSV.z, maskedHSV.z));
58
- const brightnessCheck = brightnessDiff <= brightnessTolerance;
58
+ let hueDiff = std.sub(colorHSV.x, maskedHSV.x);
59
+ hueDiff = std.select(hueDiff, std.sub(hueDiff, 1.0), hueDiff > d.f32(0.5));
60
+ hueDiff = std.select(hueDiff, std.add(hueDiff, 1.0), hueDiff < d.f32(-0.5));
61
+ const lowerHueCheck = hueDiff >= -hueLower;
62
+ const upperHueCheck = hueDiff <= hueUpper;
63
+ let hueCheck = lowerHueCheck && upperHueCheck;
59
64
 
60
- const pixelIsGray = colorHSV.y < lowSaturationThreshold;
61
- const targetIsGray = maskedHSV.y < lowSaturationThreshold;
65
+ const saturationDiff = std.abs(std.sub(colorHSV.y, maskedHSV.y));
66
+ const saturationCheck = saturationDiff <= saturationTolerance;
62
67
 
63
- const pixelIsBlack = colorHSV.z < lowBrightnessThreshold;
64
- const targetIsBlack = maskedHSV.z < lowBrightnessThreshold;
68
+ const brightnessDiff = std.abs(std.sub(colorHSV.z, maskedHSV.z));
69
+ const brightnessCheck = brightnessDiff <= brightnessTolerance;
65
70
 
66
- //hue is unstable when either color is gray or black (low saturation or low brightness)
67
- const hueIsUnstable =
68
- pixelIsGray || targetIsGray || pixelIsBlack || targetIsBlack;
71
+ const pixelIsGray = colorHSV.y < lowSaturationThreshold;
72
+ const targetIsGray = maskedHSV.y < lowSaturationThreshold;
69
73
 
70
- hueCheck = std.select(hueCheck, d.bool(true), hueIsUnstable);
74
+ const pixelIsBlack = colorHSV.z < lowBrightnessThreshold;
75
+ const targetIsBlack = maskedHSV.z < lowBrightnessThreshold;
71
76
 
72
- const hsvCheck = hueCheck && saturationCheck && brightnessCheck;
73
- const maskCheck = std.select(rgbCheck, hsvCheck, useHSV === d.u32(1));
77
+ //hue is unstable when either color is gray or black (low saturation or low brightness)
78
+ //TODO: investigate the '||' operator usage, it seems to severely slow down the shader?
79
+ const hueIsUnstable =
80
+ pixelIsGray || targetIsGray || pixelIsBlack || targetIsBlack;
74
81
 
75
- color = std.select(color, d.vec4f(color.xyz, 0.0), maskCheck);
82
+ hueCheck = std.select(hueCheck, d.bool(true), hueIsUnstable);
76
83
 
84
+ const hsvCheck = hueCheck && saturationCheck && brightnessCheck;
85
+ const maskCheck = std.select(rgbCheck, hsvCheck, useHSV === d.u32(1));
86
+ cumulativeMaskCheck = cumulativeMaskCheck + d.u32(maskCheck);
87
+ colorMaskDebug = colorMaskDebug + mask.debugMode;
88
+ }
89
+
90
+ const maskingLogic = std.select(
91
+ cumulativeMaskCheck > 0,
92
+ cumulativeMaskCheck === 0,
93
+ reverseHighlight === 1
94
+ );
95
+ color = std.select(color, d.vec4f(color.xyz, 0.0), maskingLogic);
77
96
  //debug - shows masked areas coloring them red
78
97
  color = std.select(
79
98
  color,
80
99
  d.vec4f(1.0, 0.0, 0.0, 0.0),
81
- maskCheck && colorMaskDebug === d.u32(1)
100
+ maskingLogic && colorMaskDebug > 0
82
101
  );
83
102
  return color;
84
103
  });
@@ -23,11 +23,13 @@ export const glareFragment = tgpu['~unstable'].fragmentFn({
23
23
  const glareOptions = glareBindGroupLayout.$.glareOptions;
24
24
  const glareIntensity = glareOptions.glareIntensity;
25
25
  const glowPower = glareOptions.glowPower;
26
- const hueBlendPower = glareOptions.hueBlendPower;
27
- const hueShiftAngleMax = glareOptions.hueShiftAngleMax;
28
- const hueShiftAngleMin = glareOptions.hueShiftAngleMin;
29
26
  const lightIntensity = glareOptions.lightIntensity;
30
27
 
28
+ const glareColor = glareOptions.glareColor;
29
+ const hueBlendPower = glareColor.hueBlendPower;
30
+ const hueShiftAngleMax = glareColor.hueShiftAngleMax;
31
+ const hueShiftAngleMin = glareColor.hueShiftAngleMin;
32
+
31
33
  // const mask = colorMaskBindGroupLayout.$.mask;
32
34
  // const maskedColor = mask.baseColor;
33
35
  // const rgbToleranceRange = mask.rgbToleranceRange;
@@ -94,11 +96,13 @@ export const newGlareFragment = tgpu['~unstable'].fragmentFn({
94
96
  const opts = glareBindGroupLayout.$.glareOptions;
95
97
  const glareIntensity = opts.glareIntensity; // [0..∞): bigger → wider/stronger area
96
98
  const glowPower = opts.glowPower; // (0..∞): curve shaping; bigger → softer/wider glow
97
- const hueBlendPower = opts.hueBlendPower; // [0..1+]: how much hue-shifted color blends in
98
- const hueShiftAngleMin = opts.hueShiftAngleMin; // degrees
99
- const hueShiftAngleMax = opts.hueShiftAngleMax; // degrees
100
99
  const lightIntensity = opts.lightIntensity / 1.3; // [0..∞): brightness boost of the glare/bloom
101
100
 
101
+ const glareColor = opts.glareColor;
102
+ const hueBlendPower = glareColor.hueBlendPower; // [0..1+]: how much hue-shifted color blends in
103
+ const hueShiftAngleMin = glareColor.hueShiftAngleMin; // degrees
104
+ const hueShiftAngleMax = glareColor.hueShiftAngleMax; // degrees
105
+
102
106
  let color = std.textureSample(
103
107
  textureBindGroupLayout.$.texture,
104
108
  textureBindGroupLayout.$.sampler,
@@ -25,17 +25,17 @@ export const holoFragment = tgpu['~unstable'].fragmentFn({
25
25
  const waveX = wave.x;
26
26
  const waveY = wave.y;
27
27
 
28
- const band = std.add(0.2 * waveX * uv.x, 2 * waveY * uv.y);
28
+ const band = std.add(waveX * uv.x, waveY * uv.y * 2.0);
29
+ // const band = waveX * uv.x;
29
30
 
30
31
  //TODO: fix holo
31
- const hueAngle =
32
- d.f32(180) * std.mul(std.abs(band), (10 * Math.PI * rot.x) / 3);
33
- const rainbowColor = hueShift(d.vec3f(1.0, 1.0, 1.0), hueAngle);
32
+ const frequency = d.f32(1.0);
33
+ const hueAngle = d.f32(180) * std.mul(band, frequency * Math.PI * rot.x);
34
+ const rainbowColor = hueShift(d.vec3f(uv.x, 0.0, 0.0), hueAngle);
34
35
  const finalColor = std.mul(rainbowColor, 1.0);
35
36
 
36
37
  // console.log('\ncurrentColor = (', rainbowColor.xyz, ')');
37
38
  // console.log('hueAngle = ', hueAngle);
38
39
  // console.clear();
39
-
40
40
  return d.vec4f(finalColor, 0.9 * textureColor.w);
41
41
  });