Ultrasound sim project at @LevelExGameDev is starting to produce vaguely plausible results
here's a gas bubble reverberating; sound gets trapped inside and bounces multiple times before escaping, creating a characteristic trail of echoes
This is a record of a twitter thread, originally posted in 2019
Ultrasound sim project at @LevelExGameDev is starting to produce vaguely plausible results
here's a gas bubble reverberating; sound gets trapped inside and bounces multiple times before escaping, creating a characteristic trail of echoes
The real-world artifact doesn't precisely look like this, but I'm pretty proud of the fact that the sim just *does this* when presented with a pocket of low-impedance, non-scattering material, without any special-case code
Also check out my kickass mad-scientist debug visualizations
Mouse selects blue scanline on the left, which is displayed as an amplitude signal ("A-mode" in ultrasound terminology) on the right
Black graph is raw signal, white graph is after time-gain compensation and tonemapping
Amplitude at the mouse (red circle) is printed at bottom
this is a bug but it's also extremely good
So earlier images simulating 1D wave propagation on a texel grid. Now trying an alternate approach using huge numbers of particles, representing stochastic effects like diffuse reflections by just doing dice rolls for every particle
Makes a very cool visualization at least
did you know that compute shaders are Really Fast
update: did you know that compute shaders are Not Fast Enough
So here's an (idealized) single pulse of energy along a single direction, analogous to an A-mode line in actual ultrasound
(the grey image isn't coming from the sim; it's just displaying the underlying anatomy that the waves interact with)
The handful of stationary particles are those that followed paths back to the transducer to register an echo signal
What it SHOULD produce is a nice yellow line of varying brightness, but instead it runs out of particles almost entirely after like two centimeters
I have thus learned the problem with rendering participating media via huge numbers of particles: Everything falls off exponentially, so it turns out the sheer quantity of particles required is completely untenable
That dot had *ten million particles* in it
When a wave strikes an interface, some portion of its energy is reflected and the rest transmitted
I'm simulating this by having particles check a random roll to see if they should bounce or continue on
A wave of 10,000,000 particles is down to single digits by the third bounce
...and that's just reflection/refraction at interfaces, I haven't even added scattering yet, which is an even faster exponential energy loss
I can do 10M particles in 16ms via compute shaders, but to actually fully resolve an image you'd need... trillions? quadrillions?
Anyway this is why nobody writes renderers that just naively track discrete photons, obviously. I was hoping that since ultrasound operates in 2D (sorta) I could at least produce a recognizable image with a reasonably tractable particle count, but, nope lol
Obviously the real solution here is Just Write A Path Tracer Dude but that's boring and hard and also probably too slow for phones (probably)
The grid-based propagation sim from earlier in the thread is still super promising in any case
Absolutely zero people will ever notice this but I feel extremely smart
One day I'll be as powerful as those dudes who publish siggraph papers about like An Improved BDRF Thing with a picture of spheres and then a picture of IMPROVED spheres and then they subtract the two in Photoshop and have to put the diff on an inverse log scale for you to see it
procedurally generating thyroids wrong