99 useBlending ,
1010 useFxTexture ,
1111 useNoise ,
12+ useFluid ,
1213} from "../../packages/use-shader-fx/src" ;
1314import {
1415 BlendingParams ,
@@ -22,7 +23,6 @@ const setGUI = (gui: GUI) => {
2223 gui . add ( CONFIG , "mapIntensity" , 0 , 1 , 0.01 ) ;
2324 gui . add ( CONFIG , "min" , 0 , 1 , 0.01 ) ;
2425 gui . add ( CONFIG , "max" , 0 , 1 , 0.01 ) ;
25- gui . addColor ( CONFIG , "color" ) ;
2626} ;
2727const setConfig = ( ) => {
2828 return {
@@ -42,18 +42,36 @@ export const UseBlending = (args: BlendingParams) => {
4242 } ) ;
4343 const [ updateFxTexture ] = useFxTexture ( { size, dpr } ) ;
4444 const [ updateNoise ] = useNoise ( { size, dpr } ) ;
45- const [ updateBlending ] = useBlending ( { size, dpr } ) ;
45+ const [ updateFluid , setFluid ] = useFluid ( { size, dpr } ) ;
46+ const [ updateBlending , setBlending ] = useBlending ( { size, dpr } ) ;
47+
48+ const colorVec = React . useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
49+
50+ setFluid ( {
51+ density_dissipation : 0.92 ,
52+ velocity_dissipation : 0.99 ,
53+ velocity_acceleration : 12.0 ,
54+ splat_radius : 0.015 ,
55+ curl_strength : 5.0 ,
56+ pressure_iterations : 4 ,
57+ fluid_color : ( velocity : THREE . Vector2 ) => {
58+ const rCol = Math . max ( 0.0 , velocity . x * 150 ) ;
59+ const gCol = Math . max ( 0.0 , velocity . y * 150 ) ;
60+ const bCol = Math . max ( 0.1 , ( rCol + gCol ) / 2 ) ;
61+ return colorVec . set ( rCol , gCol , bCol ) ;
62+ } ,
63+ } ) ;
4664
4765 useFrame ( ( props ) => {
4866 const bgTexture = updateFxTexture ( props , {
4967 textureResolution : CONSTANT . textureResolution ,
5068 texture0 : bg ,
5169 } ) ;
52- const noise = updateNoise ( props ) ;
70+ const fluid = updateFluid ( props ) ;
5371 const fx = updateBlending ( props , {
5472 ...setConfig ( ) ,
5573 texture : bgTexture ,
56- map : noise ,
74+ map : fluid ,
5775 } ) ;
5876 fxRef . current ! . u_fx = fx ;
5977 updateGUI ( ) ;
0 commit comments