Spaces:
Running
Running
File size: 891 Bytes
01488bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import * as THREE from "three";
import { useFBO, type FboProps } from "@react-three/drei";
import { useRef } from "react";
type FBO = {
read: THREE.WebGLRenderTarget;
write: THREE.WebGLRenderTarget;
swap: () => void;
dispose: () => void;
setGenerateMipmaps: (value: boolean) => void;
};
export const useDoubleFBO = (
width: number,
height: number,
options: FboProps,
) => {
const read = useFBO(width, height, options);
const write = useFBO(width, height, options);
const fbo = useRef<FBO>({
read,
write,
swap: () => {
const temp = fbo.read;
fbo.read = fbo.write;
fbo.write = temp;
},
dispose: () => {
read.dispose();
write.dispose();
},
setGenerateMipmaps: (value: boolean) => {
read.texture.generateMipmaps = value;
write.texture.generateMipmaps = value;
},
}).current;
return fbo;
};
|