From aa865376f6737393a7f089dda8e1254520af30ba Mon Sep 17 00:00:00 2001 From: realtradam Date: Tue, 19 Apr 2022 04:16:52 -0400 Subject: cleaned up some code --- shaders/pixalizer.fs | 43 +++++++++++++++++++++++++++++++++++++++++++ shaders/test.fs | 42 ------------------------------------------ 2 files changed, 43 insertions(+), 42 deletions(-) create mode 100644 shaders/pixalizer.fs delete mode 100644 shaders/test.fs (limited to 'shaders') 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; +} diff --git a/shaders/test.fs b/shaders/test.fs deleted file mode 100644 index cba5bfb..0000000 --- a/shaders/test.fs +++ /dev/null @@ -1,42 +0,0 @@ -#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; -uniform vec4 colDiffuse; - -// Output fragment color -out vec4 finalColor; - -// NOTE: Add here your custom variables -uniform float renderWidth; -uniform float renderHeight; -vec2 textureResolution = vec2(renderWidth, renderHeight); -uniform float grid_size; -//vec2 onePixel = vec2(1.0, 1.0) / 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() -{ - //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; -} -- cgit v1.2.3