Skip to content

Commit 4744541

Browse files
author
takuma-hmng8
committed
v1.1.10
1 parent 7700e1a commit 4744541

File tree

24 files changed

+277
-478
lines changed

24 files changed

+277
-478
lines changed

app/ShaderFx.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ export const ShaderFx = ({
99
children,
1010
preserveDrawingBuffer = false,
1111
shadows = false,
12+
isDprUpdate = true,
1213
}: {
1314
children: React.ReactNode;
1415
preserveDrawingBuffer?: boolean;
1516
shadows?: boolean;
17+
isDprUpdate?: boolean;
1618
}) => {
1719
const [dpr, setDpr] = useState(1.5);
1820
return (
@@ -26,6 +28,9 @@ export const ShaderFx = ({
2628
if (preserveDrawingBuffer) {
2729
return;
2830
}
31+
if (!isDprUpdate) {
32+
return;
33+
}
2934
console.log(`dpr:${dpr}`);
3035
setDpr(Math.round((1.0 + 1.0 * factor) * 10) / 10);
3136
}}>

app/obscurus/Playground.tsx

Lines changed: 96 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@ import * as THREE from "three";
44
import { useEffect, useMemo } from "react";
55
import { useFrame, useThree, extend, useLoader } from "@react-three/fiber";
66
import {
7-
useBeat,
87
useCreateWobble3D,
98
Wobble3DParams,
109
WOBBLE3D_PARAMS,
11-
useWobble3D,
12-
useMorphParticles,
1310
useCreateMorphParticles,
1411
MorphParticlesParams,
1512
MORPHPARTICLES_PARAMS,
16-
useNoise,
17-
useFPSLimiter,
1813
} from "@/packages/use-shader-fx/src";
1914
import { FxMaterial } from "./FxMaterial";
2015
import GUI from "lil-gui";
@@ -23,154 +18,155 @@ import { OrbitControls, Environment } from "@react-three/drei";
2318

2419
extend({ FxMaterial });
2520

26-
const CONFIG: Wobble3DParams = {
21+
const WOBBLE_CONFIG: Wobble3DParams = {
2722
...structuredClone(WOBBLE3D_PARAMS),
28-
color0: new THREE.Color(0x1adb91),
29-
color1: new THREE.Color(0xdbff57),
30-
color2: new THREE.Color(0xdf6bff),
31-
color3: new THREE.Color(0x9eaeff),
32-
wobbleStrength: 0.8,
33-
wobbleTimeFrequency: 0.4,
23+
color0: new THREE.Color(0x000000),
24+
color1: new THREE.Color(0x000000),
25+
color2: new THREE.Color(0x000000),
26+
color3: new THREE.Color(0x000000),
27+
wobbleStrength: 0.35,
28+
wobbleTimeFrequency: 0.2,
3429
warpStrength: 0.2,
35-
colorMix: 0.6,
36-
chromaticAberration: 0.8,
30+
colorMix: 0.3,
31+
chromaticAberration: 0.05,
3732
anisotropicBlur: 0.2,
38-
distortion: 2,
39-
distortionScale: 0.8,
33+
distortion: 0.3,
34+
distortionScale: 0.5,
4035
temporalDistortion: 0.3,
4136
};
4237

4338
const MATERIAL_CONFIG: THREE.MeshPhysicalMaterialParameters = {
44-
iridescence: 1,
39+
iridescence: 0.1,
4540
metalness: 0.0,
4641
roughness: 0.0,
4742
transmission: 2,
48-
thickness: 1,
43+
thickness: 1.2,
4944
transparent: true,
5045
};
5146

5247
const PARTICLE_CONFIG: MorphParticlesParams = {
5348
...structuredClone(MORPHPARTICLES_PARAMS),
54-
blurAlpha: 0.86,
55-
blurRadius: 0.07,
56-
pointSize: 0.9,
49+
blurAlpha: 0.01,
50+
blurRadius: 0.6,
51+
pointSize: 0.4,
52+
sizeRandomIntensity: 1,
53+
sizeRandomMax: 2.5,
54+
sizeRandomMin: 0.8,
55+
sizeRandomTimeFrequency: 1,
5756
color0: new THREE.Color(0x000000),
5857
color1: new THREE.Color(0x000000),
5958
color2: new THREE.Color(0x000000),
60-
color3: new THREE.Color(0x080808),
61-
wobbleStrength: 0.8,
62-
warpStrength: 0.7,
59+
color3: new THREE.Color(0x000000),
60+
wobbleStrength: 0.4,
61+
warpStrength: 2.6,
6362
wobblePositionFrequency: 0.4,
6463
wobbleTimeFrequency: 0.4,
64+
warpTimeFrequency: 0.2,
6565
};
6666

6767
const setGUI = (gui: GUI) => {
68-
// gui.addColor(CONFIG, "color0");
69-
// gui.addColor(CONFIG, "color1");
70-
// gui.addColor(CONFIG, "color2");
71-
// gui.addColor(CONFIG, "color3");
72-
// gui.add(CONFIG, "wobbleStrength", 0, 10, 0.01);
73-
// gui.add(CONFIG, "wobblePositionFrequency", 0, 10, 0.01);
74-
// gui.add(CONFIG, "wobbleTimeFrequency", 0, 10, 0.01);
75-
// gui.add(CONFIG, "warpStrength", 0, 10, 0.01);
76-
// gui.add(CONFIG, "warpPositionFrequency", 0, 10, 0.01);
77-
// gui.add(CONFIG, "warpTimeFrequency", 0, 10, 0.01);
78-
// gui.add(CONFIG, "wobbleShine", 0, 5, 0.01);
79-
// gui.add(CONFIG, "samples", 0, 10, 1);
80-
// gui.add(CONFIG, "colorMix", 0, 1, 0.01);
81-
// gui.add(CONFIG, "chromaticAberration", 0, 10, 0.01);
82-
// gui.add(CONFIG, "anisotropicBlur", 0, 10, 0.01);
83-
// gui.add(CONFIG, "distortion", 0, 10, 0.01);
84-
// gui.add(CONFIG, "distortionScale", 0, 10, 0.01);
85-
// gui.add(CONFIG, "temporalDistortion", 0, 10, 0.01);
86-
// const mpm = gui.addFolder("MeshPhysicalMaterial");
87-
// mpm.add(MATERIAL_CONFIG, "iridescence", 0, 1, 0.01);
88-
// mpm.add(MATERIAL_CONFIG, "metalness", 0, 1, 0.01);
89-
// mpm.add(MATERIAL_CONFIG, "roughness", 0, 1, 0.01);
90-
// mpm.add(MATERIAL_CONFIG, "transmission", 0, 10, 0.01);
91-
// mpm.add(MATERIAL_CONFIG, "thickness", 0, 10, 0.01);
92-
gui.add(PARTICLE_CONFIG, "blurAlpha", 0, 1, 0.01);
93-
gui.add(PARTICLE_CONFIG, "blurRadius", 0, 2, 0.01);
94-
gui.add(PARTICLE_CONFIG, "pointSize", 0.01, 2, 0.01);
95-
gui.addColor(PARTICLE_CONFIG, "color0");
96-
gui.addColor(PARTICLE_CONFIG, "color1");
97-
gui.addColor(PARTICLE_CONFIG, "color2");
98-
gui.addColor(PARTICLE_CONFIG, "color3");
99-
gui.add(PARTICLE_CONFIG, "wobbleStrength", 0, 10, 0.01);
100-
gui.add(PARTICLE_CONFIG, "wobblePositionFrequency", 0, 10, 0.01);
101-
gui.add(PARTICLE_CONFIG, "wobbleTimeFrequency", 0, 10, 0.01);
102-
gui.add(PARTICLE_CONFIG, "warpStrength", 0, 10, 0.01);
103-
gui.add(PARTICLE_CONFIG, "warpPositionFrequency", 0, 10, 0.01);
104-
gui.add(PARTICLE_CONFIG, "warpTimeFrequency", 0, 10, 0.01);
105-
gui.add(PARTICLE_CONFIG, "displacementIntensity", 0, 10, 0.01);
106-
gui.add(PARTICLE_CONFIG, "displacementColorIntensity", 0, 40, 0.01);
107-
gui.add(PARTICLE_CONFIG, "sizeRandomIntensity", 0, 10, 0.01);
108-
gui.add(PARTICLE_CONFIG, "sizeRandomTimeFrequency", 0, 3, 0.01);
109-
gui.add(PARTICLE_CONFIG, "sizeRandomMin", 0, 1, 0.01);
110-
gui.add(PARTICLE_CONFIG, "sizeRandomMax", 1, 2, 0.01);
111-
gui.add(PARTICLE_CONFIG, "divergence", -2, 2, 0.1);
68+
const wobble = gui.addFolder("Wobble3D");
69+
wobble.addColor(WOBBLE_CONFIG, "color0");
70+
wobble.addColor(WOBBLE_CONFIG, "color1");
71+
wobble.addColor(WOBBLE_CONFIG, "color2");
72+
wobble.addColor(WOBBLE_CONFIG, "color3");
73+
wobble.add(WOBBLE_CONFIG, "wobbleStrength", 0, 10, 0.01);
74+
wobble.add(WOBBLE_CONFIG, "wobblePositionFrequency", 0, 10, 0.01);
75+
wobble.add(WOBBLE_CONFIG, "wobbleTimeFrequency", 0, 10, 0.01);
76+
wobble.add(WOBBLE_CONFIG, "warpStrength", 0, 10, 0.01);
77+
wobble.add(WOBBLE_CONFIG, "warpPositionFrequency", 0, 10, 0.01);
78+
wobble.add(WOBBLE_CONFIG, "warpTimeFrequency", 0, 10, 0.01);
79+
wobble.add(WOBBLE_CONFIG, "wobbleShine", 0, 5, 0.01);
80+
wobble.add(WOBBLE_CONFIG, "samples", 0, 10, 1);
81+
wobble.add(WOBBLE_CONFIG, "colorMix", 0, 1, 0.01);
82+
wobble.add(WOBBLE_CONFIG, "chromaticAberration", 0, 10, 0.01);
83+
wobble.add(WOBBLE_CONFIG, "anisotropicBlur", 0, 10, 0.01);
84+
wobble.add(WOBBLE_CONFIG, "distortion", 0, 10, 0.01);
85+
wobble.add(WOBBLE_CONFIG, "distortionScale", 0, 10, 0.01);
86+
wobble.add(WOBBLE_CONFIG, "temporalDistortion", 0, 10, 0.01);
87+
88+
const mpm = gui.addFolder("MeshPhysicalMaterial");
89+
mpm.add(MATERIAL_CONFIG, "iridescence", 0, 1, 0.01);
90+
mpm.add(MATERIAL_CONFIG, "metalness", 0, 1, 0.01);
91+
mpm.add(MATERIAL_CONFIG, "roughness", 0, 1, 0.01);
92+
mpm.add(MATERIAL_CONFIG, "transmission", 0, 10, 0.01);
93+
mpm.add(MATERIAL_CONFIG, "thickness", 0, 10, 0.01);
94+
95+
const particle = gui.addFolder("MorphParticles");
96+
particle.add(PARTICLE_CONFIG, "blurAlpha", 0, 1, 0.01);
97+
particle.add(PARTICLE_CONFIG, "blurRadius", 0, 2, 0.01);
98+
particle.add(PARTICLE_CONFIG, "pointSize", 0.01, 2, 0.01);
99+
particle.addColor(PARTICLE_CONFIG, "color0");
100+
particle.addColor(PARTICLE_CONFIG, "color1");
101+
particle.addColor(PARTICLE_CONFIG, "color2");
102+
particle.addColor(PARTICLE_CONFIG, "color3");
103+
particle.add(PARTICLE_CONFIG, "wobbleStrength", 0, 10, 0.01);
104+
particle.add(PARTICLE_CONFIG, "wobblePositionFrequency", 0, 10, 0.01);
105+
particle.add(PARTICLE_CONFIG, "wobbleTimeFrequency", 0, 10, 0.01);
106+
particle.add(PARTICLE_CONFIG, "warpStrength", 0, 10, 0.01);
107+
particle.add(PARTICLE_CONFIG, "warpPositionFrequency", 0, 10, 0.01);
108+
particle.add(PARTICLE_CONFIG, "warpTimeFrequency", 0, 10, 0.01);
109+
particle.add(PARTICLE_CONFIG, "displacementIntensity", 0, 10, 0.01);
110+
particle.add(PARTICLE_CONFIG, "displacementColorIntensity", 0, 40, 0.01);
111+
particle.add(PARTICLE_CONFIG, "sizeRandomIntensity", 0, 10, 0.01);
112+
particle.add(PARTICLE_CONFIG, "sizeRandomTimeFrequency", 0, 3, 0.01);
113+
particle.add(PARTICLE_CONFIG, "sizeRandomMin", 0, 1, 0.01);
114+
particle.add(PARTICLE_CONFIG, "sizeRandomMax", 1, 2, 0.01);
115+
particle.add(PARTICLE_CONFIG, "divergence", -2, 2, 0.1);
112116
return gui;
113117
};
114118
const setParticleConfig = () => {
115119
return {
116120
...PARTICLE_CONFIG,
117121
} as MorphParticlesParams;
118122
};
123+
const setWobbleConfig = () => {
124+
return {
125+
...WOBBLE_CONFIG,
126+
} as Wobble3DParams;
127+
};
119128

120129
export const Playground = () => {
121-
const updateGUI = useGUI(setGUI);
122-
const [noise] = useLoader(THREE.TextureLoader, ["/alphaMap.jpg"]);
123-
124-
const { size, viewport, camera } = useThree();
125-
130+
useGUI(setGUI);
131+
const [noise] = useLoader(THREE.TextureLoader, ["/noise.jpg"]);
132+
const { size, viewport } = useThree();
126133
const [updateWobble, wobble] = useCreateWobble3D({
127134
baseMaterial: THREE.MeshPhysicalMaterial,
128-
materialParameters: { ...MATERIAL_CONFIG },
135+
geometry: useMemo(() => new THREE.IcosahedronGeometry(2.4, 10), []),
136+
materialParameters: MATERIAL_CONFIG,
129137
});
130-
131138
const [updateParticle, particles] = useCreateMorphParticles({
132139
size,
133140
dpr: viewport.dpr,
134-
geometry: useMemo(() => new THREE.IcosahedronGeometry(2, 10), []),
141+
geometry: useMemo(() => new THREE.IcosahedronGeometry(0.8, 10), []),
135142
});
136-
137143
useEffect(() => {
138-
particles.points.material.blending = THREE.NormalBlending;
139-
}, []);
140-
141-
const beat = useBeat(140, "easeInOutBack");
142-
const limiter = useFPSLimiter(5);
144+
const particleMat = particles.points.material as THREE.ShaderMaterial;
145+
particleMat.blending = THREE.NormalBlending;
146+
}, [noise, updateParticle, particles.points.material]);
143147

144148
useFrame((props) => {
145-
// updateWobble(props, {
146-
// ...setConfig(),
147-
// beat: beat(props.clock).beat,
148-
// });
149-
// const mat = wobble.mesh.material as THREE.MeshPhysicalMaterial;
150-
// mat.iridescence = MATERIAL_CONFIG.iridescence!;
151-
// mat.metalness = MATERIAL_CONFIG.metalness!;
152-
// mat.roughness = MATERIAL_CONFIG.roughness!;
153-
// mat.transmission = MATERIAL_CONFIG.transmission!;
154-
// mat.thickness = MATERIAL_CONFIG.thickness!;
155-
149+
updateWobble(props, {
150+
...setWobbleConfig(),
151+
});
152+
const mat = wobble.mesh.material as THREE.MeshPhysicalMaterial;
153+
mat.iridescence = MATERIAL_CONFIG.iridescence!;
154+
mat.metalness = MATERIAL_CONFIG.metalness!;
155+
mat.roughness = MATERIAL_CONFIG.roughness!;
156+
mat.transmission = MATERIAL_CONFIG.transmission!;
157+
mat.thickness = MATERIAL_CONFIG.thickness!;
156158
updateParticle(props, {
157159
...setParticleConfig(),
158160
alphaMap: noise,
159161
});
160-
161-
updateGUI();
162162
});
163163

164164
return (
165165
<mesh>
166166
<OrbitControls />
167167
<Environment files={"/snowpark.exr"} background={true} />
168-
{/* <primitive object={wobble.mesh} /> */}
168+
<primitive object={wobble.mesh} />
169169
<primitive object={particles.points} />
170-
{/* <mesh>
171-
<planeGeometry args={[2, 2]} />
172-
<fxMaterial key={FxMaterial.key} u_fx={noise} />
173-
</mesh> */}
174170
</mesh>
175171
);
176172
};

app/playground/FxMaterial.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)