64 lines
2.2 KiB
GLSL
64 lines
2.2 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 = pc.context.highlights.h[gl_InstanceIndex].hex;
|
|
uint highlight_triangle = pc.context.highlights.h[gl_InstanceIndex].triangle;
|
|
// Wedge index (0-5) for this vertex, same meaning as hex.vert's `wedge`.
|
|
// A highlight targeting one specific wedge degenerates every vertex
|
|
// outside it; 0xFFFFFFFF (the default) means "whole hex", unchanged.
|
|
uint wedge = gl_VertexIndex / 3;
|
|
if(hex_index != 0xFFFFFFFF && highlight_triangle != 0xFFFFFFFF && wedge != highlight_triangle) {
|
|
gl_Position = vec4(0, 0, 0, 0);
|
|
color = vec4(0, 0, 0, 0);
|
|
return;
|
|
}
|
|
if(hex_index != 0xFFFFFFFF) {
|
|
Region region = pc.context.regions.r[pc.context.highlights.h[gl_InstanceIndex].region];
|
|
color = pc.context.highlights.h[gl_InstanceIndex].color;
|
|
float raise = pc.context.highlights.h[gl_InstanceIndex].offset;
|
|
|
|
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;
|
|
}
|
|
|
|
position.y += raise;
|
|
|
|
gl_Position = pc.camera.proj * pc.camera.view * position;
|
|
} else {
|
|
gl_Position = vec4(0, 0, 0, 0);
|
|
color = vec4(0, 0, 0, 0);
|
|
}
|
|
}
|