[424/906] tunnel: get rid of polar coordinates conversion

Get rid of polar coordinates in the tunnel effect as the same can easily
be done just clamping the radius and multiplying.
Remove the evil atan() call that uses branching and a lot of unneeded alu
instructions. Now works on i915!
This commit is contained in:
Filippo Argiolas 2010-04-24 20:43:39 +02:00 committed by Matthew Waters
parent 98752e51da
commit 797250d9c2

View file

@ -171,14 +171,12 @@ const gchar *tunnel_fragment_source =
" vec2 tex_size = vec2 (width, height);"
" vec2 texturecoord = gl_TexCoord[0].xy;"
" vec2 normcoord;"
/* little trick with normalized coords to obtain a circle */
" normcoord = texturecoord / tex_size.x - tex_size / tex_size.x;"
/* little trick with normalized coords to obtain a circle with
* rect textures */
" normcoord = (texturecoord - tex_size) / tex_size.x;"
" float r = length(normcoord);"
" float phi = atan(normcoord.y, normcoord.x);"
" r = clamp (r, 0.0, 0.5);" /* is there a way to do this without polars? */
" normcoord.x = r * cos(phi);"
" normcoord.y = r * sin(phi); "
" texturecoord = (normcoord + tex_size/tex_size.x) * tex_size.x;"
" normcoord *= clamp (r, 0.0, 0.5) / r;"
" texturecoord = (normcoord * tex_size.x) + tex_size;"
" vec4 color = texture2DRect (tex, texturecoord); "
" gl_FragColor = color;"
"}";