Improved Bloom Effect by adding a Radius-parameter

This commit is contained in:
Michel Fedde 2021-03-24 13:08:27 +01:00
parent c492470430
commit 7ea788534c
4 changed files with 17 additions and 3 deletions

View file

@ -77,6 +77,12 @@ namespace SM.Base.PostEffects
/// </summary> /// </summary>
public float Power = 1; public float Power = 1;
/// <summary>
/// Radius of the effect
/// <para>Default: 2</para>
/// </summary>
public float Radius = 2;
/// <summary> /// <summary>
/// This can disable the bloom calculation. /// This can disable the bloom calculation.
/// <para>Default: true</para> /// <para>Default: true</para>
@ -175,6 +181,8 @@ namespace SM.Base.PostEffects
collection["Weights"].SetUniform1(_weights); collection["Weights"].SetUniform1(_weights);
collection["WeightCount"].SetUniform1(WeightCurvePickAmount); collection["WeightCount"].SetUniform1(WeightCurvePickAmount);
collection["Power"].SetUniform1(Power); collection["Power"].SetUniform1(Power);
collection["Radius"].SetUniform1(_textureScale * Radius);
}); });
hoz = !hoz; hoz = !hoz;

View file

@ -13,6 +13,8 @@ uniform float[32] Weights;
uniform int WeightCount; uniform int WeightCount;
uniform float Power; uniform float Power;
uniform float Radius;
layout(location = 0) out vec4 color; layout(location = 0) out vec4 color;
vec4 GetRenderColorOffset(vec2 offset); vec4 GetRenderColorOffset(vec2 offset);
@ -37,8 +39,8 @@ void main() {
result *= GetWeight(0); result *= GetWeight(0);
for(int i = 1; i < WeightCount; i++) { for(int i = 1; i < WeightCount; i++) {
result += max(GetRenderColorOffset(tex_offset * i).rgb - thres, 0) * (First ? Power : 1) * GetWeight(i); result += max(GetRenderColorOffset(tex_offset * i * Radius).rgb - thres, 0) * (First ? Power : 1) * GetWeight(i);
result += max(GetRenderColorOffset(-tex_offset * i).rgb - thres, 0) * (First ? Power : 1) * GetWeight(i); result += max(GetRenderColorOffset(-tex_offset * i * Radius).rgb - thres, 0) * (First ? Power : 1) * GetWeight(i);
} }
color = vec4(result, 1); color = vec4(result, 1);

View file

@ -23,8 +23,11 @@ namespace SM_TEST
{ {
window = new GLWindow(); window = new GLWindow();
window.ApplySetup(new Window2DSetup()); window.ApplySetup(new Window2DSetup());
window.SetRenderPipeline(new TestRenderPipeline());
window.SetScene(scene = new Scene()); window.SetScene(scene = new Scene());
scene.Objects.Add(new DrawObject2D()); scene.Objects.Add(new DrawObject2D());
window.UpdateFrame += WindowOnUpdateFrame; window.UpdateFrame += WindowOnUpdateFrame;
window.Run(); window.Run();

View file

@ -18,9 +18,10 @@ namespace SM_TEST
_postBuffer = CreateWindowFramebuffer(0); _postBuffer = CreateWindowFramebuffer(0);
Framebuffers.Add(_postBuffer); Framebuffers.Add(_postBuffer);
_bloom = new BloomEffect(MainFramebuffer, hdr: true, .75f) _bloom = new BloomEffect(MainFramebuffer, hdr: true, .5f)
{ {
Threshold = .5f, Threshold = .5f,
Radius = 5
}; };