diff options
Diffstat (limited to 'game')
-rw-r--r-- | game/src/GameSession/MapView.gd | 12 | ||||
-rw-r--r-- | game/src/GameSession/TerrainMap.gdshader | 23 |
2 files changed, 17 insertions, 18 deletions
diff --git a/game/src/GameSession/MapView.gd b/game/src/GameSession/MapView.gd index 510d70a..e74ea59 100644 --- a/game/src/GameSession/MapView.gd +++ b/game/src/GameSession/MapView.gd @@ -41,7 +41,6 @@ var _mouse_over_viewport : bool = true var _map_mesh : MapMesh var _map_shader_material : ShaderMaterial var _map_image_size : Vector2 -var _map_province_index_image : Image var _map_province_colour_image : Image var _map_province_colour_texture : ImageTexture var _map_mesh_corner : Vector2 @@ -77,12 +76,15 @@ func _ready(): return _map_shader_material = map_material - # Province index texture - _map_province_index_image = GameSingleton.get_province_index_image() - if _map_province_index_image == null: + # Province index textures + var map_province_index_images := GameSingleton.get_province_index_images() + if map_province_index_images == null or map_province_index_images.is_empty(): push_error("Failed to get province index image!") return - var province_index_texture := ImageTexture.create_from_image(_map_province_index_image) + var province_index_texture := Texture2DArray.new() + if province_index_texture.create_from_images(map_province_index_images) != OK: + push_error("Failed to generate province index texture array!") + return _map_shader_material.set_shader_parameter(_shader_param_province_index, province_index_texture) # Province colour texture diff --git a/game/src/GameSession/TerrainMap.gdshader b/game/src/GameSession/TerrainMap.gdshader index 9ce1a24..305a34b 100644 --- a/game/src/GameSession/TerrainMap.gdshader +++ b/game/src/GameSession/TerrainMap.gdshader @@ -5,7 +5,7 @@ render_mode unshaded; // Cosmetic farmlands terrain texture uniform sampler2D farmlands_tex: source_color, repeat_enable, filter_linear; // Province index texture -uniform sampler2D province_index_tex : source_color, repeat_enable, filter_nearest; +uniform sampler2DArray province_index_tex : source_color, 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 @@ -18,23 +18,20 @@ uniform float terrain_tile_factor; 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); + return vec2_to_uvec2(texture(province_index_tex, vec3(uv, idx)).rg); +} 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)); -} - const vec3 water_colour = vec3(0, 0, 1); vec3 get_terrain_colour(vec2 uv, vec2 corner, vec2 half_pixel_size, vec2 terrain_uv) { - uvec2 index_split = read_uvec2(province_index_tex, fma(corner, half_pixel_size, uv)); + uvec2 index_split = read_uvec2(fma(corner, half_pixel_size, uv)); uint index = uvec2_to_uint(index_split); vec4 province_data = texelFetch(province_colour_tex, ivec2(index_split), 0); vec3 province_colour = province_data.rgb; @@ -47,8 +44,8 @@ vec3 get_terrain_colour(vec2 uv, vec2 corner, vec2 half_pixel_size, vec2 terrain } vec3 mix_terrain_colour(vec2 uv) { - vec2 map_size = vec2(textureSize(province_index_tex, 0)); - vec2 pixel_offset = mod(fma(uv, map_size, vec2(0.5)), 1.0); + vec2 map_size = vec2(textureSize(province_index_tex, 0).xy); + vec2 pixel_offset = fract(fma(uv, map_size, vec2(0.5))); vec2 half_pixel_size = 0.49 / map_size; vec2 terrain_uv = uv; |