diff options
| author | realtradam <[email protected]> | 2022-04-18 02:28:17 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2022-04-18 02:28:17 -0400 |
| commit | 4cfbf59ab53ede8eb39a8317c504e7cee889a827 (patch) | |
| tree | 332410f7119675be6d36e25dc992033069fd9f38 /shaders | |
| parent | 1ee37746161210d17515e8ef1764e8cb3fd6dec6 (diff) | |
| download | zig-chip-8-4cfbf59ab53ede8eb39a8317c504e7cee889a827.tar.gz zig-chip-8-4cfbf59ab53ede8eb39a8317c504e7cee889a827.zip | |
rewrote shader to be more flexible
Diffstat (limited to 'shaders')
| -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 |
