what two factors determine the thermal energy in a substance