Skip to content

Commit

Permalink
[Renderer] Fix weird waveform edge
Browse files Browse the repository at this point in the history
  • Loading branch information
native-m committed Oct 20, 2024
1 parent 8bc4344 commit d1dffce
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 50 deletions.
28 changes: 28 additions & 0 deletions assets/waveform.glsli
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,31 @@ layout(push_constant) uniform DrawCmd {
uint start_idx;
uint sample_count;
} draw_cmd;

layout(set = 0, binding = 0) readonly buffer WaveformBuffer {
uint minmax[];
} vertex_input;

float lookup_value(uint pos) {
if (pos < draw_cmd.sample_count) {
vec2 values = unpackSnorm2x16(vertex_input.minmax[pos / 2]);
return (pos % 2) == 0 ? values.x : values.y;
}
return 0.0;
}

vec2 get_minmax_value(uint pos) {
float scale_x = draw_cmd.scale_x;
float sample_pos = float(pos) * scale_x;
uint scan_len = uint(ceil(scale_x + fract(sample_pos)));
float min_val = 1.0;
float max_val = -1.0;

for (uint i = 0; i < scan_len; i++) {
float s = lookup_value(uint(sample_pos) + i);
min_val = min(min_val, s);
max_val = max(max_val, s);
}

return vec2(min_val, max_val);
}
25 changes: 0 additions & 25 deletions assets/waveform_aa.vs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,6 @@

layout(location = 0) out float coverage;

layout(set = 0, binding = 0) readonly buffer WaveformBuffer {
uint minmax[];
} vertex_input;

float lookup_value(uint pos) {
vec2 values = unpackSnorm2x16(vertex_input.minmax[pos / 2]);
return (pos % 2) == 0 ? values.x : values.y;
}

vec2 get_minmax_value(uint pos) {
float scale_x = draw_cmd.scale_x;
float sample_pos = float(pos) * scale_x;
uint scan_len = uint(ceil(scale_x + fract(sample_pos)));
float min_val = 1.0;
float max_val = -1.0;

for (uint i = 0; i < scan_len; i++) {
float s = lookup_value(uint(sample_pos) + i);
min_val = min(min_val, s);
max_val = max(max_val, s);
}

return vec2(min_val, max_val);
}

void main() {
uint vertex_id = gl_VertexIndex;
uint peak_pos = vertex_id / 6;
Expand Down
25 changes: 0 additions & 25 deletions assets/waveform_fill.vs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,6 @@

layout(location = 0) out float coverage;

layout(set = 0, binding = 0) readonly buffer WaveformBuffer {
uint minmax[];
} vertex_input;

float lookup_value(uint pos) {
vec2 values = unpackSnorm2x16(vertex_input.minmax[pos / 2]);
return (pos % 2) == 0 ? values.x : values.y;
}

vec2 get_minmax_value(uint pos) {
float scale_x = draw_cmd.scale_x;
float sample_pos = float(pos) * scale_x;
uint scan_len = uint(ceil(scale_x + fract(sample_pos)));
float min_val = 1.0;
float max_val = -1.0;

for (uint i = 0; i < scan_len; i++) {
float s = lookup_value(uint(sample_pos) + i);
min_val = min(min_val, s);
max_val = max(max_val, s);
}

return vec2(min_val, max_val);
}

void main() {
uint vertex_id = gl_VertexIndex;
uint peak_pos = vertex_id / 2;
Expand Down

0 comments on commit d1dffce

Please sign in to comment.