#include "util.h"
BlurEffect::BlurEffect()
- : radius(0.3f)
+ : radius(3.0f)
{
register_float("radius", (float *)&radius);
}
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);
}
// 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(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));
}
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;
// 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);
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);