MasDennis/Rajawali — pull request #598 by Davhed (2013-04-25 20:16:50+00:00)
Title: RFC: Super simple alpha masking

Reason

While `MaskedMaterial` offered a quick way to employ alpha masking the developer experience can be improved by incorporating a new parameter. This parameter should enable and disable alpha masking on all materials through the inheritance of `AMaterial`

Method

To leverage the system of "params-as-booleans" within `AMaterial` this update adds a new bitwise parameter `ALPHA_MASKING = 1 << 2` which is used to append a new pre-processor directive `ALPHA_MASK' to the fragment shader program.

`SimpleMaterial`, `GouraudMaterial`, and `PhongMaterial` as well as the related GLSL have been updated to take advantage of this new parameter.

Usage

Continuing with the theme that begat this discussion I have put together a quick example to show this working.

The usage is super simple, just pass `AMaterial.ALPHA_MASKING` to your material instance:

````java
mPlaneF = new Plane(1,1,1,1);
mPlaneF.setPosition(.25f, .25f, 1);
mPlaneF.setMaterial(new SimpleMaterial(AMaterial.ALPHA_MASKING));
mPlaneF.addTexture(mTextureManager.addTexture(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.sn_diff), TextureType.DIFFUSE));
mPlaneF.addTexture(mTextureManager.addTexture(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.sn_map), TextureType.ALPHA));
addChild(mPlaneF);

mPlaneR = new Plane(1,1,1,1);
mPlaneR.setPosition(-.25f, -.25f, 0);
mPlaneR.setMaterial(new SimpleMaterial(AMaterial.ALPHA_MASKING));
mPlaneR.addTexture(mTextureManager.addTexture(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.rt_label)));
addChild(mPlaneR);
````

Note that `mPlaneF` is loaded first but positioned in front and has the "sn" texture using and alpha map. `mPlaneR` is loaded second and is positioned in the back. It has the texture "rt" which is a png with alpha.

This is the rendered result:
![Screenshot_2013-04-25-12-43-00](https://f.cloud.github.com/assets/2634010/427415/97eb4548-ade4-11e2-8d00-d8442a64d6ee.png)

And for any Red Tail fans I also swapped their position and load order to ensure it worked as well, and here is that render:
![Screenshot_2013-04-25-12-40-56](https://f.cloud.github.com/assets/2634010/427422/b3f92192-ade4-11e2-920b-e4a418b9f40b.png)

Still in Question

Should there be a way for the developer to change the masking tolerance? I have it fixed at ".5" currently, but it seems like making it dynamic could would be a nice additional feature.