summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippo Argiolas <filippo.argiolas@gmail.com>2010-04-24 21:11:35 +0200
committerFilippo Argiolas <filippo.argiolas@gmail.com>2010-04-24 21:11:35 +0200
commit71d90751ea9c94650953659008fb5282acce52cd (patch)
tree30c8b81d76736c56b7030c4e02e43152cc9d7a86
parentbce3332d94ad13d1b0ac06de208811b176c3c94b (diff)
twirl: get rid of polar coordinates conversion
Get rid of polar coordinates in the twirl effect. The same can be done using a rotation matrix, saving alu instructions and, most of all, avoiding the use of the evil atan() function (which uses IF operators). Calculate rotation angle in a saner, understandable way. Works on i915! (Hope it still works elsewhere too as I'm not able to test at the moment)
-rw-r--r--gst/gl/effects/gstgleffectssources.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/gst/gl/effects/gstgleffectssources.c b/gst/gl/effects/gstgleffectssources.c
index a334fad..c723582 100644
--- a/gst/gl/effects/gstgleffectssources.c
+++ b/gst/gl/effects/gstgleffectssources.c
@@ -209,11 +209,15 @@ const gchar *twirl_fragment_source =
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
" normcoord = texturecoord / tex_size - 1.0;"
- " float r = length (normcoord);"
- " float phi = atan (normcoord.y, normcoord.x);"
- " phi += (1.0 - smoothstep (-0.6, 0.6, r)) * 4.8;"
- " normcoord.x = r * cos(phi);"
- " normcoord.y = r * sin(phi);"
+ " float r = length (normcoord);"
+ /* calculate rotation angle: maximum (about pi/2) at the origin and
+ * gradually decrease it up to 0.6 of each quadrant */
+ " float phi = (1.0 - smoothstep (0.0, 0.6, r)) * 1.6;"
+ /* precalculate sin phi and cos phi, save some alu */
+ " float s = sin(phi);"
+ " float c = cos(phi);"
+ /* rotate */
+ " normcoord *= mat2(c, s, -s, c);"
" texturecoord = (normcoord + 1.0) * tex_size;"
" vec4 color = texture2DRect (tex, texturecoord); "
" gl_FragColor = color;"