@@ -3,21 +3,19 @@ import { useFrame, extend, useThree } from "@react-three/fiber";
33import { usePerformanceMonitor } from "@react-three/drei" ;
44import { CONFIG , setGUI } from "./config" ;
55import { useGUI } from "@/utils/useGUI" ;
6- import {
7- FxTransparentMaterial ,
8- FxTransparentMaterialProps ,
9- } from "@/utils/fxTransparentMaterial" ;
6+ import { FxMaterial , FxMaterialProps } from "@/utils/fxMaterial" ;
107import {
118 useFluid ,
12- useFogProjection ,
9+ useBlending ,
1310 useNoise ,
11+ useBrightnessPicker ,
1412} from "@/packages/use-shader-fx/src" ;
1513
16- extend ( { FxTransparentMaterial } ) ;
14+ extend ( { FxMaterial } ) ;
1715
1816export const Home = ( ) => {
1917 const updateGUI = useGUI ( setGUI ) ;
20- const mainShaderRef = useRef < FxTransparentMaterialProps > ( ) ;
18+ const mainShaderRef = useRef < FxMaterialProps > ( ) ;
2119
2220 const { size, dpr } = useThree ( ( state ) => {
2321 return { size : state . size , dpr : state . viewport . dpr } ;
@@ -30,7 +28,9 @@ export const Home = () => {
3028 dpr,
3129 } ) ;
3230
33- const [ updateFogProjection ] = useFogProjection ( { size, dpr } ) ;
31+ const [ updateBlending ] = useBlending ( { size, dpr } ) ;
32+
33+ const [ updateBrightnessPicker ] = useBrightnessPicker ( { size, dpr } ) ;
3434
3535 usePerformanceMonitor ( {
3636 onChange ( { factor } ) {
@@ -42,7 +42,9 @@ export const Home = () => {
4242
4343 useFrame ( ( props ) => {
4444 const noise = updateNoise ( props , {
45- timeStrength : 0.4 ,
45+ scale : 0.002 ,
46+ timeStrength : 0.2 ,
47+ warpStrength : 2.0 ,
4648 } ) ;
4749
4850 const fx = updateFluid ( props , {
@@ -55,49 +57,57 @@ export const Home = () => {
5557 fluid_color : CONFIG . fluid . fluid_color ,
5658 } ) ;
5759
58- const postFx = updateFogProjection ( props , {
60+ const postFx = updateBlending ( props , {
5961 distortionStrength : CONFIG . fogProjection . distortionStrength ,
60- fogEdge0 : CONFIG . fogProjection . fogEdge0 ,
61- fogEdge1 : CONFIG . fogProjection . fogEdge1 ,
62- fogColor : CONFIG . fogProjection . fogColor ,
62+ edge0 : CONFIG . fogProjection . fogEdge0 ,
63+ edge1 : CONFIG . fogProjection . fogEdge1 ,
64+ color : CONFIG . fogProjection . fogColor ,
6365 texture : fx ,
64- noiseMap : noise ,
66+ map : noise ,
67+ } ) ;
68+
69+ const final = updateBrightnessPicker ( props , {
70+ texture : postFx ,
6571 } ) ;
6672
6773 const main = mainShaderRef . current ;
6874 if ( main ) {
69- main . u_fx = postFx ;
75+ main . u_fx = final ;
76+ main . u_alpha = 0.0 ;
7077 }
7178 updateGUI ( ) ;
7279 } ) ;
7380
7481 return (
7582 < mesh >
7683 < planeGeometry args = { [ 2 , 2 ] } />
77- < fxTransparentMaterial
78- key = { FxTransparentMaterial . key }
79- ref = { mainShaderRef }
80- />
84+ < fxMaterial ref = { mainShaderRef } />
8185 </ mesh >
8286 ) ;
8387} ;
8488
8589/*===============================================
86- the simplest demo
90+ playground
8791===============================================*/
8892
8993// import * as THREE from "three";
9094// import { useRef } from "react";
9195// import { useFrame, useThree } from "@react-three/fiber";
92- // import { useFluid } from "@hmng8/ use-shader-fx";
96+ // import { useNoise } from "@/packages/ use-shader-fx/src ";
9397
9498// export const Home = () => {
9599// const ref = useRef<THREE.ShaderMaterial>(null);
96100// const size = useThree((state) => state.size);
97101// const dpr = useThree((state) => state.viewport.dpr);
98- // const [updateFluid] = useFluid({ size, dpr });
102+ // const [updateNoise] = useNoise({ size, dpr });
103+
99104// useFrame((props) => {
100- // ref.current!.uniforms.u_fx.value = updateFluid(props);
105+ // ref.current!.uniforms.u_fx.value = updateNoise(props, {
106+ // scale: 0.002,
107+ // warpOctaves: 2,
108+ // timeStrength: 0.2,
109+ // warpStrength: 20.0,
110+ // });
101111// });
102112
103113// return (
@@ -116,10 +126,22 @@ the simplest demo
116126// precision highp float;
117127// varying vec2 vUv;
118128// uniform sampler2D u_fx;
119-
129+ // float sq(float x) {
130+ // return x*x*7.0;
131+ // }
120132// void main() {
121133// vec2 uv = vUv;
122- // gl_FragColor = texture2D(u_fx, uv);
134+ // vec3 noise = texture2D(u_fx, uv).rgb;
135+ // vec3 col;
136+ // vec2 p = noise.rg * .4;
137+ // for(float j = 0.0; j < 3.0; j++){
138+ // for(float i = 1.0; i < 8.0; i++){
139+ // p.x += 0.01 / (i + j) * cos(i * 10.0 * p.y + sin(i + j));
140+ // p.y += 0.01 / (i + j)* cos(i * 10.0 * p.x + sin(i + j));
141+ // }
142+ // col[int(j)] = sin(.5 * 7.0*sq(p.x)) + sin(7.0*sq(p.y));
143+ // }
144+ // gl_FragColor = vec4(col, 1.0);
123145// }
124146// `}
125147// uniforms={{
0 commit comments