react-native-shine 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module/components/Content.js +79 -41
- package/lib/module/components/Content.js.map +1 -1
- package/lib/module/components/Shine.js +10 -0
- package/lib/module/components/Shine.js.map +1 -1
- package/lib/module/components/ShineGroup.js +16 -8
- package/lib/module/components/ShineGroup.js.map +1 -1
- package/lib/module/enums/colorHighlightPresets.js +24 -0
- package/lib/module/enums/colorHighlightPresets.js.map +1 -0
- package/lib/module/enums/effectPresets.js +16 -0
- package/lib/module/enums/effectPresets.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/shaders/bindGroupLayouts.js +24 -15
- package/lib/module/shaders/bindGroupLayouts.js.map +1 -1
- package/lib/module/shaders/bindGroupUtils.js +16 -7
- package/lib/module/shaders/bindGroupUtils.js.map +1 -1
- package/lib/module/shaders/computeShaders/precomputeColorMask.js +34 -0
- package/lib/module/shaders/computeShaders/precomputeColorMask.js.map +1 -0
- package/lib/module/shaders/fragmentShaders/colorMaskFragment.js +53 -41
- package/lib/module/shaders/fragmentShaders/colorMaskFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/glareFragment.js +11 -8
- package/lib/module/shaders/fragmentShaders/glareFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/holoFragment.js +6 -5
- package/lib/module/shaders/fragmentShaders/holoFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js +12 -8
- package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js.map +1 -1
- package/lib/module/shaders/pipelineSetups.js +3 -1
- package/lib/module/shaders/pipelineSetups.js.map +1 -1
- package/lib/module/shaders/resourceManagement/bufferManager.js.map +1 -1
- package/lib/module/types/size.js +2 -0
- package/lib/module/types/typeUtils.js +120 -75
- package/lib/module/types/typeUtils.js.map +1 -1
- package/lib/module/types/vector.js +2 -0
- package/lib/module/utils/vector.js +6 -6
- package/lib/typescript/src/components/Content.d.ts +11 -8
- package/lib/typescript/src/components/Content.d.ts.map +1 -1
- package/lib/typescript/src/components/Shine.d.ts.map +1 -1
- package/lib/typescript/src/components/ShineGroup.d.ts +1 -1
- package/lib/typescript/src/components/ShineGroup.d.ts.map +1 -1
- package/lib/typescript/src/enums/colorHighlightPresets.d.ts +12 -0
- package/lib/typescript/src/enums/colorHighlightPresets.d.ts.map +1 -0
- package/lib/typescript/src/enums/effectPresets.d.ts +14 -0
- package/lib/typescript/src/enums/effectPresets.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/shaders/bindGroupLayouts.d.ts +98 -49
- package/lib/typescript/src/shaders/bindGroupLayouts.d.ts.map +1 -1
- package/lib/typescript/src/shaders/bindGroupUtils.d.ts +41 -48
- package/lib/typescript/src/shaders/bindGroupUtils.d.ts.map +1 -1
- package/lib/typescript/src/shaders/computeShaders/precomputeColorMask.d.ts +5 -0
- package/lib/typescript/src/shaders/computeShaders/precomputeColorMask.d.ts.map +1 -0
- package/lib/typescript/src/shaders/fragmentShaders/colorMaskFragment.d.ts.map +1 -1
- package/lib/typescript/src/shaders/fragmentShaders/glareFragment.d.ts.map +1 -1
- package/lib/typescript/src/shaders/fragmentShaders/reverseHoloFragment.d.ts.map +1 -1
- package/lib/typescript/src/shaders/pipelineSetups.d.ts +3 -4
- package/lib/typescript/src/shaders/pipelineSetups.d.ts.map +1 -1
- package/lib/typescript/src/shaders/resourceManagement/bufferManager.d.ts +5 -3
- package/lib/typescript/src/shaders/resourceManagement/bufferManager.d.ts.map +1 -1
- package/lib/typescript/src/types/typeUtils.d.ts +43 -10
- package/lib/typescript/src/types/typeUtils.d.ts.map +1 -1
- package/lib/typescript/src/types/types.d.ts +31 -4
- package/lib/typescript/src/types/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/components/Content.tsx +98 -39
- package/src/components/Shine.tsx +8 -0
- package/src/components/ShineGroup.tsx +16 -8
- package/src/enums/colorHighlightPresets.ts +33 -0
- package/src/enums/effectPresets.ts +11 -0
- package/src/index.tsx +2 -0
- package/src/shaders/bindGroupLayouts.ts +34 -11
- package/src/shaders/bindGroupUtils.ts +19 -26
- package/src/shaders/computeShaders/precomputeColorMask.ts +29 -0
- package/src/shaders/fragmentShaders/colorMaskFragment.ts +64 -45
- package/src/shaders/fragmentShaders/glareFragment.ts +10 -6
- package/src/shaders/fragmentShaders/holoFragment.ts +5 -5
- package/src/shaders/fragmentShaders/reverseHoloFragment.ts +12 -7
- package/src/shaders/pipelineSetups.ts +15 -6
- package/src/shaders/resourceManagement/bufferManager.ts +8 -3
- package/src/types/typeUtils.ts +134 -82
- package/src/types/types.ts +36 -4
|
@@ -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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
45
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
55
|
-
const saturationCheck = saturationDiff <= saturationTolerance;
|
|
56
|
+
const maskedHSV = rgbToHSV(maskedColor);
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
61
|
-
|
|
65
|
+
const saturationDiff = std.abs(std.sub(colorHSV.y, maskedHSV.y));
|
|
66
|
+
const saturationCheck = saturationDiff <= saturationTolerance;
|
|
62
67
|
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
const brightnessDiff = std.abs(std.sub(colorHSV.z, maskedHSV.z));
|
|
69
|
+
const brightnessCheck = brightnessDiff <= brightnessTolerance;
|
|
65
70
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
pixelIsGray || targetIsGray || pixelIsBlack || targetIsBlack;
|
|
71
|
+
const pixelIsGray = colorHSV.y < lowSaturationThreshold;
|
|
72
|
+
const targetIsGray = maskedHSV.y < lowSaturationThreshold;
|
|
69
73
|
|
|
70
|
-
|
|
74
|
+
const pixelIsBlack = colorHSV.z < lowBrightnessThreshold;
|
|
75
|
+
const targetIsBlack = maskedHSV.z < lowBrightnessThreshold;
|
|
71
76
|
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
|
32
|
-
|
|
33
|
-
const rainbowColor = hueShift(d.vec3f(
|
|
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
|
});
|
|
@@ -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
|
|
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
|
|
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
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
TgpuBindGroup,
|
|
3
|
+
TgpuComputePipeline,
|
|
3
4
|
TgpuRenderPipeline,
|
|
4
5
|
TgpuRoot,
|
|
5
6
|
TgpuTexture,
|
|
@@ -19,14 +20,22 @@ import {
|
|
|
19
20
|
waveCallbackSlot,
|
|
20
21
|
} from '../enums/waveCallback';
|
|
21
22
|
|
|
22
|
-
export
|
|
23
|
+
export function attachBindGroups(
|
|
23
24
|
pipeline: TgpuRenderPipeline,
|
|
24
25
|
bindGroups: TgpuBindGroup[]
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
): TgpuRenderPipeline;
|
|
27
|
+
|
|
28
|
+
export function attachBindGroups(
|
|
29
|
+
pipeline: TgpuComputePipeline,
|
|
30
|
+
bindGroups: TgpuBindGroup[]
|
|
31
|
+
): TgpuComputePipeline;
|
|
32
|
+
|
|
33
|
+
export function attachBindGroups(
|
|
34
|
+
pipeline: TgpuRenderPipeline | TgpuComputePipeline,
|
|
35
|
+
bindGroups: TgpuBindGroup[]
|
|
36
|
+
) {
|
|
37
|
+
return bindGroups.reduce((acc, bindGroup) => acc.with(bindGroup), pipeline);
|
|
38
|
+
}
|
|
30
39
|
|
|
31
40
|
export const blend: GPUBlendState = {
|
|
32
41
|
color: {
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import { type BufferSchemas } from './../bindGroupLayouts';
|
|
1
2
|
import type { TgpuRoot, TgpuBuffer, ValidateBufferSchema } from 'typegpu';
|
|
2
3
|
import { debug } from '../../config/debugMode';
|
|
4
|
+
import type { Infer } from 'typegpu/data';
|
|
3
5
|
|
|
4
6
|
export type BufferUsageType = 'uniform' | 'storage' | 'vertex';
|
|
5
7
|
|
|
6
8
|
type BufferWithUsageFromEntry<
|
|
7
|
-
TEntry extends {
|
|
9
|
+
TEntry extends {
|
|
10
|
+
schema: ValidateBufferSchema<BufferSchemas>;
|
|
11
|
+
usage: BufferUsageType;
|
|
12
|
+
},
|
|
8
13
|
> = TEntry['usage'] extends 'uniform'
|
|
9
14
|
? TgpuBuffer<TEntry['schema']> & { usableAsUniform: true }
|
|
10
15
|
: TEntry['usage'] extends 'storage'
|
|
@@ -16,7 +21,7 @@ type BufferWithUsageFromEntry<
|
|
|
16
21
|
export class TypedBufferMap<
|
|
17
22
|
TSchemas extends Record<
|
|
18
23
|
string,
|
|
19
|
-
{ schema: ValidateBufferSchema<
|
|
24
|
+
{ schema: ValidateBufferSchema<BufferSchemas>; usage: BufferUsageType }
|
|
20
25
|
>,
|
|
21
26
|
> {
|
|
22
27
|
private buffers: {
|
|
@@ -41,7 +46,7 @@ export class TypedBufferMap<
|
|
|
41
46
|
addBuffer<K extends keyof TSchemas>(
|
|
42
47
|
root: TgpuRoot,
|
|
43
48
|
key: K,
|
|
44
|
-
initValues?: TSchemas[K]['schema']
|
|
49
|
+
initValues?: Infer<TSchemas[K]['schema']>
|
|
45
50
|
): BufferWithUsageFromEntry<TSchemas[K]> {
|
|
46
51
|
const entry = this.schemas[key];
|
|
47
52
|
if (!entry) {
|
package/src/types/typeUtils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { vec2f, vec3f, vec4f } from 'typegpu/data';
|
|
2
2
|
import * as d from 'typegpu/data';
|
|
3
3
|
import type {
|
|
4
4
|
GlareOptions,
|
|
@@ -7,88 +7,135 @@ import type {
|
|
|
7
7
|
vec3,
|
|
8
8
|
HoloOptions,
|
|
9
9
|
ReverseHoloDetectionChannelFlags,
|
|
10
|
+
vec2,
|
|
11
|
+
vec4,
|
|
10
12
|
} from './types';
|
|
11
13
|
import { div } from 'typegpu/std';
|
|
12
14
|
import { WAVE_CALLBACKS } from '../enums/waveCallback';
|
|
13
15
|
import { colorMaskDebug } from '../config/debugMode';
|
|
16
|
+
import {
|
|
17
|
+
COLOR_MASK_MAX_COUNT,
|
|
18
|
+
type ColorMaskSchema,
|
|
19
|
+
} from '../shaders/bindGroupLayouts';
|
|
14
20
|
|
|
15
21
|
export const createGlareOptions = (
|
|
16
22
|
options: Partial<GlareOptions>
|
|
17
23
|
): GlareOptions => {
|
|
18
|
-
const {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
hueShiftAngleMin,
|
|
22
|
-
hueBlendPower,
|
|
23
|
-
lightIntensity,
|
|
24
|
-
glareIntensity,
|
|
25
|
-
} = options;
|
|
24
|
+
const { glowPower, glareColor, lightIntensity, glareIntensity } = options;
|
|
25
|
+
const { hueBlendPower, hueShiftAngleMax, hueShiftAngleMin } =
|
|
26
|
+
glareColor || {};
|
|
26
27
|
|
|
27
28
|
const glareOp = {
|
|
28
29
|
glowPower: glowPower ?? 1.0,
|
|
29
|
-
hueShiftAngleMax: hueShiftAngleMax ?? 1.0,
|
|
30
|
-
hueShiftAngleMin: hueShiftAngleMin ?? 0.0,
|
|
31
|
-
hueBlendPower: hueBlendPower ?? 1.0,
|
|
32
30
|
lightIntensity: lightIntensity ?? 1.0,
|
|
33
31
|
glareIntensity: glareIntensity ?? 1.0,
|
|
32
|
+
glareColor: {
|
|
33
|
+
hueShiftAngleMax: hueShiftAngleMax ?? 1.0,
|
|
34
|
+
hueShiftAngleMin: hueShiftAngleMin ?? 0.0,
|
|
35
|
+
hueBlendPower: hueBlendPower ?? 1.0,
|
|
36
|
+
},
|
|
34
37
|
};
|
|
35
38
|
|
|
36
39
|
return glareOp;
|
|
37
40
|
};
|
|
38
41
|
|
|
39
|
-
export const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
export const glareOptionsToTyped = (glareOptions: GlareOptions) => {
|
|
43
|
+
return {
|
|
44
|
+
glowPower: glareOptions.glowPower,
|
|
45
|
+
lightIntensity: glareOptions.lightIntensity,
|
|
46
|
+
glareIntensity: glareOptions.glareIntensity,
|
|
47
|
+
glareColor: {
|
|
48
|
+
hueShiftAngleMax: glareOptions.glareColor.hueShiftAngleMax,
|
|
49
|
+
hueShiftAngleMin: glareOptions.glareColor.hueShiftAngleMin,
|
|
50
|
+
hueBlendPower: glareOptions.glareColor.hueBlendPower,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
50
53
|
};
|
|
51
54
|
|
|
52
|
-
export const
|
|
53
|
-
|
|
54
|
-
): ColorMask => {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
55
|
+
export const createColorMasks = (
|
|
56
|
+
colorMasks: DeepPartiallyOptional<ColorMask, 'baseColor'>[]
|
|
57
|
+
): ColorMask[] => {
|
|
58
|
+
const newColorMasks: ColorMask[] = [];
|
|
59
|
+
for (const i in colorMasks) {
|
|
60
|
+
const {
|
|
61
|
+
baseColor,
|
|
62
|
+
rgbToleranceRange,
|
|
63
|
+
useHSV,
|
|
64
|
+
hueToleranceRange,
|
|
65
|
+
brightnessTolerance,
|
|
66
|
+
saturationTolerance,
|
|
67
|
+
lowBrightnessThreshold,
|
|
68
|
+
lowSaturationThreshold,
|
|
69
|
+
} = colorMasks[i]!;
|
|
70
|
+
const baseTolerance = {
|
|
71
|
+
upper: [20, 20, 20] as vec3,
|
|
72
|
+
lower: [20, 20, 20] as vec3,
|
|
73
|
+
};
|
|
74
|
+
const baseHueTolerance = {
|
|
75
|
+
upper: 20,
|
|
76
|
+
lower: 20,
|
|
77
|
+
};
|
|
78
|
+
const tolerance = { ...baseTolerance, ...rgbToleranceRange };
|
|
79
|
+
const hueTolerance = { ...baseHueTolerance, ...hueToleranceRange };
|
|
80
|
+
const newColorMask: ColorMask = {
|
|
81
|
+
baseColor: baseColor,
|
|
82
|
+
rgbToleranceRange: tolerance,
|
|
83
|
+
useHSV: useHSV!!,
|
|
84
|
+
hueToleranceRange: hueTolerance,
|
|
85
|
+
brightnessTolerance: brightnessTolerance ?? 1.0,
|
|
86
|
+
saturationTolerance: saturationTolerance ?? 1.0,
|
|
87
|
+
lowBrightnessThreshold: lowBrightnessThreshold ?? 0.0,
|
|
88
|
+
lowSaturationThreshold: lowSaturationThreshold ?? 0.0,
|
|
89
|
+
debugMode: colorMaskDebug,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
newColorMasks[i] = newColorMask;
|
|
93
|
+
}
|
|
75
94
|
|
|
76
95
|
// TODO: add radian and degree angle handling
|
|
77
96
|
// '123deg' <- interpret as a numeric angle value
|
|
78
97
|
// 2 <- interpret as a radian value
|
|
79
|
-
const mask: ColorMask = {
|
|
80
|
-
baseColor: baseColor,
|
|
81
|
-
rgbToleranceRange: tolerance,
|
|
82
|
-
useHSV: useHSV!!,
|
|
83
|
-
hueToleranceRange: hueTolerance,
|
|
84
|
-
brightnessTolerance: brightnessTolerance ?? 1.0,
|
|
85
|
-
saturationTolerance: saturationTolerance ?? 1.0,
|
|
86
|
-
lowBrightnessThreshold: lowBrightnessThreshold ?? 0.0,
|
|
87
|
-
lowSaturationThreshold: lowSaturationThreshold ?? 0.0,
|
|
88
|
-
debugMode: colorMaskDebug,
|
|
89
|
-
};
|
|
90
98
|
|
|
91
|
-
return
|
|
99
|
+
return newColorMasks;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const fillColorMaskBufferWithDummies = (
|
|
103
|
+
colorMasks: ColorMask[]
|
|
104
|
+
): ColorMask[] => {
|
|
105
|
+
const dummyFilledColorMasks = new Array(COLOR_MASK_MAX_COUNT);
|
|
106
|
+
for (let i = 0; i < dummyFilledColorMasks.length; i++) {
|
|
107
|
+
if (i < colorMasks.length) {
|
|
108
|
+
dummyFilledColorMasks[i] = colorMasks[i];
|
|
109
|
+
} else {
|
|
110
|
+
dummyFilledColorMasks[i] = {
|
|
111
|
+
baseColor: [0, 0, 0],
|
|
112
|
+
useHSV: false,
|
|
113
|
+
rgbToleranceRange: {
|
|
114
|
+
upper: [0, 0, 0],
|
|
115
|
+
lower: [0, 0, 0],
|
|
116
|
+
},
|
|
117
|
+
hueToleranceRange: {
|
|
118
|
+
upper: 0,
|
|
119
|
+
lower: 0,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return dummyFilledColorMasks;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const colorMasksToTyped = (
|
|
128
|
+
colorMasks: ColorMask[],
|
|
129
|
+
reverseHighlight: boolean
|
|
130
|
+
) => {
|
|
131
|
+
const typedColorMasks = fillColorMaskBufferWithDummies(colorMasks).map(
|
|
132
|
+
(mask) => colorMaskToTyped(mask)
|
|
133
|
+
);
|
|
134
|
+
return {
|
|
135
|
+
masks: typedColorMasks,
|
|
136
|
+
usedMaskCount: colorMasks.length,
|
|
137
|
+
reverseHighlight: reverseHighlight ? 1 : 0,
|
|
138
|
+
};
|
|
92
139
|
};
|
|
93
140
|
|
|
94
141
|
export const colorMaskToTyped = (colorMask: ColorMask) => {
|
|
@@ -98,17 +145,18 @@ export const colorMaskToTyped = (colorMask: ColorMask) => {
|
|
|
98
145
|
upper: div(numberArrToTyped(colorMask.rgbToleranceRange.upper), 255),
|
|
99
146
|
lower: div(numberArrToTyped(colorMask.rgbToleranceRange.lower), 255),
|
|
100
147
|
},
|
|
101
|
-
useHSV:
|
|
148
|
+
useHSV: colorMask.useHSV ? 1 : 0,
|
|
102
149
|
hueToleranceRange: {
|
|
103
|
-
lower: div(
|
|
104
|
-
upper: div(
|
|
150
|
+
lower: div(colorMask.hueToleranceRange.lower, 360),
|
|
151
|
+
upper: div(colorMask.hueToleranceRange.upper, 360),
|
|
105
152
|
},
|
|
106
|
-
brightnessTolerance:
|
|
107
|
-
saturationTolerance:
|
|
108
|
-
lowSaturationThreshold:
|
|
109
|
-
lowBrightnessThreshold:
|
|
110
|
-
debugMode:
|
|
111
|
-
}
|
|
153
|
+
brightnessTolerance: colorMask.brightnessTolerance,
|
|
154
|
+
saturationTolerance: colorMask.saturationTolerance,
|
|
155
|
+
lowSaturationThreshold: colorMask.lowSaturationThreshold,
|
|
156
|
+
lowBrightnessThreshold: colorMask.lowBrightnessThreshold,
|
|
157
|
+
debugMode: colorMask.debugMode ? 1 : 0,
|
|
158
|
+
} as d.Infer<ColorMaskSchema>;
|
|
159
|
+
|
|
112
160
|
return result;
|
|
113
161
|
};
|
|
114
162
|
|
|
@@ -133,29 +181,33 @@ export const createReverseHoloDetectionChannelFlags = (
|
|
|
133
181
|
options;
|
|
134
182
|
|
|
135
183
|
channelFlags = {
|
|
136
|
-
redChannel: redChannel ??
|
|
137
|
-
greenChannel: greenChannel ??
|
|
138
|
-
blueChannel: blueChannel ??
|
|
139
|
-
hue: hue ??
|
|
140
|
-
saturation: saturation ??
|
|
141
|
-
value: value ??
|
|
184
|
+
redChannel: redChannel ?? 0.0,
|
|
185
|
+
greenChannel: greenChannel ?? 0.0,
|
|
186
|
+
blueChannel: blueChannel ?? 0.0,
|
|
187
|
+
hue: hue ?? 0.0,
|
|
188
|
+
saturation: saturation ?? 0.0,
|
|
189
|
+
value: value ?? 0.0,
|
|
142
190
|
};
|
|
143
191
|
} else {
|
|
144
192
|
channelFlags = {
|
|
145
|
-
redChannel:
|
|
146
|
-
greenChannel:
|
|
147
|
-
blueChannel:
|
|
148
|
-
hue:
|
|
149
|
-
saturation:
|
|
150
|
-
value:
|
|
193
|
+
redChannel: 1.0,
|
|
194
|
+
greenChannel: 0.0,
|
|
195
|
+
blueChannel: 0.0,
|
|
196
|
+
hue: 0.0,
|
|
197
|
+
saturation: 0.0,
|
|
198
|
+
value: 0.0,
|
|
151
199
|
};
|
|
152
200
|
}
|
|
153
201
|
|
|
154
202
|
return channelFlags;
|
|
155
203
|
};
|
|
156
204
|
|
|
157
|
-
export
|
|
158
|
-
|
|
205
|
+
export function numberArrToTyped(vec: vec2): d.v2f;
|
|
206
|
+
export function numberArrToTyped(vec: vec3): d.v3f;
|
|
207
|
+
export function numberArrToTyped(vec: vec4): d.v4f;
|
|
208
|
+
export function numberArrToTyped(vec: number[]): d.v2f | d.v3f | d.v4f;
|
|
209
|
+
export function numberArrToTyped(vec: number[]) {
|
|
210
|
+
let convFn: ((...args: number[]) => d.v2f | d.v3f | d.v4f) | null = null;
|
|
159
211
|
switch (vec.length) {
|
|
160
212
|
case 2:
|
|
161
213
|
convFn = vec2f;
|
|
@@ -172,4 +224,4 @@ export const numberArrToTyped = (vec: number[]) => {
|
|
|
172
224
|
|
|
173
225
|
const typed = convFn(...vec);
|
|
174
226
|
return typed;
|
|
175
|
-
}
|
|
227
|
+
}
|
package/src/types/types.ts
CHANGED
|
@@ -12,11 +12,13 @@ export type quaternion = vec4;
|
|
|
12
12
|
|
|
13
13
|
export type GlareOptions = {
|
|
14
14
|
glowPower: number;
|
|
15
|
-
hueShiftAngleMax: number;
|
|
16
|
-
hueShiftAngleMin: number;
|
|
17
|
-
hueBlendPower: number;
|
|
18
15
|
lightIntensity: number;
|
|
19
16
|
glareIntensity: number;
|
|
17
|
+
glareColor: {
|
|
18
|
+
hueBlendPower: number;
|
|
19
|
+
hueShiftAngleMax: number;
|
|
20
|
+
hueShiftAngleMin: number;
|
|
21
|
+
};
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
export type ColorMask = {
|
|
@@ -24,8 +26,8 @@ export type ColorMask = {
|
|
|
24
26
|
useHSV?: boolean;
|
|
25
27
|
hueToleranceRange: { upper: number; lower: number };
|
|
26
28
|
brightnessTolerance?: number;
|
|
27
|
-
lowBrightnessThreshold?: number;
|
|
28
29
|
saturationTolerance?: number;
|
|
30
|
+
lowBrightnessThreshold?: number;
|
|
29
31
|
lowSaturationThreshold?: number;
|
|
30
32
|
rgbToleranceRange: {
|
|
31
33
|
upper: vec3;
|
|
@@ -34,6 +36,36 @@ export type ColorMask = {
|
|
|
34
36
|
debugMode?: boolean;
|
|
35
37
|
};
|
|
36
38
|
|
|
39
|
+
//TODO: figure out how to tell compiler that im sure that it's long enough ;-;
|
|
40
|
+
export type ColorMaskArrayShaderAssert = [
|
|
41
|
+
any,
|
|
42
|
+
any,
|
|
43
|
+
any,
|
|
44
|
+
any,
|
|
45
|
+
any,
|
|
46
|
+
any,
|
|
47
|
+
any,
|
|
48
|
+
any,
|
|
49
|
+
any,
|
|
50
|
+
any,
|
|
51
|
+
any,
|
|
52
|
+
any,
|
|
53
|
+
any,
|
|
54
|
+
any,
|
|
55
|
+
any,
|
|
56
|
+
any,
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
export type Effect =
|
|
60
|
+
| {
|
|
61
|
+
name: 'reverseHolo';
|
|
62
|
+
options: Partial<ReverseHoloDetectionChannelFlags>;
|
|
63
|
+
}
|
|
64
|
+
| {
|
|
65
|
+
name: 'holo';
|
|
66
|
+
options?: HoloOptions;
|
|
67
|
+
};
|
|
68
|
+
|
|
37
69
|
export type ReverseHoloDetectionChannelFlags = {
|
|
38
70
|
redChannel: number;
|
|
39
71
|
greenChannel: number;
|