aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/GlobalClass/ShaderManager.gd
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-01-19 14:02:05 +0100
committer hop311 <hop3114@gmail.com>2024-01-19 14:02:05 +0100
commit32dbfc1107b59085ba78929102f313b88c34a6a3 (patch)
tree68f95c20c21c67f46af9801bb07d57de7e0f9617 /game/src/Game/GlobalClass/ShaderManager.gd
parent7acaf673f0465dcfa35b86bfbaf5dc0f83f2fc00 (diff)
Added overlay parchment map and refactored map shader
Diffstat (limited to 'game/src/Game/GlobalClass/ShaderManager.gd')
-rw-r--r--game/src/Game/GlobalClass/ShaderManager.gd96
1 files changed, 68 insertions, 28 deletions
diff --git a/game/src/Game/GlobalClass/ShaderManager.gd b/game/src/Game/GlobalClass/ShaderManager.gd
index a6d555f..7e409d3 100644
--- a/game/src/Game/GlobalClass/ShaderManager.gd
+++ b/game/src/Game/GlobalClass/ShaderManager.gd
@@ -6,20 +6,41 @@ const param_province_shape_subdivisions : StringName = &"province_shape_subdivis
const param_province_colour_tex : StringName = &"province_colour_tex"
const param_hover_index : StringName = &"hover_index"
const param_selected_index : StringName = &"selected_index"
+const param_parchment_mix : StringName = &"parchment_mix"
const param_terrain_tex : StringName = &"terrain_tex"
const param_terrain_tile_factor : StringName = &"terrain_tile_factor"
const param_stripe_tex : StringName = &"stripe_tex"
const param_stripe_tile_factor : StringName = &"stripe_tile_factor"
+const param_overlay_tex : StringName = &"overlay_tex"
+const param_overlay_tile_factor : StringName = &"overlay_tile_factor"
const param_colormap_land_tex : StringName = &"colormap_land_tex"
const param_colormap_water_tex : StringName = &"colormap_water_tex"
+const param_colormap_overlay_tex : StringName = &"colormap_overlay_tex"
-func _set_shader_texture(shader_material : ShaderMaterial, texture_path : StringName, texture_param : StringName) -> Error:
- var texture := AssetManager.get_texture(texture_path)
- if texture == null:
- push_error("Failed to get texture: ", texture_path)
- return FAILED
- shader_material.set_shader_parameter(texture_param, texture)
- return OK
+func _set_shader_texture(
+ shader_material : ShaderMaterial, texture_param : StringName, texture : Texture,
+ tile_factor_param : StringName = &"", pixels_per_tile : float = 0.0
+) -> Error:
+ var err : Error = OK
+ if texture != null:
+ shader_material.set_shader_parameter(texture_param, texture)
+ else:
+ push_error("Invalid texture for shader parameter ", texture_param, " - null!")
+ err = FAILED
+ if tile_factor_param:
+ # Set to 1.0 / pixels_per_tile as the shader can multiply faster than it can divide, and it will not automatically
+ # optimise to multiplication by a reciprocal for fear of losing precision. As pixels_per_tile is often a power of two,
+ # this doesn't actually lose any precision, and even if it did it would be insignificant.
+ shader_material.set_shader_parameter(tile_factor_param, 1.0 / pixels_per_tile)
+ return err
+
+func _set_shader_asset_texture(
+ shader_material : ShaderMaterial, texture_param : StringName, texture_path : StringName,
+ tile_factor_param : StringName = &"", pixels_per_tile : float = 0.0
+) -> Error:
+ return _set_shader_texture(
+ shader_material, texture_param, AssetManager.get_texture(texture_path), tile_factor_param, pixels_per_tile
+ )
func set_up_shader(material : Material, add_cosmetic_textures : bool) -> Error:
# Shader Material
@@ -34,46 +55,65 @@ func set_up_shader(material : Material, add_cosmetic_textures : bool) -> Error:
var ret : Error = OK
# Province shape texture
- var province_shape_texture := GameSingleton.get_province_shape_texture()
- if province_shape_texture == null:
- push_error("Failed to get province shape texture!")
+ if _set_shader_texture(shader_material, param_province_shape_tex, GameSingleton.get_province_shape_texture()) != OK:
+ push_error("Failed to set province shape shader texture array!")
ret = FAILED
+
+ var subdivisions : Vector2i = GameSingleton.get_province_shape_image_subdivisions()
+ if subdivisions.x >= 1 and subdivisions.y >= 1:
+ shader_material.set_shader_parameter(param_province_shape_subdivisions, Vector2(subdivisions))
else:
- shader_material.set_shader_parameter(param_province_shape_tex, province_shape_texture)
- var subdivisions := GameSingleton.get_province_shape_image_subdivisions()
- if subdivisions.x < 1 or subdivisions.y < 1:
push_error("Invalid province shape image subdivision: ", subdivisions.x, "x", subdivisions.y)
ret = FAILED
- else:
- shader_material.set_shader_parameter(param_province_shape_subdivisions, Vector2(subdivisions))
if add_cosmetic_textures:
# Province colour texture
- var map_province_colour_texture := GameSingleton.get_province_colour_texture()
- if map_province_colour_texture == null:
- push_error("Failed to get province colour texture!")
+ if _set_shader_texture(shader_material, param_province_colour_tex, GameSingleton.get_province_colour_texture()) != OK:
+ push_error("Failed to set province colour shader texture!")
ret = FAILED
- else:
- shader_material.set_shader_parameter(param_province_colour_tex, map_province_colour_texture)
# Terrain texture
- var terrain_texture := GameSingleton.get_terrain_texture()
- if terrain_texture == null:
- push_error("Failed to get terrain texture!")
+ const pixels_per_terrain_tile : float = 16.0
+ if _set_shader_texture(
+ shader_material,
+ param_terrain_tex, GameSingleton.get_terrain_texture(),
+ param_terrain_tile_factor, pixels_per_terrain_tile
+ ) != OK:
+ push_error("Failed to set terrain shader texture array!")
ret = FAILED
- else:
- shader_material.set_shader_parameter(param_terrain_tex, terrain_texture)
# Stripe texture
- if _set_shader_texture(shader_material, &"map/terrain/stripes.dds", param_stripe_tex) != OK:
+ const pixels_per_stripe_tile : float = 8.0
+ if _set_shader_asset_texture(
+ shader_material,
+ param_stripe_tex, &"map/terrain/stripes.dds",
+ param_stripe_tile_factor, pixels_per_stripe_tile
+ ) != OK:
+ push_error("Failed to set stripe shader texture!")
+ ret = FAILED
+
+ # Overlay texture
+ const pixels_per_overlay_tile : float = 512.0
+ if _set_shader_asset_texture(
+ shader_material,
+ param_overlay_tex, &"map/terrain/map_overlay_tile.dds",
+ param_overlay_tile_factor, pixels_per_overlay_tile
+ ) != OK:
+ push_error("Failed to set overlay shader texture!")
ret = FAILED
# Land colormap
- if _set_shader_texture(shader_material, &"map/terrain/colormap.dds", param_colormap_land_tex) != OK:
+ if _set_shader_asset_texture(shader_material, param_colormap_land_tex, &"map/terrain/colormap.dds") != OK:
+ push_error("Failed to set land colormap shader texture!")
ret = FAILED
# Water colormap
- if _set_shader_texture(shader_material, &"map/terrain/colormap_water.dds", param_colormap_water_tex) != OK:
+ if _set_shader_asset_texture(shader_material, param_colormap_water_tex, &"map/terrain/colormap_water.dds") != OK:
+ push_error("Failed to set water colormap shader texture!")
+ ret = FAILED
+ # Overlay colormap
+ if _set_shader_asset_texture(shader_material, param_colormap_overlay_tex, &"map/terrain/colormap_political.dds") != OK:
+ push_error("Failed to set overlay colormap shader texture!")
ret = FAILED
return ret