Pixel-Composer/shaders/sh_checkerboard/sh_checkerboard.fsh

48 lines
1.1 KiB
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
2022-09-21 06:09:40 +02:00
uniform vec2 dimension;
uniform vec2 position;
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
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
2022-09-21 06:09:40 +02:00
vec2 dimension_norm = dimension / dimension.y;
2023-12-23 12:59:21 +01:00
vec2 c = (v_vTexcoord - position) * dimension_norm;
float _x = c.x * cos(ang) - c.y * sin(ang);
float _y = c.x * sin(ang) + c.y * cos(ang);
float _a = 1. / amo;
2022-01-13 05:24:03 +01:00
if(mod(floor(_x / _a) + floor(_y / _a), 2.) > 0.5)
2022-09-21 06:09:40 +02:00
gl_FragColor = vec4(col1.rgb, 1.);
2022-01-13 05:24:03 +01:00
else
2022-09-21 06:09:40 +02:00
gl_FragColor = vec4(col2.rgb, 1.);
2022-01-13 05:24:03 +01:00
}