From ca2835943ca4327ad08b54af480e0c6333df201f Mon Sep 17 00:00:00 2001 From: talha Date: Mon, 22 Apr 2024 03:38:29 +0500 Subject: Completed main levels to progress to text-rendering and 2d development. - Only lessons left are geometry shaders and anti-aliasing - will get to those later on soon - need to do text rendering now --- source/lessons/cubemaps/shaders/fbo.fs.glsl | 72 +++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 source/lessons/cubemaps/shaders/fbo.fs.glsl (limited to 'source/lessons/cubemaps/shaders/fbo.fs.glsl') diff --git a/source/lessons/cubemaps/shaders/fbo.fs.glsl b/source/lessons/cubemaps/shaders/fbo.fs.glsl new file mode 100644 index 0000000..e12ad33 --- /dev/null +++ b/source/lessons/cubemaps/shaders/fbo.fs.glsl @@ -0,0 +1,72 @@ +#version 330 core + +in vec2 TexCoords; +uniform sampler2D TexId; +out vec4 FragColor; + +vec4 filter_color_invert(vec4 color) +{ + vec4 res = vec4(vec3(1.0) - vec3(color), 1.0); + return res; +} + +vec4 filter_color_grayscale(vec4 color) +{ + // we will need to average the colors + // float average = (color.x + color.y + color.z) / 3.0f; + // in reality, human our most sensitive towards green and least to blue, so will need to weight those + float average = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b; + vec4 res = vec4(vec3(average), 1.0); + + return res; +} + +// @note: different kernels for experimentation +const float kernel_sharpen[9] = float[]( + -1, -1, -1, + -1, 9, -1, + -1, -1, -1 +); + +const float kernel_blur[9] = float[]( + 1.0/16.0, 2.0/16.0, 1.0/16.0, + 2.0/16.0, 4.0/16.0, 2.0/16.0, + 1.0/16.0, 2.0/16.0, 1.0/16.0 +); + +const float kernel_edge_detection[9] = float[]( + 1, 1, 1, + 1, -8, 1, + 1, 1, 1 +); + +vec4 filter_kernal_effects() +{ + const float offset = 1.0/300.0; + vec2 offsets[9] = vec2[]( + vec2(-offset, offset), // top left + vec2( 0, offset), // top center + vec2( offset, offset), // top right + vec2(-offset, 0), // center left + vec2( 0, 0), // center center + vec2( offset, 0), // center right + vec2(-offset, -offset), // bot left + vec2( 0, -offset), // bot center + vec2( offset, -offset) // bot right + ); + + float kernal[9] = kernel_edge_detection; + vec3 kernalValue = vec3(0.0); + vec3 sampleTex[9]; + for (int i=0; i<9; i++) { + sampleTex[i] = vec3(texture(TexId, TexCoords + offsets[i])); + kernalValue += (kernal[i] * sampleTex[i]); + } + + vec4 res = vec4(kernalValue, 1.0); + return res; +} + +void main() { + FragColor = texture(TexId, TexCoords); +} -- cgit v1.2.3