11#include "galaxy/core/ServiceLocator.hpp"
20 layout (location = 0) in vec2 l_pos;
21 layout (location = 1) in vec2 l_texels;
25 gl_Position = vec4(l_pos, 0.0, 1.0);
45 out vec4 io_frag_colour;
47 uniform int u_strength;
48 uniform vec2 u_direction;
49 uniform sampler2D u_texture;
51 vec4 blur5(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
52 vec4 color = vec4(0.0);
53 vec2 off1 = vec2(1.3333333333333333) * direction;
55 color += texture2D(image, uv) * 0.29411764705882354;
56 color += texture2D(image, uv + (off1 / resolution)) * 0.35294117647058826;
57 color += texture2D(image, uv - (off1 / resolution)) * 0.35294117647058826;
62 vec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
63 vec4 color = vec4(0.0);
64 vec2 off1 = vec2(1.3846153846) * direction;
65 vec2 off2 = vec2(3.2307692308) * direction;
67 color += texture2D(image, uv) * 0.2270270270;
68 color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;
69 color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;
70 color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;
71 color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;
76 vec4 blur13(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
77 vec4 color = vec4(0.0);
78 vec2 off1 = vec2(1.411764705882353) * direction;
79 vec2 off2 = vec2(3.2941176470588234) * direction;
80 vec2 off3 = vec2(5.176470588235294) * direction;
82 color += texture2D(image, uv) * 0.1964825501511404;
83 color += texture2D(image, uv + (off1 / resolution)) * 0.2969069646728344;
84 color += texture2D(image, uv - (off1 / resolution)) * 0.2969069646728344;
85 color += texture2D(image, uv + (off2 / resolution)) * 0.09447039785044732;
86 color += texture2D(image, uv - (off2 / resolution)) * 0.09447039785044732;
87 color += texture2D(image, uv + (off3 / resolution)) * 0.010381362401148057;
88 color += texture2D(image, uv - (off3 / resolution)) * 0.010381362401148057;
95 vec2 size = textureSize(u_texture, 0).xy;
96 vec2 uv = gl_FragCoord.xy / size.xy;
100 io_frag_colour = blur5(u_texture, uv, size, u_direction);
102 else if (u_strength == 1)
104 io_frag_colour = blur9(u_texture, uv, size, u_direction);
106 else if (u_strength == 2)
108 io_frag_colour = blur13(u_texture, uv, size, u_direction);
144 glActiveTexture(GL_TEXTURE0);
145 glBindTexture(GL_TEXTURE_2D, input);
146 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
152 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
165 return core::ServiceLocator<core::Config>::ref().get<
bool>(
"gaussian_blur",
"graphics.effects");
constexpr const char *const gaussianblur_vert
GaussianBlur.cpp galaxy.
constexpr const char *const gaussianblur_frag
bool is_enabled() override
Is this effect enabled?
GaussianBlur()=delete
Constructor.
void resize(const int width, const int height) override
Resize framebuffers.
RenderTexture m_horizontal
Framebuffer to render horizontal blur to.
unsigned int render(const unsigned int input) override
Render effect to input texture.
RenderTexture m_vertical
Framebuffer to render vertical blur to.
Strength
Pixel sample strength.
Strength m_strength
Which pixel sample strength to use.
void set_strength(const Strength strength)
Set gaussian blur strength.
Shader m_shader
Shader for post processing effect.
void create(const int width, const int height)
Create framebuffer and texture.
unsigned int texture() const
Gets framebuffer texture.
void recreate(const int width=-1, const int height=-1)
Destroy and re-create framebuffer.
void bind(bool clear=true)
Activate context.
bool parse(const std::string &src)
Loads a combined raw shader.
void set_uniform(const std::string &name, const Uniforms &... args)
Specialized variadic template for setting shader uniforms.
void compile()
Compiles shader into GPU mem.
void bind() const
Make active shader.