diff options
Diffstat (limited to 'shaders/test.fs')
| -rw-r--r-- | shaders/test.fs | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/shaders/test.fs b/shaders/test.fs index 16cf7c3..cba5bfb 100644 --- a/shaders/test.fs +++ b/shaders/test.fs @@ -1,9 +1,11 @@ #version 330 +#define PI 3.1415926538 // Input vertex attributes (from vertex shader) in vec2 fragTexCoord; in vec4 fragColor; +vec2 flipped = vec2(fragTexCoord.x, 1 - fragTexCoord.y); // Input uniform values uniform sampler2D texture0; @@ -18,26 +20,21 @@ uniform float renderHeight; vec2 textureResolution = vec2(renderWidth, renderHeight); uniform float grid_size; //vec2 onePixel = vec2(1.0, 1.0) / textureResolution; -vec2 pixelCoor = fragTexCoord * textureResolution; +vec2 pixelCoor = flipped * textureResolution; + +float gridify(float coordinate, float spacing) { + return clamp(floor(((-cos( coordinate * 2 * PI)) / 2) + spacing), 0.0, 1.0); +} + +float is_pixel(vec2 coordinate, float spacing) { + return gridify(coordinate.x, spacing) * gridify(coordinate.y, spacing); +} void main() { - vec4 texelColor = vec4(0.0, 0.0, 0.0, 0.0); - // Texel color fetching from texture sampler - if ((mod(floor(pixelCoor.x), grid_size + 1.0) == grid_size) || (mod(floor(pixelCoor.y), grid_size + 1.0) == grid_size)) - { - texelColor = vec4(0.0, 0.0, 0.0, 1.0); - } - else { - pixelCoor.y = -pixelCoor.y; - pixelCoor = pixelCoor / (grid_size + 1.0); - texelColor = texture(texture0, (pixelCoor /textureResolution)); - } -//if ((pix % 3) == 2) -//black pixel -//else -//get color of floor(pix / 3) -//end + //float is_pixel = gridify(pixelCoor.x, 1.0) * gridify(pixelCoor.y, 1.0); + vec4 texelColor = texture(texture0, flipped); + texelColor.rbg *= is_pixel(pixelCoor, grid_size); // NOTE: Implement here your fragment shader code |
