aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/GameSession/ProvinceIndexSampler.gdshaderinc
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-11-17 21:17:55 +0100
committer GitHub <noreply@github.com>2023-11-17 21:17:55 +0100
commit9165f5980c5cfe75b3bad4303a5822340f6adcfc (patch)
tree79a69cb7601bf1367e4ee4f10ebf61b698319bf3 /game/src/Game/GameSession/ProvinceIndexSampler.gdshaderinc
parent72d893d55d26ae9dc6739a853d1773b3cb286123 (diff)
parentaefc61a1aff091e31436c60d004531b5905cecba (diff)
Merge pull request #166 from OpenVicProject/gui
GUI elements -> Godot UI nodes generator
Diffstat (limited to 'game/src/Game/GameSession/ProvinceIndexSampler.gdshaderinc')
-rw-r--r--game/src/Game/GameSession/ProvinceIndexSampler.gdshaderinc6
1 files changed, 6 insertions, 0 deletions
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;
}