Thanks to visit codestin.com
Credit goes to github.com

Skip to content

blend modes behave differently than in ggez #56

@PSteinhaus

Description

@PSteinhaus

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions