SPIRV-Cross/reference/shaders/comp/generate_height.comp
Hans-Kristian Arntzen 0e7c33ff81 Update glslang to latest on Travis.
Fix a lingering bug with OpSelect and boolean mix().
2017-02-11 10:52:34 +01:00

97 lines
1.9 KiB
Plaintext

#version 310 es
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) readonly buffer Distribution
{
vec2 distribution[];
} _136;
layout(binding = 2, std140) uniform UBO
{
vec4 uModTime;
} _165;
layout(binding = 1, std430) writeonly buffer HeightmapFFT
{
uint heights[];
} _224;
uvec2 workaround_mix(uvec2 a, uvec2 b, bvec2 sel)
{
uint _83;
if (sel.x)
{
_83 = b.x;
}
else
{
_83 = a.x;
}
uint _93 = _83;
uint _94;
if (sel.y)
{
_94 = b.y;
}
else
{
_94 = a.y;
}
return uvec2(_93, _94);
}
vec2 alias(vec2 i, vec2 N)
{
return mix(i, i - N, greaterThan(i, N * 0.5));
}
vec2 cmul(vec2 a, vec2 b)
{
vec2 r3 = a.yx;
vec2 r1 = b.xx;
vec2 R0 = a * r1;
vec2 r2 = b.yy;
vec2 R1 = r2 * r3;
return R0 + vec2(-R1.x, R1.y);
}
uint pack2(vec2 v)
{
return packHalf2x16(v);
}
void generate_heightmap()
{
uvec2 N = uvec2(64u, 1u) * gl_NumWorkGroups.xy;
uvec2 i = gl_GlobalInvocationID.xy;
uvec2 param = N - i;
uvec2 param_1 = uvec2(0u);
bvec2 param_2 = equal(i, uvec2(0u));
uvec2 wi = workaround_mix(param, param_1, param_2);
vec2 a = _136.distribution[(i.y * N.x) + i.x];
vec2 b = _136.distribution[(wi.y * N.x) + wi.x];
vec2 param_3 = vec2(i);
vec2 param_4 = vec2(N);
vec2 k = _165.uModTime.xy * alias(param_3, param_4);
float k_len = length(k);
float w = sqrt(9.81000041961669921875 * k_len) * _165.uModTime.z;
float cw = cos(w);
float sw = sin(w);
vec2 param_5 = a;
vec2 param_6 = vec2(cw, sw);
a = cmul(param_5, param_6);
vec2 param_7 = b;
vec2 param_8 = vec2(cw, sw);
b = cmul(param_7, param_8);
b = vec2(b.x, -b.y);
vec2 res = a + b;
vec2 param_9 = res;
_224.heights[(i.y * N.x) + i.x] = pack2(param_9);
}
void main()
{
generate_heightmap();
}