#Shading Grand Strategy Borders

1 messages · Page 1 of 1 (latest)

quartz vigil
#

Hello everyone! I have a map of region provinces which are each a different, unique pixel color. This is shown in the first image. I want to find a way to draw borders between them on the game map which are colored by their province owner.

You can see in the second picture that on the game map I have, I already found a shader which draws borders in between them, but I can't find a way to differentiate by color. Does anyone know how this might be done? For example, all regions owned by the English would have a red border, the French provinces would have a border in blue, etc.

I would also like to have a shader which would overlay on top of the map. This would shade the entire province one color. In the third picture, you can see a highlighted province which is colored white. I would like to find a way where a shader can highlight all provinces in the faction color.

Basically, since my province map each has a unique color per province, I want to be able to draw colored borders in between them, and also to highlight each unique province in a color of my choosing. Apologies if this is complicated, I'm really looking for any help I can get because it's a fairly niche issue.

lean pine
#

I guess you're drawing the province borders by sampling the pixels around the current one and check for difference ?
You could just tint the border based on the reference pixel color to have it the same color as the current province.

quartz vigil
#

What would that look like in the shader script? Like what do I type in for the color

lean pine
#

If you could share a bit of the actual shader it would help.
But if you're doing like I've guessed, you should already have the current color of the province in some variable, and just have to output that instead of the white border color.

quartz vigil
#

I was thinking more that I want the borders to be the same color as the owner of the province, not the province itself though, is this still possible with the shader?

#

I don’t know if you can pass in variables for the color or not

lean pine
#

You can definitively pass variables for the colors.

Here's my suggestion :
Change the way you work with the "province map" to make it more flexible and optimized :
The texture is in RGB(A ?) format. Instead of wasting channels data to store the color do this :

  • In channel R, store an index for the province. With regular RGB8 texture format, you can have 256 provinces, that should be plenty enough ?
  • In channel G, store the provinces border lines. If you use a distance field method (basically, a gradient of the distance to the border), you can even easily tweak the border lines thickness or add some fancy rendering effects.
  • In channel B, you can store the countries index. But maybe in you gameplay the provinces can change countries, so this might not be relevant.
  • If needed you can store something else in the alpha channel 🤷

Then you can expose the provinces colors on the material as color properties and set them from script.
If you think it's to much properties, you can also use a ColorArray, that can be easilly accessed from the shader by the index stored in the red channel.

Coloring a single country is done either by checking the blue channel index, or having a list of provinces index.

clear palm
#

this immediately makes me think of jump flooding -- the article mentions that Paradox games use it to draw borders, in fact

#

that'll let you efficiently compute the distance field

lean pine
#

Yes, that's a way to compute the distance fields for the borders.
Other ways are possible, and if you pre-bake them in a color channel like suggested, you could simply use a layer style in photoshop

quartz vigil
#

@lean pine @clear palm Thank you for your advice

#

In my current shader script I'm drawing borders by basically making four offsets of the region map, one slightly higher, slightly lower, to the right and to the left, and shading them where the colors don't match up

#

So it makes a black border where the offset pixels are not the same color as the actual map

#

since they've been shifted

#

Every province has a unique color, and I already have a way to access the owner's faction color just by getting the color of the province

#

I kinda wanted to know if I could just return that color instead of black somehow, but I don't know how to check for it in the script

#

Right now im checking for any pixel in color (my region map) which doesnt equal a pixel in my offset maps, but if I had a way to determine what color that overlapped pixel was, I would know which region the border is drawn on and might be able to color the border to the corresponding faction color

quartz vigil
#

Actually, just returning the color instead of black does this:

#

As you can see, the border colors are now the same as the colors on the region map

#

However, I want the colors to be the same as the faction which owns the province itself

lean pine
#

That's why I suggested to change the logic to have and province and faction index.
If you want to keep your existing map, for color by faction you'd need some province -> faction table

raw patrol
#

Hmm let me think so we have the province id via color, that can index into a province owner array passed to the shader that holds a faction id and that can index into an array of faction colors

#

Two levels if indirection… not ideal

lean pine
#

Just one for province -> faction color is enough though.

quartz vigil
#

I'm thinking I might have a separate image file which has the regions colored according to the corresponding faction, and I would just change the pixels in this map as needed to update the colors

#

And this would be what I return instead of the region file itself, because I need that file to keep its colors for the sake of being unique

#

Thank you all so much, I did more research on shaders according to your advice and now I know what they can and cannot do

raw patrol
raw patrol
#

There is no need to iterate all pixels

#

Odly enough I am also working on a gsg prototype. Mind if I ask how you generate your province map in the first place. Right now I’m stuck on parsing real world gis data to populate the initial seeds for the voronoi step but I can’t find good data in order to get the province count like in EU5

quartz vigil
#

Then I added a layer and traced my regions on top, saving as a separate file

raw patrol
#

By hand?

quartz vigil
raw patrol
#

Only he says 😁

quartz vigil
#

I did it all in GIMP

#

This was my first version, I filled in the land with a parchment texture and erased out rivers and stuff, placed mountains with some free brushes

#

Then I colorized it

#

Then I just traced over the top where I wanted my regions to go

#

So yeah I guess it took a little bit, but only like a couple days since I had the time

quartz vigil
# raw patrol That sounds like too much cpu work all you have to update is a. ProvinceColors[p...

You're correct, I already have all provinces mapped to their color, and each one has an owner with their own faction color. Problem is when I access the province color in the shader script, I don't know if there's a way to get the actual province object from that so I can return the faction color. It seems like C# script functionality that idk how to implement in the shader, so that's why I'm thinking that I will use C# scripts to construct an image that my shader script can then return

raw patrol
#

The province color is just an id

#

It’s a number

#

You can use than number to index an array where you have stored the faction color of a province by it’s id

#

You can pass a array of arbitrary data to the shader

quartz vigil
#

Oh, so is it kind of like a dictionary then? The key being the province color and the value being the corresponding faction color?

raw patrol
#

Yep you can think of it that way

quartz vigil
#

Gotcha

#

How do I pass it to the shader?

raw patrol
#

I really want to know what data and method paradox used to create the eu5 map

quartz vigil
#

Im a huge Total War fan mostly

#

But they've been disappointing me so I have to make my own games now

quartz vigil
raw patrol
#

that's another thing yeah, I'm trying to understand how they generated 20k locations for eu5, cause no way people painted them by hand

quartz vigil
quartz vigil
quartz vigil
raw patrol
#

nice

lean pine
#

If you try the approach that I've initially proposed, you don't have to update the texture from script, only the material values.

quartz vigil
#

Idk what the actual code is for sending the variables there, which I will need to do when the ownership changes.

#

I'm sorry for so many questions, I really am a noob at this 😂

lean pine
# quartz vigil Im just confused about this: I make this dictionary in the C# script, which is v...

Dictionaries don't really exist in shader :/
If you want to map a color (the province color) to an other (the owner color), you'd indeed need some indirection to do color -> id -> color.
Since the provinces color seems stable, you could hard code the first part in the shader code itself. And use a color array for the second.

I can't refrain to suggest to try what I did, by storing the provinces ID in a single channel instead of the color. That would get rid of the first lookup.

#

There is a way though to map a color to an other one : a 3D lookup table , in the form of a 3D texture.
The province color value is interpreted as 3D texture coordinates, that samples the 3D texture and outputs the owner color.

quartz vigil
#

And I would update the faction color array through script and send it to the shader script