Pixel-Composer/shaders/sh_checkerboard/sh_checkerboard.fsh

66 lines
1.6 KiB
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
2024-03-27 14:18:39 +01:00
#define PI 3.14159265359
2022-09-21 06:09:40 +02:00
uniform vec2 dimension;
uniform vec2 position;
2024-03-27 14:18:39 +01:00
uniform int blend;
2022-01-13 05:24:03 +01:00
2023-12-23 12:59:21 +01:00
uniform vec2 amount;
uniform int amountUseSurf;
uniform sampler2D amountSurf;
uniform vec2 angle;
uniform int angleUseSurf;
uniform sampler2D angleSurf;
uniform vec4 col1;
uniform vec4 col2;
2022-09-21 06:09:40 +02:00
2024-03-27 14:18:39 +01:00
float check(vec2 c, float amo, float ang) {
float _x = c.x * cos(ang) - c.y * sin(ang);
float _y = c.x * sin(ang) + c.y * cos(ang);
float _a = 1. / amo;
vec2 px = vec2(floor(_x / _a) + 0.5, floor(_y / _a) + 0.5) * _a;
float dd = 1. - (max(abs(px.x - _x), abs(px.y - _y)) / _a + 0.5);
float mm = mod(floor(_x / _a) + floor(_y / _a), 2.);
return mm < .5? 0.5 + dd : 0.5 - dd;
//return mod(floor(_x / _a) + floor(_y / _a), 2.);
}
2022-01-13 05:24:03 +01:00
void main() {
2023-12-23 12:59:21 +01:00
#region params
float amo = amount.x;
if(amountUseSurf == 1) {
vec4 _vMap = texture2D( amountSurf, v_vTexcoord );
amo = mix(amount.x, amount.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
}
float ang = angle.x;
if(angleUseSurf == 1) {
vec4 _vMap = texture2D( angleSurf, v_vTexcoord );
ang = mix(angle.x, angle.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
}
ang = radians(ang);
#endregion
2024-03-27 14:18:39 +01:00
vec2 a = dimension / dimension.y;
vec2 c = (v_vTexcoord - position) * a;
float ch = check(c, amo, ang);
2022-01-13 05:24:03 +01:00
2024-03-27 14:18:39 +01:00
if(blend == 0) gl_FragColor = ch < 0.5? col1 : col2;
else if(blend == 1) {
gl_FragColor = mix(col1, col2, ch);
} else if(blend == 2) {
float px = 2. / max(dimension.x, dimension.y);
ch = smoothstep(0.5 - px, 0.5 + px, ch);
gl_FragColor = mix(col1, col2, ch);
}
2022-01-13 05:24:03 +01:00
}