Dick makes fantastic use of Gnostic mythology/theogony in his so-called VALIS trilogy (VALIS, The Transmigration of Timothy Archer, and The Divine Invasion).

the basic premise of these three books is that a genuinely benevolent being (represented by VALIS) is attempting to save humanity by piercing a metaphorical barrier of evil that has been erected around the world (or at least the United States) by a police state.

this is the state of the universe according to the Gnostics--the true, benevolent god has been separated from the world by the "mad creator god", also sometimes called the Demiurge (a term taken from Plato). the Gnostics considered Yahweh to be this mad god, while Christ was a piece of the true god who had attempted to interpose itself between the mad god and humanity. this mythology figures prominently in the novels, as the few humans who have been contacted by VALIS attempt to make sense out of it.

unfortunately, the true benevolent god never seems to obtain any kind of final victory over the Demiurge in Dick's novels, and so the cycle continues forever.

see also:
  • Radio Free Albemuth by Philip K. Dick (a novel in the vein of the VALIS trilogy, published posthumously).
  • Philip K. Dick is Dead, Alas by Michael Bishop (a sort of homage to PKD in the style of the VALIS novels, though not executed so well, IMHO).