summaryrefslogtreecommitdiff
path: root/advanced_lighting/7.bloom/shaders/blur.frag
diff options
context:
space:
mode:
Diffstat (limited to 'advanced_lighting/7.bloom/shaders/blur.frag')
-rw-r--r--advanced_lighting/7.bloom/shaders/blur.frag29
1 files changed, 29 insertions, 0 deletions
diff --git a/advanced_lighting/7.bloom/shaders/blur.frag b/advanced_lighting/7.bloom/shaders/blur.frag
new file mode 100644
index 0000000..67b7e43
--- /dev/null
+++ b/advanced_lighting/7.bloom/shaders/blur.frag
@@ -0,0 +1,29 @@
+#version 330 core
+
+in VS_OUT {
+ vec2 tex_coords;
+} vs_out;
+
+out vec4 frag_color;
+
+uniform sampler2D image;
+uniform bool horizontal;
+uniform float weights[5] = float[](0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162);
+
+void main(void)
+{
+ vec2 tex_offset = 1.0 / textureSize(image, 0);
+ vec3 result = texture(image, vs_out.tex_coords).rgb * weights[0];
+ if (horizontal) {
+ for (int i = 1; i < 5; i++) {
+ result += texture(image, vs_out.tex_coords + vec2(tex_offset.x * i, 0.0)).rgb * weights[i];
+ result += texture(image, vs_out.tex_coords - vec2(tex_offset.x * i, 0.0)).rgb * weights[i];
+ }
+ } else {
+ for (int i = 1; i < 5; i++) {
+ result += texture(image, vs_out.tex_coords + vec2(0.0, tex_offset.y * i)).rgb * weights[i];
+ result += texture(image, vs_out.tex_coords - vec2(0.0, tex_offset.y * i)).rgb * weights[i];
+ }
+ }
+ frag_color = vec4(result, 1.0);
+}