55 lines
1.5 KiB
GLSL
55 lines
1.5 KiB
GLSL
|
#version 450
|
||
|
#extension GL_EXT_buffer_reference : require
|
||
|
|
||
|
#include "hex_common.glsl"
|
||
|
|
||
|
layout(location = 0) flat out vec4 color;
|
||
|
|
||
|
void main() {
|
||
|
uint hex_index;
|
||
|
uint vertex_index;
|
||
|
Region region;
|
||
|
float raise;
|
||
|
|
||
|
|
||
|
if(gl_InstanceIndex == 0) {
|
||
|
hex_index = pc.context.clicked_hex;
|
||
|
region = pc.context.regions[pc.context.clicked_region];
|
||
|
vertex_index = pc.context.clicked_vertex;
|
||
|
color = vec4(1, 0, 0, 1);
|
||
|
gl_PointSize = 15;
|
||
|
raise = 0.01;
|
||
|
} else {
|
||
|
hex_index = pc.context.hovered_hex;
|
||
|
region = pc.context.regions[pc.context.hovered_region];
|
||
|
vertex_index = pc.context.hovered_vertex;
|
||
|
color = vec4(0, 1, 0, 1);
|
||
|
gl_PointSize = 10;
|
||
|
raise = 0.015;
|
||
|
}
|
||
|
|
||
|
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[vertex_index]
|
||
|
+ (starts[side]*radius)
|
||
|
+ (direction[side]*(ring-(radius*side)))
|
||
|
+ region_pos;
|
||
|
|
||
|
position.y = region.hexes[hex_index].heights[vertex_index-1] + region.y + raise;
|
||
|
|
||
|
gl_Position = pc.context.proj * pc.context.view * position;
|
||
|
}
|