react-native-shine 0.0.0 → 0.2.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/LICENSE +20 -0
- package/README.md +159 -0
- package/lib/module/index.js +222 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/roots.js +16 -0
- package/lib/module/roots.js.map +1 -0
- package/lib/module/shaders/bindGroupLayouts.js +45 -0
- package/lib/module/shaders/bindGroupLayouts.js.map +1 -0
- package/lib/module/shaders/bindGroupUtils.js +45 -0
- package/lib/module/shaders/bindGroupUtils.js.map +1 -0
- package/lib/module/shaders/fragmentShaders/bloomFragment.js +66 -0
- package/lib/module/shaders/fragmentShaders/bloomFragment.js.map +1 -0
- package/lib/module/shaders/fragmentShaders/colorMaskFragment.js +28 -0
- package/lib/module/shaders/fragmentShaders/colorMaskFragment.js.map +1 -0
- package/lib/module/shaders/pipelineSetups.js +32 -0
- package/lib/module/shaders/pipelineSetups.js.map +1 -0
- package/lib/module/shaders/resourceManagement.js +19 -0
- package/lib/module/shaders/resourceManagement.js.map +1 -0
- package/lib/module/shaders/tgpuUtils.js +38 -0
- package/lib/module/shaders/tgpuUtils.js.map +1 -0
- package/lib/module/shaders/utils.js +65 -0
- package/lib/module/shaders/utils.js.map +1 -0
- package/lib/module/shaders/vertexShaders/mainVertex.js +35 -0
- package/lib/module/shaders/vertexShaders/mainVertex.js.map +1 -0
- package/lib/module/types/typeUtils.js +92 -0
- package/lib/module/types/typeUtils.js.map +1 -0
- package/lib/module/types/types.js +4 -0
- package/lib/module/types/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/index.d.ts +12 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/roots.d.ts +4 -0
- package/lib/typescript/src/roots.d.ts.map +1 -0
- package/lib/typescript/src/shaders/bindGroupLayouts.d.ts +57 -0
- package/lib/typescript/src/shaders/bindGroupLayouts.d.ts.map +1 -0
- package/lib/typescript/src/shaders/bindGroupUtils.d.ts +53 -0
- package/lib/typescript/src/shaders/bindGroupUtils.d.ts.map +1 -0
- package/lib/typescript/src/shaders/fragmentShaders/bloomFragment.d.ts +6 -0
- package/lib/typescript/src/shaders/fragmentShaders/bloomFragment.d.ts.map +1 -0
- package/lib/typescript/src/shaders/fragmentShaders/colorMaskFragment.d.ts +6 -0
- package/lib/typescript/src/shaders/fragmentShaders/colorMaskFragment.d.ts.map +1 -0
- package/lib/typescript/src/shaders/pipelineSetups.d.ts +8 -0
- package/lib/typescript/src/shaders/pipelineSetups.d.ts.map +1 -0
- package/lib/typescript/src/shaders/resourceManagement.d.ts +3 -0
- package/lib/typescript/src/shaders/resourceManagement.d.ts.map +1 -0
- package/lib/typescript/src/shaders/tgpuUtils.d.ts +6 -0
- package/lib/typescript/src/shaders/tgpuUtils.d.ts.map +1 -0
- package/lib/typescript/src/shaders/utils.d.ts +13 -0
- package/lib/typescript/src/shaders/utils.d.ts.map +1 -0
- package/lib/typescript/src/shaders/vertexShaders/mainVertex.d.ts +6 -0
- package/lib/typescript/src/shaders/vertexShaders/mainVertex.d.ts.map +1 -0
- package/lib/typescript/src/types/typeUtils.d.ts +17 -0
- package/lib/typescript/src/types/typeUtils.d.ts.map +1 -0
- package/lib/typescript/src/types/types.d.ts +33 -0
- package/lib/typescript/src/types/types.d.ts.map +1 -0
- package/package.json +160 -13
- package/src/index.tsx +326 -0
- package/src/roots.ts +16 -0
- package/src/shaders/bindGroupLayouts.ts +40 -0
- package/src/shaders/bindGroupUtils.ts +101 -0
- package/src/shaders/fragmentShaders/bloomFragment.ts +83 -0
- package/src/shaders/fragmentShaders/colorMaskFragment.ts +35 -0
- package/src/shaders/pipelineSetups.ts +44 -0
- package/src/shaders/resourceManagement.ts +22 -0
- package/src/shaders/tgpuUtils.ts +75 -0
- package/src/shaders/utils.ts +103 -0
- package/src/shaders/vertexShaders/mainVertex.ts +35 -0
- package/src/types/typeUtils.ts +122 -0
- package/src/types/types.ts +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 VoidFrog
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# react-native-shine
|
|
2
|
+
|
|
3
|
+
Fast and efficient way to add interactive GPU-based shader effects to your React Native apps using [TypeGPU](https://github.com/type-gpu/type-gpu) and [WebGPU](https://github.com/wojtus7/react-native-wgpu).
|
|
4
|
+
|
|
5
|
+
`react-native-shine` leverages powerful GPU execution via native bindings, delivering lovely, fancy and **shiny** effects—ideal for UIs or creative interactions.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ⚙️ Installation
|
|
10
|
+
|
|
11
|
+
Install the library:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
yarn add react-native-shine
|
|
15
|
+
# or
|
|
16
|
+
npm install react-native-shine
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
### 📦 Install Required Peer Dependencies
|
|
22
|
+
|
|
23
|
+
This library depends on several native modules that must be installed in your host app.
|
|
24
|
+
|
|
25
|
+
Install required peer dependencies with:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
yarn add react-native-reanimated react-native-worklets react-native-wgpu typegpu
|
|
29
|
+
# or
|
|
30
|
+
npm install react-native-reanimated react-native-worklets react-native-wgpu typegpu
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
These are not bundled with the library and must match compatible versions used by your app.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
### 🛠️ Optional: Auto-install Peer Dependencies
|
|
38
|
+
|
|
39
|
+
You can also use our helper script to install all peer deps automatically:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
yarn run install-peers
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Or use `install-peerdeps`:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
npx install-peerdeps react-native-shine
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
> Note: `install-peerdeps` reads the `peerDependencies` section of the package and installs them at the root level of your project.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### Update Your `babel.config.js`
|
|
56
|
+
|
|
57
|
+
For this library to work, you need to add the `unplugin-typegpu/babel` plugin. It comes bundled as a dependency, so you just need to add it in your Babel config.
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
plugins: ['unplugin-typegpu/babel'];
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For additional instructions, please follow the [TypeGPU Unplugin docs](https://docs.swmansion.com/TypeGPU/tooling/unplugin-typegpu/).
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 📋 Requirements
|
|
68
|
+
|
|
69
|
+
- React Native ≥ 0.71
|
|
70
|
+
- `react-native-reanimated` ≥ 4.0.0
|
|
71
|
+
- `react-native-webgpu` ≥ 0.2.0
|
|
72
|
+
- WebGPU-compatible device/emulator
|
|
73
|
+
|
|
74
|
+
> [!NOTE]
|
|
75
|
+
> If you’re using Expo, you’ll need to use the bare workflow (custom dev client or prebuild) to support native modules.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 🚀 Usage
|
|
80
|
+
|
|
81
|
+
Basic example:
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import { View } from 'react-native';
|
|
85
|
+
import { Shine } from 'react-native-shine';
|
|
86
|
+
|
|
87
|
+
export default function Index() {
|
|
88
|
+
return (
|
|
89
|
+
<View
|
|
90
|
+
style={{
|
|
91
|
+
flex: 1,
|
|
92
|
+
justifyContent: 'center',
|
|
93
|
+
alignItems: 'center',
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
<Shine
|
|
97
|
+
imageURI="https://assets.pkmn.gg/fit-in/600x836/filters:format(webp)/images/cards/dp7/dp7-101.png?signature=1354344def4514e05080d064310884cdd6a27ef93692d9656eda9ae84ae1b2e1"
|
|
98
|
+
width={300}
|
|
99
|
+
height={400}
|
|
100
|
+
/>
|
|
101
|
+
</View>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Coming soon: docs and examples.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 🧪 Troubleshooting
|
|
111
|
+
|
|
112
|
+
If you encounter runtime or build issues:
|
|
113
|
+
|
|
114
|
+
- Make sure all peer dependencies are installed.
|
|
115
|
+
- Rebuild your app after installing native modules:
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
# iOS
|
|
119
|
+
cd ios && xcodebuild clean && cd ..
|
|
120
|
+
npx react-native run-ios
|
|
121
|
+
|
|
122
|
+
# Android
|
|
123
|
+
cd android && ./gradlew clean && cd ..
|
|
124
|
+
npx react-native run-android
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
# Expo
|
|
129
|
+
|
|
130
|
+
# iOS
|
|
131
|
+
npx expo prebuild
|
|
132
|
+
npx expo run:ios
|
|
133
|
+
|
|
134
|
+
# Android
|
|
135
|
+
npx expo prebuild
|
|
136
|
+
npx expo run:android
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- Clear bundler cache (helps with Metro native linking issues).
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## 🧑💻 Contributing
|
|
144
|
+
|
|
145
|
+
Want to help improve `react-native-shine`?
|
|
146
|
+
|
|
147
|
+
Check out the [`CONTRIBUTING.md`](CONTRIBUTING.md) guide for instructions on how to build, test, and submit PRs.
|
|
148
|
+
|
|
149
|
+
We welcome shaders, GPU visual effects, demos, and bug fixes!
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## 📜 License
|
|
154
|
+
|
|
155
|
+
MIT © [VoidFrog](https://github.com/VoidFrog)
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
Made with ❤️ and [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { Canvas, useDevice, useGPUContext } from 'react-native-wgpu';
|
|
5
|
+
import { getOrInitRoot } from "./roots.js";
|
|
6
|
+
import mainVertex from "./shaders/vertexShaders/mainVertex.js";
|
|
7
|
+
import getBitmapFromURI from "./shaders/resourceManagement.js";
|
|
8
|
+
import { createTexture, loadTexture, clamp, rotate2D, subscribeToOrientationChange, getAngleFromDimensions } from "./shaders/utils.js";
|
|
9
|
+
import { bloomOptionsBindGroupLayout, colorMaskBindGroupLayout, rotationValuesBindGroupLayout, textureBindGroupLayout } from "./shaders/bindGroupLayouts.js";
|
|
10
|
+
import { SensorType, useAnimatedSensor, useDerivedValue, useSharedValue } from 'react-native-reanimated';
|
|
11
|
+
import * as d from 'typegpu/data';
|
|
12
|
+
import { Platform } from 'react-native';
|
|
13
|
+
import bloomFragment from "./shaders/fragmentShaders/bloomFragment.js";
|
|
14
|
+
import { createBloomOptionsBindGroup, createBloomOptionsBuffer, createColorMaskBindGroup, createColorMaskBuffer, createRotationBuffer, createRotationValuesBindGroup } from "./shaders/bindGroupUtils.js";
|
|
15
|
+
import { createBindGroupPairs, createBloomOptions, createColorMask } from "./types/typeUtils.js";
|
|
16
|
+
import { attachBindGroups, getDefaultTarget } from "./shaders/pipelineSetups.js";
|
|
17
|
+
import colorMaskFragment from "./shaders/fragmentShaders/colorMaskFragment.js";
|
|
18
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
|
+
export function Shine({
|
|
20
|
+
width,
|
|
21
|
+
height,
|
|
22
|
+
imageURI,
|
|
23
|
+
bloomOptions,
|
|
24
|
+
colorMaskOptions
|
|
25
|
+
}) {
|
|
26
|
+
const {
|
|
27
|
+
device = null
|
|
28
|
+
} = useDevice();
|
|
29
|
+
const root = device ? getOrInitRoot(device) : null;
|
|
30
|
+
const {
|
|
31
|
+
ref,
|
|
32
|
+
context
|
|
33
|
+
} = useGPUContext();
|
|
34
|
+
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
|
|
35
|
+
const frameRef = useRef(null);
|
|
36
|
+
const [imageTexture, setImageTexture] = useState(null);
|
|
37
|
+
const orientationAngle = useSharedValue(0); // degrees
|
|
38
|
+
const rotationShared = useSharedValue([0, 0, 0]); // final GPU offsets
|
|
39
|
+
|
|
40
|
+
// Calibration shared values (UI thread)
|
|
41
|
+
const initialGravity = useSharedValue([0, 0, 0]);
|
|
42
|
+
const calibSum = useSharedValue([0, 0, 0]);
|
|
43
|
+
const calibCount = useSharedValue(0);
|
|
44
|
+
const calibrated = useSharedValue(false);
|
|
45
|
+
const gravitySensor = useAnimatedSensor(SensorType.GRAVITY, {
|
|
46
|
+
interval: 20
|
|
47
|
+
});
|
|
48
|
+
console.log('render');
|
|
49
|
+
|
|
50
|
+
// Subscribe to orientation changes and reset calibration on change
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
orientationAngle.value = getAngleFromDimensions();
|
|
53
|
+
const unsubscribe = subscribeToOrientationChange(angleDeg => {
|
|
54
|
+
orientationAngle.value = angleDeg;
|
|
55
|
+
});
|
|
56
|
+
return () => unsubscribe();
|
|
57
|
+
}, [orientationAngle]);
|
|
58
|
+
|
|
59
|
+
// Calibration & mapping logic
|
|
60
|
+
useDerivedValue(() => {
|
|
61
|
+
'worklet';
|
|
62
|
+
|
|
63
|
+
// console.log(orientationAngle.value);
|
|
64
|
+
const v = gravitySensor.sensor?.value ?? gravitySensor.sensor.value ?? {
|
|
65
|
+
x: 0,
|
|
66
|
+
y: 0,
|
|
67
|
+
z: 0
|
|
68
|
+
};
|
|
69
|
+
const gx = v.x ?? 0;
|
|
70
|
+
const gy = v.y ?? 0;
|
|
71
|
+
const gz = v.z ?? 0;
|
|
72
|
+
const CALIBRATION_SAMPLES = 40;
|
|
73
|
+
const alpha = 0.15; // smoothing
|
|
74
|
+
const scale = 0.6;
|
|
75
|
+
if (!calibrated.value) {
|
|
76
|
+
// accumulate baseline in device coordinates
|
|
77
|
+
const s = calibSum.value;
|
|
78
|
+
const c = calibCount.value + 1;
|
|
79
|
+
calibSum.value = [s[0] + gx, s[1] + gy, s[2] + gz];
|
|
80
|
+
calibCount.value = c;
|
|
81
|
+
if (c >= CALIBRATION_SAMPLES) {
|
|
82
|
+
const avg = calibSum.value;
|
|
83
|
+
initialGravity.value = [avg[0] / c, avg[1] / c, avg[2] / c];
|
|
84
|
+
calibrated.value = true;
|
|
85
|
+
}
|
|
86
|
+
rotationShared.value = [0, 0, 0];
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const init = initialGravity.value;
|
|
90
|
+
const dx = gx - init[0];
|
|
91
|
+
const dy = gy - init[1];
|
|
92
|
+
const dz = gz - init[2];
|
|
93
|
+
|
|
94
|
+
// Rotate into screen coordinates so offsets auto-swap with orientation
|
|
95
|
+
const [mx, my] = rotate2D([dx, dy], -orientationAngle.value);
|
|
96
|
+
const screenX = mx;
|
|
97
|
+
const screenY = -my;
|
|
98
|
+
const prev = rotationShared.value;
|
|
99
|
+
const smoothX = prev[0] * (1 - alpha) + screenX * alpha;
|
|
100
|
+
const smoothY = prev[1] * (1 - alpha) + screenY * alpha;
|
|
101
|
+
const smoothZ = prev[2] * (1 - alpha) + dz * alpha;
|
|
102
|
+
if (orientationAngle.value === 90) {
|
|
103
|
+
rotationShared.value = [clamp(smoothY * scale, -1, 1), clamp(-smoothX * scale, -1, 1), clamp(smoothZ * scale, -1, 1)];
|
|
104
|
+
} else {
|
|
105
|
+
rotationShared.value = [clamp(smoothX * scale, -1, 1), clamp(smoothY * scale, -1, 1), clamp(smoothZ * scale, -1, 1)];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Resource setup
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!root || !device || !context) return;
|
|
112
|
+
(async () => {
|
|
113
|
+
const bitmap = await getBitmapFromURI(imageURI);
|
|
114
|
+
const texture = await createTexture(root, bitmap);
|
|
115
|
+
setImageTexture(texture);
|
|
116
|
+
await loadTexture(root, bitmap, texture);
|
|
117
|
+
})();
|
|
118
|
+
}, [root, device, context, imageURI]);
|
|
119
|
+
|
|
120
|
+
// Render loop
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (!root || !device || !context || !imageTexture) return;
|
|
123
|
+
context.configure({
|
|
124
|
+
device,
|
|
125
|
+
format: presentationFormat,
|
|
126
|
+
alphaMode: 'premultiplied'
|
|
127
|
+
});
|
|
128
|
+
const sampler = device.createSampler({
|
|
129
|
+
magFilter: 'linear',
|
|
130
|
+
minFilter: 'linear'
|
|
131
|
+
});
|
|
132
|
+
const textureBindGroup = root.createBindGroup(textureBindGroupLayout, {
|
|
133
|
+
texture: root.unwrap(imageTexture).createView(),
|
|
134
|
+
sampler
|
|
135
|
+
});
|
|
136
|
+
const rotationBuffer = createRotationBuffer(root);
|
|
137
|
+
const rotationBindGroup = createRotationValuesBindGroup(root, rotationBuffer);
|
|
138
|
+
const bloomOptionsBuffer = createBloomOptionsBuffer(root, createBloomOptions(bloomOptions ?? {}));
|
|
139
|
+
const bloomOptionsBindGroup = createBloomOptionsBindGroup(root, bloomOptionsBuffer);
|
|
140
|
+
const colorMaskBuffer = createColorMaskBuffer(root, createColorMask(colorMaskOptions ?? {
|
|
141
|
+
baseColor: [-20, -20, -20]
|
|
142
|
+
}));
|
|
143
|
+
const colorMaskBindGroup = createColorMaskBindGroup(root, colorMaskBuffer);
|
|
144
|
+
const bloomBGP = createBindGroupPairs([textureBindGroupLayout, rotationValuesBindGroupLayout, bloomOptionsBindGroupLayout, colorMaskBindGroupLayout], [textureBindGroup, rotationBindGroup, bloomOptionsBindGroup, colorMaskBindGroup]);
|
|
145
|
+
const maskBGP = createBindGroupPairs([textureBindGroupLayout, colorMaskBindGroupLayout], [textureBindGroup, colorMaskBindGroup]);
|
|
146
|
+
let bloomPipeline = root['~unstable'].withVertex(mainVertex, {}).withFragment(bloomFragment, getDefaultTarget(presentationFormat)).createPipeline();
|
|
147
|
+
bloomPipeline = attachBindGroups(bloomPipeline, bloomBGP);
|
|
148
|
+
let colorMaskPipeline = root['~unstable'].withVertex(mainVertex, {}).withFragment(colorMaskFragment, getDefaultTarget(presentationFormat)).createPipeline();
|
|
149
|
+
colorMaskPipeline = attachBindGroups(colorMaskPipeline, maskBGP);
|
|
150
|
+
const rot = d.vec3f(0.0);
|
|
151
|
+
let view;
|
|
152
|
+
let bloomAttachment;
|
|
153
|
+
let colorMaskAttachment;
|
|
154
|
+
const render = () => {
|
|
155
|
+
rot[0] = rotationShared.value[0];
|
|
156
|
+
rot[1] = rotationShared.value[1];
|
|
157
|
+
rot[2] = rotationShared.value[2];
|
|
158
|
+
rotationBuffer.write(rot);
|
|
159
|
+
view = context.getCurrentTexture().createView();
|
|
160
|
+
bloomAttachment = {
|
|
161
|
+
view: view,
|
|
162
|
+
clearValue: [0, 0, 0, 0],
|
|
163
|
+
loadOp: 'clear',
|
|
164
|
+
storeOp: 'store'
|
|
165
|
+
};
|
|
166
|
+
colorMaskAttachment = {
|
|
167
|
+
view: view,
|
|
168
|
+
loadOp: 'load',
|
|
169
|
+
storeOp: 'store'
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// root['~unstable'].beginRenderPass(
|
|
173
|
+
// {
|
|
174
|
+
// colorAttachments: [
|
|
175
|
+
// {
|
|
176
|
+
// view,
|
|
177
|
+
// clearValue: [0, 0, 0, 0],
|
|
178
|
+
// loadOp: 'clear',
|
|
179
|
+
// storeOp: 'store',
|
|
180
|
+
// },
|
|
181
|
+
// ],
|
|
182
|
+
// },
|
|
183
|
+
// (pass) => {
|
|
184
|
+
// pass.setPipeline(bloomPipeline);
|
|
185
|
+
// // pass = attachBindGroupsToPass(pass, bloomBGP);
|
|
186
|
+
// pass.setBindGroup(textureBindGroupLayout, textureBindGroup);
|
|
187
|
+
// pass.setBindGroup(rotationValuesBindGroupLayout, rotationBindGroup);
|
|
188
|
+
// pass.setBindGroup(bloomOptionsBindGroupLayout, bloomOptionsBindGroup);
|
|
189
|
+
// pass.setBindGroup(colorMaskBindGroupLayout, colorMaskBindGroup);
|
|
190
|
+
// pass.draw(6);
|
|
191
|
+
|
|
192
|
+
// // Mask draw
|
|
193
|
+
// pass.setPipeline(colorMaskPipeline);
|
|
194
|
+
// pass.setBindGroup(textureBindGroupLayout, textureBindGroup);
|
|
195
|
+
// pass.setBindGroup(colorMaskBindGroupLayout, colorMaskBindGroup);
|
|
196
|
+
// pass.draw(6);
|
|
197
|
+
// }
|
|
198
|
+
// );
|
|
199
|
+
// root['~unstable'].flush();
|
|
200
|
+
|
|
201
|
+
bloomPipeline.withColorAttachment(bloomAttachment).draw(6);
|
|
202
|
+
colorMaskPipeline.withColorAttachment(colorMaskAttachment).draw(6);
|
|
203
|
+
context.present();
|
|
204
|
+
frameRef.current = requestAnimationFrame(render);
|
|
205
|
+
};
|
|
206
|
+
frameRef.current = requestAnimationFrame(render);
|
|
207
|
+
return () => {
|
|
208
|
+
if (frameRef.current) cancelAnimationFrame(frameRef.current);
|
|
209
|
+
};
|
|
210
|
+
}, [device, context, root, presentationFormat, imageTexture, rotationShared, bloomOptions, colorMaskOptions]);
|
|
211
|
+
return /*#__PURE__*/_jsx(Canvas, {
|
|
212
|
+
ref: ref,
|
|
213
|
+
style: {
|
|
214
|
+
width,
|
|
215
|
+
height,
|
|
216
|
+
aspectRatio: width / height
|
|
217
|
+
},
|
|
218
|
+
transparent: Platform.OS === 'ios'
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
export { subscribeToOrientationChange, getAngleFromDimensions };
|
|
222
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","useState","Canvas","useDevice","useGPUContext","getOrInitRoot","mainVertex","getBitmapFromURI","createTexture","loadTexture","clamp","rotate2D","subscribeToOrientationChange","getAngleFromDimensions","bloomOptionsBindGroupLayout","colorMaskBindGroupLayout","rotationValuesBindGroupLayout","textureBindGroupLayout","SensorType","useAnimatedSensor","useDerivedValue","useSharedValue","d","Platform","bloomFragment","createBloomOptionsBindGroup","createBloomOptionsBuffer","createColorMaskBindGroup","createColorMaskBuffer","createRotationBuffer","createRotationValuesBindGroup","createBindGroupPairs","createBloomOptions","createColorMask","attachBindGroups","getDefaultTarget","colorMaskFragment","jsx","_jsx","Shine","width","height","imageURI","bloomOptions","colorMaskOptions","device","root","ref","context","presentationFormat","navigator","gpu","getPreferredCanvasFormat","frameRef","imageTexture","setImageTexture","orientationAngle","rotationShared","initialGravity","calibSum","calibCount","calibrated","gravitySensor","GRAVITY","interval","console","log","value","unsubscribe","angleDeg","v","sensor","x","y","z","gx","gy","gz","CALIBRATION_SAMPLES","alpha","scale","s","c","avg","init","dx","dy","dz","mx","my","screenX","screenY","prev","smoothX","smoothY","smoothZ","bitmap","texture","configure","format","alphaMode","sampler","createSampler","magFilter","minFilter","textureBindGroup","createBindGroup","unwrap","createView","rotationBuffer","rotationBindGroup","bloomOptionsBuffer","bloomOptionsBindGroup","colorMaskBuffer","baseColor","colorMaskBindGroup","bloomBGP","maskBGP","bloomPipeline","withVertex","withFragment","createPipeline","colorMaskPipeline","rot","vec3f","view","bloomAttachment","colorMaskAttachment","render","write","getCurrentTexture","clearValue","loadOp","storeOp","withColorAttachment","draw","present","current","requestAnimationFrame","cancelAnimationFrame","style","aspectRatio","transparent","OS"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACnD,SAASC,MAAM,EAAEC,SAAS,EAAEC,aAAa,QAAQ,mBAAmB;AACpE,SAASC,aAAa,QAAQ,YAAS;AACvC,OAAOC,UAAU,MAAM,uCAAoC;AAC3D,OAAOC,gBAAgB,MAAM,iCAA8B;AAC3D,SACEC,aAAa,EACbC,WAAW,EACXC,KAAK,EACLC,QAAQ,EACRC,4BAA4B,EAC5BC,sBAAsB,QACjB,oBAAiB;AAExB,SACEC,2BAA2B,EAC3BC,wBAAwB,EACxBC,6BAA6B,EAC7BC,sBAAsB,QACjB,+BAA4B;AACnC,SACEC,UAAU,EACVC,iBAAiB,EACjBC,eAAe,EACfC,cAAc,QACT,yBAAyB;AAChC,OAAO,KAAKC,CAAC,MAAM,cAAc;AACjC,SAASC,QAAQ,QAAQ,cAAc;AACvC,OAAOC,aAAa,MAAM,4CAAyC;AACnE,SACEC,2BAA2B,EAC3BC,wBAAwB,EACxBC,wBAAwB,EACxBC,qBAAqB,EACrBC,oBAAoB,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AAsB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { tgpu } from 'typegpu';
|
|
4
|
+
const deviceToRootMap = new WeakMap();
|
|
5
|
+
function getOrInitRoot(device) {
|
|
6
|
+
let root = deviceToRootMap.get(device);
|
|
7
|
+
if (!root) {
|
|
8
|
+
root = tgpu.initFromDevice({
|
|
9
|
+
device
|
|
10
|
+
});
|
|
11
|
+
deviceToRootMap.set(device, root);
|
|
12
|
+
}
|
|
13
|
+
return root;
|
|
14
|
+
}
|
|
15
|
+
export { getOrInitRoot };
|
|
16
|
+
//# sourceMappingURL=roots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["tgpu","deviceToRootMap","WeakMap","getOrInitRoot","device","root","get","initFromDevice","set"],"sourceRoot":"../../src","sources":["roots.ts"],"mappings":";;AAAA,SAASA,IAAI,QAAuB,SAAS;AAE7C,MAAMC,eAAe,GAAG,IAAIC,OAAO,CAAsB,CAAC;AAE1D,SAASC,aAAaA,CAACC,MAAiB,EAAY;EAClD,IAAIC,IAAI,GAAGJ,eAAe,CAACK,GAAG,CAACF,MAAM,CAAC;EAEtC,IAAI,CAACC,IAAI,EAAE;IACTA,IAAI,GAAGL,IAAI,CAACO,cAAc,CAAC;MAAEH;IAAO,CAAC,CAAC;IACtCH,eAAe,CAACO,GAAG,CAACJ,MAAM,EAAEC,IAAI,CAAC;EACnC;EAEA,OAAOA,IAAI;AACb;AAEA,SAASF,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import tgpu from 'typegpu';
|
|
4
|
+
import * as d from 'typegpu/data';
|
|
5
|
+
export const textureBindGroupLayout = tgpu.bindGroupLayout({
|
|
6
|
+
texture: {
|
|
7
|
+
texture: 'float',
|
|
8
|
+
dimension: '2d',
|
|
9
|
+
sampleType: 'float'
|
|
10
|
+
},
|
|
11
|
+
sampler: {
|
|
12
|
+
sampler: 'filtering'
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
export const rotationValuesBindGroupLayout = tgpu.bindGroupLayout({
|
|
16
|
+
vec: {
|
|
17
|
+
uniform: d.vec3f
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
export const bloomOptionsSchema = d.struct({
|
|
21
|
+
glowPower: d.f32,
|
|
22
|
+
hueShiftAngleMax: d.f32,
|
|
23
|
+
hueShiftAngleMin: d.f32,
|
|
24
|
+
hueBlendPower: d.f32,
|
|
25
|
+
lightIntensity: d.f32,
|
|
26
|
+
bloomIntensity: d.f32
|
|
27
|
+
});
|
|
28
|
+
export const bloomOptionsBindGroupLayout = tgpu.bindGroupLayout({
|
|
29
|
+
bloomOptions: {
|
|
30
|
+
uniform: bloomOptionsSchema
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
export const colorMaskSchema = d.struct({
|
|
34
|
+
baseColor: d.vec3f,
|
|
35
|
+
rgbToleranceRange: d.struct({
|
|
36
|
+
upper: d.vec3f,
|
|
37
|
+
lower: d.vec3f
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
export const colorMaskBindGroupLayout = tgpu.bindGroupLayout({
|
|
41
|
+
mask: {
|
|
42
|
+
uniform: colorMaskSchema
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=bindGroupLayouts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["tgpu","d","textureBindGroupLayout","bindGroupLayout","texture","dimension","sampleType","sampler","rotationValuesBindGroupLayout","vec","uniform","vec3f","bloomOptionsSchema","struct","glowPower","f32","hueShiftAngleMax","hueShiftAngleMin","hueBlendPower","lightIntensity","bloomIntensity","bloomOptionsBindGroupLayout","bloomOptions","colorMaskSchema","baseColor","rgbToleranceRange","upper","lower","colorMaskBindGroupLayout","mask"],"s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3D0B,IAAI,EAAE;IAAEnB,OAAO,EAAEa;EAAgB;AACnC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import * as d from 'typegpu/data';
|
|
4
|
+
import { bloomOptionsBindGroupLayout, bloomOptionsSchema, colorMaskBindGroupLayout, colorMaskSchema, rotationValuesBindGroupLayout } from "./bindGroupLayouts.js";
|
|
5
|
+
import { colorMaskToTyped, createBloomOptions, createColorMask, mapToF32 } from "../types/typeUtils.js";
|
|
6
|
+
export const createRotationBuffer = (root, initValues) => {
|
|
7
|
+
const init = initValues ? d.vec3f(initValues.x, initValues.y, initValues.z) : d.vec3f(0.0);
|
|
8
|
+
const rotationValuesBuffer = root.createBuffer(d.vec3f, init).$usage('uniform');
|
|
9
|
+
return rotationValuesBuffer;
|
|
10
|
+
};
|
|
11
|
+
export const createRotationValuesBindGroup = (root, buffer) => {
|
|
12
|
+
const rotationValuesBindGroup = root.createBindGroup(rotationValuesBindGroupLayout, {
|
|
13
|
+
vec: buffer
|
|
14
|
+
});
|
|
15
|
+
return rotationValuesBindGroup;
|
|
16
|
+
};
|
|
17
|
+
export const createBloomOptionsBuffer = (root, initValues) => {
|
|
18
|
+
const bloomOptions = createBloomOptions({
|
|
19
|
+
...initValues
|
|
20
|
+
});
|
|
21
|
+
const bloomOptionsTyped = mapToF32(bloomOptions);
|
|
22
|
+
const bloomOptionsBuffer = root.createBuffer(bloomOptionsSchema, bloomOptionsTyped).$usage('uniform');
|
|
23
|
+
return bloomOptionsBuffer;
|
|
24
|
+
};
|
|
25
|
+
export const createBloomOptionsBindGroup = (root, buffer) => {
|
|
26
|
+
const bloomOptionsBindGroup = root.createBindGroup(bloomOptionsBindGroupLayout, {
|
|
27
|
+
bloomOptions: buffer
|
|
28
|
+
});
|
|
29
|
+
return bloomOptionsBindGroup;
|
|
30
|
+
};
|
|
31
|
+
export const createColorMaskBuffer = (root, initValues) => {
|
|
32
|
+
const colorMask = createColorMask({
|
|
33
|
+
...initValues
|
|
34
|
+
});
|
|
35
|
+
const colorMaskTyped = colorMaskToTyped(colorMask);
|
|
36
|
+
const colorMaskBuffer = root.createBuffer(colorMaskSchema, colorMaskTyped).$usage('uniform');
|
|
37
|
+
return colorMaskBuffer;
|
|
38
|
+
};
|
|
39
|
+
export const createColorMaskBindGroup = (root, buffer) => {
|
|
40
|
+
const colorMaskBindGroup = root.createBindGroup(colorMaskBindGroupLayout, {
|
|
41
|
+
mask: buffer
|
|
42
|
+
});
|
|
43
|
+
return colorMaskBindGroup;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=bindGroupUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["d","bloomOptionsBindGroupLayout","bloomOptionsSchema","colorMaskBindGroupLayout","colorMaskSchema","rotationValuesBindGroupLayout","colorMaskToTyped","createBloomOptions","createColorMask","mapToF32","createRotationBuffer","root","initValues","init","vec3f","x","y","z","rotationValuesBuffer","createBuffer","$usage","createRotationValuesBindGroup","buffer","rotationValuesBindGroup","createBindGroup","vec","createBloomOptionsBuffer","bloomOptions","bloomOptionsTyped","bloomOptionsBuffer","createBloomOptionsBindGroup","bloomOptionsBindGroup","createColorMaskBuffer","colorMask","colorMaskTyped","colorMaskBuffer","createColorMaskBindGroup","colorMaskBindGroup","mask"],"sourceRoot":"../../../src","sources":["shaders/bindGroupUtils.ts"],"mappings":";;AACA,OAAO,KAAKA,CAAC,MAAM,cAAc;AACjC,SACEC,2BAA2B,EAC3BC,kBAAkB,EAClBC,wBAAwB,EACxBC,eAAe,EACfC,6BAA6B,QACxB,uBAAoB;AAM3B,SACEC,gBAAgB,EAChBC,kBAAkB,EAClBC,eAAe,EACfC,QAAQ,QACH,uBAAoB;AAE3B,OAAO,MAAMC,oBAAoB,GAAGA,CAClCC,IAAc,EACdC,UAAgD,KAC7C;EACH,MAAMC,IAAI,GAAGD,UAAU,GACnBZ,CAAC,CAACc,K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5B,gBAAgB,CAAC2B,SAAS,CAAC;EAElD,MAAME,eAAe,GAAGxB,IAAI,CACzBQ,YAAY,CAACf,eAAe,EAAE8B,cAAc,CAAC,CAC7Cd,MAAM,CAAC,SAAS,CAAC;EAEpB,OAAOe,eAAe;AACxB,CAAC;AAED,OAAO,MAAMC,wBAAwB,GAAGA,CACtCzB,IAAc,EACdW,MAAiD,KAC9C;EACH,MAAMe,kBAAkB,GAAG1B,IAAI,CAACa,eAAe,CAACrB,wBAAwB,EAAE;IACxEmC,IAAI,EAAEhB;EACR,CAAC,CAAC;EAEF,OAAOe,kBAAkB;AAC3B,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import tgpu from 'typegpu';
|
|
4
|
+
import * as d from 'typegpu/data';
|
|
5
|
+
import * as std from 'typegpu/std';
|
|
6
|
+
import { rotationValuesBindGroupLayout, textureBindGroupLayout, bloomOptionsBindGroupLayout, colorMaskBindGroupLayout } from "../bindGroupLayouts.js";
|
|
7
|
+
import { bloomColorShift, hueShift, overlayChannels } from "../tgpuUtils.js";
|
|
8
|
+
const bloomFragment = tgpu['~unstable'].fragmentFn({
|
|
9
|
+
in: {
|
|
10
|
+
uv: d.vec2f
|
|
11
|
+
},
|
|
12
|
+
out: d.vec4f
|
|
13
|
+
})(input => {
|
|
14
|
+
const texcoord = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
15
|
+
const uv = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
16
|
+
const centeredCoords = std.sub(std.mul(uv, 2.0), 1); //-1 to 1
|
|
17
|
+
|
|
18
|
+
const rot = rotationValuesBindGroupLayout.$.vec;
|
|
19
|
+
const center = std.add(d.vec2f(0.0), d.vec2f(rot.x, rot.y));
|
|
20
|
+
const bloomOptions = bloomOptionsBindGroupLayout.$.bloomOptions;
|
|
21
|
+
const bloomIntensity = bloomOptions.bloomIntensity;
|
|
22
|
+
const glowPower = bloomOptions.glowPower;
|
|
23
|
+
const hueBlendPower = bloomOptions.hueBlendPower;
|
|
24
|
+
const hueShiftAngleMax = bloomOptions.hueShiftAngleMax;
|
|
25
|
+
const hueShiftAngleMin = bloomOptions.hueShiftAngleMin;
|
|
26
|
+
const lightIntensity = bloomOptions.lightIntensity;
|
|
27
|
+
const mask = colorMaskBindGroupLayout.$.mask;
|
|
28
|
+
const maskedColor = mask.baseColor;
|
|
29
|
+
const rgbToleranceRange = mask.rgbToleranceRange;
|
|
30
|
+
let color = std.textureSample(textureBindGroupLayout.$.texture, textureBindGroupLayout.$.sampler, texcoord);
|
|
31
|
+
const maskedColorLower = std.sub(maskedColor, rgbToleranceRange.lower);
|
|
32
|
+
const maskedColorUpper = std.add(maskedColor, rgbToleranceRange.upper);
|
|
33
|
+
const upperCheck = std.all(std.le(color.xyz, maskedColorUpper));
|
|
34
|
+
const lowerCheck = std.all(std.ge(color.xyz, maskedColorLower));
|
|
35
|
+
if (upperCheck && lowerCheck) {
|
|
36
|
+
return color;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//bloomIntensity
|
|
40
|
+
const dst = std.exp(-std.distance(center, centeredCoords));
|
|
41
|
+
const distToCenter = std.smoothstep(0.0, 1 / bloomIntensity, dst);
|
|
42
|
+
|
|
43
|
+
//glowPower
|
|
44
|
+
let glow = d.vec3f(distToCenter);
|
|
45
|
+
glow = std.mul(glow, glowPower * color.w);
|
|
46
|
+
|
|
47
|
+
//hueBlend
|
|
48
|
+
const hueBlend = d.f32(hueBlendPower) * dst / 10.0;
|
|
49
|
+
|
|
50
|
+
//lightIntensity
|
|
51
|
+
glow = std.add(glow, lightIntensity / 10.0);
|
|
52
|
+
let shiftedRGB = bloomColorShift(color.xyz, dst / (lightIntensity * 2));
|
|
53
|
+
|
|
54
|
+
//hueShiftAngleMin/Max
|
|
55
|
+
const hueShiftAngle = std.smoothstep(hueShiftAngleMin, hueShiftAngleMax, distToCenter);
|
|
56
|
+
const shiftedHue = hueShift(shiftedRGB, hueShiftAngle);
|
|
57
|
+
shiftedRGB = overlayChannels(shiftedRGB, shiftedHue);
|
|
58
|
+
color = d.vec4f(std.mix(color.xyz, shiftedRGB, hueBlend), color.w);
|
|
59
|
+
const baseColor = color;
|
|
60
|
+
const blendColor = glow;
|
|
61
|
+
const combined = overlayChannels(baseColor.xyz, blendColor);
|
|
62
|
+
color = d.vec4f(std.mix(color.xyz, combined, glow), color.w);
|
|
63
|
+
return color;
|
|
64
|
+
});
|
|
65
|
+
export default bloomFragment;
|
|
66
|
+
//# sourceMappingURL=bloomFragment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["tgpu","d","std","rotationValuesBindGroupLayout","textureBindGroupLayout","bloomOptionsBindGroupLayout","colorMaskBindGroupLayout","bloomColorShift","hueShift","overlayChannels","bloomFragment","fragmentFn","in","uv","vec2f","out","vec4f","input","texcoord","x","y","centeredCoords","sub","mul","rot","$","vec","center","add","bloomOptions","bloomIntensity","glowPower","hueBlendPower","hueShiftAngleMax","hueShiftAngleMin","lightIntensity","mask","maskedColor","baseColor","rgbToleranceRange","color","textureSample","texture","sampler","maskedColorLower","lower","maskedColorUpper","upper","upperCheck","all","le","xyz","lowerCheck","ge","dst","exp","distance","distToCenter","smoothstep","glow","vec3f","w","hueBlend","f32","shiftedRGB","hueShiftAngle","shiftedHue","mix","blendColor","combined"],"sourceRoot":"../../../../src","sources":["shaders/fragmentShaders/bloomFragment.ts"],"mappings":";;AAAA,OAAOA,IAAI,MAAM,SAAS;AAC1B,OAAO,KAAKC,CAAC,MAAM,cAAc;AACjC,OAAO,KAAKC,GAAG,MAAM,aAAa;AAClC,SACEC,6BAA6B,EAC7BC,sBAAsB,EACtBC,2BAA2B,EAC3BC,wBAAwB,QACnB,wBAAqB;AAC5B,SAASC,eAAe,EAAEC,QAAQ,EAAEC,eAAe,QAAQ,iBAAc;AAEzE,MAAMC,aAAa,GAAGV,IAAI,CAAC,WAAW,CAAC,CAACW,UAAU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,GAAI,IAAI;;EAEpD;EACAK,IAAI,GAAGzD,GAAG,CAAC0B,GAAG,CAAC+B,IAAI,EAAExB,cAAc,GAAG,IAAI,CAAC;EAC3C,IAAI6B,UAAU,GAAGzD,eAAe,CAACiC,KAAK,CAACW,GAAG,EAAEG,GAAG,IAAInB,cAAc,GAAG,CAAC,CAAC,CAAC;;EAEvE;EACA,MAAM8B,aAAa,GAAG/D,GAAG,CAACwD,UAAU,CAClCxB,gBAAgB,EAChBD,gBAAgB,EAChBwB,YACF,CAAC;EACD,MAAMS,UAAU,GAAG1D,QAAQ,CAACwD,UAAU,EAAEC,aAAa,CAAC;EACtDD,UAAU,GAAGvD,eAAe,CAACuD,UAAU,EAAEE,UAAU,CAAC;EAEpD1B,KAAK,GAAGvC,CAAC,CAACe,KAAK,CAACd,GAAG,CAACiE,GAAG,CAAC3B,KAAK,CAACW,GAAG,EAAEa,UAAU,EAAEF,QAAQ,CAAC,EAAEtB,KAAK,CAACqB,CAAC,CAAC;EAClE,MAAMvB,SAAS,GAAGE,KAAK;EACvB,MAAM4B,UAAU,GAAGT,IAAI;EAEvB,MAAMU,QAAQ,GAAG5D,eAAe,CAAC6B,SAAS,CAACa,GAAG,EAAEiB,UAAU,CAAC;EAC3D5B,KAAK,GAAGvC,CAAC,CAACe,KAAK,CAACd,GAAG,CAACiE,GAAG,CAAC3B,KAAK,CAACW,GAAG,EAAEkB,QAAQ,EAAEV,IAAI,CAAC,EAAEnB,KAAK,CAACqB,CAAC,CAAC;EAE5D,OAAOrB,KAAK;AACd,CAAC,CAAC;AAEF,eAAe9B,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import tgpu from 'typegpu';
|
|
4
|
+
import * as d from 'typegpu/data';
|
|
5
|
+
import * as std from 'typegpu/std';
|
|
6
|
+
import { textureBindGroupLayout, colorMaskBindGroupLayout } from "../bindGroupLayouts.js";
|
|
7
|
+
const colorMaskFragment = tgpu['~unstable'].fragmentFn({
|
|
8
|
+
in: {
|
|
9
|
+
uv: d.vec2f
|
|
10
|
+
},
|
|
11
|
+
out: d.vec4f
|
|
12
|
+
})(input => {
|
|
13
|
+
const texcoord = d.vec2f(input.uv.x, 1.0 - input.uv.y);
|
|
14
|
+
const mask = colorMaskBindGroupLayout.$.mask;
|
|
15
|
+
const maskedColor = mask.baseColor;
|
|
16
|
+
const rgbToleranceRange = mask.rgbToleranceRange;
|
|
17
|
+
let color = std.textureSample(textureBindGroupLayout.$.texture, textureBindGroupLayout.$.sampler, texcoord);
|
|
18
|
+
const maskedColorLower = std.sub(maskedColor, rgbToleranceRange.lower);
|
|
19
|
+
const maskedColorUpper = std.add(maskedColor, rgbToleranceRange.upper);
|
|
20
|
+
const upperCheck = std.all(std.le(color.xyz, maskedColorUpper));
|
|
21
|
+
const lowerCheck = std.all(std.ge(color.xyz, maskedColorLower));
|
|
22
|
+
if (upperCheck && lowerCheck) {
|
|
23
|
+
return color;
|
|
24
|
+
}
|
|
25
|
+
std.discard();
|
|
26
|
+
});
|
|
27
|
+
export default colorMaskFragment;
|
|
28
|
+
//# sourceMappingURL=colorMaskFragment.js.map
|