mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-26 02:00:33 +00:00
[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:
parent
797250d9c2
commit
7ee7688ae8
1 changed files with 9 additions and 5 deletions
|
@ -210,10 +210,14 @@ const gchar *twirl_fragment_source =
|
||||||
" vec2 normcoord;"
|
" vec2 normcoord;"
|
||||||
" normcoord = texturecoord / tex_size - 1.0;"
|
" normcoord = texturecoord / tex_size - 1.0;"
|
||||||
" float r = length (normcoord);"
|
" float r = length (normcoord);"
|
||||||
" float phi = atan (normcoord.y, normcoord.x);"
|
/* calculate rotation angle: maximum (about pi/2) at the origin and
|
||||||
" phi += (1.0 - smoothstep (-0.6, 0.6, r)) * 4.8;"
|
* gradually decrease it up to 0.6 of each quadrant */
|
||||||
" normcoord.x = r * cos(phi);"
|
" float phi = (1.0 - smoothstep (0.0, 0.6, r)) * 1.6;"
|
||||||
" normcoord.y = r * sin(phi);"
|
/* 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;"
|
" texturecoord = (normcoord + 1.0) * tex_size;"
|
||||||
" vec4 color = texture2DRect (tex, texturecoord); "
|
" vec4 color = texture2DRect (tex, texturecoord); "
|
||||||
" gl_FragColor = color;"
|
" gl_FragColor = color;"
|
||||||
|
|
Loading…
Reference in a new issue