65 lines
1.5 KiB
GLSL
65 lines
1.5 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),
|
|
};
|
|
|
|
void main() {
|
|
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);
|
|
}
|
|
|
|
// Calculate position based on radius/ring/side/hex
|
|
vec4 position = vertices[indices[gl_VertexIndex]] + (starts[side]*radius) + (direction[side]*hex);
|
|
|
|
gl_Position = pc.context.proj * pc.context.view * position;
|
|
}
|