roleplay/client/shader/hex.vert

60 lines
2.0 KiB
GLSL

#version 450
#extension GL_EXT_buffer_reference : require
#extension GL_EXT_buffer_reference_uvec2 : require
#include "hex_common.glsl"
layout(location=0) out vec4 color;
vec4 int2color(uint color_int) {
float r = float((color_int >> 24) & 0xFF);
float g = float((color_int >> 16) & 0xFF);
float b = float((color_int >> 8) & 0xFF);
float a = float((color_int >> 0) & 0xFF);
return vec4(r, g, b, a)/255.0;
}
void main() {
int region_index = gl_InstanceIndex/region_hex_count;
Region region = pc.context.regions[region_index];
if(uvec2(region) == uvec2(0)) {
gl_Position = vec4(0, 0, 0, 0);
return;
}
if(region.map != pc.context.current_map) {
gl_Position = vec4(0, 0, 0, 0);
return;
}
int hex_index = gl_InstanceIndex - (region_index*region_hex_count);
vec2 region_qr = vec2(region.q, region.r);
vec4 region_pos = vec4(0, 0, 0, 0);
region_pos.x = (region_qr.x+region_qr.y/2)*region_width - region_qr.y*x/2;
region_pos.z = 0.75*region_qr.y*region_height + 0.25*region_qr.y*z + 0.5*region_qr.x*z;
float radius = 0;
float ring = 0;
int side = 0;
if(hex_index != 0) {
radius = floor(0.5 + sqrt(12*hex_index-3)/6);
ring = hex_index - (3*radius*radius - 3*radius + 1);
side = int(floor(ring/(radius)));
}
vec4 position = vertices[indices[gl_VertexIndex]] + (starts[side]*radius) + (direction[side]*(ring-(radius*side))) + region_pos;
if(gl_VertexIndex % 3 == 0) {
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 + region.y;
} else {
position.y = region.hexes[hex_index].heights[indices[gl_VertexIndex]-1] + region.y;
}
color = int2color(region.hexes[hex_index].colors[indices[gl_VertexIndex]]);
gl_Position = pc.context.proj * pc.context.view * position;
}