This is basic
Existing genes are sometimes duplicated during DNA replication. Mutations can then occur in one of the copies without affecting the original function of that gene.
This is why (most) humans have tri-chromatic vision - parts of the opsin gene duplicated, then mutated to see different parts of the light spectrum. Strongly selected for because of the advantages of such things as being able to tell the difference between ripe and unripe fruit, for example