A method for shaping an optical waveguide within a substrate, the method comprising: (a) depositing a layer of a masking material on a surface of the substrate; (b) performing a photo-lithographic process of etching said layer of masking material while leaving openings where the optical waveguide is to be formed; (c) performing a first Ion Exchange process by contacting the masked surface of the substrate with a first molten salt bath, to exchange sodium ions in the substrate for a doping cation; wherein the performing of the first Ion Exchange process comprises creating an optical waveguide which is within the substrate and is adjacent to the surface of the substrate; (d) burying the optical waveguide deeper within the substrate by performing a second, different, Ion Exchange process comprising the steps of: (i) removing the layer of the masking material from the surface of the substrate; (ii) placing the substrate in an oven, and applying across the substrate an electric field directed substantially perpendicularly to the substrate surface; (iii) together with step (ii), contacting the active side of the substrate with a second molten salt bath which includes ions that contribute to the substrate refractive index less than the first molten salt bath of step (c); wherein the step of applying the electric field comprises: generating an ionic current, thereby causing the exchange ions from the first Ion Exchange process of step (c) to electro-migrate towards the depth of the substrate, and causing the optical waveguide to drift towards the depth of the substrate; characterized in that the electric field applied in step (d)(ii) is a non-uniform electric field, and in that the magnitude of the non-uniform electrical field applied across the substrate is controlled so as to: modify the burying depth of the optical waveguide along the substrate, and create a gradient in the refractive index along the optical waveguide buried within the substrate. (a) depositing a layer of a masking material on a surface of the substrate; (b) performing a photo-lithographic process of etching said layer of masking material while leaving openings where the optical waveguide is to be formed; (c) performing a first Ion Exchange process by contacting the masked surface of the substrate with a first molten salt bath, to exchange sodium ions in the substrate for a doping cation; wherein the performing of the first Ion Exchange process comprises creating an optical waveguide which is within the substrate and is adjacent to the surface of the substrate; (d) burying the optical waveguide deeper within the substrate by performing a second, different, Ion Exchange process comprising the steps of: (i) removing the layer of the masking material from the surface of the substrate; (ii) placing the substrate in an oven, and applying across the substrate an electric field directed substantially perpendicularly to the substrate surface; (iii) together with step (ii), contacting the active side of the substrate with a second molten salt bath which includes ions that contribute to the substrate refractive index less than the first molten salt bath of step (c); (i) removing the layer of the masking material from the surface of the substrate; (ii) placing the substrate in an oven, and applying across the substrate an electric field directed substantially perpendicularly to the substrate surface; (iii) together with step (ii), contacting the active side of the substrate with a second molten salt bath which includes ions that contribute to the substrate refractive index less than the first molten salt bath of step (c);