Skip to content

Commit 548109b

Browse files
authored
Merge pull request #74 from FunTechInc/minor-update
Minor update
2 parents d9d0ec1 + fb198d4 commit 548109b

File tree

237 files changed

+6033
-2995
lines changed

Some content is hidden

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

237 files changed

+6033
-2995
lines changed

.storybook/constant.ts

-5
This file was deleted.

.storybook/public/app-head.jpg

689 KB
Loading

.storybook/public/favicon.ico

116 KB
Binary file not shown.

.storybook/public/logo.svg

+49-16
Loading

.storybook/public/thumbnail.jpg

561 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as React from "react";
2+
import type { StoryObj } from "@storybook/react";
3+
import { setArgTypes } from "../utils/setArgTypes";
4+
import { Setup } from "../utils/Setup";
5+
import type { Meta } from "@storybook/react";
6+
import { UseAlphaBlending } from "./UseAlphaBlending";
7+
import {
8+
ALPHABLENDING_PARAMS,
9+
AlphaBlendingParams,
10+
} from "../../packages/use-shader-fx/src/fxs/utils/useAlphaBlending";
11+
12+
const meta = {
13+
title: "utils/useAlphaBlending",
14+
component: UseAlphaBlending,
15+
tags: ["autodocs"],
16+
decorators: [(storyFn: any) => <Setup>{storyFn()}</Setup>],
17+
} satisfies Meta<typeof UseAlphaBlending>;
18+
export default meta;
19+
type Story = StoryObj<typeof meta>;
20+
21+
export const Default: Story = {
22+
args: ALPHABLENDING_PARAMS,
23+
argTypes: setArgTypes<AlphaBlendingParams>(ALPHABLENDING_PARAMS),
24+
};
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import * as React from "react";
2+
import * as THREE from "three";
3+
import { useFrame, useLoader, extend, useThree } from "@react-three/fiber";
4+
import { FxMaterial, FxMaterialProps } from "../../utils/fxMaterial";
5+
import GUI from "lil-gui";
6+
import { useGUI } from "../../utils/useGUI";
7+
import {
8+
useAlphaBlending,
9+
useMarble,
10+
useBrush,
11+
} from "../../packages/use-shader-fx/src";
12+
import {
13+
ALPHABLENDING_PARAMS,
14+
AlphaBlendingParams,
15+
} from "../../packages/use-shader-fx/src/fxs/utils/useAlphaBlending";
16+
17+
extend({ FxMaterial });
18+
19+
const CONFIG: AlphaBlendingParams = structuredClone(ALPHABLENDING_PARAMS);
20+
const setGUI = (gui: GUI) => {};
21+
const setConfig = () => {
22+
return {
23+
...CONFIG,
24+
} as AlphaBlendingParams;
25+
};
26+
27+
export const UseAlphaBlending = (args: AlphaBlendingParams) => {
28+
const updateGUI = useGUI(setGUI);
29+
const fxRef = React.useRef<FxMaterialProps>();
30+
const { size, dpr } = useThree((state) => {
31+
return { size: state.size, dpr: state.viewport.dpr };
32+
});
33+
34+
const [updateBrush, setBrush, { output: brush }] = useBrush({ size, dpr });
35+
const [update, set, { output }] = useAlphaBlending({ size, dpr });
36+
const [updateMarble, setMarble, { output: marble }] = useMarble({
37+
size,
38+
dpr,
39+
});
40+
41+
set({
42+
texture: marble,
43+
map: brush,
44+
});
45+
46+
useFrame((props) => {
47+
updateBrush(props);
48+
updateMarble(props);
49+
update(props);
50+
updateGUI();
51+
});
52+
53+
return (
54+
<mesh>
55+
<planeGeometry args={[2, 2]} />
56+
<fxMaterial
57+
key={FxMaterial.key}
58+
u_fx={output}
59+
u_alpha={0.0}
60+
ref={fxRef}
61+
/>
62+
</mesh>
63+
);
64+
};

.storybook/stories/UseBlending.tsx

+7-10
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ import * as React from "react";
22
import * as THREE from "three";
33
import { useFrame, useLoader, extend, useThree } from "@react-three/fiber";
44
import { FxMaterial, FxMaterialProps } from "../../utils/fxMaterial";
5-
import { CONSTANT } from "../constant";
65
import GUI from "lil-gui";
76
import { useGUI } from "../../utils/useGUI";
87
import {
98
useBlending,
10-
useFxTexture,
119
useNoise,
1210
useBrightnessPicker,
1311
useFluid,
12+
useCoverTexture,
1413
} from "../../packages/use-shader-fx/src";
1514
import {
1615
BlendingParams,
1716
BLENDING_PARAMS,
18-
} from "../../packages/use-shader-fx/src/hooks/useBlending";
17+
} from "../../packages/use-shader-fx/src/fxs/utils/useBlending";
1918

2019
extend({ FxMaterial });
2120

@@ -36,14 +35,13 @@ const setConfig = () => {
3635
*/
3736
export const UseBlending = (args: BlendingParams) => {
3837
const updateGUI = useGUI(setGUI);
39-
const [bg] = useLoader(THREE.TextureLoader, ["thumbnail.jpg"]);
38+
const [bg] = useLoader(THREE.TextureLoader, ["momo.jpg"]);
4039
const fxRef = React.useRef<FxMaterialProps>();
4140
const { size, dpr } = useThree((state) => {
4241
return { size: state.size, dpr: state.viewport.dpr };
4342
});
44-
const [updateFxTexture] = useFxTexture({ size, dpr });
45-
const [updateNoise] = useNoise({ size, dpr });
46-
const [updateFluid, setFluid] = useFluid({ size, dpr });
43+
const [updateCover] = useCoverTexture({ size, dpr });
44+
const [updateFluid, setFluid, { output: fluid }] = useFluid({ size, dpr });
4745
const [updateBlending, setBlending] = useBlending({ size, dpr });
4846
const [updateBrightnessPicker] = useBrightnessPicker({ size, dpr });
4947

@@ -65,9 +63,8 @@ export const UseBlending = (args: BlendingParams) => {
6563
});
6664

6765
useFrame((props) => {
68-
const bgTexture = updateFxTexture(props, {
69-
textureResolution: CONSTANT.textureResolution,
70-
texture0: bg,
66+
const bgTexture = updateCover(props, {
67+
texture: bg,
7168
});
7269
const fluid = updateFluid(props);
7370
const picked = updateBrightnessPicker(props, { texture: fluid });

.storybook/stories/UseBrightnessPicker.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import {
1212
BrightnessPickerParams,
1313
BRIGHTNESSPICKER_PARAMS,
14-
} from "../../packages/use-shader-fx/src/hooks/useBrightnessPicker";
14+
} from "../../packages/use-shader-fx/src/fxs/utils/useBrightnessPicker";
1515

1616
extend({ FxMaterial });
1717

.storybook/stories/UseBrush.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import { useFrame, extend, useThree, useLoader } from "@react-three/fiber";
44
import { FxMaterial, FxMaterialProps } from "../../utils/fxMaterial";
55
import GUI from "lil-gui";
66
import { useGUI } from "../../utils/useGUI";
7-
import { CONSTANT } from "../constant";
87
import { useBrush, useFxTexture } from "../../packages/use-shader-fx/src";
98
import {
109
BrushParams,
1110
BRUSH_PARAMS,
12-
} from "../../packages/use-shader-fx/src/hooks/useBrush";
11+
} from "../../packages/use-shader-fx/src/fxs/interactions/useBrush";
1312

1413
extend({ FxMaterial });
1514

@@ -57,16 +56,15 @@ export const UseBrushWithTexture = (args: BrushParams) => {
5756
return { size: state.size, dpr: state.viewport.dpr };
5857
});
5958
const [updateFxTexture] = useFxTexture({ size, dpr });
60-
const [updateBrush] = useBrush({ size, dpr });
59+
const [updateBrush, setBrush] = useBrush({ size, dpr });
6160

6261
useFrame((props) => {
6362
const bgTexture = updateFxTexture(props, {
64-
textureResolution: CONSTANT.textureResolution,
6563
texture0: bg,
6664
});
6765
const fx = updateBrush(props, {
68-
texture: bgTexture,
6966
...setConfig(),
67+
texture: bgTexture,
7068
});
7169
fxRef.current!.u_fx = fx;
7270
updateGUI();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as React from "react";
2+
import type { StoryObj } from "@storybook/react";
3+
import { setArgTypes } from "../utils/setArgTypes";
4+
import { Setup } from "../utils/Setup";
5+
import type { Meta } from "@storybook/react";
6+
import { UseChromaKey } from "./UseChromaKey";
7+
import {
8+
CHROMAKEY_PARAMS,
9+
ChromaKeyParams,
10+
} from "../../packages/use-shader-fx/src/fxs/misc/useChromaKey";
11+
12+
const meta = {
13+
title: "misc/useChromaKey",
14+
component: UseChromaKey,
15+
tags: ["autodocs"],
16+
decorators: [(storyFn: any) => <Setup>{storyFn()}</Setup>],
17+
} satisfies Meta<typeof UseChromaKey>;
18+
export default meta;
19+
type Story = StoryObj<typeof meta>;
20+
21+
export const Default: Story = {
22+
args: CHROMAKEY_PARAMS,
23+
argTypes: setArgTypes<ChromaKeyParams>(CHROMAKEY_PARAMS),
24+
};

.storybook/stories/UseChromaKey.tsx

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import * as React from "react";
2+
import * as THREE from "three";
3+
import { useFrame, useLoader, extend, useThree } from "@react-three/fiber";
4+
import { FxMaterial, FxMaterialProps } from "../../utils/fxMaterial";
5+
import GUI from "lil-gui";
6+
import { useGUI } from "../../utils/useGUI";
7+
import {
8+
useChromaKey,
9+
useCoverTexture,
10+
} from "../../packages/use-shader-fx/src";
11+
import {
12+
CHROMAKEY_PARAMS,
13+
ChromaKeyParams,
14+
} from "../../packages/use-shader-fx/src/fxs/misc/useChromaKey";
15+
16+
extend({ FxMaterial });
17+
18+
const CONFIG: ChromaKeyParams = structuredClone(CHROMAKEY_PARAMS);
19+
const setGUI = (gui: GUI) => {
20+
gui.addColor(CONFIG, "keyColor");
21+
gui.add(CONFIG, "similarity", 0, 1, 0.01);
22+
gui.add(CONFIG, "smoothness", 0, 1, 0.01);
23+
gui.add(CONFIG, "spill", 0, 1, 0.01);
24+
gui.addColor(CONFIG, "color");
25+
gui.add(CONFIG, "contrast", 0, 2, 0.01);
26+
gui.add(CONFIG, "brightness", 0, 2, 0.01);
27+
gui.add(CONFIG, "gamma", 0, 2, 0.01);
28+
};
29+
const setConfig = () => {
30+
return {
31+
...CONFIG,
32+
} as ChromaKeyParams;
33+
};
34+
35+
export const UseChromaKey = (args: ChromaKeyParams) => {
36+
const updateGUI = useGUI(setGUI);
37+
const [bg] = useLoader(THREE.TextureLoader, ["thumbnail.jpg"]);
38+
const fxRef = React.useRef<FxMaterialProps>();
39+
const { size, dpr } = useThree((state) => {
40+
return { size: state.size, dpr: state.viewport.dpr };
41+
});
42+
43+
const [update, set, { output }] = useChromaKey({ size, dpr });
44+
45+
const [updateCover, setCover, { output: cover }] = useCoverTexture({
46+
size,
47+
dpr,
48+
});
49+
50+
setCover({
51+
texture: bg,
52+
});
53+
54+
useFrame((props) => {
55+
updateCover(props);
56+
update(props, {
57+
...setConfig(),
58+
texture: cover,
59+
});
60+
updateGUI();
61+
});
62+
63+
return (
64+
<mesh>
65+
<planeGeometry args={[2, 2]} />
66+
<fxMaterial
67+
key={FxMaterial.key}
68+
u_fx={output}
69+
u_alpha={0.0}
70+
ref={fxRef}
71+
/>
72+
</mesh>
73+
);
74+
};

.storybook/stories/UseColorStrata.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useColorStrata, useNoise } from "../../packages/use-shader-fx/src";
88
import {
99
COLORSTRATA_PARAMS,
1010
ColorStrataParams,
11-
} from "../../packages/use-shader-fx/src/hooks/useColorStrata";
11+
} from "../../packages/use-shader-fx/src/fxs/noises/useColorStrata";
1212

1313
extend({ FxMaterial });
1414

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as React from "react";
2+
import type { StoryObj } from "@storybook/react";
3+
import { setArgTypes } from "../utils/setArgTypes";
4+
import { Setup } from "../utils/Setup";
5+
import type { Meta } from "@storybook/react";
6+
import { UseCoverTexture } from "./UseCoverTexture";
7+
import {
8+
COVERTEXTURE_PARAMS,
9+
CoverTextureParams,
10+
} from "../../packages/use-shader-fx/src/fxs/utils/useCoverTexture";
11+
12+
const meta = {
13+
title: "utils/useCoverTexture",
14+
component: UseCoverTexture,
15+
tags: ["autodocs"],
16+
decorators: [(storyFn: any) => <Setup>{storyFn()}</Setup>],
17+
} satisfies Meta<typeof UseCoverTexture>;
18+
export default meta;
19+
type Story = StoryObj<typeof meta>;
20+
21+
export const Default: Story = {
22+
args: COVERTEXTURE_PARAMS,
23+
argTypes: setArgTypes<CoverTextureParams>(COVERTEXTURE_PARAMS),
24+
};
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as React from "react";
2+
import * as THREE from "three";
3+
import { useFrame, useLoader, extend, useThree } from "@react-three/fiber";
4+
import { FxMaterial, FxMaterialProps } from "../../utils/fxMaterial";
5+
import GUI from "lil-gui";
6+
import { useGUI } from "../../utils/useGUI";
7+
import { useCoverTexture } from "../../packages/use-shader-fx/src";
8+
import {
9+
COVERTEXTURE_PARAMS,
10+
CoverTextureParams,
11+
} from "../../packages/use-shader-fx/src/fxs/utils/useCoverTexture";
12+
13+
extend({ FxMaterial });
14+
15+
const CONFIG: CoverTextureParams = structuredClone(COVERTEXTURE_PARAMS);
16+
const setGUI = (gui: GUI) => {};
17+
const setConfig = () => {
18+
return {
19+
...CONFIG,
20+
} as CoverTextureParams;
21+
};
22+
23+
/** The hook with `~~Texutre` calculates the texture resolution and canvas resolution and covers the texture. */
24+
export const UseCoverTexture = (args: CoverTextureParams) => {
25+
const [bg] = useLoader(THREE.TextureLoader, ["/momo.jpg"]);
26+
const updateGUI = useGUI(setGUI);
27+
const fxRef = React.useRef<FxMaterialProps>();
28+
const { size, dpr } = useThree((state) => {
29+
return { size: state.size, dpr: state.viewport.dpr };
30+
});
31+
32+
const [update, set, { output }] = useCoverTexture({ size, dpr });
33+
34+
set({
35+
texture: bg,
36+
});
37+
38+
useFrame((props) => {
39+
update(props);
40+
updateGUI();
41+
});
42+
43+
return (
44+
<mesh>
45+
<planeGeometry args={[2, 2]} />
46+
<fxMaterial
47+
key={FxMaterial.key}
48+
u_fx={output}
49+
u_alpha={0.0}
50+
ref={fxRef}
51+
/>
52+
</mesh>
53+
);
54+
};

0 commit comments

Comments
 (0)