gaussian_blur_generator 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -6
- data/lib/gaussian_blur_generator/glsl.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a61df5d564b01d8be690766f0b9835ce2b75eb63452c817c96fc2b06b5f2215
|
4
|
+
data.tar.gz: 496cacd091d5cbe948f751e642dd032aab9f2f69eeb9b9413ced6dfd237c9bec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52fb1a80021f74c23d87e806d2db9cf460e809898259565721b18bfee41e05cad80ef91cedbd566c69957db98fc390c32661b1186698dfa9d85f7234c23673d7
|
7
|
+
data.tar.gz: 93ca7a93587e5aca0fb303240d02dc2947569f06ff63b7b3d033c3cb3a2b483af29f48ccc30f01330f6a4ad92a80bd13b65603bded2c47cb907e56c27864b19e
|
data/README.md
CHANGED
@@ -10,22 +10,27 @@ Normally, a blur shader would require N^2 texture reads for a kernel of size N.
|
|
10
10
|
By splitting the shader in two (horizontal, then vertical) and applying a linear
|
11
11
|
sampling technique, we can reduce the number of texture reads to approximately
|
12
12
|
N, vastly improving the performance of a Gaussian blur. This can be reduced even
|
13
|
-
further by ignoring values at the edges of kernels that
|
13
|
+
further by ignoring values at the edges of kernels that hardly make a difference
|
14
14
|
to the output image.
|
15
15
|
|
16
16
|
### What is this gem?
|
17
17
|
|
18
18
|
This gem applies the technique from the article but generates many different
|
19
|
-
shaders with
|
19
|
+
shaders with varying sample sizes. It writes these shaders to files in the
|
20
20
|
output directory, for example:
|
21
21
|
|
22
22
|
- [output/blur/x/17.frag](output/blur/x/17.frag)
|
23
|
-
- [output/
|
23
|
+
- [output/blur/y/17.frag](output/blur/y/17.frag)
|
24
|
+
|
25
|
+
These shaders sample the texture image 17 times per pixel. They are equivalent
|
26
|
+
to a Gaussian blur kernel of size 33 (2N - 1). The largest pre-compiled shader
|
27
|
+
samples 129 times which is equivalent to a Gaussiain blur of size 257. I could
|
28
|
+
have generated more but my laptop ran out of RAM after ~12 hours.
|
24
29
|
|
25
30
|
You can run `./bin/generate` yourself by cloning the repository or use one of
|
26
31
|
the pre-generated shaders in the [`output/blur`](output/blur) directory. These
|
27
|
-
have generated with an epsilon value of 0.05 which roughly corresponds to
|
28
|
-
article, but you can set this yourself if you'd like:
|
32
|
+
have been generated with an epsilon value of 0.05 which roughly corresponds to
|
33
|
+
the article, but you can set this yourself if you'd like:
|
29
34
|
|
30
35
|
```sh
|
31
36
|
$ ./bin/generate 0.07
|
@@ -38,7 +43,7 @@ This would set the threshold a little higher than the default 0.05.
|
|
38
43
|
1. Copy the x and y fragment shaders into your project for the kernel size you want.
|
39
44
|
2. Compile a shader program for each of the fragment shaders
|
40
45
|
3. Set `u_texture` to the input texture you want to blur
|
41
|
-
4. Set `
|
46
|
+
4. Set `u_scaling` base on the pixel size of the output: `[1/width, 1/height, width/height, height/width]`
|
42
47
|
5. Draw your scene to a framebuffer/texture instead of directly to the screen
|
43
48
|
6. Apply the first shader program, then draw to the screen with the second
|
44
49
|
|
@@ -28,14 +28,14 @@ class GaussianBlurGenerator
|
|
28
28
|
#endif
|
29
29
|
|
30
30
|
uniform sampler2D u_texture;
|
31
|
-
uniform vec4
|
31
|
+
uniform vec4 u_scaling;
|
32
32
|
|
33
33
|
// Generated by https://github.com/tuzz/gaussian_blur_generator
|
34
34
|
|
35
35
|
void main() {
|
36
|
-
vec2 coords = gl_FragCoord.xy
|
36
|
+
vec2 coords = gl_FragCoord.xy * u_scaling.xy;
|
37
37
|
|
38
|
-
float one_pixel =
|
38
|
+
float one_pixel = u_scaling.#{axis};
|
39
39
|
#{offsets.join("\n ")}
|
40
40
|
|
41
41
|
gl_FragColor = (
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gaussian_blur_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Patuzzo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Generates fragment shaders that apply a Gaussian blur in an efficient
|
14
14
|
manner.
|