react-native-shine 0.7.1 → 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 +112 -145
- package/lib/module/components/Content.js.map +1 -1
- package/lib/module/components/Shine.js +14 -5
- 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 +47 -29
- 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 +5 -5
- package/lib/module/shaders/computeShaders/precomputeColorMask.js.map +1 -1
- 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 +2 -61
- package/lib/module/shaders/pipelineSetups.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 +26 -155
- 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 +77 -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/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 +0 -6
- package/lib/typescript/src/shaders/pipelineSetups.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 +8 -47
- 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 +126 -296
- package/src/components/Shine.tsx +22 -5
- 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 +57 -28
- package/src/shaders/bindGroupUtils.ts +66 -69
- package/src/shaders/colorConversions.ts +88 -0
- package/src/shaders/computeShaders/precomputeColorMask.ts +4 -4
- 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 +2 -120
- 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 +39 -159
- package/src/types/types.ts +111 -60
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ColorMaskPreTypedSchema } from '../types/types';
|
|
2
|
+
|
|
3
|
+
export const GLARE_DEFAULTS = {
|
|
4
|
+
glowPower: 0.5,
|
|
5
|
+
glareIntensity: 0.4,
|
|
6
|
+
lightIntensity: 1.1,
|
|
7
|
+
glareColor: {
|
|
8
|
+
hueBlendPower: 1.0,
|
|
9
|
+
hueShiftAngleMin: -30,
|
|
10
|
+
hueShiftAngleMax: 30,
|
|
11
|
+
},
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
export const REVERSE_HOLO_DEFAULTS = {
|
|
15
|
+
redChannel: 1.0,
|
|
16
|
+
greenChannel: 0.0,
|
|
17
|
+
blueChannel: 0.0,
|
|
18
|
+
hue: 0.0,
|
|
19
|
+
saturation: 0.0,
|
|
20
|
+
value: 0.0,
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
export const HOLO_DEFAULTS = {
|
|
24
|
+
directionDegree: 45,
|
|
25
|
+
shift: 0.1,
|
|
26
|
+
rotationShiftPower: 0.6,
|
|
27
|
+
holoSize: 0.12,
|
|
28
|
+
holoMultiplier: 2.5,
|
|
29
|
+
holoEaseSize: 0.2,
|
|
30
|
+
holoVisibility: 0.88,
|
|
31
|
+
holoSaturation: 0.5,
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
export const GLARE_FLARE_DEFAULTS = {
|
|
35
|
+
flareIntensity: 0.7, // Overall intensity of the flare
|
|
36
|
+
spotIntensity: 0.4, // Intensity of the central spot
|
|
37
|
+
ringIntensity: 0.1, // Intensity of the rings
|
|
38
|
+
rayIntensity: 0.8, // Intensity of the rays
|
|
39
|
+
falloff: 8.0, // Falloff factor for rings and spots
|
|
40
|
+
rayCount: 4.0, // Number of rays
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const COLOR_MASK_DEFAULT_OPTIONS: ColorMaskPreTypedSchema = {
|
|
44
|
+
rgbToleranceRange: {
|
|
45
|
+
upper: [20, 20, 20],
|
|
46
|
+
lower: [20, 20, 20],
|
|
47
|
+
},
|
|
48
|
+
baseColor: [0, 0, 0],
|
|
49
|
+
hueMin: 0,
|
|
50
|
+
hueMax: 360,
|
|
51
|
+
saturationMin: 0.2,
|
|
52
|
+
saturationMax: 1,
|
|
53
|
+
lightnessMin: 0.3,
|
|
54
|
+
lightnessMax: 0.9,
|
|
55
|
+
debugMode: false,
|
|
56
|
+
useHSV: 0,
|
|
57
|
+
} as const;
|
|
@@ -1,11 +1,144 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
precomputeColorMaskBindGroupLayout,
|
|
3
|
+
type ColorMaskArraySchema,
|
|
4
|
+
} from './../shaders/bindGroupLayouts';
|
|
5
|
+
import {
|
|
6
|
+
glareFlareSchema,
|
|
7
|
+
glareSchema,
|
|
8
|
+
holoSchema,
|
|
9
|
+
reverseHoloDetectionChannelFlagsSchema,
|
|
10
|
+
} from '../shaders/bindGroupLayouts';
|
|
11
|
+
import {
|
|
12
|
+
createGlareBindGroup,
|
|
13
|
+
createGlareFlareBindGroup,
|
|
14
|
+
createHoloBindGroup,
|
|
15
|
+
createReverseHoloDetectionChannelFlagsBindGroup,
|
|
16
|
+
} from '../shaders/bindGroupUtils';
|
|
17
|
+
import {
|
|
18
|
+
createEffect,
|
|
19
|
+
type DeepPartial,
|
|
20
|
+
type ExtractEffectOptions,
|
|
21
|
+
type UnwrapLayout,
|
|
22
|
+
} from '../types/types';
|
|
23
|
+
import { glareFragment } from '../shaders/fragmentShaders/glareFragment';
|
|
24
|
+
import { reverseHoloFragment } from '../shaders/fragmentShaders/reverseHoloFragment';
|
|
25
|
+
import {
|
|
26
|
+
doubleHoloFragment,
|
|
27
|
+
holoFragment,
|
|
28
|
+
} from '../shaders/fragmentShaders/holoFragment';
|
|
29
|
+
import { glareFlareFragment } from '../shaders/fragmentShaders/glareFlareFragment';
|
|
30
|
+
import type {
|
|
31
|
+
StorageFlag,
|
|
32
|
+
TgpuBindGroup,
|
|
33
|
+
TgpuBuffer,
|
|
34
|
+
TgpuComputeFn,
|
|
35
|
+
TgpuRoot,
|
|
36
|
+
TgpuTexture,
|
|
37
|
+
UniformFlag,
|
|
38
|
+
ValidateUniformSchema,
|
|
39
|
+
} from 'typegpu';
|
|
40
|
+
import {
|
|
41
|
+
GLARE_DEFAULTS,
|
|
42
|
+
GLARE_FLARE_DEFAULTS,
|
|
43
|
+
HOLO_DEFAULTS,
|
|
44
|
+
REVERSE_HOLO_DEFAULTS,
|
|
45
|
+
} from './effectDefaults';
|
|
46
|
+
//TODO: move schema to separate object that would match them with corresponding bindGroups, then they would be defined in the effect
|
|
47
|
+
|
|
48
|
+
export const blend: GPUBlendState = {
|
|
49
|
+
color: {
|
|
50
|
+
srcFactor: 'one-minus-src-alpha',
|
|
51
|
+
dstFactor: 'src-alpha',
|
|
52
|
+
operation: 'add',
|
|
53
|
+
} satisfies GPUBlendComponent,
|
|
54
|
+
alpha: {
|
|
55
|
+
srcFactor: 'one-minus-src-alpha',
|
|
56
|
+
dstFactor: 'dst-alpha',
|
|
57
|
+
operation: 'add',
|
|
58
|
+
} satisfies GPUBlendComponent,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const GLARE = createEffect({
|
|
62
|
+
buffers: [
|
|
63
|
+
{
|
|
64
|
+
schema: glareSchema,
|
|
65
|
+
defaultOptions: GLARE_DEFAULTS,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
bindGroupCreator: createGlareBindGroup,
|
|
69
|
+
fragment: glareFragment,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const REVERSE_HOLO = createEffect({
|
|
73
|
+
buffers: [
|
|
74
|
+
{ schema: glareSchema, defaultOptions: GLARE_DEFAULTS },
|
|
75
|
+
{
|
|
76
|
+
schema: reverseHoloDetectionChannelFlagsSchema,
|
|
77
|
+
defaultOptions: REVERSE_HOLO_DEFAULTS,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
fragment: reverseHoloFragment,
|
|
81
|
+
bindGroupCreator: createReverseHoloDetectionChannelFlagsBindGroup,
|
|
82
|
+
blend,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const HOLO = createEffect({
|
|
86
|
+
fragment: holoFragment,
|
|
87
|
+
buffers: [
|
|
88
|
+
{
|
|
89
|
+
schema: holoSchema,
|
|
90
|
+
defaultOptions: HOLO_DEFAULTS,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
bindGroupCreator: createHoloBindGroup,
|
|
94
|
+
blend,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const DOUBLE_HOLO = { ...HOLO, fragment: doubleHoloFragment };
|
|
98
|
+
|
|
99
|
+
const GLARE_FLARE = createEffect({
|
|
100
|
+
fragment: glareFlareFragment,
|
|
101
|
+
buffers: [
|
|
102
|
+
{
|
|
103
|
+
schema: glareFlareSchema,
|
|
104
|
+
defaultOptions: GLARE_FLARE_DEFAULTS,
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
bindGroupCreator: createGlareFlareBindGroup,
|
|
108
|
+
});
|
|
2
109
|
|
|
3
110
|
export const Effects = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
111
|
+
glare: GLARE,
|
|
112
|
+
reverseHolo: REVERSE_HOLO,
|
|
113
|
+
holo: HOLO,
|
|
114
|
+
doubleHolo: DOUBLE_HOLO,
|
|
115
|
+
glareFlare: GLARE_FLARE,
|
|
116
|
+
} as const; //todo: add forced typings
|
|
117
|
+
|
|
118
|
+
export type Effect = {
|
|
119
|
+
[K in keyof typeof Effects]: {
|
|
120
|
+
name: K;
|
|
121
|
+
options?: DeepPartial<ExtractEffectOptions<(typeof Effects)[K]>>;
|
|
122
|
+
};
|
|
123
|
+
}[keyof typeof Effects];
|
|
124
|
+
export type ComputePipelineInput = {
|
|
125
|
+
compute: TgpuComputeFn;
|
|
126
|
+
buffers: {
|
|
127
|
+
schema: ValidateUniformSchema<any>;
|
|
128
|
+
defaultOptions: any;
|
|
129
|
+
}[];
|
|
130
|
+
storageTexture: TgpuTexture<{
|
|
131
|
+
format: 'rgba8unorm';
|
|
132
|
+
size: readonly number[];
|
|
133
|
+
}> &
|
|
134
|
+
StorageFlag;
|
|
135
|
+
bindGroupCreator: (
|
|
136
|
+
root: TgpuRoot,
|
|
137
|
+
storageTexture: TgpuTexture<{
|
|
138
|
+
format: 'rgba8unorm';
|
|
139
|
+
size: readonly number[];
|
|
140
|
+
}> &
|
|
141
|
+
StorageFlag,
|
|
142
|
+
colorMaskBuffer: TgpuBuffer<ColorMaskArraySchema> & UniformFlag
|
|
143
|
+
) => TgpuBindGroup<UnwrapLayout<typeof precomputeColorMaskBindGroupLayout>>;
|
|
144
|
+
};
|
|
@@ -2,9 +2,12 @@ import tgpu, { type ValidateBufferSchema } from 'typegpu';
|
|
|
2
2
|
import * as d from 'typegpu/data';
|
|
3
3
|
import type { BufferUsageType } from './resourceManagement/bufferManager';
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const rotationSchema = d.vec3f;
|
|
6
|
+
|
|
7
|
+
export const sharedBindGroupLayout = tgpu.bindGroupLayout({
|
|
6
8
|
texture: { texture: d.texture2d(d.f32) },
|
|
7
9
|
sampler: { sampler: 'filtering' },
|
|
10
|
+
rot: { uniform: rotationSchema },
|
|
8
11
|
});
|
|
9
12
|
|
|
10
13
|
export const maskTextureBindGroupLayout = tgpu.bindGroupLayout({
|
|
@@ -12,10 +15,6 @@ export const maskTextureBindGroupLayout = tgpu.bindGroupLayout({
|
|
|
12
15
|
sampler: { sampler: 'filtering' },
|
|
13
16
|
});
|
|
14
17
|
|
|
15
|
-
export const rotationBindGroupLayout = tgpu.bindGroupLayout({
|
|
16
|
-
vec: { uniform: d.vec3f },
|
|
17
|
-
});
|
|
18
|
-
|
|
19
18
|
export const glareSchema = d.struct({
|
|
20
19
|
glareColor: d.struct({
|
|
21
20
|
hueShiftAngleMax: d.f32,
|
|
@@ -40,21 +39,17 @@ export const colorMaskSchema = d.struct({
|
|
|
40
39
|
upper: d.vec3f,
|
|
41
40
|
lower: d.vec3f,
|
|
42
41
|
}),
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
lower: d.f32,
|
|
46
|
-
}),
|
|
42
|
+
hueStart: d.f32,
|
|
43
|
+
hueRange: d.f32,
|
|
47
44
|
useHSV: d.align(16, d.u32),
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
lowSaturationThreshold: d.f32,
|
|
51
|
-
lowBrightnessThreshold: d.f32,
|
|
45
|
+
minLimits: d.vec2f,
|
|
46
|
+
maxLimits: d.vec2f,
|
|
52
47
|
debugMode: d.u32,
|
|
53
48
|
});
|
|
54
49
|
|
|
55
|
-
export type ColorMaskSchema = typeof colorMaskSchema
|
|
50
|
+
export type ColorMaskSchema = d.Infer<typeof colorMaskSchema>;
|
|
56
51
|
|
|
57
|
-
export const COLOR_MASK_MAX_COUNT =
|
|
52
|
+
export const COLOR_MASK_MAX_COUNT = 8;
|
|
58
53
|
|
|
59
54
|
export const colorMaskArraySchema = d.struct({
|
|
60
55
|
masks: d.arrayOf(colorMaskSchema, COLOR_MASK_MAX_COUNT),
|
|
@@ -86,9 +81,54 @@ export const reverseHoloDetectionChannelFlagsBindGroupLayout =
|
|
|
86
81
|
glareOptions: { uniform: glareSchema },
|
|
87
82
|
});
|
|
88
83
|
|
|
84
|
+
export const holoSchema = d.struct({
|
|
85
|
+
directionDegree: d.align(16, d.f32),
|
|
86
|
+
shift: d.f32,
|
|
87
|
+
rotationShiftPower: d.f32,
|
|
88
|
+
holoSize: d.f32,
|
|
89
|
+
holoMultiplier: d.f32,
|
|
90
|
+
holoEaseSize: d.f32,
|
|
91
|
+
holoVisibility: d.f32,
|
|
92
|
+
holoSaturation: d.f32,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export type HoloSchema = typeof holoSchema;
|
|
96
|
+
|
|
97
|
+
export const holoBindGroupLayout = tgpu.bindGroupLayout({
|
|
98
|
+
holoOptions: { uniform: holoSchema },
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export const glareFlareSchema = d.struct({
|
|
102
|
+
flareIntensity: d.f32,
|
|
103
|
+
spotIntensity: d.f32,
|
|
104
|
+
ringIntensity: d.f32,
|
|
105
|
+
rayIntensity: d.f32,
|
|
106
|
+
falloff: d.f32,
|
|
107
|
+
rayCount: d.f32,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
export type glareFlareSchema = typeof glareFlareSchema;
|
|
111
|
+
|
|
112
|
+
export const glareFlareBindGroupLayout = tgpu.bindGroupLayout({
|
|
113
|
+
glareFlare: { uniform: glareFlareSchema },
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export const precomputeTextureSchema = d.textureStorage2d(
|
|
117
|
+
'rgba8unorm',
|
|
118
|
+
'read-write'
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
export type PrecomputeTextureSchema = typeof precomputeTextureSchema;
|
|
122
|
+
|
|
89
123
|
export const precomputeColorMaskBindGroupLayout = tgpu.bindGroupLayout({
|
|
90
|
-
|
|
91
|
-
storageTexture:
|
|
124
|
+
colorMaskStorage: {
|
|
125
|
+
storageTexture: precomputeTextureSchema,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export const precomputeColorMaskOutputBindGroupLayout = tgpu.bindGroupLayout({
|
|
130
|
+
colorMaskOutput: {
|
|
131
|
+
texture: d.texture2d(d.f32),
|
|
92
132
|
},
|
|
93
133
|
});
|
|
94
134
|
|
|
@@ -121,14 +161,3 @@ export const bufferData = {
|
|
|
121
161
|
>;
|
|
122
162
|
|
|
123
163
|
export type BufferData = typeof bufferData;
|
|
124
|
-
|
|
125
|
-
// export const holoSchema = d.struct({
|
|
126
|
-
// intensity: d.f32,
|
|
127
|
-
// waveCallback: WaveCallback, //TgpuFn<(uv: d.Vec2f) => d.Vec2f>,
|
|
128
|
-
// });
|
|
129
|
-
|
|
130
|
-
// export type holoSchema = typeof holoSchema;
|
|
131
|
-
|
|
132
|
-
// export const holoBindGroupLayout = tgpu.bindGroupLayout({
|
|
133
|
-
// holoOptions: { uniform: holoSchema },
|
|
134
|
-
// });
|
|
@@ -1,61 +1,53 @@
|
|
|
1
|
-
import { type TgpuBuffer, type TgpuRoot, type UniformFlag } from 'typegpu';
|
|
2
|
-
import * as d from 'typegpu/data';
|
|
3
1
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
type StorageFlag,
|
|
3
|
+
type TgpuBuffer,
|
|
4
|
+
type TgpuRoot,
|
|
5
|
+
type TgpuTexture,
|
|
6
|
+
type UniformFlag,
|
|
7
|
+
} from 'typegpu';
|
|
8
|
+
import {
|
|
6
9
|
colorMaskBindGroupLayout,
|
|
7
|
-
rotationBindGroupLayout,
|
|
8
10
|
type GlareSchema,
|
|
9
11
|
type ReverseHoloDetectionChannelFlagsSchema,
|
|
10
12
|
reverseHoloDetectionChannelFlagsBindGroupLayout,
|
|
11
13
|
type ColorMaskArraySchema,
|
|
14
|
+
glareBindGroupLayout,
|
|
15
|
+
holoBindGroupLayout,
|
|
16
|
+
type HoloSchema,
|
|
17
|
+
glareFlareSchema,
|
|
18
|
+
glareFlareBindGroupLayout,
|
|
19
|
+
precomputeColorMaskBindGroupLayout,
|
|
12
20
|
} from './bindGroupLayouts';
|
|
13
|
-
import type {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export const createRotationBuffer = (root: TgpuRoot, initValues = zeroV3d) =>
|
|
18
|
-
root
|
|
19
|
-
.createBuffer(d.vec3f, d.vec3f(...componentsFromV3d(initValues)))
|
|
20
|
-
.$usage('uniform');
|
|
21
|
-
|
|
22
|
-
export const createRotationValuesBindGroup = (
|
|
23
|
-
root: TgpuRoot,
|
|
24
|
-
buffer: TgpuBuffer<d.Vec3f>
|
|
25
|
-
) =>
|
|
26
|
-
root.createBindGroup(rotationBindGroupLayout, {
|
|
27
|
-
vec: root.unwrap(buffer),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
export const createGlareOptionsBuffer = (
|
|
31
|
-
root: TgpuRoot,
|
|
32
|
-
initValues?: Partial<GlareOptions>
|
|
33
|
-
) =>
|
|
34
|
-
root
|
|
35
|
-
.createBuffer(
|
|
36
|
-
glareSchema,
|
|
37
|
-
glareOptionsToTyped(createGlareOptions({ ...initValues }))
|
|
38
|
-
)
|
|
39
|
-
.$usage('uniform');
|
|
21
|
+
import type {
|
|
22
|
+
BindGroupCreatorArgument,
|
|
23
|
+
TgpuUniformBuffer,
|
|
24
|
+
} from '../types/types';
|
|
40
25
|
|
|
41
26
|
export const createGlareBindGroup = (
|
|
42
|
-
root:
|
|
43
|
-
buffer:
|
|
44
|
-
) =>
|
|
27
|
+
{ root }: BindGroupCreatorArgument,
|
|
28
|
+
[buffer]: readonly [buffer: TgpuUniformBuffer<GlareSchema>]
|
|
29
|
+
) => [
|
|
45
30
|
root.createBindGroup(glareBindGroupLayout, {
|
|
46
31
|
glareOptions: buffer,
|
|
47
|
-
})
|
|
32
|
+
}),
|
|
33
|
+
];
|
|
48
34
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
35
|
+
export const createReverseHoloDetectionChannelFlagsBindGroup = (
|
|
36
|
+
{ root, maskBindGroup }: BindGroupCreatorArgument,
|
|
37
|
+
[glareOptions, channelFlags]: readonly [
|
|
38
|
+
g: TgpuUniformBuffer<GlareSchema>,
|
|
39
|
+
f: TgpuUniformBuffer<ReverseHoloDetectionChannelFlagsSchema>,
|
|
40
|
+
]
|
|
41
|
+
) => {
|
|
42
|
+
const reverseHoloBindGroup = root.createBindGroup(
|
|
43
|
+
reverseHoloDetectionChannelFlagsBindGroupLayout,
|
|
44
|
+
{
|
|
45
|
+
channelFlags,
|
|
46
|
+
glareOptions,
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
return [reverseHoloBindGroup, maskBindGroup];
|
|
50
|
+
};
|
|
59
51
|
|
|
60
52
|
export const createColorMaskBindGroup = (
|
|
61
53
|
root: TgpuRoot,
|
|
@@ -65,28 +57,33 @@ export const createColorMaskBindGroup = (
|
|
|
65
57
|
colorMasks: buffer,
|
|
66
58
|
});
|
|
67
59
|
|
|
68
|
-
export const
|
|
69
|
-
root:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
glareOptions: glareOptionsBuffer,
|
|
77
|
-
});
|
|
60
|
+
export const createHoloBindGroup = (
|
|
61
|
+
{ root }: BindGroupCreatorArgument,
|
|
62
|
+
[buffer]: readonly [buffer: TgpuUniformBuffer<HoloSchema>]
|
|
63
|
+
) => [
|
|
64
|
+
root.createBindGroup(holoBindGroupLayout, {
|
|
65
|
+
holoOptions: buffer,
|
|
66
|
+
}),
|
|
67
|
+
];
|
|
78
68
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// };
|
|
69
|
+
export const createGlareFlareBindGroup = (
|
|
70
|
+
{ root }: BindGroupCreatorArgument,
|
|
71
|
+
[buffer]: readonly [buffer: TgpuUniformBuffer<glareFlareSchema>]
|
|
72
|
+
) => [
|
|
73
|
+
root.createBindGroup(glareFlareBindGroupLayout, {
|
|
74
|
+
glareFlare: buffer,
|
|
75
|
+
}),
|
|
76
|
+
];
|
|
88
77
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
78
|
+
export const createPrecomputeColorMaskBindGroup = (
|
|
79
|
+
root: TgpuRoot,
|
|
80
|
+
storageTexture: TgpuTexture<{
|
|
81
|
+
format: 'rgba8unorm';
|
|
82
|
+
size: readonly number[];
|
|
83
|
+
}> &
|
|
84
|
+
StorageFlag
|
|
85
|
+
) => {
|
|
86
|
+
return root.createBindGroup(precomputeColorMaskBindGroupLayout, {
|
|
87
|
+
colorMaskStorage: storageTexture,
|
|
88
|
+
});
|
|
89
|
+
};
|
|
@@ -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
|
+
});
|
|
@@ -3,7 +3,7 @@ import * as d from 'typegpu/data';
|
|
|
3
3
|
import * as std from 'typegpu/std';
|
|
4
4
|
import {
|
|
5
5
|
precomputeColorMaskBindGroupLayout,
|
|
6
|
-
|
|
6
|
+
sharedBindGroupLayout,
|
|
7
7
|
} from './../bindGroupLayouts';
|
|
8
8
|
|
|
9
9
|
export const precomputeColorMask = tgpu['~unstable'].computeFn({
|
|
@@ -13,15 +13,15 @@ export const precomputeColorMask = tgpu['~unstable'].computeFn({
|
|
|
13
13
|
const x = input.gid.x;
|
|
14
14
|
const y = input.gid.y;
|
|
15
15
|
const colorMaskStorageTexture =
|
|
16
|
-
precomputeColorMaskBindGroupLayout.$.
|
|
16
|
+
precomputeColorMaskBindGroupLayout.$.colorMaskStorage;
|
|
17
17
|
const size = std.textureDimensions(colorMaskStorageTexture);
|
|
18
18
|
|
|
19
19
|
if (x >= size.x || y >= size.y) return;
|
|
20
20
|
const uv = d.vec2f(d.f32(x) / d.f32(size.x), d.f32(y) / d.f32(size.y));
|
|
21
21
|
|
|
22
22
|
const colorSampled = std.textureSample(
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
sharedBindGroupLayout.$.texture,
|
|
24
|
+
sharedBindGroupLayout.$.sampler,
|
|
25
25
|
uv
|
|
26
26
|
);
|
|
27
27
|
|
|
@@ -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
|
});
|