IT'S BEGINNING TO LOOK as though greatness has been thrust upon Philip K. Dick. This greatest of science fiction writers -- though he's by no means the best writer of science fiction, a distinction we'll try to show makes sense -- has just come though an appalling decade, through a series of experiences no one in his right mind would exactly volunteer for, and arrives in 1981 bearing at long last triumphant evidence of his survival, in the shape of two new novels, VALIS (Bantam Books, $2.25), and The Divine Invasion (Timescape Books/ Simon and Schuster, $12.95, due later this spring). Though the only characters both books have in common are what you might call aspects of God and his adversary, the second, a genre novel science-fictionalizing the Second Coming, is a close sequel to and partial resolution of the first, a tortured autobiographical confession just this side of lunacy. Both novels are about the nature of being and why we live in the shadows: both are formulations of Philip K. Dick's self-lacerating, feverish, deeply argued refusal to believe that the diseased prison of a world we all live in could possibly be the "real" world.

There are two forms of this refusal: refusal to accept the world for what it is; refusal to believe that the world is what it seems to be. The first is the response of a revolutionary, or an entrepreneur. The second is the response of a prophet, or a lunatic. In a career which began in 1952 and reached its productive peak in the 1960s with novels like The Man in the High Castle (1962), Martian Time-Slip (1964), The Three Stigmata of Palmer Eldritch (1965), Do Androids Dream of Electric Sheep? (1968) and Ubik (1969), Dick has consistently applied the ample resources of the science fiction genre to an impassioned examination of the masquarades of being. His entrepreneurs manipulate being; his prophets transform it. Time and again, reality is seen as a cruel hoax, and that in which we invest our trust and our very lives turns out to be a simulacrum managed for profit by figures of malign power, like Palmer Eldritch, dealer in a reality-transforming drug. But how do you tell the simulacrum from the real thing? When you cannot tell -- and ultimately Dick's entrepreneurs never can -- then you are in hell. Palmer Eldritch is as deeply imprisoned as his victims.

In the earlier novels, these profound misadventures tend to be embedded in the kind of science fiction surrounding that Dick has long been a master of: His claustrophobic urbanized solar system -- with its obsessive power figures, androids, autonomic taxicabs, computer psychiatrists, metamorphic aliens and idiot-savant children who plumb deeper realities than we can -- has become immediately recognizable to most genre readers. And because he has always written for this restricted but demanding market, Dick has always been remarkably easy to read, however difficult his message, which is that something like God is with us, inhabiting this world; but that he is a fake God, as trapped as we are.

And this, of course, is terribly wrong. It is terribly frightening to live in hell, oppressed, diseased, deluded, alone. As he has made clear in interviews, at the beginning of the 1970s Dick was coming closer and closer to a genuine personal refusal of the second kind -- he was beginning to refuse to believe that the "real" world could be the hell we live in like netted fish: The sea around us must be Belial's. Written at the end of the 1970s, VALIS is about this refusal.

It is therefore about madness, pain, deception, death, obsessive delusory states of mind, cruelty, solitude, imprisonment, and it is a joy to read. Though madness inhabits its core, it is a testimony to the sanity of art. To deal with the complexities of his confession of sustained psychosis -- of delusional insights he still half-believes in -- Dick divides himself through most of the text two characters, a first-person narrator named Phil who has written the books Dick has written, and Horselover Fat, whom Phil admits from the very first is himself, Philip K. Dick. It is Horselover Fat who received the pink-light laser messages from the stars, who gums together Gnostic doctrines, Talmudic exegetics, Zoroastrianisms, Von Daniken and the Lord knows what to lend verisimilitude to his basic redeeming obsession -- the conviction that he had witnessed a benign power "which has invaded this world" like a champion ready to do battle. The universe might be irrational, but something rational had broken into it, as a thief in the night breaks into a sleeping household.

Men and the world are mutually toxic. But God -- the true God -- has penetrated both, penetrated man and penetrated the world, and sobers the landscape . . .

"VALIS" (Vast Active Living Intelligence System) is another name for God, and has communicated with Horselover Fat, telling him that the garden is at hand. He need only decipher the clues that lie within and without. In passages both moving and hilarious, Horselover and Phil share with each other the ongoing revelations. But when we learn, late in the book, that for eight years Phil has "actually" been projecting a delusory Horselover Fat into "real life" as a shield against the intolerable death of loved ones, and to deal with his (Phil's own) drug-induced schizoid fragility, we begin to see the artfulness in the way Dick has chosen to handle (like a magician, or a writer) material too nutty to accept, too admonitory to forget, too haunting to abandon.

There is a gaiety in playing with fire like this, in having your cake and eating it right on the brink, a gaiety which transfigures the dread of the subject matter. And after reading VALIS, it is the joy that remains: We are glad that Dick is with us. Toward the end of the book, "VALIS" seems to manifest itself in the form of a child, but the child dies, it is only another hoax, another play of shadows. In The Divine Nvasion, the child is born again, this time into a science-fiction universe of the sort Dick has created stories about for decades, and this time comes through. The virgin Rybys becomes pregnant on a colony planet. Guided by the voice of God within her, she and her new husband and the prophet Elijah return to an earth under the sway of Belial, whose minions contrive a prenatal accident, brain-damaging the child.

But God soon conquers the amnesia we are all victims to under Belial, and begins to bring the garden home. There was never any doubt. Sticking to the rails of a simpler artifice, Dick saves us from the horrors of VALIS but from its redeeming gaiety as well. (The theological resemblance of The Divine Invasion to C. S. Lewis' Perelandra books tell the tale: We know we will be saved.) Though he has a master's control over the idioms of science fiction, and demonstrates it in this effortless novel, Dick has never created a new world of much intrinsic interest: His surroundings give color to his explorations of the human condition, not the other way round. So The Divine Invasion, all surface and success, may seem oddly reticent, compared to its fiery predecessor. Perhaps this is what Dick intends. Perhaps he is saying "VALIS" can only be regained through the shape of a science fiction romance, that this temporary solace is our only escape from the black iron prison of our solitary state, stricken by amnesia from the bounties of the garden.

We enter a different world. It is Expanded Universe: The New Worlds of Robert A. Heinlein (Grosset and Dunlap, $12.95; Ace paperback, $8.95). A compendium of Heinlein fiction and nonfiction from the beginning of his career to now, a third of the book appeared in 1966 as The Worlds of Robert A Heinlein.

Much of the new material comprises recent prognostications and polemics, along with a moving description, in a piece called "Spinoff," of his own 1970s medical crisis, a blockage of the flow of blood to the left half of his brain, which caused him to descend into near senility at a terrifying rate. While he still had his wits about him he authorized a dangerous operation: It was successful. The mind thus saved gets its most polished exploration to date in H. Bruce Franklin's Robert A. Heinlein: America as Science Fiction (Oxford University Press, $18.95; paperback, $4.95). A suave, reasonably pragmatic Marxist, Franklin avoids jargon and makes some telling points about Heinlein's increasingly desperate attempts to apply the free-enterprise, individualist ethics of his childhood and early mature years to the darkening texture of postwar America. Heinlein -- as Expanded Universe and Franklin both make clear -- has always been a didactic writer, so this exploration of his roots helps one to understand a good deal about the man, the urgent topicalness of his utterances, however extreme, and the suffocating gigantism of his recent novels. Always searching for new frontiers, by 1980 Heinlein needs an enormous ark to navigate the world's shoals into virgin territory. It will be very lonely there, Franklin tells us.