Support gamma-correction in gfx::blur
This commit is contained in:
parent
646ef45acf
commit
dbcffa8d4a
2 changed files with 11 additions and 9 deletions
|
|
@ -10,7 +10,7 @@ namespace psemek::gfx
|
|||
|
||||
struct hblur
|
||||
{
|
||||
hblur(int size, float sigma);
|
||||
hblur(int size, float sigma, float gamma = 1.f);
|
||||
~hblur();
|
||||
|
||||
void invoke(texture_2d const & src, render_target const & dst);
|
||||
|
|
@ -21,7 +21,7 @@ namespace psemek::gfx
|
|||
|
||||
struct vblur
|
||||
{
|
||||
vblur(int size, float sigma);
|
||||
vblur(int size, float sigma, float gamma = 1.f);
|
||||
~vblur();
|
||||
|
||||
void invoke(texture_2d const & src, render_target const & dst);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ const vec2 direction = vec2(@BLUR_DIRECTION@);
|
|||
|
||||
uniform sampler2D u_texture;
|
||||
uniform vec2 u_inv_texture_size;
|
||||
uniform float u_gamma;
|
||||
|
||||
in vec2 texcoord;
|
||||
|
||||
|
|
@ -57,13 +58,13 @@ void main()
|
|||
{
|
||||
vec4 p = texture(u_texture, texcoord + float(i) * direction * u_inv_texture_size);
|
||||
float c = coeffs[i + BLUR_SIZE];
|
||||
result.rgb += p.rgb * p.a * c;
|
||||
result.rgb += pow(p.rgb, vec3(1.0 / u_gamma)) * p.a * c;
|
||||
result.a += p.a * c;
|
||||
}
|
||||
if (result.a == 0.0)
|
||||
out_color = result;
|
||||
else
|
||||
out_color = vec4(result.rgb / result.a, result.a);
|
||||
out_color = vec4(pow(result.rgb / result.a, vec3(u_gamma)), result.a);
|
||||
}
|
||||
)";
|
||||
|
||||
|
|
@ -116,11 +117,12 @@ void main()
|
|||
gfx::program program;
|
||||
gfx::array array;
|
||||
|
||||
blur_impl(int size, float sigma, bool horizontal)
|
||||
blur_impl(int size, float sigma, float gamma, bool horizontal)
|
||||
: program(blur_vs, generate_blur_fs_source(size, sigma, horizontal))
|
||||
{
|
||||
program.bind();
|
||||
program["u_texture"] = 0;
|
||||
program["u_gamma"] = gamma;
|
||||
}
|
||||
|
||||
void invoke(texture_2d const & src, render_target const & dst)
|
||||
|
|
@ -145,8 +147,8 @@ void main()
|
|||
using blur_impl::blur_impl;
|
||||
};
|
||||
|
||||
hblur::hblur(int size, float sigma)
|
||||
: pimpl_{make_impl(size, sigma, true)}
|
||||
hblur::hblur(int size, float sigma, float gamma)
|
||||
: pimpl_{make_impl(size, sigma, gamma, true)}
|
||||
{}
|
||||
|
||||
hblur::~hblur() = default;
|
||||
|
|
@ -162,8 +164,8 @@ void main()
|
|||
using blur_impl::blur_impl;
|
||||
};
|
||||
|
||||
vblur::vblur(int size, float sigma)
|
||||
: pimpl_{make_impl(size, sigma, false)}
|
||||
vblur::vblur(int size, float sigma, float gamma)
|
||||
: pimpl_{make_impl(size, sigma, gamma, false)}
|
||||
{}
|
||||
|
||||
vblur::~vblur() = default;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue