[add] gaussianBlur function.

This commit is contained in:
yoichi kobayashi 2017-01-30 15:48:18 +09:00
parent 8863f97e4c
commit 410269e647
2 changed files with 25 additions and 8 deletions

View File

@ -12,32 +12,34 @@ npm i git://github.com/ykob/glsl-util.git
this function converts RGB to HSV. or is its opposite.
### Quote source
http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl
### usage
```
#pragma glslify: convertHsvToRgb = require(glsl-util/convertHsvToRgb);
#pragma glslify: convertRgbToHsv = require(glsl-util/convertRgbToHsv);
vec3 rgb = convertHsvToRgb(vec3 hsv);
vec3 hsv = convertRgbToHsv(vec3 rgb);
```
## random
### usage
```
#pragma glslify: random = require(glsl-util/random);
float p = random(vec2 c);
```
## polar
this function calculates polar coordinates.
### usage
```
#pragma glslify: polar = require(glsl-util/polar);
vec3 p = polar(float radian1, float radian2, float radius);
```
## gaussianBlur
```
#pragma glslify: gaussianBlur = require(glsl-util/gaussianBlur);
vec4 color = gaussianBlur(sampler2D texture, vec2 uv, float radius, vec2 resolution, vec2 direction);
```

15
gaussianBlur.glsl Normal file
View File

@ -0,0 +1,15 @@
vec4 gaussianBlur(sampler2D texture, vec2 uv, float radius, vec2 resolution, vec2 direction) {
vec4 color = vec4(0.0);
vec2 step = radius / resolution * direction;
color += texture2D(texture, uv - 4.0 * step) * 0.02699548325659403;
color += texture2D(texture, uv - 3.0 * step) * 0.06475879783294587;
color += texture2D(texture, uv - 2.0 * step) * 0.12098536225957168;
color += texture2D(texture, uv - 1.0 * step) * 0.17603266338214976;
color += texture2D(texture, uv) * 0.19947114020071635;
color += texture2D(texture, uv + 1.0 * step) * 0.17603266338214976;
color += texture2D(texture, uv + 2.0 * step) * 0.12098536225957168;
color += texture2D(texture, uv + 3.0 * step) * 0.06475879783294587;
color += texture2D(texture, uv + 4.0 * step) * 0.02699548325659403;
return color;
}
#pragma glslify: export(gaussianBlur)