Pixel-Composer/shaders/sh_grid/sh_grid.fsh

49 lines
1.1 KiB
Plaintext
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;
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;
}
vec2 dist = _pos - floor(_pos * scale) / scale;
float ww = width / 2.;
2022-09-21 06:09:40 +02:00
if(useSampler == 0) {
if(dist == clamp(dist, vec2(ww), vec2(1. / scale - ww)))
gl_FragColor = vec4(col1.rgb, 1.);
else
gl_FragColor = vec4(col2.rgb, 1.);
} else {
vec2 uv = fract(_pos * scale);
gl_FragColor = texture2D( gm_BaseTexture, uv );
}
}