Created
November 8, 2018 05:20
-
-
Save GunnarKarlsson/3edd9f09b479a214c59080523f64aaf2 to your computer and use it in GitHub Desktop.
edge renderer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 410 core | |
in vec2 TexCoord; | |
uniform sampler2D screenTexture; | |
out vec4 FragColor; | |
const float offset = 1.0 / 300.0; | |
vec3 setContrast(vec3 value, float contrast) | |
{ | |
return (value - 0.5) * contrast + 0.5; | |
} | |
void main() | |
{ | |
//prepare sharpen-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 | |
); | |
float kernel[9] = float[]( | |
-1, -1, -1, | |
-1, 9, -1, | |
-1, -1, -1 | |
); | |
vec3 sampleTex[9]; | |
//sample FBO | |
for(int i = 0; i < 9; i++) | |
{ | |
sampleTex[i] = vec3(texture(screenTexture, TexCoord.st + offsets[i])); | |
} | |
vec3 col = vec3(0.0); | |
//apply sharpen-kernel | |
for(int i = 0; i < 9; i++) { | |
col += sampleTex[i] * kernel[i]; | |
} | |
//grey-color image | |
float contrast = 2.0; | |
col = setContrast(col, contrast); | |
vec3 grayXfer = vec3(0.3, 0.59, 0.11); | |
vec3 gray = vec3(dot(grayXfer, col)); | |
//output | |
FragColor = vec4(mix(col, gray, 1.0), 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment