diff options
Diffstat (limited to 'advanced_opengl/10.antialiasing/shaders')
-rw-r--r-- | advanced_opengl/10.antialiasing/shaders/color.fs | 9 | ||||
-rw-r--r-- | advanced_opengl/10.antialiasing/shaders/color.vs | 12 | ||||
-rw-r--r-- | advanced_opengl/10.antialiasing/shaders/screen.fs | 122 | ||||
-rw-r--r-- | advanced_opengl/10.antialiasing/shaders/screen.vs | 12 |
4 files changed, 155 insertions, 0 deletions
diff --git a/advanced_opengl/10.antialiasing/shaders/color.fs b/advanced_opengl/10.antialiasing/shaders/color.fs new file mode 100644 index 0000000..b935555 --- /dev/null +++ b/advanced_opengl/10.antialiasing/shaders/color.fs @@ -0,0 +1,9 @@ +#version 330 core + +out vec4 frag_color; + +void +main(void) +{ + frag_color = vec4(0.76f, 0.47f, 0.84f, 1.0f); +} diff --git a/advanced_opengl/10.antialiasing/shaders/color.vs b/advanced_opengl/10.antialiasing/shaders/color.vs new file mode 100644 index 0000000..ade669b --- /dev/null +++ b/advanced_opengl/10.antialiasing/shaders/color.vs @@ -0,0 +1,12 @@ +#version 330 core +layout(location = 0) in vec3 apos; + +uniform mat4 projection; +uniform mat4 view; +uniform mat4 model; + +void +main(void) +{ + gl_Position = projection*view*model*vec4(apos, 1.0); +} diff --git a/advanced_opengl/10.antialiasing/shaders/screen.fs b/advanced_opengl/10.antialiasing/shaders/screen.fs new file mode 100644 index 0000000..8fefa24 --- /dev/null +++ b/advanced_opengl/10.antialiasing/shaders/screen.fs @@ -0,0 +1,122 @@ +#version 330 core + +out vec4 frag_color; + +in vec2 tex_coords; + +uniform sampler2D texture1; + +vec4 +inversion() +{ + vec4 result = vec4(1.0f-vec3(texture(texture1, tex_coords)), 1.0f); + return(result); +} + +vec4 +grayscale_average() +{ + vec4 tex_color = texture(texture1, tex_coords); + float average = (tex_color.r+tex_color.g+tex_color.b)/3.0f; + vec4 result = vec4(average, average, average, 1.0f); + return(result); +} + +vec4 +grayscale_weights() +{ + vec4 tex_color = texture(texture1, tex_coords); + float average = 0.2126*tex_color.r+0.7152*tex_color.g+0.0722f*tex_color.b; + vec4 result = vec4(average, average, average, 1.0f); + return(result); +} + +const float offset = 1.0f/300.0f; + +vec4 +kernel_effect(float[9] kernel) +{ + vec2 offsets[9] = vec2[]( + vec2(-offset, offset), /* top-left */ + vec2(0.0f, offset), /* top-center */ + vec2(offset, offset), /* top-right */ + vec2(-offset, 0.0f), /* center-left */ + vec2(0.0f, 0.0f), /* center-center */ + vec2(offset, 0.0f), /* center-right */ + vec2(-offset, -offset), /* bottom-left */ + vec2(0.0f, -offset), /* bottom-center */ + vec2(offset, -offset) /* bottom-right */ + ); + + vec3 sample_texture[9]; + for (int offset_index = 0; + offset_index < 9; + ++offset_index) + { + sample_texture[offset_index] = + vec3(texture(texture1, tex_coords+offsets[offset_index])); + } + + vec3 color = vec3(0.0f); + for (int i = 0; i < 9; ++i) + color += sample_texture[i]*kernel[i]; + + return(vec4(color, 1.0f)); +} + +void +main(void) +{ + float strange_kernel[9] = float[]( + -1, -1, -1, + -1, 9, -1, + -1, -1, -1 + ); + + float gaussian_blur_kernel[9] = float[]( + 1.0f/16.0f, 2.0f/16.0f, 1.0f/16.0f, + 2.0f/16.0f, 4.0f/16.0f, 2.0f/16.0f, + 1.0f/16.0f, 2.0f/16.0f, 1.0f/16.0f + ); + + float box_blur_kernel[9] = float[]( + 1.0f/9.0f, 1.0f/9.0f, 1.0f/9.0f, + 1.0f/9.0f, 1.0f/9.0f, 1.0f/9.0f, + 1.0f/9.0f, 1.0f/9.0f, 1.0f/9.0f + ); + + float edge_detection_kernel[9] = float[]( + 1.0f, 1.0f, 1.0f, + 1.0f, -8.0f, 1.0f, + 1.0f, 1.0f, 1.0f + ); + + float sharpening_kernel[9] = float[]( + 0.0f, -1.0f, 0.0f, + -1.0f, 5.0f, -1.0f, + 0.0f, -1.0f, 0.0f + ); + + float sobel_kernel_vertical[9] = float[]( + -1.0f, 0.0f, 1.0f, + -2.0f, 0.0f, 2.0f, + -1.0f, 0.0f, 0.0f + ); + float sobel_kernel_horizontal[9] = float[]( + -1.0f, -2.0f, -1.0f, + 0.0f, 0.0f, 0.0f, + 1.0f, 2.0f, 1.0f + ); + + float funny_kernel[9] = float[]( + 1.0f, 1.0f, 1.0f, + 1.0f, -4.0f, 1.0f, + 1.0f, 1.0f, 1.0f + ); + + /* + frag_color = kernel_effect(funny_kernel); + frag_color *= vec4(0.76f, 0.47f, 0.84f, 1.0f); + */ + frag_color = grayscale_weights(); +} diff --git a/advanced_opengl/10.antialiasing/shaders/screen.vs b/advanced_opengl/10.antialiasing/shaders/screen.vs new file mode 100644 index 0000000..0a5213b --- /dev/null +++ b/advanced_opengl/10.antialiasing/shaders/screen.vs @@ -0,0 +1,12 @@ +#version 330 core +layout(location = 0) in vec3 apos; +layout(location = 1) in vec2 atex_coords; + +out vec2 tex_coords; + +void +main(void) +{ + gl_Position = vec4(apos, 1.0f); + tex_coords = atex_coords; +} |