const float HEX_SCALE = 4.0;     
 
//  hex.
//        input =  2d coordinate
//        output = 2d  'hex' index identifying which hex-tile contains the  input coordinate
//
//
//  note:  0.577350269 =  1 / sqrt(3)
//         1.732050808 =  sqrt(3)
// 

vec2  hex(vec2 uv )
 {
    const vec3 hexProportions = vec3(1.0, 0.577350269, 1.732050808);   
	vec2 hexIndex = floor(uv * hexProportions.xz);
	vec2 r        = fract(hexIndex * 0.5) ;
	vec2 cmp      = vec2(r.y > r.x, r.x > r.y);  
    vec4 useIndex = vec4(hexIndex + cmp, hexIndex + 1.0 - cmp );
    vec4 delta    = uv.xyxy - useIndex  * hexProportions.xyxy;  
	return mix(useIndex.zw, useIndex.xy,  ( dot(delta.xy, delta.xy) < dot(delta.zw, delta.zw) ) ? 1.0 : 0.0 ); 
 } 
    

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{ 
    vec2 uv = fragCoord/iResolution.y;
    
    vec2 h = hex( uv * HEX_SCALE );   
    
    // quick and nasty to get a color, so we can see the difference between adjacent hex cells.
    
    float red = (sin(h.x * 12.0) + 1.0) * 0.50;
    float grn = (sin(h.y * 15.0) + 1.0) * 0.50;
    float blu = (sin(h.y * h.x * 15.0) + 1.0) * 0.50;  
      
    fragColor = vec4(red,grn,blu,1.0);
}