Procedural Paintings with Genetic Evolution Algorithm

Second Image: copyright to Liam Wong

From Randomness to a Painting

  1. First I need to explain a bit what genetic algorithm is. This part has little to do with painting and is more on the general concept
  2. How it applies to painting a picture
  3. First primitive results
  4. Improved solutions
Copy right to Liam Wong. This is an example of very high detail painting that takes more than 4 hours to paint
An example of a painting with a high mutation rate, resulting in a chaotic look

Genetic Algorithm

  1. Population is initialized with n members. Each member gets a random set of genes
  2. Each member is assessed by a fitness function, which determines how close the population member is to the desired answer
  3. Based on the fitness value of each member, a probability is assigned to a member, which determines how likely it is to become a parent for the next generation
  4. In a parent selection phase, based on those probabilities, for each second generation member, n number of parents are selected
  5. In a cross over, the genes of parents are combined together to create a new solution as a combination of previous ones.
  6. To not get stuck with only the combinations which were created in step one, from time to time genes are mutated and take random new values

Genetic Algorithm and Painting

Population Creation

Vertex shader of the brushes

Fitness Function

Fitness to Probability

Parent Selection Cross Over and Mutation

Fifth Image: copyright to Liam Wong

Needle in Haystack

Copyright to Liam Wong

About Compute Shaders

Closing Remarks

Further Readings and Resources

  1. Daniel Shiffmans video series on genetic algorithms: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6bJM3VgzjNV5YxVxUwzALHV
  2. Same as above but as text for whoever prefers reading:https://natureofcode.com/book/chapter-9-the-evolution-of-code/
  3. Post on pseudo random number generation by Nathan Reed: http://www.reedbeta.com/blog/quick-and-easy-gpu-random-numbers-in-d3d11/
  4. Article by Nvidia on parallel reduction in GPU: https://developer.download.nvidia.com/assets/cuda/files/reduction.pdf
  5. Sampling elements from a list given their probability: https://stackoverflow.com/questions/38086513/selecting-random-item-from-list-given-probability-of-each-item
  6. Post by Sebastian Aaltonen on maximizing Optimizing GPU occupancy and resource for large thread groups: https://gpuopen.com/learn/optimizing-gpu-occupancy-resource-usage-large-thread-groups/
  7. Microsoft documentation on compute shader group dispatch numbers and thread numbers per group: https://docs.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-id3d11devicecontext-dispatch
  8. Kostas Anagnostou explaining best practices on the number of threads to dispatch per group: https://twitter.com/KostasAAA/status/1274359186185428994?s=20
  9. Nice slides on downsampling and gaussian blur: http://www.cs.toronto.edu/~fidler/slides/2015/CSC420/lecture5.pdf
  10. A gaussian blur implementation in Unity done in shader and graphic pipeline: https://danielilett.com/2019-05-08-tut1-3-smo-blur/
  11. Entry on the use of append buffers in Unity: https://docs.microsoft.com/en-us/windows/win32/direct3d12/indirect-drawing
  12. Microsoft documentation on the structured of indirect drawing argument buffer: https://docs.microsoft.com/en-us/windows/win32/direct3d12/indirect-drawing

--

--

Technical Artist

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store