Pixel-Composer/shaders/sh_grid_hex/sh_grid_hex.fsh

47 lines
1.1 KiB
Plaintext
Raw Normal View History

2022-12-13 14:11:39 +01:00
/*
Triangular Grid
03/2016
seb chevrel
*/
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
uniform vec2 position;
uniform vec2 scale;
uniform float angle;
uniform float thick;
2023-01-09 03:14:20 +01:00
uniform vec4 color0;
uniform vec4 color1;
2022-12-13 14:11:39 +01:00
float hexagonAspect = sqrt(3.0);
void main() {
float time = 1.;
vec2 pos = (v_vTexcoord - position), _pos;
float ratio = dimension.x / dimension.y;
_pos.x = pos.x * ratio * cos(angle) - pos.y * sin(angle);
_pos.y = pos.x * ratio * sin(angle) + pos.y * cos(angle);
_pos.y *= hexagonAspect;
vec2 uvTiled = _pos * scale;
vec2 uvOffset = uvTiled + floor((uvTiled.y) / 1.5) * 0.5;
vec2 uvChanged = abs(fract(uvOffset) - 0.5) * 2.0;
float hexagonMask = 0.0;
if(mod(uvTiled.y, 1.5) < 1.0) {
hexagonMask = step(uvChanged.x, 1.0 - thick);
}
else {
hexagonMask =
step(uvChanged.x + thick * hexagonAspect, uvChanged.y) +
step(uvChanged.y + thick * hexagonAspect, uvChanged.x);
}
2023-01-09 03:14:20 +01:00
gl_FragColor = (hexagonMask > 0.5)? color0 : color1;
2022-12-13 14:11:39 +01:00
}