Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions .storybook/stories/UseBlending.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
useBlending,
useFxTexture,
useNoise,
useFluid,
} from "../../packages/use-shader-fx/src";
import {
BlendingParams,
Expand All @@ -22,7 +23,6 @@ const setGUI = (gui: GUI) => {
gui.add(CONFIG, "mapIntensity", 0, 1, 0.01);
gui.add(CONFIG, "min", 0, 1, 0.01);
gui.add(CONFIG, "max", 0, 1, 0.01);
gui.addColor(CONFIG, "color");
};
const setConfig = () => {
return {
Expand All @@ -42,18 +42,36 @@ export const UseBlending = (args: BlendingParams) => {
});
const [updateFxTexture] = useFxTexture({ size, dpr });
const [updateNoise] = useNoise({ size, dpr });
const [updateBlending] = useBlending({ size, dpr });
const [updateFluid, setFluid] = useFluid({ size, dpr });
const [updateBlending, setBlending] = useBlending({ size, dpr });

const colorVec = React.useMemo(() => new THREE.Vector3(), []);

setFluid({
density_dissipation: 0.92,
velocity_dissipation: 0.99,
velocity_acceleration: 12.0,
splat_radius: 0.015,
curl_strength: 5.0,
pressure_iterations: 4,
fluid_color: (velocity: THREE.Vector2) => {
const rCol = Math.max(0.0, velocity.x * 150);
const gCol = Math.max(0.0, velocity.y * 150);
const bCol = Math.max(0.1, (rCol + gCol) / 2);
return colorVec.set(rCol, gCol, bCol);
},
});

useFrame((props) => {
const bgTexture = updateFxTexture(props, {
textureResolution: CONSTANT.textureResolution,
texture0: bg,
});
const noise = updateNoise(props);
const fluid = updateFluid(props);
const fx = updateBlending(props, {
...setConfig(),
texture: bgTexture,
map: noise,
map: fluid,
});
fxRef.current!.u_fx = fx;
updateGUI();
Expand Down
Loading