2017-05-31 23:11:16 +00:00
|
|
|
#version 450
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
|
|
|
|
uniform ubuf {
|
|
|
|
S s;
|
|
|
|
};
|
|
|
|
|
2017-06-01 00:50:53 +00:00
|
|
|
uniform sampler2D s2d;
|
|
|
|
|
2017-05-31 23:11:16 +00:00
|
|
|
layout(location = 0) in vec4 inv;
|
|
|
|
layout(location = 0) out vec4 outv;
|
|
|
|
|
2017-06-01 00:50:53 +00:00
|
|
|
vec4 foo(S s)
|
2017-05-31 23:11:16 +00:00
|
|
|
{
|
2017-06-01 00:50:53 +00:00
|
|
|
vec4 r = s.a * inv;
|
|
|
|
++r;
|
|
|
|
if (r.x > 3.0)
|
|
|
|
--r;
|
|
|
|
else
|
|
|
|
r *= 2;
|
|
|
|
|
|
|
|
return r;
|
2017-05-31 23:11:16 +00:00
|
|
|
}
|
|
|
|
|
2023-03-14 17:36:24 +00:00
|
|
|
float testBranch(float x, float y)
|
|
|
|
{
|
|
|
|
float result = 0;
|
|
|
|
bool b = x > 0;
|
|
|
|
|
|
|
|
// branch with load
|
|
|
|
if (b) {
|
|
|
|
result += 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// branch with expression
|
|
|
|
if (x > y) {
|
|
|
|
result += x - y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// selection with load
|
|
|
|
result += b ?
|
|
|
|
1 : -1;
|
|
|
|
|
|
|
|
// selection with expression
|
|
|
|
result += x < y ?
|
|
|
|
y :
|
|
|
|
float(b);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-05-31 23:11:16 +00:00
|
|
|
void main()
|
|
|
|
{
|
2017-06-01 00:50:53 +00:00
|
|
|
outv = foo(s);
|
2023-03-14 17:36:24 +00:00
|
|
|
outv += testBranch(inv.x, inv.y);
|
2017-06-01 00:50:53 +00:00
|
|
|
outv += texture(s2d, vec2(0.5));
|
|
|
|
|
|
|
|
switch (s.a) {
|
|
|
|
case 10:
|
|
|
|
++outv;
|
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
outv = 2 * outv;
|
|
|
|
++outv;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
--outv;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
outv *= 3.0;
|
|
|
|
|
|
|
|
outv.x < 10.0 ?
|
|
|
|
outv = sin(outv) :
|
|
|
|
outv = cos(outv);
|
2017-05-31 23:11:16 +00:00
|
|
|
}
|