summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/host_shaders/present_gaussian.frag42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/video_core/host_shaders/present_gaussian.frag b/src/video_core/host_shaders/present_gaussian.frag
index d5e2b1781..a9558548f 100644
--- a/src/video_core/host_shaders/present_gaussian.frag
+++ b/src/video_core/host_shaders/present_gaussian.frag
@@ -2,6 +2,10 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5// Code obtained from this 2 sources:
6// - https://learnopengl.com/Advanced-Lighting/Bloom
7// - https://www.rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/
8
5#version 460 core 9#version 460 core
6 10
7#ifdef VULKAN 11#ifdef VULKAN
@@ -14,50 +18,40 @@
14 18
15#endif 19#endif
16 20
17layout (location = 0) in vec2 frag_tex_coord; 21layout(location = 0) in vec2 frag_tex_coord;
18 22
19layout (location = 0) out vec4 color; 23layout(location = 0) out vec4 color;
20 24
21layout (binding = BINDING_COLOR_TEXTURE) uniform sampler2D color_texture; 25layout(binding = BINDING_COLOR_TEXTURE) uniform sampler2D color_texture;
22 26
23const float offset[3] = float[](0.0, 1.3846153846, 3.2307692308); 27const float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
24const float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703); 28const float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
25 29
26vec4 blurVertical(sampler2D textureSampler, vec2 coord, vec2 norm) { 30vec4 blurVertical(sampler2D textureSampler, vec2 coord, vec2 norm) {
27 vec4 result = vec4(0.0f); 31 vec4 result = vec4(0.0f);
28 for (int i=1; i<3; i++) { 32 for (int i = 1; i < 3; i++) {
29 result += 33 result += texture(textureSampler, vec2(coord) + (vec2(0.0, offset[i]) * norm)) * weight[i];
30 texture(textureSampler, vec2(coord) + (vec2(0.0, offset[i]) * norm)) 34 result += texture(textureSampler, vec2(coord) - (vec2(0.0, offset[i]) * norm)) * weight[i];
31 * weight[i];
32 result +=
33 texture(textureSampler, vec2(coord) - (vec2(0.0, offset[i]) * norm))
34 * weight[i];
35 } 35 }
36 return result; 36 return result;
37} 37}
38 38
39vec4 blurHorizontal(sampler2D textureSampler, vec2 coord, vec2 norm) { 39vec4 blurHorizontal(sampler2D textureSampler, vec2 coord, vec2 norm) {
40 vec4 result = vec4(0.0f); 40 vec4 result = vec4(0.0f);
41 for (int i=1; i<3; i++) { 41 for (int i = 1; i < 3; i++) {
42 result += 42 result += texture(textureSampler, vec2(coord) + (vec2(offset[i], 0.0) * norm)) * weight[i];
43 texture(textureSampler, vec2(coord) + (vec2(offset[i], 0.0) * norm)) 43 result += texture(textureSampler, vec2(coord) - (vec2(offset[i], 0.0) * norm)) * weight[i];
44 * weight[i];
45 result +=
46 texture(textureSampler, vec2(coord) - (vec2(offset[i], 0.0) * norm))
47 * weight[i];
48 } 44 }
49 return result; 45 return result;
50} 46}
51 47
52vec4 blurDiagonal(sampler2D textureSampler, vec2 coord, vec2 norm) { 48vec4 blurDiagonal(sampler2D textureSampler, vec2 coord, vec2 norm) {
53 vec4 result = vec4(0.0f); 49 vec4 result = vec4(0.0f);
54 for (int i=1; i<3; i++) { 50 for (int i = 1; i < 3; i++) {
55 result += 51 result +=
56 texture(textureSampler, vec2(coord) + (vec2(offset[i], offset[i]) * norm)) 52 texture(textureSampler, vec2(coord) + (vec2(offset[i], offset[i]) * norm)) * weight[i];
57 * weight[i];
58 result += 53 result +=
59 texture(textureSampler, vec2(coord) - (vec2(offset[i], offset[i]) * norm)) 54 texture(textureSampler, vec2(coord) - (vec2(offset[i], offset[i]) * norm)) * weight[i];
60 * weight[i];
61 } 55 }
62 return result; 56 return result;
63} 57}
@@ -65,10 +59,12 @@ vec4 blurDiagonal(sampler2D textureSampler, vec2 coord, vec2 norm) {
65void main() { 59void main() {
66 vec3 base = texture(color_texture, vec2(frag_tex_coord)).rgb * weight[0]; 60 vec3 base = texture(color_texture, vec2(frag_tex_coord)).rgb * weight[0];
67 vec2 tex_offset = 1.0f / textureSize(color_texture, 0); 61 vec2 tex_offset = 1.0f / textureSize(color_texture, 0);
62
63 // TODO(Blinkhawk): This code can be optimized through shader group instructions.
68 vec3 horizontal = blurHorizontal(color_texture, frag_tex_coord, tex_offset).rgb; 64 vec3 horizontal = blurHorizontal(color_texture, frag_tex_coord, tex_offset).rgb;
69 vec3 vertical = blurVertical(color_texture, frag_tex_coord, tex_offset).rgb; 65 vec3 vertical = blurVertical(color_texture, frag_tex_coord, tex_offset).rgb;
70 vec3 diagonalA = blurVertical(color_texture, frag_tex_coord, tex_offset).rgb; 66 vec3 diagonalA = blurVertical(color_texture, frag_tex_coord, tex_offset).rgb;
71 vec3 diagonalB = blurVertical(color_texture, frag_tex_coord, -tex_offset).rgb; 67 vec3 diagonalB = blurVertical(color_texture, frag_tex_coord, tex_offset * vec2(1.0, -1.0)).rgb;
72 vec3 combination = mix(mix(horizontal, vertical, 0.5f), mix(diagonalA, diagonalB, 0.5f), 0.5f); 68 vec3 combination = mix(mix(horizontal, vertical, 0.5f), mix(diagonalA, diagonalB, 0.5f), 0.5f);
73 color = vec4(combination + base, 1.0f); 69 color = vec4(combination + base, 1.0f);
74} 70}