2016-12-27 00:02:07 +08:00
|
|
|
# glsl-util
|
2016-10-03 23:40:55 +08:00
|
|
|
|
2022-04-21 20:38:42 +08:00
|
|
|
Private GLSL utility functions created by @ykob
|
|
|
|
These functions are dependent on [glslify](https://github.com/glslify/glslify).
|
2016-12-27 00:30:56 +08:00
|
|
|
|
2022-04-21 20:38:42 +08:00
|
|
|
## Install
|
2016-10-03 23:40:55 +08:00
|
|
|
|
|
|
|
```
|
2022-04-20 19:24:45 +08:00
|
|
|
yarn add @ykob/glsl-util
|
2016-10-03 23:40:55 +08:00
|
|
|
```
|
|
|
|
|
2022-04-21 20:38:42 +08:00
|
|
|
## Usage
|
2017-01-26 13:44:10 +08:00
|
|
|
|
2018-01-11 16:18:52 +08:00
|
|
|
### `convertHsvToRgb(vec3 hsv)`
|
2016-12-27 00:02:07 +08:00
|
|
|
|
2022-04-21 20:38:42 +08:00
|
|
|
Convert HSV to RGB.
|
2016-12-27 00:02:07 +08:00
|
|
|
http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl
|
|
|
|
|
2016-10-03 23:40:55 +08:00
|
|
|
```
|
2022-04-21 20:38:42 +08:00
|
|
|
#pragma glslify: convertHsvToRgb = require(@ykob/glsl-util/src/convertHsvToRgb);
|
2018-01-11 16:18:52 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
### `convertRgbToHsv(vec3 rgb)`
|
|
|
|
|
2022-04-21 20:38:42 +08:00
|
|
|
Convert RGB to HSV.
|
2018-01-11 16:18:52 +08:00
|
|
|
http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl
|
|
|
|
|
|
|
|
```
|
2022-04-21 20:38:42 +08:00
|
|
|
#pragma glslify: convertRgbToHsv = require(@ykob/glsl-util/src/convertRgbToHsv);
|
2016-12-27 00:19:28 +08:00
|
|
|
```
|
|
|
|
|
2018-01-11 16:18:52 +08:00
|
|
|
### `random(vec2 p)`
|
|
|
|
|
2022-04-21 20:38:42 +08:00
|
|
|
Calculate the white noise.
|
2016-12-27 00:19:28 +08:00
|
|
|
|
|
|
|
```
|
2022-04-21 20:38:42 +08:00
|
|
|
#pragma glslify: random = require(@ykob/glsl-util/src/random);
|
2016-10-03 23:40:55 +08:00
|
|
|
```
|
2017-01-26 13:44:10 +08:00
|
|
|
|
2019-07-08 14:33:04 +08:00
|
|
|
### `polar(float radian1, float radian2, float radius)`
|
2017-01-26 13:44:10 +08:00
|
|
|
|
2022-04-21 20:38:42 +08:00
|
|
|
Calculate the polar coordinates.
|
2017-01-26 13:44:10 +08:00
|
|
|
|
|
|
|
```
|
2022-04-21 20:38:42 +08:00
|
|
|
#pragma glslify: polar = require(@ykob/glsl-util/src/polar);
|
2017-01-26 13:44:10 +08:00
|
|
|
```
|
2017-01-30 14:48:18 +08:00
|
|
|
|
2018-01-11 16:18:52 +08:00
|
|
|
### `gaussianBlur(sampler2D texture, vec2 uv, float radius, vec2 resolution, vec2 direction)`
|
|
|
|
|
2022-04-21 20:38:42 +08:00
|
|
|
Calculate the Gaussian blur.
|
2017-01-30 14:48:18 +08:00
|
|
|
|
|
|
|
```
|
2022-04-21 20:38:42 +08:00
|
|
|
#pragma glslify: gaussianBlur = require(@ykob/glsl-util/src/gaussianBlur);
|
2018-01-11 16:18:52 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
### `lookAt(vec3 base, vec3 p1, vec3 p2, vec3 up)`
|
|
|
|
|
2022-04-21 20:38:42 +08:00
|
|
|
Rotate a vector in any direction.
|
2018-01-11 16:18:52 +08:00
|
|
|
|
|
|
|
```
|
2022-04-21 20:38:42 +08:00
|
|
|
#pragma glslify: lookAt = require(@ykob/glsl-util/src/lookAt);
|
2018-01-11 16:18:52 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
### `rotateAxisAngle(vec3 p, vec3 axis, float angle)`
|
|
|
|
|
2022-04-21 20:38:42 +08:00
|
|
|
Rotate a vector with axis and angle.
|
2018-01-11 16:18:52 +08:00
|
|
|
|
|
|
|
```
|
2022-04-21 20:38:42 +08:00
|
|
|
#pragma glslify: rotateAxisAngle = require(@ykob/glsl-util/src/rotateAxisAngle);
|
2017-01-30 14:48:18 +08:00
|
|
|
```
|