Merge: gamnit: premultiply alpha for a nicer alpha blending
authorJean Privat <jean@pryen.org>
Wed, 28 Jun 2017 19:39:24 +0000 (15:39 -0400)
committerJean Privat <jean@pryen.org>
Wed, 28 Jun 2017 19:39:24 +0000 (15:39 -0400)
commit86e2cc16921c1fe9cbfd611edc229545a047d653
tree11387e9445a0d83eaed503d191869e0bb2b67f39
parentec0b87f7db3974a78ada6df4c34155295db86d8f
parenteb145bdfa0c737ba42b7dc13db963b0f66b6498f
Merge: gamnit: premultiply alpha for a nicer alpha blending

Premultiplying RBG pixels values by their alpha reduces visible artifacts when blending between different opacity levels. It also allows for mixing obstructing blending (like smoke hiding the background) and additive blending (like explosions amplifying each other, as in the second screenshot below).

Here are the old and new explosion effects in Jump 'n' Gun (using the same texture as Action Nitro):
![old](https://user-images.githubusercontent.com/208057/27644667-22a0f3d0-5bf2-11e7-884b-2e21555e5e68.png) ![new](https://user-images.githubusercontent.com/208057/27644776-619601c0-5bf2-11e7-84c4-f884533efaf0.png)

By default, textures are expected to be straight (the classic not-premultiplied) and are premultiplied at loading. It can be deactivated for asset files that are already premultiplied (as with the explosion texture above).

The color services in both APIs are also affected. `Sprite::tint` remains the same, using straight colors, the easier alternative. However, `SmoothMaterial::ambient_color`, `diffuse_color` and `specular_color` should be premultiplied, giving more possibility to the clients. Alternatively, `Actor::alpha` is applied to material colors, so while RGB values of `ambient_color` are not premultiplied by `ambient_color[3]` they are premultiplied by `Actor::alpha`.

On Android, pixel values are automatically premultiplied when loaded from a file by the system, so we unpremultiply them as needed (with a strong possibility of data loss on additive blending effects). To fix this, this PR intro a new module `gamnit::android19` using services from the API 19 to disable the premultiply. This module is optional (for now) but it should be imported by all Android games with premultiplied texture asset files.

As a bonus, fix the support for Action Nitro on Android via F-Droid. The latest performance improvements to gamnit makes the game run nicely on mobiles devices!

Pull-Request: #2518