The origins of dreams have been studied by many different people and your approach to understanding the origins depends on your approach, however, dreams seem to originate within the unconscious part of the mind.
This is a huge subject and therefore the following is only a taster to lead you into further reading on the subject.
In the psychodynamic approach, Sigmund Freud studied dreams and in 1900, he wrote a book on his theories. If you are unfamiliar with the psychodynamic approach and psychoanalysis, it may be worth reading the full article at SimplyPsychology, however if you are familiar with terms such as ego, id and superego along with Freud's theroies of the unconscious mind, then you can skip to the Dreams Analysis bit.
Basically, Freud believed
dreams to be the royal road to the unconscious as it is in dreams that
the ego's defenses are lowered so that some of the repressed material
comes through to awareness, albeit in distorted form. Dreams perform
important functions for the unconscious mind and serve as valuable
clues to how the unconscious mind operates.
Repressed material is referred to being disturbing or threatening thoughts which are repressed by the ego by an unconscious mechanism called the ego defence mechanism.
In the person centred approach, Carl Jung talked about the compensatory nature of dreams and Carl Rogers said in his book A way of being (Boston: Houghton Mifflin, 1980)
In relating to the client a Jungian will want to relate to the
unconscious as well as the conscious side of the client's personality.
This means that it will be natural to give special attention to such
things as dreams, fantasies, and projections, which from a Jungian
point of view are our chief means of contact with the unconscious.
Dreams will be given special significance, since the dream provides a
view of the client's problem that is different from his or her
conscious view, yet is still an aspect of the client's view.
Putting these ideas together in a summary, dreams
- can sometimes be pre-recorded in the form of memories of what was said or thought - e.g. in nightmares relating to past traumatic events such as war or abuse - although they can sometimes be a little skewed towards the person's understanding of what happened, and
- they can sometimes be a product of repressed or unrepressed thoughts and feelings just as the article you linked to in your question suggests.
I would also like to draw on a word of caution mentioned in the SimplyPsychology article.
'Dream dictionaries', which are still popular now, were a source of
irritation to Freud. In an amusing example of the limitations of
universal symbols, one of Freud's patients, after dreaming about
holding a wriggling fish, said to him 'that's a Freudian symbol - it
must be a penis!'
Freud explored further and it turned out that the woman's mother, who
was a passionate astrologer and a Pisces, was on the patient's mind
because she disapproved of her daughter being in analysis. It seems
more plausible, as Freud suggested, that the fish represented the
patient's mother rather than a penis!
It is believed from both approaches that dreams perform important functions for the unconscious mind, and these dreams can be beneficial in therapy if carefully and correctly examined by the therapist with the client, as they can open you up to a different view of how things happened in the past or are happening in the present.
Edit: to reflect alteration of OP question
On reflection on my answer above you concluded that Freud's work covered
the process of converting an underlying wish into a dream, an
experience that satisfies an unconscious - possibly immoral - desire
in a morally acceptable way
Whilst dreams can reflect unconscious immoral desires, the desires can be moral but repressed for other reasons such as personal prejudice. Repression is a powerful ego defence mechanism whereby it can prevent a thought or memory which can be psychologically damaging from reaching the conscious.
Repression is unconscious. When we deliberately and consciously try to push away thoughts, this is suppression.
The combination of the answers given in this posting point to the fact that dream creation can occur either before dreaming, at the start or during dreaming. Repression and suppression of thoughts and memories can lead to your unconscious creating the dream when in sleep as your ego defenses are lowered.