Commit: c414e5851aa57241be9e7686cb3aa845357f9375
Parent: 9ec10673086bccdd4284169ed6496cb6d67516b5
Author: Randy Palamar
Date: Mon, 28 Oct 2024 14:54:58 -0600
add threshold/holdoff to display shader
Diffstat:
5 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/beamformer.c b/beamformer.c
@@ -484,6 +484,7 @@ do_beamformer(BeamformerCtx *ctx, Arena arena)
glUseProgram(fs->shader.id);
glBindTextureUnit(0, ctx->out_texture);
glUniform1f(fs->db_cutoff_id, fs->db);
+ glUniform1f(fs->threshold_id, fs->threshold);
DrawTexture(fs->output.texture, 0, 0, WHITE);
EndShaderMode();
EndTextureMode();
diff --git a/beamformer.h b/beamformer.h
@@ -167,8 +167,11 @@ typedef struct {
typedef struct {
Shader shader;
RenderTexture2D output;
+ /* TODO: cleanup: X macro? */
i32 db_cutoff_id;
+ i32 threshold_id;
f32 db;
+ f32 threshold;
} FragmentShaderCtx;
enum export_state {
diff --git a/shaders/render.glsl b/shaders/render.glsl
@@ -6,6 +6,7 @@ out vec4 v_out_colour;
layout(binding = 0) uniform sampler3D u_out_data_tex;
layout(location = 1) uniform float u_db_cutoff = -60;
+layout(location = 2) uniform float u_threshold = 40;
/* input: h [0,360] | s,v [0, 1] *
* output: rgb [0,1] */
@@ -26,9 +27,14 @@ void main()
ivec3 smp_coord = ivec3(coord.x, 0, coord.y);
float smp = length(texelFetch(u_out_data_tex, smp_coord, 0).xy);
- float absmax = max(abs(min_max.y), abs(min_max.x));
- smp = 20 * log(smp / absmax) / log(10);
+ //float absmax = max(abs(min_max.y), abs(min_max.x));
+ //smp = 20 * log(smp / absmax) / log(10);
+
+ float threshold_val = pow(10.0f, u_threshold / 10.0f);
+ smp = clamp(smp, 0.0f, threshold_val);
+ smp = 20 * log(smp / threshold_val) / log(10);
+
smp = clamp(smp, u_db_cutoff, 0) / u_db_cutoff;
smp = 1 - smp;
diff --git a/static.c b/static.c
@@ -173,8 +173,9 @@ compile_shader(Arena a, u32 type, s8 shader)
static void
init_fragment_shader_ctx(FragmentShaderCtx *ctx, uv4 out_data_dim)
{
- ctx->output = LoadRenderTexture(out_data_dim.x, out_data_dim.y);
- ctx->db = -50.0f;
+ ctx->output = LoadRenderTexture(out_data_dim.x, out_data_dim.y);
+ ctx->db = -50.0f;
+ ctx->threshold = 40.0f;
}
static void
@@ -214,6 +215,7 @@ reload_shaders(BeamformerCtx *ctx, Arena a)
UnloadShader(ctx->fsctx.shader);
ctx->fsctx.shader = updated_fs;
ctx->fsctx.db_cutoff_id = GetShaderLocation(updated_fs, "u_db_cutoff");
+ ctx->fsctx.threshold_id = GetShaderLocation(updated_fs, "u_threshold");
}
}
diff --git a/ui.c b/ui.c
@@ -226,7 +226,6 @@ do_text_input(BeamformerCtx *ctx, i32 max_disp_chars, Rect r, Color colour)
Color cursor_colour = colour_from_normalized(lerp_v4(bg, FOCUSED_COLOUR,
ctx->is.cursor_blink_t));
-
/* NOTE: guess a cursor position */
if (ctx->is.cursor == -1) {
/* NOTE: extra offset to help with putting a cursor at idx 0 */
@@ -500,7 +499,7 @@ draw_settings_ui(BeamformerCtx *ctx, Arena arena, Rect r, v2 mouse)
draw_r = do_value_listing(s8("Sampling Frequency:"), s8("[MHz]"),
bp->sampling_frequency * 1e-6, ctx->font, arena, draw_r);
- static f32 hover_t[13];
+ static f32 hover_t[14];
i32 idx = 0;
BPModifiableValue bmv;
@@ -553,6 +552,11 @@ draw_settings_ui(BeamformerCtx *ctx, Arena arena, Rect r, v2 mouse)
draw_r = do_text_input_listing(s8("Dynamic Range:"), s8("[dB]"), bmv, ctx, arena,
draw_r, mouse, hover_t + idx++);
+ bmv = (BPModifiableValue){&ctx->fsctx.threshold, bmv_store_generic, .flimits = (v2){.y = 240},
+ MV_FLOAT|MV_GEN_MIPMAPS, 1, 1};
+ draw_r = do_text_input_listing(s8("Threshold:"), s8(""), bmv, ctx, arena,
+ draw_r, mouse, hover_t + idx++);
+
draw_r.pos.y += 2 * LISTING_LINE_PAD;
draw_r.size.y -= 2 * LISTING_LINE_PAD;