diff --git a/README.md b/README.md index 0c5f542..2158f5e 100644 --- a/README.md +++ b/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); +``` diff --git a/gaussianBlur.glsl b/gaussianBlur.glsl new file mode 100644 index 0000000..f08146a --- /dev/null +++ b/gaussianBlur.glsl @@ -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)