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

blend modes behave differently than in ggez #56

Open
PSteinhaus opened this issue Sep 18, 2021 · 0 comments
Open

blend modes behave differently than in ggez #56

PSteinhaus opened this issue Sep 18, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@PSteinhaus
Copy link
Member

PSteinhaus commented Sep 18, 2021

Here are both blend_modes examples. Top is ggez, bottom is good-web-game:

blendmodes

For some reason the blend modes behave differently, though they should be the same.

  • ggez's blend modes: https://github.com/ggez/ggez/blob/f85d89a7dd2803c1f0e79543dc5f6076c4bbde8d/src/graphics/shader.rs#L80-L160
  • gwg's blend modes:
    impl From<BlendMode> for (BlendState, BlendState) {
    fn from(bm: BlendMode) -> Self {
    match bm {
    BlendMode::Add => (
    BlendState::new(
    Equation::Add,
    BlendFactor::Value(BlendValue::SourceAlpha),
    BlendFactor::One,
    ),
    BlendState::new(
    Equation::Add,
    BlendFactor::Value(BlendValue::SourceAlpha),
    BlendFactor::One,
    ),
    ),
    BlendMode::Subtract => (
    BlendState::new(
    Equation::ReverseSubtract,
    BlendFactor::Value(BlendValue::SourceAlpha),
    BlendFactor::One,
    ),
    BlendState::new(Equation::Add, BlendFactor::Zero, BlendFactor::One),
    ),
    BlendMode::Alpha => (
    BlendState::new(
    Equation::Add,
    BlendFactor::Value(BlendValue::SourceAlpha),
    BlendFactor::OneMinusValue(BlendValue::SourceAlpha),
    ),
    BlendState::new(
    Equation::Add,
    BlendFactor::OneMinusValue(BlendValue::DestinationAlpha),
    BlendFactor::One,
    ),
    ),
    BlendMode::Premultiplied => (
    BlendState::new(
    Equation::Add,
    BlendFactor::One,
    BlendFactor::OneMinusValue(BlendValue::SourceAlpha),
    ),
    BlendState::new(
    Equation::Add,
    BlendFactor::OneMinusValue(BlendValue::DestinationAlpha),
    BlendFactor::One,
    ),
    ),
    BlendMode::Multiply => (
    BlendState::new(
    Equation::Add,
    BlendFactor::Value(BlendValue::DestinationColor),
    BlendFactor::Zero,
    ),
    BlendState::new(
    Equation::Add,
    BlendFactor::Value(BlendValue::DestinationAlpha),
    BlendFactor::Zero,
    ),
    ),
    BlendMode::Replace => (
    BlendState::new(Equation::Add, BlendFactor::One, BlendFactor::Zero),
    BlendState::new(Equation::Add, BlendFactor::One, BlendFactor::Zero),
    ),
    }
    }
    }

The first step to analyzing this might be calculating some colors by hand using these formulas to then check whether one of the two cases actually produces this expected result. This would at least give us an answer to which of the two is actually "correct".

@PSteinhaus PSteinhaus added the bug Something isn't working label Sep 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant