Shaders: Prefer arithmetic conditionals to branching

This commit is contained in:
Jonas Kulla 2014-12-23 19:00:14 +01:00
parent 373b90af00
commit 2f95c0613a
2 changed files with 8 additions and 6 deletions

View File

@ -18,8 +18,9 @@ const float atAniOffset = 32.0*3.0;
void main() void main()
{ {
vec2 tex = texCoord; vec2 tex = texCoord;
if (tex.x <= atAreaW && tex.y <= atAreaH)
tex.x += aniIndex * atAniOffset; lowp float pred = float(tex.x <= atAreaW && tex.y <= atAreaH);
tex.x += aniIndex * atAniOffset * pred;
gl_Position = projMat * vec4(position + translation, 0, 1); gl_Position = projMat * vec4(position + translation, 0, 1);

View File

@ -18,14 +18,15 @@ const float atAreaCW = 4.0*32.0;
void main() void main()
{ {
vec2 tex = texCoord; vec2 tex = texCoord;
lowp float pred;
/* Type A autotiles shift horizontally */ /* Type A autotiles shift horizontally */
if (tex.x <= atAreaA.x && tex.y <= atAreaA.y) pred = float(tex.x <= atAreaA.x && tex.y <= atAreaA.y);
tex.x += aniOffset.x; tex.x += aniOffset.x * pred;
/* Type C autotiles shift vertically */ /* Type C autotiles shift vertically */
if (tex.x >= atAreaCX && tex.x <= (atAreaCX+atAreaCW) && tex.y <= atAreaA.y) pred = float(tex.x >= atAreaCX && tex.x <= (atAreaCX+atAreaCW) && tex.y <= atAreaA.y);
tex.y += aniOffset.y; tex.y += aniOffset.y * pred;
gl_Position = projMat * vec4(position + translation, 0, 1); gl_Position = projMat * vec4(position + translation, 0, 1);