No one knows how the cosmos began, or even if it had a beginning. The elements were all in place before there could be conscious beings to perceive them. Thus, no explanation for the origins of the cosmos can be considered factual. But here is one theory:
In the beginning, the cosmos was nothing.
Nothing existed, and the entire cosmos was one great nothingness. The nothingness and the cosmos were one.
So really, the cosmos was one thing, and this one thing was nothingness. The cosmos began when this nothingness split into two.
Half the cosmos was pure Creation, pure substance, infinite in extent, flowing from a limitless source. The other half was pure Destruction, the end of all things, a sinkhole into which all created things must flow.
So in the beginning, the cosmos was two things, Creation and Destruction, layered one atop the other like air above water.
But if two things exist, then they must be separable, else they would be one. If the entire cosmos consisted only of two separable things, then there must have been a boundary between them. This boundary was a third thing.
In the beginning, the cosmos was three things: Creation, Destruction, and the boundary between them.
No one knows how long this state endured. Perhaps it endured forever. Most of the cosmos is still in this state, a vast sky of Creation above a vast ocean of Destruction, with the knowable cosmos only a tiny fleck of foam bobbing on the ocean swells. But because this fleck of foam contains all conscious beings, that is where we shall focus our attention.
How did the knowable cosmos come to be? It began when substance split into three. The limitless flow of substance from Creation to Destruction spontaneously differentiated itself into three modes: matter, energy, and spirit.
The instant this differentiation was accomplished, the boundary became a gap. It was no longer an abstract demarcation. It became the only place in the cosmos where substance could exist as multiple things.
In the infinite Creation, there is only one thing – one continuous, infinite, undifferentiated substance. In the infinite Destruction, there is an infinity of things, but each thing has been disintegrated into an infinity of pieces, like silt on the seafloor. And so Creation and Destruction are alike in their homogeneity.
But in the gap between the two, substance split into three modes. And each of these modes split into three elements. Then the elements split and split and split and recombined, forming the chaotic storm of the Elemental Realms.
Such was the cosmos when the deities came into being.