Pixel-Composer/shaders/sh_grid/sh_grid.fsh

57 lines
1.3 KiB
Text
Raw Normal View History

//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 position;
2022-11-01 03:06:03 +01:00
uniform vec2 dimension;
uniform vec2 scale;
2022-01-19 14:48:30 +01:00
uniform float angle;
uniform float width;
2022-09-21 06:09:40 +02:00
uniform float shift;
uniform int shiftAxis;
2022-12-13 09:20:36 +01:00
uniform int height;
2022-09-21 06:09:40 +02:00
uniform vec4 col1, col2;
uniform int useSampler;
void main() {
2022-01-19 14:48:30 +01:00
vec2 pos = v_vTexcoord - position, _pos;
2022-11-01 03:06:03 +01:00
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);
2022-09-21 06:09:40 +02:00
if(shiftAxis == 0) {
float cellY = floor(_pos.y * scale.y);
float shiftX = mod(cellY, 2.) * shift;
_pos.x += shiftX;
} else {
float cellX = floor(_pos.x * scale.x);
float shiftY = mod(cellX, 2.) * shift;
_pos.y += shiftY;
}
2022-12-13 09:20:36 +01:00
vec2 sqSt = floor(_pos * scale) / scale;
vec2 dist = _pos - sqSt;
float ww = width / 2.;
2022-09-21 06:09:40 +02:00
if(useSampler == 0) {
2022-12-13 09:20:36 +01:00
gl_FragColor = vec4(col2.rgb, 1.);
if(dist == clamp(dist, vec2(ww), vec2(1. / scale - ww))) {
2022-09-21 06:09:40 +02:00
gl_FragColor = vec4(col1.rgb, 1.);
2022-12-13 09:20:36 +01:00
if(height == 1) {
vec2 nPos = abs(dist * scale - vec2(0.5)) * 2.;
float d = max(nPos.x, nPos.y);
gl_FragColor = vec4(mix(col1.rgb, col2.rgb, d), 1.);
}
}
2022-09-21 06:09:40 +02:00
} else {
vec2 uv = fract(_pos * scale);
gl_FragColor = texture2D( gm_BaseTexture, uv );
}
}