Skip to content

Commit 1e1e19d

Browse files
author
takuma-hmng8
committed
pointerにlerpを追加する
1 parent d1046a5 commit 1e1e19d

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

app/useBrush/Playground.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export const Playground = () => {
4242
const [updateAlphaBlending, setAlphaBlending, { output: alphaBlending }] =
4343
useAlphaBlending({ size, dpr: viewport.dpr });
4444

45+
const [updateFluid, setFluid, { output: fluid }] = useFluid({
46+
size,
47+
dpr: viewport.dpr,
48+
});
49+
4550
const [updateCS, setCS, { output: cs }] = useColorStrata({
4651
size,
4752
dpr: viewport.dpr,
@@ -61,13 +66,13 @@ export const Playground = () => {
6166
});
6267

6368
setBrush({
64-
map: cs,
65-
texture: cs,
66-
mapIntensity: 0.2,
67-
radius: 0.05,
68-
smudge: 4,
69+
// map: cs,
70+
// texture: cs,
71+
// mapIntensity: 0.2,
72+
radius: 0.2,
73+
// smudge: 4,
6974
// motionBlur: 5,
70-
dissipation: 0.8,
75+
dissipation: 0.9,
7176
isCursor: false,
7277
});
7378

@@ -88,21 +93,23 @@ export const Playground = () => {
8893
// });
8994
const pointerValues = updatePointer(props.pointer);
9095
updateBrush(props, {
91-
// pressure: Easing.easeOutCirc(pointerValues.velocity.length() * 10) * 2,
9296
pointerValues: pointerValues,
9397
});
9498
// updateMarble(props);
9599
// updateAlphaBlending(props);
96-
const { beat, fract, floor, hash } = updateBeat(props.clock);
97-
updateCS(props, {
98-
beat: beat,
99-
});
100+
// const { beat, fract, floor, hash } = updateBeat(props.clock);
101+
// updateCS(props, {
102+
// beat: beat,
103+
// });
104+
// updateFluid(props, {
105+
// pointerValues: pointerValues,
106+
// });
100107
});
101108

102109
return (
103110
<mesh>
104111
<planeGeometry args={[2, 2]} />
105-
<fxMaterial key={FxMaterial.key} u_tex={cs} ref={ref} />
112+
<fxMaterial key={FxMaterial.key} u_tex={brush} ref={ref} />
106113
</mesh>
107114
);
108115
};

packages/use-shader-fx/src/utils/usePointer.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,21 @@ export const usePointer = (): UpdatePointer => {
1919
const velocity = useRef(new THREE.Vector2(0, 0));
2020
const isMoved = useRef(false);
2121

22+
// TODO : lerp
23+
const lerpPointer = useRef(new THREE.Vector2(0, 0));
24+
2225
const updatePointer = useCallback((currentPointer: THREE.Vector2) => {
2326
const now = performance.now();
24-
const current = currentPointer.clone();
27+
28+
// TODO : ラープの処理もっと洗練させる
29+
let current: THREE.Vector2;
30+
if (!isMoved.current) {
31+
current = currentPointer.clone();
32+
lerpPointer.current = current;
33+
} else {
34+
lerpPointer.current = lerpPointer.current.lerp(currentPointer, 0.1);
35+
current = lerpPointer.current.clone();
36+
}
2537

2638
// first frame
2739
if (lastUpdateTime.current === 0) {

0 commit comments

Comments
 (0)