HaRQ: Can I squeeze a ray marching shader with refraction and reflection off of a shallow water modeled pond into a ShaderToy shader ?

HaRQ: Can I squeeze a ray marching shader with refraction and reflection off of a shallow water modeled pond into a ShaderToy shader ?

Yes, but my solution nearly breaks my own rules about Euler integration, and the contrived ways ray marching figures out which surface is intersected creates quite a mess. Consequently doing more than one bounce for each reflection or refraction really hurts performance.

Overview

Shader Toy is kind'a awesome. It provides a GPU shader sandbox with standardized peripherals! It relieves you from having to deal with the JavaScript (or any other) harness and lets you get straight to the shader coding!

However, that also means you have to work within the constraints it provides. For any shader, there are just four input textures that can be variously connected to the keyboard, sound files, videos, ordinary textures, or one of four texture buffers. Each of the four texture buffers has its own shader and provides four floating-point channels per pixel. So, we have at most just 16 variables per pixel to store everything we need.

Shallow water models are very simple, and can be arranged in several different ways. All of them operate in roughly the manner, at each grid point: 1. Update tendencies from the heights, that is the spatial derivatives; 2. Update the horizontal velocities, that is, the time derivatives; 3. Update the heights, that is, integrate the time step.

Lastly, the Ray Marching part is pretty standard, along with the standard mess from not being able to do recursion. Shader languages are more of a macro language cosplaying as a C or C++-lite language, due to how the shader code is forced to executed.