aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/GameSession
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-11-16 00:54:57 +0100
committer hop311 <hop3114@gmail.com>2023-11-16 00:54:57 +0100
commit3490e740a7235dce236fc2ce973e5cbf64d6e727 (patch)
tree283c52e391c09ca8c4fb7ab6d81f4351c0fa7025 /game/src/Game/GameSession
parentbc0b3c61ae0b742da304cada451fba1df72bb0ad (diff)
Striped mapmodes
Diffstat (limited to 'game/src/Game/GameSession')
-rw-r--r--game/src/Game/GameSession/MapControlPanel/Minimap.gd2
-rw-r--r--game/src/Game/GameSession/MapView.gd5
-rw-r--r--game/src/Game/GameSession/ProvinceIndexSampler.gdshaderinc6
-rw-r--r--game/src/Game/GameSession/TerrainMap.gdshader39
4 files changed, 38 insertions, 14 deletions
diff --git a/game/src/Game/GameSession/MapControlPanel/Minimap.gd b/game/src/Game/GameSession/MapControlPanel/Minimap.gd
index be65db5..5564821 100644
--- a/game/src/Game/GameSession/MapControlPanel/Minimap.gd
+++ b/game/src/Game/GameSession/MapControlPanel/Minimap.gd
@@ -10,7 +10,7 @@ var _minimap_shader : ShaderMaterial
var _viewport_points : PackedVector2Array
func _ready():
- _minimap_texture.custom_minimum_size = Vector2(GameSingleton.get_aspect_ratio(), 1.0) * 150
+ _minimap_texture.custom_minimum_size = Vector2(GameSingleton.get_map_aspect_ratio(), 1.0) * 150
var minimap_material := _minimap_texture.get_material()
if GameLoader.ShaderManager.set_up_shader(minimap_material, false) != OK:
push_error("Failed to set up minimap shader")
diff --git a/game/src/Game/GameSession/MapView.gd b/game/src/Game/GameSession/MapView.gd
index 345ab9e..7093c69 100644
--- a/game/src/Game/GameSession/MapView.gd
+++ b/game/src/Game/GameSession/MapView.gd
@@ -74,7 +74,10 @@ func _ready():
# Set map mesh size and get bounds
const pixels_per_terrain_tile : float = 32.0
_map_shader_material.set_shader_parameter(GameLoader.ShaderManager.param_terrain_tile_factor,
- float(GameSingleton.get_height()) / pixels_per_terrain_tile)
+ float(GameSingleton.get_map_height()) / pixels_per_terrain_tile)
+ const pixels_per_stripe_tile : float = 16.0
+ _map_shader_material.set_shader_parameter(GameLoader.ShaderManager.param_stripe_tile_factor,
+ float(GameSingleton.get_map_height()) / pixels_per_stripe_tile)
var map_mesh_aabb := _map_mesh.get_core_aabb() * _map_mesh_instance.transform
_map_mesh_corner = Vector2(
min(map_mesh_aabb.position.x, map_mesh_aabb.end.x),
diff --git a/game/src/Game/GameSession/ProvinceIndexSampler.gdshaderinc b/game/src/Game/GameSession/ProvinceIndexSampler.gdshaderinc
index 65f73d8..1adcd95 100644
--- a/game/src/Game/GameSession/ProvinceIndexSampler.gdshaderinc
+++ b/game/src/Game/GameSession/ProvinceIndexSampler.gdshaderinc
@@ -4,15 +4,21 @@ uniform sampler2DArray province_shape_tex : repeat_enable, filter_nearest;
// Province shape subdivisions
uniform vec2 province_shape_subdivisions;
+// Convert a vector of 3 normalised floats to a vector of 3 unsigned bytes
uvec3 vec3_to_uvec3(vec3 v) {
return uvec3(v * 255.0);
}
+
+// Create a uint triplet describing the province and terrain data at a map-space UV coordinate:
+// (u, v) -> (province index bottom byte, province index top byte, terrain index byte)
uvec3 read_uvec3(vec2 uv) {
uv *= province_shape_subdivisions;
vec2 subdivision_coords = mod(floor(uv), province_shape_subdivisions);
float idx = subdivision_coords.x + subdivision_coords.y * province_shape_subdivisions.x;
return vec3_to_uvec3(texture(province_shape_tex, vec3(uv, idx)).rgb);
}
+
+// Combine a (lower byte, upper byte) uint pair into a single 2-byte uint
uint uvec2_to_uint(uvec2 v) {
return (v.y << 8u) | v.x;
}
diff --git a/game/src/Game/GameSession/TerrainMap.gdshader b/game/src/Game/GameSession/TerrainMap.gdshader
index 852ccc3..ff8708a 100644
--- a/game/src/Game/GameSession/TerrainMap.gdshader
+++ b/game/src/Game/GameSession/TerrainMap.gdshader
@@ -14,16 +14,29 @@ uniform uint selected_index;
uniform sampler2DArray terrain_tex: source_color, repeat_enable, filter_linear;
// The number of times the terrain textures should tile vertically
uniform float terrain_tile_factor;
+// Map stripe mask texture
+uniform sampler2D stripe_tex: source_color, repeat_enable, filter_nearest;
+// The number of times the stripe texture should tile vertically
+uniform float stripe_tile_factor;
const vec3 highlight_colour = vec3(1.0);
-vec3 get_terrain_colour(vec2 uv, vec2 corner, vec2 half_pixel_size, vec2 terrain_uv) {
+vec3 get_terrain_colour(vec2 uv, vec2 corner, vec2 half_pixel_size, vec2 terrain_uv, vec2 stripe_uv) {
uvec3 province_data = read_uvec3(fma(corner, half_pixel_size, uv));
- vec4 province_colour = texelFetch(province_colour_tex, ivec2(province_data.rg), 0);
- vec3 terrain_colour = texture(terrain_tex, vec3(terrain_uv, float(province_data.b))).rgb;
+ uint province_index = uvec2_to_uint(province_data.rg);
+ uint terrain_index = province_data.b;
+
+ province_data.r *= 2u; // Double "x coordinate" as colours come in (base, stripe) pairs
+ vec4 province_base_colour = texelFetch(province_colour_tex, ivec2(province_data.rg), 0);
+ province_data.r += 1u; // Add 1 to "x coordinate" to move from base to strip colour
+ vec4 province_stripe_colour = texelFetch(province_colour_tex, ivec2(province_data.rg), 0);
+ float stripe = texture(stripe_tex, stripe_uv).b; // Stripe mask value - 0 for base, 1 for stripe
+ vec4 province_colour = mix(province_base_colour, province_stripe_colour, stripe);
+
+ vec3 terrain_colour = texture(terrain_tex, vec3(terrain_uv, float(terrain_index))).rgb;
vec3 mixed_colour = mix(terrain_colour, province_colour.rgb, province_colour.a);
- uint index = uvec2_to_uint(province_data.rg);
- float mix_val = 0.1 * (float(index == hover_index) + float(index == selected_index));
+
+ float mix_val = 0.1 * (float(province_index == hover_index) + float(province_index == selected_index));
return mix(mixed_colour, highlight_colour, mix_val);
}
@@ -32,15 +45,17 @@ vec3 mix_terrain_colour(vec2 uv) {
vec2 pixel_offset = fract(fma(uv, map_size, vec2(0.5)));
vec2 half_pixel_size = 0.49 / map_size;
- vec2 terrain_uv = uv;
- terrain_uv.x *= map_size.x / map_size.y;
- terrain_uv *= terrain_tile_factor;
+ // UV coords adjusted to remove squashing caused by normalisation relative to map dimensions.
+ vec2 unscaled_uv = vec2(uv.x * map_size.x / map_size.y, uv.y);
+
+ vec2 terrain_uv = unscaled_uv * terrain_tile_factor;
+ vec2 stripe_uv = unscaled_uv * stripe_tile_factor;
return mix(
- mix(get_terrain_colour(uv, vec2(-1, -1), half_pixel_size, terrain_uv),
- get_terrain_colour(uv, vec2(+1, -1), half_pixel_size, terrain_uv), pixel_offset.x),
- mix(get_terrain_colour(uv, vec2(-1, +1), half_pixel_size, terrain_uv),
- get_terrain_colour(uv, vec2(+1, +1), half_pixel_size, terrain_uv), pixel_offset.x),
+ mix(get_terrain_colour(uv, vec2(-1, -1), half_pixel_size, terrain_uv, stripe_uv),
+ get_terrain_colour(uv, vec2(+1, -1), half_pixel_size, terrain_uv, stripe_uv), pixel_offset.x),
+ mix(get_terrain_colour(uv, vec2(-1, +1), half_pixel_size, terrain_uv, stripe_uv),
+ get_terrain_colour(uv, vec2(+1, +1), half_pixel_size, terrain_uv, stripe_uv), pixel_offset.x),
pixel_offset.y);
}