SPIRV-Cross/reference/shaders/comp/generate_height.comp
2017-01-21 10:08:27 +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[];
} _190;
layout(binding = 2, std140) uniform UBO
{
vec4 uModTime;
} _218;
layout(binding = 1, std430) writeonly buffer HeightmapFFT
{
uint heights[];
} _276;
uvec2 workaround_mix(uvec2 a, uvec2 b, bvec2 sel)
{
uint _137;
if (sel.x)
{
_137 = b.x;
}
else
{
_137 = a.x;
}
uint _147 = _137;
uint _148;
if (sel.y)
{
_148 = b.y;
}
else
{
_148 = a.y;
}
return uvec2(_147, _148);
}
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 = _190.distribution[(i.y * N.x) + i.x];
vec2 b = _190.distribution[(wi.y * N.x) + wi.x];
vec2 param_3 = vec2(i);
vec2 param_4 = vec2(N);
vec2 k = _218.uModTime.xy * alias(param_3, param_4);
float k_len = length(k);
float w = sqrt(9.81000041961669921875 * k_len) * _218.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;
_276.heights[(i.y * N.x) + i.x] = pack2(param_9);
}
void main()
{
generate_heightmap();
}