Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit df5cb43

Browse files
author
takuma-hmng8
committed
add:useRawBlank
1 parent 1a6276d commit df5cb43

File tree

22 files changed

+1072
-689
lines changed

22 files changed

+1072
-689
lines changed

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,12 @@ return (
500500

501501
👉 [morphParticles demo](https://use-shader-fx.vercel.app/useMorphParticles) 👈
502502

503-
# useBlank
503+
# useBlank / useRawBlank
504504

505505
By default, it is a blank canvas with nothing drawn on it. You can customise the shaders using `onBeforeInit`.
506506

507507
Fragment shaders have `uTexture`,`uBackbuffer`,`uTime`,`uPointer` and `uResolution` as default uniforms.
508+
`useRawBlank` is more raw, default uniforms is only `uResolution`.
508509

509510
```tsx
510511
const [updateBlank, _, { output: blank, material }] = useBlank({

‎app/playground/Playground.tsx‎

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,7 @@ import {
99
useLoader,
1010
createPortal,
1111
} from "@react-three/fiber";
12-
import {
13-
useDoubleFBO,
14-
useSingleFBO,
15-
useFluid,
16-
useCoverTexture,
17-
useMotionBlur,
18-
useSimpleBlur,
19-
usePointer,
20-
useNoise,
21-
useCreateWobble3D,
22-
} from "@/packages/use-shader-fx/src";
12+
import { useRawBlank } from "@/packages/use-shader-fx/src";
2313
import { FxMaterial } from "./FxMaterial";
2414
import { OrbitControls, useVideoTexture } from "@react-three/drei";
2515

@@ -28,57 +18,61 @@ extend({ FxMaterial });
2818
export const Playground = () => {
2919
const { size, viewport, camera } = useThree();
3020

31-
// /FT_Ch02-comp.mp4
32-
// http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4
33-
const funkun_mov = useVideoTexture("/FT_Ch02-comp.mp4", {
34-
width: 1280,
35-
height: 720,
36-
});
3721
const [funkun] = useLoader(THREE.TextureLoader, ["/funkun.jpg"]);
3822

39-
const [updateNoise,setNoise, { output: noise}] = useNoise({
23+
const [update,set, { output}] = useRawBlank({
4024
size,
41-
dpr: 0.2,
42-
});
43-
setNoise({
44-
noiseOctaves: 1,
45-
fbmOctaves: 1,
46-
warpOctaves: 1,
47-
timeStrength: 1,
48-
scale: 2000,
49-
});
50-
51-
const [updateWobble, wobble] = useCreateWobble3D({
52-
materialParameters: {
53-
color: "hotpink",
54-
// displacementMap: noise,
55-
// displacementScale: 2,
25+
dpr: 2,
26+
onBeforeInit: (param) => {
27+
Object.assign(param.uniforms, {
28+
uTexture: { value: funkun },
29+
uTime: { value: 0 },
30+
});
31+
param.fragmentShader = param.fragmentShader.replace(
32+
"#usf <uniforms>",
33+
`
34+
uniform sampler2D uTexture;
35+
uniform float uTime;
36+
`
37+
);
38+
param.fragmentShader = param.fragmentShader.replace(
39+
"#usf <main>",
40+
`
41+
vec2 uv = vUv;
42+
vec2 perDivSize = vec2(20.) / uResolution;
43+
vec4 outColor = vec4(
44+
texture2D(uTexture, uv + perDivSize * vec2(-1.0, -1.0)) +
45+
texture2D(uTexture, uv + perDivSize * vec2(0.0, -1.0)) +
46+
texture2D(uTexture, uv + perDivSize * vec2(1.0, -1.0)) +
47+
texture2D(uTexture, uv + perDivSize * vec2(-1.0, 0.0)) +
48+
texture2D(uTexture, uv + perDivSize * vec2(0.0, 0.0)) +
49+
texture2D(uTexture, uv + perDivSize * vec2(1.0, 0.0)) +
50+
texture2D(uTexture, uv + perDivSize * vec2(-1.0, 1.0)) +
51+
texture2D(uTexture, uv + perDivSize * vec2(0.0, 1.0)) +
52+
texture2D(uTexture, uv + perDivSize * vec2(1.0, 1.0))
53+
) / 9.0;
54+
usf_FragColor = outColor;
55+
usf_FragColor.r += sin(uTime);
56+
`
57+
);
5658
},
5759
});
5860

59-
updateWobble(null, {
60-
// wobbleStrength: 0.0,
61-
// colorMix: 0,
62-
});
63-
6461
useFrame((state) => {
65-
updateWobble(state);
66-
// updateNoise(state);
62+
update(
63+
state,
64+
{ hofsehfgose: 2 },
65+
{
66+
uTime: state.clock.getElapsedTime(),
67+
}
68+
);
6769
});
6870

6971
return (
7072
<>
7173
<mesh>
72-
<directionalLight
73-
color={"white"}
74-
position={[0.25, 2, 3]}
75-
intensity={2}
76-
/>
77-
<ambientLight intensity={1} />
78-
<primitive object={wobble.mesh} />
79-
{/* <icosahedronGeometry args={[2, 20]} />
80-
<meshPhysicalMaterial color={"hotpink"} displacementMap={noise} /> */}
81-
<OrbitControls />
74+
<planeGeometry args={[2, 2]} />
75+
<fxMaterial u_fx={output} key={FxMaterial.key} />
8276
</mesh>
8377
</>
8478
);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /