react-native-shine 0.3.0 → 0.3.2
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/README.md +21 -6
- package/lib/module/components/Content.js +232 -0
- package/lib/module/components/Content.js.map +1 -0
- package/lib/module/components/Shine.js +18 -254
- package/lib/module/components/Shine.js.map +1 -1
- package/lib/module/components/ShineGroup.js +11 -23
- package/lib/module/components/ShineGroup.js.map +1 -1
- package/lib/module/hooks/useAnimationFrame.js +17 -0
- package/lib/module/hooks/useAnimationFrame.js.map +1 -0
- package/lib/module/hooks/useOrientation.js +2 -8
- package/lib/module/hooks/useOrientation.js.map +1 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/shaders/bindGroupLayouts.js +8 -8
- package/lib/module/shaders/bindGroupLayouts.js.map +1 -1
- package/lib/module/shaders/bindGroupUtils.js +18 -40
- package/lib/module/shaders/bindGroupUtils.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/glareFragment.js +8 -7
- package/lib/module/shaders/fragmentShaders/glareFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/holoFragment.js +5 -10
- package/lib/module/shaders/fragmentShaders/holoFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js +3 -3
- package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js.map +1 -1
- package/lib/module/shaders/pipelineSetups.js +29 -43
- package/lib/module/shaders/pipelineSetups.js.map +1 -1
- package/lib/module/shaders/resourceManagement/textures.js +7 -0
- package/lib/module/shaders/resourceManagement/textures.js.map +1 -1
- package/lib/module/shaders/utils.js +8 -22
- package/lib/module/shaders/utils.js.map +1 -1
- package/lib/module/shaders/vertexShaders/mainRotationEffectVertex.js +2 -2
- package/lib/module/shaders/vertexShaders/mainRotationEffectVertex.js.map +1 -1
- package/lib/module/types/size.js +2 -0
- package/lib/module/types/size.js.map +1 -0
- package/lib/module/types/typeUtils.js +0 -14
- package/lib/module/types/typeUtils.js.map +1 -1
- package/lib/module/types/vector.js +2 -0
- package/lib/module/types/vector.js.map +1 -0
- package/lib/module/utils/size.js +25 -0
- package/lib/module/utils/size.js.map +1 -0
- package/lib/module/utils/vector.js +168 -0
- package/lib/module/utils/vector.js.map +1 -0
- package/lib/typescript/src/components/Content.d.ts +23 -0
- package/lib/typescript/src/components/Content.d.ts.map +1 -0
- package/lib/typescript/src/components/Shine.d.ts +3 -13
- package/lib/typescript/src/components/Shine.d.ts.map +1 -1
- package/lib/typescript/src/components/ShineGroup.d.ts +3 -5
- package/lib/typescript/src/components/ShineGroup.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useAnimationFrame.d.ts +2 -0
- package/lib/typescript/src/hooks/useAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useOrientation.d.ts +3 -1
- package/lib/typescript/src/hooks/useOrientation.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +4 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/shaders/bindGroupLayouts.d.ts +9 -9
- package/lib/typescript/src/shaders/bindGroupLayouts.d.ts.map +1 -1
- package/lib/typescript/src/shaders/bindGroupUtils.d.ts +3 -3
- package/lib/typescript/src/shaders/bindGroupUtils.d.ts.map +1 -1
- package/lib/typescript/src/shaders/fragmentShaders/glareFragment.d.ts.map +1 -1
- package/lib/typescript/src/shaders/fragmentShaders/holoFragment.d.ts.map +1 -1
- package/lib/typescript/src/shaders/pipelineSetups.d.ts +7 -7
- package/lib/typescript/src/shaders/pipelineSetups.d.ts.map +1 -1
- package/lib/typescript/src/shaders/resourceManagement/textures.d.ts +2 -1
- package/lib/typescript/src/shaders/resourceManagement/textures.d.ts.map +1 -1
- package/lib/typescript/src/shaders/utils.d.ts +3 -4
- package/lib/typescript/src/shaders/utils.d.ts.map +1 -1
- package/lib/typescript/src/types/size.d.ts +5 -0
- package/lib/typescript/src/types/size.d.ts.map +1 -0
- package/lib/typescript/src/types/typeUtils.d.ts +1 -4
- package/lib/typescript/src/types/typeUtils.d.ts.map +1 -1
- package/lib/typescript/src/types/types.d.ts +3 -1
- package/lib/typescript/src/types/types.d.ts.map +1 -1
- package/lib/typescript/src/types/vector.d.ts +11 -0
- package/lib/typescript/src/types/vector.d.ts.map +1 -0
- package/lib/typescript/src/utils/size.d.ts +5 -0
- package/lib/typescript/src/utils/size.d.ts.map +1 -0
- package/lib/typescript/src/utils/vector.d.ts +33 -0
- package/lib/typescript/src/utils/vector.d.ts.map +1 -0
- package/package.json +8 -7
- package/src/components/Content.tsx +403 -0
- package/src/components/Shine.tsx +24 -466
- package/src/components/ShineGroup.tsx +17 -24
- package/src/hooks/useAnimationFrame.ts +21 -0
- package/src/hooks/useOrientation.ts +11 -13
- package/src/index.tsx +9 -1
- package/src/shaders/bindGroupLayouts.ts +11 -11
- package/src/shaders/bindGroupUtils.ts +31 -61
- package/src/shaders/fragmentShaders/glareFragment.ts +8 -7
- package/src/shaders/fragmentShaders/holoFragment.ts +5 -13
- package/src/shaders/fragmentShaders/reverseHoloFragment.ts +4 -4
- package/src/shaders/pipelineSetups.ts +54 -69
- package/src/shaders/resourceManagement/textures.ts +13 -1
- package/src/shaders/utils.ts +13 -27
- package/src/shaders/vertexShaders/mainRotationEffectVertex.ts +2 -2
- package/src/types/size.ts +4 -0
- package/src/types/typeUtils.ts +0 -28
- package/src/types/types.ts +11 -1
- package/src/types/vector.ts +13 -0
- package/src/utils/size.ts +12 -0
- package/src/utils/vector.ts +132 -0
|
@@ -12,11 +12,11 @@ export const maskTextureBindGroupLayout = tgpu.bindGroupLayout({
|
|
|
12
12
|
sampler: { sampler: 'filtering' },
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
export const
|
|
15
|
+
export const rotationBindGroupLayout = tgpu.bindGroupLayout({
|
|
16
16
|
vec: { uniform: d.vec3f },
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
export const
|
|
19
|
+
export const glareSchema = d.struct({
|
|
20
20
|
glowPower: d.f32,
|
|
21
21
|
hueShiftAngleMax: d.f32,
|
|
22
22
|
hueShiftAngleMin: d.f32,
|
|
@@ -25,10 +25,10 @@ export const glareOptionsSchema = d.struct({
|
|
|
25
25
|
glareIntensity: d.f32,
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
export type
|
|
28
|
+
export type GlareSchema = typeof glareSchema;
|
|
29
29
|
|
|
30
|
-
export const
|
|
31
|
-
glareOptions: { uniform:
|
|
30
|
+
export const glareBindGroupLayout = tgpu.bindGroupLayout({
|
|
31
|
+
glareOptions: { uniform: glareSchema },
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
export const colorMaskSchema = d.struct({
|
|
@@ -39,22 +39,22 @@ export const colorMaskSchema = d.struct({
|
|
|
39
39
|
}),
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
export type
|
|
42
|
+
export type ColorMaskSchema = typeof colorMaskSchema;
|
|
43
43
|
|
|
44
44
|
export const colorMaskBindGroupLayout = tgpu.bindGroupLayout({
|
|
45
45
|
mask: { uniform: colorMaskSchema },
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
export const bufferData = {
|
|
49
|
-
|
|
49
|
+
rotation: {
|
|
50
50
|
schema: d.vec3f,
|
|
51
51
|
usage: 'uniform',
|
|
52
52
|
},
|
|
53
|
-
|
|
54
|
-
schema:
|
|
53
|
+
glare: {
|
|
54
|
+
schema: glareSchema,
|
|
55
55
|
usage: 'uniform',
|
|
56
56
|
},
|
|
57
|
-
|
|
57
|
+
colorMask: {
|
|
58
58
|
schema: colorMaskSchema,
|
|
59
59
|
usage: 'uniform',
|
|
60
60
|
},
|
|
@@ -63,7 +63,7 @@ export const bufferData = {
|
|
|
63
63
|
{ schema: ValidateBufferSchema<any>; usage: BufferUsageType }
|
|
64
64
|
>;
|
|
65
65
|
|
|
66
|
-
export type
|
|
66
|
+
export type BufferData = typeof bufferData;
|
|
67
67
|
|
|
68
68
|
// export const holoSchema = d.struct({
|
|
69
69
|
// intensity: d.f32,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type TgpuBuffer, type TgpuRoot, type UniformFlag } from 'typegpu';
|
|
2
2
|
import * as d from 'typegpu/data';
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
glareBindGroupLayout,
|
|
5
|
+
glareSchema,
|
|
6
6
|
colorMaskBindGroupLayout,
|
|
7
|
+
type ColorMaskSchema,
|
|
8
|
+
rotationBindGroupLayout,
|
|
9
|
+
type GlareSchema,
|
|
7
10
|
colorMaskSchema,
|
|
8
|
-
rotationValuesBindGroupLayout,
|
|
9
11
|
} from './bindGroupLayouts';
|
|
10
12
|
import type {
|
|
11
13
|
GlareOptions,
|
|
@@ -18,88 +20,56 @@ import {
|
|
|
18
20
|
createColorMask,
|
|
19
21
|
mapToF32,
|
|
20
22
|
} from '../types/typeUtils';
|
|
23
|
+
import { componentsFromV3d, zeroV3d } from '../utils/vector';
|
|
21
24
|
|
|
22
|
-
export const createRotationBuffer = (
|
|
23
|
-
root
|
|
24
|
-
|
|
25
|
-
) => {
|
|
26
|
-
const init = initValues
|
|
27
|
-
? d.vec3f(initValues.x, initValues.y, initValues.z)
|
|
28
|
-
: d.vec3f(0.0);
|
|
29
|
-
const rotationValuesBuffer = root
|
|
30
|
-
.createBuffer(d.vec3f, init)
|
|
25
|
+
export const createRotationBuffer = (root: TgpuRoot, initValues = zeroV3d) =>
|
|
26
|
+
root
|
|
27
|
+
.createBuffer(d.vec3f, d.vec3f(...componentsFromV3d(initValues)))
|
|
31
28
|
.$usage('uniform');
|
|
32
29
|
|
|
33
|
-
return rotationValuesBuffer;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
30
|
export const createRotationValuesBindGroup = (
|
|
37
31
|
root: TgpuRoot,
|
|
38
32
|
buffer: TgpuBuffer<d.Vec3f>
|
|
39
|
-
) =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
vec: root.unwrap(buffer),
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
return rotationValuesBindGroup;
|
|
48
|
-
};
|
|
33
|
+
) =>
|
|
34
|
+
root.createBindGroup(rotationBindGroupLayout, {
|
|
35
|
+
vec: root.unwrap(buffer),
|
|
36
|
+
});
|
|
49
37
|
|
|
50
38
|
export const createGlareOptionsBuffer = (
|
|
51
39
|
root: TgpuRoot,
|
|
52
40
|
initValues?: Partial<GlareOptions>
|
|
53
|
-
) =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const glareOptionsBuffer = root
|
|
58
|
-
.createBuffer(glareOptionsSchema, glareOptionsTyped)
|
|
41
|
+
) =>
|
|
42
|
+
root
|
|
43
|
+
.createBuffer(glareSchema, mapToF32(createGlareOptions({ ...initValues })))
|
|
59
44
|
.$usage('uniform');
|
|
60
45
|
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const createGlareOptionsBindGroup = (
|
|
46
|
+
export const createGlareBindGroup = (
|
|
65
47
|
root: TgpuRoot,
|
|
66
|
-
buffer: TgpuBuffer<
|
|
67
|
-
) =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
glareOptions: buffer,
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
return glareOptionsBindGroup;
|
|
76
|
-
};
|
|
48
|
+
buffer: TgpuBuffer<GlareSchema> & UniformFlag
|
|
49
|
+
) =>
|
|
50
|
+
root.createBindGroup(glareBindGroupLayout, {
|
|
51
|
+
glareOptions: buffer,
|
|
52
|
+
});
|
|
77
53
|
|
|
78
54
|
export const createColorMaskBuffer = (
|
|
79
55
|
root: TgpuRoot,
|
|
80
56
|
initValues: PartiallyOptional<ColorMask, 'baseColor'>
|
|
81
|
-
) =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
57
|
+
) =>
|
|
58
|
+
root
|
|
59
|
+
.createBuffer(
|
|
60
|
+
colorMaskSchema,
|
|
61
|
+
colorMaskToTyped(createColorMask({ ...initValues }))
|
|
62
|
+
)
|
|
87
63
|
.$usage('uniform');
|
|
88
64
|
|
|
89
|
-
return colorMaskBuffer;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
65
|
export const createColorMaskBindGroup = (
|
|
93
66
|
root: TgpuRoot,
|
|
94
|
-
buffer: TgpuBuffer<
|
|
95
|
-
) =>
|
|
96
|
-
|
|
67
|
+
buffer: TgpuBuffer<ColorMaskSchema> & UniformFlag
|
|
68
|
+
) =>
|
|
69
|
+
root.createBindGroup(colorMaskBindGroupLayout, {
|
|
97
70
|
mask: buffer,
|
|
98
71
|
});
|
|
99
72
|
|
|
100
|
-
return colorMaskBindGroup;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
73
|
// export const crateHoloBuffer = (
|
|
104
74
|
// root: TgpuRoot,
|
|
105
75
|
// initValues: Partial<HoloOptions>
|
|
@@ -2,9 +2,9 @@ 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
|
+
rotationBindGroupLayout,
|
|
6
6
|
textureBindGroupLayout,
|
|
7
|
-
|
|
7
|
+
glareBindGroupLayout,
|
|
8
8
|
// colorMaskBindGroupLayout,
|
|
9
9
|
} from '../bindGroupLayouts';
|
|
10
10
|
import { glareColorShift, hueShift, overlayChannels } from '../tgpuUtils';
|
|
@@ -17,10 +17,10 @@ export const glareFragment = tgpu['~unstable'].fragmentFn({
|
|
|
17
17
|
const uv = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
18
18
|
const centeredCoords = std.sub(std.mul(uv, 2.0), 1); //-1 to 1
|
|
19
19
|
|
|
20
|
-
const rot =
|
|
20
|
+
const rot = rotationBindGroupLayout.$.vec;
|
|
21
21
|
const center = std.add(d.vec2f(0.0), d.vec2f(rot.x, rot.y));
|
|
22
22
|
|
|
23
|
-
const glareOptions =
|
|
23
|
+
const glareOptions = glareBindGroupLayout.$.glareOptions;
|
|
24
24
|
const glareIntensity = glareOptions.glareIntensity;
|
|
25
25
|
const glowPower = glareOptions.glowPower;
|
|
26
26
|
const hueBlendPower = glareOptions.hueBlendPower;
|
|
@@ -88,10 +88,10 @@ export const newGlareFragment = tgpu['~unstable'].fragmentFn({
|
|
|
88
88
|
const uv = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
89
89
|
const centeredCoords = std.sub(std.mul(uv, 2.0), 1.0);
|
|
90
90
|
|
|
91
|
-
const rot =
|
|
91
|
+
const rot = rotationBindGroupLayout.$.vec;
|
|
92
92
|
const center = std.add(d.vec2f(0.0), d.vec2f(rot.x, rot.y)); // do not change
|
|
93
93
|
|
|
94
|
-
const opts =
|
|
94
|
+
const opts = glareBindGroupLayout.$.glareOptions;
|
|
95
95
|
const glareIntensity = opts.glareIntensity; // [0..∞): bigger → wider/stronger area
|
|
96
96
|
const glowPower = opts.glowPower; // (0..∞): curve shaping; bigger → softer/wider glow
|
|
97
97
|
const hueBlendPower = opts.hueBlendPower; // [0..1+]: how much hue-shifted color blends in
|
|
@@ -135,8 +135,9 @@ export const newGlareFragment = tgpu['~unstable'].fragmentFn({
|
|
|
135
135
|
const overlaidRGB = overlayChannels(chromaMixed, glareLayer);
|
|
136
136
|
const finalRGB = std.mix(chromaMixed, overlaidRGB, d.vec3f(maskedGlow));
|
|
137
137
|
|
|
138
|
-
// Optional mild safety clamp to avoid NaNs/overflow artifacts.
|
|
139
138
|
const outRGB = std.clamp(finalRGB, d.vec3f(0.0), d.vec3f(1.0));
|
|
140
139
|
|
|
140
|
+
// if (maskedGlow > 0.6) return d.vec4f(0.0, 0.0, 0.0, 0.0);
|
|
141
|
+
|
|
141
142
|
return d.vec4f(outRGB, color.w);
|
|
142
143
|
});
|
|
@@ -2,7 +2,7 @@ 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
|
+
rotationBindGroupLayout,
|
|
6
6
|
textureBindGroupLayout,
|
|
7
7
|
} from '../bindGroupLayouts';
|
|
8
8
|
import { hueShift } from '../tgpuUtils';
|
|
@@ -14,30 +14,22 @@ export const holoFragment = tgpu['~unstable'].fragmentFn({
|
|
|
14
14
|
})((input) => {
|
|
15
15
|
const texcoord = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
16
16
|
const uv = texcoord;
|
|
17
|
-
const centeredCoords = std.sub(std.mul(uv, 2.0), 1.0);
|
|
18
|
-
|
|
19
17
|
const textureColor = std.textureSample(
|
|
20
18
|
textureBindGroupLayout.$.texture,
|
|
21
19
|
textureBindGroupLayout.$.sampler,
|
|
22
20
|
texcoord
|
|
23
21
|
);
|
|
24
|
-
|
|
25
|
-
const rot = rotationValuesBindGroupLayout.$.vec;
|
|
26
|
-
const center = std.add(d.vec2f(0.0), d.vec2f(rot.x, rot.y));
|
|
22
|
+
const rot = rotationBindGroupLayout.$.vec;
|
|
27
23
|
|
|
28
24
|
const wave = waveCallbackSlot.$(rot.xy);
|
|
29
25
|
const waveX = wave.x;
|
|
30
26
|
const waveY = wave.y;
|
|
31
27
|
|
|
32
|
-
const band = std.add(waveX, waveY);
|
|
33
|
-
|
|
34
|
-
const dist = std.distance(centeredCoords, center);
|
|
35
|
-
const intensity = std.clamp(1.0 - dist, 0.0, 1.0);
|
|
36
|
-
const falloff = std.pow(std.exp(-dist), 1.0 / intensity);
|
|
28
|
+
const band = std.add(0.2 * waveX * uv.x, 2 * waveY * uv.y);
|
|
37
29
|
|
|
38
30
|
const hueAngle = std.mul(std.abs(band), (10 * Math.PI * rot.x) / 3);
|
|
39
31
|
const rainbowColor = hueShift(d.vec3f(1.0, 1.0, 1.0), hueAngle);
|
|
40
|
-
const finalColor = std.mul(rainbowColor,
|
|
32
|
+
const finalColor = std.mul(rainbowColor, 1.0);
|
|
41
33
|
|
|
42
|
-
return d.vec4f(finalColor,
|
|
34
|
+
return d.vec4f(finalColor, 0.7 * textureColor.w);
|
|
43
35
|
});
|
|
@@ -4,8 +4,8 @@ import * as std from 'typegpu/std';
|
|
|
4
4
|
import {
|
|
5
5
|
textureBindGroupLayout,
|
|
6
6
|
maskTextureBindGroupLayout,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
rotationBindGroupLayout,
|
|
8
|
+
glareBindGroupLayout,
|
|
9
9
|
} from '../bindGroupLayouts';
|
|
10
10
|
import { hueShift } from '../tgpuUtils';
|
|
11
11
|
|
|
@@ -17,10 +17,10 @@ export const reverseHoloFragment = tgpu['~unstable'].fragmentFn({
|
|
|
17
17
|
const uv = texcoord;
|
|
18
18
|
const centeredCoords = std.sub(std.mul(uv, 2.0), 1.0);
|
|
19
19
|
|
|
20
|
-
const rot =
|
|
20
|
+
const rot = rotationBindGroupLayout.$.vec;
|
|
21
21
|
const center = std.add(d.vec2f(0.0), d.vec2f(rot.x, rot.y)); // center from device orientation/touch
|
|
22
22
|
|
|
23
|
-
const opts =
|
|
23
|
+
const opts = glareBindGroupLayout.$.glareOptions;
|
|
24
24
|
const glareIntensity = opts.glareIntensity;
|
|
25
25
|
const glowPower = opts.glowPower;
|
|
26
26
|
const hueBlendPower = opts.hueBlendPower;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
TgpuBindGroup,
|
|
3
|
+
TgpuRenderPipeline,
|
|
4
|
+
TgpuRoot,
|
|
5
|
+
TgpuTexture,
|
|
6
|
+
} from 'typegpu';
|
|
2
7
|
import type { BindGroupPair } from '../types/types';
|
|
3
8
|
import {
|
|
4
9
|
maskTextureBindGroupLayout,
|
|
5
10
|
textureBindGroupLayout,
|
|
6
11
|
} from './bindGroupLayouts';
|
|
7
|
-
import { createBindGroupPair, createBindGroupPairs } from '../types/typeUtils';
|
|
8
12
|
import mainVertex from './vertexShaders/mainVertex';
|
|
9
13
|
import maskFragment from './fragmentShaders/maskFragment';
|
|
10
14
|
import { reverseHoloFragment } from './fragmentShaders/reverseHoloFragment';
|
|
@@ -17,14 +21,12 @@ import {
|
|
|
17
21
|
|
|
18
22
|
export const attachBindGroups = (
|
|
19
23
|
pipeline: TgpuRenderPipeline,
|
|
20
|
-
|
|
21
|
-
) =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return pipeline;
|
|
27
|
-
};
|
|
24
|
+
bindGroups: TgpuBindGroup[]
|
|
25
|
+
) =>
|
|
26
|
+
bindGroups.reduce(
|
|
27
|
+
(acc, bindGroup) => acc.with(bindGroup.layout, bindGroup),
|
|
28
|
+
pipeline
|
|
29
|
+
);
|
|
28
30
|
|
|
29
31
|
export const blend: GPUBlendState = {
|
|
30
32
|
color: {
|
|
@@ -62,12 +64,12 @@ export const attachBindGroupsToPass = (
|
|
|
62
64
|
|
|
63
65
|
export const createMaskPipeline = (
|
|
64
66
|
root: TgpuRoot,
|
|
65
|
-
maskTexture: TgpuTexture |
|
|
66
|
-
|
|
67
|
+
maskTexture: TgpuTexture | undefined,
|
|
68
|
+
bindGroups: TgpuBindGroup[],
|
|
67
69
|
sampler: GPUSampler,
|
|
68
70
|
presentationFormat: GPUTextureFormat
|
|
69
|
-
): TgpuRenderPipeline |
|
|
70
|
-
if (!maskTexture) return
|
|
71
|
+
): TgpuRenderPipeline | void => {
|
|
72
|
+
if (!maskTexture) return;
|
|
71
73
|
|
|
72
74
|
const maskTextureBindGroup = root.createBindGroup(
|
|
73
75
|
maskTextureBindGroupLayout,
|
|
@@ -76,12 +78,9 @@ export const createMaskPipeline = (
|
|
|
76
78
|
sampler,
|
|
77
79
|
}
|
|
78
80
|
);
|
|
79
|
-
const maskBGP:
|
|
80
|
-
|
|
81
|
-
[
|
|
82
|
-
);
|
|
83
|
-
for (let i = 0; i < BGP.length; i++) {
|
|
84
|
-
maskBGP.push(BGP[i]!);
|
|
81
|
+
const maskBGP: TgpuBindGroup[] = [maskTextureBindGroup];
|
|
82
|
+
for (let i = 0; i < bindGroups.length; i++) {
|
|
83
|
+
maskBGP.push(bindGroups[i]!);
|
|
85
84
|
}
|
|
86
85
|
let maskPipeline = root['~unstable']
|
|
87
86
|
.withVertex(mainVertex, {})
|
|
@@ -94,12 +93,12 @@ export const createMaskPipeline = (
|
|
|
94
93
|
|
|
95
94
|
export const createReverseHoloPipeline = (
|
|
96
95
|
root: TgpuRoot,
|
|
97
|
-
texture: TgpuTexture |
|
|
98
|
-
|
|
96
|
+
texture: TgpuTexture | undefined,
|
|
97
|
+
bindGroups: TgpuBindGroup[],
|
|
99
98
|
sampler: GPUSampler,
|
|
100
99
|
presentationFormat: GPUTextureFormat
|
|
101
|
-
): TgpuRenderPipeline |
|
|
102
|
-
if (!texture) return
|
|
100
|
+
): TgpuRenderPipeline | void => {
|
|
101
|
+
if (!texture) return;
|
|
103
102
|
|
|
104
103
|
const reverseHoloBindGroup = root.createBindGroup(
|
|
105
104
|
maskTextureBindGroupLayout,
|
|
@@ -108,10 +107,7 @@ export const createReverseHoloPipeline = (
|
|
|
108
107
|
sampler,
|
|
109
108
|
}
|
|
110
109
|
);
|
|
111
|
-
const reverseHoloBGP:
|
|
112
|
-
reverseHoloBGP.push(
|
|
113
|
-
createBindGroupPair(maskTextureBindGroupLayout, reverseHoloBindGroup)
|
|
114
|
-
);
|
|
110
|
+
const reverseHoloBGP: TgpuBindGroup[] = [...bindGroups, reverseHoloBindGroup];
|
|
115
111
|
|
|
116
112
|
let reverseHoloPipeline = root['~unstable']
|
|
117
113
|
.withVertex(mainVertex, {})
|
|
@@ -127,65 +123,54 @@ export const createReverseHoloPipeline = (
|
|
|
127
123
|
|
|
128
124
|
export const createRainbowHoloPipeline = (
|
|
129
125
|
root: TgpuRoot,
|
|
130
|
-
texture: TgpuTexture |
|
|
131
|
-
|
|
126
|
+
texture: TgpuTexture | undefined,
|
|
127
|
+
bindGroups: TgpuBindGroup[],
|
|
132
128
|
sampler: GPUSampler,
|
|
133
129
|
presentationFormat: GPUTextureFormat
|
|
134
|
-
): TgpuRenderPipeline |
|
|
135
|
-
if (!texture) return
|
|
130
|
+
): TgpuRenderPipeline | void => {
|
|
131
|
+
if (!texture) return;
|
|
136
132
|
|
|
137
133
|
const imageTextureBindGroup = root.createBindGroup(textureBindGroupLayout, {
|
|
138
134
|
texture: root.unwrap(texture).createView(),
|
|
139
135
|
sampler,
|
|
140
136
|
});
|
|
141
137
|
|
|
142
|
-
const texBGP = createBindGroupPair(
|
|
143
|
-
textureBindGroupLayout,
|
|
144
|
-
imageTextureBindGroup
|
|
145
|
-
);
|
|
146
|
-
|
|
147
138
|
let rainbowHoloPipeline = root['~unstable']
|
|
148
139
|
.with(waveCallbackSlot, waveCallbackFn(WAVE_CALLBACKS.default))
|
|
149
140
|
.withVertex(mainVertex, {})
|
|
150
141
|
.withFragment(holoFragment, getDefaultTarget(presentationFormat, blend))
|
|
151
142
|
.createPipeline();
|
|
152
143
|
|
|
153
|
-
rainbowHoloPipeline = attachBindGroups(rainbowHoloPipeline, [
|
|
144
|
+
rainbowHoloPipeline = attachBindGroups(rainbowHoloPipeline, [
|
|
145
|
+
...bindGroups,
|
|
146
|
+
imageTextureBindGroup,
|
|
147
|
+
]);
|
|
154
148
|
return rainbowHoloPipeline;
|
|
155
149
|
};
|
|
156
150
|
|
|
157
|
-
export
|
|
151
|
+
export function renderPipelinesInSinglePass(
|
|
158
152
|
root: TgpuRoot,
|
|
159
153
|
pipelines: TgpuRenderPipeline[],
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
pass.setPipeline(pipelines[i]!);
|
|
179
|
-
pass.draw(6);
|
|
180
|
-
}
|
|
154
|
+
view: GPUTextureView
|
|
155
|
+
) {
|
|
156
|
+
const unstableRoot = root['~unstable'];
|
|
157
|
+
const attachment: GPURenderPassColorAttachment = {
|
|
158
|
+
view,
|
|
159
|
+
clearValue: [0, 0, 0, 0],
|
|
160
|
+
loadOp: 'clear',
|
|
161
|
+
storeOp: 'store',
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
unstableRoot.beginRenderPass(
|
|
165
|
+
{
|
|
166
|
+
colorAttachments: [attachment],
|
|
167
|
+
},
|
|
168
|
+
(pass) => {
|
|
169
|
+
for (const pipeline of pipelines) {
|
|
170
|
+
pass.setPipeline(pipeline);
|
|
171
|
+
pass.draw(6);
|
|
181
172
|
}
|
|
182
|
-
);
|
|
183
|
-
root['~unstable'].flush();
|
|
184
|
-
} else {
|
|
185
|
-
for (let i = 0; i < pipelines.length; i++) {
|
|
186
|
-
const attachment = attachments[i];
|
|
187
|
-
if (!attachment) return;
|
|
188
|
-
pipelines[i]!.withColorAttachment(attachment).draw(6);
|
|
189
173
|
}
|
|
190
|
-
|
|
191
|
-
|
|
174
|
+
);
|
|
175
|
+
unstableRoot.flush();
|
|
176
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type TgpuRoot, type TgpuTexture } from 'typegpu';
|
|
1
|
+
import { type TextureProps, type TgpuRoot, type TgpuTexture } from 'typegpu';
|
|
2
|
+
import getBitmapFromURI from './bitmaps';
|
|
2
3
|
|
|
3
4
|
export const createTexture = async (
|
|
4
5
|
root: TgpuRoot,
|
|
@@ -28,3 +29,14 @@ export const loadTexture = async (
|
|
|
28
29
|
[imageBitmap.width, imageBitmap.height]
|
|
29
30
|
);
|
|
30
31
|
};
|
|
32
|
+
|
|
33
|
+
export async function loadBitmap(
|
|
34
|
+
root: TgpuRoot,
|
|
35
|
+
imageURI: string,
|
|
36
|
+
setTexture: (texture: TgpuTexture<TextureProps>) => void
|
|
37
|
+
) {
|
|
38
|
+
const bitmap = await getBitmapFromURI(imageURI);
|
|
39
|
+
const texture = await createTexture(root, bitmap);
|
|
40
|
+
setTexture(texture);
|
|
41
|
+
await loadTexture(root, bitmap, texture);
|
|
42
|
+
}
|
package/src/shaders/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { quaternion, vec3 } from '../types/types';
|
|
2
1
|
import { Dimensions } from 'react-native';
|
|
2
|
+
import type { quaternion, vec3 } from '../types/types';
|
|
3
3
|
|
|
4
4
|
export const rotateVectorByQuaternion = (
|
|
5
5
|
vec: vec3,
|
|
@@ -35,39 +35,25 @@ export const rotateVectorByQuaternion = (
|
|
|
35
35
|
return [rotated[0], rotated[1], rotated[2]];
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
export const clamp = (v: number, min = -1, max = 1) => {
|
|
39
|
-
'worklet';
|
|
40
|
-
return Math.max(min, Math.min(max, v));
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const rotate2D = (
|
|
44
|
-
[x, y]: [number, number],
|
|
45
|
-
angleDeg: number
|
|
46
|
-
): [number, number] => {
|
|
47
|
-
'worklet';
|
|
48
|
-
const rad = (angleDeg * Math.PI) / 180;
|
|
49
|
-
const c = Math.cos(rad);
|
|
50
|
-
const s = Math.sin(rad);
|
|
51
|
-
return [x * c - y * s, x * s + y * c];
|
|
52
|
-
};
|
|
53
|
-
|
|
54
38
|
// Simple helper to get angle from dimensions (0 or 90)
|
|
55
39
|
export function getAngleFromDimensions() {
|
|
40
|
+
return 90 * Number(isLandscapeMode());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function isLandscapeMode() {
|
|
56
44
|
const { width, height } = Dimensions.get('window');
|
|
57
|
-
|
|
45
|
+
|
|
46
|
+
return width >= height;
|
|
58
47
|
}
|
|
59
48
|
|
|
60
49
|
// Subscribe to orientation change via Dimensions API only
|
|
61
50
|
export function subscribeToOrientationChange(
|
|
62
|
-
callback: (
|
|
51
|
+
callback: (isLandscape: boolean) => void
|
|
63
52
|
) {
|
|
64
|
-
callback(
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
53
|
+
const handler = () => callback(isLandscapeMode());
|
|
54
|
+
const subscription = Dimensions.addEventListener('change', handler);
|
|
55
|
+
|
|
56
|
+
handler();
|
|
68
57
|
|
|
69
|
-
|
|
70
|
-
return () => {
|
|
71
|
-
dimSub.remove();
|
|
72
|
-
};
|
|
58
|
+
return () => subscription.remove();
|
|
73
59
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import tgpu from 'typegpu';
|
|
2
2
|
import * as std from 'typegpu/std';
|
|
3
3
|
import * as d from 'typegpu/data';
|
|
4
|
-
import {
|
|
4
|
+
import { rotationBindGroupLayout } from '../bindGroupLayouts';
|
|
5
5
|
|
|
6
6
|
const mainRotationEffectVertex = tgpu['~unstable'].vertexFn({
|
|
7
7
|
in: { vertexIndex: d.builtin.vertexIndex },
|
|
8
8
|
out: { position: d.builtin.position, uv: d.vec2f },
|
|
9
9
|
})((input) => {
|
|
10
|
-
const rot =
|
|
10
|
+
const rot = rotationBindGroupLayout.$.vec;
|
|
11
11
|
|
|
12
12
|
// Maximum rotation angles in radians
|
|
13
13
|
const maxAngle = d.f32((25.0 * Math.PI) / 180.0);
|
package/src/types/typeUtils.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { f32, vec2f, vec3f, vec4f } from 'typegpu/data';
|
|
2
2
|
import type {
|
|
3
|
-
BindGroupPair,
|
|
4
3
|
GlareOptions,
|
|
5
4
|
ColorMask,
|
|
6
5
|
DeepPartiallyOptional,
|
|
@@ -8,7 +7,6 @@ import type {
|
|
|
8
7
|
HoloOptions,
|
|
9
8
|
} from './types';
|
|
10
9
|
import { div } from 'typegpu/std';
|
|
11
|
-
import type { TgpuBindGroup, TgpuBindGroupLayout } from 'typegpu';
|
|
12
10
|
import { WAVE_CALLBACKS } from '../enums/waveCallback';
|
|
13
11
|
|
|
14
12
|
export const createGlareOptions = (
|
|
@@ -108,29 +106,3 @@ export const numberArrToTyped = (vec: number[]) => {
|
|
|
108
106
|
const typed = convFn(...vec);
|
|
109
107
|
return typed;
|
|
110
108
|
};
|
|
111
|
-
|
|
112
|
-
export const createBindGroupPair = (
|
|
113
|
-
bindGroupLayout: TgpuBindGroupLayout,
|
|
114
|
-
bindGroup: TgpuBindGroup
|
|
115
|
-
): BindGroupPair => {
|
|
116
|
-
return { layout: bindGroupLayout, group: bindGroup };
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export const createBindGroupPairs = (
|
|
120
|
-
bindGroupLayouts: TgpuBindGroupLayout[],
|
|
121
|
-
bindGroups: TgpuBindGroup[]
|
|
122
|
-
): BindGroupPair[] => {
|
|
123
|
-
if (
|
|
124
|
-
bindGroupLayouts.length > 0 &&
|
|
125
|
-
bindGroupLayouts.length !== bindGroups.length
|
|
126
|
-
)
|
|
127
|
-
throw new Error(
|
|
128
|
-
'createBindGroups: bindGroupLayout and bindGroup arrrays must be of the same length'
|
|
129
|
-
);
|
|
130
|
-
const pairs: BindGroupPair[] = [];
|
|
131
|
-
for (let i = 0; i < bindGroupLayouts.length; i++) {
|
|
132
|
-
pairs.push(createBindGroupPair(bindGroupLayouts[i]!, bindGroups[i]!));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return pairs;
|
|
136
|
-
};
|
package/src/types/types.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
TgpuBindGroup,
|
|
3
|
+
TgpuBindGroupLayout,
|
|
4
|
+
TgpuRenderPipeline,
|
|
5
|
+
} from 'typegpu';
|
|
2
6
|
import type { WaveCallbackFn } from '../enums/waveCallback';
|
|
3
7
|
|
|
4
8
|
export type vec2 = [number, number];
|
|
@@ -55,3 +59,9 @@ export type BindGroupPair = {
|
|
|
55
59
|
layout: TgpuBindGroupLayout;
|
|
56
60
|
group: TgpuBindGroup;
|
|
57
61
|
};
|
|
62
|
+
|
|
63
|
+
export type ColorAttachment = Parameters<
|
|
64
|
+
TgpuRenderPipeline['withColorAttachment']
|
|
65
|
+
>[0];
|
|
66
|
+
|
|
67
|
+
export type PipelineAttachmentPair = [TgpuRenderPipeline, ColorAttachment];
|