Commit: c1a71d5569172be1d5af8cfe5f643c83b2911b07
Parent: 8081307be24477a31b0e0dd9023eb6850ef400da
Author: Randy Palamar
Date: Tue, 27 Aug 2024 08:18:22 -0600
cleanup a few things in the shaders
* be explicit about F#
* lpf_order of 0 should give 0 phase offset
* lpf_order of 0 should give no I-Q correction
* hadmard left shift value should be calculated correctly -
it only worked because any number greater than 1 multiplied by
16 gives a number greater than 32 which meant that every bit
would be shifted out.
Diffstat:
5 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/beamformer_parameters.h b/beamformer_parameters.h
@@ -24,7 +24,7 @@ typedef struct {
v2 xdc_min_xy; /* [m] Min center of transducer elements */
v2 xdc_max_xy; /* [m] Max center of transducer elements */
u32 channel_offset; /* Offset into channel_mapping: 0 or 128 (rows or columns) */
- i32 lpf_order; /* Order of Low Pass Filter (-1 if disabled) */
+ u32 lpf_order; /* Order of Low Pass Filter */
f32 speed_of_sound; /* [m/s] */
f32 sampling_frequency; /* [Hz] */
f32 center_frequency; /* [Hz] */
diff --git a/shaders/2d_hercules.glsl b/shaders/2d_hercules.glsl
@@ -18,7 +18,7 @@ layout(std140, binding = 0) uniform parameters {
vec2 xdc_min_xy; /* [m] Min center of transducer elements */
vec2 xdc_max_xy; /* [m] Max center of transducer elements */
uint channel_offset; /* Offset into channel_mapping: 0 or 128 (rows or columns) */
- int lpf_order; /* Order of Low Pass Filter (-1 if disabled) */
+ uint lpf_order; /* Order of Low Pass Filter */
float speed_of_sound; /* [m/s] */
float sampling_frequency; /* [Hz] */
float center_frequency; /* [Hz] */
@@ -88,10 +88,11 @@ void main()
* \ |z_e - z_i|/
*
* where x,z_e are transducer element positions and x,z_i are image positions. */
- float apod_arg = 0.5 * radians(360) * output_size.y / output_size.x / abs(image_point.z);
+ float f_num = output_size.y / output_size.x;
+ float apod_arg = f_num * 0.5 * radians(360) / abs(image_point.z);
/* NOTE: for I-Q data phase correction */
- float iq_time_scale = radians(360) * center_frequency;
+ float iq_time_scale = (lpf_order > 0)? radians(360) * center_frequency : 0;
vec3 starting_dist = vec3(image_point.x - xdc_min_xy.x, image_point.y - xdc_min_xy.y, image_point.z);
float dx = xdc_size.x / float(dec_data_dim.y);
@@ -109,8 +110,7 @@ void main()
uint base_idx = (i - uforces) / 4;
uint sub_idx = (i - uforces) % 4;
- vec3 focal_point = vec3(uforces_channels[base_idx][sub_idx] * dx, 0, focal_depth);
- float transmit_dist = image_point.z; //+dzsign * distance(image_point, focal_point);
+ float transmit_dist = image_point.z;
for (uint j = 0; j < dec_data_dim.y; j++) {
float dist = transmit_dist + length(rdist);
diff --git a/shaders/demod.glsl b/shaders/demod.glsl
@@ -22,7 +22,7 @@ layout(std140, binding = 0) uniform parameters {
vec2 xdc_min_xy; /* [m] Min center of transducer elements */
vec2 xdc_max_xy; /* [m] Max center of transducer elements */
uint channel_offset; /* Offset into channel_mapping: 0 or 128 (rows or columns) */
- int lpf_order; /* Order of Low Pass Filter (-1 if disabled) */
+ uint lpf_order; /* Order of Low Pass Filter */
float speed_of_sound; /* [m/s] */
float sampling_frequency; /* [Hz] */
float center_frequency; /* [Hz] */
diff --git a/shaders/hadamard.glsl b/shaders/hadamard.glsl
@@ -26,7 +26,7 @@ layout(std140, binding = 0) uniform parameters {
vec2 xdc_min_xy; /* [m] Min center of transducer elements */
vec2 xdc_max_xy; /* [m] Max center of transducer elements */
uint channel_offset; /* Offset into channel_mapping: 0 or 128 (rows or columns) */
- int lpf_order; /* Order of Low Pass Filter (-1 if disabled) */
+ uint lpf_order; /* Order of Low Pass Filter */
float speed_of_sound; /* [m/s] */
float sampling_frequency; /* [Hz] */
float center_frequency; /* [Hz] */
@@ -70,7 +70,7 @@ void main()
* We need to shift arithmetically (maintaining the sign) to get the
* desired element. If the time sample is even we take the upper half
* and if its odd we take the lower half. */
- uint lfs = ~(time_sample & 1u) * 16;
+ uint lfs = ((~time_sample) & 1u) * 16;
/* NOTE: Compute N-D dot product */
int sum = 0;
diff --git a/shaders/uforces.glsl b/shaders/uforces.glsl
@@ -18,7 +18,7 @@ layout(std140, binding = 0) uniform parameters {
vec2 xdc_min_xy; /* [m] Min center of transducer elements */
vec2 xdc_max_xy; /* [m] Max center of transducer elements */
uint channel_offset; /* Offset into channel_mapping: 0 or 128 (rows or columns) */
- int lpf_order; /* Order of Low Pass Filter (-1 if disabled) */
+ uint lpf_order; /* Order of Low Pass Filter */
float speed_of_sound; /* [m/s] */
float sampling_frequency; /* [Hz] */
float center_frequency; /* [Hz] */
@@ -88,17 +88,18 @@ void main()
* \ |z_e - z_i|/
*
* where x,z_e are transducer element positions and x,z_i are image positions. */
- float apod_arg = 0.5 * radians(360) * output_size.y / output_size.x / abs(image_point.z);
+ float f_num = output_size.y / output_size.x;
+ float apod_arg = f_num * 0.5 * radians(360) / abs(image_point.z);
/* NOTE: for I-Q data phase correction */
- float iq_time_scale = radians(360) * center_frequency;
+ float iq_time_scale = (lpf_order > 0)? radians(360) * center_frequency : 0;
vec2 starting_dist = vec2(image_point.x - xdc_min_xy.x, image_point.z);
float dx = xdc_size.x / float(dec_data_dim.y);
float dzsign = sign(image_point.z - focal_depth);
/* NOTE: offset correcting for both pulse length and low pass filtering */
- float time_correction = time_offset + (lpf_order + 1) / sampling_frequency;
+ float time_correction = time_offset + lpf_order / sampling_frequency;
vec2 sum = vec2(0);
/* NOTE: skip first acquisition in uforces since its garbage */