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
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,56 @@ useFrame((props) => {
});
```

## The simplest example

This is the simplest example!

```tsx
import * as THREE from "three";
import { useRef } from "react";
import { useFrame, useThree } from "@react-three/fiber";
import { useFruid } from "@hmng8/use-shader-fx";

export const Demo = () => {
const ref = useRef<THREE.ShaderMaterial>(null);
const size = useThree((state) => state.size);
const dpr = useThree((state) => state.viewport.dpr);
const [updateFruid] = useFruid({ size, dpr });
useFrame((props) => {
ref.current!.uniforms.u_fx.value = updateFruid(props);
});

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>
);
};
```

# Performance

You can control the `dpr` using the `PerformanceMonitor` from [drei](https://github.com/pmndrs/drei). For more details, please refer to the [scaling-performance](https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance) of r3f.
Expand Down
48 changes: 48 additions & 0 deletions app/_demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,51 @@ export const Demo = () => {
</mesh>
);
};

/*===============================================
the simplest demo
===============================================*/

// import * as THREE from "three";
// import { useRef } from "react";
// import { useFrame, useThree } from "@react-three/fiber";
// import { useFruid } from "@hmng8/use-shader-fx";

// export const Demo = () => {
// const ref = useRef<THREE.ShaderMaterial>(null);
// const size = useThree((state) => state.size);
// const dpr = useThree((state) => state.viewport.dpr);
// const [updateFruid] = useFruid({ size, dpr });
// useFrame((props) => {
// ref.current!.uniforms.u_fx.value = updateFruid(props);
// });

// 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>
// );
// };
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"zustand": "^4.4.1"
},
"devDependencies": {
"@hmng8/use-shader-fx": "^1.0.12",
"@hmng8/use-shader-fx": "^1.0.13",
"@storybook/addon-essentials": "^7.5.3",
"@storybook/addon-interactions": "^7.5.3",
"@storybook/addon-links": "^7.5.3",
Expand Down
8 changes: 2 additions & 6 deletions packages/use-shader-fx/build/use-shader-fx.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/use-shader-fx/build/use-shader-fx.js.map

Large diffs are not rendered by default.

Loading