9
9
useBlending ,
10
10
useFxTexture ,
11
11
useNoise ,
12
+ useFluid ,
12
13
} from "../../packages/use-shader-fx/src" ;
13
14
import {
14
15
BlendingParams ,
@@ -22,7 +23,6 @@ const setGUI = (gui: GUI) => {
22
23
gui . add ( CONFIG , "mapIntensity" , 0 , 1 , 0.01 ) ;
23
24
gui . add ( CONFIG , "min" , 0 , 1 , 0.01 ) ;
24
25
gui . add ( CONFIG , "max" , 0 , 1 , 0.01 ) ;
25
- gui . addColor ( CONFIG , "color" ) ;
26
26
} ;
27
27
const setConfig = ( ) => {
28
28
return {
@@ -42,18 +42,36 @@ export const UseBlending = (args: BlendingParams) => {
42
42
} ) ;
43
43
const [ updateFxTexture ] = useFxTexture ( { size, dpr } ) ;
44
44
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
+ } ) ;
46
64
47
65
useFrame ( ( props ) => {
48
66
const bgTexture = updateFxTexture ( props , {
49
67
textureResolution : CONSTANT . textureResolution ,
50
68
texture0 : bg ,
51
69
} ) ;
52
- const noise = updateNoise ( props ) ;
70
+ const fluid = updateFluid ( props ) ;
53
71
const fx = updateBlending ( props , {
54
72
...setConfig ( ) ,
55
73
texture : bgTexture ,
56
- map : noise ,
74
+ map : fluid ,
57
75
} ) ;
58
76
fxRef . current ! . u_fx = fx ;
59
77
updateGUI ( ) ;
0 commit comments