Update SL's Flat Water Plane With "Gerstner Waves".
SarahKB7 Koskinen
In Second Life, the water is a single global, infinite plane, mostly fixed at a 20 metre altitude in the Mainland and Linden Homes regions.
Currently, to simulate rolling waves, scripted wave shaped objects made from prims, sculpts or meshes are physically moved across the flat water plane. And it looks unconvincing, fake and outdated.
After 23 years, this badly needs updating and replaced with something much more realistic. The most effective way to simulate realistic rolling waves for Second Life is using "Gerstner Waves".
Gerstner Waves are easier to implement, cheaper to compute, and better for stylized or simple water than other more "expensive" methods such as Fast Fourier Transform (FFT), already used in AAA games and movies.
Adding Gerstner Waves would require updating the OpenGL Shading Language shaders in the viewer code to replace the flat-plane mathematics with Gerstner Wave equations. (See: https://en.wikipedia.org/wiki/Trochoidal_wave )
However, Gerstner Waves do have a downside, their waves can appear repetitive and predictable looking when studied closely.
The Gerstner Waves offset vertices both vertically and horizontally. This creates the characteristic sharp crests and broad troughs seen in real oceans.
Real waves don't just bob up and down; they break and flatten as they hit the beach and sand. To do this without scripts:
Depth Buffers: Use the engine's depth buffer to calculate the distance between the water surface and the terrain.
Vertex Modification: Near the shore (where water depth is low), the shader can automatically reduce the wave amplitude and increase the texture "foam" opacity.
PBR Materials: Utilise the new PBR (Physically Based Rendering) extensions in Second Life to ensure the light reflects accurately off those new wave angles.
Existing boat floatation and buoyancy should be maintained, as well as the ability for an avatar to swim or dive underwater in newly updated seas too. Sunlight and surface sounds should diminish accordingly to avatar's depth underwater.
Multiple Gerstner Waves interacting with each other in SL regions would create random and chaotic waves that closely resemble those in the real world. Hopefully, multiple Gerstner Wave regions connected to each other would blend together seamlessly at region boundaries without visible gaps or troughs.
Updated seas should offer a variety of "Sea State" conditions across the entire region in the region Land settings too. There are 10 internationally recognised Sea States:
Sea State 0 - Calm (glassy) - Wave Height: 0 metres (0 ft)
Sea State 1 - Calm (rippled) - Wave Height: 0 to 0.1 metres (0.0 to 3.9 in)
Sea State 2 - Smooth (wavelets) - Wave Height: 0.1 to 0.5 metres (3.9 in to 1 ft 7.7 in)
Sea State 3 - Slight - Wave Height: 0.5 to 1.25 metres (1 ft 8 in to 4 ft 1 in)
Sea State 4 - Moderate - Wave Height: 1.25 to 2.5 metres (4 ft 1 in to 8 ft 2 in)
Sea State 5 - Rough - Wave Height: 2.5 to 4 metres (8 ft 2 in to 13 ft 1 in)
Sea State 6 - Very Rough - Wave Height: 4 to 6 metres (13 to 20 ft)
Sea State 7 - High - Wave Height: 6 to 9 metres (20 to 30 ft)
Sea State 8 - Very High - Wave Height: 9 to 14 metres (30 to 46 ft)
Sea State 9 - Phenomenal - Wave Height: Over 14 metres (46 ft)
Example video: https://www.youtube.com/watch?v=9S-Glo806TY
Log In
Huns Valen
First and foremost, this cannot be client-side only. It has to run on the simulator. My vehicles can't see what only the client knows, and this has the potential to cause very bad visuals if it's not done thoughtfully.
This could have weird interactions with smaller vessels. One of my seaplanes is barely larger than a jet ski. That doesn't bother me, as long as I have a way to reliably read the wave heights from the region a few times a second, like:
list llGetWaterSurface(vector pos) => [ float elevation, vector normal, float rateOfChange ]
Would also be EXTREMELY USEFUL to have a vehicle system flag that causes the vehicle to comport with the waves. I don't know if you'd want this on-by-default, or off-by-default. A lot of vehicle system setup code goes back as far as late 2003 and obviously won't have taken this into account, so you could get odd issues like boats floating down after cresting a wave at a weirdly slow descent rate.
I'd say a vehicle system integration is an absolute must for this. I can see "doing this manually" with an llGetWaterSurface() call but there's going to be a fair amount of experimentation and math involved. That's NOT something you want to put every vehicle developer in a position to solve individually when LL could solve it once for everyone.
Likewise, WITHOUT something like llGetWaterSurface(), my ability to make my vehicles react realistically (like pitching over once the CG passes the crest of a wave) isn't going to be there, and the results will probably look stupid. Nor do I want to have to rely too much on the vehicle system for this as I want the ability to customize how the vehicle bobs. There is not one sea or float hull. A catamaran doesn't bob the same way as a rowboat and neither bobs the same way as a huge WWII-era seaplane. They don't have the same mass or mass distribution, hence they will not have the same inertia tensor overall, or individual body elements that will push back against the waves (or suddenly stop pushing back when a wave drops). They don't have pontoons in the same places to push back against roll (if any at all).
primerib1 Resident
Huns Valen Regarding this:
"First and foremost, this cannot be client-side only. It has to run on the simulator. My vehicles can't see what only the client knows, and this has the potential to cause very bad visuals if it's not done thoughtfully."
If the Gerstner Wave equation is time-based -- which, considering there's a "t" factor in the linked Wikipedia page, probably is -- then there is no need for server-side. Only need to synchronize the timestamp between server and client, and client can figure out all the deformations needed.
After all, this is the linchpin of TOTP, enabling it to work even if the TOTP Authentication App is offline : That the server's and the app's time is synchronized 'enough'.
To ensure synchronicity, then SL's server can send a "heartbeat" packet -- say once every 2 to 5 seconds -- containing the server's UTC timestamp. Clients resync on every heartbeat (and optionally calculate their drift factor so misaligned ticks are reduced), and apply deformations to the ocean surface according to the timestamp, extrapolating the "t" factor until the next heartbeat.
But with regards to (water) vehicles, since they run server-side, then yes a new feature to read wave height might be necessary. Or might be "workaround-ed" by marking the vehicle as "on water" and let the client perform deformation/translation according to the ocean deformer's shape at the vehicle's position.
Rizzy Khaos
Im curious how these waves will react with water vehicles.
LiliSquibb Resident
I support this 100%. As a boatbuilder the relatively unconvincing nature of Second Life's waters has been frustrating for a long time. I'd go further and suggest dynamiic weather across SL, with varying (and moving) weather systems including precipitation. Yes yes I know that's a big ask and I have no technical clue how it might be implemented but it would bring SL to life in ways that are currently lacking and surely ought to be possible to implement by now. I assume this kind of system would need to be optional (use shared environment) so cruises and races could still choose their own specific winds if desired, but it might also be good to introduce an optional element of 'you have to deal with what the weather's doing today when you show up at the start line' too.
JenniWindrider Resident
I rather like the idea of better waves in SL. The question is... how does this e.g. affect boating as well as shallow inlets and/or pools that often get sunk into the ground to have the benefit of SL water over prim water?
I could see this working if there was some kind of distance modifier maybe, i.e. as the water plane gets bigger, the waves accentuate more.
The next question is how this interacts with SL coastlines.
Honestly, I'd love to see better SL water. The question is whether that can be done without breaking a ton of content, and I welcome discussions/ideas about details.
Beatrice Voxel
JenniWindrider Resident There's really only one calculation needed* for 'how big the waves can get' and that's surface area of the pond, or lake, or ocean. If the scale of the Gerstner waves is coupled to surface area in meters squared, we should be able to get everything from small pond riffles to large surfable waves (theoretically).
* yes there are also dynamics in play where depth of the water modifies an existing wave - as the depth gets less, the wave grows upward. But as far as 'wind effecting calm water' it's mostly wind velocity across distance, so small ponds shouldn't ever have huge waves.
JenniWindrider Resident
Beatrice Voxel Yes and no. That is one variable. In SL even just surface would be tricky because of mesh beaches and mesh/prim islands. You'd have a fair bit more calculation to do. And of course, existing boats. And that's completely ignoring wave refraction and build up, which does matter. You don't want huge waves outgoing from a coastline, they have to be distance-attenuated again.
As someone who sails both RL and SL, it's a complex topic. So long as we only talk water depth to ground, it's fairly easy. Enter mesh on/in the water and things get less straightforward.
Take the inlet on the Dura sim for example. Or the over-water builds on Starstrider. Both have fairly large bodies of water connected.
Not saying it can't be done, but I do think it's a bit more complex.
Cain Maven
Very interesting. Any idea how it might affect performance, though?
primerib1 Resident
Cain Maven The actual calculation is surprisingly simple-ish, based on how someone implemented it for Godot:
They even include how to calculate buoyancy.
I would speculate that the performance hit is probably 1-2%.
SarahKB7 Koskinen
Please also consider upvoting this similar request: https://feedback.secondlife.com/feature-requests/p/waves-in-second-life-seas
Bavid Dailey
there are international standards for seas state? Who decides ? (genuine question)
SarahKB7 Koskinen
Bavid Dailey - The World Meteorological Organization (WMO) sets Sea State standards. See: https://en.wikipedia.org/wiki/Sea_state
Rowan Amore
How would this impact game performance? Region crossings?