Back to shaders
Shader test bench
Checkerboard.fs
runnable fragment
Complete GLSL fragment shader. Stronghold runs it directly when the browser can compile it.
Code
uniform float width;
uniform vec2 offset;
uniform vec4 color1;
uniform vec4 color2;
uniform vec2 splitPos;
precision mediump float;
/*
{
"CATEGORIES" : [
"Pattern", "Color"
],
"ISFVSN" : "2",
"INPUTS" : [
{
"NAME" : "width",
"TYPE" : "float",
"DEFAULT" : 0.25
},
{
"NAME" : "offset",
"TYPE" : "point2D",
"DEFAULT" : [
0,
0
],
"MIN" : [
0,
0
],
"MAX" : [
1,
1
]
},
{
"NAME" : "color1",
"TYPE" : "color",
"DEFAULT" : [
1,
1,
1,
1
]
},
{
"NAME" : "color2",
"TYPE" : "color",
"DEFAULT" : [
0,
0,
0,
1
]
},
{
"NAME" : "splitPos",
"TYPE" : "point2D",
"MAX" : [
1,
1
],
"DEFAULT" : [
0.5,
0.5
],
"MIN" : [
0,
0
]
}
],
"CREDIT" : "by VIDVOX"
}
*/
void main() {
// determine if we are on an even or odd line
// math goes like..
// mod(((coord+offset) / width),2)
vec4 out_color = color2;
float size = width * u_resolution.x;
if (size == 0.0) {
out_color = color1;
}
else if ((mod(((gl_FragCoord.x+(offset.x*u_resolution.x)) / size),2.0) < 2.0 * splitPos.x)&&(mod(((gl_FragCoord.y+(offset.y*u_resolution.y)) / size),2.0) > 2.0 * splitPos.y)) {
out_color = color1;
}
else if ((mod(((gl_FragCoord.x+(offset.x*u_resolution.x)) / size),2.0) > 2.0 * splitPos.x)&&(mod(((gl_FragCoord.y+(offset.y*u_resolution.y)) / size),2.0) < 2.0 * splitPos.y)) {
out_color = color1;
}
gl_FragColor = out_color;
}