Closed AnthonyYoManz closed 4 years ago
You have saved me a lot of grief! Thank you for pointing out that WebGL expect pre-multiplied colors by default. Fortunately, we can disable that behavior when we create a context by setting the premultipliedAlpha
to false
. We have to do that on context creation, which takes place in blinds. If you want to take a stab at it, feel free; if not, I'll try to get to it soon.
So I did a little investigation into that earlier and it seemed like it was gonna be hellish. Also I read somewhere that premultipliedAlpha = false
doesn't work in Chrome, though that was a bug that's since been fixed.
I've done more investigation into how to specify attributes on context creation and I end up blocked when going as deep down as webgl_stdweb:
Basically, the from_canvas
method compiles (transpiles?) to canvas.getContext("webgl");
without any room for attributes like premultiplied alpha. If I've not made a mistake at some point, we'd need to add a route for some attributes that can go from blinds down to webgl_stdweb.
One thing I haven't looked into is alternative ways to specify premultipliedAlpha = false
, and I have pretty limited familiarity with both JavaScript and WebGL so I'm not really sure where to look.
@AnthonyYoManz Thanks for doing the initial investigation here, I have a fix over on ryanisaacg/blinds#28 that will take care of this for all blend modes.
Motivation and Context
This addresses issue #606
Unlike normal OpenGL, WebGL expects colours' RGB values to be premultiplied by their alpha value. Meeting this expectation is fairly straight forward, as it can be achieved simply by modifying the fragment shader exclusively for wasm32 architecture.
Unfortunately the usual blend func
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
isn't going to do what you'd expect thanks to this, and so I've changed it toblendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
by default on wasm32 arch. It might make more sense to apply this change toglow
orgolem
, rather thanquicksilver
, but I'm not all too familiar with the ecosystem so this could probably use some discussion.Checks
CONTRIBUTING.md
CHANGES.md
, with [BREAKING] next to all breaking changes