improved attenuation code by clamping attenuation constant between 0.0 and 1.0