]> git.sesse.net Git - movit/blobdiff - blur_effect.cpp
Set better texture environment for the intermediate textures.
[movit] / blur_effect.cpp
index 7ca895a15f6b56b8dfee4e53a0f013610097d0de..17044f12f35c54681148814f38efebac4d37f5e0 100644 (file)
@@ -3,14 +3,17 @@
 #include <math.h>
 #include <GL/gl.h>
 #include <GL/glext.h>
+#include <assert.h>
 
 #include "blur_effect.h"
 #include "util.h"
 
 BlurEffect::BlurEffect()
-       : radius(3.0f)
+       : radius(3.0f),
+         direction(HORIZONTAL)
 {
        register_float("radius", (float *)&radius);
+       register_int("direction", (int *)&direction);
 }
 
 std::string BlurEffect::output_fragment_shader()
@@ -33,11 +36,30 @@ void BlurEffect::set_uniforms(GLuint glsl_program_num, const std::string &prefix
                pixel_size *= 2.0f;
        }       
 
+       // In the second pass, we do the same, but don't sample from a mipmap;
+       // that would re-blur the other direction in an ugly fashion, and we already
+       // have the vertical box blur we need from that pass.
+       //
+       // TODO: We really need to present horizontal+vertical as a unit;
+       // currently, there's really no guarantee vertical blur is the second pass.
+       if (direction == VERTICAL) {
+               base_mipmap_level = 0;
+       }
+
        glActiveTexture(GL_TEXTURE0);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, base_mipmap_level);
        check_error();
 
-       set_uniform_float(glsl_program_num, prefix, "pixel_offset", pixel_size / 1280.0f);  // FIXME
+       // FIXME
+       if (direction == HORIZONTAL) {
+               float ps[] = { pixel_size / 1280.0f, 0.0f };
+               set_uniform_vec2(glsl_program_num, prefix, "pixel_offset", ps);
+       } else if (direction == VERTICAL) {
+               float ps[] = { 0.0f, pixel_size / 720.0f };
+               set_uniform_vec2(glsl_program_num, prefix, "pixel_offset", ps);
+       } else {
+               assert(false);
+       }
 
        // Simple Gaussian weights for now.
        float weight[15], total = 0.0f;