aboutsummaryrefslogtreecommitdiff
path: root/game/src/GameSession/TerrainMap.gdshader
diff options
context:
space:
mode:
author George L. Albany <Megacake1234@gmail.com>2023-04-14 18:31:58 +0200
committer GitHub <noreply@github.com>2023-04-14 18:31:58 +0200
commit436b038c1806e326ff6458f1692e9009d3a54346 (patch)
treeb5a33a733398b511eb0aa7781860c8accbadd2a0 /game/src/GameSession/TerrainMap.gdshader
parent1f04a7827ae377372cb491ff0257a47d0d4c2967 (diff)
parent7241811bd8c9493b7b6c6480e8d63a5fb7f38e4e (diff)
Merge pull request #84 from OpenVic2Project/terrain-map
Diffstat (limited to 'game/src/GameSession/TerrainMap.gdshader')
-rw-r--r--game/src/GameSession/TerrainMap.gdshader45
1 files changed, 45 insertions, 0 deletions
diff --git a/game/src/GameSession/TerrainMap.gdshader b/game/src/GameSession/TerrainMap.gdshader
new file mode 100644
index 0000000..7aca0f9
--- /dev/null
+++ b/game/src/GameSession/TerrainMap.gdshader
@@ -0,0 +1,45 @@
+shader_type spatial;
+
+render_mode unshaded;
+
+// Cosmetic terrain texture
+uniform sampler2D terrain_tex: source_color, repeat_enable, filter_linear;
+// Province index texture
+uniform sampler2D province_index_tex : repeat_enable, filter_nearest;
+// Province colour texture
+uniform sampler2D province_colour_tex: source_color, repeat_enable, filter_nearest;
+// Index of the mouse over the map mesh
+uniform uint hover_index;
+// Index of the currently selected province
+uniform uint selected_index;
+
+uvec2 vec2_to_uvec2(vec2 v) {
+ return uvec2(v * 255.0);
+}
+
+uint uvec2_to_uint(uvec2 v) {
+ return (v.y << 8u) | v.x;
+}
+
+uvec2 read_uvec2(sampler2D tex, vec2 uv) {
+ return vec2_to_uvec2(texture(tex, uv).rg);
+}
+
+uint read_uint16(sampler2D tex, vec2 uv) {
+ return uvec2_to_uint(read_uvec2(tex, uv));
+}
+
+void fragment() {
+ uvec2 prov_idx_split = read_uvec2(province_index_tex, UV);
+ uint prov_index = uvec2_to_uint(prov_idx_split);
+
+ // Boost prov_colour's contribution if it matches hover_colour or selected_colour
+ float mix_val = 0.3 + float(prov_index == hover_index) * 0.3 + float(prov_index == selected_index) * 0.3;
+ // Don't mix if the province index is 0
+ mix_val *= float(prov_index != 0u);
+
+ vec3 terrain_colour = texture(terrain_tex, UV).rgb;
+ vec3 province_colour = texelFetch(province_colour_tex, ivec2(prov_idx_split), 0).rgb;
+
+ ALBEDO = mix(terrain_colour, province_colour, mix_val);
+}