Making a Game in Unity 008: Upgraded Graphics & Ocean

Just so you know, this is not a tutorial series! I am writing this series mainly to give you a behind the scenes look at the process of making a game in Unity, and to document the development of this project.

See other posts in this series.


Making a game in Unity 008

These last two weeks were quite productive. Although I had planned to leave flotation alone for a while, I took another shot at it—and I got it working properly! Then I discovered some lighting issues with my low poly shader which I also managed to sort out.

Monday

Today I adapted my new low poly shader to be capable of simulating water. This included adding waves and foam, but unfortunately I wasn’t yet able to reproduce the “wave tint” I had going with the geometry shaders. Since geometry shaders work per triangle instead of per vertex, it’s easy to modify the colour of the whole triangle. As I don’t have access to the same kind of data in the new shader, changing the colour of the entire triangle (which is necessary to produce the low poly look) is more difficult. I’m still trying to find a workaround.

I also added name tags above players’ heads to making identifying players easier.

Tuesday

This evening I added some random-ish noise to the water surface to make it appear more natural.

Afterwards, I decided to tackle flotation (again), so I rewrote the entire algorithm. The ship now behaves more as though it’s actually floating in a fluid, but there’s still some strange issues with it floating up out of the water when cresting a wave.

Wednesday

I spent quite a bit of time today investigating the cause behind the ship rising so high out of the water. Based on my flotation code and physics calculations, this really shouldn’t be happening, but no matter which values I change, the results don’t seem to improve.

Thursday

Today I found the culprit. It turns out that when I added the noise to the water, I also made a minor change to the client-side wave equation, and I completely forgot to make the adjustment server-side. This means the boat was actually responding “correctly” the entire time, but due to my client’s wrong representation of the water, the flotation looked inaccurate.

Although I’m glad I figured out the problem—especially because I can actually fine-tune the flotation mechanics accurately now—I was a little ticked off when I found the cause to be a foolish mistake on my part.

Friday

Today I managed to add colour variation to the waves based on the water height, while still maintaining the low poly look. I was going to take a screenshot and share it here and on Discord, except I noticed that something was off with the lighting.

After playing with the lighting settings a little, the problem became more obvious. For some reason the same side of the ship stays lit up, no matter what its rotation relative to the light is.

Saturday

After doing some admin work on my Discord server this morning (come join the community!), I looked into the lighting issues some more. I spent quite a while trying various things with the light settings, to no avail. Then I had the bright idea of checking the standard shader, which worked fine, meaning my shader was the issue. If I had tried that sooner, I wouldn’t have wasted so much time fiddling with different lighting configurations.

After a bit of googling, I found out that shaders need to have certain code in place to make them work properly with lightmaps. I’ve decided to rewrite the entire shader, this time without skipping any parts of Catlike Coding’s twenty part rendering series. When I initially wrote the low poly shader, I kind of cherry picked the parts of that series that I thought I needed, but almost every graphics issue I’ve had has been due to something missing in the code.

Sunday

Today I wrote a post about my strategy for boosting productivity. Afterwards, I kept working through the shader tutorials.

Thursday

This evening I finished the last part of the rendering tutorial series. I excluded Monday to Wednesday’s progress updates since that’s pretty much all I was working on over the past few days.

The shader is still missing the low poly effect, but the lighting issues should be fixed now. I also want to comment it and take a stab at doing the lighting calculations per vertex (instead of per fragment). However, I’m not entirely sure this is even possible since the method I’m using to achieve the faceted look relies on the ddx and ddy functions, which may only be available in the fragment program.

Friday

This morning I made a backup of the new shader before stripping out everything I don’t need—which was essentially anything to do with textures. I then added the code that applies the low poly effect, which caused another lighting issue. Luckily, I managed to sort that one out relatively quickly.

Saturday

Today I cleaned up the new shader and then adapted it to be capable of wave simulation. Afterwards, I did some research about whether or not I can use the ddx and ddy functions in the vertex program of my shader. Unfortunately, my suspicions were correct—they’re only available in the fragment program. This means I can’t apply specular reflections on a per triangle basis, and I’m not aware of any ways of doing so at this point.

Sunday

This afternoon I modified the ship’s model to look nicer with the low poly shader. The overall shape hasn’t changed much, but it’s now predominantly made up of triangles instead of rectangles.

Remodeled ship with low poly water
The remodeled ship with the low poly shader. Lighting now works properly.

What’s next?

Due to the unexpected lighting issues that took quite a while to fix, I didn’t get around to adding cannons and ladders to the ship, so I’ll work on that next. I’d like to make them functional as well, but ladders might require me to write a custom character controller (I don’t think BEPUphysics’ default one has ladder climbing capabilities).

See other posts in this series.