Thermal fluctuations in the optical properties of dielectric and plasmonic nanomechanical metamaterials