|
1 | 1 | <div align="center">
|
2 |
| - <img alt="REACT-VFX" src="https://user-images.githubusercontent.com/1403842/71323457-c69e6900-2516-11ea-958c-b96b2121387b.png" width="100%"/> |
3 |
| - <h1>REACT-VFX: WebGL effects for React elements!!</h1> |
| 2 | + <a href="https://amagi.dev/vfx-js/" target="_blank"><img alt="VFX-JS" src="packages/docs/public/og_image.jpg" width="100%"/></a> |
| 3 | + <h1>VFX-JS: Visual Effects Framework for Web</h1> |
4 | 4 | <br/>
|
5 | 5 | <br/>
|
6 | 6 | </div>
|
7 | 7 |
|
8 |
| -## Install |
| 8 | +VFX-JS is a JavaScript library to add WebGL-powered effects to your website. |
| 9 | +You can easily attach it to normal `<img>`, `<video>` elements etc. |
9 | 10 |
|
10 |
| -``` |
11 |
| -npm i react-vfx |
12 |
| -``` |
13 |
| - |
14 |
| -## Usage |
15 |
| - |
16 |
| -REACT-VFX exports `VFXImg`, `VFXVideo`, `VFXSpan` and `VFXDiv`. |
17 |
| -These components works just like `<img>`, `<video>`, `<span>` and `<div>` - accepts all properties they have, but they are rendered in WebGL world with shader effects! |
18 | 11 |
|
19 |
| -```ts |
20 |
| -import * as VFX from 'react-vfx'; |
| 12 | +This is the core implementation of [REACT-VFX](https://amagi.dev/react-vfx). |
21 | 13 |
|
22 |
| -export default () => ( |
23 |
| - <VFX.VFXProvider> |
24 |
| - {/* Render image with shader */} |
25 |
| - <VFX.VFXImg src="cat.png" alt="image" shader="rgbShift"/> |
26 |
| - |
27 |
| - {/* It also supports animated GIFs! */} |
28 |
| - <VFX.VFXImg src="doge.gif" shader="pixelate"/> |
29 |
| - |
30 |
| - {/* and videos! */} |
31 |
| - <VFX.VFXVideo src="mind_blown.mp4" |
32 |
| - autoplay playsinline loop muted |
33 |
| - shader="halftone"/> |
34 |
| - |
35 |
| - {/* Render text as image, then apply the shader effect! */} |
36 |
| - <VFX.VFXSpan shader="rainbow">Hi there!</VFX.VFXSpan> |
37 |
| - |
38 |
| - {/* Or even inputs! */} |
39 |
| - <VFX.VFXDiv shader="rainbow"> |
40 |
| - <input type="text" value="hello" /> |
41 |
| - </VFX.VFXDiv> |
42 |
| - </VFX.VFXProvider> |
43 |
| -); |
44 |
| -``` |
45 | 14 |
|
46 |
| -NOTE: `VFXSpan` doesn't work if the content includes child nodes. |
| 15 | +## Usage |
47 | 16 |
|
48 |
| -```ts |
49 |
| -// OK |
50 |
| -<a href="https://example.com"><VFXSpan>Yo</VFXSpan></a> |
| 17 | +Install via npm: |
51 | 18 |
|
52 |
| -// NG: link styles are not rendered correctly |
53 |
| -<VFXSpan><a href="https://example.com">Yo</a></VFXSpan> |
54 | 19 | ```
|
55 |
| - |
56 |
| -### Custom Shader |
57 |
| - |
58 |
| -```ts |
59 |
| -import { VFXSpan } from 'react-vfx'; |
60 |
| - |
61 |
| -const blink = ` |
62 |
| -uniform vec2 resolution; |
63 |
| -uniform vec2 offset; |
64 |
| -uniform float time; |
65 |
| -uniform sampler2D src; |
66 |
| -
|
67 |
| -void main() { |
68 |
| - vec2 uv = (gl_FragCoord.xy - offset) / resolution; |
69 |
| - gl_FragColor = texture2D(src, uv) * step(.5, fract(time)); |
70 |
| -} |
71 |
| -`; |
72 |
| - |
73 |
| -export default = () => ( |
74 |
| - <VFXSpan shader={blink}></VFXSpan> |
75 |
| -); |
| 20 | +npm i @vfx-js/core |
76 | 21 | ```
|
77 | 22 |
|
78 |
| -<!-- #### Passing Uniforms |
79 |
| -
|
80 |
| -```ts |
81 |
| -type Uniform = THREE.IUniform | number | number[]; |
| 23 | +Then create `VFX` object in your script: |
82 | 24 |
|
83 |
| -type UniformObject = { |
84 |
| - [name: string]: THREE.IUniform; |
85 |
| -} |
| 25 | +```js |
| 26 | +import { VFX } from '@vfx-js/core'; |
86 | 27 |
|
87 |
| -type Uniforms = UniformObject | () => UniformObject; |
88 |
| -``` |
| 28 | +const img = document.querySelector('#img'); |
89 | 29 |
|
90 |
| -```ts |
91 |
| -import React, { useState } from 'react'; |
92 |
| -
|
93 |
| -export default () => { |
94 |
| - const [count, setCount] = useState(0); |
95 |
| -
|
96 |
| - return ( |
97 |
| - <VFXImg src="main_texture.png" |
98 |
| - uniforms={{ |
99 |
| - foo: [1, 2, 3], // vec3 |
100 |
| - foo: [1, 2, 3], // vec3 |
101 |
| - foo: [1, 2, 3] // vec3 |
102 |
| - }}/> |
103 |
| -
|
104 |
| - <button type="button" onClick={() => setCount(count + 1)}> |
105 |
| - <VFXImg src="main_texture.png" |
106 |
| - shader={animated} |
107 |
| - uniforms={{ count }}/> |
108 |
| - ); |
109 |
| -}; |
| 30 | +const vfx = new VFX(); |
| 31 | +vfx.add(img, { shader: "glitch", overflow: 100 }); |
110 | 32 | ```
|
111 | 33 |
|
112 |
| -### Textures |
113 |
| -
|
114 |
| -```ts |
115 |
| -<VFXImg src="main_texture.png" textures={["tex1.png", "tex2.png"]}/> |
116 |
| -``` |
| 34 | +## Examples |
117 | 35 |
|
118 |
| -```glsl |
119 |
| -uniform sampler2D input; |
120 |
| -uniform sampler2D texture1; |
121 |
| -uniform sampler2D texture2; |
122 |
| -``` --> |
| 36 | +TBD: See VFX-JS website for now. |
123 | 37 |
|
124 |
| -## Future work |
| 38 | +https://amagi.dev/vfx-js/ |
125 | 39 |
|
126 |
| -- Passing custom uniforms |
127 |
| -- Passing custom textures |
128 | 40 |
|
129 | 41 | ## Author
|
130 | 42 |
|
|
0 commit comments