121 lines
2.4 KiB
GLSL
121 lines
2.4 KiB
GLSL
#version 430
|
|
|
|
in vec2 uv;
|
|
|
|
out vec4 final_color;
|
|
|
|
uniform sampler2D tex;
|
|
|
|
subroutine vec4 shading_t(vec4 color);
|
|
subroutine uniform shading_t Shading;
|
|
|
|
const float f = 1.0 / 300.0;
|
|
|
|
vec2 offsets[9] = vec2[](
|
|
vec2(-f, f), vec2(0.0, f), vec2(f, f),
|
|
vec2(-f, 0.0), vec2(0.0, 0.0), vec2(f, 0.0),
|
|
vec2(-f, -f), vec2(0.0, -f), vec2(f, -f)
|
|
);
|
|
|
|
subroutine(shading_t)
|
|
vec4 absolutely_no_postprocess(vec4 color)
|
|
{
|
|
return color;
|
|
}
|
|
|
|
subroutine(shading_t)
|
|
vec4 sepia(vec4 color)
|
|
{
|
|
return vec4(color.r * .393 + color.g * .769 + color.b * .189,
|
|
color.r * .349 + color.g * .686 + color.b * .168,
|
|
color.r * .272 + color.g * .534 + color.b * .131, 1.0);
|
|
}
|
|
|
|
subroutine(shading_t)
|
|
vec4 grayscale(vec4 color)
|
|
{
|
|
float average = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722;
|
|
return vec4(average, average, average, 1);
|
|
}
|
|
|
|
subroutine(shading_t)
|
|
vec4 depthing(vec4 color)
|
|
{
|
|
float zNear = 2.1f; // zNear of your perspective projection
|
|
float zFar = 40.0f; // zFar of your perspective projection
|
|
float depth = color.x;
|
|
float r = (zNear * 2.0) / (zFar + zNear - depth * (zFar - zNear));
|
|
return vec4(r, r, r, 1);
|
|
}
|
|
|
|
subroutine(shading_t)
|
|
vec4 blurring(vec4 color)
|
|
{
|
|
float blur_kernel[9] = float[](
|
|
1.0 / 16, 2.0 / 16, 1.0 / 16,
|
|
2.0 / 16, 4.0 / 16, 2.0 / 16,
|
|
1.0 / 16, 2.0 / 16, 1.0 / 16
|
|
);
|
|
|
|
vec3 texblur = vec3(0,0,0);
|
|
for (int i = 0; i < 9; i++)
|
|
texblur += vec3(texture(tex, uv + offsets[i]).rgb * blur_kernel[i]);
|
|
|
|
return vec4(texblur, 1);
|
|
}
|
|
|
|
subroutine(shading_t)
|
|
vec4 sharpening(vec4 color)
|
|
{
|
|
float sharp_kernel[9] = float[](
|
|
-1, -1, -1,
|
|
-1, 9, -1,
|
|
-1, -1, -1
|
|
);
|
|
|
|
vec3 texsharp = vec3(0,0,0);
|
|
for (uint i = 0; i < 9; i++)
|
|
texsharp += texture(tex, uv + offsets[i]).rgb * sharp_kernel[i];
|
|
|
|
return vec4(texsharp, 1);
|
|
}
|
|
|
|
subroutine(shading_t)
|
|
vec4 sobel_filter(vec4 color)
|
|
{
|
|
float sobel_x[9] = float[](
|
|
-1, 0, 1,
|
|
-2, 0, 2,
|
|
-1, 0, 1
|
|
);
|
|
|
|
float sobel_y[9] = float[](
|
|
-1, -2, -1,
|
|
0, 0, 0,
|
|
1, 2, 1
|
|
);
|
|
|
|
vec3 vec_x = vec3(0);
|
|
vec3 vec_y = vec3(0);
|
|
|
|
for (int i = 0; i < 9; i++)
|
|
{
|
|
vec_x += texture(tex, uv + offsets[i]).rgb * sobel_x[i];
|
|
vec_y += texture(tex, uv + offsets[i]).rgb * sobel_y[i];
|
|
}
|
|
|
|
vec4 sobeled = vec4(sqrt(vec_x * vec_x + vec_y * vec_y), 1);
|
|
return grayscale(sobeled);
|
|
}
|
|
|
|
subroutine(shading_t)
|
|
vec4 no_postprocess(vec4 color)
|
|
{
|
|
return color;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
final_color = texture(tex, uv).rgba;
|
|
final_color = Shading(final_color);
|
|
} |