Systematic Evolution of Optical Bandgap and Local Chemical State in Transparent MgO and HfO2 Resistive Switching Materials