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.
- package/lib/module/components/Content.js +126 -135
- package/lib/module/components/Content.js.map +1 -1
- package/lib/module/components/Shine.js +22 -3
- package/lib/module/components/Shine.js.map +1 -1
- package/lib/module/components/ShineGroup.js +0 -4
- package/lib/module/components/ShineGroup.js.map +1 -1
- package/lib/module/enums/colorPresets.js +192 -0
- package/lib/module/enums/colorPresets.js.map +1 -1
- package/lib/module/enums/effectDefaults.js +59 -0
- package/lib/module/enums/effectDefaults.js.map +1 -0
- package/lib/module/enums/effectPresets.js +67 -10
- package/lib/module/enums/effectPresets.js.map +1 -1
- package/lib/module/shaders/bindGroupLayouts.js +50 -27
- package/lib/module/shaders/bindGroupLayouts.js.map +1 -1
- package/lib/module/shaders/bindGroupUtils.js +30 -44
- package/lib/module/shaders/bindGroupUtils.js.map +1 -1
- package/lib/module/shaders/colorConversions.js +78 -0
- package/lib/module/shaders/colorConversions.js.map +1 -0
- package/lib/module/shaders/computeShaders/precomputeColorMask.js +34 -0
- package/lib/module/shaders/computeShaders/precomputeColorMask.js.map +1 -0
- package/lib/module/shaders/fragmentShaders/baseTextureFragment.js +4 -9
- package/lib/module/shaders/fragmentShaders/baseTextureFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/colorMaskFragment.js +28 -41
- package/lib/module/shaders/fragmentShaders/colorMaskFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/glareFlareFragment.js +84 -0
- package/lib/module/shaders/fragmentShaders/glareFlareFragment.js.map +1 -0
- package/lib/module/shaders/fragmentShaders/glareFragment.js +8 -88
- package/lib/module/shaders/fragmentShaders/glareFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/holoFragment.js +120 -11
- package/lib/module/shaders/fragmentShaders/holoFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/maskFragment.js +5 -4
- package/lib/module/shaders/fragmentShaders/maskFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js +7 -7
- package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js.map +1 -1
- package/lib/module/shaders/pipelineSetups.js +5 -62
- package/lib/module/shaders/pipelineSetups.js.map +1 -1
- package/lib/module/shaders/resourceManagement/bufferManager.js.map +1 -1
- package/lib/module/shaders/resourceManagement/buffersMap.js +41 -0
- package/lib/module/shaders/resourceManagement/buffersMap.js.map +1 -0
- package/lib/module/shaders/resourceManagement/pipelineMap.js +115 -0
- package/lib/module/shaders/resourceManagement/pipelineMap.js.map +1 -0
- package/lib/module/shaders/resourceManagement/textures.js +2 -2
- package/lib/module/shaders/resourceManagement/textures.js.map +1 -1
- package/lib/module/shaders/tgpuUtils.js +41 -0
- package/lib/module/shaders/tgpuUtils.js.map +1 -1
- package/lib/module/shaders/utils.js +21 -2
- package/lib/module/shaders/utils.js.map +1 -1
- package/lib/module/shaders/vertexShaders/mainRotationEffectVertex.js +4 -4
- package/lib/module/shaders/vertexShaders/mainRotationEffectVertex.js.map +1 -1
- package/lib/module/types/typeUtils.js +29 -159
- package/lib/module/types/typeUtils.js.map +1 -1
- package/lib/module/types/types.js +8 -1
- package/lib/module/types/types.js.map +1 -1
- package/lib/module/utils/size.js +4 -4
- package/lib/module/utils/vector.js +38 -38
- package/lib/typescript/src/components/Content.d.ts +6 -6
- 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/colorPresets.d.ts +152 -0
- package/lib/typescript/src/enums/colorPresets.d.ts.map +1 -1
- package/lib/typescript/src/enums/effectDefaults.d.ts +39 -0
- package/lib/typescript/src/enums/effectDefaults.d.ts.map +1 -0
- package/lib/typescript/src/enums/effectPresets.d.ts +284 -5
- package/lib/typescript/src/enums/effectPresets.d.ts.map +1 -1
- package/lib/typescript/src/shaders/bindGroupLayouts.d.ts +82 -41
- package/lib/typescript/src/shaders/bindGroupLayouts.d.ts.map +1 -1
- package/lib/typescript/src/shaders/bindGroupUtils.d.ts +86 -70
- package/lib/typescript/src/shaders/bindGroupUtils.d.ts.map +1 -1
- package/lib/typescript/src/shaders/colorConversions.d.ts +4 -0
- package/lib/typescript/src/shaders/colorConversions.d.ts.map +1 -0
- 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/baseTextureFragment.d.ts.map +1 -1
- package/lib/typescript/src/shaders/fragmentShaders/colorMaskFragment.d.ts.map +1 -1
- package/lib/typescript/src/shaders/fragmentShaders/glareFlareFragment.d.ts +5 -0
- package/lib/typescript/src/shaders/fragmentShaders/glareFlareFragment.d.ts.map +1 -0
- package/lib/typescript/src/shaders/fragmentShaders/glareFragment.d.ts +0 -3
- package/lib/typescript/src/shaders/fragmentShaders/glareFragment.d.ts.map +1 -1
- package/lib/typescript/src/shaders/fragmentShaders/holoFragment.d.ts +7 -0
- package/lib/typescript/src/shaders/fragmentShaders/holoFragment.d.ts.map +1 -1
- package/lib/typescript/src/shaders/fragmentShaders/maskFragment.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 -10
- 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/shaders/resourceManagement/buffersMap.d.ts +10 -0
- package/lib/typescript/src/shaders/resourceManagement/buffersMap.d.ts.map +1 -0
- package/lib/typescript/src/shaders/resourceManagement/pipelineMap.d.ts +24 -0
- package/lib/typescript/src/shaders/resourceManagement/pipelineMap.d.ts.map +1 -0
- package/lib/typescript/src/shaders/resourceManagement/textures.d.ts +0 -1
- package/lib/typescript/src/shaders/resourceManagement/textures.d.ts.map +1 -1
- package/lib/typescript/src/shaders/tgpuUtils.d.ts +3 -0
- package/lib/typescript/src/shaders/tgpuUtils.d.ts.map +1 -1
- package/lib/typescript/src/shaders/utils.d.ts +1 -0
- package/lib/typescript/src/shaders/utils.d.ts.map +1 -1
- package/lib/typescript/src/types/typeUtils.d.ts +16 -51
- package/lib/typescript/src/types/typeUtils.d.ts.map +1 -1
- package/lib/typescript/src/types/types.d.ts +59 -54
- package/lib/typescript/src/types/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Content.tsx +130 -269
- package/src/components/Shine.tsx +28 -3
- package/src/components/ShineGroup.tsx +0 -4
- package/src/enums/colorPresets.ts +59 -1
- package/src/enums/effectDefaults.ts +57 -0
- package/src/enums/effectPresets.ts +142 -9
- package/src/shaders/bindGroupLayouts.ts +64 -28
- package/src/shaders/bindGroupUtils.ts +66 -69
- package/src/shaders/colorConversions.ts +88 -0
- package/src/shaders/computeShaders/precomputeColorMask.ts +29 -0
- package/src/shaders/fragmentShaders/baseTextureFragment.ts +2 -10
- package/src/shaders/fragmentShaders/colorMaskFragment.ts +34 -55
- package/src/shaders/fragmentShaders/glareFlareFragment.ts +79 -0
- package/src/shaders/fragmentShaders/glareFragment.ts +9 -84
- package/src/shaders/fragmentShaders/holoFragment.ts +139 -11
- package/src/shaders/fragmentShaders/maskFragment.ts +3 -9
- package/src/shaders/fragmentShaders/reverseHoloFragment.ts +4 -9
- package/src/shaders/pipelineSetups.ts +16 -125
- package/src/shaders/resourceManagement/bufferManager.ts +8 -3
- package/src/shaders/resourceManagement/buffersMap.ts +80 -0
- package/src/shaders/resourceManagement/pipelineMap.ts +169 -0
- package/src/shaders/resourceManagement/textures.ts +2 -2
- package/src/shaders/tgpuUtils.ts +29 -0
- package/src/shaders/utils.ts +29 -0
- package/src/shaders/vertexShaders/mainRotationEffectVertex.ts +2 -2
- package/src/types/typeUtils.ts +53 -164
- package/src/types/types.ts +111 -60
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import tgpu from 'typegpu';
|
|
2
|
+
import * as std from 'typegpu/std';
|
|
3
|
+
import * as d from 'typegpu/data';
|
|
4
|
+
// branchless implementation
|
|
5
|
+
export const RGBToHSL = tgpu.fn(
|
|
6
|
+
[d.vec3f],
|
|
7
|
+
d.vec3f
|
|
8
|
+
)((rgb) => {
|
|
9
|
+
const chroma_max = std.max(rgb.x, std.max(rgb.y, rgb.z));
|
|
10
|
+
const chroma_min = std.min(rgb.x, std.min(rgb.y, rgb.z));
|
|
11
|
+
const chroma = chroma_max - chroma_min;
|
|
12
|
+
const lightness = (chroma_max + chroma_min) / 2.0;
|
|
13
|
+
|
|
14
|
+
const safe_chroma = chroma + d.f32(chroma === 0.0);
|
|
15
|
+
const saturation_denomitator = 1.0 - std.abs(2.0 * lightness - 1.0);
|
|
16
|
+
const safe_saturation_denominator =
|
|
17
|
+
saturation_denomitator + d.f32(saturation_denomitator === 0.0);
|
|
18
|
+
|
|
19
|
+
const safe_saturation = chroma / safe_saturation_denominator;
|
|
20
|
+
|
|
21
|
+
const hue_red = ((rgb.y - rgb.z) / safe_chroma) % 6;
|
|
22
|
+
const hue_green = (rgb.z - rgb.x) / safe_chroma + 2.0;
|
|
23
|
+
const hue_blue = (rgb.x - rgb.y) / safe_chroma + 4.0;
|
|
24
|
+
|
|
25
|
+
let hue_prime = hue_red;
|
|
26
|
+
hue_prime = std.select(hue_prime, hue_green, chroma_max === rgb.y);
|
|
27
|
+
hue_prime = std.select(hue_prime, hue_blue, chroma_max === rgb.z);
|
|
28
|
+
|
|
29
|
+
hue_prime = std.select(hue_prime, hue_prime + 6, hue_prime < 0);
|
|
30
|
+
|
|
31
|
+
const safe_hue = hue_prime * 60;
|
|
32
|
+
const hue = std.select(0.0, safe_hue, chroma !== 0);
|
|
33
|
+
return d.vec3f(hue, safe_saturation, lightness);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const HSLToRGB = tgpu.fn(
|
|
37
|
+
[d.vec3f],
|
|
38
|
+
d.vec3f
|
|
39
|
+
)((rgb) => {
|
|
40
|
+
// Your HSL values
|
|
41
|
+
const h = rgb.x;
|
|
42
|
+
const s = rgb.y;
|
|
43
|
+
const l = rgb.z;
|
|
44
|
+
// 1. Calculate Chroma (c)
|
|
45
|
+
let c = (1.0 - std.abs(2.0 * l - 1.0)) * s;
|
|
46
|
+
|
|
47
|
+
// 2. Calculate H_prime (H') and the intermediate value (x)
|
|
48
|
+
// H' is H mapped to a 0.0-6.0 range
|
|
49
|
+
let h_prime = (h / 60.0) % 6.0;
|
|
50
|
+
let x = c * (1.0 - std.abs((h_prime % 2.0) - 1.0));
|
|
51
|
+
|
|
52
|
+
// 3. Get the integer "sector" (0-5)
|
|
53
|
+
let i = std.floor(h_prime);
|
|
54
|
+
|
|
55
|
+
// 4. Find the (r', g', b') triplet using a branchless switch.
|
|
56
|
+
// We multiply each possible triplet by 1.0 if it's the right
|
|
57
|
+
// sector, or 0.0 if not, then add them all together.
|
|
58
|
+
let rgb_prime = d.vec3f(0.0);
|
|
59
|
+
|
|
60
|
+
rgb_prime = std.add(
|
|
61
|
+
rgb_prime,
|
|
62
|
+
std.mix(d.vec3f(), d.vec3f(c, x, 0.0), d.f32(i === 0.0))
|
|
63
|
+
);
|
|
64
|
+
rgb_prime = std.add(
|
|
65
|
+
rgb_prime,
|
|
66
|
+
std.mix(d.vec3f(), d.vec3f(x, c, 0.0), d.f32(i === 1.0))
|
|
67
|
+
);
|
|
68
|
+
rgb_prime = std.add(
|
|
69
|
+
rgb_prime,
|
|
70
|
+
std.mix(d.vec3f(), d.vec3f(0, c, x), d.f32(i === 2.0))
|
|
71
|
+
);
|
|
72
|
+
rgb_prime = std.add(
|
|
73
|
+
rgb_prime,
|
|
74
|
+
std.mix(d.vec3f(), d.vec3f(0, x, c), d.f32(i === 3.0))
|
|
75
|
+
);
|
|
76
|
+
rgb_prime = std.add(
|
|
77
|
+
rgb_prime,
|
|
78
|
+
std.mix(d.vec3f(), d.vec3f(x, 0, c), d.f32(i === 4.0))
|
|
79
|
+
);
|
|
80
|
+
rgb_prime = std.add(
|
|
81
|
+
rgb_prime,
|
|
82
|
+
std.mix(d.vec3f(), d.vec3f(c, 0, x), d.f32(i === 5.0))
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// 5. Calculate the lightness offset (m) and add it to all components
|
|
86
|
+
let m = l - c / 2.0;
|
|
87
|
+
return std.add(rgb_prime, d.vec3f(m));
|
|
88
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import tgpu from 'typegpu';
|
|
2
|
+
import * as d from 'typegpu/data';
|
|
3
|
+
import * as std from 'typegpu/std';
|
|
4
|
+
import {
|
|
5
|
+
precomputeColorMaskBindGroupLayout,
|
|
6
|
+
sharedBindGroupLayout,
|
|
7
|
+
} from './../bindGroupLayouts';
|
|
8
|
+
|
|
9
|
+
export const precomputeColorMask = tgpu['~unstable'].computeFn({
|
|
10
|
+
in: { gid: d.builtin.globalInvocationId },
|
|
11
|
+
workgroupSize: [8, 8, 1],
|
|
12
|
+
})((input) => {
|
|
13
|
+
const x = input.gid.x;
|
|
14
|
+
const y = input.gid.y;
|
|
15
|
+
const colorMaskStorageTexture =
|
|
16
|
+
precomputeColorMaskBindGroupLayout.$.colorMaskStorage;
|
|
17
|
+
const size = std.textureDimensions(colorMaskStorageTexture);
|
|
18
|
+
|
|
19
|
+
if (x >= size.x || y >= size.y) return;
|
|
20
|
+
const uv = d.vec2f(d.f32(x) / d.f32(size.x), d.f32(y) / d.f32(size.y));
|
|
21
|
+
|
|
22
|
+
const colorSampled = std.textureSample(
|
|
23
|
+
sharedBindGroupLayout.$.texture,
|
|
24
|
+
sharedBindGroupLayout.$.sampler,
|
|
25
|
+
uv
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
std.textureStore(colorMaskStorageTexture, d.vec2u(x, y), colorSampled);
|
|
29
|
+
});
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import tgpu from 'typegpu';
|
|
2
2
|
import * as d from 'typegpu/data';
|
|
3
|
-
import
|
|
4
|
-
import { textureBindGroupLayout } from '../bindGroupLayouts';
|
|
3
|
+
import { getPixelColorFromNonReversedVector } from '../tgpuUtils';
|
|
5
4
|
|
|
6
5
|
export const baseTextureFragment = tgpu['~unstable'].fragmentFn({
|
|
7
6
|
in: { uv: d.vec2f },
|
|
8
7
|
out: d.vec4f,
|
|
9
8
|
})((input) => {
|
|
10
|
-
|
|
11
|
-
let color = std.textureSample(
|
|
12
|
-
textureBindGroupLayout.$.texture,
|
|
13
|
-
textureBindGroupLayout.$.sampler,
|
|
14
|
-
texcoord
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
return color;
|
|
9
|
+
return getPixelColorFromNonReversedVector(input.uv);
|
|
18
10
|
});
|
|
@@ -2,50 +2,37 @@ import tgpu from 'typegpu';
|
|
|
2
2
|
import * as d from 'typegpu/data';
|
|
3
3
|
import * as std from 'typegpu/std';
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
COLOR_MASK_MAX_COUNT,
|
|
6
6
|
colorMaskBindGroupLayout,
|
|
7
|
+
type ColorMaskSchema,
|
|
8
|
+
// sharedBindGroupLayout,
|
|
9
|
+
// precomputeColorMaskOutputBindGroupLayout,
|
|
7
10
|
} from '../bindGroupLayouts';
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
11
|
+
import { getPixelColorFromNonReversedVector } from '../tgpuUtils';
|
|
12
|
+
import { RGBToHSL } from '../colorConversions';
|
|
10
13
|
|
|
11
14
|
const colorMaskFragment = tgpu['~unstable'].fragmentFn({
|
|
12
15
|
in: { uv: d.vec2f },
|
|
13
16
|
out: d.vec4f,
|
|
14
17
|
})((input) => {
|
|
15
|
-
|
|
18
|
+
let color = getPixelColorFromNonReversedVector(input.uv);
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
textureBindGroupLayout.$.texture,
|
|
19
|
-
textureBindGroupLayout.$.sampler,
|
|
20
|
-
texcoord
|
|
21
|
-
);
|
|
22
|
-
const masks = colorMaskBindGroupLayout.$.colorMasks
|
|
23
|
-
.masks as ColorMaskArrayShaderAssert;
|
|
20
|
+
const masks = colorMaskBindGroupLayout.$.colorMasks.masks;
|
|
24
21
|
const usedMaskCount = colorMaskBindGroupLayout.$.colorMasks.usedMaskCount;
|
|
25
22
|
const reverseHighlight =
|
|
26
23
|
colorMaskBindGroupLayout.$.colorMasks.reverseHighlight;
|
|
27
24
|
|
|
28
25
|
let colorMaskDebug = d.u32(0);
|
|
29
26
|
let cumulativeMaskCheck = d.u32(0);
|
|
30
|
-
const
|
|
27
|
+
const colorHSL = RGBToHSL(color.xyz);
|
|
31
28
|
|
|
32
29
|
//TODO: optimize this more
|
|
33
|
-
for (let i = 0; i <
|
|
30
|
+
for (let i = 0; i < COLOR_MASK_MAX_COUNT; i++) {
|
|
34
31
|
if (usedMaskCount <= i) break;
|
|
35
32
|
|
|
36
|
-
const mask = masks[i];
|
|
33
|
+
const mask = masks[i] as ColorMaskSchema;
|
|
37
34
|
const maskedColor = mask.baseColor;
|
|
38
35
|
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;
|
|
49
36
|
|
|
50
37
|
const maskedColorLower = std.sub(maskedColor, rgbToleranceRange.lower);
|
|
51
38
|
const maskedColorUpper = std.add(maskedColor, rgbToleranceRange.upper);
|
|
@@ -53,37 +40,29 @@ const colorMaskFragment = tgpu['~unstable'].fragmentFn({
|
|
|
53
40
|
const lowerCheck = std.all(std.ge(color.xyz, maskedColorLower));
|
|
54
41
|
const rgbCheck = upperCheck && lowerCheck;
|
|
55
42
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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);
|
|
43
|
+
const saturationAndLightness = colorHSL.yz;
|
|
44
|
+
const hueStart = mask.hueStart;
|
|
45
|
+
const hueDiff = colorHSL.x - hueStart;
|
|
46
|
+
const distance = std.mod(std.add(hueDiff, 360), 360);
|
|
47
|
+
const hueCheck = std.step(distance, mask.hueRange);
|
|
48
|
+
|
|
49
|
+
// step(min, val) -> returns 1.0, if val >= min
|
|
50
|
+
// step(val, max) -> returns 1.0, if max >= val
|
|
51
|
+
const checkVec = std.mul(
|
|
52
|
+
std.step(mask.minLimits, saturationAndLightness),
|
|
53
|
+
std.step(saturationAndLightness, mask.maxLimits)
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const saturationAndLightnessMask = std.mul(checkVec.x, checkVec.y);
|
|
57
|
+
|
|
58
|
+
const hslCheck = std.mul(hueCheck, saturationAndLightnessMask);
|
|
59
|
+
|
|
60
|
+
const maskCheck = std.select(
|
|
61
|
+
d.u32(rgbCheck),
|
|
62
|
+
hslCheck,
|
|
63
|
+
mask.useHSV === d.u32(1)
|
|
64
|
+
);
|
|
65
|
+
cumulativeMaskCheck = cumulativeMaskCheck + maskCheck;
|
|
87
66
|
colorMaskDebug = colorMaskDebug + mask.debugMode;
|
|
88
67
|
}
|
|
89
68
|
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import tgpu from 'typegpu';
|
|
2
|
+
import * as d from 'typegpu/data';
|
|
3
|
+
import * as std from 'typegpu/std';
|
|
4
|
+
import {
|
|
5
|
+
glareFlareBindGroupLayout,
|
|
6
|
+
sharedBindGroupLayout,
|
|
7
|
+
} from '../bindGroupLayouts';
|
|
8
|
+
import { getPixelColorFromVector } from '../tgpuUtils';
|
|
9
|
+
import { HSLToRGB, RGBToHSL } from '../colorConversions';
|
|
10
|
+
|
|
11
|
+
export const glareFlareFragment = tgpu['~unstable'].fragmentFn({
|
|
12
|
+
in: { uv: d.vec2f },
|
|
13
|
+
out: d.vec4f,
|
|
14
|
+
})((input) => {
|
|
15
|
+
const uv = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
16
|
+
const centeredCoords = std.sub(std.mul(uv, 2.0), 1.0);
|
|
17
|
+
|
|
18
|
+
let color = getPixelColorFromVector(uv);
|
|
19
|
+
|
|
20
|
+
const rot = sharedBindGroupLayout.$.rot;
|
|
21
|
+
const center = std.add(d.vec2f(0.0), d.vec2f(rot.x, rot.y)); // do not change
|
|
22
|
+
let dist = std.distance(center, centeredCoords);
|
|
23
|
+
|
|
24
|
+
// Normalize UV coordinates to be between -1 and 1
|
|
25
|
+
let uv_norm = std.sub(std.mul(input.uv, 2.0), 1.0);
|
|
26
|
+
|
|
27
|
+
// Calculate distance from center and ensure it does not exceed 1
|
|
28
|
+
let angle = std.atan2(std.add(rot.y, uv_norm.y), std.sub(rot.x, uv_norm.x));
|
|
29
|
+
|
|
30
|
+
dist = std.clamp(dist, 0.0, 1.0);
|
|
31
|
+
// Parameters for flare components
|
|
32
|
+
let flare_intensity = glareFlareBindGroupLayout.$.glareFlare.flareIntensity;
|
|
33
|
+
let spot_intensity = glareFlareBindGroupLayout.$.glareFlare.flareIntensity;
|
|
34
|
+
let ring_intensity = glareFlareBindGroupLayout.$.glareFlare.ringIntensity;
|
|
35
|
+
let ray_intensity = glareFlareBindGroupLayout.$.glareFlare.rayIntensity;
|
|
36
|
+
let falloff = glareFlareBindGroupLayout.$.glareFlare.falloff;
|
|
37
|
+
let ray_count = glareFlareBindGroupLayout.$.glareFlare.rayCount;
|
|
38
|
+
|
|
39
|
+
// Central bright spot with distance-based falloff
|
|
40
|
+
let spot = spot_intensity / (dist * falloff + 0.1);
|
|
41
|
+
|
|
42
|
+
// Rings calculation, also respecting the texture boundary
|
|
43
|
+
let ring1 = (std.sin(dist * 10.0) * ring_intensity) / (dist * falloff + 0.5);
|
|
44
|
+
let ring2 = (std.sin(dist * 20.0) * ring_intensity) / (dist * falloff + 0.3);
|
|
45
|
+
|
|
46
|
+
const noise = std.abs(std.sin(rot.x)) + std.abs(std.cos(rot.y));
|
|
47
|
+
// Ray calculation: create a series of sharp radial spikes
|
|
48
|
+
let ray_angle = angle * ray_count + noise;
|
|
49
|
+
|
|
50
|
+
// Enhanced variability in ray length and size
|
|
51
|
+
let ray_length_factor =
|
|
52
|
+
0.25 + 0.95 * std.abs(std.sin(angle * 3.0 * noise)) * noise;
|
|
53
|
+
let ray_size_factor =
|
|
54
|
+
0.05 + 1.15 * std.abs(std.cos(angle * 13.0 * noise)) + noise;
|
|
55
|
+
|
|
56
|
+
// Apply variability to rays
|
|
57
|
+
let ray =
|
|
58
|
+
std.pow(std.abs(std.sin(ray_angle)), 15.0 * ray_size_factor) *
|
|
59
|
+
ray_intensity *
|
|
60
|
+
(1.0 - dist * ray_length_factor) *
|
|
61
|
+
noise;
|
|
62
|
+
|
|
63
|
+
// Combine all flare components
|
|
64
|
+
let flare = spot + ring1 + ring2 + ray;
|
|
65
|
+
|
|
66
|
+
// Calculate fade factor to black based on distance to the edge
|
|
67
|
+
let edge_fade = 1.0 - dist;
|
|
68
|
+
|
|
69
|
+
// Apply edge fade
|
|
70
|
+
const flareFaded = flare * edge_fade;
|
|
71
|
+
const flareFinal = std.clamp(flareFaded * flare_intensity, 0.0, 1.0);
|
|
72
|
+
|
|
73
|
+
const hslColor = RGBToHSL(color.xyz);
|
|
74
|
+
const lightness = std.clamp(hslColor.z + flareFinal, 0.0, 1.0);
|
|
75
|
+
const combined = HSLToRGB(d.vec3f(hslColor.xy, lightness));
|
|
76
|
+
// Final color with flare intensity, clamped to prevent oversaturation
|
|
77
|
+
// color = d.vec4f(std.mix(color.xyz, combined, glow), color.w);
|
|
78
|
+
return d.vec4f(combined, color.w);
|
|
79
|
+
});
|
|
@@ -2,95 +2,24 @@ import tgpu from 'typegpu';
|
|
|
2
2
|
import * as d from 'typegpu/data';
|
|
3
3
|
import * as std from 'typegpu/std';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
textureBindGroupLayout,
|
|
5
|
+
sharedBindGroupLayout,
|
|
7
6
|
glareBindGroupLayout,
|
|
8
|
-
// colorMaskBindGroupLayout,
|
|
9
7
|
} from '../bindGroupLayouts';
|
|
10
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
getPixelColorFromVector,
|
|
10
|
+
glareColorShift,
|
|
11
|
+
hueShift,
|
|
12
|
+
overlayChannels,
|
|
13
|
+
} from '../tgpuUtils';
|
|
11
14
|
|
|
12
15
|
export const glareFragment = tgpu['~unstable'].fragmentFn({
|
|
13
16
|
in: { uv: d.vec2f },
|
|
14
17
|
out: d.vec4f,
|
|
15
18
|
})((input) => {
|
|
16
|
-
const texcoord = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
17
|
-
const uv = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
18
|
-
const centeredCoords = std.sub(std.mul(uv, 2.0), 1); //-1 to 1
|
|
19
|
-
|
|
20
|
-
const rot = rotationBindGroupLayout.$.vec;
|
|
21
|
-
const center = std.add(d.vec2f(0.0), d.vec2f(rot.x, rot.y));
|
|
22
|
-
|
|
23
|
-
const glareOptions = glareBindGroupLayout.$.glareOptions;
|
|
24
|
-
const glareIntensity = glareOptions.glareIntensity;
|
|
25
|
-
const glowPower = glareOptions.glowPower;
|
|
26
|
-
const lightIntensity = glareOptions.lightIntensity;
|
|
27
|
-
|
|
28
|
-
const glareColor = glareOptions.glareColor;
|
|
29
|
-
const hueBlendPower = glareColor.hueBlendPower;
|
|
30
|
-
const hueShiftAngleMax = glareColor.hueShiftAngleMax;
|
|
31
|
-
const hueShiftAngleMin = glareColor.hueShiftAngleMin;
|
|
32
|
-
|
|
33
|
-
// const mask = colorMaskBindGroupLayout.$.mask;
|
|
34
|
-
// const maskedColor = mask.baseColor;
|
|
35
|
-
// const rgbToleranceRange = mask.rgbToleranceRange;
|
|
36
|
-
|
|
37
|
-
let color = std.textureSample(
|
|
38
|
-
textureBindGroupLayout.$.texture,
|
|
39
|
-
textureBindGroupLayout.$.sampler,
|
|
40
|
-
texcoord
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
// const maskedColorLower = std.sub(maskedColor, rgbToleranceRange.lower);
|
|
44
|
-
// const maskedColorUpper = std.add(maskedColor, rgbToleranceRange.upper);
|
|
45
|
-
// const upperCheck = std.all(std.le(color.xyz, maskedColorUpper));
|
|
46
|
-
// const lowerCheck = std.all(std.ge(color.xyz, maskedColorLower));
|
|
47
|
-
// if (upperCheck && lowerCheck) {
|
|
48
|
-
// return color;
|
|
49
|
-
// }
|
|
50
|
-
|
|
51
|
-
//glareIntensity
|
|
52
|
-
const dst = std.exp(-std.distance(center, centeredCoords));
|
|
53
|
-
const distToCenter = std.smoothstep(0.0, 1 / glareIntensity, dst);
|
|
54
|
-
|
|
55
|
-
//glowPower
|
|
56
|
-
let glow = d.vec3f(distToCenter);
|
|
57
|
-
glow = std.mul(glow, glowPower * color.w);
|
|
58
|
-
|
|
59
|
-
//hueBlend
|
|
60
|
-
const hueBlend = (d.f32(hueBlendPower) * dst) / 10.0;
|
|
61
|
-
|
|
62
|
-
//lightIntensity
|
|
63
|
-
glow = std.add(glow, lightIntensity / 10.0);
|
|
64
|
-
let shiftedRGB = glareColorShift(color.xyz, dst / (lightIntensity * 2));
|
|
65
|
-
|
|
66
|
-
//hueShiftAngleMin/Max
|
|
67
|
-
const hueShiftAngle = std.smoothstep(
|
|
68
|
-
hueShiftAngleMin,
|
|
69
|
-
hueShiftAngleMax,
|
|
70
|
-
distToCenter
|
|
71
|
-
);
|
|
72
|
-
const shiftedHue = hueShift(shiftedRGB, hueShiftAngle);
|
|
73
|
-
shiftedRGB = overlayChannels(shiftedRGB, shiftedHue);
|
|
74
|
-
|
|
75
|
-
color = d.vec4f(std.mix(color.xyz, shiftedRGB, hueBlend), color.w);
|
|
76
|
-
const baseColor = color;
|
|
77
|
-
const blendColor = glow;
|
|
78
|
-
|
|
79
|
-
const combined = overlayChannels(baseColor.xyz, blendColor);
|
|
80
|
-
color = d.vec4f(std.mix(color.xyz, combined, glow), color.w);
|
|
81
|
-
|
|
82
|
-
return color;
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
export const newGlareFragment = tgpu['~unstable'].fragmentFn({
|
|
86
|
-
in: { uv: d.vec2f },
|
|
87
|
-
out: d.vec4f,
|
|
88
|
-
})((input) => {
|
|
89
|
-
const texcoord = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
90
19
|
const uv = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
91
20
|
const centeredCoords = std.sub(std.mul(uv, 2.0), 1.0);
|
|
92
21
|
|
|
93
|
-
const rot =
|
|
22
|
+
const rot = sharedBindGroupLayout.$.rot;
|
|
94
23
|
const center = std.add(d.vec2f(0.0), d.vec2f(rot.x, rot.y)); // do not change
|
|
95
24
|
|
|
96
25
|
const opts = glareBindGroupLayout.$.glareOptions;
|
|
@@ -103,11 +32,7 @@ export const newGlareFragment = tgpu['~unstable'].fragmentFn({
|
|
|
103
32
|
const hueShiftAngleMin = glareColor.hueShiftAngleMin; // degrees
|
|
104
33
|
const hueShiftAngleMax = glareColor.hueShiftAngleMax; // degrees
|
|
105
34
|
|
|
106
|
-
let color =
|
|
107
|
-
textureBindGroupLayout.$.texture,
|
|
108
|
-
textureBindGroupLayout.$.sampler,
|
|
109
|
-
texcoord
|
|
110
|
-
);
|
|
35
|
+
let color = getPixelColorFromVector(uv);
|
|
111
36
|
|
|
112
37
|
const dist = std.distance(center, centeredCoords);
|
|
113
38
|
const radial = std.exp(-dist); // (0,1], steeper near center
|
|
@@ -2,24 +2,152 @@ import tgpu from 'typegpu';
|
|
|
2
2
|
import * as d from 'typegpu/data';
|
|
3
3
|
import * as std from 'typegpu/std';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
holoBindGroupLayout,
|
|
6
|
+
sharedBindGroupLayout,
|
|
7
7
|
} from '../bindGroupLayouts';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
getPixelColorFromVector,
|
|
10
|
+
hsvToRGB,
|
|
11
|
+
hueShift,
|
|
12
|
+
overlayChannels,
|
|
13
|
+
random,
|
|
14
|
+
} from '../tgpuUtils';
|
|
9
15
|
import { waveCallbackSlot } from '../../enums/waveCallback';
|
|
10
16
|
|
|
17
|
+
export const holo = tgpu.fn(
|
|
18
|
+
[d.vec2f, d.f32, d.f32, d.f32],
|
|
19
|
+
d.vec4f
|
|
20
|
+
)((uv, directionDegreeModifier, shiftModifier, rotationShiftPowerModifier) => {
|
|
21
|
+
const rot = sharedBindGroupLayout.$.rot;
|
|
22
|
+
|
|
23
|
+
const textureColor = getPixelColorFromVector(uv);
|
|
24
|
+
|
|
25
|
+
const directionDegree = std.add(
|
|
26
|
+
holoBindGroupLayout.$.holoOptions.directionDegree,
|
|
27
|
+
directionDegreeModifier
|
|
28
|
+
);
|
|
29
|
+
const shift = std.add(holoBindGroupLayout.$.holoOptions.shift, shiftModifier);
|
|
30
|
+
const rotationShiftPower = std.mul(
|
|
31
|
+
holoBindGroupLayout.$.holoOptions.rotationShiftPower,
|
|
32
|
+
rotationShiftPowerModifier
|
|
33
|
+
);
|
|
34
|
+
const holoSize = holoBindGroupLayout.$.holoOptions.holoSize;
|
|
35
|
+
const holoMultiplier = holoBindGroupLayout.$.holoOptions.holoMultiplier;
|
|
36
|
+
|
|
37
|
+
//todo: need to redo logic of this, it should base on the calcualted diff size not add additional width
|
|
38
|
+
const holoEaseSize = holoBindGroupLayout.$.holoOptions.holoEaseSize;
|
|
39
|
+
const holoVisibility = holoBindGroupLayout.$.holoOptions.holoVisibility;
|
|
40
|
+
const holoSaturation = holoBindGroupLayout.$.holoOptions.holoSaturation;
|
|
41
|
+
|
|
42
|
+
const angelDegrees = std.radians(
|
|
43
|
+
std.add(
|
|
44
|
+
holoBindGroupLayout.$.holoOptions.directionDegree,
|
|
45
|
+
directionDegreeModifier
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const yMultiplier = std.abs(std.cos(angelDegrees));
|
|
50
|
+
const xMultiplier = std.abs(std.sin(angelDegrees));
|
|
51
|
+
const range = std.add(xMultiplier, yMultiplier);
|
|
52
|
+
|
|
53
|
+
const intervalSize = std.div(range, holoMultiplier);
|
|
54
|
+
const x =
|
|
55
|
+
std.add(std.mul(uv.x, xMultiplier), std.mul(uv.y, yMultiplier)) + shift + 1; //scale to [0,2)
|
|
56
|
+
|
|
57
|
+
const rotationShift = std.add(
|
|
58
|
+
std.mul(rot.x, xMultiplier),
|
|
59
|
+
std.mul(rot.y, yMultiplier)
|
|
60
|
+
);
|
|
61
|
+
const shiftMultiplied = std.mul(rotationShift, rotationShiftPower);
|
|
62
|
+
const offset = shiftMultiplied + shift; //why is shitft here?
|
|
63
|
+
|
|
64
|
+
const xOffseted = (x + offset) % intervalSize;
|
|
65
|
+
const diffractionSizeCalculated = std.mul(holoSize, intervalSize);
|
|
66
|
+
const diffractionNoiseSizeCalcualted = std.mul(
|
|
67
|
+
diffractionSizeCalculated,
|
|
68
|
+
holoEaseSize
|
|
69
|
+
);
|
|
70
|
+
const diffractionStart = diffractionNoiseSizeCalcualted;
|
|
71
|
+
const diffractionEnd = std.add(diffractionSizeCalculated, diffractionStart);
|
|
72
|
+
|
|
73
|
+
const t =
|
|
74
|
+
(xOffseted - diffractionStart) / (diffractionEnd - diffractionStart);
|
|
75
|
+
const holoRotated = std.select(0, Math.PI, directionDegree > 179);
|
|
76
|
+
const ft = (1 - std.cos(Math.PI * t - holoRotated)) / 2;
|
|
77
|
+
const hue = -0.06 + ft * 0.85;
|
|
78
|
+
const hueWithNoise = std.add(std.div(random(uv.xy) - 0.5, 180) * 40, hue); //check with normal distribution
|
|
79
|
+
const missingRedHue = hueWithNoise + 1.0; // maps negative values to red from the end of hue
|
|
80
|
+
const rainbowAccurateHue = std.select(
|
|
81
|
+
missingRedHue,
|
|
82
|
+
hueWithNoise,
|
|
83
|
+
hueWithNoise > 0
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const boundaryCheck = std.any(
|
|
87
|
+
d.vec2b(xOffseted < diffractionStart, xOffseted > diffractionEnd)
|
|
88
|
+
);
|
|
89
|
+
const xBoundary = std.select(
|
|
90
|
+
diffractionStart - xOffseted,
|
|
91
|
+
xOffseted - diffractionEnd,
|
|
92
|
+
xOffseted > diffractionStart
|
|
93
|
+
);
|
|
94
|
+
const xBoundaryScalled = std.div(xBoundary, diffractionNoiseSizeCalcualted);
|
|
95
|
+
const boundaryVisibilityScalled = std.pow(xBoundaryScalled, 2);
|
|
96
|
+
const calculatedVisibility = std.clamp(
|
|
97
|
+
std.mix(
|
|
98
|
+
holoVisibility,
|
|
99
|
+
1,
|
|
100
|
+
boundaryVisibilityScalled * d.f32(boundaryCheck)
|
|
101
|
+
),
|
|
102
|
+
0,
|
|
103
|
+
1
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const shiftedRGB = hsvToRGB(d.vec3f(rainbowAccurateHue, holoSaturation, 1));
|
|
107
|
+
const vsibilityAdjustsed = std.mul(calculatedVisibility, textureColor.w);
|
|
108
|
+
return d.vec4f(shiftedRGB, vsibilityAdjustsed);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
export const doubleHoloFragment = tgpu['~unstable'].fragmentFn({
|
|
112
|
+
in: { uv: d.vec2f },
|
|
113
|
+
out: d.vec4f,
|
|
114
|
+
})((input) => {
|
|
115
|
+
const uv = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
116
|
+
const firstHolo = holo(uv, 0, 0, 1);
|
|
117
|
+
const secondHolo = holo(uv, 178, 0.59, -1);
|
|
118
|
+
const aa = std.add(firstHolo.w, secondHolo.w);
|
|
119
|
+
const vis = std.sub(2.0, aa);
|
|
120
|
+
const test = std.sub(1, vis);
|
|
121
|
+
const visibility = std.clamp(test, 0.9, 1);
|
|
122
|
+
const singleColor = std.select(firstHolo, secondHolo, secondHolo.w !== 1);
|
|
123
|
+
const addedColor = d.vec4f(
|
|
124
|
+
overlayChannels(firstHolo.xyz, secondHolo.xyz),
|
|
125
|
+
visibility
|
|
126
|
+
);
|
|
127
|
+
const finalColor = std.select(
|
|
128
|
+
singleColor,
|
|
129
|
+
addedColor,
|
|
130
|
+
std.all(d.vec2b(secondHolo.w !== 1, firstHolo.w !== 1))
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return finalColor;
|
|
134
|
+
});
|
|
135
|
+
|
|
11
136
|
export const holoFragment = tgpu['~unstable'].fragmentFn({
|
|
12
137
|
in: { uv: d.vec2f },
|
|
13
138
|
out: d.vec4f,
|
|
14
139
|
})((input) => {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
140
|
+
const uv = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
141
|
+
return holo(uv, 0, 0, 1);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
export const oldHoloFragment = tgpu['~unstable'].fragmentFn({
|
|
145
|
+
in: { uv: d.vec2f },
|
|
146
|
+
out: d.vec4f,
|
|
147
|
+
})((input) => {
|
|
148
|
+
const uv = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
149
|
+
const textureColor = getPixelColorFromVector(uv);
|
|
150
|
+
const rot = sharedBindGroupLayout.$.rot;
|
|
23
151
|
|
|
24
152
|
const wave = waveCallbackSlot.$(rot.xy);
|
|
25
153
|
const waveX = wave.x;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import tgpu from 'typegpu';
|
|
2
2
|
import * as d from 'typegpu/data';
|
|
3
3
|
import * as std from 'typegpu/std';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
maskTextureBindGroupLayout,
|
|
7
|
-
} from '../bindGroupLayouts';
|
|
4
|
+
import { maskTextureBindGroupLayout } from '../bindGroupLayouts';
|
|
5
|
+
import { getPixelColorFromVector } from '../tgpuUtils';
|
|
8
6
|
|
|
9
7
|
const maskFragment = tgpu['~unstable'].fragmentFn({
|
|
10
8
|
in: { uv: d.vec2f },
|
|
@@ -19,11 +17,7 @@ const maskFragment = tgpu['~unstable'].fragmentFn({
|
|
|
19
17
|
);
|
|
20
18
|
const reversedMask = d.vec4f(std.sub(1.0, mask.xyz), mask.w);
|
|
21
19
|
|
|
22
|
-
let color =
|
|
23
|
-
textureBindGroupLayout.$.texture,
|
|
24
|
-
textureBindGroupLayout.$.sampler,
|
|
25
|
-
texcoord
|
|
26
|
-
);
|
|
20
|
+
let color = getPixelColorFromVector(texcoord);
|
|
27
21
|
|
|
28
22
|
return d.vec4f(color.xyz, reversedMask.x);
|
|
29
23
|
});
|