diff options
| author | realtradam <[email protected]> | 2022-04-19 04:16:52 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2022-04-19 04:16:52 -0400 |
| commit | aa865376f6737393a7f089dda8e1254520af30ba (patch) | |
| tree | 10b5d70b03db52f731af9baf84af7ae83a5b0ed3 /shaders/pixalizer.fs | |
| parent | 4cfbf59ab53ede8eb39a8317c504e7cee889a827 (diff) | |
| download | zig-chip-8-aa865376f6737393a7f089dda8e1254520af30ba.tar.gz zig-chip-8-aa865376f6737393a7f089dda8e1254520af30ba.zip | |
cleaned up some code
Diffstat (limited to 'shaders/pixalizer.fs')
| -rw-r--r-- | shaders/pixalizer.fs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/shaders/pixalizer.fs b/shaders/pixalizer.fs new file mode 100644 index 0000000..a215a73 --- /dev/null +++ b/shaders/pixalizer.fs @@ -0,0 +1,43 @@ +#version 330 + +#define PI 3.1415926538 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; +in vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// Output fragment color +out vec4 finalColor; + +// Imported variables from code +uniform float renderWidth; +uniform float renderHeight; +uniform float grid_size; + +// Variable set up +vec2 flipped = vec2(fragTexCoord.x, 1 - fragTexCoord.y); // flipping +vec2 textureResolution = vec2(renderWidth, renderHeight); +//vec2 onePixel = vec2(1.0, 1.0) / textureResolution; // distance of a single pixel in texels +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() +{ + //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 + finalColor = texelColor*colDiffuse; +} |
