Tanshaydar's Place
Currently nothing
Filed under: Programming, Video Games

An Anatomy of a Simulation

Most difficult thing about being an indie developer is financial issues. To overcome this, you’ll either forsake your independence, your time, or your life force.
But sometimes, sometimes it is possible to hit the jackpot.
This post, is a story of that kind of an event.

Since the time I started to develop Paralycid, the money we spent has an extend; but we have to postpone some things constantly. To maintain ourselves as freelancers by the job we are doing is nearly impossible. Furthermore, most companies in Turkey are acting like necrophiliac, trying to buy whole company at the price of the simplest product. Nevertheless, it is required to do something withing our knowledge and skills. At this moment, one of the members of my core team, Marco, said that the place he works at needs a simulation.

What’s required was relatively simple, but in order to do that, I had to prepare an ocean scene realistically, and simulate the water physics inside that.

Marco, loves UDK more than Unity, and I love Unity more than UDK and CryEngine. I’ve talked about reasons if this situation (Pattern Oriented). Nevertheless, to make a realistic looking ocean scene was relatively easier in UDK than Unity. Okay, fine, then how about other mechanics? I decided to go with ‘the way I know’ and wanted to do it in Unity.

1) Unity’s Own Water System

Unity Free and Unity Pro, has a built-in shaders. The water shader in Pro version is transparent, has both refraction and reflection visually; but even though it has all these features, the extend of visuals are limited to these:
Unity Pro WaterUnity Pro Water

Unfortunately, as you can see, it’s way aged visually. Especially in an ocean scene. Maybe it can be considered as ‘just enough’ for a shoreline; but when I start to build Reflections, it’s sure that I won’t use this to build Gemlik shore. It looks like a jell.
This is the best you can do, and it was achieved many years ago:
Unity Pro Water

Therefore, I started to search for Unity water plugins, maybe I’d find something better.

2) Triton for Unity3D

Triton for Unity3D

Now, Triton looks relatively better. Waves and buoyancy mechanics are included too. Visuals are not that appealing, but mechanics I want is there. With some shader quality playground, I’d achieve what I want… Oh, ok, wait a minute, $475. Well…

Triton for Unity3D

To be honest, I wouldn’t spend $475 for this. So, Triton is out of options.

3) Livenda DX11 Ocean

Now, this is a killer!
This is exactly what I’ve been looking for.
Livenda DX11 Ocean for Unity3D

Nevertheless, it’s still under development and when I tried to contact with developers, it was stated that it’s not a topic of question to share/sell the current stage. So, this was another dead end. I had to keep looking.

4) Tasharen Water / Suimono Water System / Dynamic Water v2

There are lots of water system for Unity out there.

One of them is Tasharen Water.
Tasharem Water
As you can see, visually, it’s at the same level of Age of Empires 2. Next.

Next one is Suimono Water System (2.0 beta).
SUIMONO Water
Appealing, physically fit, mechanically meets the requirements; however it is still in its beta stage and crashes, FPS drops and other minor bugs prevents me to go for end user.
Plus, this video shows that those waves are not that good looking in real time. It looks like a cheap trick. Livenda’s water system is gorgeous compared to this; but they both are still under development and using them is out of question.

Dynamic Water System, physically gives exactly what I needed, but visually…
Dynamic Water System
Physically great; but man, this is even worse than Unity’s own water shaders!

5) Ocean Surface Effects in Unity

At the end, ocean surface, sea surface, or even water surface can be created procedurally with specific algorithms. When they first announced DirectX11, new water dynamics were an eyesore.
Now, is is possible to use these procedural algorithms in Unity to create such a surface?

Looks like it is:
Ocean Surface Effect for Unity
Realtime procedural water surface generation thesis, papers etc… This is based on them, completely procedural and impact on the system is really low!
I think anyone who traveled with a ship has seen this scene 😀

And I decided to go with this system. All codes, shaders were for me to play with (Triton gives dlls btw).

5-a)Reflections?

When I decided to use this, I realized that there is no reflection of objects over the surface. The shader that comes with it doesn’t accept new additions (or I failed to add them).
Then I found another way to accomplish this. I’d place another surface and draw reflections of the objects over it.
But this time, the water was not transparent and it was impossible to see reflections!

I opened the Shader and inspected it thoroughly. I inspected procedural code, and I failed to make the shader transparent. Then I went ahead and changed the priority of the layer in drawing code, making it so that reflections would be drawn before the water surface. Well, what do you know, it worked.

5-b)Refraction?

But there was another problem. Reflections were so direct that it looked like a mirror. However, no ocean, no sea would reflect like a mirror. There needs to be an amount of refraction. Therefore, I had to implement a refraction. I put a third layer for this, between the surface and reflection layers, made it so that it’s priority was lowest but still would work like a post process. I refracted the reflections then draw them.

6) Waves & Buoyancy

Now, this is what I needed physically.
At this point, Unity’s own physics system would be enough I thought. There was gravity, yeah so I could play with it. Just a little inside editor plugin let me to compare buoyancy and gravity, and calculate the fractures. But this time, there was another problem: Object would rise and sink completely, not partially or rotate.

I thought I couldn’t solve this, but then I inspected how previous plugins do that. I saw that they would generate extra colliders procedurally. Means that relatively to the object size and buoyancy quality, it was possible to calculate the force on specific points. High school physics:
1 – Calculate the gravity center or pick it
2 – Create colliders procedurally and calculate wave, buoyancy and gravity force at these points
3 – Gather all to calculate the momentum on the object
4 – Translate this momentum to position and rotation. At this point, I used Quaternion with Euler.

As a result, I got this:
tanshaydar_dgs_defence_water_simulation

On the movement point, I added a splash effect, writing a simple controller, and now the framework of the simulation worked like a charm.

I have achieved more than I guessed I would, I would say, but then I saw Naval Action…
It is two decades in front of my technolgoy.

3rdratestorm

Nevertheless, all programming, visuals, shaders, effects and all other kind of little f*ckers are on me and I’ve been working with Unity for 10 months now. So, this kind of professionalism is way beyond me. They created their own system, shaders, and all are procedural as I learned from them.

In the end, I achieved the level I wanted for this simulation. After all, I needed to provide a web build, which I have no idea if UDK and/or CryEngine supports. Given the states and requirements, I’d say, this is the anatomy of a simulation.

Verba Volant, Scripta Manent

This site uses Akismet to reduce spam. Learn how your comment data is processed.