Method of producing an optical sensor at wafer-level, comprising the steps of: - providing a wafer of semiconductor material having a main top surface and a main back surface; - arranging at or near the top surface of the wafer a plurality of first integrated circuits each having a light sensitive component; - providing in the wafer at least one through-substrate via for electrically contacting the plurality of integrated circuits via the back surface; - forming a first mold structure by wafer-level molding a first mold material over the top surface of the wafer, such that the first mold structure is arranged above the light sensitive components and at least partly encloses the first integrated circuits, the first mold structure being made at least partly transparent by using an optically transparent mold material as first mold material; and - forming a second mold structure by wafer-level molding a second mold material over the first mold structure, such that the second mold structure at least partly encloses the first mold structure, the second mold structure being made at least partly opaque by using an optically opaque mold material as second mold material, apertures of the second mold structure being formed at or near a top surface of the first mold structure, the apertures being coplanar or flush with the top surface of the first mold structure, wherein: - the first mold structure is formed by means of a structured first mold tool, which is structured and comprises a plurality of cavities each of which are interconnected by channels allowing mold material to flow between the cavities during wafer-level molding, in particular conical or otherwise tapered cavities; - the first mold tool is placed at or near the top surface of the wafer; and - the first mold material is applied to the cavity via a channel in the first mold tool or via a gap left between the first mold tool and the top surface to form the first mold structure, and wherein: - the first and second mold structure (2, 3) are applied to the plurality of first integrated circuits and arranged above the light sensitive components; and - the wafer is singulated into individual optical sensors each comprising at least one of the first integrated circuits. - providing a wafer of semiconductor material having a main top surface and a main back surface; - arranging at or near the top surface of the wafer a plurality of first integrated circuits each having a light sensitive component; - providing in the wafer at least one through-substrate via for electrically contacting the plurality of integrated circuits via the back surface; - forming a first mold structure by wafer-level molding a first mold material over the top surface of the wafer, such that the first mold structure is arranged above the light sensitive components and at least partly encloses the first integrated circuits, the first mold structure being made at least partly transparent by using an optically transparent mold material as first mold material; and - forming a second mold structure by wafer-level molding a second mold material over the first mold structure, such that the second mold structure at least partly encloses the first mold structure, the second mold structure being made at least partly opaque by using an optically opaque mold material as second mold material, apertures of the second mold structure being formed at or near a top surface of the first mold structure, the apertures being coplanar or flush with the top surface of the first mold structure, wherein: - the first mold structure is formed by means of a structured first mold tool, which is structured and comprises a plurality of cavities each of which are interconnected by channels allowing mold material to flow between the cavities during wafer-level molding, in particular conical or otherwise tapered cavities; - the first mold tool is placed at or near the top surface of the wafer; and - the first mold material is applied to the cavity via a channel in the first mold tool or via a gap left between the first mold tool and the top surface to form the first mold structure, and wherein: - the first and second mold structure (2, 3) are applied to the plurality of first integrated circuits and arranged above the light sensitive components; and - the wafer is singulated into individual optical sensors each comprising at least one of the first integrated circuits.