# Real-Time Simulation of Wave Phenomena in Lung Ultrasound Imaging
## 2 Simulation Method
### Ultrasound Simulation  
The first step was a 3D vector model creation of a patient and internal structures. The authors decided to use the Daz 3D [36] software and an asset of male and female with internal organs available in the Daz 3D Assets Store [37]. To meet the simulation requirements, models were adjusted and animated; in particular, the motion of the lungs was added. The animation was manually implemented to reflect the lung's movement as visible on the acquired ultrasound videos. Ribs movement was not implemented because the complexity of modeling exceeds the benefits and impact of animation on the final outcome. The speed and the range of the lung animation vary depending on the selected patient, which reflects the breathing speed and the depth of inhalation.  
In the following step, the Unity framework was used to create a simulation platform for the Lung Ultrasound Simulator. The Unity framework is widely utilized for developing 2D and 3D games, and it has also found extensive application in the medical field [38; 39; 40; 41]. Moreover, it serves as a solid foundation for creating web-based 3D applications, offering a versatile platform for delivering immersive experiences over the Internet.  
The previously prepared models were imported into the Unity framework, and then a virtual examination room and virtual US probe were created. Users can manipulate the probe and position it on the patient's body using a computer mouse.  
Next, a disease scenario was implemented for each patient by configuring the landmark states to the appropriate values based on the expected observations.  
Then, the simulation algorithm is used to render the simulated US image:  
1. According to the virtual probe position and orientation, the 3D model of the patient and its internal structures are rendered using a virtual camera and custom shader program. Only the cross-section is visible and rendered as an image into the frame-buffer. This is an approximation of an ultrasound image in which individual tissues are rendered using a custom shader (called Material) that, among others, encodes the required physical parameters (like absorption coefficient and acoustic impedance) as a color. Additionally, the cross-section is completed with a simulation of the tissue structure. This is achieved using a position-dependent pseudorandom values function [42].
2. The same virtual camera renders a UV map of the moving tissues. UV value is a vertex attribute required to correctly map a texture on an object. However, in this case, this step is used to simulate pulmonary pleurae movement and related artifacts. The values rendered on the UV map correspond to the local position of the lung surface. The lung's movement corresponds to the changes in these values.
3. Another virtual camera is employed to render the ultrasound (US) sector. This camera utilizes a shader program that incorporates the modified ray-marching method to simulate wave propagation. This step was challenging because instead of a compute shader, better suited for this problem, a regular fragment shader had to be used. Compute shaders were not supported in the web browser environment at the time of writing. In the resulting image, each column corresponds to a ray, and each row is a ray marching step.
4. A shader program that extends the results of previous steps with additional wave phenomena, including A-lines and noise.
5. A shader program that transforms the results into a selected sector view.