Unity to Godot part 13: Loading a level
More porting work this week, this time aiming to get into a level from the overworld. Spoiler alert: level is loaded, and some of the graphics are ported too. Video above. Some of the things that got done, relevant or not:
- Refactor C++ bindings generator. I have a C++ plugin bindings generator written in python, that generates a C# file with all function signatures. It's a code generator rather than a simple file because with Unity there were some tedious #ifdefs and different ways of handling things. Now, even though the bindings specification is simpler, the script still makes things easier, so I made sure it works identically to how it did, fixing a few bugs on the way
- Allow disabling AI globally with a checkbox. This was one of the "Why did I not have this earlier?" moments, and the need came because the game now crashes when some entities attack each other, but I wanted to focus on graphics, so I needed a way to shut everyone up without killing them, so with the addition of this button the AI now can always just skip turn. Super useful.
- Allow granular render pass control. It's super useful to only render a subset of passes, especially when debugging graphics and trying to figure out the source of some artifacts. So, thanks to ImGUI and Godot's open architecture, I can list all my renderpasses and allow enabling/disabling each one. As a reminder, I've got a custom rendering pipeline so I have full control (and responsibility) of what's rendered when.
- GPU buffer refactor. I had made some design fart where resources that needed serialization contained actual GPU resources such as GPU buffers, so I did another pass and now buffers are "rented" from a central graphics resources object. Bonus: I know what resources are allocated at any given time.
- Graphics resources inspector. I have a "graphics resource database" where I put loaded textures, buffers etc. I've implemented some ImGUI display for the database too so I can check what's loaded
- Humble audio and Sound Explorer. I got tempted by some humble bundle for audio music and sfx, so I bought that. One of my PhD students suggested to me an application called Sound Explorer, for managing audio files. Due to other more pressing work, this is all waiting in the background, but I do want to have a go at adding more audio soon.
- Fixed a mean graphics glitch. In the past, and also at some point this week, I got a mean graphics glitch that manifested as horizontal or vertical thin lines in the game area at tile borders. This was because of some custom hacky code to handle Unity's stupid sampler limitation, where you can't have separate minification and magnification filters. But now in Godot, because it exposes the low-level stuff, I can finally select trilinear filter for minification and point filter for magnification. I think that's great for pixel art as the minification is not noisy (but gets blurrier; such is life) and magnification is nice and crispy.
- Fixed liquids in levels. Liquids in levels are a bit different to the overworld and also a bit special, so some work was put to port that shader. Still some related work to be done.
- Hover-over info tooltips. Thanks to ImGUI again, I've added a tooltip with tile information when hovering over a tile and holding F1. Currently it's the info generated by the dungeon generator, but needs to be replaced with more rich information
- Layout buffer equality source generation. I'm using layout buffers for vulkan shaders, and they have C# equivalent structs that I can use to convert to bytes and upload to GPU. For a few reasons, it's useful to be able to quickly compare buffer contents, so I wrote some code to generate equality testing code. It's a bit tedious in C#, having to implement 3 functions, but it's easily automated at least.
- Fog of war port. This was the heavy hitter of the week, since it's a complex shader that adds funky fog of war, time-of-day color gradients and explored/currently-seen visualisation, in addition to support for heat haze, actual fog, darkvision and lightning effects. After a bit of sweat, it's done, and you can see the results at the video above. The colours I think are different to what they used to be, and I'm not sure if it's related to sRGB vs linear texture, although I can't see such option in Godot.
- Border rendering order. I used to draw the border before sprites such as trees and mountains, but after adding fog of war, this ended up occasionally revealing trees/mountains near borders (overlapping borders). So I moved borders after such sprites and before fog of war.
That's it for now, phew! It's SO much work, but the port is moving ahead, always.