ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | LICENSE

render.glsl (1122B)


      1 /* See LICENSE for license details. */
      2 layout(binding = 0) uniform sampler3D u_out_data_tex;
      3 
      4 /* input:  h [0,360] | s,v [0, 1] *
      5  * output: rgb [0,1]              */
      6 vec3 hsv2rgb(vec3 hsv)
      7 {
      8 	vec3 k = mod(vec3(5, 3, 1) + hsv.x / 60, 6);
      9 	k = max(min(min(k, 4 - k), 1), 0);
     10 	return hsv.z - hsv.z * hsv.y * k;
     11 }
     12 
     13 void main()
     14 {
     15 	ivec2 out_data_dim = textureSize(u_out_data_tex, 0).xz;
     16 
     17 	//vec2 min_max = texelFetch(u_out_data_tex, ivec3(0), textureQueryLevels(u_out_data_tex) - 1).xy;
     18 
     19 	/* TODO(rnp): select between x and y and specify slice */
     20 	ivec2 coord     = ivec2(fragment_texture_coordinate * vec2(out_data_dim));
     21 	ivec3 smp_coord = ivec3(coord.x, 0, coord.y);
     22 	float smp       = length(texelFetch(u_out_data_tex, smp_coord, 0).xy);
     23 
     24 	float threshold_val = pow(10.0f, u_threshold / 20.0f);
     25 	smp = clamp(smp, 0.0f, threshold_val);
     26 	smp = smp / threshold_val;
     27 	smp = pow(smp, u_gamma);
     28 
     29 	if (u_log_scale) {
     30 		smp = 20 * log(smp) / log(10);
     31 		smp = clamp(smp, -u_db_cutoff, 0) / -u_db_cutoff;
     32 		smp = 1 - smp;
     33 	}
     34 
     35 	//v_out_colour = vec4(hsv2rgb(vec3(360 * smp, 0.8, 0.95)), 1);
     36 	v_out_colour = vec4(smp, smp, smp, 1);
     37 }