Skip to content

Commit 00c0f9c

Browse files
authored
Merge pull request #52 from takuma-hmng8/dev
update demo site
2 parents 97b5ac7 + 3dbb4f7 commit 00c0f9c

File tree

1 file changed

+23
-134
lines changed

1 file changed

+23
-134
lines changed

app/_home/index.tsx

+23-134
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as THREE from "three";
2-
import { useMemo, useRef, useState, useEffect } from "react";
3-
import { useFrame, useThree } from "@react-three/fiber";
2+
import { useMemo, useRef, useState } from "react";
3+
import { useFrame, useThree, createPortal } from "@react-three/fiber";
44
import {
55
useNoise,
66
useFluid,
@@ -82,17 +82,14 @@ export const Home = () => {
8282

8383
// This scene is rendered offscreen
8484
const offscreenScene = useMemo(() => new THREE.Scene(), []);
85-
const offscreenMesh = useRef<THREE.Mesh>(null);
85+
8686
// create FBO for offscreen rendering
8787
const [_, updateRenderTarget] = useSingleFBO({
8888
scene: offscreenScene,
8989
camera,
9090
size,
9191
dpr: viewport.dpr,
9292
});
93-
useEffect(() => {
94-
offscreenScene.add(offscreenMesh.current!);
95-
}, [offscreenScene]);
9693

9794
useFrame((props) => {
9895
const noise = updateNoise(props);
@@ -114,23 +111,26 @@ export const Home = () => {
114111

115112
return (
116113
<>
117-
<mesh ref={offscreenMesh}>
118-
<ambientLight intensity={Math.PI} />
119-
<spotLight
120-
position={[10, 10, 10]}
121-
angle={0.15}
122-
penumbra={1}
123-
decay={0}
124-
intensity={Math.PI}
125-
/>
126-
<pointLight
127-
position={[-10, -10, -10]}
128-
decay={0}
129-
intensity={Math.PI}
130-
/>
131-
<Box position={[-1.5, 0, 0]} />
132-
<Box position={[1.5, 0, 0]} />
133-
</mesh>
114+
{createPortal(
115+
<mesh>
116+
<ambientLight intensity={Math.PI} />
117+
<spotLight
118+
position={[10, 10, 10]}
119+
angle={0.15}
120+
penumbra={1}
121+
decay={0}
122+
intensity={Math.PI}
123+
/>
124+
<pointLight
125+
position={[-10, -10, -10]}
126+
decay={0}
127+
intensity={Math.PI}
128+
/>
129+
<Box position={[-1.5, 0, 0]} />
130+
<Box position={[1.5, 0, 0]} />
131+
</mesh>,
132+
offscreenScene
133+
)}
134134
<mesh>
135135
<planeGeometry args={[2, 2]} />
136136
<shaderMaterial
@@ -179,114 +179,3 @@ export const Home = () => {
179179
</>
180180
);
181181
};
182-
183-
// import * as THREE from "three";
184-
// import { useEffect, useMemo, useRef, useState } from "react";
185-
// import { useFrame, useThree } from "@react-three/fiber";
186-
// import { useNoise, useSingleFBO } from "@/packages/use-shader-fx/src";
187-
188-
// function Box(props: any) {
189-
// // This reference will give us direct access to the mesh
190-
// const meshRef = useRef<THREE.Mesh>();
191-
// // Set up state for the hovered and active state
192-
// const [hovered, setHover] = useState(false);
193-
// const [active, setActive] = useState(false);
194-
// // Subscribe this component to the render-loop, rotate the mesh every frame
195-
// useFrame((state, delta) => (meshRef.current!.rotation.x += delta));
196-
// // Return view, these are regular three.js elements expressed in JSX
197-
// return (
198-
// <mesh
199-
// {...props}
200-
// ref={meshRef}
201-
// scale={active ? 1.5 : 1}
202-
// onClick={(event) => setActive(!active)}
203-
// onPointerOver={(event) => setHover(true)}
204-
// onPointerOut={(event) => setHover(false)}>
205-
// <boxGeometry args={[1, 1, 1]} />
206-
// <meshStandardMaterial color={hovered ? "hotpink" : "orange"} />
207-
// </mesh>
208-
// );
209-
// }
210-
211-
// export const Home = () => {
212-
// const { size, viewport, camera, gl } = useThree();
213-
214-
// // This scene is rendered offscreen
215-
// const offscreenScene = useMemo(() => new THREE.Scene(), []);
216-
// const offscreenMesh = useRef<THREE.Mesh>(null);
217-
// // create FBO for offscreen rendering
218-
// const [_, updateRenderTarget] = useSingleFBO({
219-
// scene: offscreenScene,
220-
// camera,
221-
// size,
222-
// dpr: viewport.dpr,
223-
// });
224-
// useEffect(() => {
225-
// offscreenScene.add(offscreenMesh.current!);
226-
// }, [offscreenScene]);
227-
228-
// // generate noise
229-
// const shaderMaterial = useRef<THREE.ShaderMaterial>(null);
230-
// const [updateNoise] = useNoise({ size, dpr: viewport.dpr });
231-
232-
// useFrame((props) => {
233-
// shaderMaterial.current!.uniforms.u_fx.value = updateNoise(props);
234-
// shaderMaterial.current!.uniforms.u_texture.value = updateRenderTarget(gl);
235-
// });
236-
237-
// return (
238-
// <>
239-
// <mesh ref={offscreenMesh}>
240-
// <ambientLight intensity={Math.PI / 2} />
241-
// <spotLight
242-
// position={[10, 10, 10]}
243-
// angle={0.15}
244-
// penumbra={1}
245-
// decay={0}
246-
// intensity={Math.PI}
247-
// />
248-
// <pointLight
249-
// position={[-10, -10, -10]}
250-
// decay={0}
251-
// intensity={Math.PI}
252-
// />
253-
// <Box position={[-1.2, 0, 0]} />
254-
// <Box position={[1.2, 0, 0]} />
255-
// </mesh>
256-
// <mesh>
257-
// <planeGeometry args={[2, 2]} />
258-
// <shaderMaterial
259-
// ref={shaderMaterial}
260-
// transparent
261-
// vertexShader={`
262-
// varying vec2 vUv;
263-
// void main() {
264-
// vUv = uv;
265-
// gl_Position = vec4(position, 1.0);
266-
// }
267-
// `}
268-
// fragmentShader={`
269-
// precision highp float;
270-
// varying vec2 vUv;
271-
// uniform sampler2D u_fx;
272-
// uniform sampler2D u_texture;
273-
274-
// void main() {
275-
// vec2 uv = vUv;
276-
// vec3 noiseMap = texture2D(u_fx, uv).rgb;
277-
// vec3 nNoiseMap = noiseMap * 2.0 - 1.0;
278-
// uv = uv * 2.0 - 1.0;
279-
// uv *= mix(vec2(1.0), abs(nNoiseMap.rg), .6);
280-
// uv = (uv + 1.0) / 2.0;
281-
// gl_FragColor = texture2D(u_texture, uv);
282-
// }
283-
// `}
284-
// uniforms={{
285-
// u_texture: { value: null },
286-
// u_fx: { value: null },
287-
// }}
288-
// />
289-
// </mesh>
290-
// </>
291-
// );
292-
// };

0 commit comments

Comments
 (0)