diff options
author | Hop311 <hop3114@gmail.com> | 2023-04-26 13:06:19 +0200 |
---|---|---|
committer | Hop311 <hop3114@gmail.com> | 2023-04-26 13:06:19 +0200 |
commit | 2455806f52f0133e5bd5e4997589c5ce4fe99b2c (patch) | |
tree | a1882d8d3a4e836ec305dd0893b6eda5ec3dd230 /game | |
parent | 10053cf259c55ee45803268a844edf1011d8a16b (diff) |
Vertical subdivision + calculation for both dims
Diffstat (limited to 'game')
-rw-r--r-- | game/src/GameSession/MapView.gd | 5 | ||||
-rw-r--r-- | game/src/GameSession/TerrainMap.gdshader | 8 |
2 files changed, 10 insertions, 3 deletions
diff --git a/game/src/GameSession/MapView.gd b/game/src/GameSession/MapView.gd index e74ea59..1b04097 100644 --- a/game/src/GameSession/MapView.gd +++ b/game/src/GameSession/MapView.gd @@ -13,6 +13,7 @@ const _action_drag : StringName = &"map_drag" const _action_click : StringName = &"map_click" const _shader_param_province_index : StringName = &"province_index_tex" +const _shader_param_province_index_subdivisions : StringName = &"province_index_subdivisions" const _shader_param_province_colour : StringName = &"province_colour_tex" const _shader_param_hover_index : StringName = &"hover_index" const _shader_param_selected_index : StringName = &"selected_index" @@ -86,6 +87,10 @@ func _ready(): push_error("Failed to generate province index texture array!") return _map_shader_material.set_shader_parameter(_shader_param_province_index, province_index_texture) + var subdivisions := GameSingleton.get_province_index_image_subdivisions() + if subdivisions.x < 1 or subdivisions.y < 1: + push_error("Invalid province index image subdivision: ", subdivisions.x, "x", subdivisions.y) + _map_shader_material.set_shader_parameter(_shader_param_province_index_subdivisions, Vector2(subdivisions)) # Province colour texture _map_province_colour_image = GameSingleton.get_province_colour_image() diff --git a/game/src/GameSession/TerrainMap.gdshader b/game/src/GameSession/TerrainMap.gdshader index 305a34b..f80d6bd 100644 --- a/game/src/GameSession/TerrainMap.gdshader +++ b/game/src/GameSession/TerrainMap.gdshader @@ -6,6 +6,8 @@ render_mode unshaded; uniform sampler2D farmlands_tex: source_color, repeat_enable, filter_linear; // Province index texture uniform sampler2DArray province_index_tex : source_color, repeat_enable, filter_nearest; +// Province index subdivisions +uniform vec2 province_index_subdivisions; // Province colour texture uniform sampler2D province_colour_tex: source_color, repeat_enable, filter_nearest; // Index of the mouse over the map mesh @@ -19,9 +21,9 @@ uvec2 vec2_to_uvec2(vec2 v) { return uvec2(v * 255.0); } uvec2 read_uvec2(vec2 uv) { - float width_divisions = float(textureSize(province_index_tex, 0).z); - uv.x *= width_divisions; - float idx = mod(floor(uv.x), width_divisions); + uv *= province_index_subdivisions; + vec2 subdivision_coords = mod(floor(uv), province_index_subdivisions); + float idx = subdivision_coords.x + subdivision_coords.y * province_index_subdivisions.x; return vec2_to_uvec2(texture(province_index_tex, vec3(uv, idx)).rg); } uint uvec2_to_uint(uvec2 v) { |