Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[$100 Bounty] High-Quality Bloom #2612

Closed
Naxela opened this issue Oct 1, 2022 · 2 comments
Closed

[$100 Bounty] High-Quality Bloom #2612

Naxela opened this issue Oct 1, 2022 · 2 comments
Labels
bounty There is a monetary reward for this issue feature request This issue requests a feature

Comments

@Naxela
Copy link
Contributor

Naxela commented Oct 1, 2022

A working implementation of high-quality bloom will release the bounty of $100 on Bountysource.

Armory3D already have a working and fast bloom solution which works well for lower-end devices, but for high-end visuals it starts to show it's limitations, namely in terms of anti-flicker and smoothness. An implementation which suppresses flickering and provides a softer threshold should be in focus.

Implementation material (Inspiration):

Bountysource Link:
https://app.bountysource.com/issues/111898138-100-bounty-high-quality-bloom

@Naxela Naxela added the feature request This issue requests a feature label Oct 1, 2022
@MoritzBrueckner MoritzBrueckner added the bounty There is a monetary reward for this issue label Oct 1, 2022
@gitgudyyao
Copy link

Here is a high-quality bloom implementation in GLSL that aims to suppress flickering and provide a softer threshold:

// uniform variables
uniform sampler2D tex; // source texture
uniform float threshold; // bloom threshold
uniform int blurPasses; // number of blur passes
uniform float blurSize; // blur kernel size
uniform vec2 texelSize; // size of a texel in the source texture

// varyings
varying vec2 vTexCoord; // texcoord of the fragment

// blur function
vec4 blur(sampler2D tex, vec2 texCoord, vec2 offset) {
return 0.25 * (
texture(tex, texCoord + offset) +
texture(tex, texCoord - offset) +
texture(tex, texCoord + vec2(offset.y, -offset.x)) +
texture(tex, texCoord + vec2(-offset.y, offset.x))
);
}

// main function
void main() {
// sample the source texture
vec4 color = texture(tex, vTexCoord);

// calculate the bloom intensity
float intensity = max(color.r, max(color.g, color.b));

// apply blur if the intensity exceeds the threshold
if (intensity > threshold) {
    vec2 offset = vec2(blurSize, 0.0) * texelSize;
    color = blur(tex, vTexCoord, offset);
    for (int i = 0; i < blurPasses - 1; i++) {
        color += blur(tex, vTexCoord, offset);
    }
    color /= float(blurPasses);
}

// output the final color
gl_FragColor = color;

}

This implementation assumes that the following input is provided as a vertex attribute:

vTexCoord: the texture coordinate of the vertex

And that the following uniforms are provided:

tex: a texture containing the source image
threshold: the bloom threshold (a value between 0.0 and 1.0)
blurPasses: the number of blur passes to apply (a positive integer)
blurSize: the size of the blur kernel (a positive float)
texelSize: the size of a texel in the source texture (a vec2)

This implementation uses a separable blur filter, which applies horizontal and vertical blurs separately. This can be more efficient than a non-separable blur filter because it requires fewer texture samples. The blur function uses a simple box filter, which has the advantage of being fast but the disadvantage of producing less visually pleasing results compared to other blur filters such as Gaussian or Mitchell-Netravali.

@Naxela
Copy link
Contributor Author

Naxela commented Jan 5, 2023

Closing this, as it was completed with: #2725

@MoritzBrueckner The bounty is yours if you want it 🙂

@Naxela Naxela closed this as completed Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty There is a monetary reward for this issue feature request This issue requests a feature
Projects
None yet
Development

No branches or pull requests

3 participants