Flash 3D Water Simulation

This project demonstrates a simple 3D water simulation written in Flash, using ActionScript 3, Flare3D, and PixelBender. Originally, it was developed as the technical test for an interview. It was a very interesting project to create, as the limitations of Flash in terms of functionality made for some intriguing solutions. The shader for the water is completely overkill for what was required, but it was fun to keep throwing new features at it. If you want to know how it works, the source code is available on GitHub and BitBucket.

You can try it out for yourself, if you so please, but do be warned that performance was not a concern with this project. Dragging the left mouse button on its own will rotate the camera, and scrolling the mouse wheel will zoom in and out. Pressing CTRL will toggle a rain effect. Pressing spacebar will toggle the ability to draw in the water with your mouse. From my experience, certain browsers dislike this and lag a lot, whereas others run very smooth, so your mileage may vary depending on your current browser.

Unfortunately, Flash doesn't support floating point textures, so everything had to be stored per vertex. Due to limitations in how (I think that) Flare3D works, custom vertex data can be assigned to a Surface3D on top of a mesh (such as a Plane, as is used in this simulation). Due to either a bug or misunderstanding, only a single piece of additional data could be added to each vertex, with a maximum of four components. With that in mind, I added a single color channel to each vertex; in other words, each vertex had X, Y, Z, and W components in a Surface3D in addition to its usual XYZ. Using PixelBender, the vertex data is sent into various shaders, such as simulation update, normals update, and water droplets (which is used when the mouse is moved to disturb the surface, and also for rain). The four components mentioned earlier represent the height, velocity, normal X, and normal Z respectively. In the final shader, the complete normal is recomputed from the Z and W components of the vertex color (normal X and normal Z), and the position of each vertex is offset by its corresponding height. The shader also includes blended normal maps, specular highlights, diffuse lighting, sunlight simulation, cubemap reflection, scene reflection and refraction, wave colors, and foam colors.