[425/906] 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)
This commit is contained in:
Filippo Argiolas 2010-04-24 21:11:35 +02:00 committed by Matthew Waters
parent 797250d9c2
commit 7ee7688ae8

View file

@ -210,10 +210,14 @@ const gchar *twirl_fragment_source =
" 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);"
/* 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;"