react-native-shine 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -7
- package/lib/module/components/Content.js +232 -0
- package/lib/module/components/Content.js.map +1 -0
- package/lib/module/components/Shine.js +33 -0
- package/lib/module/components/Shine.js.map +1 -0
- package/lib/module/components/ShineGroup.js +92 -0
- package/lib/module/components/ShineGroup.js.map +1 -0
- package/lib/module/enums/waveCallback.js +19 -0
- package/lib/module/enums/waveCallback.js.map +1 -0
- package/lib/module/hooks/useAnimationFrame.js +17 -0
- package/lib/module/hooks/useAnimationFrame.js.map +1 -0
- package/lib/module/hooks/useOrientation.js +10 -0
- package/lib/module/hooks/useOrientation.js.map +1 -0
- package/lib/module/index.js +6 -219
- package/lib/module/index.js.map +1 -1
- package/lib/module/shaders/bindGroupLayouts.js +41 -6
- package/lib/module/shaders/bindGroupLayouts.js.map +1 -1
- package/lib/module/shaders/bindGroupUtils.js +34 -41
- package/lib/module/shaders/bindGroupUtils.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/colorMaskFragment.js +2 -2
- package/lib/module/shaders/fragmentShaders/colorMaskFragment.js.map +1 -1
- package/lib/module/shaders/fragmentShaders/glareFragment.js +115 -0
- package/lib/module/shaders/fragmentShaders/glareFragment.js.map +1 -0
- package/lib/module/shaders/fragmentShaders/holoFragment.js +28 -0
- package/lib/module/shaders/fragmentShaders/holoFragment.js.map +1 -0
- package/lib/module/shaders/fragmentShaders/maskFragment.js +20 -0
- package/lib/module/shaders/fragmentShaders/maskFragment.js.map +1 -0
- package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js +46 -0
- package/lib/module/shaders/fragmentShaders/reverseHoloFragment.js.map +1 -0
- package/lib/module/shaders/pipelineSetups.js +72 -17
- package/lib/module/shaders/pipelineSetups.js.map +1 -1
- package/lib/module/shaders/{resourceManagement.js → resourceManagement/bitmaps.js} +2 -1
- package/lib/module/shaders/resourceManagement/bitmaps.js.map +1 -0
- package/lib/module/shaders/resourceManagement/bufferManager.js +46 -0
- package/lib/module/shaders/resourceManagement/bufferManager.js.map +1 -0
- package/lib/module/shaders/resourceManagement/textures.js +24 -0
- package/lib/module/shaders/resourceManagement/textures.js.map +1 -0
- package/lib/module/shaders/tgpuUtils.js +19 -1
- package/lib/module/shaders/tgpuUtils.js.map +1 -1
- package/lib/module/shaders/utils.js +8 -36
- package/lib/module/shaders/utils.js.map +1 -1
- package/lib/module/shaders/vertexShaders/mainRotationEffectVertex.js +47 -0
- package/lib/module/shaders/vertexShaders/mainRotationEffectVertex.js.map +1 -0
- package/lib/module/types/size.js +2 -0
- package/lib/module/types/size.js.map +1 -0
- package/lib/module/types/typeUtils.js +17 -19
- 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 +7 -0
- package/lib/typescript/src/components/Shine.d.ts.map +1 -0
- package/lib/typescript/src/components/ShineGroup.d.ts +6 -0
- package/lib/typescript/src/components/ShineGroup.d.ts.map +1 -0
- package/lib/typescript/src/enums/waveCallback.d.ts +9 -0
- package/lib/typescript/src/enums/waveCallback.d.ts.map +1 -0
- 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 +4 -0
- package/lib/typescript/src/hooks/useOrientation.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +8 -11
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/shaders/bindGroupLayouts.d.ts +46 -8
- package/lib/typescript/src/shaders/bindGroupLayouts.d.ts.map +1 -1
- package/lib/typescript/src/shaders/bindGroupUtils.d.ts +9 -9
- package/lib/typescript/src/shaders/bindGroupUtils.d.ts.map +1 -1
- package/lib/typescript/src/shaders/fragmentShaders/glareFragment.d.ts +8 -0
- package/lib/typescript/src/shaders/fragmentShaders/glareFragment.d.ts.map +1 -0
- package/lib/typescript/src/shaders/fragmentShaders/holoFragment.d.ts +5 -0
- package/lib/typescript/src/shaders/fragmentShaders/holoFragment.d.ts.map +1 -0
- package/lib/typescript/src/shaders/fragmentShaders/maskFragment.d.ts +6 -0
- package/lib/typescript/src/shaders/fragmentShaders/maskFragment.d.ts.map +1 -0
- package/lib/typescript/src/shaders/fragmentShaders/reverseHoloFragment.d.ts +5 -0
- package/lib/typescript/src/shaders/fragmentShaders/reverseHoloFragment.d.ts.map +1 -0
- package/lib/typescript/src/shaders/pipelineSetups.d.ts +9 -4
- package/lib/typescript/src/shaders/pipelineSetups.d.ts.map +1 -1
- package/lib/typescript/src/shaders/{resourceManagement.d.ts → resourceManagement/bitmaps.d.ts} +1 -1
- package/lib/typescript/src/shaders/resourceManagement/bitmaps.d.ts.map +1 -0
- package/lib/typescript/src/shaders/resourceManagement/bufferManager.d.ts +28 -0
- package/lib/typescript/src/shaders/resourceManagement/bufferManager.d.ts.map +1 -0
- package/lib/typescript/src/shaders/resourceManagement/textures.d.ts +8 -0
- package/lib/typescript/src/shaders/resourceManagement/textures.d.ts.map +1 -0
- package/lib/typescript/src/shaders/tgpuUtils.d.ts +5 -1
- package/lib/typescript/src/shaders/tgpuUtils.d.ts.map +1 -1
- package/lib/typescript/src/shaders/utils.d.ts +3 -10
- package/lib/typescript/src/shaders/utils.d.ts.map +1 -1
- package/lib/typescript/src/shaders/vertexShaders/mainRotationEffectVertex.d.ts +6 -0
- package/lib/typescript/src/shaders/vertexShaders/mainRotationEffectVertex.d.ts.map +1 -0
- 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 +3 -5
- package/lib/typescript/src/types/typeUtils.d.ts.map +1 -1
- package/lib/typescript/src/types/types.d.ts +10 -3
- 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 +7 -5
- package/scripts/postinstall.js +16 -17
- package/src/components/Content.tsx +403 -0
- package/src/components/Shine.tsx +38 -0
- package/src/components/ShineGroup.tsx +100 -0
- package/src/enums/waveCallback.ts +22 -0
- package/src/hooks/useAnimationFrame.ts +21 -0
- package/src/hooks/useOrientation.ts +18 -0
- package/src/index.tsx +14 -322
- package/src/shaders/bindGroupLayouts.ts +45 -8
- package/src/shaders/bindGroupUtils.ts +50 -65
- package/src/shaders/fragmentShaders/colorMaskFragment.ts +2 -2
- package/src/shaders/fragmentShaders/glareFragment.ts +143 -0
- package/src/shaders/fragmentShaders/holoFragment.ts +35 -0
- package/src/shaders/fragmentShaders/maskFragment.ts +31 -0
- package/src/shaders/fragmentShaders/reverseHoloFragment.ts +71 -0
- package/src/shaders/pipelineSetups.ts +152 -20
- package/src/shaders/{resourceManagement.ts → resourceManagement/bitmaps.ts} +1 -0
- package/src/shaders/resourceManagement/bufferManager.ts +82 -0
- package/src/shaders/resourceManagement/textures.ts +42 -0
- package/src/shaders/tgpuUtils.ts +36 -1
- package/src/shaders/utils.ts +13 -57
- package/src/shaders/vertexShaders/mainRotationEffectVertex.ts +76 -0
- package/src/types/size.ts +4 -0
- package/src/types/typeUtils.ts +22 -36
- package/src/types/types.ts +19 -3
- package/src/types/vector.ts +13 -0
- package/src/utils/size.ts +12 -0
- package/src/utils/vector.ts +132 -0
- package/lib/module/shaders/fragmentShaders/bloomFragment.js +0 -66
- package/lib/module/shaders/fragmentShaders/bloomFragment.js.map +0 -1
- package/lib/module/shaders/resourceManagement.js.map +0 -1
- package/lib/typescript/src/shaders/fragmentShaders/bloomFragment.d.ts +0 -6
- package/lib/typescript/src/shaders/fragmentShaders/bloomFragment.d.ts.map +0 -1
- package/lib/typescript/src/shaders/resourceManagement.d.ts.map +0 -1
- package/src/shaders/fragmentShaders/bloomFragment.ts +0 -83
package/src/index.tsx
CHANGED
|
@@ -1,326 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Canvas, useDevice, useGPUContext } from 'react-native-wgpu';
|
|
3
|
-
import { getOrInitRoot } from './roots';
|
|
4
|
-
import mainVertex from './shaders/vertexShaders/mainVertex';
|
|
5
|
-
import getBitmapFromURI from './shaders/resourceManagement';
|
|
1
|
+
import { useOrientation } from './hooks/useOrientation';
|
|
6
2
|
import {
|
|
7
|
-
createTexture,
|
|
8
|
-
loadTexture,
|
|
9
|
-
clamp,
|
|
10
|
-
rotate2D,
|
|
11
|
-
subscribeToOrientationChange,
|
|
12
3
|
getAngleFromDimensions,
|
|
4
|
+
isLandscapeMode,
|
|
5
|
+
subscribeToOrientationChange,
|
|
13
6
|
} from './shaders/utils';
|
|
14
|
-
import type { TgpuTexture } from 'typegpu';
|
|
15
|
-
import {
|
|
16
|
-
bloomOptionsBindGroupLayout,
|
|
17
|
-
colorMaskBindGroupLayout,
|
|
18
|
-
rotationValuesBindGroupLayout,
|
|
19
|
-
textureBindGroupLayout,
|
|
20
|
-
} from './shaders/bindGroupLayouts';
|
|
21
|
-
import {
|
|
22
|
-
SensorType,
|
|
23
|
-
useAnimatedSensor,
|
|
24
|
-
useDerivedValue,
|
|
25
|
-
useSharedValue,
|
|
26
|
-
} from 'react-native-reanimated';
|
|
27
|
-
import * as d from 'typegpu/data';
|
|
28
|
-
import { Platform } from 'react-native';
|
|
29
|
-
import bloomFragment from './shaders/fragmentShaders/bloomFragment';
|
|
30
|
-
import {
|
|
31
|
-
createBloomOptionsBindGroup,
|
|
32
|
-
createBloomOptionsBuffer,
|
|
33
|
-
createColorMaskBindGroup,
|
|
34
|
-
createColorMaskBuffer,
|
|
35
|
-
createRotationBuffer,
|
|
36
|
-
createRotationValuesBindGroup,
|
|
37
|
-
} from './shaders/bindGroupUtils';
|
|
38
|
-
import {
|
|
39
|
-
createBindGroupPairs,
|
|
40
|
-
createBloomOptions,
|
|
41
|
-
createColorMask,
|
|
42
|
-
} from './types/typeUtils';
|
|
43
|
-
import type {
|
|
44
|
-
BindGroupPair,
|
|
45
|
-
BloomOptions,
|
|
46
|
-
ColorMask,
|
|
47
|
-
DeepPartiallyOptional,
|
|
48
|
-
} from './types/types';
|
|
49
|
-
import { attachBindGroups, getDefaultTarget } from './shaders/pipelineSetups';
|
|
50
|
-
import colorMaskFragment from './shaders/fragmentShaders/colorMaskFragment';
|
|
51
|
-
interface ShineProps {
|
|
52
|
-
width: number;
|
|
53
|
-
height: number;
|
|
54
|
-
imageURI: string;
|
|
55
|
-
bloomOptions?: Partial<BloomOptions>;
|
|
56
|
-
colorMaskOptions?: DeepPartiallyOptional<ColorMask, 'baseColor'>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function Shine({
|
|
60
|
-
width,
|
|
61
|
-
height,
|
|
62
|
-
imageURI,
|
|
63
|
-
bloomOptions,
|
|
64
|
-
colorMaskOptions,
|
|
65
|
-
}: ShineProps) {
|
|
66
|
-
const { device = null } = useDevice();
|
|
67
|
-
const root = device ? getOrInitRoot(device) : null;
|
|
68
|
-
const { ref, context } = useGPUContext();
|
|
69
|
-
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
|
|
70
|
-
const frameRef = useRef<number | null>(null);
|
|
71
|
-
|
|
72
|
-
const [imageTexture, setImageTexture] = useState<TgpuTexture | null>(null);
|
|
73
|
-
|
|
74
|
-
const orientationAngle = useSharedValue<number>(0); // degrees
|
|
75
|
-
const rotationShared = useSharedValue<[number, number, number]>([0, 0, 0]); // final GPU offsets
|
|
76
|
-
|
|
77
|
-
// Calibration shared values (UI thread)
|
|
78
|
-
const initialGravity = useSharedValue<[number, number, number]>([0, 0, 0]);
|
|
79
|
-
const calibSum = useSharedValue<[number, number, number]>([0, 0, 0]);
|
|
80
|
-
const calibCount = useSharedValue<number>(0);
|
|
81
|
-
const calibrated = useSharedValue<boolean>(false);
|
|
82
|
-
|
|
83
|
-
const gravitySensor = useAnimatedSensor(SensorType.GRAVITY, { interval: 20 });
|
|
84
|
-
|
|
85
|
-
console.log('render');
|
|
86
|
-
|
|
87
|
-
// Subscribe to orientation changes and reset calibration on change
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
orientationAngle.value = getAngleFromDimensions();
|
|
90
|
-
const unsubscribe = subscribeToOrientationChange((angleDeg) => {
|
|
91
|
-
orientationAngle.value = angleDeg;
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return () => unsubscribe();
|
|
95
|
-
}, [orientationAngle]);
|
|
96
|
-
|
|
97
|
-
// Calibration & mapping logic
|
|
98
|
-
useDerivedValue(() => {
|
|
99
|
-
'worklet';
|
|
100
|
-
|
|
101
|
-
// console.log(orientationAngle.value);
|
|
102
|
-
const v: any = gravitySensor.sensor?.value ??
|
|
103
|
-
gravitySensor.sensor.value ?? { x: 0, y: 0, z: 0 };
|
|
104
|
-
const gx = v.x ?? 0;
|
|
105
|
-
const gy = v.y ?? 0;
|
|
106
|
-
const gz = v.z ?? 0;
|
|
107
|
-
|
|
108
|
-
const CALIBRATION_SAMPLES = 40;
|
|
109
|
-
const alpha = 0.15; // smoothing
|
|
110
|
-
const scale = 0.6;
|
|
111
|
-
|
|
112
|
-
if (!calibrated.value) {
|
|
113
|
-
// accumulate baseline in device coordinates
|
|
114
|
-
const s = calibSum.value;
|
|
115
|
-
const c = calibCount.value + 1;
|
|
116
|
-
calibSum.value = [s[0] + gx, s[1] + gy, s[2] + gz];
|
|
117
|
-
calibCount.value = c;
|
|
118
|
-
|
|
119
|
-
if (c >= CALIBRATION_SAMPLES) {
|
|
120
|
-
const avg = calibSum.value;
|
|
121
|
-
initialGravity.value = [avg[0] / c, avg[1] / c, avg[2] / c];
|
|
122
|
-
calibrated.value = true;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
rotationShared.value = [0, 0, 0];
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const init = initialGravity.value;
|
|
130
|
-
const dx = gx - init[0];
|
|
131
|
-
const dy = gy - init[1];
|
|
132
|
-
const dz = gz - init[2];
|
|
133
|
-
|
|
134
|
-
// Rotate into screen coordinates so offsets auto-swap with orientation
|
|
135
|
-
const [mx, my] = rotate2D([dx, dy], -orientationAngle.value);
|
|
136
|
-
const screenX = mx;
|
|
137
|
-
const screenY = -my;
|
|
138
|
-
|
|
139
|
-
const prev = rotationShared.value;
|
|
140
|
-
const smoothX = prev[0] * (1 - alpha) + screenX * alpha;
|
|
141
|
-
const smoothY = prev[1] * (1 - alpha) + screenY * alpha;
|
|
142
|
-
const smoothZ = prev[2] * (1 - alpha) + dz * alpha;
|
|
143
7
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
];
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
// Resource setup
|
|
160
|
-
useEffect(() => {
|
|
161
|
-
if (!root || !device || !context) return;
|
|
162
|
-
(async () => {
|
|
163
|
-
const bitmap = await getBitmapFromURI(imageURI);
|
|
164
|
-
const texture = await createTexture(root, bitmap);
|
|
165
|
-
setImageTexture(texture);
|
|
166
|
-
await loadTexture(root, bitmap, texture);
|
|
167
|
-
})();
|
|
168
|
-
}, [root, device, context, imageURI]);
|
|
169
|
-
|
|
170
|
-
// Render loop
|
|
171
|
-
useEffect(() => {
|
|
172
|
-
if (!root || !device || !context || !imageTexture) return;
|
|
173
|
-
|
|
174
|
-
context.configure({
|
|
175
|
-
device,
|
|
176
|
-
format: presentationFormat,
|
|
177
|
-
alphaMode: 'premultiplied',
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
const sampler = device.createSampler({
|
|
181
|
-
magFilter: 'linear',
|
|
182
|
-
minFilter: 'linear',
|
|
183
|
-
});
|
|
184
|
-
const textureBindGroup = root.createBindGroup(textureBindGroupLayout, {
|
|
185
|
-
texture: root.unwrap(imageTexture).createView(),
|
|
186
|
-
sampler,
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
const rotationBuffer = createRotationBuffer(root);
|
|
190
|
-
const rotationBindGroup = createRotationValuesBindGroup(
|
|
191
|
-
root,
|
|
192
|
-
rotationBuffer
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
const bloomOptionsBuffer = createBloomOptionsBuffer(
|
|
196
|
-
root,
|
|
197
|
-
createBloomOptions(bloomOptions ?? {})
|
|
198
|
-
);
|
|
199
|
-
const bloomOptionsBindGroup = createBloomOptionsBindGroup(
|
|
200
|
-
root,
|
|
201
|
-
bloomOptionsBuffer
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
const colorMaskBuffer = createColorMaskBuffer(
|
|
205
|
-
root,
|
|
206
|
-
createColorMask(colorMaskOptions ?? { baseColor: [-20, -20, -20] })
|
|
207
|
-
);
|
|
208
|
-
const colorMaskBindGroup = createColorMaskBindGroup(root, colorMaskBuffer);
|
|
209
|
-
|
|
210
|
-
const bloomBGP: BindGroupPair[] = createBindGroupPairs(
|
|
211
|
-
[
|
|
212
|
-
textureBindGroupLayout,
|
|
213
|
-
rotationValuesBindGroupLayout,
|
|
214
|
-
bloomOptionsBindGroupLayout,
|
|
215
|
-
colorMaskBindGroupLayout,
|
|
216
|
-
],
|
|
217
|
-
[
|
|
218
|
-
textureBindGroup,
|
|
219
|
-
rotationBindGroup,
|
|
220
|
-
bloomOptionsBindGroup,
|
|
221
|
-
colorMaskBindGroup,
|
|
222
|
-
]
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
const maskBGP: BindGroupPair[] = createBindGroupPairs(
|
|
226
|
-
[textureBindGroupLayout, colorMaskBindGroupLayout],
|
|
227
|
-
[textureBindGroup, colorMaskBindGroup]
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
let bloomPipeline = root['~unstable']
|
|
231
|
-
.withVertex(mainVertex, {})
|
|
232
|
-
.withFragment(bloomFragment, getDefaultTarget(presentationFormat))
|
|
233
|
-
.createPipeline();
|
|
234
|
-
bloomPipeline = attachBindGroups(bloomPipeline, bloomBGP);
|
|
235
|
-
|
|
236
|
-
let colorMaskPipeline = root['~unstable']
|
|
237
|
-
.withVertex(mainVertex, {})
|
|
238
|
-
.withFragment(colorMaskFragment, getDefaultTarget(presentationFormat))
|
|
239
|
-
.createPipeline();
|
|
240
|
-
colorMaskPipeline = attachBindGroups(colorMaskPipeline, maskBGP);
|
|
241
|
-
|
|
242
|
-
const rot = d.vec3f(0.0);
|
|
243
|
-
let view: GPUTextureView;
|
|
244
|
-
let bloomAttachment;
|
|
245
|
-
let colorMaskAttachment;
|
|
246
|
-
const render = () => {
|
|
247
|
-
rot[0] = rotationShared.value[0];
|
|
248
|
-
rot[1] = rotationShared.value[1];
|
|
249
|
-
rot[2] = rotationShared.value[2];
|
|
250
|
-
rotationBuffer.write(rot);
|
|
251
|
-
|
|
252
|
-
view = context.getCurrentTexture().createView();
|
|
253
|
-
bloomAttachment = {
|
|
254
|
-
view: view,
|
|
255
|
-
clearValue: [0, 0, 0, 0],
|
|
256
|
-
loadOp: 'clear' as GPULoadOp,
|
|
257
|
-
storeOp: 'store' as GPUStoreOp,
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
colorMaskAttachment = {
|
|
261
|
-
view: view,
|
|
262
|
-
loadOp: 'load' as GPULoadOp,
|
|
263
|
-
storeOp: 'store' as GPUStoreOp,
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
// root['~unstable'].beginRenderPass(
|
|
267
|
-
// {
|
|
268
|
-
// colorAttachments: [
|
|
269
|
-
// {
|
|
270
|
-
// view,
|
|
271
|
-
// clearValue: [0, 0, 0, 0],
|
|
272
|
-
// loadOp: 'clear',
|
|
273
|
-
// storeOp: 'store',
|
|
274
|
-
// },
|
|
275
|
-
// ],
|
|
276
|
-
// },
|
|
277
|
-
// (pass) => {
|
|
278
|
-
// pass.setPipeline(bloomPipeline);
|
|
279
|
-
// // pass = attachBindGroupsToPass(pass, bloomBGP);
|
|
280
|
-
// pass.setBindGroup(textureBindGroupLayout, textureBindGroup);
|
|
281
|
-
// pass.setBindGroup(rotationValuesBindGroupLayout, rotationBindGroup);
|
|
282
|
-
// pass.setBindGroup(bloomOptionsBindGroupLayout, bloomOptionsBindGroup);
|
|
283
|
-
// pass.setBindGroup(colorMaskBindGroupLayout, colorMaskBindGroup);
|
|
284
|
-
// pass.draw(6);
|
|
285
|
-
|
|
286
|
-
// // Mask draw
|
|
287
|
-
// pass.setPipeline(colorMaskPipeline);
|
|
288
|
-
// pass.setBindGroup(textureBindGroupLayout, textureBindGroup);
|
|
289
|
-
// pass.setBindGroup(colorMaskBindGroupLayout, colorMaskBindGroup);
|
|
290
|
-
// pass.draw(6);
|
|
291
|
-
// }
|
|
292
|
-
// );
|
|
293
|
-
// root['~unstable'].flush();
|
|
294
|
-
|
|
295
|
-
bloomPipeline.withColorAttachment(bloomAttachment).draw(6);
|
|
296
|
-
colorMaskPipeline.withColorAttachment(colorMaskAttachment).draw(6);
|
|
297
|
-
|
|
298
|
-
context.present();
|
|
299
|
-
frameRef.current = requestAnimationFrame(render);
|
|
300
|
-
};
|
|
301
|
-
frameRef.current = requestAnimationFrame(render);
|
|
302
|
-
|
|
303
|
-
return () => {
|
|
304
|
-
if (frameRef.current) cancelAnimationFrame(frameRef.current);
|
|
305
|
-
};
|
|
306
|
-
}, [
|
|
307
|
-
device,
|
|
308
|
-
context,
|
|
309
|
-
root,
|
|
310
|
-
presentationFormat,
|
|
311
|
-
imageTexture,
|
|
312
|
-
rotationShared,
|
|
313
|
-
bloomOptions,
|
|
314
|
-
colorMaskOptions,
|
|
315
|
-
]);
|
|
316
|
-
|
|
317
|
-
return (
|
|
318
|
-
<Canvas
|
|
319
|
-
ref={ref}
|
|
320
|
-
style={{ width, height, aspectRatio: width / height }}
|
|
321
|
-
transparent={Platform.OS === 'ios'}
|
|
322
|
-
/>
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
export { subscribeToOrientationChange, getAngleFromDimensions };
|
|
8
|
+
export {
|
|
9
|
+
subscribeToOrientationChange,
|
|
10
|
+
getAngleFromDimensions,
|
|
11
|
+
isLandscapeMode,
|
|
12
|
+
useOrientation,
|
|
13
|
+
};
|
|
14
|
+
export { Shine } from './components/Shine';
|
|
15
|
+
export { ShineGroup } from './components/ShineGroup';
|
|
16
|
+
export type { ShineProps } from './components/Shine';
|
|
17
|
+
export * from './utils/vector';
|
|
18
|
+
export type { V2d, V3d } from './types/vector';
|
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
import tgpu from 'typegpu';
|
|
1
|
+
import tgpu, { type ValidateBufferSchema } from 'typegpu';
|
|
2
2
|
import * as d from 'typegpu/data';
|
|
3
|
+
import type { BufferUsageType } from './resourceManagement/bufferManager';
|
|
3
4
|
|
|
4
5
|
export const textureBindGroupLayout = tgpu.bindGroupLayout({
|
|
5
6
|
texture: { texture: 'float', dimension: '2d', sampleType: 'float' },
|
|
6
7
|
sampler: { sampler: 'filtering' },
|
|
7
8
|
});
|
|
8
9
|
|
|
9
|
-
export const
|
|
10
|
+
export const maskTextureBindGroupLayout = tgpu.bindGroupLayout({
|
|
11
|
+
texture: { texture: 'float', dimension: '2d', sampleType: 'float' },
|
|
12
|
+
sampler: { sampler: 'filtering' },
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const rotationBindGroupLayout = tgpu.bindGroupLayout({
|
|
10
16
|
vec: { uniform: d.vec3f },
|
|
11
17
|
});
|
|
12
18
|
|
|
13
|
-
export const
|
|
19
|
+
export const glareSchema = d.struct({
|
|
14
20
|
glowPower: d.f32,
|
|
15
21
|
hueShiftAngleMax: d.f32,
|
|
16
22
|
hueShiftAngleMin: d.f32,
|
|
17
23
|
hueBlendPower: d.f32,
|
|
18
24
|
lightIntensity: d.f32,
|
|
19
|
-
|
|
25
|
+
glareIntensity: d.f32,
|
|
20
26
|
});
|
|
21
27
|
|
|
22
|
-
export type
|
|
28
|
+
export type GlareSchema = typeof glareSchema;
|
|
23
29
|
|
|
24
|
-
export const
|
|
25
|
-
|
|
30
|
+
export const glareBindGroupLayout = tgpu.bindGroupLayout({
|
|
31
|
+
glareOptions: { uniform: glareSchema },
|
|
26
32
|
});
|
|
27
33
|
|
|
28
34
|
export const colorMaskSchema = d.struct({
|
|
@@ -33,8 +39,39 @@ export const colorMaskSchema = d.struct({
|
|
|
33
39
|
}),
|
|
34
40
|
});
|
|
35
41
|
|
|
36
|
-
export type
|
|
42
|
+
export type ColorMaskSchema = typeof colorMaskSchema;
|
|
37
43
|
|
|
38
44
|
export const colorMaskBindGroupLayout = tgpu.bindGroupLayout({
|
|
39
45
|
mask: { uniform: colorMaskSchema },
|
|
40
46
|
});
|
|
47
|
+
|
|
48
|
+
export const bufferData = {
|
|
49
|
+
rotation: {
|
|
50
|
+
schema: d.vec3f,
|
|
51
|
+
usage: 'uniform',
|
|
52
|
+
},
|
|
53
|
+
glare: {
|
|
54
|
+
schema: glareSchema,
|
|
55
|
+
usage: 'uniform',
|
|
56
|
+
},
|
|
57
|
+
colorMask: {
|
|
58
|
+
schema: colorMaskSchema,
|
|
59
|
+
usage: 'uniform',
|
|
60
|
+
},
|
|
61
|
+
} as const satisfies Record<
|
|
62
|
+
string,
|
|
63
|
+
{ schema: ValidateBufferSchema<any>; usage: BufferUsageType }
|
|
64
|
+
>;
|
|
65
|
+
|
|
66
|
+
export type BufferData = typeof bufferData;
|
|
67
|
+
|
|
68
|
+
// export const holoSchema = d.struct({
|
|
69
|
+
// intensity: d.f32,
|
|
70
|
+
// waveCallback: WaveCallback, //TgpuFn<(uv: d.Vec2f) => d.Vec2f>,
|
|
71
|
+
// });
|
|
72
|
+
|
|
73
|
+
// export type holoSchema = typeof holoSchema;
|
|
74
|
+
|
|
75
|
+
// export const holoBindGroupLayout = tgpu.bindGroupLayout({
|
|
76
|
+
// holoOptions: { uniform: holoSchema },
|
|
77
|
+
// });
|
|
@@ -1,101 +1,86 @@
|
|
|
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,
|
|
12
14
|
ColorMask,
|
|
13
15
|
PartiallyOptional,
|
|
14
16
|
} from '../types/types';
|
|
15
17
|
import {
|
|
16
18
|
colorMaskToTyped,
|
|
17
|
-
|
|
19
|
+
createGlareOptions,
|
|
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
|
-
buffer: TgpuBuffer<d.Vec3f>
|
|
39
|
-
) =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
vec: buffer,
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
return rotationValuesBindGroup;
|
|
48
|
-
};
|
|
32
|
+
buffer: TgpuBuffer<d.Vec3f>
|
|
33
|
+
) =>
|
|
34
|
+
root.createBindGroup(rotationBindGroupLayout, {
|
|
35
|
+
vec: root.unwrap(buffer),
|
|
36
|
+
});
|
|
49
37
|
|
|
50
|
-
export const
|
|
38
|
+
export const createGlareOptionsBuffer = (
|
|
51
39
|
root: TgpuRoot,
|
|
52
|
-
initValues?: Partial<
|
|
53
|
-
) =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const bloomOptionsBuffer = root
|
|
58
|
-
.createBuffer(bloomOptionsSchema, bloomOptionsTyped)
|
|
40
|
+
initValues?: Partial<GlareOptions>
|
|
41
|
+
) =>
|
|
42
|
+
root
|
|
43
|
+
.createBuffer(glareSchema, mapToF32(createGlareOptions({ ...initValues })))
|
|
59
44
|
.$usage('uniform');
|
|
60
45
|
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const createBloomOptionsBindGroup = (
|
|
46
|
+
export const createGlareBindGroup = (
|
|
65
47
|
root: TgpuRoot,
|
|
66
|
-
buffer: TgpuBuffer<
|
|
67
|
-
) =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
bloomOptions: buffer,
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
return bloomOptionsBindGroup;
|
|
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
|
-
|
|
101
|
-
|
|
73
|
+
// export const crateHoloBuffer = (
|
|
74
|
+
// root: TgpuRoot,
|
|
75
|
+
// initValues: Partial<HoloOptions>
|
|
76
|
+
// ) => {
|
|
77
|
+
// const holoOptions: HoloOptions = createHoloOptions({ ...initValues });
|
|
78
|
+
// const holoOptionsTyped = {
|
|
79
|
+
// intensity: d.f32(holoOptions.intensity),
|
|
80
|
+
// waveCallback: holoOptions.waveCallback,
|
|
81
|
+
// };
|
|
82
|
+
|
|
83
|
+
// const holoBuffer = root
|
|
84
|
+
// .createBuffer(holoSchema, holoOptionsTyped)
|
|
85
|
+
// .$usage('uniform');
|
|
86
|
+
// };
|
|
@@ -27,9 +27,9 @@ const colorMaskFragment = tgpu['~unstable'].fragmentFn({
|
|
|
27
27
|
const upperCheck = std.all(std.le(color.xyz, maskedColorUpper));
|
|
28
28
|
const lowerCheck = std.all(std.ge(color.xyz, maskedColorLower));
|
|
29
29
|
if (upperCheck && lowerCheck) {
|
|
30
|
-
return color;
|
|
30
|
+
return d.vec4f(color.xyz, 0.0);
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
return d.vec4f(1.0);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
export default colorMaskFragment;
|