mirror of
https://github.com/libretro/RetroArch
synced 2025-02-01 20:54:10 +00:00
420b7913d4
2820ab0b51 Merge pull request #1076 from KhronosGroup/bitcast-pre-330-glsl 63bcbd511e GLSL: Need extension to use bitcast on GLSL < 330. 9f3bebe3d0 Merge pull request #1075 from lifpan/master b11c20fc1d Remove unreasonable assertion for OpTypeImage Sampled parameter. 1a592b7c0f Merge pull request #1067 from cdavis5e/msl-scalar-block-layout 28454facbb MSL: Handle packed matrices. ea5c0ed82f MSL: Fix alignment of packed types. 44f688bf0b Merge pull request #1070 from KhronosGroup/fix-1066 25c74b324e Forget loop variable enables after emitting block chain. 6b010e0cbc Merge pull request #1069 from KhronosGroup/fix-1053 f6f849397e MSL: Re-roll array expressions in initializers. e5fa7edfd6 MSL: Support scalar block layout. git-subtree-dir: deps/SPIRV-Cross git-subtree-split: 2820ab0b51bf5e4187435d904b34e762b988f48b
98 lines
2.3 KiB
Plaintext
98 lines
2.3 KiB
Plaintext
#version 310 es
|
|
|
|
layout(local_size_x = 64) in;
|
|
|
|
layout(std430, binding = 0) readonly buffer Distribution
|
|
{
|
|
vec2 distribution[];
|
|
};
|
|
|
|
layout(std430, binding = 1) writeonly buffer HeightmapFFT
|
|
{
|
|
uint heights[];
|
|
};
|
|
|
|
layout(binding = 2, std140) uniform UBO
|
|
{
|
|
vec4 uModTime;
|
|
};
|
|
|
|
vec2 alias(vec2 i, vec2 N)
|
|
{
|
|
return mix(i, i - N, greaterThan(i, 0.5 * N));
|
|
}
|
|
|
|
vec4 cmul(vec4 a, vec4 b)
|
|
{
|
|
vec4 r3 = a.yxwz;
|
|
vec4 r1 = b.xxzz;
|
|
vec4 R0 = a * r1;
|
|
vec4 r2 = b.yyww;
|
|
vec4 R1 = r2 * r3;
|
|
return R0 + vec4(-R1.x, R1.y, -R1.z, R1.w);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
uvec2 pack4(vec4 v)
|
|
{
|
|
return uvec2(packHalf2x16(v.xy), packHalf2x16(v.zw));
|
|
}
|
|
|
|
uvec2 workaround_mix(uvec2 a, uvec2 b, bvec2 sel)
|
|
{
|
|
return uvec2(sel.x ? b.x : a.x, sel.y ? b.y : a.y);
|
|
}
|
|
|
|
void generate_heightmap()
|
|
{
|
|
uvec2 N = gl_WorkGroupSize.xy * gl_NumWorkGroups.xy;
|
|
uvec2 i = gl_GlobalInvocationID.xy;
|
|
// Pick out the negative frequency variant.
|
|
uvec2 wi = workaround_mix(N - i, uvec2(0u), equal(i, uvec2(0u)));
|
|
|
|
// Pick out positive and negative travelling waves.
|
|
vec2 a = distribution[i.y * N.x + i.x];
|
|
vec2 b = distribution[wi.y * N.x + wi.x];
|
|
|
|
vec2 k = uModTime.xy * alias(vec2(i), vec2(N));
|
|
float k_len = length(k);
|
|
|
|
const float G = 9.81;
|
|
|
|
// If this sample runs for hours on end, the cosines of very large numbers will eventually become unstable.
|
|
// It is fairly easy to fix this by wrapping uTime,
|
|
// and quantizing w such that wrapping uTime does not change the result.
|
|
// See Tessendorf's paper for how to do it.
|
|
// The sqrt(G * k_len) factor represents how fast ocean waves at different frequencies propagate.
|
|
float w = sqrt(G * k_len) * uModTime.z;
|
|
float cw = cos(w);
|
|
float sw = sin(w);
|
|
|
|
// Complex multiply to rotate our frequency samples.
|
|
a = cmul(a, vec2(cw, sw));
|
|
b = cmul(b, vec2(cw, sw));
|
|
b = vec2(b.x, -b.y); // Complex conjugate since we picked a frequency with the opposite direction.
|
|
vec2 res = a + b; // Sum up forward and backwards travelling waves.
|
|
heights[i.y * N.x + i.x] = pack2(res);
|
|
}
|
|
|
|
void main()
|
|
{
|
|
generate_heightmap();
|
|
}
|
|
|