Save a multiplication in the vignette effect.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 8 Oct 2012 16:49:58 +0000 (18:49 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 8 Oct 2012 16:49:58 +0000 (18:49 +0200)
vignette_effect.cpp
vignette_effect.frag

index 4ac564a..f75b4ae 100644 (file)
@@ -23,7 +23,7 @@ void VignetteEffect::set_gl_state(GLuint glsl_program_num, const std::string &pr
 {
        Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
 
-       set_uniform_float(glsl_program_num, prefix, "inv_radius", 1.0f / radius);
+       set_uniform_float(glsl_program_num, prefix, "pihalf_div_radius", 0.5 * M_PI / radius);
 
        Point2D aspect(16.0f / 9.0f, 1.0f);  // FIXME
        set_uniform_vec2(glsl_program_num, prefix, "aspect_correction", (float *)&aspect);
index 422b27f..54fafff 100644 (file)
@@ -1,6 +1,6 @@
 // A simple, circular vignette, with a cosĀ² falloff.
        
-uniform float PREFIX(inv_radius);
+uniform float PREFIX(pihalf_div_radius);
 uniform vec2 PREFIX(aspect_correction);
 
 vec4 FUNCNAME(vec2 tc) {
@@ -9,8 +9,8 @@ vec4 FUNCNAME(vec2 tc) {
        const float pihalf = 0.5 * 3.14159265358979324;
 
        vec2 normalized_pos = (tc - PREFIX(center)) * PREFIX(aspect_correction);
-       float dist = (length(normalized_pos) - PREFIX(inner_radius)) * PREFIX(inv_radius);
-       float linear_falloff = clamp(dist, 0.0, 1.0) * pihalf;
+       float dist = (length(normalized_pos) - PREFIX(inner_radius)) * PREFIX(pihalf_div_radius);
+       float linear_falloff = clamp(dist, 0.0, pihalf);
        float falloff = cos(linear_falloff) * cos(linear_falloff);
        x.rgb *= vec3(falloff);