Irides are muscular structures that can expand and contract to change the amount of light entering the eye. But, could this structure be replaced by a non-muscular structure containing pigment cells that allows its opacity to be altered? The eye would not be a vertebrate eye, and the opacity-iris would be the outermost part of the eye. There would also be no eyelids, and the opacity-iris would be used to block out light like eyelids are used
In principle it could be possible to use something akin to liquid crystals to change the opacity of the pupil.
However, in the design current picked by evolution, the eyelid serves both for protecting the eyes from excessive light and physical damages (dust, liquids, other bodies tampering with the eyes), while the iris around the pupil does the fine tuning on the amount of light that reaches the retina.
Even if you take away the function of light reduction, you will still need something to provide protection from physical agents. This takes away a large driver for make this evolve.
Moreover, having a light absorbing pigment in the tissue of the pupil means that, whenever this is tuned opaque, the energy coming from the absorbed light will accumulate in the iris itself. Increased temperatures and proteins do not go well together. Improving the vascularization to take away that excess heat clashes with keeping the area transparent, making this concept less efficient for its intended purpose.
Of course if something could pull off a feat like turning transparent it would be a cephalopod.
The cephalopods have special organs called chromatophores in their tissues.
If you have a baseline transparent body (or organ) you can color it or opacify it as you choose with the chromatophores. That would work for a opacifyable iris or cornea. If opacifyable was not a word in English I assert that it is now; you are all welcome.
Opacity on the receptors
As you can read in some of the other answers, opacity in the iris can lead to a multitude of problems. Heating of the eyeballs where no blood vessels can move the heat away. Colour changes because of filtering out parts of the spectrum. Actively obscuring the light, which will likely make objects seem vague.
A solution might actually be simple. Instead of having the pigment on the frontal or inside structure of the eye, we move it to the back.The pigment can be added to the outside of the receptor cells. Each cell is in a sheath or has a cell membrane that can become opaque in gradients. There's plenty of those in nature, like those of Cephalopods that have both a wide range and fast changing. Whether these are small enough I cannot say with certainty, but I assume they are.
This means you don't obscure in a generalised way anymore, but reduce the light wavelengths this specific receptor is sensitive for. In addition, the light hitting the receptor cells or the opacity pigment won't matter in heat. The blood is close enough to move it.
This way might also allow you to see in much brighter conditions than with the current iris. You can filter out much more percentage of light, as well as filter on specific wavelengths. If only red is incredibly bright, you can reduce that specific wavelength with similar red pigment, or use white and reduce all wavelengths on the red spectrum/red receptors. That way you can see "normally" even in specific bright conditions.
Further advantages could arise if you can remove or reduce specific wavelengths. As we can see on colourblind tests, there many situations where they can distinguish some things better. Camouflage would work much less well if you change through the colour blindness and even greyscale. It can also be utilised in art.
Although not specified, you can use nictitating membranes to protect each eye, like with a chameleon. But as you seek a non vertebrate eyes it might be a solution to a non-existent problem.