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

Add support for Dual Source Blending #1955

Merged
merged 1 commit into from Aug 10, 2021
Merged

Add support for Dual Source Blending #1955

merged 1 commit into from Aug 10, 2021

Conversation

wez
Copy link
Contributor

@wez wez commented Aug 10, 2021

I'm no expert, but this seems to allow using dual source blending ala:

let alpha_blending = glium::DrawParameters {
    blend: glium::Blend {
        color: BlendingFunction::Addition {
            source: LinearBlendingFactor::SourceOneColor,
            destination: LinearBlendingFactor::OneMinusSourceOneColor,
        },
        alpha: BlendingFunction::Addition {
            source: LinearBlendingFactor::SourceOneColor,
            destination: LinearBlendingFactor::OneMinusSourceOneColor,
        },
        constant_value: (0.0, 0.0, 0.0, 0.0),
    },

    ..Default::default()
};

and this in the shader:

// The color + alpha
layout(location=0, index=0) out vec4 color;
// Individual alpha channels for RGBA in color, used for subpixel
// antialiasing blending
layout(location=0, index=1) out vec4 colorMask;

based on my reading of:
https://stackoverflow.com/questions/48491340/use-rgb-texture-as-alpha-values-subpixel-font-rendering-in-opengl
https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_blend_func_extended.txt

refs: wez/wezterm#932

I'm no expert, but this seems to allow using dual source blending ala:

```
let alpha_blending = glium::DrawParameters {
    blend: glium::Blend {
        color: BlendingFunction::Addition {
            source: LinearBlendingFactor::SourceOneColor,
            destination: LinearBlendingFactor::OneMinusSourceOneColor,
        },
        alpha: BlendingFunction::Addition {
            source: LinearBlendingFactor::SourceOneColor,
            destination: LinearBlendingFactor::OneMinusSourceOneColor,
        },
        constant_value: (0.0, 0.0, 0.0, 0.0),
    },

    ..Default::default()
};
```

and this in the shader:

```
// The color + alpha
layout(location=0, index=0) out vec4 color;
// Individual alpha channels for RGBA in color, used for subpixel
// antialiasing blending
layout(location=0, index=1) out vec4 colorMask;
```

based on my reading of:
https://stackoverflow.com/questions/48491340/use-rgb-texture-as-alpha-values-subpixel-font-rendering-in-opengl
https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_blend_func_extended.txt

refs: wez/wezterm#932
Copy link
Collaborator

@est31 est31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@est31 est31 merged commit a4e0b55 into glium:master Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants