1
1
'use client' ;
2
2
3
- import { useRef } from 'react' ;
3
+ import { useEffect , useRef } from 'react' ;
4
4
import { Canvas , useFrame , useThree } from '@react-three/fiber' ;
5
5
import fragmentShader from './shaders/fragment.glsl' ;
6
6
import vertexShader from './shaders/vertex.glsl' ;
7
7
import * as THREE from 'three' ;
8
+ import { useTweaks } from 'use-tweaks' ;
8
9
9
- function Box ( props : any ) {
10
+ function Shader ( props : any ) {
10
11
const shaderRef = useRef < THREE . ShaderMaterial | null > ( null ) ;
11
12
const { viewport } = useThree ( ) ;
13
+ const { opacity } = useTweaks ( {
14
+ opacity : { value : 1 , min : 0 , max : 1 , step : 0.05 } ,
15
+ } ) ;
12
16
useFrame ( ( state ) => {
13
17
if ( shaderRef . current ) {
14
18
shaderRef . current . uniforms . uTime . value += 0.01 ;
19
+ shaderRef . current . uniforms . uOpacity . value = opacity ;
15
20
shaderRef . current . uniforms . uPointer . value = state . pointer ;
21
+ // console.log(opacity);
16
22
}
17
23
} ) ;
18
24
@@ -26,6 +32,7 @@ function Box(props: any) {
26
32
uniforms = { {
27
33
uTime : { value : 0.0 } ,
28
34
uPointer : { value : new THREE . Vector2 ( 0.5 , 0.5 ) } ,
35
+ uOpacity : { value : 0.0 } ,
29
36
} }
30
37
/>
31
38
</ mesh >
@@ -38,7 +45,7 @@ export default function Home() {
38
45
< Canvas orthographic >
39
46
< ambientLight intensity = { Math . PI / 2 } />
40
47
< pointLight position = { [ - 10 , - 10 , - 10 ] } decay = { 0 } intensity = { Math . PI } />
41
- < Box props = { { position : [ 0 , 0 , 0 ] } } />
48
+ < Shader props = { { position : [ 0 , 0 , 0 ] } } />
42
49
</ Canvas >
43
50
</ main >
44
51
) ;
0 commit comments