Dear Urho3D community,
because this is my first Topic in this forum I am very excited about your feedback. But first I have to say thank to the people that created this great game engine. I stumbled over it when I was looking for an alternative to the Ogre3D engine, which is a little bit outdated, at least from my perspective. When I looked into the source code of the Urho3D engine I was really impressed how clean and easy to understand it is. I really do not understand why so few people are using it, but maybe I can contribute at least a little bit to change that. But now to my project.
As already mentioned in the title, I am working on a component to simulate waves in real time. Similar to what Lumak already did with his FFT Waves, but I decided to use the Gerstner Waves approach. The work is based on this GPU Gems article . My first version contains only the mesh transforming stuff and no texturing at all . But enough of the bla, bla now. Here is a video of what is already working.
How it works:
I created a component called Ocean that needs a planar mesh which is used as a water plane. By applying several sine wave calculation to a
the vertices the waves are created. Currently everything is calculated on the CPU.
By pressing E, the Wave Editor shows up, which allows you to change the basic properties that are used to create waves. To create some variations the basic properties are not taken as they are but are randomized. To avoid visual jumps all waves are faded-in and out. All waves have a lifetime and if a wave dies it is faded out.
Properties:
Waves
- The amount of active waves at the same time
Lifetime - The time in seconds a wave is active. Randomized between half and double of the basic property.
Steepness
- Defines how steep the crest of a wave is (0 - 1). Higher values moves the vertices closer together at the
top of the wave.
Length - The distance between the crests. It is also randomized between the half and the double of the basic value.
Amplitude
- The height of the wave. Because the length is randomized the amplitude needs to hold the same ratio to
the length as the basic properties.
Speed - How fast a wave moves. Can be randomized with the Speed Variation checkbox.
Direction - Is the direction of movement (x,z). To create some variation in the direction you specify an angle that defines the allowed variation of the direction vector.
Fading
- The editor allows to disable the fading but without fading you get jumps in the vertex positions.
Speed Variation
- Enable speed variations.
Set Button - Feeds the properties of the Wave Editor to the Wave System. Newly created waves use the new properties. It takes some time to see the change, depending on the set lifetime.
Reset Button - Saves the new properties to the Wave System and erases all active waves from the Wave System to force a creation of new waves. If fading is disabled, this allows to see immediately the final state of the new properties.
The next steps could be something like this:
- Try to create a realistic texturing for the water plane. I think what I achieved until now was like a walk in the park compared to creating a realistic looking water surface
- Try to make other objects floating realistically in the water. There is a good but hard to understand article about that topic Water Interaction Model
- Optimize by moving the calculations to a Vertex Shader. Not sure if it makes too much sense, because I need the height field also for the physics.
I guess that`s it for now.
Ah one thing left, you find the source code on my github account. I have a Urho3D fork with a branch feature/ocean, but also a repository Urho3D-Ocean which contains only the added files and the water plane model.