RW scholars are still pretty much divided about the origins of the Egyptian religion.
Some see it as an import from Black Africa, the traditional totemic animals having evolved into animal-headed gods.
Some others regard the Egyptian gods as local adaptations of Semitic or Proto-Semitic gods, as shown by their family-like organisation.
Some others, yet, claim the Egyptian religion evolved and grew up spontaneously in the Nile Valley, without any outer influence. After all, most Egyptian gods are specifically tied to one given locale.
Personally, I believe all of this being true to some extent.
It has been shown that the very first inhabitants of the Upper Nile Valley were black-skinned nomads from (probably) Central Africa, who may have followed the river Nile as it went through the African heartland north to the Mediterranean Sea. They brought with themselves their clan-related totems and settled in the fertile Upper Nile Valley.
With time, each clan became tied with a specific region to which its totem animal became associated. The clans would sometimes war against each other and march behind tall poles bearing their totem.
Now figure out a tall pole bearing an animal's head... the Egyptian Gods were born.
The original inhabitants of the Lower Nile Valley (the Delta) were probably related with today's Berbers and Tuaregs. They soon adopted their neighbours' ways and habits, including the correspondence between the territory and the ensign.
However, the original, totemic, meaning was lost to them. It may or may not have been under the influence of the Middle Eastern people that the problem of the gods' residence arose.
Anyway, the gods not only became to be associated with the territories, they were also supposed to somehow live in them, though they still retained a presence in an Afterworld which grew more and more complex with time.
to the index of the Scripta Planorum.
Find more about the RW Egyptian Culture.
Suggested reading: