Image copyright Getty Images Image caption Barry said his son Toby had taught him 'the wonder of being gay'

Novelist Sebastian Barry has said his youngest son coming out was pivotal in the writing of Days Without End, winner of the Costa Book of the Year prize.

"He basically has been my teacher in all matters gay," the Irish writer told Radio 4's Today programme.

Days Without End, which begins in the 1850s, tells of two Irish soldiers who go to fight in America.

At the heart of the story is a gay relationship Barry said was informed by his son Toby's experiences.

Toby coming out at 16, he said, "was the beginning of him teaching me the ins and outs and the majesty and the wonder of being gay".

"All that was drawn into the book and became part of this love between these two men," he said on Wednesday.

Barry became the first novelist to win the Costa Book of the Year prize twice on Tuesday when Days Without End beat four other titles to the award.

Image copyright PA Image caption The Republic of Ireland voted overwhelmingly to legalise same-sex marriage in 2015

Speaking immediately after the presentation, the 61-year-old said Ireland's referendum on same-sex marriage had also been a factor.

"It was just after that that I started writing the book," he told reporters, saying that he and Toby had "had a secret mission" to reflect the referendum result in its narrative.

"If I had written this 20 or 30 years ago it may not have had that element," the author went on.

"You should be teaching your child something; it's not supposed to be the other way around. But maybe it always is in truth."

Excerpt from Days Without End

We get back to our room and light the wick in the oil lamp and pull off our boots and we don't dare to send Winona down for eats and so we will have a hungry night. Winona sets everything to rights then beds down on the little divan pushed agin the foot of our bed.

We'll be chaste as real travellers tonight. Soon her little shipshape form is caught in sleep, rising and falling with every small breath so that the bed feels like there must be a troubled brook running through it. In the darkness as we lie side by side John Cole's left hand snakes over under the sheets and takes a hold of my right hand.

We listen to the cries of the night revellers outside and hear the horses tramping along the ways. We're holding hands then like lovers who have just met or how we imagine lovers might be in the unknown realm where lovers act as lovers without concealment.

Immediately after his win, Barry got in contact with Toby, to whom the book is dedicated, via Skype.

"I couldn't hear what he was saying, he couldn't hear me, but his face was so radiant with happiness," he told BBC Breakfast on Wednesday.

Barry, who receives £30,000, also won the prize in 2008 with The Secret Scripture.

In 2015 the author wrote a widely circulated letter to the Irish Times in which he described himself as "the more than proud father of one shining person who happens to be a member of the LGBT community."

Follow us on Facebook, on Twitter @BBCNewsEnts, or on Instagram at bbcnewsents. If you have a story suggestion email entertainment.news@bbc.co.uk.