View Full Version : Water... endless water...

10.10.2013, 13:34
So let's continue our journey. You might know (well ok, of course you know!) that the Pacific Ocean is pretty huge. So how do I put such an endless ocean into a smartphone which fits in your pocket?

Simple answer: I don't. Actually I want some water which looks a bit like water so it should have real waves and yes, it has real ones! The key to that is some boring math stuff (fast fourier transformation) which works pretty good. There's only one BUT, which is that it can become quite time consuming especially on mobile devices which simply doesn't have the power to handle many of these calculations.

So the first trick is to use patches of the ocean like a grid of the same waves over and over. That limits the needed calculations but then we have still the problem that the vertex count goes beyond any imagination. So the more triangles the GPU has to render, the slower everything gets. Hmm...

Best is to just render only a few patches. In that case we have the problem that the visibility range is pretty low. So no endless ocean.

Let's take some pictures here to see what I'm talking about. Look at this freighter which is about 6,100 metres away from your submarine (out of torpedo range anyway!):
Click to enlarge (http://www.silentdepth.com/dl/screenshots/b017-1.jpg)

Let's take a look to the 8x zoomed periscope as well:
Click to enlarge (http://www.silentdepth.com/dl/screenshots/b017-2.jpg)

You clearly see the freighter which is far, far away and... well... it's flying?! Right actually it doesn't but the real horizon line is at 0 level, the ship is there as well but the ocean simply doesn't reach that far as I render only a few patches!

So what to do? There are two things you can consider here. Either you move the ship down or you just move it in front of your submarine and scale it down. I use the second technique here because I will introduce some horizon later which would just hide the ship in its original position.

How does it look? You have to take a closer look to see the ship in the distance...
Click to enlarge (http://www.silentdepth.com/dl/screenshots/b017-3.jpg)

It's easier to spot with the periscope:
Click to enlarge (http://www.silentdepth.com/dl/screenshots/b017-4.jpg)

Right, this looks ok. Remember, the ship is still 6,100m away but it's now scaled down and moved to a position right onto the ocean grid (which only goes about 400m, yes only four hundred metres, into each direction).
BUT wait! That still doesn't look right, mhh? Ahh grasshopper! You're right! The periscope looks into the sky, to the real 0-horizon line where the rendered one is just below (because of the camera perspective). So we do a trick again and just let the camera look down a bit dependent from the periscope zoom!
Click to enlarge (http://www.silentdepth.com/dl/screenshots/b017-5.jpg)

That's better! :) Still, the horizon looks pretty "sharp" and "edged" so let's add just some kind of a ring mesh to make more dump and circular:
Click to enlarge (http://www.silentdepth.com/dl/screenshots/b017-6.jpg)

Again the periscope view:
Click to enlarge (http://www.silentdepth.com/dl/screenshots/b017-7.jpg)

That's it! Some tricks, we can look now as far as we want to but haven't to render that far away! Oh and I did forget to mention that the ocean patches are moved together with the submarine of course!