2023-05-09 21:51:45 +02:00
|
|
|
shader_type spatial;
|
|
|
|
render_mode specular_schlick_ggx, async_visible;
|
|
|
|
|
|
|
|
uniform sampler2D MapAlbedoTexture : hint_black_albedo;
|
|
|
|
uniform int TextureSize: hint_range(0, 1024, 4);
|
|
|
|
varying vec2 map_coord;
|
|
|
|
|
|
|
|
const mat2 _HexAffineInverse = mat2(vec2(1.333333, -0.6666667), vec2(0, -1.154701));
|
|
|
|
|
|
|
|
vec3 axial_to_cube(vec2 axial) {
|
|
|
|
return vec3(axial.x, axial.y, -axial.x - axial.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
ivec3 round_cube_coords(vec3 cube) {
|
2023-05-19 12:29:03 +02:00
|
|
|
ivec3 rounded = ivec3(round(cube));
|
2023-05-09 21:51:45 +02:00
|
|
|
|
|
|
|
vec3 diffs = abs(vec3(rounded) - cube);
|
|
|
|
|
|
|
|
if (diffs.x > diffs.y && diffs.x > diffs.z) {
|
|
|
|
rounded.x = -rounded.y - rounded.z;
|
|
|
|
} else if (diffs.y > diffs.z) {
|
|
|
|
rounded.y = -rounded.x - rounded.z;
|
|
|
|
} else {
|
|
|
|
rounded.z = -rounded.x - rounded.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rounded;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec2 axial_to_offset(vec2 axial) {
|
|
|
|
ivec3 cubeCoords = round_cube_coords(axial_to_cube(axial));
|
|
|
|
int x = cubeCoords.x;
|
|
|
|
int y = cubeCoords.y;
|
2023-05-19 12:29:03 +02:00
|
|
|
int off_y = y + (x - (x % 2)) / 2;
|
2023-05-09 21:51:45 +02:00
|
|
|
return vec2(float(x), float(off_y));
|
|
|
|
}
|
|
|
|
|
|
|
|
void vertex() {
|
|
|
|
// Input:2
|
|
|
|
mat4 model_matrix = WORLD_MATRIX;
|
|
|
|
|
|
|
|
vec3 origin = vec4(WORLD_MATRIX * vec4(0, 0, 0, 1)).xyz;
|
|
|
|
vec3 axial_coords = vec3(_HexAffineInverse * origin.xz, 0);
|
|
|
|
|
|
|
|
map_coord = origin.xz * 1. / float(TextureSize);
|
2023-05-13 09:29:54 +02:00
|
|
|
map_coord = axial_to_offset(axial_coords.xy) / float(TextureSize) - vec2(0.5);
|
2023-05-09 21:51:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void fragment() {
|
2023-05-19 12:29:03 +02:00
|
|
|
ALBEDO = texture(MapAlbedoTexture, map_coord).rgb;
|
2023-05-09 21:51:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void light() {
|
|
|
|
// Output:0
|
|
|
|
|
|
|
|
}
|