react-native-shine 0.7.0 → 0.8.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 (130) hide show
  1. package/lib/module/components/Content.js +126 -135
  2. package/lib/module/components/Content.js.map +1 -1
  3. package/lib/module/components/Shine.js +22 -3
  4. package/lib/module/components/Shine.js.map +1 -1
  5. package/lib/module/components/ShineGroup.js +0 -4
  6. package/lib/module/components/ShineGroup.js.map +1 -1
  7. package/lib/module/enums/colorPresets.js +192 -0
  8. package/lib/module/enums/colorPresets.js.map +1 -1
  9. package/lib/module/enums/effectDefaults.js +59 -0
  10. package/lib/module/enums/effectDefaults.js.map +1 -0
  11. package/lib/module/enums/effectPresets.js +67 -10
  12. package/lib/module/enums/effectPresets.js.map +1 -1
  13. package/lib/module/shaders/bindGroupLayouts.js +50 -27
  14. package/lib/module/shaders/bindGroupLayouts.js.map +1 -1
  15. package/lib/module/shaders/bindGroupUtils.js +30 -44
  16. package/lib/module/shaders/bindGroupUtils.js.map +1 -1
  17. package/lib/module/shaders/colorConversions.js +78 -0
  18. package/lib/module/shaders/colorConversions.js.map +1 -0
  19. package/lib/module/shaders/computeShaders/precomputeColorMask.js +34 -0
  20. package/lib/module/shaders/computeShaders/precomputeColorMask.js.map +1 -0
  21. package/lib/module/shaders/fragmentShaders/baseTextureFragment.js +4 -9
  22. package/lib/module/shaders/fragmentShaders/baseTextureFragment.js.map +1 -1
  23. package/lib/module/shaders/fragmentShaders/colorMaskFragment.js +28 -41
  24. package/lib/module/shaders/fragmentShaders/colorMaskFragment.js.map +1 -1
  25. package/lib/module/shaders/fragmentShaders/glareFlareFragment.js +84 -0
  26. package/lib/module/shaders/fragmentShaders/glareFlareFragment.js.map +1 -0
  27. package/lib/module/shaders/fragmentShaders/glareFragment.js +8 -88
  28. package/lib/module/shaders/fragmentShaders/glareFragment.js.map +1 -1
  29. package/lib/module/shaders/fragmentShaders/holoFragment.js +120 -11
  30. package/lib/module/shaders/fragmentShaders/holoFragment.js.map +1 -1
  31. package/lib/module/shaders/fragmentShaders/maskFragment.js +5 -4
  32. package/lib/module/shaders/fragmentShaders/maskFragment.js.map +1 -1
  33. package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js +7 -7
  34. package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js.map +1 -1
  35. package/lib/module/shaders/pipelineSetups.js +5 -62
  36. package/lib/module/shaders/pipelineSetups.js.map +1 -1
  37. package/lib/module/shaders/resourceManagement/bufferManager.js.map +1 -1
  38. package/lib/module/shaders/resourceManagement/buffersMap.js +41 -0
  39. package/lib/module/shaders/resourceManagement/buffersMap.js.map +1 -0
  40. package/lib/module/shaders/resourceManagement/pipelineMap.js +115 -0
  41. package/lib/module/shaders/resourceManagement/pipelineMap.js.map +1 -0
  42. package/lib/module/shaders/resourceManagement/textures.js +2 -2
  43. package/lib/module/shaders/resourceManagement/textures.js.map +1 -1
  44. package/lib/module/shaders/tgpuUtils.js +41 -0
  45. package/lib/module/shaders/tgpuUtils.js.map +1 -1
  46. package/lib/module/shaders/utils.js +21 -2
  47. package/lib/module/shaders/utils.js.map +1 -1
  48. package/lib/module/shaders/vertexShaders/mainRotationEffectVertex.js +4 -4
  49. package/lib/module/shaders/vertexShaders/mainRotationEffectVertex.js.map +1 -1
  50. package/lib/module/types/typeUtils.js +29 -159
  51. package/lib/module/types/typeUtils.js.map +1 -1
  52. package/lib/module/types/types.js +8 -1
  53. package/lib/module/types/types.js.map +1 -1
  54. package/lib/module/utils/size.js +4 -4
  55. package/lib/module/utils/vector.js +38 -38
  56. package/lib/typescript/src/components/Content.d.ts +6 -6
  57. package/lib/typescript/src/components/Content.d.ts.map +1 -1
  58. package/lib/typescript/src/components/Shine.d.ts.map +1 -1
  59. package/lib/typescript/src/components/ShineGroup.d.ts +1 -1
  60. package/lib/typescript/src/components/ShineGroup.d.ts.map +1 -1
  61. package/lib/typescript/src/enums/colorPresets.d.ts +152 -0
  62. package/lib/typescript/src/enums/colorPresets.d.ts.map +1 -1
  63. package/lib/typescript/src/enums/effectDefaults.d.ts +39 -0
  64. package/lib/typescript/src/enums/effectDefaults.d.ts.map +1 -0
  65. package/lib/typescript/src/enums/effectPresets.d.ts +284 -5
  66. package/lib/typescript/src/enums/effectPresets.d.ts.map +1 -1
  67. package/lib/typescript/src/shaders/bindGroupLayouts.d.ts +82 -41
  68. package/lib/typescript/src/shaders/bindGroupLayouts.d.ts.map +1 -1
  69. package/lib/typescript/src/shaders/bindGroupUtils.d.ts +86 -70
  70. package/lib/typescript/src/shaders/bindGroupUtils.d.ts.map +1 -1
  71. package/lib/typescript/src/shaders/colorConversions.d.ts +4 -0
  72. package/lib/typescript/src/shaders/colorConversions.d.ts.map +1 -0
  73. package/lib/typescript/src/shaders/computeShaders/precomputeColorMask.d.ts +5 -0
  74. package/lib/typescript/src/shaders/computeShaders/precomputeColorMask.d.ts.map +1 -0
  75. package/lib/typescript/src/shaders/fragmentShaders/baseTextureFragment.d.ts.map +1 -1
  76. package/lib/typescript/src/shaders/fragmentShaders/colorMaskFragment.d.ts.map +1 -1
  77. package/lib/typescript/src/shaders/fragmentShaders/glareFlareFragment.d.ts +5 -0
  78. package/lib/typescript/src/shaders/fragmentShaders/glareFlareFragment.d.ts.map +1 -0
  79. package/lib/typescript/src/shaders/fragmentShaders/glareFragment.d.ts +0 -3
  80. package/lib/typescript/src/shaders/fragmentShaders/glareFragment.d.ts.map +1 -1
  81. package/lib/typescript/src/shaders/fragmentShaders/holoFragment.d.ts +7 -0
  82. package/lib/typescript/src/shaders/fragmentShaders/holoFragment.d.ts.map +1 -1
  83. package/lib/typescript/src/shaders/fragmentShaders/maskFragment.d.ts.map +1 -1
  84. package/lib/typescript/src/shaders/fragmentShaders/reverseHoloFragment.d.ts.map +1 -1
  85. package/lib/typescript/src/shaders/pipelineSetups.d.ts +3 -10
  86. package/lib/typescript/src/shaders/pipelineSetups.d.ts.map +1 -1
  87. package/lib/typescript/src/shaders/resourceManagement/bufferManager.d.ts +5 -3
  88. package/lib/typescript/src/shaders/resourceManagement/bufferManager.d.ts.map +1 -1
  89. package/lib/typescript/src/shaders/resourceManagement/buffersMap.d.ts +10 -0
  90. package/lib/typescript/src/shaders/resourceManagement/buffersMap.d.ts.map +1 -0
  91. package/lib/typescript/src/shaders/resourceManagement/pipelineMap.d.ts +24 -0
  92. package/lib/typescript/src/shaders/resourceManagement/pipelineMap.d.ts.map +1 -0
  93. package/lib/typescript/src/shaders/resourceManagement/textures.d.ts +0 -1
  94. package/lib/typescript/src/shaders/resourceManagement/textures.d.ts.map +1 -1
  95. package/lib/typescript/src/shaders/tgpuUtils.d.ts +3 -0
  96. package/lib/typescript/src/shaders/tgpuUtils.d.ts.map +1 -1
  97. package/lib/typescript/src/shaders/utils.d.ts +1 -0
  98. package/lib/typescript/src/shaders/utils.d.ts.map +1 -1
  99. package/lib/typescript/src/types/typeUtils.d.ts +16 -51
  100. package/lib/typescript/src/types/typeUtils.d.ts.map +1 -1
  101. package/lib/typescript/src/types/types.d.ts +59 -54
  102. package/lib/typescript/src/types/types.d.ts.map +1 -1
  103. package/package.json +1 -1
  104. package/src/components/Content.tsx +130 -269
  105. package/src/components/Shine.tsx +28 -3
  106. package/src/components/ShineGroup.tsx +0 -4
  107. package/src/enums/colorPresets.ts +59 -1
  108. package/src/enums/effectDefaults.ts +57 -0
  109. package/src/enums/effectPresets.ts +142 -9
  110. package/src/shaders/bindGroupLayouts.ts +64 -28
  111. package/src/shaders/bindGroupUtils.ts +66 -69
  112. package/src/shaders/colorConversions.ts +88 -0
  113. package/src/shaders/computeShaders/precomputeColorMask.ts +29 -0
  114. package/src/shaders/fragmentShaders/baseTextureFragment.ts +2 -10
  115. package/src/shaders/fragmentShaders/colorMaskFragment.ts +34 -55
  116. package/src/shaders/fragmentShaders/glareFlareFragment.ts +79 -0
  117. package/src/shaders/fragmentShaders/glareFragment.ts +9 -84
  118. package/src/shaders/fragmentShaders/holoFragment.ts +139 -11
  119. package/src/shaders/fragmentShaders/maskFragment.ts +3 -9
  120. package/src/shaders/fragmentShaders/reverseHoloFragment.ts +4 -9
  121. package/src/shaders/pipelineSetups.ts +16 -125
  122. package/src/shaders/resourceManagement/bufferManager.ts +8 -3
  123. package/src/shaders/resourceManagement/buffersMap.ts +80 -0
  124. package/src/shaders/resourceManagement/pipelineMap.ts +169 -0
  125. package/src/shaders/resourceManagement/textures.ts +2 -2
  126. package/src/shaders/tgpuUtils.ts +29 -0
  127. package/src/shaders/utils.ts +29 -0
  128. package/src/shaders/vertexShaders/mainRotationEffectVertex.ts +2 -2
  129. package/src/types/typeUtils.ts +53 -164
  130. package/src/types/types.ts +111 -60
@@ -1,9 +1,13 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { useDevice } from 'react-native-wgpu';
3
- import type { TgpuTexture } from 'typegpu';
3
+ import type { StorageFlag, TgpuTexture } from 'typegpu';
4
4
  import { getOrInitRoot } from '../roots';
5
- import { loadBitmap } from '../shaders/resourceManagement/textures';
5
+ import {
6
+ createTexture,
7
+ loadBitmap,
8
+ } from '../shaders/resourceManagement/textures';
6
9
  import Content, { type SharedProps } from './Content';
10
+ import getBitmapFromURI from '../shaders/resourceManagement/bitmaps';
7
11
 
8
12
  export interface ShineProps extends SharedProps {
9
13
  imageURI: string;
@@ -15,15 +19,35 @@ export function Shine({ imageURI, maskURI, ...props }: ShineProps) {
15
19
  const root = device && getOrInitRoot(device);
16
20
  const [imageTexture, setImageTexture] = useState<TgpuTexture>();
17
21
  const [maskTexture, setMaskTexture] = useState<TgpuTexture>();
22
+ const [colorMaskStorageTexture, setColorMaskStorageTexture] = useState<
23
+ TgpuTexture<any> & StorageFlag
24
+ >();
25
+ //TODO: complete the work with the compute shader, try out the shader
18
26
 
19
27
  useEffect(() => {
20
- if (root) loadBitmap(root, imageURI, setImageTexture);
28
+ if (root) {
29
+ loadBitmap(root, imageURI, setImageTexture);
30
+ const makeStorage = async () => {
31
+ const bitmap = await getBitmapFromURI(imageURI);
32
+ const texture = (await createTexture(root, bitmap)).$usage(
33
+ 'storage',
34
+ 'sampled'
35
+ );
36
+ setColorMaskStorageTexture(texture);
37
+ };
38
+ makeStorage();
39
+ }
21
40
  }, [root, imageURI]);
22
41
 
23
42
  useEffect(() => {
24
43
  if (root && maskURI) loadBitmap(root, maskURI, setMaskTexture);
25
44
  }, [root, imageURI, maskURI]);
26
45
 
46
+ // useEffect(() => {
47
+ // //TODO: write the logic for allocating the storage texture for the precomputed colorMask
48
+ // if (root)
49
+ // }, [root, imageURI]);
50
+
27
51
  return (
28
52
  root &&
29
53
  imageTexture && (
@@ -32,6 +56,7 @@ export function Shine({ imageURI, maskURI, ...props }: ShineProps) {
32
56
  root={root}
33
57
  imageTexture={imageTexture}
34
58
  maskTexture={maskTexture}
59
+ colorMaskStorageTexture={colorMaskStorageTexture}
35
60
  />
36
61
  )
37
62
  );
@@ -15,12 +15,10 @@ type ShineGroupProps = PropsWithChildren<Partial<ShineProps>>;
15
15
 
16
16
  export function ShineGroup({
17
17
  children,
18
- glareOptions,
19
18
  highlightColors,
20
19
  maskURI,
21
20
  lightPosition: touchPosition,
22
21
  effects,
23
- enableGlare = true,
24
22
  isHighlightInclusive = true,
25
23
  translateViewIn3d = false,
26
24
  containerStyle,
@@ -79,13 +77,11 @@ export function ShineGroup({
79
77
  <Shine
80
78
  {...sizeFromV2d(size)}
81
79
  imageURI={capturedURI}
82
- glareOptions={glareOptions}
83
80
  highlightColors={highlightColors}
84
81
  maskURI={maskURI}
85
82
  lightPosition={touchPosition}
86
83
  effects={effects}
87
84
  translateViewIn3d={translateViewIn3d}
88
- enableGlare={enableGlare}
89
85
  containerStyle={containerStyle}
90
86
  isHighlightInclusive={isHighlightInclusive}
91
87
  style={style}
@@ -1,4 +1,4 @@
1
- import type { vec3 } from '../types/types';
1
+ import type { ColorMask, vec3 } from '../types/types';
2
2
 
3
3
  export const ColorPresets = {
4
4
  // --- Primary & Secondary ---
@@ -39,3 +39,61 @@ export const ColorPresets = {
39
39
  BEIGE: [245, 245, 220], // #F5F5DC
40
40
  POTATO: [222, 184, 135], // #DEB887
41
41
  } as const satisfies Record<string, vec3>;
42
+
43
+ export const HSVColorsPreset = {
44
+ RED: { hueMin: 330, hueMax: 15 }, // #FF0022
45
+ ORANGE: { hueMin: 15, hueMax: 45 }, // #FF8000
46
+ YELLOW: { hueMin: 45, hueMax: 75 }, // #FFFF00
47
+ GREEN: { hueMin: 75, hueMax: 165 }, // #00FF00
48
+ BLUE: { hueMin: 165, hueMax: 255 }, // #0080FF
49
+ VIOLET: { hueMin: 255, hueMax: 285 }, // #8000FF
50
+ MAGENTA: { hueMin: 285, hueMax: 330 }, // #FF00D5
51
+
52
+ TRUE_RED: { hueMin: 345, hueMax: 15 }, // #FF0000
53
+ CRIMSON: { hueMin: 330, hueMax: 350 }, // #FF0055
54
+ ROSE: { hueMin: 315, hueMax: 335 }, // #FF0095
55
+ PINK: { hueMin: 300, hueMax: 330 }, // #FF00BF
56
+
57
+ CORAL: { hueMin: 10, hueMax: 30 }, // #FF5500
58
+ TRUE_ORANGE: { hueMin: 20, hueMax: 45 }, // #FF8C00
59
+ AMBER: { hueMin: 35, hueMax: 50 }, // #FFB300
60
+ TRUE_YELLOW: { hueMin: 45, hueMax: 65 }, // #FFD500
61
+ GOLD: { hueMin: 40, hueMax: 55 }, // #FFCC00
62
+
63
+ LIME: { hueMin: 65, hueMax: 90 }, // #BFFF00
64
+ CHARTREUSE: { hueMin: 70, hueMax: 100 }, // #95FF00
65
+ TRUE_GREEN: { hueMin: 90, hueMax: 140 }, // #15FF00
66
+ EMERALD: { hueMin: 130, hueMax: 160 }, // #00FF6A
67
+ MINT: { hueMin: 140, hueMax: 170 }, // #00FF95
68
+
69
+ TEAL: { hueMin: 160, hueMax: 180 }, // #00FFD5
70
+ CYAN: { hueMin: 170, hueMax: 195 }, // #00F2FF
71
+ TURQUOISE: { hueMin: 165, hueMax: 190 }, // #00FFF2
72
+ AZURE: { hueMin: 190, hueMax: 215 }, // #009FFF
73
+ TRUE_BLUE: { hueMin: 210, hueMax: 240 }, // #0040FF
74
+ ROYAL_BLUE: { hueMin: 225, hueMax: 250 }, // #0011FF
75
+ INDIGO: { hueMin: 240, hueMax: 260 }, // #2B00FF
76
+
77
+ TRUE_VIOLET: { hueMin: 250, hueMax: 280 }, // #6A00FF
78
+ PURPLE: { hueMin: 260, hueMax: 290 }, // #9500FF
79
+ TRUE_MAGENTA: { hueMin: 285, hueMax: 315 }, // #FF00FF
80
+ FUCHSIA: { hueMin: 295, hueMax: 325 }, // #ff00d5ff
81
+
82
+ GRAY: { hueMin: 0, hueMax: 360, saturationMax: 0.2, saturationMin: 0 }, // #738c8cff
83
+ WHITE: {
84
+ hueMin: 0,
85
+ hueMax: 360,
86
+ saturationMax: 1,
87
+ saturationMin: 0,
88
+ lightnessMax: 1,
89
+ lightnessMin: 0.9,
90
+ }, // #d9f2f2ff
91
+ BLACK: {
92
+ hueMin: 0,
93
+ hueMax: 360,
94
+ saturationMax: 1,
95
+ saturationMin: 0,
96
+ lightnessMax: 0.2,
97
+ lightnessMin: 0,
98
+ }, // #0d2626ff
99
+ } as const satisfies Record<string, ColorMask>;
@@ -0,0 +1,57 @@
1
+ import type { ColorMaskPreTypedSchema } from '../types/types';
2
+
3
+ export const GLARE_DEFAULTS = {
4
+ glowPower: 0.5,
5
+ glareIntensity: 0.4,
6
+ lightIntensity: 1.1,
7
+ glareColor: {
8
+ hueBlendPower: 1.0,
9
+ hueShiftAngleMin: -30,
10
+ hueShiftAngleMax: 30,
11
+ },
12
+ } as const;
13
+
14
+ export const REVERSE_HOLO_DEFAULTS = {
15
+ redChannel: 1.0,
16
+ greenChannel: 0.0,
17
+ blueChannel: 0.0,
18
+ hue: 0.0,
19
+ saturation: 0.0,
20
+ value: 0.0,
21
+ } as const;
22
+
23
+ export const HOLO_DEFAULTS = {
24
+ directionDegree: 45,
25
+ shift: 0.1,
26
+ rotationShiftPower: 0.6,
27
+ holoSize: 0.12,
28
+ holoMultiplier: 2.5,
29
+ holoEaseSize: 0.2,
30
+ holoVisibility: 0.88,
31
+ holoSaturation: 0.5,
32
+ } as const;
33
+
34
+ export const GLARE_FLARE_DEFAULTS = {
35
+ flareIntensity: 0.7, // Overall intensity of the flare
36
+ spotIntensity: 0.4, // Intensity of the central spot
37
+ ringIntensity: 0.1, // Intensity of the rings
38
+ rayIntensity: 0.8, // Intensity of the rays
39
+ falloff: 8.0, // Falloff factor for rings and spots
40
+ rayCount: 4.0, // Number of rays
41
+ };
42
+
43
+ export const COLOR_MASK_DEFAULT_OPTIONS: ColorMaskPreTypedSchema = {
44
+ rgbToleranceRange: {
45
+ upper: [20, 20, 20],
46
+ lower: [20, 20, 20],
47
+ },
48
+ baseColor: [0, 0, 0],
49
+ hueMin: 0,
50
+ hueMax: 360,
51
+ saturationMin: 0.2,
52
+ saturationMax: 1,
53
+ lightnessMin: 0.3,
54
+ lightnessMax: 0.9,
55
+ debugMode: false,
56
+ useHSV: 0,
57
+ } as const;
@@ -1,11 +1,144 @@
1
- import type { Effect } from '../types/types';
1
+ import {
2
+ precomputeColorMaskBindGroupLayout,
3
+ type ColorMaskArraySchema,
4
+ } from './../shaders/bindGroupLayouts';
5
+ import {
6
+ glareFlareSchema,
7
+ glareSchema,
8
+ holoSchema,
9
+ reverseHoloDetectionChannelFlagsSchema,
10
+ } from '../shaders/bindGroupLayouts';
11
+ import {
12
+ createGlareBindGroup,
13
+ createGlareFlareBindGroup,
14
+ createHoloBindGroup,
15
+ createReverseHoloDetectionChannelFlagsBindGroup,
16
+ } from '../shaders/bindGroupUtils';
17
+ import {
18
+ createEffect,
19
+ type DeepPartial,
20
+ type ExtractEffectOptions,
21
+ type UnwrapLayout,
22
+ } from '../types/types';
23
+ import { glareFragment } from '../shaders/fragmentShaders/glareFragment';
24
+ import { reverseHoloFragment } from '../shaders/fragmentShaders/reverseHoloFragment';
25
+ import {
26
+ doubleHoloFragment,
27
+ holoFragment,
28
+ } from '../shaders/fragmentShaders/holoFragment';
29
+ import { glareFlareFragment } from '../shaders/fragmentShaders/glareFlareFragment';
30
+ import type {
31
+ StorageFlag,
32
+ TgpuBindGroup,
33
+ TgpuBuffer,
34
+ TgpuComputeFn,
35
+ TgpuRoot,
36
+ TgpuTexture,
37
+ UniformFlag,
38
+ ValidateUniformSchema,
39
+ } from 'typegpu';
40
+ import {
41
+ GLARE_DEFAULTS,
42
+ GLARE_FLARE_DEFAULTS,
43
+ HOLO_DEFAULTS,
44
+ REVERSE_HOLO_DEFAULTS,
45
+ } from './effectDefaults';
46
+ //TODO: move schema to separate object that would match them with corresponding bindGroups, then they would be defined in the effect
47
+
48
+ export const blend: GPUBlendState = {
49
+ color: {
50
+ srcFactor: 'one-minus-src-alpha',
51
+ dstFactor: 'src-alpha',
52
+ operation: 'add',
53
+ } satisfies GPUBlendComponent,
54
+ alpha: {
55
+ srcFactor: 'one-minus-src-alpha',
56
+ dstFactor: 'dst-alpha',
57
+ operation: 'add',
58
+ } satisfies GPUBlendComponent,
59
+ };
60
+
61
+ const GLARE = createEffect({
62
+ buffers: [
63
+ {
64
+ schema: glareSchema,
65
+ defaultOptions: GLARE_DEFAULTS,
66
+ },
67
+ ],
68
+ bindGroupCreator: createGlareBindGroup,
69
+ fragment: glareFragment,
70
+ });
71
+
72
+ const REVERSE_HOLO = createEffect({
73
+ buffers: [
74
+ { schema: glareSchema, defaultOptions: GLARE_DEFAULTS },
75
+ {
76
+ schema: reverseHoloDetectionChannelFlagsSchema,
77
+ defaultOptions: REVERSE_HOLO_DEFAULTS,
78
+ },
79
+ ],
80
+ fragment: reverseHoloFragment,
81
+ bindGroupCreator: createReverseHoloDetectionChannelFlagsBindGroup,
82
+ blend,
83
+ });
84
+
85
+ const HOLO = createEffect({
86
+ fragment: holoFragment,
87
+ buffers: [
88
+ {
89
+ schema: holoSchema,
90
+ defaultOptions: HOLO_DEFAULTS,
91
+ },
92
+ ],
93
+ bindGroupCreator: createHoloBindGroup,
94
+ blend,
95
+ });
96
+
97
+ const DOUBLE_HOLO = { ...HOLO, fragment: doubleHoloFragment };
98
+
99
+ const GLARE_FLARE = createEffect({
100
+ fragment: glareFlareFragment,
101
+ buffers: [
102
+ {
103
+ schema: glareFlareSchema,
104
+ defaultOptions: GLARE_FLARE_DEFAULTS,
105
+ },
106
+ ],
107
+ bindGroupCreator: createGlareFlareBindGroup,
108
+ });
2
109
 
3
110
  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>;
111
+ glare: GLARE,
112
+ reverseHolo: REVERSE_HOLO,
113
+ holo: HOLO,
114
+ doubleHolo: DOUBLE_HOLO,
115
+ glareFlare: GLARE_FLARE,
116
+ } as const; //todo: add forced typings
117
+
118
+ export type Effect = {
119
+ [K in keyof typeof Effects]: {
120
+ name: K;
121
+ options?: DeepPartial<ExtractEffectOptions<(typeof Effects)[K]>>;
122
+ };
123
+ }[keyof typeof Effects];
124
+ export type ComputePipelineInput = {
125
+ compute: TgpuComputeFn;
126
+ buffers: {
127
+ schema: ValidateUniformSchema<any>;
128
+ defaultOptions: any;
129
+ }[];
130
+ storageTexture: TgpuTexture<{
131
+ format: 'rgba8unorm';
132
+ size: readonly number[];
133
+ }> &
134
+ StorageFlag;
135
+ bindGroupCreator: (
136
+ root: TgpuRoot,
137
+ storageTexture: TgpuTexture<{
138
+ format: 'rgba8unorm';
139
+ size: readonly number[];
140
+ }> &
141
+ StorageFlag,
142
+ colorMaskBuffer: TgpuBuffer<ColorMaskArraySchema> & UniformFlag
143
+ ) => TgpuBindGroup<UnwrapLayout<typeof precomputeColorMaskBindGroupLayout>>;
144
+ };
@@ -2,9 +2,12 @@ import tgpu, { type ValidateBufferSchema } from 'typegpu';
2
2
  import * as d from 'typegpu/data';
3
3
  import type { BufferUsageType } from './resourceManagement/bufferManager';
4
4
 
5
- export const textureBindGroupLayout = tgpu.bindGroupLayout({
5
+ export const rotationSchema = d.vec3f;
6
+
7
+ export const sharedBindGroupLayout = tgpu.bindGroupLayout({
6
8
  texture: { texture: d.texture2d(d.f32) },
7
9
  sampler: { sampler: 'filtering' },
10
+ rot: { uniform: rotationSchema },
8
11
  });
9
12
 
10
13
  export const maskTextureBindGroupLayout = tgpu.bindGroupLayout({
@@ -12,10 +15,6 @@ export const maskTextureBindGroupLayout = tgpu.bindGroupLayout({
12
15
  sampler: { sampler: 'filtering' },
13
16
  });
14
17
 
15
- export const rotationBindGroupLayout = tgpu.bindGroupLayout({
16
- vec: { uniform: d.vec3f },
17
- });
18
-
19
18
  export const glareSchema = d.struct({
20
19
  glareColor: d.struct({
21
20
  hueShiftAngleMax: d.f32,
@@ -40,21 +39,17 @@ export const colorMaskSchema = d.struct({
40
39
  upper: d.vec3f,
41
40
  lower: d.vec3f,
42
41
  }),
43
- hueToleranceRange: d.struct({
44
- upper: d.f32,
45
- lower: d.f32,
46
- }),
42
+ hueStart: d.f32,
43
+ hueRange: d.f32,
47
44
  useHSV: d.align(16, d.u32),
48
- brightnessTolerance: d.f32,
49
- saturationTolerance: d.f32,
50
- lowSaturationThreshold: d.f32,
51
- lowBrightnessThreshold: d.f32,
45
+ minLimits: d.vec2f,
46
+ maxLimits: d.vec2f,
52
47
  debugMode: d.u32,
53
48
  });
54
49
 
55
- export type ColorMaskSchema = typeof colorMaskSchema;
50
+ export type ColorMaskSchema = d.Infer<typeof colorMaskSchema>;
56
51
 
57
- export const COLOR_MASK_MAX_COUNT = 16;
52
+ export const COLOR_MASK_MAX_COUNT = 8;
58
53
 
59
54
  export const colorMaskArraySchema = d.struct({
60
55
  masks: d.arrayOf(colorMaskSchema, COLOR_MASK_MAX_COUNT),
@@ -86,9 +81,61 @@ export const reverseHoloDetectionChannelFlagsBindGroupLayout =
86
81
  glareOptions: { uniform: glareSchema },
87
82
  });
88
83
 
84
+ export const holoSchema = d.struct({
85
+ directionDegree: d.align(16, d.f32),
86
+ shift: d.f32,
87
+ rotationShiftPower: d.f32,
88
+ holoSize: d.f32,
89
+ holoMultiplier: d.f32,
90
+ holoEaseSize: d.f32,
91
+ holoVisibility: d.f32,
92
+ holoSaturation: d.f32,
93
+ });
94
+
95
+ export type HoloSchema = typeof holoSchema;
96
+
97
+ export const holoBindGroupLayout = tgpu.bindGroupLayout({
98
+ holoOptions: { uniform: holoSchema },
99
+ });
100
+
101
+ export const glareFlareSchema = d.struct({
102
+ flareIntensity: d.f32,
103
+ spotIntensity: d.f32,
104
+ ringIntensity: d.f32,
105
+ rayIntensity: d.f32,
106
+ falloff: d.f32,
107
+ rayCount: d.f32,
108
+ });
109
+
110
+ export type glareFlareSchema = typeof glareFlareSchema;
111
+
112
+ export const glareFlareBindGroupLayout = tgpu.bindGroupLayout({
113
+ glareFlare: { uniform: glareFlareSchema },
114
+ });
115
+
116
+ export const precomputeTextureSchema = d.textureStorage2d(
117
+ 'rgba8unorm',
118
+ 'read-write'
119
+ );
120
+
121
+ export type PrecomputeTextureSchema = typeof precomputeTextureSchema;
122
+
123
+ export const precomputeColorMaskBindGroupLayout = tgpu.bindGroupLayout({
124
+ colorMaskStorage: {
125
+ storageTexture: precomputeTextureSchema,
126
+ },
127
+ });
128
+
129
+ export const precomputeColorMaskOutputBindGroupLayout = tgpu.bindGroupLayout({
130
+ colorMaskOutput: {
131
+ texture: d.texture2d(d.f32),
132
+ },
133
+ });
134
+
89
135
  export type BufferSchemas =
136
+ | d.Vec3f
90
137
  | ReverseHoloDetectionChannelFlagsSchema
91
- | ColorMaskSchema
138
+ | ColorMaskArraySchema
92
139
  | GlareSchema;
93
140
 
94
141
  export const bufferData = {
@@ -110,18 +157,7 @@ export const bufferData = {
110
157
  },
111
158
  } as const satisfies Record<
112
159
  string,
113
- { schema: ValidateBufferSchema<any>; usage: BufferUsageType }
160
+ { schema: ValidateBufferSchema<BufferSchemas>; usage: BufferUsageType }
114
161
  >;
115
162
 
116
163
  export type BufferData = typeof bufferData;
117
-
118
- // export const holoSchema = d.struct({
119
- // intensity: d.f32,
120
- // waveCallback: WaveCallback, //TgpuFn<(uv: d.Vec2f) => d.Vec2f>,
121
- // });
122
-
123
- // export type holoSchema = typeof holoSchema;
124
-
125
- // export const holoBindGroupLayout = tgpu.bindGroupLayout({
126
- // holoOptions: { uniform: holoSchema },
127
- // });
@@ -1,61 +1,53 @@
1
- import { type TgpuBuffer, type TgpuRoot, type UniformFlag } from 'typegpu';
2
- import * as d from 'typegpu/data';
3
1
  import {
4
- glareBindGroupLayout,
5
- glareSchema,
2
+ type StorageFlag,
3
+ type TgpuBuffer,
4
+ type TgpuRoot,
5
+ type TgpuTexture,
6
+ type UniformFlag,
7
+ } from 'typegpu';
8
+ import {
6
9
  colorMaskBindGroupLayout,
7
- rotationBindGroupLayout,
8
10
  type GlareSchema,
9
11
  type ReverseHoloDetectionChannelFlagsSchema,
10
12
  reverseHoloDetectionChannelFlagsBindGroupLayout,
11
13
  type ColorMaskArraySchema,
14
+ glareBindGroupLayout,
15
+ holoBindGroupLayout,
16
+ type HoloSchema,
17
+ glareFlareSchema,
18
+ glareFlareBindGroupLayout,
19
+ precomputeColorMaskBindGroupLayout,
12
20
  } from './bindGroupLayouts';
13
- import type { GlareOptions } from '../types/types';
14
- import { createGlareOptions, glareOptionsToTyped } from '../types/typeUtils';
15
- import { componentsFromV3d, zeroV3d } from '../utils/vector';
16
-
17
- export const createRotationBuffer = (root: TgpuRoot, initValues = zeroV3d) =>
18
- root
19
- .createBuffer(d.vec3f, d.vec3f(...componentsFromV3d(initValues)))
20
- .$usage('uniform');
21
-
22
- export const createRotationValuesBindGroup = (
23
- root: TgpuRoot,
24
- buffer: TgpuBuffer<d.Vec3f>
25
- ) =>
26
- root.createBindGroup(rotationBindGroupLayout, {
27
- vec: root.unwrap(buffer),
28
- });
29
-
30
- export const createGlareOptionsBuffer = (
31
- root: TgpuRoot,
32
- initValues?: Partial<GlareOptions>
33
- ) =>
34
- root
35
- .createBuffer(
36
- glareSchema,
37
- glareOptionsToTyped(createGlareOptions({ ...initValues }))
38
- )
39
- .$usage('uniform');
21
+ import type {
22
+ BindGroupCreatorArgument,
23
+ TgpuUniformBuffer,
24
+ } from '../types/types';
40
25
 
41
26
  export const createGlareBindGroup = (
42
- root: TgpuRoot,
43
- buffer: TgpuBuffer<GlareSchema> & UniformFlag
44
- ) =>
27
+ { root }: BindGroupCreatorArgument,
28
+ [buffer]: readonly [buffer: TgpuUniformBuffer<GlareSchema>]
29
+ ) => [
45
30
  root.createBindGroup(glareBindGroupLayout, {
46
31
  glareOptions: buffer,
47
- });
32
+ }),
33
+ ];
48
34
 
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');
35
+ export const createReverseHoloDetectionChannelFlagsBindGroup = (
36
+ { root, maskBindGroup }: BindGroupCreatorArgument,
37
+ [glareOptions, channelFlags]: readonly [
38
+ g: TgpuUniformBuffer<GlareSchema>,
39
+ f: TgpuUniformBuffer<ReverseHoloDetectionChannelFlagsSchema>,
40
+ ]
41
+ ) => {
42
+ const reverseHoloBindGroup = root.createBindGroup(
43
+ reverseHoloDetectionChannelFlagsBindGroupLayout,
44
+ {
45
+ channelFlags,
46
+ glareOptions,
47
+ }
48
+ );
49
+ return [reverseHoloBindGroup, maskBindGroup];
50
+ };
59
51
 
60
52
  export const createColorMaskBindGroup = (
61
53
  root: TgpuRoot,
@@ -65,28 +57,33 @@ export const createColorMaskBindGroup = (
65
57
  colorMasks: buffer,
66
58
  });
67
59
 
68
- export const createReverseHoloDetectionChannelFlagsBindGroup = (
69
- root: TgpuRoot,
70
- detectionChannelBuffer: TgpuBuffer<ReverseHoloDetectionChannelFlagsSchema> &
71
- UniformFlag,
72
- glareOptionsBuffer: TgpuBuffer<GlareSchema> & UniformFlag
73
- ) =>
74
- root.createBindGroup(reverseHoloDetectionChannelFlagsBindGroupLayout, {
75
- channelFlags: detectionChannelBuffer,
76
- glareOptions: glareOptionsBuffer,
77
- });
60
+ export const createHoloBindGroup = (
61
+ { root }: BindGroupCreatorArgument,
62
+ [buffer]: readonly [buffer: TgpuUniformBuffer<HoloSchema>]
63
+ ) => [
64
+ root.createBindGroup(holoBindGroupLayout, {
65
+ holoOptions: buffer,
66
+ }),
67
+ ];
78
68
 
79
- // export const crateHoloBuffer = (
80
- // root: TgpuRoot,
81
- // initValues: Partial<HoloOptions>
82
- // ) => {
83
- // const holoOptions: HoloOptions = createHoloOptions({ ...initValues });
84
- // const holoOptionsTyped = {
85
- // intensity: d.f32(holoOptions.intensity),
86
- // waveCallback: holoOptions.waveCallback,
87
- // };
69
+ export const createGlareFlareBindGroup = (
70
+ { root }: BindGroupCreatorArgument,
71
+ [buffer]: readonly [buffer: TgpuUniformBuffer<glareFlareSchema>]
72
+ ) => [
73
+ root.createBindGroup(glareFlareBindGroupLayout, {
74
+ glareFlare: buffer,
75
+ }),
76
+ ];
88
77
 
89
- // const holoBuffer = root
90
- // .createBuffer(holoSchema, holoOptionsTyped)
91
- // .$usage('uniform');
92
- // };
78
+ export const createPrecomputeColorMaskBindGroup = (
79
+ root: TgpuRoot,
80
+ storageTexture: TgpuTexture<{
81
+ format: 'rgba8unorm';
82
+ size: readonly number[];
83
+ }> &
84
+ StorageFlag
85
+ ) => {
86
+ return root.createBindGroup(precomputeColorMaskBindGroupLayout, {
87
+ colorMaskStorage: storageTexture,
88
+ });
89
+ };