Commit: ef9bfd349de6ad0e71c7652f6fa96f6d979978cf
Parent: caa974ffa3c99cf4525c631eb2285098abefd1ea
Author: Randy Palamar
Date:   Tue, 27 May 2025 15:27:11 -0600
tweak a few rendering settings
Diffstat:
4 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/common.c b/common.c
@@ -409,6 +409,7 @@ init_viewer(ViewerContext *ctx)
 	"layout(location = " str(MODEL_RENDER_LOG_SCALE_LOC)     ") uniform bool  u_log_scale;\n"
 	"layout(location = " str(MODEL_RENDER_BB_COLOUR_LOC)     ") uniform vec4  u_bb_colour   = vec4(" str(BOUNDING_BOX_COLOUR) ");\n"
 	"layout(location = " str(MODEL_RENDER_BB_FRACTION_LOC)   ") uniform float u_bb_fraction = " str(BOUNDING_BOX_FRACTION) ";\n"
+	"layout(location = " str(MODEL_RENDER_GAIN_LOC)          ") uniform float u_gain        = 1.0f;\n"
 	"\n"
 	"layout(binding = 0) uniform sampler3D u_texture;\n"
 	"\n#line 1\n");
@@ -602,6 +603,7 @@ draw_volume_item(ViewerContext *ctx, VolumeDisplayItem *v, f32 rotation, f32 tra
 
 	glProgramUniform1f(program,  MODEL_RENDER_CLIP_FRACTION_LOC, 1 - v->clip_fraction);
 	glProgramUniform1f(program,  MODEL_RENDER_THRESHOLD_LOC,     v->threshold);
+	glProgramUniform1f(program,  MODEL_RENDER_GAIN_LOC,          v->gain);
 	glProgramUniform1ui(program, MODEL_RENDER_SWIZZLE_LOC,       v->swizzle);
 
 	glBindTextureUnit(0, v->texture);
@@ -651,6 +653,9 @@ update_scene(ViewerContext *ctx, f32 dt)
 	set_camera(program, MODEL_RENDER_VIEW_MATRIX_LOC, camera,
 	           v3_normalize(v3_sub(camera, (v3){0})), (v3){{0, 1, 0}});
 
+	glProgramUniform1ui(program, MODEL_RENDER_LOG_SCALE_LOC,     LOG_SCALE);
+	glProgramUniform1f(program,  MODEL_RENDER_DYNAMIC_RANGE_LOC, DYNAMIC_RANGE);
+
 	#if DRAW_ALL_VOLUMES
 	for (u32 i = 0; i < countof(volumes); i++)
 		draw_volume_item(ctx, volumes + i, angle, volumes[i].translate_x);
diff --git a/opengl.h b/opengl.h
@@ -68,6 +68,7 @@ typedef ptrdiff_t GLintptr;
 	X(glObjectLabel,                         void,   (GLenum identifier, GLuint name, GLsizei length, const char *label)) \
 	X(glProgramUniform1f,                    void,   (GLuint program, GLint location, GLfloat v0)) \
 	X(glProgramUniform1ui,                   void,   (GLuint program, GLint location, GLuint v0)) \
+	X(glProgramUniform4fv,                   void,   (GLuint program, GLint location, GLsizei count, const GLfloat *value)) \
 	X(glProgramUniformMatrix4fv,             void,   (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)) \
 	X(glShaderSource,                        void,   (GLuint shader, GLsizei count, const GLchar **strings, const GLint *lengths)) \
 	X(glTextureParameteri,                   void,   (GLuint texture, GLenum pname, GLint param)) \
diff --git a/options.h b/options.h
@@ -15,6 +15,9 @@
 #define BOUNDING_BOX_COLOUR    0.78, 0.07, 0.20, 1
 #define BOUNDING_BOX_FRACTION  0.007f
 
+#define DYNAMIC_RANGE 30
+#define LOG_SCALE     1
+
 typedef struct {
 	c8  *file_path;
 	u32  width;         /* number of points in data */
@@ -27,6 +30,7 @@ typedef struct {
 	f32  translate_x;   /* mm to translate by when multi display is active */
 	b32  swizzle;       /* 1 -> swap y-z coordinates when sampling texture */
 	b32  multi_file;    /* 1 -> depth == N-frames, file_path == fmt string */
+	f32  gain;          /* uniform image gain */
 	u32  texture;
 } VolumeDisplayItem;
 
@@ -34,8 +38,8 @@ typedef struct {
 global u32 single_volume_index = 0;
 global VolumeDisplayItem volumes[] = {
 	/* WALKING FORCES */
-	{"./data/test/frame_%02u.bin", 512, 1024, 64, {{-20.5, -9.6, 5}}, {{20.5, 9.6, 50}}, 0.62, 72, 0, 0, 1},
+	{"./data/test/frame_%02u.bin", 512, 1024, 64, {{-20.5, -9.6, 5}}, {{20.5, 9.6, 50}}, 0.62, 72, 0, 0, 1, 3.7},
 	/* RCA */
-	{"./data/tpw.bin", 512, 64, 1024, {{-9.6, -9.6, 5}}, {{9.6, 9.6, 50}}, 0, 92, -5 *  18.5, 1, 0},
-	{"./data/vls.bin", 512, 64, 1024, {{-9.6, -9.6, 5}}, {{9.6, 9.6, 50}}, 0, 89,  5 *  18.5, 1, 0},
+	{"./data/tpw.bin", 512, 64, 1024, {{-9.6, -9.6, 5}}, {{9.6, 9.6, 50}}, 0, 92, -5 *  18.5, 1, 0, 5},
+	{"./data/vls.bin", 512, 64, 1024, {{-9.6, -9.6, 5}}, {{9.6, 9.6, 50}}, 0, 89,  5 *  18.5, 1, 0, 5},
 };
diff --git a/render_model.frag.glsl b/render_model.frag.glsl
@@ -26,6 +26,9 @@ void main()
 	smp = smp / threshold_val;
 	smp = pow(smp, u_gamma);
 
+	float t = test_texture_coordinate.y;
+	smp = smp * smoothstep(-0.4, 1.1, t) * u_gain;
+
 	if (u_log_scale) {
 		smp = 20 * log(smp) / log(10);
 		smp = clamp(smp, -u_db_cutoff, 0) / -u_db_cutoff;