]> git.sesse.net Git - movit/commitdiff
Make the blur into a simple, Gaussian horizontal blur. Still not very good.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 2 Oct 2012 22:45:32 +0000 (00:45 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 2 Oct 2012 22:45:32 +0000 (00:45 +0200)
blur_effect.cpp
blur_effect.frag
effect.cpp
effect.h
main.cpp

index e945295da641dd565c74b54684be93e158de0022..ddf542eec62fea98c362ba726d3b942bb0b61fa7 100644 (file)
@@ -8,7 +8,7 @@
 #include "util.h"
 
 BlurEffect::BlurEffect()
 #include "util.h"
 
 BlurEffect::BlurEffect()
-       : radius(0.3f)
+       : radius(3.0f)
 {
        register_float("radius", (float *)&radius);
 }
 {
        register_float("radius", (float *)&radius);
 }
@@ -21,4 +21,24 @@ std::string BlurEffect::output_fragment_shader()
 void BlurEffect::set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
 {
        Effect::set_uniforms(glsl_program_num, prefix, sampler_num);
 void BlurEffect::set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
 {
        Effect::set_uniforms(glsl_program_num, prefix, sampler_num);
+
+       //glActiveTexture(GL_TEXTURE0);
+       //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
+       //check_error();
+
+       set_uniform_float(glsl_program_num, prefix, "pixel_offset", 1.0f / 1280.0f);  // FIXME
+
+       // Simple Gaussian weights for now.
+       float weight[15], total = 0.0f;
+       for (unsigned i = 0; i < 15; ++i) {
+               float z = (i - 7.0f) / radius;
+               weight[i] = exp(-(z*z));
+               total += weight[i];
+       }
+       for (unsigned i = 0; i < 15; ++i) {
+               weight[i] /= total;
+               printf("%f\n", weight[i]);
+       }
+       printf("\n");
+       set_uniform_float_array(glsl_program_num, prefix, "weight", weight, 15);
 }
 }
index bfa1d16de06386ffd57297e9996668abea40bd1f..51ff39a58c33d44b5a241a2f1a82864485c85383 100644 (file)
@@ -1,17 +1,24 @@
 // A simple, very stupid horizontal blur. Will be fixed soonish.
 
 // A simple, very stupid horizontal blur. Will be fixed soonish.
 
+uniform float PREFIX(pixel_offset);
+uniform float PREFIX(weight)[15];
+
 vec4 FUNCNAME(vec2 tc) {
        vec4 x = LAST_INPUT(tc);
        return
 vec4 FUNCNAME(vec2 tc) {
        vec4 x = LAST_INPUT(tc);
        return
-               vec4(0.1) * LAST_INPUT(tc + vec2(-0.010f, 0.0)) +
-               vec4(0.1) * LAST_INPUT(tc + vec2(-0.008f, 0.0)) +
-               vec4(0.1) * LAST_INPUT(tc + vec2(-0.006f, 0.0)) +
-               vec4(0.1) * LAST_INPUT(tc + vec2(-0.004f, 0.0)) +
-               vec4(0.2) * LAST_INPUT(tc + vec2(-0.002f, 0.0)) +
-               vec4(0.3) * LAST_INPUT(tc + vec2(-0.000f, 0.0)) +
-               vec4(0.2) * LAST_INPUT(tc + vec2( 0.002f, 0.0)) +
-               vec4(0.1) * LAST_INPUT(tc + vec2( 0.004f, 0.0)) +
-               vec4(0.1) * LAST_INPUT(tc + vec2( 0.006f, 0.0)) +
-               vec4(0.1) * LAST_INPUT(tc + vec2( 0.008f, 0.0)) +
-               vec4(0.1) * LAST_INPUT(tc + vec2( 0.010f, 0.0));
+               vec4(PREFIX(weight)[ 0]) * LAST_INPUT(vec2(tc.x - 7.0 * PREFIX(pixel_offset), tc.y)) +
+               vec4(PREFIX(weight)[ 1]) * LAST_INPUT(vec2(tc.x - 6.0 * PREFIX(pixel_offset), tc.y)) +
+               vec4(PREFIX(weight)[ 2]) * LAST_INPUT(vec2(tc.x - 5.0 * PREFIX(pixel_offset), tc.y)) +
+               vec4(PREFIX(weight)[ 3]) * LAST_INPUT(vec2(tc.x - 4.0 * PREFIX(pixel_offset), tc.y)) +
+               vec4(PREFIX(weight)[ 4]) * LAST_INPUT(vec2(tc.x - 3.0 * PREFIX(pixel_offset), tc.y)) +
+               vec4(PREFIX(weight)[ 5]) * LAST_INPUT(vec2(tc.x - 2.0 * PREFIX(pixel_offset), tc.y)) +
+               vec4(PREFIX(weight)[ 6]) * LAST_INPUT(vec2(tc.x -       PREFIX(pixel_offset), tc.y)) +
+               vec4(PREFIX(weight)[ 7]) * LAST_INPUT(tc) +
+               vec4(PREFIX(weight)[ 8]) * LAST_INPUT(vec2(tc.x +       PREFIX(pixel_offset), tc.y)) +
+               vec4(PREFIX(weight)[ 9]) * LAST_INPUT(vec2(tc.x + 2.0 * PREFIX(pixel_offset), tc.y)) +
+               vec4(PREFIX(weight)[10]) * LAST_INPUT(vec2(tc.x + 3.0 * PREFIX(pixel_offset), tc.y)) +
+               vec4(PREFIX(weight)[11]) * LAST_INPUT(vec2(tc.x + 4.0 * PREFIX(pixel_offset), tc.y)) +
+               vec4(PREFIX(weight)[12]) * LAST_INPUT(vec2(tc.x + 5.0 * PREFIX(pixel_offset), tc.y));
+               vec4(PREFIX(weight)[13]) * LAST_INPUT(vec2(tc.x + 6.0 * PREFIX(pixel_offset), tc.y));
+               vec4(PREFIX(weight)[14]) * LAST_INPUT(vec2(tc.x + 7.0 * PREFIX(pixel_offset), tc.y));
 }
 }
index edf100c566c549417f7df158472a6803c3e2da87..4cc1775d75587305e4504fdf0a534c78d73ec817 100644 (file)
@@ -33,6 +33,18 @@ void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const
        check_error();
 }
 
        check_error();
 }
 
+void set_uniform_float_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values)
+{
+       std::string name = prefix + "_" + key;
+       GLint l = glGetUniformLocation(glsl_program_num, name.c_str());
+       if (l == -1) {
+               return;
+       }
+       check_error();
+       glUniform1fv(l, num_values, values);
+       check_error();
+}
+
 void set_uniform_vec2(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values)
 {
        std::string name = prefix + "_" + key;
 void set_uniform_vec2(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values)
 {
        std::string name = prefix + "_" + key;
index 196682f3f3f652450dd01aa809d5394064d46da6..2f0172a9bc2c983222653aef5620c2dd3e626ea9 100644 (file)
--- a/effect.h
+++ b/effect.h
@@ -25,6 +25,7 @@ struct RGBTriplet {
 // Convenience functions that deal with prepending the prefix.
 void set_uniform_int(GLuint glsl_program_num, const std::string &prefix, const std::string &key, int value);
 void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const std::string &key, float value);
 // Convenience functions that deal with prepending the prefix.
 void set_uniform_int(GLuint glsl_program_num, const std::string &prefix, const std::string &key, int value);
 void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const std::string &key, float value);
+void set_uniform_float_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values);
 void set_uniform_vec2(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values);
 void set_uniform_vec3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values);
 
 void set_uniform_vec2(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values);
 void set_uniform_vec3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values);
 
index 17cbeca9f6524aca66f7e2c4eb31575ca074951f..e4690ba6f1ba7efe29121782d237ba33cc3e274a 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -175,10 +175,6 @@ int main(int argc, char **argv)
        chain.add_output(inout_format);
        chain.finalize();
 
        chain.add_output(inout_format);
        chain.finalize();
 
-       //glGenerateMipmap(GL_TEXTURE_2D);
-       //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 4);
-       //check_error();
-
        // generate a PDO to hold the data we read back with glReadPixels()
        // (Intel/DRI goes into a slow path if we don't read to PDO)
        glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 1);
        // generate a PDO to hold the data we read back with glReadPixels()
        // (Intel/DRI goes into a slow path if we don't read to PDO)
        glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 1);