check section 3 of this review:
https://www.asc.ohio-state.edu/golubitsky.4/reprintweb-0.5/o...or for a narrower slice this paper is reference [6]:
https://www.researchgate.net/publication/11500666_What_Geome...
The full mathematics are quite challenging, but the gist of the result (iirc) is basically: many common hallucinatory experiences, including the geometric patterns reported from both psychedelics and migraines, can be explained by the inherent connectivity patterns in the visual cortex.
Consistent with this idea, there's other strains of research (sorry, too lazy to look up more citations) that show that psychedelics tend to decrease input from the primary sense organs, so that during a trip we really are literally turning inward. (if you want to look it up, iirc the effect is called "thalamic gating" or something? the senses all come up the spinal nerves into the thalamus which helps gate our attention, but during psychedelic experiences all thalamic input is turned down.)
So what happens when you turn down the dimmer on external senses, is that you "see" only from the "higher" cortical areas: suddenly the neurons that are several synapses removed from primary sense activity are the 'loudest' in our experience. This is why "set and setting" are so important in a trip, because you're going to literally experience your mood and emotional state more strongly than usual, since it won't be mediated as much by external sensory events. That's not to say there's no external senses- most people report experiencing a sort of psychedelic remix of ordinary reality. But back to the geometric patterns -- sometimes what you see really does seem to be based on the fundamental connectivity matrix. it's like in absence of strong input, the visual cortex just has activity rippling across it along its own wiring.
anyways hopefully this rambling with a few sources cited helped a little.