94 lines
2.8 KiB
GLSL
94 lines
2.8 KiB
GLSL
#version 450
|
|
#extension GL_EXT_buffer_reference : require
|
|
|
|
#include "hex_common.glsl"
|
|
|
|
#define PI 3.1415926535897932384626433832795
|
|
const float w = 0.5;
|
|
const float x = 0.75;
|
|
const float z = sqrt(3.0)/4.0;
|
|
|
|
const vec4 vertices[] = {
|
|
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),
|
|
};
|
|
|
|
const uint indices[] = {
|
|
0, 2, 1,
|
|
0, 3, 2,
|
|
0, 4, 3,
|
|
0, 5, 4,
|
|
0, 6, 5,
|
|
0, 1, 6,
|
|
};
|
|
|
|
const vec4 starts[] = {
|
|
vec4( 0, 0, 2*z, 0),
|
|
vec4(-x, 0, z, 0),
|
|
vec4(-x, 0, -z, 0),
|
|
vec4( 0, 0, -2*z, 0),
|
|
vec4( x, 0, -z, 0),
|
|
vec4( x, 0, z, 0),
|
|
};
|
|
|
|
const vec4 direction[] = {
|
|
vec4(-x, 0, -z, 0),
|
|
vec4( 0, 0, -2*z, 0),
|
|
vec4( x, 0, -z, 0),
|
|
vec4( x, 0, z, 0),
|
|
vec4( 0, 0, 2*z, 0),
|
|
vec4(-x, 0, z, 0),
|
|
};
|
|
|
|
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);
|
|
}
|
|
|
|
void main() {
|
|
Region region = pc.context.regions[pc.region];
|
|
|
|
uint radius = 0;
|
|
uint ring = 0;
|
|
uint side = 0;
|
|
uint hex = 0;
|
|
if(gl_InstanceIndex != 0) {
|
|
radius = uint(floor(0.5 + sqrt(12*gl_InstanceIndex-3)/6));
|
|
ring = gl_InstanceIndex - (3*radius*radius - 3*radius + 1);
|
|
side = uint(floor(ring/(radius)));
|
|
hex = ring - (radius*side);
|
|
}
|
|
|
|
vec4 position = vertices[indices[gl_VertexIndex]] + (starts[side]*radius) + (direction[side]*hex);
|
|
if(gl_VertexIndex % 3 == 0) {
|
|
position.y = (region.hexes[gl_InstanceIndex].heights[0] +
|
|
region.hexes[gl_InstanceIndex].heights[1] +
|
|
region.hexes[gl_InstanceIndex].heights[2] +
|
|
region.hexes[gl_InstanceIndex].heights[3] +
|
|
region.hexes[gl_InstanceIndex].heights[4] +
|
|
region.hexes[gl_InstanceIndex].heights[5])/6;
|
|
|
|
color = (int2color(region.hexes[gl_InstanceIndex].colors[0]) +
|
|
int2color(region.hexes[gl_InstanceIndex].colors[1]) +
|
|
int2color(region.hexes[gl_InstanceIndex].colors[2]) +
|
|
int2color(region.hexes[gl_InstanceIndex].colors[3]) +
|
|
int2color(region.hexes[gl_InstanceIndex].colors[4]) +
|
|
int2color(region.hexes[gl_InstanceIndex].colors[5]))/6;
|
|
} else {
|
|
position.y = region.hexes[gl_InstanceIndex].heights[indices[gl_VertexIndex]-1];
|
|
color = int2color(region.hexes[gl_InstanceIndex].colors[indices[gl_VertexIndex]-1]);
|
|
}
|
|
|
|
gl_Position = pc.context.proj * pc.context.view * position;
|
|
}
|