48 lines
989 B
Plaintext
48 lines
989 B
Plaintext
#version 460
|
|
|
|
layout (local_size_x = 1,local_size_y = 1,local_size_z = 1) in;
|
|
|
|
layout (std430, binding = 0) buffer Samples
|
|
{
|
|
float AudioSamples[];
|
|
};
|
|
layout (std430, binding = 1) buffer Params
|
|
{
|
|
vec4 WaveColor;
|
|
vec4 BgColor;
|
|
float LineUV;
|
|
};
|
|
layout (binding = 2) writeonly uniform image2D Result;
|
|
|
|
vec4 lerp(vec4 a, vec4 b, float x)
|
|
{
|
|
return a + x * (b - a);
|
|
}
|
|
|
|
void main()
|
|
{
|
|
vec2 size = vec2(imageSize(Result));
|
|
ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
|
|
|
|
int X = pos.x;
|
|
int Y = pos.y;
|
|
|
|
float height = size.y;
|
|
float Top = AudioSamples[X * 2] + 1; // -1;
|
|
float Bottom = AudioSamples[X * 2 + 1] + 1; // 1;
|
|
Top = min(Top, 1);
|
|
Bottom = max(Bottom, 0);
|
|
Top *= height;
|
|
Top *= 0.5;
|
|
Bottom *= height;
|
|
Bottom *= 0.5;
|
|
|
|
|
|
// (id.y >= Top && id.y <= Bottom)
|
|
float b1 = min(step(Top, Y), step(Y , Bottom));
|
|
// (Y == height / 2)
|
|
float b2 = step(Y, height * LineUV) * step(height * LineUV, Y);
|
|
float b3 = max(b1, b2);
|
|
imageStore(Result, pos, lerp(BgColor, WaveColor, b3));
|
|
}
|