react-native-shine 0.4.0 → 0.5.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 (65) hide show
  1. package/lib/module/components/Content.js +35 -32
  2. package/lib/module/components/Content.js.map +1 -1
  3. package/lib/module/components/ShineGroup.js +0 -2
  4. package/lib/module/components/ShineGroup.js.map +1 -1
  5. package/lib/module/config/debugMode.js +4 -0
  6. package/lib/module/config/debugMode.js.map +1 -0
  7. package/lib/module/enums/colorPresets.js +71 -0
  8. package/lib/module/enums/colorPresets.js.map +1 -0
  9. package/lib/module/index.js +1 -0
  10. package/lib/module/index.js.map +1 -1
  11. package/lib/module/shaders/bindGroupLayouts.js +10 -1
  12. package/lib/module/shaders/bindGroupLayouts.js.map +1 -1
  13. package/lib/module/shaders/fragmentShaders/colorMaskFragment.js +37 -6
  14. package/lib/module/shaders/fragmentShaders/colorMaskFragment.js.map +1 -1
  15. package/lib/module/shaders/resourceManagement/bitmaps.js +4 -3
  16. package/lib/module/shaders/resourceManagement/bitmaps.js.map +1 -1
  17. package/lib/module/shaders/resourceManagement/bufferManager.js +6 -1
  18. package/lib/module/shaders/resourceManagement/bufferManager.js.map +1 -1
  19. package/lib/module/shaders/tgpuUtils.js +27 -19
  20. package/lib/module/shaders/tgpuUtils.js.map +1 -1
  21. package/lib/module/shaders/utils.js +1 -1
  22. package/lib/module/types/typeUtils.js +36 -4
  23. package/lib/module/types/typeUtils.js.map +1 -1
  24. package/lib/module/utils/size.js +2 -2
  25. package/lib/module/utils/vector.js +26 -19
  26. package/lib/module/utils/vector.js.map +1 -1
  27. package/lib/typescript/src/components/Content.d.ts +4 -2
  28. package/lib/typescript/src/components/Content.d.ts.map +1 -1
  29. package/lib/typescript/src/components/ShineGroup.d.ts +1 -1
  30. package/lib/typescript/src/components/ShineGroup.d.ts.map +1 -1
  31. package/lib/typescript/src/config/debugMode.d.ts +2 -0
  32. package/lib/typescript/src/config/debugMode.d.ts.map +1 -0
  33. package/lib/typescript/src/enums/colorPresets.d.ts +33 -0
  34. package/lib/typescript/src/enums/colorPresets.d.ts.map +1 -0
  35. package/lib/typescript/src/index.d.ts +1 -0
  36. package/lib/typescript/src/index.d.ts.map +1 -1
  37. package/lib/typescript/src/shaders/bindGroupLayouts.d.ts +27 -0
  38. package/lib/typescript/src/shaders/bindGroupLayouts.d.ts.map +1 -1
  39. package/lib/typescript/src/shaders/bindGroupUtils.d.ts +18 -0
  40. package/lib/typescript/src/shaders/bindGroupUtils.d.ts.map +1 -1
  41. package/lib/typescript/src/shaders/fragmentShaders/colorMaskFragment.d.ts.map +1 -1
  42. package/lib/typescript/src/shaders/resourceManagement/bitmaps.d.ts.map +1 -1
  43. package/lib/typescript/src/shaders/resourceManagement/bufferManager.d.ts.map +1 -1
  44. package/lib/typescript/src/shaders/tgpuUtils.d.ts +1 -0
  45. package/lib/typescript/src/shaders/tgpuUtils.d.ts.map +1 -1
  46. package/lib/typescript/src/types/typeUtils.d.ts +9 -0
  47. package/lib/typescript/src/types/typeUtils.d.ts.map +1 -1
  48. package/lib/typescript/src/types/types.d.ts +9 -0
  49. package/lib/typescript/src/types/types.d.ts.map +1 -1
  50. package/lib/typescript/src/utils/vector.d.ts +1 -0
  51. package/lib/typescript/src/utils/vector.d.ts.map +1 -1
  52. package/package.json +6 -6
  53. package/src/components/Content.tsx +32 -11
  54. package/src/components/ShineGroup.tsx +0 -2
  55. package/src/config/debugMode.ts +1 -0
  56. package/src/enums/colorPresets.ts +41 -0
  57. package/src/index.tsx +1 -0
  58. package/src/shaders/bindGroupLayouts.ts +9 -0
  59. package/src/shaders/fragmentShaders/colorMaskFragment.ts +46 -4
  60. package/src/shaders/resourceManagement/bitmaps.ts +4 -3
  61. package/src/shaders/resourceManagement/bufferManager.ts +10 -1
  62. package/src/shaders/tgpuUtils.ts +38 -21
  63. package/src/types/typeUtils.ts +33 -2
  64. package/src/types/types.ts +6 -0
  65. package/src/utils/vector.ts +4 -0
@@ -1,19 +1,20 @@
1
1
  import { Asset } from 'expo-asset';
2
+ import { debug } from '../../config/debugMode';
2
3
 
3
4
  const getBitmapFromURI = async (uri: string): Promise<ImageBitmap> => {
4
5
  if (uriToBitmapMap.has(uri)) return uriToBitmapMap.get(uri)!;
5
- console.log('bitmap not found in cache, fetching from URI');
6
+ if (debug) console.log('bitmap not found in cache, fetching from URI');
6
7
 
7
8
  const ast = Asset.fromURI(uri);
8
9
  await ast.downloadAsync();
9
10
  const fileURI = ast.localUri || ast.uri;
10
11
 
11
- console.log('fetch completed, creating ImageBitmap');
12
+ if (debug) console.log('fetch completed, creating ImageBitmap');
12
13
  const response = await fetch(fileURI);
13
14
  const blob = await response.blob();
14
15
  const imageBitmap = await createImageBitmap(blob);
15
16
 
16
- console.log('bitmap size: ', imageBitmap);
17
+ if (debug) console.log('bitmap size: ', imageBitmap);
17
18
  uriToBitmapMap.set(uri, imageBitmap);
18
19
  return imageBitmap;
19
20
  };
@@ -1,4 +1,5 @@
1
1
  import type { TgpuRoot, TgpuBuffer, ValidateBufferSchema } from 'typegpu';
2
+ import { debug } from '../../config/debugMode';
2
3
 
3
4
  export type BufferUsageType = 'uniform' | 'storage' | 'vertex';
4
5
 
@@ -49,7 +50,15 @@ export class TypedBufferMap<
49
50
 
50
51
  const { schema, usage } = entry;
51
52
  if (this.buffers[key]) {
52
- console.warn(`Buffer "${String(key)}" already exists. Skipping...`);
53
+ if (debug) console.warn(`Buffer "${String(key)}" already exists.`);
54
+
55
+ if (initValues) {
56
+ (this.buffers[key] as TgpuBuffer<any>).write(initValues);
57
+ if (debug)
58
+ console.log(
59
+ `Buffer "${String(key)}" updated with new initial values.`
60
+ );
61
+ }
53
62
  return this.buffers[key]!;
54
63
  }
55
64
 
@@ -33,33 +33,50 @@ export const hueShift = tgpu.fn(
33
33
  return d.vec3f(r, g, b);
34
34
  });
35
35
 
36
- export const rgbToHSV = tgpu.fn(
36
+ export const rgbToHSV = tgpu['~unstable'].fn(
37
37
  [d.vec3f],
38
38
  d.vec3f
39
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)
40
+ const K = d.vec4f(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
41
+ const p = std.mix(
42
+ d.vec4f(rgb.y, rgb.z, K.w, K.z),
43
+ d.vec4f(rgb.z, rgb.y, K.x, K.y),
44
+ std.step(rgb.z, rgb.y)
53
45
  );
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));
46
+ const q = std.mix(
47
+ d.vec4f(p.x, p.y, p.w, rgb.x),
48
+ d.vec4f(rgb.x, p.y, p.z, p.x),
49
+ std.step(p.x, rgb.x)
50
+ );
51
+
52
+ const d_val = std.sub(q.x, std.min(q.w, q.y));
53
+ const epsilon = d.f32(1.0e-10);
57
54
 
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;
55
+ const h = std.abs(
56
+ std.add(
57
+ q.z,
58
+ std.div(std.sub(q.w, q.y), std.add(std.mul(6.0, d_val), epsilon))
59
+ )
60
+ );
61
+ const s = std.div(d_val, std.add(q.x, epsilon));
62
+ const v = q.x;
63
+
64
+ return d.vec3f(h, s, v);
65
+ });
61
66
 
62
- return d.vec3f(hue, saturation, value);
67
+ export const hsvToRGB = tgpu['~unstable'].fn(
68
+ [d.vec3f],
69
+ d.vec3f
70
+ )((hsv) => {
71
+ const K = d.vec4f(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
72
+ const p = std.abs(
73
+ std.sub(std.mul(std.fract(std.add(hsv.xxx, K.xxx)), 6.0), K.zzz)
74
+ );
75
+ const rgb = std.mul(
76
+ hsv.z,
77
+ std.mix(K.xxx, std.saturate(std.sub(p, K.xxx)), hsv.y)
78
+ );
79
+ return rgb;
63
80
  });
64
81
 
65
82
  export const fmod = tgpu.fn(
@@ -51,16 +51,39 @@ export const mapToF32 = <T extends Record<string, number>>(
51
51
  export const createColorMask = (
52
52
  colorMask: DeepPartiallyOptional<ColorMask, 'baseColor'>
53
53
  ): ColorMask => {
54
- const { baseColor, rgbToleranceRange } = colorMask;
54
+ const {
55
+ baseColor,
56
+ rgbToleranceRange,
57
+ useHSV,
58
+ hueToleranceRange,
59
+ brightnessTolerance,
60
+ saturationTolerance,
61
+ lowBrightnessThreshold,
62
+ lowSaturationThreshold,
63
+ } = colorMask;
55
64
  const baseTolerance = {
56
65
  upper: [20, 20, 20] as vec3,
57
66
  lower: [20, 20, 20] as vec3,
58
67
  };
68
+ const baseHueTolerance = {
69
+ upper: 20,
70
+ lower: 20,
71
+ };
59
72
  const tolerance = { ...baseTolerance, ...rgbToleranceRange };
73
+ const hueTolerance = { ...baseHueTolerance, ...hueToleranceRange };
60
74
 
75
+ // TODO: add radian and degree angle handling
76
+ // '123deg' <- interpret as a numeric angle value
77
+ // 2 <- interpret as a radian value
61
78
  const mask: ColorMask = {
62
79
  baseColor: baseColor,
63
80
  rgbToleranceRange: tolerance,
81
+ useHSV: useHSV!!,
82
+ hueToleranceRange: hueTolerance,
83
+ brightnessTolerance: brightnessTolerance ?? 1.0,
84
+ saturationTolerance: saturationTolerance ?? 1.0,
85
+ lowBrightnessThreshold: lowBrightnessThreshold ?? 0.0,
86
+ lowSaturationThreshold: lowSaturationThreshold ?? 0.0,
64
87
  };
65
88
 
66
89
  return mask;
@@ -73,6 +96,15 @@ export const colorMaskToTyped = (colorMask: ColorMask) => {
73
96
  upper: div(numberArrToTyped(colorMask.rgbToleranceRange.upper), 255),
74
97
  lower: div(numberArrToTyped(colorMask.rgbToleranceRange.lower), 255),
75
98
  },
99
+ useHSV: d.u32(colorMask.useHSV ? 1 : 0),
100
+ hueToleranceRange: {
101
+ lower: div(f32(colorMask.hueToleranceRange.lower), 360),
102
+ upper: div(f32(colorMask.hueToleranceRange.upper), 360),
103
+ },
104
+ brightnessTolerance: f32(colorMask.brightnessTolerance),
105
+ saturationTolerance: f32(colorMask.saturationTolerance),
106
+ lowSaturationThreshold: f32(colorMask.lowSaturationThreshold),
107
+ lowBrightnessThreshold: f32(colorMask.lowBrightnessThreshold),
76
108
  };
77
109
  return result;
78
110
  };
@@ -116,7 +148,6 @@ export const createReverseHoloDetectionChannelFlags = (
116
148
  };
117
149
  }
118
150
 
119
- console.log('createReverseHoloDetectionChannelFlags:', channelFlags);
120
151
  return channelFlags;
121
152
  };
122
153
 
@@ -21,6 +21,12 @@ export type GlareOptions = {
21
21
 
22
22
  export type ColorMask = {
23
23
  baseColor: vec3;
24
+ useHSV?: boolean;
25
+ hueToleranceRange: { upper: number; lower: number };
26
+ brightnessTolerance?: number;
27
+ lowBrightnessThreshold?: number;
28
+ saturationTolerance?: number;
29
+ lowSaturationThreshold?: number;
24
30
  rgbToleranceRange: {
25
31
  upper: vec3;
26
32
  lower: vec3;
@@ -129,4 +129,8 @@ export function degToRad(deg: number): number {
129
129
  return (deg * Math.PI) / 180;
130
130
  }
131
131
 
132
+ export function createV3d(x: number, y: number, z: number): V3d {
133
+ return { x: x, y: y, z: z };
134
+ }
135
+
132
136
  export const zeroV3d = { x: 0, y: 0, z: 0 };