In the small London house where I grew up, a very large portrait of my father, then aged about 40, hung on the dining room wall. Its colour tones were greys, yellows and umbers. The picture must also have given some prominence to my father's dark, abundant and shiny hair. I don't remember it in great detail. Perhaps this is because, in the rigidly observed seating hierarchy of my small family, I was always positioned with my back to the wall on which the portrait hung.

Perhaps, also, it's because, after my 10th birthday, when my father left our home and divorced my mother, he took the portrait with him and I never saw it again. Yet among the competing imagery of my childhood, it remains solidly there: Dad's portrait, a picture of a hauntingly good-looking man, who abandoned the life I was in and never rejoined it; the representation of a ghost. I've often wondered who commissioned this portrait and why.

My father was a moderately successful playwright and theatre director, whose most lasting claim to fame turned out to be his "discovery" of the then-unknown actress, Mary Ure, whom he cast as the Virgin Mary in an admired production of the York cycle of mystery plays in 1951.

Did the relative triumph of this event, for which he was made an OBE, lead my father to commission a portrait of himself – before his looks faded, before his career began to slide? Did my mother commission it, out of doomed affection for him? Or did the artist (whose name I don't recall, or possibly never knew) come to him and ask him to sit? In other words, did the picture exist because of an act of vanity, an act of adoration, or a plain and simple commercial transaction?

There is always a reason why each and every portrait exists, and I'm very interested in what some of these reasons might be.

We know from Pepys's diary that after the restoration of Charles II in 1660, members of the class to which the diarist belonged (the aspiring middles and upper middles) were extremely eager to commission noble likenesses of themselves and their families to hang above the mantel. Pepys (1633–1703), who habitually tended to put his own selfish desires before those of his wife, Elizabeth (1640–69), in fact commissioned her portrait first – from an artist referred to only by his surname, Savill. "To the paynters," Pepys writes, "and there she sat . . . and I stood by and did tell her some little things to do, that now I think her picture will please me very well." This narration conjures a lively image of the bossy husband arranging and rearranging his wife's appearance to suit his preferences, but the tone is fond. Pepys even allows the artist to paint Elizabeth's dog, "which made us very merry".

Pepys had good reason to spend money on portraits. He was a rising man. He knew that his life might be short, but that a picture would lend it significance while it lasted and prolong his memory beyond the grave. More than this, men such as Pepys, who worked in the Navy Office and was a confidant of the king, would have had very frequent sight of the ever-proliferating portraits of Charles II that adorned the rooms and galleries of Whitehall, and would have been impressed by what they captured.

In the pictures painted of Charles II in the 10 years that followed the restoration there resides an essence of kingship, a kind of beau idéal of monarchy, never quite matched before or since. Charles's sombre but still-beautiful features, the waterfall of black curls, the exquisite lace at his throat, the satin and velvet of the royal vestments inspired the artists of the day to some memorable work. And Pepys no doubt asked himself: if the essence of a sovereign could be rendered so exquisitely in oil paint (as, for example, by the Pieter Nason portrait of 1664), then why not other essences, more modest of course, yet manifesting nonetheless a noble singularity, a proud and distinct humanity?

It is this kind of yearning – to get a proper place in the world and give his life some substance and seeming permanence – which possesses Robert Merivel, the hero (or, more correctly, the anti-hero) of my novel Restoration, set during the years 1664–67. Forgotten by Charles after a brief stint as the king's "fool" at court, languishing alone and bored on his Norfolk estates, Merivel decides, not to commission his own portrait, but to attempt to become an artist himself. He believes that if he could learn to paint, he might arrive at "compassion" (what he actually means is empathy), and that compassion will lead him onwards towards some inexpressible kind of enlightenment. These sentiments are dismissed by Merivel's Quaker friend, Pearce, as "pagan, freakish piffle", but Merivel clings to them, orders an artist's smock and a floppy hat, canvases, pigments and brushes, and sets about his task with his characteristic over-enthusiasm, only to understand very quickly that his work has no value whatsoever.

It's at this point in the story that Elias Finn enters Merivel's life. Finn, Merivel writes, "describes himself as a portraitist, but leads, I discover, an almost mendicant life in the shires of England, going on foot from one great house to another, begging to paint its inhabitants". Hired by Merivel to help him progress in his new vocation, Finn has, in fact, understood the age slightly better than his employer. Merivel mocks the artist's poverty, but Finn knows that, in the end, he will find enough willing sitters to survive as a portraitist. Smart society is once again engaged in a scramble for personal advancement and public recognition; the portrait is a necessary fashion accessory along the route, and there are only so many portrait painters to go round.

Much later in the story, after Merivel's fall from grace and during his long struggle to make sense of his life by an attempted return to his first vocation, medicine, Finn executes a portrait of him, and this confrontation with his own face brings about a rare moment of stillness amid my hero's restless strivings. In its essence, Restoration is itself a "portrait". It's a long study of how one man arrives, by very slow degrees, at wisdom and understanding. Finn's painting is one landmark along the way. "I watched the picture carefully," writes Merivel, "for any signs of fiction and untruth. But I am glad to say there were none. Behind my head is no imagined Utopia."

Merivel manages to hold a fairly steady gaze upon his own features, but seeing one's face "as it is" may often be shocking. Pictures (both portraits and photographs) fling back at us details the mirror somehow fails to point out. As we age, we age more in pictures than we do day by day, for the simple reason that time continues its relentless work between the taking of one set of pictures and the next, but our self-image remains linked to the former set. (Perhaps Oscar Wilde came by the idea for The Picture of Dorian Gray from this realisation.)

As a writer who works very frequently from visual material of all kinds, I have been fascinated to chart the passage of particular lives from an assemblage of portraits and photographs. In my long short story "The Darkness of Wallis Simpson", the narrator is Wallis herself, but this is Wallis in her 80s, a Wallis of whom no single picture exists, for the simple reason that nobody was allowed to visit her. In old age she became a prisoner of her house in Paris, kept out of sight by her "guardian", Maître Suzanne Blum, in such an isolated state that from time to time rumours spread that the duchess was already dead.

In the middle of her life, however, from the day her affair with Edward, Prince of Wales began, Wallis was one of the most photographed women in the world. To write my story – which turns on the idea that the ageing Wallis can remember almost everything about her life except the momentous fact of her relationship with the man who gave up his empire for her – I spent hours looking at Wallis's changing face. At the time of her rise to notoriety, most descriptions of her were unflattering. She was described as "mannish", "vulgar", "coarse" and "too American"(!). It was she who immortalised the idea that "you can't be too rich or too thin". She seems to have lived mainly on a diet of dry martinis and green apples and resorted readily to cosmetic surgery to keep her cheekbones sharp as she aged. She was, in fact, a significant precursor of the cult of the size-zero model.

There are many reasons to feel hostile towards Wallis Simpson, or at least towards the values she espoused. And yet, the more time I spent looking at pictures of her, the more beautiful she became to me. I'm sure there's some kind of syndrome to describe this, an author's gradual and illogical attachment to his or her subject's physical attributes. But still, today, I can't look at a portrait of Wallis Simpson without finding some beauty in it. You could argue, however, that because what my story records/invents are Wallis's internal confusions, longings, sorrows and moments of joy, it is in fact her humanity and not her face that moves me. We've arrived at one definition of the portrait painter's prime aspiration here: to record without words the internal life of the individual.

Like Charles II, Wallis Simpson was defined physically in her pictures by what she wore and by her immaculate grooming. In most portraits of her, the background is kept simple, so as not to distract from the magnificence of her gowns and jewellery, and from the enviable lustre of her hair. Sometimes, however, she's pictured beside some sumptuous piece of furniture or an oversized flower arrangement, and these props function as symbols of her life, or at least of her lifestyle.

Whatever is in the background of a portrait – the small details that may at first go unnoticed but soon congregate into sharp focus – can, if well chosen, add brilliantly to the viewer's perception of an individual. In Derry Moore's adroit colour print of Alan Bennett, photographed in 1992, the chosen background is full of noisy variety. It talks to you. Moore has positioned Bennett in front of a gilded classical mirror, whose surface is almost entirely covered up with cards and photos. These range in subject from a young WH Auden, a cobbled Paris street, a provincial playhouse, a boy (looking rather like the young Picasso) holding a white dog, a theatre programme, a wrought-iron staircase to assorted snaps of Bennett himself with relations or friends. In Bennett's solid, unmoving face, we can recognise his trademark outward persona, the "wryly amused northern stoic". But near his head, above and around the unchanging blond hairline, the collage of pictures suggests to perfection the writer's voice talking and wondering, selecting and sifting; a mind fully alive and curious about the world.

Another writer's portrait I admire is Delmar Banner's picture of Beatrix Potter, painted in 1938. This, in a clever sleight of hand, is Potter as field vole. The artist has integrated the subject cunningly and completely with her fictional world. It's as though the 72-year-old author had just popped out of a ripening cornfield to take a sniff at the sheep-shearing contest going on behind her. At any moment, she will scuttle away, in her camouflage colours of brown, green and grey, but with her wide-awake, inquisitive eyes alert to what has been planted in Mr McGregor's vegetable garden, there to wreak her abiding havoc down the centuries, impervious to changing weather and fashion: part of nature.

And this, of course, is what we all want when we sit for a portrait. We want to become part of what is going to last. Writers, kings, courtesans and clerks, we all crave our own immortality. No doubt my father craved it too, when he sat for the picture that hung in our dining room. Did he get it? Did that picture actually exist? Or is it – like Wallis Simpson's forgetting of the thing that was most precious to her – just another of my mind's provocative inventions?