Skip to content

Commit 5c8ca3e

Browse files
authored
Merge pull request #61 from takuma-hmng8/dev
update README
2 parents 8fcc38b + c72ff83 commit 5c8ca3e

File tree

34 files changed

+444
-413
lines changed

34 files changed

+444
-413
lines changed

README.md

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ From each `fxHooks`, you can receive [`updateFx`, `setParams`, `fxObject`] in ar
1515

1616
1. `updateFx` - A function to be invoked inside `useFrame`, returning a `THREE.Texture`.
1717
2. `setParams` - A function to refresh the parameters, beneficial for performance tweaking, etc.
18-
3. `fxObject` - An object that holds various FX components, such as scene, camera, material, and renderTarget.
18+
3. `fxObject` - An object that holds various FX components, such as scene, camera, material,renderTarget, and `output`(final rendered texture).
1919

2020
```js
2121
const [updateFx, setParams, fxObject] = useSomeFx(config);
@@ -43,13 +43,11 @@ import { useRef } from "react";
4343
import { useFrame, useThree } from "@react-three/fiber";
4444
import { useFluid } from "@hmng8/use-shader-fx";
4545

46-
export const Demo = () => {
46+
export const Home = () => {
4747
const ref = useRef<THREE.ShaderMaterial>(null);
4848
const { size, viewport } = useThree();
49-
const [updateFluid] = useFluid({ size, dpr: viewport.dpr });
50-
useFrame((props) => {
51-
ref.current!.uniforms.u_fx.value = updateFluid(props);
52-
});
49+
const [updateFluid, , { output }] = useFluid({ size, dpr: viewport.dpr });
50+
useFrame((props) => updateFluid(props));
5351

5452
return (
5553
<mesh>
@@ -74,7 +72,7 @@ export const Demo = () => {
7472
}
7573
`}
7674
uniforms={{
77-
u_fx: { value: null },
75+
u_fx: { value: output },
7876
}}
7977
/>
8078
</mesh>
@@ -121,22 +119,16 @@ function Box(props: any) {
121119
export const Home = () => {
122120
const ref = useRef<THREE.ShaderMaterial>(null);
123121
const { size, viewport, camera } = useThree();
124-
const [updateNoise, setNoise] = useNoise({ size, dpr: viewport.dpr });
125-
126-
setNoise({
127-
scale: 0.01,
128-
warpOctaves: 1,
129-
noiseOctaves: 1,
130-
fbmOctaves: 1,
131-
timeStrength: 1.2,
132-
warpStrength: 20.0,
122+
const [updateNoise, , { output }] = useNoise({
123+
size,
124+
dpr: viewport.dpr,
133125
});
134126

135127
// This scene is rendered offscreen
136128
const offscreenScene = useMemo(() => new THREE.Scene(), []);
137129

138130
// create FBO for offscreen rendering
139-
const [_, updateRenderTarget] = useSingleFBO({
131+
const [boxView, updateRenderTarget] = useSingleFBO({
140132
scene: offscreenScene,
141133
camera,
142134
size,
@@ -145,9 +137,8 @@ export const Home = () => {
145137
});
146138

147139
useFrame((props) => {
148-
const noise = updateNoise(props);
149-
ref.current!.uniforms.u_fx.value = noise;
150-
ref.current!.uniforms.u_texture.value = updateRenderTarget(props.gl);
140+
updateNoise(props);
141+
updateRenderTarget(props.gl);
151142
});
152143

153144
return (
@@ -201,8 +192,8 @@ export const Home = () => {
201192
}
202193
`}
203194
uniforms={{
204-
u_texture: { value: null },
205-
u_fx: { value: null },
195+
u_texture: { value: boxView.texture },
196+
u_fx: { value: output },
206197
}}
207198
/>
208199
</mesh>

app/_home/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const Home = () => {
8585
const offscreenScene = useMemo(() => new THREE.Scene(), []);
8686

8787
// create FBO for offscreen rendering
88-
const [_, updateRenderTarget] = useSingleFBO({
88+
const [boxView, updateRenderTarget] = useSingleFBO({
8989
scene: offscreenScene,
9090
camera,
9191
size,
@@ -95,9 +95,8 @@ export const Home = () => {
9595

9696
useFrame((props) => {
9797
const noise = updateNoise(props);
98-
const fluid = updateFluid(props);
9998
const blending = updateFxBlending(props, {
100-
texture: fluid,
99+
texture: updateFluid(props),
101100
map: noise,
102101
});
103102
const picked = updateBrightnessPicker(props, {
@@ -107,8 +106,8 @@ export const Home = () => {
107106
texture: picked,
108107
noise: noise,
109108
});
109+
updateRenderTarget(props.gl);
110110
ref.current!.uniforms.u_fx.value = colorStrata;
111-
ref.current!.uniforms.u_texture.value = updateRenderTarget(props.gl);
112111
});
113112

114113
return (
@@ -173,7 +172,7 @@ export const Home = () => {
173172
}
174173
`}
175174
uniforms={{
176-
u_texture: { value: null },
175+
u_texture: { value: boxView.texture },
177176
u_fx: { value: null },
178177
}}
179178
/>

0 commit comments

Comments
 (0)