2024-10-30 21:24:03 -06:00
|
|
|
#version 450
|
|
|
|
#extension GL_EXT_buffer_reference : require
|
|
|
|
|
|
|
|
#include "hex_common.glsl"
|
|
|
|
|
|
|
|
#define PI 3.1415926535897932384626433832795
|
2024-11-01 15:46:27 -06:00
|
|
|
const float w = 0.5;
|
|
|
|
const float x = 0.75;
|
2024-11-02 12:07:11 -06:00
|
|
|
const float z = sqrt(3.0)/2.0;
|
2024-10-30 21:24:03 -06:00
|
|
|
|
2024-11-01 15:46:27 -06:00
|
|
|
const vec4 vertices[] = {
|
2024-11-01 12:55:56 -06:00
|
|
|
vec4(0, 0, 0, 1),
|
|
|
|
vec4(w*cos(0*PI/3), 0, w*sin(0*PI/3), 1),
|
|
|
|
vec4(w*cos(1*PI/3), 0, w*sin(1*PI/3), 1),
|
|
|
|
vec4(w*cos(2*PI/3), 0, w*sin(2*PI/3), 1),
|
|
|
|
vec4(w*cos(3*PI/3), 0, w*sin(3*PI/3), 1),
|
|
|
|
vec4(w*cos(4*PI/3), 0, w*sin(4*PI/3), 1),
|
|
|
|
vec4(w*cos(5*PI/3), 0, w*sin(5*PI/3), 1),
|
2024-10-30 21:24:03 -06:00
|
|
|
};
|
|
|
|
|
2024-11-01 15:46:27 -06:00
|
|
|
const uint indices[] = {
|
2024-11-01 12:55:56 -06:00
|
|
|
0, 2, 1,
|
|
|
|
0, 3, 2,
|
|
|
|
0, 4, 3,
|
|
|
|
0, 5, 4,
|
|
|
|
0, 6, 5,
|
|
|
|
0, 1, 6,
|
2024-10-30 21:24:03 -06:00
|
|
|
};
|
|
|
|
|
2024-11-01 15:46:27 -06:00
|
|
|
const vec4 starts[] = {
|
2024-11-02 12:07:11 -06:00
|
|
|
vec4( 0, 0, z, 0),
|
|
|
|
vec4(-x, 0, z/2, 0),
|
|
|
|
vec4(-x, 0, -z/2, 0),
|
|
|
|
vec4( 0, 0, -z, 0),
|
|
|
|
vec4( x, 0, -z/2, 0),
|
|
|
|
vec4( x, 0, z/2, 0),
|
2024-11-01 15:46:27 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
const vec4 direction[] = {
|
2024-11-02 12:07:11 -06:00
|
|
|
vec4(-x, 0, -z/2, 0),
|
|
|
|
vec4( 0, 0, -z, 0),
|
|
|
|
vec4( x, 0, -z/2, 0),
|
|
|
|
vec4( x, 0, z/2, 0),
|
|
|
|
vec4( 0, 0, z, 0),
|
|
|
|
vec4(-x, 0, z/2, 0),
|
2024-11-01 15:46:27 -06:00
|
|
|
};
|
|
|
|
|
2024-11-01 17:34:41 -06:00
|
|
|
layout(location=0) out vec4 color;
|
|
|
|
|
|
|
|
vec4 int2color(uint color_int) {
|
|
|
|
float r = float((color_int >> 24) & 0xFF)/255.0;
|
|
|
|
float g = float((color_int >> 16) & 0xFF)/255.0;
|
|
|
|
float b = float((color_int >> 8) & 0xFF)/255.0;
|
|
|
|
float a = float((color_int >> 0) & 0xFF)/255.0;
|
|
|
|
return vec4(r, g, b, a);
|
|
|
|
}
|
|
|
|
|
2024-11-02 12:07:11 -06:00
|
|
|
const uint region_size = 6;
|
|
|
|
const uint region_hex_count = 3*region_size*(region_size-1)+1;
|
|
|
|
|
2024-10-30 21:24:03 -06:00
|
|
|
void main() {
|
2024-11-02 12:07:11 -06:00
|
|
|
uint region_index = uint(floor(gl_InstanceIndex/region_hex_count));
|
|
|
|
uint hex_index = gl_InstanceIndex - (region_index*region_hex_count);
|
|
|
|
Region region = pc.context.regions[region_index];
|
|
|
|
|
|
|
|
float q = region.q;
|
|
|
|
float r = region.r;
|
|
|
|
|
|
|
|
float z_off = 0;
|
|
|
|
if(r != 0) {
|
|
|
|
z_off = r/2;
|
|
|
|
}
|
|
|
|
float x_off = 0;
|
|
|
|
if((q+r) != 0) {
|
|
|
|
x_off = (q+r)/2;
|
|
|
|
}
|
|
|
|
vec4 region_offset = vec4(x*(x_off + 2*(r+(-q-r)/2)*(region_size-0.5)), 0, z*(z_off + 2*(-q-r)*(region_size-1.75)), 0);
|
2024-11-01 17:34:41 -06:00
|
|
|
|
2024-11-01 15:46:27 -06:00
|
|
|
uint radius = 0;
|
|
|
|
uint ring = 0;
|
|
|
|
uint side = 0;
|
|
|
|
uint hex = 0;
|
2024-11-02 12:07:11 -06:00
|
|
|
if(hex_index != 0) {
|
|
|
|
radius = uint(floor(0.5 + sqrt(12*hex_index-3)/6));
|
|
|
|
ring = hex_index - (3*radius*radius - 3*radius + 1);
|
2024-11-01 15:46:27 -06:00
|
|
|
side = uint(floor(ring/(radius)));
|
|
|
|
hex = ring - (radius*side);
|
|
|
|
}
|
2024-11-02 12:07:11 -06:00
|
|
|
|
|
|
|
vec4 position = vertices[indices[gl_VertexIndex]] + (starts[side]*radius) + (direction[side]*hex) + region_offset;
|
2024-11-01 17:34:41 -06:00
|
|
|
if(gl_VertexIndex % 3 == 0) {
|
2024-11-02 12:07:11 -06:00
|
|
|
position.y = (region.hexes[hex_index].heights[0] +
|
|
|
|
region.hexes[hex_index].heights[1] +
|
|
|
|
region.hexes[hex_index].heights[2] +
|
|
|
|
region.hexes[hex_index].heights[3] +
|
|
|
|
region.hexes[hex_index].heights[4] +
|
|
|
|
region.hexes[hex_index].heights[5])/6;
|
2024-11-01 17:34:41 -06:00
|
|
|
|
2024-11-02 12:07:11 -06:00
|
|
|
color = (int2color(region.hexes[hex_index].colors[0]) +
|
|
|
|
int2color(region.hexes[hex_index].colors[1]) +
|
|
|
|
int2color(region.hexes[hex_index].colors[2]) +
|
|
|
|
int2color(region.hexes[hex_index].colors[3]) +
|
|
|
|
int2color(region.hexes[hex_index].colors[4]) +
|
|
|
|
int2color(region.hexes[hex_index].colors[5]))/6;
|
2024-11-01 17:34:41 -06:00
|
|
|
} else {
|
2024-11-02 12:07:11 -06:00
|
|
|
position.y = region.hexes[hex_index].heights[indices[gl_VertexIndex]-1];
|
|
|
|
color = int2color(region.hexes[hex_index].colors[indices[gl_VertexIndex]-1]);
|
2024-11-01 17:34:41 -06:00
|
|
|
}
|
2024-11-01 15:46:27 -06:00
|
|
|
|
|
|
|
gl_Position = pc.context.proj * pc.context.view * position;
|
2024-10-30 21:24:03 -06:00
|
|
|
}
|