summaryrefslogtreecommitdiffstats
path: root/src/video_core/host_shaders/present_gaussian.frag
blob: d5e2b1781981375d0e7ea001ee3bff7cdd63ec1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2019 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#version 460 core

#ifdef VULKAN

#define BINDING_COLOR_TEXTURE 1

#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv

#define BINDING_COLOR_TEXTURE 0

#endif

layout (location = 0) in vec2 frag_tex_coord;

layout (location = 0) out vec4 color;

layout (binding = BINDING_COLOR_TEXTURE) uniform sampler2D color_texture;

const float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
const float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);

vec4 blurVertical(sampler2D textureSampler, vec2 coord, vec2 norm) {
    vec4 result = vec4(0.0f);
    for (int i=1; i<3; i++) {
        result +=
            texture(textureSampler, vec2(coord) + (vec2(0.0, offset[i]) * norm))
                * weight[i];
        result +=
            texture(textureSampler, vec2(coord) - (vec2(0.0, offset[i]) * norm))
                * weight[i];
    }
    return result;
}

vec4 blurHorizontal(sampler2D textureSampler, vec2 coord, vec2 norm) {
    vec4 result = vec4(0.0f);
    for (int i=1; i<3; i++) {
        result +=
            texture(textureSampler, vec2(coord) + (vec2(offset[i], 0.0) * norm))
                * weight[i];
        result +=
            texture(textureSampler, vec2(coord) - (vec2(offset[i], 0.0) * norm))
                * weight[i];
    }
    return result;
}

vec4 blurDiagonal(sampler2D textureSampler, vec2 coord, vec2 norm) {
    vec4 result = vec4(0.0f);
    for (int i=1; i<3; i++) {
        result +=
            texture(textureSampler, vec2(coord) + (vec2(offset[i], offset[i]) * norm))
                * weight[i];
        result +=
            texture(textureSampler, vec2(coord) - (vec2(offset[i], offset[i]) * norm))
                * weight[i];
    }
    return result;
}

void main() {
    vec3 base = texture(color_texture, vec2(frag_tex_coord)).rgb * weight[0];
    vec2 tex_offset = 1.0f / textureSize(color_texture, 0);
    vec3 horizontal = blurHorizontal(color_texture, frag_tex_coord, tex_offset).rgb;
    vec3 vertical = blurVertical(color_texture, frag_tex_coord, tex_offset).rgb;
    vec3 diagonalA = blurVertical(color_texture, frag_tex_coord, tex_offset).rgb;
    vec3 diagonalB = blurVertical(color_texture, frag_tex_coord, -tex_offset).rgb;
    vec3 combination = mix(mix(horizontal, vertical, 0.5f), mix(diagonalA, diagonalB, 0.5f), 0.5f);
    color = vec4(combination + base, 1.0f);
}