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
13 changes: 7 additions & 6 deletions .storybook/stories/UseColorStrata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useFrame, extend, useThree } from "@react-three/fiber";
import { FxMaterial, FxMaterialProps } from "../../utils/fxMaterial";
import GUI from "lil-gui";
import { useGUI } from "../../utils/useGUI";
import { useColorStrata, useNoise } from "../../packages/use-shader-fx/src";
import { useColorStrata } from "../../packages/use-shader-fx/src";
import {
COLORSTRATA_PARAMS,
ColorStrataParams,
Expand All @@ -13,8 +13,10 @@ import {
extend({ FxMaterial });

const CONFIG: ColorStrataParams = structuredClone(COLORSTRATA_PARAMS);

const setGUI = (gui: GUI) => {
gui.add(CONFIG, "laminateLayer", 0, 10, 1);
gui.add(CONFIG, "laminateLayer", 0, 20, 1);
gui.add(CONFIG, "scale", 0, 1, 0.01);
const laminateInterval = gui.addFolder("laminateInterval");
laminateInterval.add(CONFIG.laminateInterval!, "x", 0, 2, 0.01);
laminateInterval.add(CONFIG.laminateInterval!, "y", 0, 2, 0.01);
Expand All @@ -28,6 +30,9 @@ const setGUI = (gui: GUI) => {
colorFactor.add(CONFIG.colorFactor!, "x", 0, 10, 0.01);
colorFactor.add(CONFIG.colorFactor!, "y", 0, 10, 0.01);
colorFactor.add(CONFIG.colorFactor!, "z", 0, 10, 0.01);
const timeStrength = gui.addFolder("timeStrength");
timeStrength.add(CONFIG.timeStrength!, "x", 0, 2, 0.01);
timeStrength.add(CONFIG.timeStrength!, "y", 0, 2, 0.01);
};
const setConfig = () => {
return {
Expand Down Expand Up @@ -67,14 +72,10 @@ export const UseColorStrataWithNoise = (args: ColorStrataParams) => {
return { size: state.size, dpr: state.viewport.dpr };
});
const [updateColorStrata] = useColorStrata({ size, dpr });
const [updateNoise] = useNoise({ size, dpr });

useFrame((props) => {
const noise = updateNoise(props);

const fx = updateColorStrata(props, {
...setConfig(),
texture: noise,
});

fxRef.current!.u_fx = fx;
Expand Down
41 changes: 0 additions & 41 deletions app/_home/config.ts

This file was deleted.

116 changes: 9 additions & 107 deletions app/_home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const Home = () => {
});

setNoise({
scale: 1.0,
scale: 0.01,
warpOctaves: 1,
noiseOctaves: 1,
fbmOctaves: 1,
Expand All @@ -42,11 +42,13 @@ export const Home = () => {
});

setColorStrata({
laminateLayer: 2,
laminateInterval: new THREE.Vector2(2.0, 2.0),
laminateDetail: new THREE.Vector2(1.4, 1.2),
distortion: new THREE.Vector2(1.4, 1.2),
colorFactor: new THREE.Vector3(1.2, 1.0, 3.2),
laminateLayer: 4,
laminateInterval: new THREE.Vector2(1, 1),
laminateDetail: new THREE.Vector2(0.3, 0.3),
distortion: new THREE.Vector2(2, 2),
colorFactor: new THREE.Vector3(6.2, 4.2, 8.8),
timeStrength: new THREE.Vector2(1, 1),
noiseStrength: new THREE.Vector2(1, 1),
});

useFrame((props) => {
Expand All @@ -61,6 +63,7 @@ export const Home = () => {
});
const colorStrata = updateColorStrata(props, {
texture: picked,
noise: noise,
});
ref.current!.uniforms.u_fx.value = colorStrata;
});
Expand Down Expand Up @@ -94,104 +97,3 @@ export const Home = () => {
</mesh>
);
};

/*===============================================
playground
===============================================*/

// import * as THREE from "three";
// import { useRef } from "react";
// import { useFrame, useThree } from "@react-three/fiber";
// import {
// useNoise,
// useFluid,
// useBlending,
// useColorStrata,
// useBrightnessPicker,
// } from "@/packages/use-shader-fx/src";

// export const Home = () => {
// const ref = useRef<THREE.ShaderMaterial>(null);
// const { size, dpr } = useThree((state) => {
// return { size: state.size, dpr: state.viewport.dpr };
// });
// const [updateNoise, setNoise] = useNoise({ size, dpr });
// const [updateFluid, setFluid] = useFluid({ size, dpr });
// const [updateBlending, setBlending] = useBlending({ size, dpr });
// const [updateColorStrata, setColorStrata] = useColorStrata({ size, dpr });
// const [updateBrightnessPicker] = useBrightnessPicker({ size, dpr });

// setBlending({
// color: new THREE.Color(0xff0000),
// brightness: new THREE.Vector3(0.2, 0.2, 0.2),
// mapIntensity: 0.4,
// });

// setNoise({
// scale: 1.0,
// warpOctaves: 1,
// noiseOctaves: 1,
// fbmOctaves: 1,
// timeStrength: 1.2,
// warpStrength: 20.0,
// });

// setFluid({
// curl_strength: 0.0,
// splat_radius: 0.002,
// pressure_iterations: 2,
// });

// setColorStrata({
// laminateLayer: 2,
// laminateInterval: new THREE.Vector2(2.0, 2.0),
// laminateDetail: new THREE.Vector2(1.4, 1.2),
// distortion: new THREE.Vector2(1.4, 1.2),
// colorFactor: new THREE.Vector3(1.2, 1.0, 3.2),
// });

// useFrame((props) => {
// const noise = updateNoise(props);
// const fluid = updateFluid(props);
// const picked = updateBrightnessPicker(props, {
// texture: fluid,
// });
// const blending = updateBlending(props, {
// texture: picked,
// map: noise,
// });
// const colorStrata = updateColorStrata(props, {
// texture: blending,
// });
// ref.current!.uniforms.u_fx.value = colorStrata;
// });

// return (
// <mesh>
// <planeGeometry args={[2, 2]} />
// <shaderMaterial
// ref={ref}
// vertexShader={`
// varying vec2 vUv;
// void main() {
// vUv = uv;
// gl_Position = vec4(position, 1.0);
// }
// `}
// fragmentShader={`
// precision highp float;
// varying vec2 vUv;
// uniform sampler2D u_fx;

// void main() {
// vec2 uv = vUv;
// gl_FragColor = texture2D(u_fx, uv);
// }
// `}
// uniforms={{
// u_fx: { value: null },
// }}
// />
// </mesh>
// );
// };
141 changes: 141 additions & 0 deletions app/playground/Playground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
"use client";

import * as THREE from "three";
import { useRef } from "react";
import { useFrame, useThree } from "@react-three/fiber";
import {
useNoise,
useFluid,
useFxBlending,
useColorStrata,
useBrightnessPicker,
} from "@/packages/use-shader-fx/src";
import {
NoiseParams,
NOISE_PARAMS,
} from "@/packages/use-shader-fx/src/hooks/useNoise";
import {
ColorStrataParams,
COLORSTRATA_PARAMS,
} from "@/packages/use-shader-fx/src/hooks/useColorStrata";
import GUI from "lil-gui";
import { useGUI } from "@/utils/useGUI";

const CONFIG = {
noise: structuredClone(NOISE_PARAMS) as NoiseParams,
colorStrata: {
...structuredClone(COLORSTRATA_PARAMS),
laminateLayer: 20,
laminateInterval: new THREE.Vector2(0.1, 0.1),
laminateDetail: new THREE.Vector2(0.7, 0.7),
distortion: new THREE.Vector2(10.0, 10.0),
colorFactor: new THREE.Vector3(1, 1, 1),
timeStrength: new THREE.Vector2(1, 1),
noiseStrength: new THREE.Vector2(1, 1),
} as ColorStrataParams,
};

const setGUI = (gui: GUI) => {
// noise
const noise = gui.addFolder("noise");
noise.add(CONFIG.noise, "scale", 0, 0.1, 0.0001);
noise.add(CONFIG.noise, "timeStrength", 0, 10, 0.01);
noise.add(CONFIG.noise, "noiseOctaves", 1, 10, 1);
noise.add(CONFIG.noise, "fbmOctaves", 1, 10, 1);
noise.add(CONFIG.noise, "warpOctaves", 1, 10, 1);
const warpDirection = noise.addFolder("warpDirection");
warpDirection.add(CONFIG.noise.warpDirection!, "x", 1, 10, 0.1);
warpDirection.add(CONFIG.noise.warpDirection!, "y", 1, 10, 0.1);
noise.add(CONFIG.noise, "warpStrength", 1, 50, 0.1);
//color strata
const colorStrata = gui.addFolder("colorStrata");
colorStrata.add(CONFIG.colorStrata, "laminateLayer", 0, 20, 1);
colorStrata.add(CONFIG.colorStrata, "scale", 0, 1, 0.01);
const laminateInterval = colorStrata.addFolder("laminateInterval");
laminateInterval.add(CONFIG.colorStrata.laminateInterval!, "x", 0, 2, 0.01);
laminateInterval.add(CONFIG.colorStrata.laminateInterval!, "y", 0, 2, 0.01);
const laminateDetail = colorStrata.addFolder("laminateDetail");
laminateDetail.add(CONFIG.colorStrata.laminateDetail!, "x", 0, 10, 0.1);
laminateDetail.add(CONFIG.colorStrata.laminateDetail!, "y", 0, 10, 0.1);
const distortion = colorStrata.addFolder("distortion");
distortion.add(CONFIG.colorStrata.distortion!, "x", 0, 10, 0.01);
distortion.add(CONFIG.colorStrata.distortion!, "y", 0, 10, 0.01);
const colorFactor = colorStrata.addFolder("colorFactor");
colorFactor.add(CONFIG.colorStrata.colorFactor!, "x", 0, 10, 0.01);
colorFactor.add(CONFIG.colorStrata.colorFactor!, "y", 0, 10, 0.01);
colorFactor.add(CONFIG.colorStrata.colorFactor!, "z", 0, 10, 0.01);
const timeStrength = colorStrata.addFolder("timeStrength");
timeStrength.add(CONFIG.colorStrata.timeStrength!, "x", 0, 2, 0.01);
timeStrength.add(CONFIG.colorStrata.timeStrength!, "y", 0, 2, 0.01);
const noiseStrength = colorStrata.addFolder("noiseStrength");
noiseStrength.add(CONFIG.colorStrata.noiseStrength!, "x", 0, 5, 0.01);
noiseStrength.add(CONFIG.colorStrata.noiseStrength!, "y", 0, 5, 0.01);
};

const setConfig = () => {
return {
noise: { ...CONFIG.noise },
colorStrata: { ...CONFIG.colorStrata },
};
};

export const Playground = () => {
const updateGUI = useGUI(setGUI);

const ref = useRef<THREE.ShaderMaterial>(null);
const { size, dpr } = useThree((state) => {
return { size: state.size, dpr: state.viewport.dpr };
});
const [updateNoise] = useNoise({ size, dpr });
const [updateFluid] = useFluid({ size, dpr });
const [updateFxBlending, setFxBlending] = useFxBlending({ size, dpr });
const [updateColorStrata] = useColorStrata({ size, dpr });
// const [updateBrightnessPicker] = useBrightnessPicker({ size, dpr });

useFrame((props) => {
const noise = updateNoise(props, {
...setConfig().noise,
});
// const fluid = updateFluid(props);
// const blending = updateFxBlending(props, {
// texture: fluid,
// map: noise,
// });
const colorStrata = updateColorStrata(props, {
...setConfig().colorStrata,
texture: false,
noise: false,
});
ref.current!.uniforms.u_fx.value = colorStrata;
updateGUI();
});

return (
<mesh>
<planeGeometry args={[2, 2]} />
<shaderMaterial
ref={ref}
vertexShader={`
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = vec4(position, 1.0);
}
`}
fragmentShader={`
precision highp float;
varying vec2 vUv;
uniform sampler2D u_fx;

void main() {
vec2 uv = vUv;
gl_FragColor = texture2D(u_fx, uv);
}
`}
uniforms={{
u_fx: { value: null },
}}
/>
</mesh>
);
};
12 changes: 12 additions & 0 deletions app/playground/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ShaderFx } from "../ShaderFx";
import { Playground } from "./Playground";

export default function Page() {
return (
<div style={{ width: "100%", height: "100svh", overflow: "hidden" }}>
<ShaderFx>
<Playground />
</ShaderFx>
</div>
);
}
Loading