Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@ const [params, setParams] = useParams<HooksParams>;
}
```

## useCopyTexture

Generate an FBO array to copy the texture.

```tsx
const [renderTargets, copyTexture] = useCopyTexture(
{ scene, camera, size, dpr },
length
);
copyTexture(gl, index); // return texture
```

# Other Hooks

## useDomSyncer
Expand Down Expand Up @@ -254,6 +266,11 @@ useLayoutEffect(() => {
});
}, [state]);

const [, copyTexture] = useCopyTexture(
{ scene: fxTextureObj.scene, camera: fxTextureObj.camera, size, dpr },
domArr.current.length
);

useFrame((props) => {
const syncedTexture = updateDomSyncer(props, {
texture: [...Array(domArr.current.length)].map((_, i) => {
Expand All @@ -262,6 +279,7 @@ useFrame((props) => {
map: someFx,
texture0: someTexture,
});
return copyTexture(props.gl, i);
}
}),
resolution: [...Array(domArr.current.length)].map(() =>
Expand Down
15 changes: 12 additions & 3 deletions app/domSyncer/DomSyncer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as THREE from "three";
import { useLayoutEffect, useRef } from "react";
import { useEffect, useLayoutEffect, useRef } from "react";
import { useFrame, extend, useThree, useLoader } from "@react-three/fiber";
import { FxMaterial, FxMaterialProps } from "@/utils/fxMaterial";
import {
useDomSyncer,
useWave,
useFxTexture,
useCopyTexture,
} from "@/packages/use-shader-fx/src";
import { WaveParams } from "@/packages/use-shader-fx/src/hooks/useWave";
import gsap from "gsap";
Expand Down Expand Up @@ -36,7 +37,7 @@ export const DomSyncer = ({ state }: { state: number }) => {
const size = useThree((state) => state.size);
const dpr = useThree((state) => state.viewport.dpr);

const [updateFxTexture] = useFxTexture({ size, dpr });
const [updateFxTexture, , fxTextureObj] = useFxTexture({ size, dpr });
const [updateWave] = useWave({ size, dpr });

const [updateDomSyncer, setDomSyncer, domSyncerObj] = useDomSyncer(
Expand All @@ -48,6 +49,7 @@ export const DomSyncer = ({ state }: { state: number }) => {

useLayoutEffect(() => {
CONFIG.waveArr = [];

if (state === 0) {
domArr.current = [...document.querySelectorAll(".item")!];
} else {
Expand Down Expand Up @@ -83,11 +85,16 @@ export const DomSyncer = ({ state }: { state: number }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [state]);

const [, copyTexture] = useCopyTexture(
{ scene: fxTextureObj.scene, camera: fxTextureObj.camera, size, dpr },
domArr.current.length
);

useFrame((props) => {
const syncedTexture = updateDomSyncer(props, {
texture: [...Array(domArr.current.length)].map((_, i) => {
if (domSyncerObj.isIntersecting(i, false)) {
textureRef.current = updateFxTexture(props, {
updateFxTexture(props, {
padding: 0.0,
map: updateWave(props, {
epicenter: CONFIG.waveArr[i].epicenter,
Expand All @@ -99,6 +106,8 @@ export const DomSyncer = ({ state }: { state: number }) => {
textureResolution: CONFIG.textureResolution,
texture0: momo,
});

return copyTexture(props.gl, i);
}
return textureRef.current;
}),
Expand Down
2 changes: 1 addition & 1 deletion app/domSyncer/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function Page() {
key={i}
style={{
width: "calc(50% - 40px)",
height: "120vh",
height: "80vh",
zIndex: 100,
borderRadius: `${i * 50}px`,
}}></div>
Expand Down
Loading