]> git.sesse.net Git - movit/commitdiff
Move calculation of normalized position for the vignette into the vertex shader.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 2 Oct 2012 11:59:31 +0000 (13:59 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 2 Oct 2012 11:59:31 +0000 (13:59 +0200)
vignette_effect.cpp
vignette_effect.frag
vignette_effect.h
vignette_effect.vert [new file with mode: 0644]

index f1449aec6073313df76a5189a24ee547589dface..e1403100bc945489dedc521f826dc7fe666f912c 100644 (file)
@@ -17,6 +17,11 @@ VignetteEffect::VignetteEffect()
        register_float("inner_radius", (float *)&inner_radius);
 }
 
        register_float("inner_radius", (float *)&inner_radius);
 }
 
+std::string VignetteEffect::output_vertex_shader()
+{
+       return read_file("vignette_effect.vert");
+}
+
 std::string VignetteEffect::output_fragment_shader()
 {
        return read_file("vignette_effect.frag");
 std::string VignetteEffect::output_fragment_shader()
 {
        return read_file("vignette_effect.frag");
index bc84516437685727301a7f512f0f9aba911cd724..c7e1d6143785f2a5a484aadb7f955544945ebb6e 100644 (file)
@@ -1,15 +1,14 @@
 // A simple, circular vignette, with a cosĀ² falloff.
        
 uniform float PREFIX(inv_radius);
 // A simple, circular vignette, with a cosĀ² falloff.
        
 uniform float PREFIX(inv_radius);
-uniform vec2 PREFIX(aspect_correction);
+varying vec2 PREFIX(normalized_pos);
 
 vec4 FUNCNAME(vec2 tc) {
        vec4 x = LAST_INPUT(tc);
 
        const float pihalf = 0.5 * 3.14159265358979324;
 
 
 vec4 FUNCNAME(vec2 tc) {
        vec4 x = LAST_INPUT(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 dist = (length(PREFIX(normalized_pos)) - PREFIX(inner_radius)) * PREFIX(inv_radius);
        float linear_falloff = clamp(dist, 0.0, 1.0) * pihalf;
        float falloff = cos(linear_falloff) * cos(linear_falloff);
        x.rgb *= vec3(falloff);
        float linear_falloff = clamp(dist, 0.0, 1.0) * pihalf;
        float falloff = cos(linear_falloff) * cos(linear_falloff);
        x.rgb *= vec3(falloff);
index b8e0f68c7f1c5cfe16bc82fef2d9c5abcb9fd83f..1d75f7e63b11432677a6944e9d2bd2f89ccb296e 100644 (file)
@@ -6,6 +6,7 @@
 class VignetteEffect : public Effect {
 public:
        VignetteEffect();
 class VignetteEffect : public Effect {
 public:
        VignetteEffect();
+       std::string output_vertex_shader();
        std::string output_fragment_shader();
 
        void set_uniforms(GLuint glsl_program_num, const std::string &prefix);
        std::string output_fragment_shader();
 
        void set_uniforms(GLuint glsl_program_num, const std::string &prefix);
diff --git a/vignette_effect.vert b/vignette_effect.vert
new file mode 100644 (file)
index 0000000..44edeb8
--- /dev/null
@@ -0,0 +1,9 @@
+uniform vec2 PREFIX(aspect_correction);
+varying vec2 PREFIX(normalized_pos);
+
+vec2 FUNCNAME()
+{
+       vec2 temp = LAST_INPUT();
+       PREFIX(normalized_pos) = (temp - PREFIX(center)) * PREFIX(aspect_correction);
+       return temp;
+}