I have been working on a grand strategy game prototype for awhile now and just got my map editor working in the Godot editor! I needed to be able to place map objects and locators for those map objects (position, scale, and rotation) on a whole bunch of positions all over the map in a way that I could do a lot of them without being a massive pain or insanely time consuming.
Thankfully Godot exposes a lot of really great ways to do all of this directly in the editor. A lot of the functionality I needed was basically already done and is the exact same as how the 3D viewport in the editor works which saved me a ton of time, this only took a few days to put together but if I had to write all the 3D editor functionality myself it easily could have taken several months to get to where it is now. The Node3DEditor is actually not exposed to the godot API at all (except in some very limited ways) but lucky for me I was already developing as a C++ engine module so was able to add some functionality that makes it integrate in seamlessly with the Godot editor that would not have been possible outside of module development. Some of it is definitely kind of hacky and there is still a little bit of jank I can’t seem to get around because of how EditorPlugins work but overall I’m very happy with how it came out.
I plan on adding a lot more functionality to the map editor, it’s kind of barebones right now. In particular the inspector UI I made is pretty lame right now, it’s just an ItemList that let’s you select each province. Later on I want to have buttons for every locator node and some ways to automatically adjust locator positions without having to actually move them.
Here is the project if anyone want to check it out, or even help out adding new features. It’s just a protoype at this stage but I’ve made some pretty solid progress so far and this map editor should help with getting in more features even faster.
Hello, I am more or less trying to do thid kind of tool for a university project but scaled down. How did you implement country borders? I am struggling to think of a way to have good performance while changing country borders at runtime in godot. I am using compute shaders for most of the calculations
Borders are tough and I’m not totally satisfied with the algorithm I have now but it’s good enough. You can read through src/cg/Map.cpp for all the code related to borders.
Basically what is does is:
Iterates over every pixel in the province map and for every province it creates a dictionary of Vector4 line segments that are used to connect borders.
All the line segments then get cached. This part of the code is super slow so I avoid doing it at runtime at all and instead generate all the data I need in the map editor so I don’t have to wait 10 seconds iterating over 40 million pixels every time the game starts.
Then at runtime I load all those border line segments and create the border meshes based on them. I then do some calculations based on the borders to figure out province adjacencies, which are important for navigation.
Like I said though I don’t think this is optimal it was just the way I got it done in an acceptable enough way to move on to something else. I’d like to improve the mesh generation at some point to make the borders nice and rounded so there aren’t sharp corners anywhere but I haven’t figured that out yet.
Your compute shader method sounds pretty interesting would you mind sharing it so I can poke around and see how you did things? It was difficult finding any info at all online on how to go about this.
Hi, I read about the approach you describe using meshes for borders, in my case it does not really work since I want to change borders of countries at runtime. Now I can share my repo with you, but it is super messy at the moment and most importantly, the shader I use is not implemented correctly. It is based on this paper:
And I agree, there is not enough info on the internet about making nice looking borders.
Here is my repo, the work in progress shader is on another branch. I would wait a week though. I am going to implement it correctly eventually and have readable code.
Hey, my method is definately wrong. I do not think anything other than a vector based approach would be feasible to have smooth borders. My approach would only add gradients to the countries. It might be worth looking for a HQX shader to upscale the result a bit, which might get rid of any jaggedness.
This was the very best I could do, with SDF of the map, apply black border right on the edge, gradient of with country color then plug it in with HQX upscale:
Yeah I think I remember reading online that paradox games draw them using vector math for the actual borders, the sdf part is all done in a shader more or less the same way you did it here.
Your implementation looks great now though! I wish my borders looked that good haha.
Idk if I’m going to do the sdf gradient borders on my map because imo they sometimes look kinda weird with really small areas. It’s not as noticeable on paradox maps because they are fully in 3D but I think it’ll be tough to make it always look good on my map since it’s 2D where having a couple weird pixels is a lot easier to see. I definitely plan to add hqx to mine at some point though, I think that’ll probably be the easiest way to make it look good enough.
Do you plan on customizing the border graphics based on gameplay?
For mine I kinda had to make each border a separate mesh because I need to apply different shader parameters to them at runtime. Like for example borders with uninhabitable provinces get colored red and region borders are a dashed line instead of solid.
Thanks a lot! I am still disappointed I could not implement SDF generation with JFA in Godot and only using the brute force SDF creation, but I am content with the visuals for now.
On the gameplay aspect, this project I planned to do in 8 weeks (I got 4 more to go) for university as a portfolio project. I want to work in engine/graphics programming. I want to create a pipeline that allows the user to make maps used for modding, or offer a starting point for grand strategy development in Godot. So my main focus is graphics and making a system for parsing province/country data, editing that data and so on.
On the other hand, I would like to make a grand strategy game sometime, but with my own engine and probably a dedicated designer. I would definitely need to customize the borders, I think, but that is far in the future. I hope we’ll chat again then to share tips on our grand strategy endeavors :). By the way, your project is super cool!
PS: If somebody manages to implement the Distance Field Texture generation with JFA as is shown in that Intel paper, please DM me! I have to see the code!