Shader: Buggy Waves

With this shader I tried to replicate a GIF you probably would've seen sometimes. Anyway, here is the GIF I am talking about.

We can calculate the height of the bars with: $$ y = \sin\left(\sqrt{x^2 + z^2}\right). $$ Of course it has some offset in the phase, and is animated, but this gives a general idea on how to get the shape. I have added the shader below, which is hosted on ShaderToy. Press play to start it!

We also need to calculate the subdivisions for each bar, because every point on the same bar should have an equal height. We can do this, in 2D, with $$y = \frac{\textrm{floor}(n \cdot x)}{n},$$ where $n$ is how many subdivisions we want to create. This image should give a good idea of it.

Something that bugs me is that I actually didn't get the count right for subdividing the bars, so there are some bugs. I will look at this later, and probably expand a bit on this post.