reworked calculation of opacity