HostShader: Fix gaussian and add attribution.
This commit is contained in:
parent
a96c9c803b
commit
99547d2656
|
@ -2,6 +2,10 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
// Code obtained from this 2 sources:
|
||||||
|
// - https://learnopengl.com/Advanced-Lighting/Bloom
|
||||||
|
// - https://www.rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/
|
||||||
|
|
||||||
#version 460 core
|
#version 460 core
|
||||||
|
|
||||||
#ifdef VULKAN
|
#ifdef VULKAN
|
||||||
|
@ -26,12 +30,8 @@ const float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
|
||||||
vec4 blurVertical(sampler2D textureSampler, vec2 coord, vec2 norm) {
|
vec4 blurVertical(sampler2D textureSampler, vec2 coord, vec2 norm) {
|
||||||
vec4 result = vec4(0.0f);
|
vec4 result = vec4(0.0f);
|
||||||
for (int i = 1; i < 3; i++) {
|
for (int i = 1; i < 3; i++) {
|
||||||
result +=
|
result += texture(textureSampler, vec2(coord) + (vec2(0.0, offset[i]) * norm)) * weight[i];
|
||||||
texture(textureSampler, vec2(coord) + (vec2(0.0, offset[i]) * norm))
|
result += texture(textureSampler, vec2(coord) - (vec2(0.0, offset[i]) * norm)) * weight[i];
|
||||||
* weight[i];
|
|
||||||
result +=
|
|
||||||
texture(textureSampler, vec2(coord) - (vec2(0.0, offset[i]) * norm))
|
|
||||||
* weight[i];
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,8 @@ vec4 blurVertical(sampler2D textureSampler, vec2 coord, vec2 norm) {
|
||||||
vec4 blurHorizontal(sampler2D textureSampler, vec2 coord, vec2 norm) {
|
vec4 blurHorizontal(sampler2D textureSampler, vec2 coord, vec2 norm) {
|
||||||
vec4 result = vec4(0.0f);
|
vec4 result = vec4(0.0f);
|
||||||
for (int i = 1; i < 3; i++) {
|
for (int i = 1; i < 3; i++) {
|
||||||
result +=
|
result += texture(textureSampler, vec2(coord) + (vec2(offset[i], 0.0) * norm)) * weight[i];
|
||||||
texture(textureSampler, vec2(coord) + (vec2(offset[i], 0.0) * norm))
|
result += texture(textureSampler, vec2(coord) - (vec2(offset[i], 0.0) * norm)) * weight[i];
|
||||||
* weight[i];
|
|
||||||
result +=
|
|
||||||
texture(textureSampler, vec2(coord) - (vec2(offset[i], 0.0) * norm))
|
|
||||||
* weight[i];
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -53,11 +49,9 @@ vec4 blurDiagonal(sampler2D textureSampler, vec2 coord, vec2 norm) {
|
||||||
vec4 result = vec4(0.0f);
|
vec4 result = vec4(0.0f);
|
||||||
for (int i = 1; i < 3; i++) {
|
for (int i = 1; i < 3; i++) {
|
||||||
result +=
|
result +=
|
||||||
texture(textureSampler, vec2(coord) + (vec2(offset[i], offset[i]) * norm))
|
texture(textureSampler, vec2(coord) + (vec2(offset[i], offset[i]) * norm)) * weight[i];
|
||||||
* weight[i];
|
|
||||||
result +=
|
result +=
|
||||||
texture(textureSampler, vec2(coord) - (vec2(offset[i], offset[i]) * norm))
|
texture(textureSampler, vec2(coord) - (vec2(offset[i], offset[i]) * norm)) * weight[i];
|
||||||
* weight[i];
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -65,10 +59,12 @@ vec4 blurDiagonal(sampler2D textureSampler, vec2 coord, vec2 norm) {
|
||||||
void main() {
|
void main() {
|
||||||
vec3 base = texture(color_texture, vec2(frag_tex_coord)).rgb * weight[0];
|
vec3 base = texture(color_texture, vec2(frag_tex_coord)).rgb * weight[0];
|
||||||
vec2 tex_offset = 1.0f / textureSize(color_texture, 0);
|
vec2 tex_offset = 1.0f / textureSize(color_texture, 0);
|
||||||
|
|
||||||
|
// TODO(Blinkhawk): This code can be optimized through shader group instructions.
|
||||||
vec3 horizontal = blurHorizontal(color_texture, frag_tex_coord, tex_offset).rgb;
|
vec3 horizontal = blurHorizontal(color_texture, frag_tex_coord, tex_offset).rgb;
|
||||||
vec3 vertical = blurVertical(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 diagonalA = blurVertical(color_texture, frag_tex_coord, tex_offset).rgb;
|
||||||
vec3 diagonalB = blurVertical(color_texture, frag_tex_coord, -tex_offset).rgb;
|
vec3 diagonalB = blurVertical(color_texture, frag_tex_coord, tex_offset * vec2(1.0, -1.0)).rgb;
|
||||||
vec3 combination = mix(mix(horizontal, vertical, 0.5f), mix(diagonalA, diagonalB, 0.5f), 0.5f);
|
vec3 combination = mix(mix(horizontal, vertical, 0.5f), mix(diagonalA, diagonalB, 0.5f), 0.5f);
|
||||||
color = vec4(combination + base, 1.0f);
|
color = vec4(combination + base, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue