Skip to content

Incorrect Alpha Blending #63

@KokeCacao

Description

@KokeCacao

Before:

Image Image

After:

Image Image

The Fix:

  protected initialize() {
    this.gl.enable(this.gl.DEPTH_TEST)
    this.gl.depthFunc(this.gl.LEQUAL)

    this.gl.enable(this.gl.BLEND)
    this.gl.blendFuncSeparate(
      this.gl.SRC_ALPHA, // RGB src factor
      this.gl.ONE_MINUS_SRC_ALPHA, // RGB dst factor
      this.gl.ONE, // Alpha src factor: take full αf
      this.gl.ONE_MINUS_SRC_ALPHA // Alpha dst factor
    );


    this.gl.enable(this.gl.CULL_FACE)
    this.gl.cullFace(this.gl.BACK)
  }

Reason:
Incorrect formula: $\alpha_{\text{out}} = \alpha_f \times \alpha_f + \alpha_b \times (1 - \alpha_f)$
Correct formula: $\alpha_{\text{out}} = \alpha_f + \alpha_b ,(1 - \alpha_f)$

There are still other alpha issues, though... trying to fix them all.
Let me know if this is good for a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions