react-native-shine 0.5.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 (90) hide show
  1. package/lib/module/components/Content.js +56 -36
  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/config/debugMode.js +1 -0
  6. package/lib/module/config/debugMode.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/enums/waveCallback.js +2 -1
  12. package/lib/module/enums/waveCallback.js.map +1 -1
  13. package/lib/module/index.js +2 -0
  14. package/lib/module/index.js.map +1 -1
  15. package/lib/module/shaders/bindGroupLayouts.js +21 -16
  16. package/lib/module/shaders/bindGroupLayouts.js.map +1 -1
  17. package/lib/module/shaders/bindGroupUtils.js +16 -7
  18. package/lib/module/shaders/bindGroupUtils.js.map +1 -1
  19. package/lib/module/shaders/fragmentShaders/baseTextureFragment.js +28 -0
  20. package/lib/module/shaders/fragmentShaders/baseTextureFragment.js.map +1 -0
  21. package/lib/module/shaders/fragmentShaders/colorMaskFragment.js +56 -39
  22. package/lib/module/shaders/fragmentShaders/colorMaskFragment.js.map +1 -1
  23. package/lib/module/shaders/fragmentShaders/glareFragment.js +13 -11
  24. package/lib/module/shaders/fragmentShaders/glareFragment.js.map +1 -1
  25. package/lib/module/shaders/fragmentShaders/holoFragment.js +13 -4
  26. package/lib/module/shaders/fragmentShaders/holoFragment.js.map +1 -1
  27. package/lib/module/shaders/fragmentShaders/maskFragment.js +1 -0
  28. package/lib/module/shaders/fragmentShaders/maskFragment.js.map +1 -1
  29. package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js +13 -8
  30. package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js.map +1 -1
  31. package/lib/module/shaders/resourceManagement/textures.js.map +1 -1
  32. package/lib/module/shaders/tgpuUtils.js +49 -29
  33. package/lib/module/shaders/tgpuUtils.js.map +1 -1
  34. package/lib/module/shaders/vertexShaders/mainRotationEffectVertex.js +1 -0
  35. package/lib/module/shaders/vertexShaders/mainRotationEffectVertex.js.map +1 -1
  36. package/lib/module/shaders/vertexShaders/mainVertex.js +1 -0
  37. package/lib/module/shaders/vertexShaders/mainVertex.js.map +1 -1
  38. package/lib/module/types/size.js +2 -0
  39. package/lib/module/types/typeUtils.js +100 -51
  40. package/lib/module/types/typeUtils.js.map +1 -1
  41. package/lib/module/types/vector.js +2 -0
  42. package/lib/module/utils/vector.js +6 -6
  43. package/lib/typescript/src/components/Content.d.ts +11 -8
  44. package/lib/typescript/src/components/Content.d.ts.map +1 -1
  45. package/lib/typescript/src/components/ShineGroup.d.ts +1 -1
  46. package/lib/typescript/src/components/ShineGroup.d.ts.map +1 -1
  47. package/lib/typescript/src/config/debugMode.d.ts +1 -0
  48. package/lib/typescript/src/config/debugMode.d.ts.map +1 -1
  49. package/lib/typescript/src/enums/colorHighlightPresets.d.ts +12 -0
  50. package/lib/typescript/src/enums/colorHighlightPresets.d.ts.map +1 -0
  51. package/lib/typescript/src/enums/effectPresets.d.ts +14 -0
  52. package/lib/typescript/src/enums/effectPresets.d.ts.map +1 -0
  53. package/lib/typescript/src/index.d.ts +2 -0
  54. package/lib/typescript/src/index.d.ts.map +1 -1
  55. package/lib/typescript/src/shaders/bindGroupLayouts.d.ts +90 -51
  56. package/lib/typescript/src/shaders/bindGroupLayouts.d.ts.map +1 -1
  57. package/lib/typescript/src/shaders/bindGroupUtils.d.ts +41 -46
  58. package/lib/typescript/src/shaders/bindGroupUtils.d.ts.map +1 -1
  59. package/lib/typescript/src/shaders/fragmentShaders/baseTextureFragment.d.ts +5 -0
  60. package/lib/typescript/src/shaders/fragmentShaders/baseTextureFragment.d.ts.map +1 -0
  61. package/lib/typescript/src/shaders/fragmentShaders/colorMaskFragment.d.ts.map +1 -1
  62. package/lib/typescript/src/shaders/fragmentShaders/glareFragment.d.ts.map +1 -1
  63. package/lib/typescript/src/shaders/fragmentShaders/holoFragment.d.ts.map +1 -1
  64. package/lib/typescript/src/shaders/fragmentShaders/reverseHoloFragment.d.ts.map +1 -1
  65. package/lib/typescript/src/shaders/resourceManagement/textures.d.ts +3 -3
  66. package/lib/typescript/src/shaders/resourceManagement/textures.d.ts.map +1 -1
  67. package/lib/typescript/src/shaders/tgpuUtils.d.ts.map +1 -1
  68. package/lib/typescript/src/types/typeUtils.d.ts +33 -3
  69. package/lib/typescript/src/types/typeUtils.d.ts.map +1 -1
  70. package/lib/typescript/src/types/types.d.ts +32 -4
  71. package/lib/typescript/src/types/types.d.ts.map +1 -1
  72. package/package.json +5 -4
  73. package/src/components/Content.tsx +92 -47
  74. package/src/components/ShineGroup.tsx +16 -8
  75. package/src/config/debugMode.ts +1 -0
  76. package/src/enums/colorHighlightPresets.ts +33 -0
  77. package/src/enums/effectPresets.ts +11 -0
  78. package/src/enums/waveCallback.ts +1 -1
  79. package/src/index.tsx +2 -0
  80. package/src/shaders/bindGroupLayouts.ts +27 -10
  81. package/src/shaders/bindGroupUtils.ts +19 -26
  82. package/src/shaders/fragmentShaders/baseTextureFragment.ts +18 -0
  83. package/src/shaders/fragmentShaders/colorMaskFragment.ts +70 -42
  84. package/src/shaders/fragmentShaders/glareFragment.ts +10 -8
  85. package/src/shaders/fragmentShaders/holoFragment.ts +9 -3
  86. package/src/shaders/fragmentShaders/reverseHoloFragment.ts +12 -7
  87. package/src/shaders/resourceManagement/textures.ts +3 -3
  88. package/src/shaders/tgpuUtils.ts +41 -46
  89. package/src/types/typeUtils.ts +102 -56
  90. package/src/types/types.ts +37 -4
@@ -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>;
@@ -3,7 +3,7 @@ import * as std from 'typegpu/std';
3
3
  import * as d from 'typegpu/data';
4
4
 
5
5
  const defaultWave = (pos: d.v2f) => {
6
- 'kernel';
6
+ 'use gpu';
7
7
 
8
8
  const x = pos.x;
9
9
  const y = pos.y;
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({
@@ -48,12 +49,23 @@ export const colorMaskSchema = d.struct({
48
49
  saturationTolerance: d.f32,
49
50
  lowSaturationThreshold: d.f32,
50
51
  lowBrightnessThreshold: d.f32,
52
+ debugMode: d.u32,
51
53
  });
52
54
 
53
55
  export type ColorMaskSchema = typeof colorMaskSchema;
54
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
+
55
67
  export const colorMaskBindGroupLayout = tgpu.bindGroupLayout({
56
- mask: { uniform: colorMaskSchema },
68
+ colorMasks: { uniform: colorMaskArraySchema },
57
69
  });
58
70
 
59
71
  export const reverseHoloDetectionChannelFlagsSchema = d.struct({
@@ -74,6 +86,11 @@ export const reverseHoloDetectionChannelFlagsBindGroupLayout =
74
86
  glareOptions: { uniform: glareSchema },
75
87
  });
76
88
 
89
+ export type BufferSchemas =
90
+ | ReverseHoloDetectionChannelFlagsSchema
91
+ | ColorMaskSchema
92
+ | GlareSchema;
93
+
77
94
  export const bufferData = {
78
95
  rotation: {
79
96
  schema: d.vec3f,
@@ -84,7 +101,7 @@ export const bufferData = {
84
101
  usage: 'uniform',
85
102
  },
86
103
  colorMask: {
87
- schema: colorMaskSchema,
104
+ schema: colorMaskArraySchema,
88
105
  usage: 'uniform',
89
106
  },
90
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 = (
@@ -0,0 +1,18 @@
1
+ import tgpu from 'typegpu';
2
+ import * as d from 'typegpu/data';
3
+ import * as std from 'typegpu/std';
4
+ import { textureBindGroupLayout } from '../bindGroupLayouts';
5
+
6
+ export const baseTextureFragment = tgpu['~unstable'].fragmentFn({
7
+ in: { uv: d.vec2f },
8
+ out: d.vec4f,
9
+ })((input) => {
10
+ const texcoord = d.vec2f(input.uv.x, 1.0 - input.uv.y);
11
+ let color = std.textureSample(
12
+ textureBindGroupLayout.$.texture,
13
+ textureBindGroupLayout.$.sampler,
14
+ texcoord
15
+ );
16
+
17
+ return color;
18
+ });
@@ -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,64 +14,91 @@ 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
17
  let color = std.textureSample(
31
18
  textureBindGroupLayout.$.texture,
32
19
  textureBindGroupLayout.$.sampler,
33
20
  texcoord
34
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);
35
31
 
36
- const maskedColorLower = std.sub(maskedColor, rgbToleranceRange.lower);
37
- const maskedColorUpper = std.add(maskedColor, rgbToleranceRange.upper);
38
- const upperCheck = std.all(std.le(color.xyz, maskedColorUpper));
39
- const lowerCheck = std.all(std.ge(color.xyz, maskedColorLower));
40
- const rgbCheck = upperCheck && lowerCheck;
32
+ //TODO: optimize this more
33
+ for (let i = 0; i < 16; i++) {
34
+ if (usedMaskCount <= i) break;
41
35
 
42
- const maskedHSV = rgbToHSV(maskedColor);
43
- 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
44
 
45
- let hueDiff = std.sub(colorHSV.x, maskedHSV.x);
46
- hueDiff = std.select(hueDiff, std.sub(hueDiff, 1.0), hueDiff > d.f32(0.5));
47
- hueDiff = std.select(hueDiff, std.add(hueDiff, 1.0), hueDiff < d.f32(-0.5));
48
- const lowerHueCheck = hueDiff >= -hueLower;
49
- const upperHueCheck = hueDiff <= hueUpper;
50
- let hueCheck = lowerHueCheck && upperHueCheck;
45
+ const brightnessTolerance = mask.brightnessTolerance;
46
+ const saturationTolerance = mask.saturationTolerance;
47
+ const lowSaturationThreshold = mask.lowSaturationThreshold;
48
+ const lowBrightnessThreshold = mask.lowBrightnessThreshold;
51
49
 
52
- const saturationDiff = std.abs(std.sub(colorHSV.y, maskedHSV.y));
53
- const saturationCheck = saturationDiff <= saturationTolerance;
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;
54
55
 
55
- const brightnessDiff = std.abs(std.sub(colorHSV.z, maskedHSV.z));
56
- const brightnessCheck = brightnessDiff <= brightnessTolerance;
56
+ const maskedHSV = rgbToHSV(maskedColor);
57
57
 
58
- const pixelIsGray = colorHSV.y < lowSaturationThreshold;
59
- const targetIsGray = maskedHSV.y < lowSaturationThreshold;
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;
60
64
 
61
- const pixelIsBlack = colorHSV.z < lowBrightnessThreshold;
62
- const targetIsBlack = maskedHSV.z < lowBrightnessThreshold;
65
+ const saturationDiff = std.abs(std.sub(colorHSV.y, maskedHSV.y));
66
+ const saturationCheck = saturationDiff <= saturationTolerance;
63
67
 
64
- //hue is unstable when either color is gray or black (low saturation or low brightness)
65
- const hueIsUnstable =
66
- pixelIsGray || targetIsGray || pixelIsBlack || targetIsBlack;
68
+ const brightnessDiff = std.abs(std.sub(colorHSV.z, maskedHSV.z));
69
+ const brightnessCheck = brightnessDiff <= brightnessTolerance;
67
70
 
68
- hueCheck = std.select(hueCheck, d.bool(true), hueIsUnstable);
71
+ const pixelIsGray = colorHSV.y < lowSaturationThreshold;
72
+ const targetIsGray = maskedHSV.y < lowSaturationThreshold;
69
73
 
70
- const hsvCheck = hueCheck && saturationCheck && brightnessCheck;
71
- const maskCheck = std.select(rgbCheck, hsvCheck, useHSV === d.u32(1));
74
+ const pixelIsBlack = colorHSV.z < lowBrightnessThreshold;
75
+ const targetIsBlack = maskedHSV.z < lowBrightnessThreshold;
72
76
 
73
- color = std.select(color, d.vec4f(color.xyz, 0.0), maskCheck);
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;
81
+
82
+ hueCheck = std.select(hueCheck, d.bool(true), hueIsUnstable);
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);
96
+ //debug - shows masked areas coloring them red
97
+ color = std.select(
98
+ color,
99
+ d.vec4f(1.0, 0.0, 0.0, 0.0),
100
+ maskingLogic && colorMaskDebug > 0
101
+ );
74
102
  return color;
75
103
  });
76
104
 
@@ -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; // radians
99
- const hueShiftAngleMax = opts.hueShiftAngleMax; // radians
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,
@@ -137,7 +141,5 @@ export const newGlareFragment = tgpu['~unstable'].fragmentFn({
137
141
 
138
142
  const outRGB = std.clamp(finalRGB, d.vec3f(0.0), d.vec3f(1.0));
139
143
 
140
- // if (maskedGlow > 0.6) return d.vec4f(0.0, 0.0, 0.0, 0.0);
141
-
142
144
  return d.vec4f(outRGB, color.w);
143
145
  });
@@ -25,11 +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
- const hueAngle = std.mul(std.abs(band), (10 * Math.PI * rot.x) / 3);
31
- const rainbowColor = hueShift(d.vec3f(1.0, 1.0, 1.0), hueAngle);
31
+ //TODO: fix holo
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);
32
35
  const finalColor = std.mul(rainbowColor, 1.0);
33
36
 
37
+ // console.log('\ncurrentColor = (', rainbowColor.xyz, ')');
38
+ // console.log('hueAngle = ', hueAngle);
39
+ // console.clear();
34
40
  return d.vec4f(finalColor, 0.9 * textureColor.w);
35
41
  });
@@ -24,10 +24,12 @@ export const reverseHoloFragment = tgpu['~unstable'].fragmentFn({
24
24
  const opts = reverseHoloDetectionChannelFlagsBindGroupLayout.$.glareOptions;
25
25
  const glareIntensity = opts.glareIntensity;
26
26
  const glowPower = opts.glowPower;
27
- const hueBlendPower = opts.hueBlendPower;
28
- const hueShiftAngleMin = opts.hueShiftAngleMin;
29
- const hueShiftAngleMax = opts.hueShiftAngleMax;
30
27
  const lightIntensity = opts.lightIntensity;
28
+
29
+ const glareColor = opts.glareColor;
30
+ const hueBlendPower = glareColor.hueBlendPower;
31
+ const hueShiftAngleMin = glareColor.hueShiftAngleMin;
32
+ const hueShiftAngleMax = glareColor.hueShiftAngleMax;
31
33
  //-----------------------------------------------
32
34
 
33
35
  // detection channel flags-----------------------
@@ -82,7 +84,8 @@ export const reverseHoloFragment = tgpu['~unstable'].fragmentFn({
82
84
  holoMaskColor.w *
83
85
  std.pow(scaledRadial, 1.5);
84
86
 
85
- const maskedGlow = std.mul(glowMask, holoFactor); // only affect masked areas
87
+ // const decayedGlowMask = std.exp(1.0 - glowMask);
88
+ const maskedGlow = std.pow(std.mul(glowMask, holoFactor), 2.0); // only affect masked areas
86
89
 
87
90
  const hueAmount = std.mix(
88
91
  hueShiftAngleMin,
@@ -90,11 +93,13 @@ export const reverseHoloFragment = tgpu['~unstable'].fragmentFn({
90
93
  std.clamp(maskedGlow, 0.0, 1.0)
91
94
  );
92
95
  const sparkleHue = hueShift(cardColor.xyz, hueAmount);
96
+ const shineStrength = std.clamp(lightIntensity, 1.0, 100.0);
97
+ const shineIntensity = 1.5 * shineStrength * maskedGlow;
98
+
93
99
  const hueMixAmt = std.clamp((hueBlendPower / 5.0) * maskedGlow, 0.0, 1.0);
94
100
  const chromaMix = std.mix(cardColor.xyz, sparkleHue, hueMixAmt);
95
101
 
96
- const shineStrength = std.clamp(lightIntensity, 1.0, 100.0);
97
- const shineLayer = std.mul(chromaMix, 1.5 * shineStrength * maskedGlow);
102
+ const shineLayer = std.mul(chromaMix, shineIntensity);
98
103
 
99
- return d.vec4f(shineLayer, 1 - maskedGlow);
104
+ return d.vec4f(d.vec3f(shineLayer), 1.0 - maskedGlow);
100
105
  });
@@ -7,8 +7,8 @@ export const createTexture = async (
7
7
  width: number;
8
8
  height: number;
9
9
  }
10
- //TODO: check why the error message screams about 'texture_2d' and 'texture_multisampled_2d'
11
- ): Promise<TgpuTexture> => {
10
+ //TODO: change any to the texture types (make a type that includes a union of all texture formats that are used)
11
+ ): Promise<TgpuTexture<any>> => {
12
12
  const texture = root['~unstable'].createTexture({
13
13
  size: [size.width, size.height, 1],
14
14
  format: 'rgba8unorm',
@@ -20,7 +20,7 @@ export const createTexture = async (
20
20
  export const loadTexture = async (
21
21
  root: TgpuRoot,
22
22
  imageBitmap: ImageBitmap,
23
- texture: TgpuTexture
23
+ texture: TgpuTexture<any>
24
24
  ) => {
25
25
  root.device.queue.copyExternalImageToTexture(
26
26
  { source: imageBitmap },
@@ -6,41 +6,20 @@ export const hueShift = tgpu.fn(
6
6
  [d.vec3f, d.f32],
7
7
  d.vec3f
8
8
  )((rgb, angle) => {
9
- const yiqY = std.add(
10
- std.mul(rgb.x, 0.299),
11
- std.add(std.mul(rgb.y, 0.587), std.mul(rgb.z, 0.114))
12
- );
13
- const yiqI = std.add(
14
- std.mul(rgb.x, 0.596),
15
- std.sub(std.mul(rgb.y, -0.274), std.mul(rgb.z, 0.322))
16
- );
17
- const yiqQ = std.add(
18
- std.mul(rgb.x, 0.211),
19
- std.sub(std.mul(rgb.y, -0.523), std.mul(rgb.z, 0.311))
20
- );
21
-
22
- // Rotate hue
23
- const cosA = std.cos(angle);
24
- const sinA = std.sin(angle);
25
- const i = std.sub(std.mul(yiqI, cosA), std.mul(yiqQ, sinA));
26
- const q = std.add(std.mul(yiqI, sinA), std.mul(yiqQ, cosA));
27
-
28
- // Convert back to RGB
29
- const r = std.add(std.add(yiqY, std.mul(i, 0.956)), std.mul(q, 0.621));
30
- const g = std.add(std.add(yiqY, std.mul(i, -0.272)), std.mul(q, -0.647));
31
- const b = std.add(std.add(yiqY, std.mul(i, -1.105)), std.mul(q, 1.702));
32
-
33
- return d.vec3f(r, g, b);
9
+ const hsv = rgbToHSV(rgb);
10
+ const shiftedH = std.fract(std.add(hsv.x, angle / 360.0));
11
+ const shiftedRGB = hsvToRGB(d.vec3f(shiftedH, hsv.y, hsv.z));
12
+ return shiftedRGB;
34
13
  });
35
14
 
36
- export const rgbToHSV = tgpu['~unstable'].fn(
15
+ export const rgbToHSV = tgpu.fn(
37
16
  [d.vec3f],
38
17
  d.vec3f
39
18
  )((rgb) => {
40
19
  const K = d.vec4f(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
41
20
  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),
21
+ d.vec4f(rgb.z, rgb.y, K.w, K.z),
22
+ d.vec4f(rgb.y, rgb.z, K.x, K.y),
44
23
  std.step(rgb.z, rgb.y)
45
24
  );
46
25
  const q = std.mix(
@@ -49,34 +28,50 @@ export const rgbToHSV = tgpu['~unstable'].fn(
49
28
  std.step(p.x, rgb.x)
50
29
  );
51
30
 
52
- const d_val = std.sub(q.x, std.min(q.w, q.y));
31
+ const v = std.max(q.x, q.y);
32
+ const d_val = std.sub(v, std.min(q.y, q.w));
53
33
  const epsilon = d.f32(1.0e-10);
54
34
 
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
- )
35
+ const h_temp = std.add(
36
+ q.z,
37
+ std.div(std.sub(q.w, q.y), std.add(std.mul(6.0, d_val), epsilon))
60
38
  );
61
- const s = std.div(d_val, std.add(q.x, epsilon));
62
- const v = q.x;
39
+ const h = std.fract(h_temp);
40
+ const s = std.div(d_val, std.add(v, epsilon));
63
41
 
64
42
  return d.vec3f(h, s, v);
65
43
  });
66
44
 
67
- export const hsvToRGB = tgpu['~unstable'].fn(
45
+ export const hsvToRGB = tgpu.fn(
68
46
  [d.vec3f],
69
47
  d.vec3f
70
48
  )((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;
49
+ const h = hsv.x;
50
+ const s = hsv.y;
51
+ const v = hsv.z;
52
+
53
+ // Multiply by 6.0 to convert [0,1] hue range to [0,6] sector range
54
+ const h2 = h * d.f32(6.0);
55
+
56
+ const i = std.floor(h2);
57
+ const f = h2 - i;
58
+
59
+ const p = v * (d.f32(1) - s);
60
+ const q = v * (d.f32(1) - s * f);
61
+ const t = v * (d.f32(1) - s * (d.f32(1) - f));
62
+
63
+ const i1 = d.f32(i === 1);
64
+ const i2 = d.f32(i === 2);
65
+ const i3 = d.f32(i === 3);
66
+ const i4 = d.f32(i === 4);
67
+ const i5 = d.f32(i === 5);
68
+ const i0 = d.f32(d.u32(i5 + i1 + i2 + i3 + i4) === d.u32(0)); //doesnt work, clamps on 300
69
+
70
+ const r = i0 * v + i1 * q + i2 * p + i3 * p + i4 * t + i5 * v;
71
+ const g = i0 * t + i1 * v + i2 * v + i3 * q + i4 * p + i5 * p;
72
+ const b = i0 * p + i1 * p + i2 * t + i3 * v + i4 * v + i5 * q;
73
+
74
+ return d.vec3f(r, g, b);
80
75
  });
81
76
 
82
77
  export const fmod = tgpu.fn(