Thursday, December 26, 2013

Phong alpha

I'd like to post my findings about phong alpha shader with an example of semi-transparent curtains.

Phong alpha is only shader for which gray scale multiplier alpha layers can be applied. We can use CAStable glass shaders for semi transparent parts, but its transparency is defined by one parameter (simple monotone).




The appearance of semi-transparent parts mainly depends on alpha layer of the multiplier and the Alpha Mask Threshold value in mesh's material.

 For example, in my sheer curtain, alpha layer is relatively dark.  I intended sheer fabric like organdy.  In this case, Alpha Mask Threshold was set to 65.

Alpha layer (size reduced) of multiplier  

Appropriate AMT value varies depending on the gray scale of alpha layer.  If you changed its tone, you have to adjust AMT accordingly.  The darker the alpha layer, the lower value for AMT you should choose, and vice versa.


In preview window of TSRWS, we can't see the effect of alpha layer.  So in some cases you might have to repeat 'testing in game' - 'adjusting alpha layer and AMT' cycles.



The major disadvantage of phong alpha is that the semi-transparent part of a mesh often looks weird in game. I call it back-to-front problem. Back side faces looks forward and front faces looks backward (I hope my description makes sense....)

For example, if whole mesh of my curtain is set to phong alpha, it looked like this:



The cloth part was intended to cover the bar. But it looked as if the cloth was under the bar.

Then I set the cloth part to group 0 (= red area), phong alpha, and Alpha Mask Threshold = 180, and
the bar part to group 1 (= green area), phong, and AMT= 0.

This is curtain's alpha layer of multiplier:



And UV-mapping with mask colors:




Then both groups 0 and 1 turned to non-transparent, fully opaque.

Next I changed the AMT value of group 1 (bar part) to 180. Then group 0 returned to semi-transparent, and group 1 remains non-transparent, as intended.



So, if you want to make both semi-transparent part and non-transparent part in one object, you should separate these parts into different groups, and set shader to Phong for the non-transparent group and Phong alpha for semi-transparent group.   In addition, the AMT value of non-transparent group should be set to the same value as those of semi-transparent group.




No comments:

Post a Comment