combined common functionality in light rendering code