Skip to content

Commit f3c610e

Browse files
authored
Merge pull request #94 from FunTechInc/v1.1.13
V1.1.13
2 parents b2bbd88 + d2c61ad commit f3c610e

File tree

87 files changed

+1887
-1710
lines changed

Some content is hidden

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

87 files changed

+1887
-1710
lines changed

README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ From each `fxHooks`, you can receive [`updateFx`, `setParams`, `fxObject`] in ar
6868
const [updateFx, setParams, fxObject] = useSomeFx(config);
6969
```
7070

71-
Execute `updateFx` in `useFrame`. The first argument receives the RootState from `useFrame`, and the second one takes `HookPrams`. Each fx has its `HookPrams`, and each type is exported.
71+
invoke `updateFx` in `useFrame`. The first argument receives the RootState from `useFrame`, and the second one takes `HookPrams`. Each fx has its `HookPrams`, and each type is exported.
7272

7373
```js
7474
useFrame((props) => {
@@ -288,6 +288,29 @@ usePerformanceMonitor({
288288
});
289289
```
290290

291+
When using some expensive FX (such as `useFluid`), lowering the `dpr` of the FBO of that FX can improve performance.
292+
293+
```js
294+
const [updateFx, setParams, fxObject] = useSomeFx({ size, dpr: 0.01 });
295+
```
296+
297+
Also, you can make more detailed adjustments by passing an object to `dpr` instead of `number`.
298+
299+
```ts
300+
type Dpr =
301+
| number
302+
| {
303+
dpr: number;
304+
/** you can set whether `dpr` affects `shader` and `fbo`. default is `true` for both */
305+
effect?: {
306+
/** default : `true` */
307+
shader?: boolean;
308+
/** default : `true` */
309+
fbo?: boolean;
310+
};
311+
};
312+
```
313+
291314
# Misc
292315

293316
## useDomSyncer

app/ShaderFx.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export const ShaderFx = ({
5353
setDpr(Math.round((1.0 + 1.0 * factor) * 10) / 10);
5454
}}>
5555
{children}
56-
{/* <Suspense fallback={null}>{children}</Suspense> */}
5756
{/* <Perf position={"bottom-left"} minimal={false} /> */}
5857
</PerformanceMonitor>
5958
</Canvas>

app/playground/FxMaterial.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ export const FxMaterial = shaderMaterial(
3131
uniform sampler2D u_fx;
3232
3333
void main() {
34-
gl_FragColor = texture2D(u_fx,vUv);
35-
// gl_FragColor = vec4(1.,1.,0.,1.);
34+
vec2 uv = vUv;
35+
vec4 color = texture2D(u_fx, uv);
36+
gl_FragColor = color;
37+
// gl_FragColor.rgb = color.rgb;
38+
// gl_FragColor.a = color.r + color.g + color.b;
3639
}
3740
`
3841
);

app/playground/Playground.tsx

+39-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,57 @@
11
"use client";
22

33
import * as THREE from "three";
4-
import { useEffect, useMemo } from "react";
4+
import { useEffect, useMemo, useRef, useState } from "react";
55
import { useFrame, useThree, extend, useLoader } from "@react-three/fiber";
6-
import { useFluid } from "@/packages/use-shader-fx/src";
6+
import {
7+
useCoverTexture,
8+
useFluid,
9+
useSingleFBO,
10+
} from "@/packages/use-shader-fx/src";
711
import { FxMaterial } from "./FxMaterial";
812

913
extend({ FxMaterial });
1014

1115
export const Playground = () => {
1216
const { size, viewport, camera } = useThree();
1317

14-
const [updateFluid, , { output }] = useFluid({ size, dpr: viewport.dpr });
18+
const [funkun] = useLoader(THREE.TextureLoader, ["/funkun.jpg"]);
19+
20+
const [updateCover, setCover, { output: cover }] = useCoverTexture({
21+
size,
22+
dpr: 0.01,
23+
});
24+
setCover({
25+
texture: funkun,
26+
});
27+
28+
const [updateFluid, setFluid, { output: fluid }] = useFluid({
29+
size,
30+
dpr: {
31+
dpr: 0.08,
32+
effect: {
33+
fbo: false,
34+
},
35+
},
36+
});
37+
38+
setFluid({
39+
density_dissipation: 0.99,
40+
velocity_dissipation: 0.99,
41+
splat_radius: 0.001,
42+
});
1543

1644
useFrame((props) => {
17-
updateFluid(props);
45+
updateCover(props);
46+
// updateFluid(props);
1847
});
1948

2049
return (
21-
<mesh>
22-
<planeGeometry args={[2, 2]} />
23-
<fxMaterial u_fx={output} key={FxMaterial.key} />
24-
</mesh>
50+
<>
51+
<mesh>
52+
<planeGeometry args={[2, 2]} />
53+
<fxMaterial u_fx={cover} key={FxMaterial.key} />
54+
</mesh>
55+
</>
2556
);
2657
};

app/useMorphParticles/Playground.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const Playground = () => {
120120
// map: funkun,
121121
// alphaMap: funkunAlpha,
122122
beat: b.beat,
123-
morphProgress: Math.max(Math.sin(props.clock.getElapsedTime() / 2), 0),
123+
// morphProgress: Math.max(Math.sin(props.clock.getElapsedTime() / 2), 0),
124124
// morphProgress: 0.5,
125125
});
126126
updateGUI();

0 commit comments

Comments
 (0)