I am using this framework https://github.com/bmfs/glslTest_openfl to render sprites that contains drawTiles() to a texture and use it for special effects. But when I try to render the sprite to a RGBA texture, I see transparent edges that exposes the background.
The default alpha blend function is this: GL.blendFunc (GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);.
This method works find when you are performing it on RGB targets, but for some of the effects including God Rays, I need the alpha channel of the foreground layer. We multiply image2 RGBA by image2’s alpha value, and multiple image1 RGBA by 1-image2’s alpha value. This makes sense but it will create a problem here if you have image2 with alpha 0.5 and image1 with alpha 1.0. As you can see, 0.50.5 + 1.00.5 is less than 1.0, which exposes the background color when it’s not suppose to.
I think the key here (and a difference between legacy and the newer code) is that it was not premultiplied before, but is premultiplied now. This should have an impact on how it interacts with other aspects of rendering, but is positive by and large for supporting hardware blend modes (which wasn’t really possible before)
The newer code supports hardware ADD, MULTIPLY and (if I remember properly) SCREEN support. It sounds like this is similar to some of the effects you want to accomplish
There’s a compile flag for the legacy code to try and enable premultiplied alpha, but it never worked in all cases (though I know some people who use it successfully)
lime rebuild windows -Dlegacy -DLEGACY_PREMULTIPLIED_ALPHA (might need to use -clean)
The newer code has some issue when I am trying to port the framework there, including added tiles not showing up, my render passes not showing up etc. I am trying to achieve simply alpha blending RGBA without incorrectly exposing the background.
I am not sure if premultiplying works, because it might still multiply the alpha by itself. I will try it though.
@singmajesty I have modified the OpenGLContext.cpp to correctly blend alpha when premAlpha is not used. But I am somehow unable to test it. When I run lime rebuild windows -Dlegacy the ndll is not updated at all.
I have lime from haxelib, and there is CHANGELOG.md and even .cpp sources in legacy.
But for me rebuild never works for lime from haxelib. But when I do git clone ... from lime repo, than everything works well. Probably haxelib git ... should also work.
On github click on fork to create a copy of the repository for yourself,
push to this repository, it’s recommended to use a separate branch.
Then click on the green button, “compare, review, create a pull request” to create a pull request.
I hope it’s not too unhelpful, if not don’t hesitate to ask again