Skip to content

Commit 8ea4701

Browse files
author
takuma-hmng8
committed
パッケージ化
1 parent a8562d7 commit 8ea4701

File tree

6,318 files changed

+2344357
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,318 files changed

+2344357
-232
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
![use-shader-fx](public/app.jpg)
2+
13
# Usage
24

35
それぞれの fxHook からは{updateFx,setParams,fxObject}を受け取ります。

app/fx/Scene.tsx

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,66 @@
1-
import { useEffect, useRef, useState } from "react";
1+
import { useRef } from "react";
22
import * as THREE from "three";
3-
import { useFrame, useLoader, extend } from "@react-three/fiber";
4-
import { RippleParams, useRipple } from "./hooks/useRipple";
5-
import { useFlowmap, FlowmapParams } from "./hooks/useFlowmap";
6-
import { useSimpleFruid } from "./hooks/useSimpleFruid";
7-
import { FruidParams, useFruid } from "./hooks/useFruid";
8-
import { useBrush } from "./hooks/useBrush";
9-
import { TransitionBgParams, useTransitionBg } from "./hooks/useTransitionBg";
3+
import { useRipple } from "@/packages/use-shader-fx/src";
4+
import { useFlowmap } from "@/packages/use-shader-fx/src";
5+
import { useSimpleFruid } from "@/packages/use-shader-fx/src";
6+
import { useFruid } from "@/packages/use-shader-fx/src";
7+
import { useBrush } from "@/packages/use-shader-fx/src";
8+
import { useTransitionBg } from "@/packages/use-shader-fx/src";
9+
import { useDuoTone } from "@/packages/use-shader-fx/src";
10+
import { useFogProjection } from "@/packages/use-shader-fx/src";
11+
import { useFrame, useLoader, extend, useThree } from "@react-three/fiber";
1012
import { MainShaderMaterial, TMainShaderUniforms } from "./ShaderMaterial";
13+
import { usePerformanceMonitor } from "@react-three/drei";
1114
import { useGUI } from "./gui/useGUI";
1215
import { CONFIG } from "./config";
13-
import { DuoToneParams, useDuoTone } from "./hooks/useDuoTone";
14-
import {
15-
FogProjectionParams,
16-
useFogProjection,
17-
} from "./hooks/useFogProjection";
18-
import { usePerformanceMonitor } from "@react-three/drei";
1916

2017
extend({ MainShaderMaterial });
2118

19+
/*===============================================
20+
TODO*
21+
- dprは入れ込んだほうがいいかも?
22+
- 初期値とGUIの整理
23+
- read meの整理
24+
- fx hookは配列で返すようにするか
25+
- 配列とオブジェクトの出ストラクチャリングについてちゃんとstyle bookにまとめよっと
26+
- いや、名前に意味があるし、拡張性的には、オブジェクトか?
27+
- usePointerは確実にオブジェクトで返すいのがいいよな。名前に意味があるし。順不同だから。
28+
- そう考えると、順は確定してるし、今後も増やす必要はないから(むしろそういう設計にしたほうがいい)、配列か
29+
===============================================*/
30+
2231
export const Scene = () => {
23-
const [bg, bg2, smoke, ripple, noise, pNoise] = useLoader(
24-
THREE.TextureLoader,
25-
[
26-
"background.jpg",
27-
"background2.jpeg",
28-
"smoke.png",
29-
"ripple.png",
30-
"noise.png",
31-
"p-noise.webp",
32-
]
33-
);
32+
const [bg, bg2, ripple, noise] = useLoader(THREE.TextureLoader, [
33+
"thumbnail.jpg",
34+
"momo.jpg",
35+
"ripple.png",
36+
"noise.png",
37+
]);
3438
const updateGUI = useGUI();
3539
const mainShaderRef = useRef<TMainShaderUniforms>();
3640

41+
const size = useThree((state) => state.size);
42+
const dpr = useThree((state) => state.viewport.dpr);
43+
3744
// fx
38-
const { updateFx: updateRipple } = useRipple({ texture: smoke });
39-
const { updateFx: updateFruid, setParams: setFruid } = useFruid();
40-
const { updateFx: updateFlowmap } = useFlowmap();
41-
const { updateFx: updateSimpleFruid } = useSimpleFruid();
42-
const { updateFx: updateBrush } = useBrush();
45+
const { updateFx: updateRipple } = useRipple({ texture: ripple, size });
46+
const { updateFx: updateFruid, setParams: setFruid } = useFruid({
47+
size,
48+
dpr,
49+
});
50+
const { updateFx: updateFlowmap } = useFlowmap({ size });
51+
const { updateFx: updateSimpleFruid } = useSimpleFruid({ size });
52+
const { updateFx: updateBrush } = useBrush({ size });
4353

4454
// post fx
45-
const { updateFx: updateTransitionBg } = useTransitionBg();
46-
const { updateFx: updateDuoTone } = useDuoTone();
47-
const { updateFx: updateFogProjection } = useFogProjection();
55+
const { updateFx: updateTransitionBg } = useTransitionBg({ size, dpr });
56+
const { updateFx: updateDuoTone } = useDuoTone({ size });
57+
const { updateFx: updateFogProjection } = useFogProjection({ size });
4858

4959
// Monitor performance changes and execute update functions of params
5060
usePerformanceMonitor({
51-
onChange(api) {
61+
onChange({ factor }) {
5262
setFruid({
53-
pressure_iterations: Math.round(20 * api.factor),
63+
pressure_iterations: Math.round(20 * factor),
5464
});
5565
},
5666
});
@@ -81,7 +91,7 @@ export const Scene = () => {
8191
break;
8292
case 2:
8393
fx = updateBrush(props, {
84-
texture: smoke,
94+
texture: ripple,
8595
radius: CONFIG.brush.radius,
8696
alpha: CONFIG.brush.alpha,
8797
smudge: CONFIG.brush.smudge,

app/fx/config.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export const CONFIG = {
88
transitionBg: {
99
noiseStrength: 0.0,
1010
progress: 0.0,
11-
dir: new THREE.Vector2(0.3, 0.2),
12-
imageResolution: new THREE.Vector2(1440, 1440),
13-
active: false,
11+
dir: new THREE.Vector2(0.3, 0.4),
12+
imageResolution: new THREE.Vector2(1440, 1029),
13+
active: true,
1414
transformDir: 1,
1515
transform: () => {
1616
CONFIG.transitionBg.transformDir =
@@ -21,12 +21,12 @@ export const CONFIG = {
2121
tl.to(CONFIG.transitionBg, {
2222
noiseStrength: 0.2,
2323
progress: 0.5,
24-
ease: "power3.in",
24+
ease: "power2.in",
2525
});
2626
tl.to(CONFIG.transitionBg, {
2727
noiseStrength: 0.0,
2828
progress: CONFIG.transitionBg.transformDir > 0 ? 0.0 : 1.0,
29-
ease: "power3.out",
29+
ease: "power2.out",
3030
});
3131
},
3232
},
@@ -36,11 +36,11 @@ export const CONFIG = {
3636
active: false,
3737
},
3838
fogProjection: {
39-
timeStrength: 0.2,
40-
distortionStrength: 0.1,
41-
fogEdge0: 0.0,
42-
fogEdge1: 0.9,
43-
fogColor: new THREE.Color(0xffffff),
39+
timeStrength: 0.23,
40+
distortionStrength: 0.04,
41+
fogEdge0: 0.43,
42+
fogEdge1: 0.88,
43+
fogColor: new THREE.Color(0xd5cea3),
4444
active: false,
4545
},
4646
/*===============================================
@@ -56,9 +56,9 @@ export const CONFIG = {
5656
fruid: {
5757
density_dissipation: 0.98,
5858
velocity_dissipation: 0.99,
59-
velocity_acceleration: 8.0,
59+
velocity_acceleration: 10.0,
6060
pressure_dissipation: 0.9,
61-
curl_strength: 4,
61+
curl_strength: 35,
6262
splat_radius: 0.002,
6363
fruidVec: new THREE.Vector3(),
6464
fruid_color: (velocity: THREE.Vector2) => {

app/fx/hooks/utils/useResolution.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

app/fx/index.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ import { PerformanceMonitor } from "@react-three/drei";
99
export const Fx = () => {
1010
const [dpr, setDpr] = useState(1.5);
1111
return (
12-
<>
13-
<Canvas dpr={dpr}>
14-
<PerformanceMonitor
15-
factor={1}
16-
onChange={({ factor }) =>
17-
setDpr(Math.round((0.5 + 1.5 * factor) * 10) / 10)
18-
}>
19-
<Suspense fallback={null}>
20-
<Scene />
21-
</Suspense>
22-
<Perf position={"bottom-right"} minimal={false} />
23-
</PerformanceMonitor>
24-
</Canvas>
25-
</>
12+
<Canvas dpr={dpr}>
13+
<PerformanceMonitor
14+
factor={1}
15+
onChange={({ factor }) => {
16+
console.log(`dpr:${dpr}`);
17+
setDpr(Math.round((0.5 + 1.5 * factor) * 10) / 10);
18+
}}>
19+
<Suspense fallback={null}>
20+
<Scene />
21+
</Suspense>
22+
<Perf position={"bottom-right"} minimal={false} />
23+
</PerformanceMonitor>
24+
</Canvas>
2625
);
2726
};

packages/use-shader-fx/.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules
2+
/src
3+
glsl.d.ts
4+
tsconfig.json

packages/use-shader-fx/README.md

Whitespace-only changes.

0 commit comments

Comments
 (0)