[add] gaussianBlur function.
This commit is contained in:
parent
8863f97e4c
commit
410269e647
18
README.md
18
README.md
@ -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
15
gaussianBlur.glsl
Normal 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)
|
Loading…
Reference in New Issue
Block a user